public override void ExitStmtBlock([NotNull] PigeonParser.StmtBlockContext context) { if (ShouldCreateScope(context)) { scope = scope.Parent; } }
public override void EnterStmtBlock([NotNull] PigeonParser.StmtBlockContext context) { if (ShouldCreateScope(context)) { scope = new Scope(scope); } }
public override object VisitStmtBlock([NotNull] PigeonParser.StmtBlockContext context) { if (ShouldCreateScope(context)) { functionScopes.Peek().EnterScope(); } try { foreach (var statement in context.stmt()) { var r = Visit(statement); if (statement is PigeonParser.ContinueStatementContext) { throw new ContinueLoopException(); } if (statement is PigeonParser.BreakStatementContext) { throw new BreakLoopException(); } if (statement is PigeonParser.ReturnStatementContext) { throw new FuncReturnValueException(r); } } } finally { if (ShouldCreateScope(context)) { functionScopes.Peek().ExitScope(); } } return(null); }
private bool ShouldCreateScope(PigeonParser.StmtBlockContext context) { if ( context.Parent is PigeonParser.FunctionDeclContext || context.Parent is PigeonParser.ForStatementContext ) { return(false); } return(true); }