From: Ted Kremenek Date: Mon, 6 Oct 2008 18:39:36 +0000 (+0000) Subject: Added PrintRawDeclStmt; use this method to print out DeclStmt instead of using PrintR... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ecd64c5e53012ab7b1fdc64094a24f83c9893581;p=clang Added PrintRawDeclStmt; use this method to print out DeclStmt instead of using PrintRawDecl (which falsely assumes DeclStmts have only one Decl). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57191 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index e95b8c8409..844a3e8560 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -50,6 +50,7 @@ namespace { void PrintRawCompoundStmt(CompoundStmt *S); void PrintRawDecl(Decl *D); + void PrintRawDeclStmt(DeclStmt *S); void PrintRawIfStmt(IfStmt *If); void PrintExpr(Expr *E) { @@ -144,15 +145,28 @@ void StmtPrinter::PrintRawDecl(Decl *D) { } } +void StmtPrinter::PrintRawDeclStmt(DeclStmt *S) { + bool isFirst = false; + + for (DeclStmt::decl_iterator I = S->decl_begin(), E = S->decl_end(); + I != E; ++I) { + + if (!isFirst) OS << ", "; + else isFirst = false; + + PrintRawDecl(*I); + } +} void StmtPrinter::VisitNullStmt(NullStmt *Node) { Indent() << ";\n"; } void StmtPrinter::VisitDeclStmt(DeclStmt *Node) { - for (ScopedDecl *D = Node->getDecl(); D; D = D->getNextDeclarator()) { + for (DeclStmt::decl_iterator I = Node->decl_begin(), E = Node->decl_end(); + I!=E; ++I) { Indent(); - PrintRawDecl(D); + PrintRawDecl(*I); OS << ";\n"; } } @@ -268,7 +282,7 @@ void StmtPrinter::VisitForStmt(ForStmt *Node) { Indent() << "for ("; if (Node->getInit()) { if (DeclStmt *DS = dyn_cast(Node->getInit())) - PrintRawDecl(DS->getDecl()); + PrintRawDeclStmt(DS); else PrintExpr(cast(Node->getInit())); } @@ -296,7 +310,7 @@ void StmtPrinter::VisitForStmt(ForStmt *Node) { void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) { Indent() << "for ("; if (DeclStmt *DS = dyn_cast(Node->getElement())) - PrintRawDecl(DS->getDecl()); + PrintRawDeclStmt(DS); else PrintExpr(cast(Node->getElement())); OS << " in "; @@ -418,7 +432,7 @@ void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { Indent() << "@catch("; if (catchStmt->getCatchParamStmt()) { if (DeclStmt *DS = dyn_cast(catchStmt->getCatchParamStmt())) - PrintRawDecl(DS->getDecl()); + PrintRawDeclStmt(DS); } OS << ")"; if (CompoundStmt *CS = dyn_cast(catchStmt->getCatchBody()))