public void EnterCodeScopeDuringPrePass(LSLParser.CodeScopeContext context)
 {
     _scopeTypeStack.Push(LSLAntlrTreeTools.ResolveCodeScopeNodeType(context));
     _singleStatementScopeTrackingStack.Push(false);
     _scopeStack.Push(context);
     _labelScopes.Add(context, new Dictionary <string, LSLLabelStatementNode>());
 }
 public void EnterCodeScopeAfterPrePass(LSLParser.CodeScopeContext context)
 {
     _scopeTypeStack.Push(LSLAntlrTreeTools.ResolveCodeScopeNodeType(context));
     _singleStatementScopeTrackingStack.Push(false);
     _scopeStack.Push(context);
     EnterLocalVariableScope();
 }
예제 #3
0
        /*
         * /// <summary>
         * ///     Clone this <see cref="LSLCodeScopeNode" /> from another.
         * /// </summary>
         * /// <param name="other">The other node.</param>
         * private LSLCodeScopeNode(LSLCodeScopeNode other)
         * {
         *  SourceRangesAvailable = other.SourceRangesAvailable;
         *
         *  if (SourceRangesAvailable)
         *  {
         *      SourceRange = other.SourceRange;
         *  }
         *
         *  foreach (var child in other._codeStatements)
         *  {
         *      AddCodeStatement(child.Clone());
         *  }
         *
         *  HasErrors = other.HasErrors;
         * }*/


        /// <exception cref="ArgumentNullException"><paramref name="context" /> is <c>null</c>.</exception>
        internal LSLCodeScopeNode(LSLParser.CodeScopeContext context, int scopeId)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ScopeId = scopeId;

            SourceRange = new LSLSourceCodeRange(context);

            SourceRangesAvailable = true;
        }
예제 #4
0
        public static LSLCodeScopeType ResolveCodeScopeNodeType(LSLParser.CodeScopeContext context)
        {
            if (context.Parent is LSLParser.FunctionDeclarationContext)
            {
                return(LSLCodeScopeType.Function);
            }
            if (context.Parent is LSLParser.EventHandlerContext)
            {
                return(LSLCodeScopeType.EventHandler);
            }


            if (context.Parent.Parent is LSLParser.ControlStructureContext)
            {
                if (context.Parent.Parent.Parent.Parent is LSLParser.ElseStatementContext)
                {
                    return(LSLCodeScopeType.ElseIf);
                }
                return(LSLCodeScopeType.If);
            }
            if (context.Parent.Parent is LSLParser.ElseStatementContext)
            {
                return(LSLCodeScopeType.Else);
            }
            if (context.Parent.Parent is LSLParser.DoLoopContext)
            {
                return(LSLCodeScopeType.DoLoop);
            }
            if (context.Parent.Parent is LSLParser.WhileLoopContext)
            {
                return(LSLCodeScopeType.WhileLoop);
            }
            if (context.Parent.Parent is LSLParser.ForLoopContext)
            {
                return(LSLCodeScopeType.ForLoop);
            }
            if (context.Parent.Parent is LSLParser.CodeScopeContext)
            {
                return(LSLCodeScopeType.AnonymousBlock);
            }

            //bugcheck assert
            throw new InvalidOperationException(
                      "BUGCHECK: Unexpected ANTLR syntax tree structure in " + typeof(LSLAntlrTreeTools).FullName +
                      ".ResolveCodeScopeNodeType");
        }
예제 #5
0
        public override bool VisitCodeScope(LSLParser.CodeScopeContext context)
        {
            if (context == null || context.children == null)
            {
                throw LSLCodeValidatorInternalException.VisitContextInvalidState("VisitCodeScope", true);
            }

            _scopingManager.EnterCodeScopeDuringPrePass(context);
            _currentScopeId++;
            _statementIndexStack.Push(new StatementIndexContainer {
                Index = 0, ScopeId = _currentScopeId
            });

            var result = base.VisitCodeScope(context);

            _statementIndexStack.Pop();
            _scopingManager.ExitCodeScopeDuringPrePass();

            return(result);
        }
예제 #6
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="LSLParser.codeScope"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitCodeScope([NotNull] LSLParser.CodeScopeContext context)
 {
 }
예제 #7
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="LSLParser.codeScope"/>.
 /// <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 VisitCodeScope([NotNull] LSLParser.CodeScopeContext context)
 {
     return(VisitChildren(context));
 }