From 64f650062fbe5e2bc6fb6d341c46a2ec0284694f Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 30 May 2009 00:56:08 +0000 Subject: [PATCH] Clean up printing for Objective-C, designated initializers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72602 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/DeclPrinter.cpp | 58 ++++++++++++++++++++--------------------- lib/AST/StmtPrinter.cpp | 5 ++++ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index a48737560e..b665e2e0e1 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -108,7 +108,14 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { if (isa(*D) && cast(*D)->isThisDeclarationADefinition()) Terminator = 0; - else if (isa(*D) || isa(*D)) + else if (isa(*D) && cast(*D)->getBody()) + Terminator = 0; + else if (isa(*D) || isa(*D) || + isa(*D) || + isa(*D) || + isa(*D) || + isa(*D) || + isa(*D)) Terminator = 0; else if (isa(*D)) { DeclContext::decl_iterator Next = D; @@ -323,14 +330,13 @@ void DeclPrinter::VisitObjCClassDecl(ObjCClassDecl *D) { if (I != D->begin()) Out << ", "; Out << (*I)->getNameAsString(); } - Out << ";\n"; } void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { if (OMD->isInstanceMethod()) - Out << "\n- "; + Out << "- "; else - Out << "\n+ "; + Out << "+ "; if (!OMD->getResultType().isNull()) Out << '(' << OMD->getResultType().getAsString() << ")"; @@ -356,8 +362,7 @@ void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { Out << ' '; OMD->getBody()->printPretty(Out, 0, Policy); Out << '\n'; - } else - Out << ";"; + } } void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) { @@ -368,9 +373,9 @@ void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) { Out << "@implementation " << I << " : " << SID->getNameAsString(); else Out << "@implementation " << I; - - VisitDeclContext(OID); - Out << "@end\n"; + Out << "\n"; + VisitDeclContext(OID, false); + Out << "@end"; } void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) { @@ -391,21 +396,22 @@ void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) { } if (!Protocols.empty()) - Out << ">"; - Out << '\n'; + Out << "> "; if (OID->ivar_size() > 0) { - Out << '{'; + Out << "{\n"; + Indentation += Policy.Indentation; for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(), E = OID->ivar_end(); I != E; ++I) { - Out << '\t' << (*I)->getType().getAsString(Policy) + Indent() << (*I)->getType().getAsString(Policy) << ' ' << (*I)->getNameAsString() << ";\n"; } + Indentation -= Policy.Indentation; Out << "}\n"; } VisitDeclContext(OID, false); - Out << "@end\n"; + Out << "@end"; // FIXME: implement the rest... } @@ -417,35 +423,30 @@ void DeclPrinter::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D) { if (I != D->protocol_begin()) Out << ", "; Out << (*I)->getNameAsString(); } - Out << ";\n"; } void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { Out << "@protocol " << PID->getNameAsString() << '\n'; - - for (ObjCProtocolDecl::prop_iterator I = PID->prop_begin(Context), - E = PID->prop_end(Context); I != E; ++I) - VisitObjCPropertyDecl(*I); - Out << "@end\n"; - // FIXME: implement the rest... + VisitDeclContext(PID, false); + Out << "@end"; } void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { Out << "@implementation " << PID->getClassInterface()->getNameAsString() - << '(' << PID->getNameAsString() << ");\n"; + << '(' << PID->getNameAsString() << ")\n"; VisitDeclContext(PID, false); - Out << "@end\n"; + Out << "@end"; // FIXME: implement the rest... } void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) { Out << "@interface " << PID->getClassInterface()->getNameAsString() - << '(' << PID->getNameAsString() << ");\n"; + << '(' << PID->getNameAsString() << ")\n"; VisitDeclContext(PID, false); - Out << "@end\n"; + Out << "@end"; // FIXME: implement the rest... } @@ -514,17 +515,14 @@ void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) { } Out << ' ' << PDecl->getType().getAsString(Policy) << ' ' << PDecl->getNameAsString(); - - Out << ";\n"; } void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) { if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize) - Out << "\n@synthesize "; + Out << "@synthesize "; else - Out << "\n@dynamic "; + Out << "@dynamic "; Out << PID->getPropertyDecl()->getNameAsString(); if (PID->getPropertyIvarDecl()) Out << "=" << PID->getPropertyIvarDecl()->getNameAsString(); - Out << ";\n"; } diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 7fe1524c58..a427147472 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -982,6 +982,11 @@ void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) { } void StmtPrinter::VisitInitListExpr(InitListExpr* Node) { + if (Node->getSyntacticForm()) { + Visit(Node->getSyntacticForm()); + return; + } + OS << "{ "; for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) { if (i) OS << ", "; -- 2.40.0