示例#1
0
        public override bool VisitCodeStatement(LSLParser.CodeStatementContext context)
        {
            if (context == null)
            {
                throw
                    LSLCodeValidatorInternalException.
                    VisitContextInvalidState("VisitCodeStatement",
                                             true);
            }

            if (LSLAntlrTreeTools.IsBracelessCodeScopeStatement(context))
            {
                _scopingManager.EnterSingleStatementScope(context);

                _currentScopeId++;
                _statementIndexStack.Push(new StatementIndexContainer {
                    Index = 0, ScopeId = _currentScopeId
                });
                base.VisitCodeStatement(context);
                _statementIndexStack.Pop();

                _scopingManager.ExitSingleStatementScope();
            }
            else
            {
                base.VisitCodeStatement(context);

                if (context.Parent is LSLParser.CodeScopeContext)
                {
                    _statementIndexStack.Peek().Index++;
                }
            }
            return(false);
        }
        /// <exception cref="ArgumentNullException"><paramref name="context" /> is <c>null</c>.</exception>
        internal LSLSemicolonStatement(LSLParser.CodeStatementContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            SourceRangesAvailable = true;

            SourceRange = new LSLSourceCodeRange(context);
        }
示例#3
0
        public static bool IsBracelessCodeScopeStatement(LSLParser.CodeStatementContext context)
        {
            //if the statement is a code scope who's parent is not another code scope then it cannot be
            //a brace-less code scope statement used with a do/while/for loop or if/else statement.

            //Control structures (if statement nodes) are excluded if their parent is an else statement.
            //because that constitutes an 'if else' statement combo that is possibly followed by a single statement,
            //or a code scope.

            return(context.code_scope == null &&
                   !(context.Parent is LSLParser.CodeScopeContext) &&
                   !(context.Parent is LSLParser.ElseStatementContext && context.control_structure != null));
        }
示例#4
0
        public static LSLCodeScopeType ResolveCodeScopeNodeType(LSLParser.CodeStatementContext context)
        {
            if (context.Parent is LSLParser.ControlStructureContext)
            {
                if (context.Parent.Parent.Parent is LSLParser.ElseStatementContext)
                {
                    //This is statement is after 'else if'
                    return(LSLCodeScopeType.ElseIf);
                }

                //This statement is after just 'if'
                return(LSLCodeScopeType.If);
            }
            if (context.Parent is LSLParser.ElseStatementContext)
            {
                return(LSLCodeScopeType.Else);
            }
            if (context.Parent is LSLParser.DoLoopContext)
            {
                return(LSLCodeScopeType.DoLoop);
            }
            if (context.Parent is LSLParser.WhileLoopContext)
            {
                return(LSLCodeScopeType.WhileLoop);
            }
            if (context.Parent is LSLParser.ForLoopContext)
            {
                return(LSLCodeScopeType.ForLoop);
            }

            var parent = context.Parent as LSLParser.CodeScopeContext;

            if (parent != null)
            {
                return(ResolveCodeScopeNodeType(parent));
            }

            //bugcheck assert
            throw new InvalidOperationException(
                      "BUGCHECK: Unexpected ANTLR syntax tree structure in " + typeof(LSLAntlrTreeTools).FullName +
                      ".ResolveCodeScopeNodeType");
        }
示例#5
0
        /// <exception cref="ArgumentNullException"><paramref name="context" /> or <paramref name="statement" /> is <c>null</c>.</exception>
        internal LSLCodeScopeNode(LSLParser.CodeStatementContext context, int scopeId, ILSLCodeStatement statement)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }

            AddStatement(statement);
            EndScope();

            ScopeId = scopeId;
            _isSingleStatementScope = true;

            SourceRange = new LSLSourceCodeRange(context);

            SourceRangesAvailable = true;
        }
 public void EnterSingleStatementScope(LSLParser.CodeStatementContext statement)
 {
     _scopeTypeStack.Push(LSLAntlrTreeTools.ResolveCodeScopeNodeType(statement));
     _singleStatementScopeTrackingStack.Push(true);
 }
示例#7
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="LSLParser.codeStatement"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitCodeStatement([NotNull] LSLParser.CodeStatementContext context)
 {
 }
示例#8
0
        internal LSLCodeStatementError(LSLParser.CodeStatementContext parserContext)
        {
            SourceRange = new LSLSourceCodeRange(parserContext);

            SourceRangesAvailable = true;
        }
示例#9
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="LSLParser.codeStatement"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitCodeStatement([NotNull] LSLParser.CodeStatementContext context)
 {
     return(VisitChildren(context));
 }