public virtual Statement VisitTry(Try Try)
 {
     if (Try == null) return null;
     Try.TryBlock = this.VisitBlock(Try.TryBlock);
     Try.Catchers = this.VisitCatchList(Try.Catchers);
     Try.Filters = this.VisitFilterList(Try.Filters);
     Try.FaultHandlers = this.VisitFaultHandlerList(Try.FaultHandlers);
     Try.Finally = (Finally)this.VisitFinally(Try.Finally);
     return Try;
 }
Beispiel #2
0
 public override Statement VisitTry(Try Try)
 {
     if (Try == null) return null;
     return base.VisitTry((Try)Try.Clone());
 }
Beispiel #3
0
 private Try ParseTry(TokenSet followers){
   object catchContext = null;
   object finallyContext = null;
   bool savedUnmatchedTry = this.unmatchedTry;
   Try Try = new Try();
   Try.SourceContext = this.scanner.CurrentSourceContext;
   Debug.Assert(this.currentToken == Token.Try || this.currentToken == Token.Catch || this.currentToken == Token.Finally);
   TokenSet tryBlockFollowers = followers|Parser.CatchOrFinally;
   if (this.currentToken == Token.Try){
     this.unmatchedTry = true;
     this.GetNextToken();
     if (this.currentToken == Token.LeftBrace)
       Try.TryBlock = this.ParseBlock(tryBlockFollowers);
     else{
       this.HandleError(Error.ExpectedLeftBrace);
       if (Parser.StatementStart[this.currentToken]){
         Block block = new Block();
         block.Checked = this.insideCheckedBlock;
         block.IsUnsafe = this.inUnsafeCode;
         block.SuppressCheck = this.insideUncheckedBlock;
         SourceContext ctx = this.scanner.CurrentSourceContext;
         block.SourceContext = this.scanner.CurrentSourceContext;
         block.Statements = this.ParseStatements(tryBlockFollowers|Token.RightBrace);
         block.SourceContext.EndPos = this.scanner.CurrentSourceContext.StartPos;
         Try.TryBlock = block;
         this.Skip(Token.RightBrace);
       }
     }
   }else{
     if (savedUnmatchedTry && ((this.currentToken == Token.Catch && followers[Token.Catch]) || (this.currentToken == Token.Finally && followers[Token.Finally])))
       return null;
     else
       this.HandleError(Error.SyntaxError, "try");
   }
   CatchList catchers = new CatchList();
   bool seenEmptyCatch = false;
   while (this.currentToken == Token.Catch){
     if (seenEmptyCatch) this.HandleError(Error.TooManyCatches);
     catchContext = this.scanner.CurrentSourceContext;
     Catch c = this.ParseCatch(tryBlockFollowers);
     if (c == null) continue;
     if (c.TypeExpression == null) seenEmptyCatch = true;
     catchers.Add(c);
   }
   Try.Catchers = catchers;
   if (this.currentToken == Token.Finally){
     finallyContext = this.scanner.CurrentSourceContext;
     this.GetNextToken();
     Try.Finally = new Finally(this.ParseBlock(followers));
   }else if (catchers.Count == 0)
     this.SkipTo(followers, Error.ExpectedEndTry);
   if (this.sink != null){
     if (finallyContext != null)
       if (catchContext != null)
         this.sink.MatchTriple(Try.SourceContext, (SourceContext)catchContext, (SourceContext)finallyContext);
       else
         this.sink.MatchPair(Try.SourceContext, (SourceContext)finallyContext);
     else if (catchContext != null)
       this.sink.MatchPair(Try.SourceContext, (SourceContext)catchContext);
   }
   this.unmatchedTry = savedUnmatchedTry;
   return Try;
 }
Beispiel #4
0
 private void ParseDestructor(TypeNode parentType, AttributeList attributes, TokenList modifierTokens,
   SourceContextList modifierContexts, object sctx, TokenSet followers){
   Method meth = new Method(parentType, attributes, new Identifier("Finalize"), null, this.TypeExpressionFor(Token.Void), null);
   meth.OverridesBaseClassMember = !this.TypeIsSystemObject(parentType);
   meth.Documentation = this.LastDocComment;
   meth.Flags = this.GetDestructorFlags(modifierTokens, modifierContexts, meth);
   meth.CallingConvention = CallingConventionFlags.HasThis;
   Debug.Assert(this.currentToken == Token.BitwiseNot);
   this.GetNextToken();
   if (!(parentType is Class))
     this.HandleError(Error.OnlyClassesCanContainDestructors);
   else
     parentType.Members.Add(meth);
   Identifier id = this.scanner.GetIdentifier();
   meth.Name.SourceContext = id.SourceContext;
   this.SkipIdentifierOrNonReservedKeyword();
   if (id.UniqueIdKey != parentType.Name.UniqueIdKey)
     this.HandleError(Error.WrongNameForDestructor);
   ParameterList pars = this.ParseParameters(Token.RightParenthesis, followers|Token.LeftBrace);
   if (pars != null && pars.Count > 0 && pars[0] != null)
     this.HandleError(pars[0].SourceContext, Error.ExpectedRightParenthesis);
   Block b = this.ParseBody(meth, sctx, followers);
   if (b != null && !this.TypeIsSystemObject(parentType)) {
     StatementList stats = new StatementList(1);
     stats.Add(new ExpressionStatement(new MethodCall(new QualifiedIdentifier(new Base(), StandardIds.Finalize), null)));
     Try t = new Try(b, null, null, null, new Finally(new Block(stats, this.insideCheckedBlock, this.insideUncheckedBlock, this.inUnsafeCode)));
     stats = new StatementList(1);
     stats.Add(t);
     meth.Body = new Block(stats, this.insideCheckedBlock, this.insideUncheckedBlock, this.inUnsafeCode);
   } else
     meth.Body = b;
 }
Beispiel #5
0
        public override Statement VisitTry(Try Try)
        {
            WriteLine("try");
            this.VisitBlock(Try.TryBlock);

            if (Try.Catchers != null)
            {
                for (int i = 0, n = Try.Catchers.Count; i < n; i++)
                    this.VisitCatch(Try.Catchers[i]);
            }
            if (Try.Filters != null)
            {
                for (int i = 0, n = Try.Filters.Count; i < n; i++)
                    this.VisitFilter(Try.Filters[i]);
            }
            if (Try.FaultHandlers != null)
            {
                for (int i = 0, n = Try.FaultHandlers.Count; i < n; i++)
                    this.VisitFaultHandler(Try.FaultHandlers[i]);
            }
            this.VisitFinally(Try.Finally);

            return Try;
        }
 public EventingVisitor(Action<Try> visitTry) { VisitedTry += visitTry; } public event Action<Try> VisitedTry; public override Statement VisitTry(Try Try) { if (VisitedTry != null) VisitedTry(Try); return base.VisitTry(Try); }