예제 #1
0
        public PlayerType(DeltinScript deltinScript, ITypeSupplier typeSupplier) : base("Player")
        {
            AsReferenceResetSettability = true;
            ArrayHandler = this;
            _supplier    = typeSupplier;

            deltinScript.StagedInitiation.On(this);
        }
예제 #2
0
        public AnyType(string name, bool unknown, DeltinScript deltinScript) : base(name)
        {
            CanBeDeleted  = true;
            _unknown      = unknown;
            _deltinScript = deltinScript;

            deltinScript.StagedInitiation.On(InitiationStage.Meta, ResolveElements);
        }
        public VectorType(DeltinScript deltinScript, ITypeSupplier supplier) : base("Vector")
        {
            TokenType     = SemanticTokenType.Struct;
            _deltinScript = deltinScript;
            _typeSupplier = supplier;

            deltinScript.StagedInitiation.On(this);
        }
 public CreateArrayAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.CreatearrayContext createArrayContext)
 {
     Values = new IExpression[createArrayContext.expr().Length];
     for (int i = 0; i < Values.Length; i++)
     {
         Values[i] = DeltinScript.GetExpression(parseInfo, scope, createArrayContext.expr(i));
     }
 }
예제 #5
0
 public override IndexReference GetObjectSource(DeltinScript translateInfo, IWorkshopTree element)
 {
     if (TypeKind == TypeKind.Struct)
     {
         throw new NotImplementedException();
     }
     return(translateInfo.SetupClasses().ClassArray.CreateChild((Element)element));
 }
예제 #6
0
        public SelfContainedClassProvider(DeltinScript deltinScript, ISelfContainedClass selfContainedClass) : base(selfContainedClass.Name)
        {
            _selfContainedClass = selfContainedClass;
            _deltinScript       = deltinScript;
            GenericTypes        = new AnonymousType[0];

            Instance = new SelfContainedClassInstance(deltinScript, selfContainedClass, this);
        }
예제 #7
0
 public ReturnAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ReturnContext returnContext)
 {
     ErrorRange = DocRange.GetRange(returnContext.RETURN());
     if (returnContext.expr() != null)
     {
         ReturningValue = DeltinScript.GetExpression(parseInfo, scope, returnContext.expr());
     }
 }
 public ScriptTypes(DeltinScript deltinScript)
 {
     _deltinScript = deltinScript;
     _playerType   = new PlayerType(deltinScript, this);
     _vectorType   = new VectorType(deltinScript, this);
     _numberType   = new NumberType(deltinScript, this);
     _stringType   = new StringType(deltinScript, this);
     _booleanType  = new BooleanType(this);
 }
예제 #9
0
 // Formatted
 public StringAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Formatted_stringContext stringContext) : this(parseInfo.Script, stringContext.@string(), false)
 {
     FormatParameters = new IExpression[stringContext.expr().Length];
     for (int i = 0; i < FormatParameters.Length; i++)
     {
         FormatParameters[i] = DeltinScript.GetExpression(parseInfo, scope, stringContext.expr(i));
     }
     ParseString(parseInfo.Script);
 }
 public void SetupBlock()
 {
     if (ExpressionToParse == null)
     {
         return;
     }
     Expression = DeltinScript.GetExpression(parseInfo.SetCallInfo(CallInfo), scope, ExpressionToParse);
     ReturnType = Expression?.Type();
 }
 public TranslateRule(DeltinScript deltinScript, Subroutine subroutine, string name, bool defaultGlobal)
 {
     DeltinScript = deltinScript;
     IsGlobal     = defaultGlobal;
     Name         = name;
     EventType    = RuleEvent.Subroutine;
     Subroutine   = subroutine;
     ActionSet    = new ActionSet(this, null, Actions);
 }
예제 #12
0
 public DefinedEnumMember(DeltinScript translateInfo, DefinedEnum type, string name, int id, Location definedAt)
 {
     Enum           = type;
     Name           = name;
     DefinedAt      = definedAt;
     ID             = id;
     _translateInfo = translateInfo;
     translateInfo.AddSymbolLink(this, definedAt);
 }
예제 #13
0
 public CompletionItem GetCompletion(DeltinScript deltinScript) => new CompletionItem()
 {
     Label         = Name,
     Kind          = CompletionItemKind.Function,
     Documentation = new MarkupBuilder()
                     .StartCodeLine()
                     .Add(
         Functions[0].GetLabel(deltinScript, LabelInfo.SignatureOverload) + (Functions.Length == 1 ? "" : " (+" + (Functions.Length - 1) + " overloads)")
         ).EndCodeLine().ToMarkup()
 };
