diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-05-30 00:56:08 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-05-30 00:56:08 +0000 |
commit | 64f650062fbe5e2bc6fb6d341c46a2ec0284694f (patch) | |
tree | 381bc2fbe457ddb002350348e4abe8f035444f47 /lib | |
parent | d12ef8d142868889867f9dd968b5f3ea02d463c1 (diff) |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/DeclPrinter.cpp | 58 | ||||
-rw-r--r-- | 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<FunctionDecl>(*D) && cast<FunctionDecl>(*D)->isThisDeclarationADefinition()) Terminator = 0; - else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D)) + else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->getBody()) + Terminator = 0; + else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) || + isa<ObjCImplementationDecl>(*D) || + isa<ObjCInterfaceDecl>(*D) || + isa<ObjCProtocolDecl>(*D) || + isa<ObjCCategoryImplDecl>(*D) || + isa<ObjCCategoryDecl>(*D)) Terminator = 0; else if (isa<EnumConstantDecl>(*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 << ", "; |