]> granicus.if.org Git - clang/commitdiff
Clean up printing for Objective-C, designated initializers.
authorDouglas Gregor <dgregor@apple.com>
Sat, 30 May 2009 00:56:08 +0000 (00:56 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 30 May 2009 00:56:08 +0000 (00:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72602 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclPrinter.cpp
lib/AST/StmtPrinter.cpp

index a48737560e4458a3dcd5ea28fef6c09b6d16c562..b665e2e0e19d411ae21ae2aaebd0cea6ba85f28a 100644 (file)
@@ -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";
 }
index 7fe1524c58c49a68e856027191e5bf10edc287db..a4271474729e7fe5d30da293fff110d1761d7e7a 100644 (file)
@@ -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 << ", ";