public RuleAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Ow_ruleContext ruleContext)
        {
            Name               = Extras.RemoveQuotes(ruleContext.STRINGLITERAL().GetText());
            Disabled           = ruleContext.DISABLED() != null;
            _missingBlockRange = DocRange.GetRange(ruleContext.RULE_WORD());

            GetRuleSettings(parseInfo, scope, ruleContext);

            // Get the conditions
            if (ruleContext.rule_if() == null)
            {
                Conditions = new RuleIfAction[0];
            }
            else
            {
                Conditions = new RuleIfAction[ruleContext.rule_if().Length];
                for (int i = 0; i < Conditions.Length; i++)
                {
                    Conditions[i]      = new RuleIfAction(parseInfo, scope, ruleContext.rule_if(i));
                    _missingBlockRange = DocRange.GetRange(ruleContext.rule_if(i));
                }
            }

            if (ruleContext.block() != null)
            {
                Block = new BlockAction(parseInfo, scope, ruleContext.block());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Missing block.", _missingBlockRange);
            }
        }
Esempio n. 2
0
        public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext)
        {
            RawContinue = false;

            Scope varScope = scope.Child();

            ForeachVar = new ForeachVariable(varScope, new ForeachContextHandler(parseInfo, foreachContext));

            // Get the array that will be iterated on. Syntax error if it is missing.
            if (foreachContext.expr() != null)
            {
                Array = parseInfo.GetExpression(scope, foreachContext.expr());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN()));
            }

            // Get the foreach block. Syntax error if it is missing.
            if (foreachContext.block() != null)
            {
                Block = new BlockAction(parseInfo.SetLoop(this), varScope, foreachContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN()));
            }
        }
        public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext)
        {
            Scope varScope = scope.Child();

            ForeachVar = new Var(foreachContext.name.Text, new Location(parseInfo.Script.Uri, DocRange.GetRange(foreachContext.name)), parseInfo);
            ForeachVar.VariableType = VariableType.ElementReference;
            ForeachVar.CodeType     = CodeType.GetCodeTypeFromContext(parseInfo, foreachContext.code_type());
            ForeachVar.Finalize(varScope);

            // Get the array that will be iterated on. Syntax error if it is missing.
            if (foreachContext.expr() != null)
            {
                Array = DeltinScript.GetExpression(parseInfo, scope, foreachContext.expr());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN()));
            }

            // Get the foreach block. Syntax error if it is missing.
            if (foreachContext.block() != null)
            {
                Block = new BlockAction(parseInfo, varScope, foreachContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN()));
            }
        }
        public ForAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForContext forContext)
        {
            Scope varScope = scope.Child();

            if (forContext.define() != null)
            {
                DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, forContext.define()));
            }
            else if (forContext.initialVarset != null)
            {
                InitialVarSet = new SetVariableAction(parseInfo, varScope, forContext.initialVarset);
            }

            if (forContext.expr() != null)
            {
                Condition = DeltinScript.GetExpression(parseInfo, varScope, forContext.expr());
            }

            if (forContext.endingVarset != null)
            {
                SetVariableAction = new SetVariableAction(parseInfo, varScope, forContext.endingVarset);
            }

            // Get the block.
            if (forContext.block() != null)
            {
                Block = new BlockAction(parseInfo.SetLoop(this), varScope, forContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(forContext.FOR()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected a block.", DocRange.GetRange(forContext.RIGHT_PAREN()));
            }
        }
        public void GetContent()
        {
            var parseInfo = _parseInfo
                            .SetReturnType(ReturnType)
                            .SetThisType(ContainingType)
                            .SetCallInfo(CallInfo);

            if (Context.Block != null)
            {
                var returnTracker = new ReturnTracker();
                Block = new BlockAction(parseInfo.SetReturnTracker(returnTracker), _methodScope, Context.Block);

                MultiplePaths = returnTracker.IsMultiplePaths;

                // If there is only one return statement, set SingleReturnValue.
                if (returnTracker.Returns.Count == 1)
                {
                    SingleReturnValue = returnTracker.Returns[0].ReturningValue;
                }
            }
            else if (Context.MacroValue != null)
            {
                MacroValue = SingleReturnValue = parseInfo.SetExpectType(ReturnType).GetExpression(_methodScope, Context.MacroValue);

                SemanticsHelper.ExpectValueType(parseInfo, MacroValue, ReturnType, Context.MacroValue.Range);
            }

            ContentReady.Set();
        }
 public SwitchSection(DocRange errorRange, bool isDefault, IExpression[] cases, IStatement[] statements)
 {
     ErrorRange = errorRange;
     IsDefault  = isDefault;
     Cases      = cases;
     Block      = new BlockAction(statements);
 }
 public override void SetupBlock()
 {
     if (context.block() != null)
     {
         block = new BlockAction(parseInfo.SetCallInfo(CallInfo), methodScope, context.block());
         ValidateReturns(parseInfo.Script, context);
     }
 }
 public void SetupBlock()
 {
     Block = new BlockAction(parseInfo.SetCallInfo(CallInfo), ConstructorScope, context.block());
     foreach (var listener in listeners)
     {
         listener.Applied();
     }
 }
Esempio n. 9
0
 public BlockTreeScan(ParseInfo parseInfo, BlockAction block, string objectName, DocRange genericErrorRange)
 {
     _parseInfo         = parseInfo;
     _objectName        = objectName;
     _genericErrorRange = genericErrorRange;
     Block        = block;
     Returns      = GetReturns();
     ReturnsValue = Returns.Any(r => r.ReturningValue != null);
 }
        public RuleAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Ow_ruleContext ruleContext)
        {
            Name     = Extras.RemoveQuotes(ruleContext.STRINGLITERAL().GetText());
            Disabled = ruleContext.DISABLED() != null;
            DocRange ruleInfoRange = DocRange.GetRange(ruleContext.RULE_WORD());

            missingBlockRange = ruleInfoRange;

            GetRuleSettings(parseInfo, scope, ruleContext);

            // Store restricted calls
            CallInfo callInfo = new CallInfo(parseInfo.Script);

            // Get the conditions.
            if (ruleContext.rule_if() == null)
            {
                Conditions = new RuleIfAction[0];
            }
            else
            {
                Conditions = new RuleIfAction[ruleContext.rule_if().Length];
                for (int i = 0; i < Conditions.Length; i++)
                {
                    parseInfo.Script.AddCompletionRange(new CompletionRange(
                                                            scope,
                                                            DocRange.GetRange(ruleContext.rule_if(i).LEFT_PAREN(), ruleContext.rule_if(i).RIGHT_PAREN()),
                                                            CompletionRangeKind.Catch
                                                            ));

                    Conditions[i]     = new RuleIfAction(parseInfo.SetCallInfo(callInfo), scope, ruleContext.rule_if(i));
                    missingBlockRange = DocRange.GetRange(ruleContext.rule_if(i));
                }
            }

            // Get the block.
            if (ruleContext.block() != null)
            {
                Block = new BlockAction(parseInfo.SetCallInfo(callInfo), scope, ruleContext.block());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Missing block.", missingBlockRange);
            }

            // Check restricted calls.
            callInfo.CheckRestrictedCalls(EventType);

            // Get the rule order priority.
            if (ruleContext.number() != null)
            {
                Priority = double.Parse(ruleContext.number().GetText());
            }

            ElementCountLens = new ElementCountCodeLens(ruleInfoRange, parseInfo.TranslateInfo.OptimizeOutput);
            parseInfo.Script.AddCodeLensRange(ElementCountLens);
        }