예제 #14
0
 public TranslateRule(DeltinScript deltinScript, string name, RuleEvent eventType, Team team, PlayerSelector player, bool disabled = false)
 {
     DeltinScript = deltinScript;
     IsGlobal     = eventType == RuleEvent.OngoingGlobal;
     Name         = name;
     EventType    = eventType;
     Team         = team;
     Player       = player;
     Disabled     = disabled;
     ActionSet    = new ActionSet(this, null, Actions);
 }
예제 #15
0
        public DefinedEnumMember(ParseInfo parseInfo, DefinedEnum type, string name, LanguageServer.Location definedAt, ExpressionOrWorkshopValue value)
        {
            Enum            = type;
            Name            = name;
            DefinedAt       = definedAt;
            _translateInfo  = parseInfo.TranslateInfo;
            ValueExpression = value;

            _translateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, definedAt, true);
            parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.EnumValue, DefinedAt.range));
        }
        public DefinedEnumMember(ParseInfo parseInfo, DefinedEnum type, string name, int id, Location definedAt)
        {
            Enum           = type;
            Name           = name;
            DefinedAt      = definedAt;
            ID             = id;
            _translateInfo = parseInfo.TranslateInfo;

            _translateInfo.AddSymbolLink(this, definedAt, true);
            parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.EnumValue, DefinedAt.range));
        }
예제 #17
0
        public DefinedEnumMember(ParseInfo parseInfo, DefinedEnum type, string name, LanguageServer.Location definedAt, ExpressionOrWorkshopValue value)
        {
            Enum            = type;
            Name            = name;
            DefinedAt       = definedAt;
            _deltinScript   = parseInfo.TranslateInfo;
            ValueExpression = value;

            parseInfo.Script.Elements.AddDeclarationCall(this, new(definedAt.range, true));
            parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.EnumValue, DefinedAt.range));
        }
예제 #18
0
 public void SetupBlock()
 {
     if (ExpressionToParse != null)
     {
         Expression = DeltinScript.GetExpression(parseInfo.SetCallInfo(CallInfo), scope, ExpressionToParse);
     }
     foreach (var listener in listeners)
     {
         listener.Applied();
     }
 }
예제 #19
0
 private void GetInitialValue()
 {
     // Get the initial value.
     if (_initalValueContext != null)
     {
         InitialValue = DeltinScript.GetExpression(parseInfo, _operationalScope, _initalValueContext);
         if (InitialValue?.Type() != null && InitialValue.Type().Constant() == TypeSettable.Constant && CodeType != InitialValue.Type())
         {
             parseInfo.Script.Diagnostics.Error($"The type '{InitialValue.Type().Name}' cannot be stored.", DocRange.GetRange(_initalValueContext));
         }
     }
 }
        public IfAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.IfContext ifContext)
        {
            if (ifContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(ifContext.LEFT_PAREN()));
            }
            else
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, ifContext.expr());
            }

            var paths = new List <PathInfo>();

            if (ifContext.block() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(ifContext.IF()));
            }
            else
            {
                Block = new BlockAction(parseInfo, scope, ifContext.block());
            }
            paths.Add(new PathInfo(Block, DocRange.GetRange(ifContext.IF()), false));

            if (ifContext.else_if() != null)
            {
                ElseIfs = new ElseIf[ifContext.else_if().Length];
                for (int i = 0; i < ElseIfs.Length; i++)
                {
                    ElseIfs[i] = new ElseIf(parseInfo, scope, ifContext.else_if(i));
                    paths.Add(new PathInfo(Block, DocRange.GetRange(ifContext.else_if(i).ELSE(), ifContext.else_if(i).IF()), false));
                }
            }
            else
            {
                ElseIfs = new ElseIf[0];
            }

            // If there is an else statement, get the else block.
            if (ifContext.@else() != null)
            {
                if (ifContext.block() == null)
                {
                    parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(ifContext.@else().block()));
                }
                else
                {
                    ElseBlock = new BlockAction(parseInfo, scope, ifContext.@else().block());
                }
                // Add the else path info.
                paths.Add(new PathInfo(ElseBlock, DocRange.GetRange(ifContext.@else().ELSE()), true));
            }
            Paths = paths.ToArray();
        }
