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);
        }
Example #2
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);
        }
        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();
        }
Example #4
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();
        }