Esempio n. 11
0
        public void SetupBlock()
        {
            var parameterInfo = CodeParameter.GetParameters(parseInfo, ConstructorScope, context.setParameters());

            Parameters    = parameterInfo.Parameters;
            ParameterVars = parameterInfo.Variables;

            Block = new BlockAction(parseInfo.SetCallInfo(CallInfo), ConstructorScope, context.block());
            parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true));
        }
 // Sets up the method's block.
 public override void SetupBlock()
 {
     if (context.block() != null)
     {
         block = new BlockAction(parseInfo.SetCallInfo(CallInfo), methodScope, context.block());
         ValidateReturns();
     }
     foreach (var listener in listeners)
     {
         listener.Applied();
     }
 }
        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();
        }
        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);
        }
Esempio n. 15
0
        // Sets up the method's block.
        public override void SetupBlock()
        {
            if (context.block() != null)
            {
                block = new BlockAction(parseInfo.SetCallInfo(CallInfo), BlockScope, context.block());

                BlockTreeScan validation = new BlockTreeScan(doesReturnValue, parseInfo, this);
                validation.ValidateReturns();
                multiplePaths = validation.MultiplePaths;
            }
            foreach (var listener in listeners)
            {
                listener.Applied();
            }
        }
        public RuleAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Ow_ruleContext ruleContext)
        {
            Name               = Extras.RemoveQuotes(ruleContext.STRINGLITERAL().GetText());
            Disabled           = ruleContext.DISABLED() != null;
            _missingBlockRange = DocRange.GetRange(ruleContext.RULE_WORD());

            GetRuleSettings(parseInfo, scope, ruleContext);

            // Get the conditions.
            if (ruleContext.rule_if() == null)
            {
                Conditions = new RuleIfAction[0];
            }
            else
            {
                Conditions = new RuleIfAction[ruleContext.rule_if().Length];
                for (int i = 0; i < Conditions.Length; i++)
                {
                    parseInfo.Script.AddCompletionRange(new CompletionRange(
                                                            scope,
                                                            DocRange.GetRange(ruleContext.rule_if(i).LEFT_PAREN(), ruleContext.rule_if(i).RIGHT_PAREN()),
                                                            CompletionRangeKind.Catch
                                                            ));

                    Conditions[i]      = new RuleIfAction(parseInfo, scope, ruleContext.rule_if(i));
                    _missingBlockRange = DocRange.GetRange(ruleContext.rule_if(i));
                }
            }

            // Get the block.
            if (ruleContext.block() != null)
            {
                Block = new BlockAction(parseInfo, scope, ruleContext.block());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Missing block.", _missingBlockRange);
            }

            // Get the rule order priority.
            if (ruleContext.number() != null)
            {
                Priority = double.Parse(ruleContext.number().GetText());
            }
        }
        public ElseIf(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Else_ifContext elseIfContext)
        {
            if (elseIfContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(elseIfContext.LEFT_PAREN()));
            }
            else
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, elseIfContext.expr());
            }

            if (elseIfContext.block() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(elseIfContext.ELSE(), elseIfContext.IF()));
            }
            else
            {
                Block = new BlockAction(parseInfo, scope, elseIfContext.block());
            }
        }
 private static bool HasReturnStatement(BlockAction block)
 {
     foreach (var statement in block.Statements)
     {
         if (statement is ReturnAction)
         {
             return(true);
         }
         else if (statement is IBlockContainer)
         {
             foreach (var path in ((IBlockContainer)statement).GetPaths())
             {
                 if (HasReturnStatement(path.Block))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
        // Sets up the method's block.
        public override void SetupBlock()
        {
            if (Context.block() != null)
            {
                Block = new BlockAction(parseInfo.SetCallInfo(CallInfo), methodScope.Child(), Context.block());

                // Validate returns.
                BlockTreeScan validation = new BlockTreeScan(DoesReturnValue, parseInfo, this);
                validation.ValidateReturns();
                MultiplePaths = validation.MultiplePaths;

                // If there is only one return statement, set SingleReturnValue.
                if (validation.Returns.Length == 1)
                {
                    SingleReturnValue = validation.Returns[0].ReturningValue;
                }

                // If the return type is a constant type...
                if (ReturnType != null && ReturnType.IsConstant())
                {
                    // ... iterate through each return statement ...
                    foreach (ReturnAction returnAction in validation.Returns)
                    {
                        // ... If the current return statement returns a value and that value does not implement the return type ...
                        if (returnAction.ReturningValue != null && (returnAction.ReturningValue.Type() == null || !returnAction.ReturningValue.Type().Implements(ReturnType)))
                        {
                            // ... then add a syntax error.
                            parseInfo.Script.Diagnostics.Error("Must return a value of type '" + ReturnType.GetName() + "'.", returnAction.ErrorRange);
                        }
                    }
                }
            }
            WasApplied = true;
            foreach (var listener in listeners)
            {
                listener.Applied();
            }
        }
Esempio n. 20
0
        public IfAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.IfContext ifContext)
        {
            // Get the if condition.
            if (ifContext.expr() != null)
            {
                Expression = parseInfo.GetExpression(scope, ifContext.expr());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(ifContext.LEFT_PAREN()));
            }

            // Contains the path info of all blocks in the if/else-if/else list.
            var paths = new List <PathInfo>();

            // Get the if's block.
            if (ifContext.block() != null)
            {
                Block = new BlockAction(parseInfo, scope, ifContext.block());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(ifContext.IF()));
            }

            // Add the if block path info.
            paths.Add(new PathInfo(Block, DocRange.GetRange(ifContext.IF()), false));

            // Get the else-ifs.
            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));
                }
            }
            // If there is none, set `ElseIfs` to an empty array since it should not be null.
            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();
        }