예제 #21
0
        private SwitchElement[] ResolveElements(ParseInfo parseInfo, Scope scope, DeltinScriptParser.SwitchContext switchContext)
        {
            List <SwitchElement> elements = new List <SwitchElement>();
            bool inSection  = false;
            bool caseError  = false;
            bool gotDefault = false;

            // Resolve paths.
            foreach (var switchElement in switchContext.switch_element())
            {
                // Syntax error if there is a statement before a case.
                if (switchElement.statement() != null && !inSection && !caseError)
                {
                    parseInfo.Script.Diagnostics.Error("Expected case or default.", DocRange.GetRange(switchElement));
                    caseError = true;
                }

                // Don't throw the syntax error multiple times in one switch.
                if (switchElement.DEFAULT() != null || switchElement.@case() != null)
                {
                    inSection = true;
                }

                // Default case.
                if (switchElement.DEFAULT() != null)
                {
                    if (gotDefault)
                    {
                        parseInfo.Script.Diagnostics.Error("Switch cannot have multiple defaults.", DocRange.GetRange(switchElement));
                    }
                    gotDefault = true;
                }

                // Get the statement
                if (switchElement.statement() != null)
                {
                    elements.Add(new SwitchElement(DeltinScript.GetStatement(parseInfo, scope, switchElement.statement())));
                }
                // Get the case
                else if (switchElement.@case() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.@case().CASE()), DeltinScript.GetExpression(parseInfo, scope, switchElement.@case().expr())));
                }
                // Get default
                else if (switchElement.DEFAULT() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.DEFAULT())));
                }
            }

            return(elements.ToArray());
        }
        public MarkupBuilder GetLabel(DeltinScript deltinScript, LabelInfo labelInfo)
        {
            var builder = new MarkupBuilder().StartCodeLine().Add("new " + Type.GetName());

            builder.Add(CodeParameter.GetLabels(deltinScript, labelInfo.AnonymousLabelInfo, Parameters)).EndCodeLine();

            if (labelInfo.IncludeDocumentation)
            {
                builder.NewSection().Add(Documentation);
            }

            return(builder);
        }
예제 #23
0
        public DeleteAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.DeleteContext deleteContext)
        {
            DeleteValue = DeltinScript.GetExpression(parseInfo, scope, deleteContext.expr());

            if (DeleteValue.Type() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expression has no type.", DocRange.GetRange(deleteContext.expr()));
            }
            else if (!DeleteValue.Type().CanBeDeleted)
            {
                parseInfo.Script.Diagnostics.Error($"Type '{DeleteValue.Type().Name}' cannot be deleted.", DocRange.GetRange(deleteContext.expr()));
            }
        }
 public void CheckRecursion(DeltinScript deltinScript)
 {
     foreach (var call in _calls)
     {
         if (DoesTreeCall(Function, call.Key))
         {
             foreach (DocRange range in call.Value)
             {
                 _script.Diagnostics.Error($"Recursion is not allowed here, the {call.Key.TypeName} '{call.Key.GetLabel(deltinScript)}' calls '{Function.GetLabel(deltinScript)}'.", range);
             }
         }
     }
 }
예제 #25
0
        public override void WorkshopInit(DeltinScript translateInfo)
        {
            if (workshopInitialized)
            {
                return;
            }
            base.WorkshopInit(translateInfo);

            foreach (Var staticVariable in staticVariables)
            {
                DefineAction.Assign(translateInfo.InitialGlobal.ActionSet, staticVariable);
            }
        }
        public RuleIfAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Rule_ifContext ifContext)
        {
            // Syntax error if there is no expression.
            if (ifContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(ifContext.RIGHT_PAREN()));
            }

            // Get the expression.
            else
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, ifContext.expr());
            }
        }
예제 #27
0
        public WhileAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.WhileContext whileContext)
        {
            if (whileContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(whileContext.LEFT_PAREN()));
            }
            else
            {
                Condition = DeltinScript.GetExpression(parseInfo, scope, whileContext.expr());
            }

            Block = new BlockAction(parseInfo, scope, whileContext.block());
            Path  = new PathInfo(Block, DocRange.GetRange(whileContext.WHILE()), false);
        }
        public TypeConvertAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.TypeconvertContext typeConvert)
        {
            Expression = DeltinScript.GetExpression(parseInfo, scope, typeConvert.expr());

            // Get the type. Syntax error if there is none.
            if (typeConvert.PART() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected type name.", DocRange.GetRange(typeConvert.LESS_THAN()));
            }
            else
            {
                ConvertingTo = parseInfo.TranslateInfo.GetCodeType(typeConvert.PART().GetText(), parseInfo.Script.Diagnostics, DocRange.GetRange(typeConvert.PART()));
            }
        }
 public override void WorkshopInit(DeltinScript translateInfo)
 {
     foreach (EnumValuePair pair in ValuePairs)
     {
         if (Constant)
         {
             translateInfo.DefaultIndexAssigner.Add(pair, pair.Member);
         }
         else
         {
             translateInfo.DefaultIndexAssigner.Add(pair, EnumData.ToElement(pair.Member));
         }
     }
 }
        public ValueInArrayAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.E_array_indexContext exprContext)
        {
            Expression      = DeltinScript.GetExpression(parseInfo, scope, exprContext.array);
            expressionRange = DocRange.GetRange(exprContext.array);

            if (exprContext.index == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected an expression.", DocRange.GetRange(exprContext.INDEX_START()));
            }
            else
            {
                Index      = DeltinScript.GetExpression(parseInfo, scope, exprContext.index);
                indexRange = DocRange.GetRange(exprContext.index);
            }
        }