]> granicus.if.org Git - clang/commitdiff
Several small patches to do pretty printing for objective-c top-level decls
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 8 Oct 2007 18:53:38 +0000 (18:53 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 8 Oct 2007 18:53:38 +0000 (18:53 +0000)
(minimal printing), Derive ObjcClassDecl from Decl. Ted may want to
take note of the change I made to CFGRecStmtDeclVisitor.h

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42764 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/ASTConsumers.cpp
Parse/ParseObjc.cpp
include/clang/AST/DeclObjC.h
include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h

index ddacfa88c1b46f6df719032c3f5f929ce5bf895b..a52cd4511aa3c6044e654b4acbac22a20d5f5881 100644 (file)
@@ -79,6 +79,26 @@ static void PrintObjcInterfaceDecl(ObjcInterfaceDecl *OID) {
   // FIXME: implement the rest...
 }
 
+static void PrintObjcProtocolDecl(ObjcProtocolDecl *PID) {
+  std::string S = PID->getName();
+  fprintf(stderr, "@protocol %s;\n", S.c_str());
+  // FIXME: implement the rest...
+}
+
+static void PrintObjcCategoryImplDecl(ObjcCategoryImplDecl *PID) {
+  std::string S = PID->getName();
+  std::string I = PID->getClassInterface()->getName();
+  fprintf(stderr, "@implementation %s(%s);\n", I.c_str(), S.c_str());
+  // FIXME: implement the rest...
+}
+
+static void PrintObjcCategoryDecl(ObjcCategoryDecl *PID) {
+  std::string S = PID->getName();
+  std::string I = PID->getClassInterface()->getName();
+  fprintf(stderr, "@interface %s(%s);\n", I.c_str(), S.c_str());
+  // FIXME: implement the rest...
+}
+
 namespace {
   class ASTPrinter : public ASTConsumer {
     virtual void HandleTopLevelDecl(Decl *D) {
@@ -92,10 +112,10 @@ namespace {
         }
       } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
         PrintTypeDefDecl(TD);
-      } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
-        fprintf(stderr, "Read top-level variable decl: '%s'\n", SD->getName());
       } else if (ObjcInterfaceDecl *OID = dyn_cast<ObjcInterfaceDecl>(D)) {
         PrintObjcInterfaceDecl(OID);
+      } else if (ObjcProtocolDecl *PID = dyn_cast<ObjcProtocolDecl>(D)) {
+        PrintObjcProtocolDecl(PID);
       } else if (ObjcForwardProtocolDecl *OFPD = 
                      dyn_cast<ObjcForwardProtocolDecl>(D)) {
         fprintf(stderr, "@protocol ");
@@ -109,8 +129,16 @@ namespace {
                    dyn_cast<ObjcImplementationDecl>(D)) {
         fprintf(stderr, "@implementation %s  [printing todo]\n",
                 OID->getName());
+      } else if (ObjcCategoryImplDecl *OID = 
+                 dyn_cast<ObjcCategoryImplDecl>(D)) {
+        PrintObjcCategoryImplDecl(OID);
+      } else if (ObjcCategoryDecl *OID = 
+                 dyn_cast<ObjcCategoryDecl>(D)) {
+        PrintObjcCategoryDecl(OID);
       } else if (isa<ObjcClassDecl>(D)) {
         fprintf(stderr, "@class [printing todo]\n");
+      } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
+        fprintf(stderr, "Read top-level variable decl: '%s'\n", SD->getName());
       } else {
         assert(0 && "Unknown decl type!");
       }
index cd78797e2ecd6fdbf426935a6e0c845555430abb..b7ec93aacaca94f6d5549b4ee51980463d1b7082 100644 (file)
@@ -163,7 +163,7 @@ Parser::DeclTy *Parser::ParseObjCAtInterfaceDeclaration(
     // The @ sign was already consumed by ParseObjCInterfaceDeclList().
     if (Tok.isObjCAtKeyword(tok::objc_end)) {
       ConsumeToken(); // the "end" identifier
-      return 0;
+      return CategoryType;
     }
     Diag(Tok, diag::err_objc_missing_end);
     return 0;
@@ -803,7 +803,7 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
   // The @ sign was already consumed by ParseObjCInterfaceDeclList().
   if (Tok.isObjCAtKeyword(tok::objc_end)) {
     ConsumeToken(); // the "end" identifier
-    return 0;
+    return ProtoType;
   }
   Diag(Tok, diag::err_objc_missing_end);
   return 0;
index b53996fb868c767e0d3eb67dd04b04094d72f836..b6f83322044fdafe2bc811f3aef13b26441a2293 100644 (file)
@@ -347,12 +347,12 @@ public:
 ///
 /// @class NSCursor, NSImage, NSPasteboard, NSWindow;
 ///
-class ObjcClassDecl : public TypeDecl {
+class ObjcClassDecl : public Decl {
   ObjcInterfaceDecl **ForwardDecls;
   unsigned NumForwardDecls;
 public:
   ObjcClassDecl(SourceLocation L, ObjcInterfaceDecl **Elts, unsigned nElts)
-    : TypeDecl(ObjcClass, L, 0, 0) { 
+    : Decl(ObjcClass, L) { 
     if (nElts) {
       ForwardDecls = new ObjcInterfaceDecl*[nElts];
       memcpy(ForwardDecls, Elts, nElts*sizeof(ObjcInterfaceDecl*));
index 7b93705d8499e17e1b87feee6d7e61d487f7770a..b5858ebbb4a0cb54d4bc16c225496afcd10da2ca 100644 (file)
@@ -64,7 +64,6 @@ public:
         DISPATCH_CASE(Class,RecordDecl)     // FIXME: Refine. 
         DISPATCH_CASE(Enum,EnumDecl)
         DISPATCH_CASE(ObjcInterface,ObjcInterfaceDecl)
-        DISPATCH_CASE(ObjcClass,ObjcClassDecl)
         DISPATCH_CASE(ObjcProtocol,ObjcProtocolDecl)
       default:
         assert(false && "Subtype of ScopedDecl not handled.");