public override object VisitCatchClause(CatchClause catchClause, object data) { catchClause.Condition.Parent = catchClause; catchClause.StatementBlock.Parent = catchClause; catchClause.TypeReference.Parent = catchClause; return base.VisitCatchClause(catchClause, data); }
public sealed override object VisitCatchClause(CatchClause catchClause, object data) { this.BeginVisit(catchClause); object result = this.TrackedVisitCatchClause(catchClause, data); this.EndVisit(catchClause); return result; }
public virtual object VisitCatchClause(CatchClause catchClause, object data) { throw new global::System.NotImplementedException("CatchClause"); }
IEnumerable<Ast.INode> TransformNode(Node node) { if (Options.NodeComments) { yield return MakeComment("// " + node.Description); } yield return new Ast.LabelStatement(node.Label); if (node is BasicBlock) { foreach(ILNode expr in ((BasicBlock)node).Body) { if (expr is ILLabel) { yield return new Ast.LabelStatement(((ILLabel)expr).Name); } else { Statement stmt = TransformExpressionToStatement((ILExpression)expr); if (stmt != null) { yield return stmt; } } } foreach(Ast.INode inode in TransformNodes(node.Childs)) { yield return inode; } Node fallThroughNode = ((BasicBlock)node).FallThroughBasicBlock; // If there is default branch and it is not the following node if (fallThroughNode != null) { yield return new Ast.GotoStatement(fallThroughNode.Label); } } else if (node is AcyclicGraph) { foreach(Ast.INode inode in TransformNodes(node.Childs)) { yield return inode; } } else if (node is Loop) { Ast.BlockStatement blockStatement = new Ast.BlockStatement(); blockStatement.Children.AddRange(TransformNodes(node.Childs)); yield return new Ast.ForStatement( null, null, null, blockStatement ); } else if (node is Block) { foreach(Ast.INode inode in TransformNodes(node.Childs)) { yield return inode; } } else if (node is Branch) { yield return new Ast.LabelStatement(((Branch)node).FirstBasicBlock.Label); Ast.BlockStatement trueBlock = new Ast.BlockStatement(); trueBlock.Children.Add(new Ast.GotoStatement(((Branch)node).TrueSuccessor.Label)); Ast.BlockStatement falseBlock = new Ast.BlockStatement(); falseBlock.Children.Add(new Ast.GotoStatement(((Branch)node).FalseSuccessor.Label)); Ast.IfElseStatement ifElseStmt = new Ast.IfElseStatement( MakeBranchCondition((Branch)node), trueBlock, falseBlock ); trueBlock.Parent = ifElseStmt; falseBlock.Parent = ifElseStmt; yield return ifElseStmt; } else if (node is ConditionalNode) { ConditionalNode conditionalNode = (ConditionalNode)node; yield return new Ast.LabelStatement(conditionalNode.Condition.FirstBasicBlock.Label); Ast.BlockStatement trueBlock = new Ast.BlockStatement(); // The block entry code trueBlock.Children.Add(new Ast.GotoStatement(conditionalNode.Condition.TrueSuccessor.Label)); // Sugested content trueBlock.Children.AddRange(TransformNode(conditionalNode.TrueBody)); Ast.BlockStatement falseBlock = new Ast.BlockStatement(); // The block entry code falseBlock.Children.Add(new Ast.GotoStatement(conditionalNode.Condition.FalseSuccessor.Label)); // Sugested content falseBlock.Children.AddRange(TransformNode(conditionalNode.FalseBody)); Ast.IfElseStatement ifElseStmt = new Ast.IfElseStatement( // Method bodies are swapped new Ast.UnaryOperatorExpression( new Ast.ParenthesizedExpression( MakeBranchCondition(conditionalNode.Condition) ), UnaryOperatorType.Not ), falseBlock, trueBlock ); trueBlock.Parent = ifElseStmt; falseBlock.Parent = ifElseStmt; yield return ifElseStmt; } else if (node is TryCatchNode) { TryCatchNode tryCachNode = ((TryCatchNode)node); Ast.BlockStatement tryBlock = new Ast.BlockStatement(); tryBlock.Children.AddRange(TransformNode(tryCachNode.Childs[0])); Ast.BlockStatement finallyBlock = null; if (tryCachNode.Childs[1].Childs.Count > 0) { finallyBlock = new Ast.BlockStatement(); finallyBlock.Children.AddRange(TransformNode(tryCachNode.Childs[1])); } List<Ast.CatchClause> ccs = new List<CatchClause>(); for (int i = 0; i < tryCachNode.Types.Count; i++) { Ast.BlockStatement catchBlock = new Ast.BlockStatement(); catchBlock.Children.AddRange(TransformNode(tryCachNode.Childs[i + 2])); Ast.CatchClause cc = new Ast.CatchClause( new Ast.TypeReference(tryCachNode.Types[i].FullName), "exception", catchBlock ); ccs.Add(cc); } Ast.TryCatchStatement tryCachStmt = new Ast.TryCatchStatement(tryBlock, ccs, finallyBlock); yield return tryCachStmt; } else { throw new Exception("Bad node type"); } if (Options.NodeComments) { yield return MakeComment(""); } }
void CatchClause( #line 1746 "cs.ATG" out CatchClause catchClause) { Expect(56); #line 1748 "cs.ATG" string identifier; BlockStatement stmt; TypeReference typeRef; Location startPos = t.Location; catchClause = null; if (la.kind == 16) { Block( #line 1756 "cs.ATG" out stmt); #line 1756 "cs.ATG" catchClause = new CatchClause(stmt); } else if (la.kind == 20) { lexer.NextToken(); ClassType( #line 1759 "cs.ATG" out typeRef, false); #line 1759 "cs.ATG" identifier = null; if (StartOf(18)) { Identifier(); #line 1760 "cs.ATG" identifier = t.val; } Expect(21); Block( #line 1761 "cs.ATG" out stmt); #line 1762 "cs.ATG" catchClause = new CatchClause(typeRef, identifier, stmt); } else SynErr(206); #line 1765 "cs.ATG" if (catchClause != null) { catchClause.StartLocation = startPos; catchClause.EndLocation = t.Location; } }
public virtual object VisitCatchClause(CatchClause catchClause, object data) { throw CreateException(catchClause); }
public virtual object VisitCatchClause(CatchClause catchClause, object data) { Debug.Assert((catchClause != null)); Debug.Assert((catchClause.TypeReference != null)); Debug.Assert((catchClause.StatementBlock != null)); Debug.Assert((catchClause.Condition != null)); nodeStack.Push(catchClause.TypeReference); catchClause.TypeReference.AcceptVisitor(this, data); catchClause.TypeReference = ((TypeReference)(nodeStack.Pop())); nodeStack.Push(catchClause.StatementBlock); catchClause.StatementBlock.AcceptVisitor(this, data); catchClause.StatementBlock = ((Statement)(nodeStack.Pop())); nodeStack.Push(catchClause.Condition); catchClause.Condition.AcceptVisitor(this, data); catchClause.Condition = ((Expression)(nodeStack.Pop())); return null; }
private bool LinqVersion(CatchClause catchClause) { List<INode> children = catchClause.StatementBlock.Children; var z = from c in children.OfType<LocalVariableDeclaration>() from l in c.Variables where c.TypeReference.Type == "System.String" && l.Initializer is InvocationExpression let initializer = (InvocationExpression) l.Initializer where initializer.TargetObject is MemberReferenceExpression let mre = (MemberReferenceExpression) initializer.TargetObject where mre.MemberName == "ToString" && mre.TargetObject is IdentifierExpression let ie = (IdentifierExpression) mre.TargetObject where ie.Identifier == catchClause.VariableName let next_child = children.IndexOf(c) + 1 where next_child >= children.Count || IsNotUsedInAnyRemainingStatements(ie, children.GetRange(next_child, children.Count - next_child)) select c; return z.Any(); }
public object VisitCatchClause(CatchClause catchClause, object data) { throw new NotImplementedException (); }
public virtual bool VisitCatchClause(CatchClause catchClause, object d) { if ((catchClause == null)) { return SetFailure(); } if ((d == null)) { return SetFailure(); } if ((catchClause.TypeReference == null)) { return SetFailure(); } if ((catchClause.StatementBlock == null)) { return SetFailure(); } if ((catchClause.Condition == null)) { return SetFailure(); } if(catchClause.GetType() != d.GetType()) {return SetFailure();} var data = (CatchClause)d; if (!IsMatch(catchClause, data)) { return SetFailure(); } catchClause.TypeReference.AcceptVisitor(this, data.TypeReference); catchClause.StatementBlock.AcceptVisitor(this, data.StatementBlock); return catchClause.Condition.AcceptVisitor(this, data.Condition); }
public override object VisitCatchClause(CatchClause catchClause, object data) { return base.VisitCatchClause(catchClause, data); }
private bool IsMatch(CatchClause left, CatchClause right) { return left.VariableName == right.VariableName; }
public object VisitCatchClause(CatchClause catchClause, object data) { throw new ApplicationException("CatchClause visited."); }
private bool NonLinqVersion(CatchClause catchClause) { List<INode> children = catchClause.StatementBlock.Children; if (children.Count <= 0) { return false; } LocalVariableDeclaration lvd = children[0] as LocalVariableDeclaration; if (lvd == null || lvd.TypeReference.Type != "System.String") { return false; } InvocationExpression initializer = lvd.Variables[0].Initializer as InvocationExpression; if (initializer == null) { return false; } MemberReferenceExpression mre = initializer.TargetObject as MemberReferenceExpression; if (mre == null) { return false; } if (mre.MemberName != "ToString") { return false; } IdentifierExpression ie = mre.TargetObject as IdentifierExpression; if (ie == null || ie.Identifier != catchClause.VariableName) { return false; } // ToString is being called on the exception return children.Count == 1 || IsNotUsedInAnyRemainingStatements(ie, children.GetRange(1, children.Count - 1)); }
public virtual object TrackedVisitCatchClause(CatchClause catchClause, object data) { return base.VisitCatchClause(catchClause, data); }
public virtual object VisitCatchClause(CatchClause catchClause, object data) { Debug.Assert((catchClause != null)); Debug.Assert((catchClause.TypeReference != null)); Debug.Assert((catchClause.StatementBlock != null)); Debug.Assert((catchClause.Condition != null)); catchClause.TypeReference.AcceptVisitor(this, data); catchClause.StatementBlock.AcceptVisitor(this, data); return catchClause.Condition.AcceptVisitor(this, data); }
public override object TrackedVisitCatchClause(CatchClause catchClause, object data) { Console.WriteLine("VisitCatchClause"); return null; }
public override object VisitCatchClause(CatchClause catchClause, object data) { bool found = NonLinqVersion(catchClause); // bool found = LinqVersion(catchClause); if (found) Found++; return base.VisitCatchClause(catchClause, data); }