Esempio n. 21
0
 public PathInfo(BlockAction block, DocRange errorRange, bool willRun)
 {
     Block      = block;
     ErrorRange = errorRange;
     WillRun    = willRun;
 }
Esempio n. 22
0
        public AutoForAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.For_autoContext autoForContext)
        {
            RawContinue = true;

            // Get the auto-for variable. (Required)
            if (autoForContext.forVariable != null)
            {
                IExpression variable = parseInfo.GetExpression(scope, autoForContext.forVariable);

                // Get the variable being set.
                VariableResolve = new VariableResolve(new VariableResolveOptions()
                {
                    // The for cannot be indexed and should be on the rule-level.
                    CanBeIndexed = false,
                    FullVariable = true
                }, variable, DocRange.GetRange(autoForContext.forVariable), parseInfo.Script.Diagnostics);

                if (autoForContext.EQUALS() != null)
                {
                    if (autoForContext.start == null)
                    {
                        parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(autoForContext.EQUALS()));
                    }
                    else
                    {
                        InitialResolveValue = parseInfo.GetExpression(scope, autoForContext.start);
                    }
                }
            }
            // Get the defined variable.
            else if (autoForContext.forDefine != null)
            {
                DefinedVariable = new AutoForVariable(scope, new DefineContextHandler(parseInfo, autoForContext.forDefine));
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected define or variable.", DocRange.GetRange(autoForContext.FOR()));
            }

            // Get the auto-for end. (Required)
            if (autoForContext.stop == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected end expression.", DocRange.GetRange(autoForContext.startSep));
            }
            else
            {
                Stop = parseInfo.GetExpression(scope, autoForContext.stop);
            }

            // Get the auto-for step. (Not Required)
            if (autoForContext.step == null)
            {
                Step = new ExpressionOrWorkshopValue(new V_Number(1));
            }
            else
            {
                Step = new ExpressionOrWorkshopValue(parseInfo.GetExpression(scope, autoForContext.step));
            }

            // Get the block.
            if (autoForContext.block() == null)
            {
                parseInfo.Script.Diagnostics.Error("Missing block.", DocRange.GetRange(autoForContext.RIGHT_PAREN()));
            }
            else
            {
                Block = new BlockAction(parseInfo.SetLoop(this), scope, autoForContext.block());
                Path  = new PathInfo(Block, DocRange.GetRange(autoForContext.block()), false);
            }
        }