コード例 #1
0
        public IfAction(ParseInfo parseInfo, Scope scope, If ifContext)
        {
            // Get the if condition.
            Expression = parseInfo.GetExpression(scope, ifContext.Expression);

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

            // Get the if's block.
            Block = parseInfo.GetStatement(scope, ifContext.Statement);

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

            // Get the else-ifs.
            ElseIfs = new ElseIfAction[ifContext.ElseIfs.Count];
            for (int i = 0; i < ElseIfs.Length; i++)
            {
                ElseIfs[i] = new ElseIfAction(parseInfo, scope, ifContext.ElseIfs[i]);
                paths.Add(new PathInfo(Block, ifContext.Range, false));
            }

            // If there is an else statement, get the else block.
            if (ifContext.Else != null)
            {
                ElseBlock = parseInfo.GetStatement(scope, ifContext.Else.Statement);

                // Add the else path info.
                paths.Add(new PathInfo(ElseBlock, ifContext.Range, true));
            }
            Paths = paths.ToArray();
        }
コード例 #2
0
        public ElseIfAction(ParseInfo parseInfo, Scope scope, ElseIf elseIfContext)
        {
            // Get the else-if's expression.
            Expression = parseInfo.GetExpression(scope, elseIfContext.Expression);

            // Get the else-if's block.
            Block = parseInfo.GetStatement(scope, elseIfContext.Statement);
        }
コード例 #3
0
        public ElseIfAction(ParseInfo parseInfo, Scope scope, ElseIf elseIfContext)
        {
            // Get the else-if's expression.
            Expression = parseInfo.GetExpression(scope, elseIfContext.Expression);

            TypeComparison.ExpectNonConstant(parseInfo, elseIfContext.Expression.Range, Expression.Type());

            // Get the else-if's block.
            Block = parseInfo.GetStatement(scope, elseIfContext.Statement);
        }
コード例 #4
0
        private SwitchElement[] ResolveElements(ParseInfo parseInfo, Scope scope, Switch switchContext)
        {
            List <SwitchElement> elements = new List <SwitchElement>();
            bool inSection  = false;
            bool caseError  = false;
            bool gotDefault = false;

            // Resolve paths.
            foreach (var statement in switchContext.Statements)
            {
                var switchCase = statement as SwitchCase;

                // Syntax error if there is a statement before a case.
                if (switchCase == null && !inSection && !caseError)
                {
                    parseInfo.Script.Diagnostics.Error("Expected case or default.", statement.Range);
                    caseError = true;
                }

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

                // Default case.
                if (switchCase != null && switchCase.IsDefault)
                {
                    if (gotDefault)
                    {
                        parseInfo.Script.Diagnostics.Error("Switch cannot have multiple defaults.", switchCase.Range);
                    }
                    gotDefault = true;
                }

                // Get the statement
                if (switchCase == null)
                {
                    elements.Add(new SwitchElement(parseInfo.GetStatement(scope, statement)));
                }
                // Get the case
                else if (!switchCase.IsDefault)
                {
                    elements.Add(new SwitchElement(switchCase.Token.Range, parseInfo.GetExpression(scope, switchCase.Value)));
                }
                // Get default
                else
                {
                    elements.Add(new SwitchElement(switchCase.Token.Range));
                }
            }

            return(elements.ToArray());
        }
コード例 #5
0
        public BlockAction(ParseInfo parseInfo, Scope scope, Block blockContext)
        {
            BlockScope = scope.Child();

            Statements = new IStatement[blockContext.Statements.Count];
            for (int i = 0; i < Statements.Length; i++)
            {
                Statements[i] = parseInfo.GetStatement(BlockScope, blockContext.Statements[i]);
            }

            parseInfo.Script.AddCompletionRange(new CompletionRange(BlockScope, blockContext.Range, CompletionRangeKind.Catch));
        }
コード例 #6
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.documented_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.documented_statement() != null)
                {
                    elements.Add(new SwitchElement(parseInfo.GetStatement(scope, switchElement.documented_statement())));
                }
                // Get the case
                else if (switchElement.@case() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.@case().CASE()), parseInfo.GetExpression(scope, switchElement.@case().expr())));
                }
                // Get default
                else if (switchElement.DEFAULT() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.DEFAULT())));
                }
            }

            return(elements.ToArray());
        }
コード例 #7
0
        public BlockAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.S_blockContext blockContext)
        {
            BlockScope = scope.Child();

            if (blockContext.statement() == null)
            {
                Statements = new IStatement[0];
            }
            else
            {
                Statements = new IStatement[blockContext.statement().Length];
                for (int i = 0; i < Statements.Length; i++)
                {
                    Statements[i] = parseInfo.GetStatement(BlockScope, blockContext.statement(i));
                }
            }

            parseInfo.Script.AddCompletionRange(new CompletionRange(BlockScope, DocRange.GetRange(blockContext.BLOCK_START(), blockContext.BLOCK_END()), CompletionRangeKind.Catch));
        }