public override bool Walk(TryStatement node) { _statements.Add(node); return base.Walk(node); }
//try_stmt: ('try' ':' suite (except_clause ':' suite)+ // ['else' ':' suite] | 'try' ':' suite 'finally' ':' suite) //# NB compile.c makes sure that the default except clause is last // J 2.5 grammar //try_stmt: 'try' ':' suite // ( // (except_clause ':' suite)+ // ['else' ':' suite] // ['finally' ':' suite] // | // 'finally' : suite // ) private Statement ParseTryStatement() { Eat(TokenKind.KeywordTry); string tryWhiteSpace = _tokenWhiteSpace; var start = GetStart(); var mid = GetEnd(); Statement body = ParseSuite(); Statement finallySuite = null; Statement elseSuite = null; Statement ret; int end; string finallyWhiteSpace = null, elseWhiteSpace = null; if (MaybeEat(TokenKind.KeywordFinally)) { finallyWhiteSpace = _tokenWhiteSpace; finallySuite = ParseFinallySuite(finallySuite); end = finallySuite.EndIndex; TryStatement tfs = new TryStatement(body, null, elseSuite, finallySuite); tfs.HeaderIndex = mid; ret = tfs; } else { List<TryStatementHandler> handlers = new List<TryStatementHandler>(); TryStatementHandler dh = null; end = GetEnd(); while (true) { if (!MaybeEat(TokenKind.KeywordExcept)) { break; } TryStatementHandler handler = ParseTryStmtHandler(); end = handler.EndIndex; handlers.Add(handler); if (dh != null) { ReportSyntaxError(dh.StartIndex, dh.HeaderIndex, "default 'except' must be last"); } if (handler.Test == null) { dh = handler; } } if (MaybeEat(TokenKind.KeywordElse)) { elseWhiteSpace = _tokenWhiteSpace; elseSuite = ParseSuite(); end = elseSuite.EndIndex; } if (MaybeEat(TokenKind.KeywordFinally)) { // If this function has an except block, then it can set the current exception. finallyWhiteSpace = _tokenWhiteSpace; finallySuite = ParseFinallySuite(finallySuite); end = finallySuite.EndIndex; } TryStatement ts = new TryStatement(body, handlers.ToArray(), elseSuite, finallySuite); ts.HeaderIndex = mid; ret = ts; } if (_verbatim) { AddPreceedingWhiteSpace(ret, tryWhiteSpace); if (elseWhiteSpace != null) { AddSecondPreceedingWhiteSpace(ret, elseWhiteSpace); } if (finallyWhiteSpace != null) { AddThirdPreceedingWhiteSpace(ret, finallyWhiteSpace); } } ret.SetLoc(start, end); return ret; }
// TryStmt public override bool Walk(TryStatement node) { BitArray save = _bits; _bits = new BitArray(_bits); // Flow the body node.Body.Walk(this); if (node.Else != null) { // Else is flown only after completion of Try with same bits node.Else.Walk(this); } if (node.Handlers != null) { foreach (TryStatementHandler tsh in node.Handlers) { // Restore to saved state _bits.SetAll(false); _bits.Or(save); // Flow the test if (tsh.Test != null) { tsh.Test.Walk(this); } // Define the target if (tsh.Target != null) { tsh.Target.Walk(_fdef); } // Flow the body tsh.Body.Walk(this); } } _bits = save; if (node.Finally != null) { // Flow finally - this executes no matter what node.Finally.Walk(this); } return false; }
public override bool Walk(TryStatement node) { UpdateChildRanges(node); return base.Walk(node); }
// TryStatement public override bool Walk(TryStatement node) { return ShouldWalkWorker(node); }
public override void PostWalk(TryStatement node) { PostWalkWorker(node); }
public override bool Walk(TryStatement node) { node.Body.Walk(this); if (node.Handlers != null && node.Handlers.Count > 0) { // treat any exceptions from the body as handled, any exceptions // from the handlers/else are not handled. _raises = false; foreach (var handler in node.Handlers) { handler.Walk(this); } } if (node.Finally != null) { node.Finally.Walk(this); } if (node.Else != null) { node.Else.Walk(this); } return false; }