コード例 #1
0
ファイル: SemanticAnalyser.cs プロジェクト: kostic017/pigeon
 public override void ExitStmtBlock([NotNull] PigeonParser.StmtBlockContext context)
 {
     if (ShouldCreateScope(context))
     {
         scope = scope.Parent;
     }
 }
コード例 #2
0
ファイル: SemanticAnalyser.cs プロジェクト: kostic017/pigeon
 public override void EnterStmtBlock([NotNull] PigeonParser.StmtBlockContext context)
 {
     if (ShouldCreateScope(context))
     {
         scope = new Scope(scope);
     }
 }
コード例 #3
0
 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);
 }
コード例 #4
0
ファイル: SemanticAnalyser.cs プロジェクト: kostic017/pigeon
 private bool ShouldCreateScope(PigeonParser.StmtBlockContext context)
 {
     if (
         context.Parent is PigeonParser.FunctionDeclContext ||
         context.Parent is PigeonParser.ForStatementContext
         )
     {
         return(false);
     }
     return(true);
 }