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(); }
/* * /// <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; }
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"); }
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); }
/// <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) { }
/// <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)); }