[cfe-commits] r150985 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/ASTImporter.cpp lib/AST/DeclObjC.cpp lib/Rewrite/RewriteModernObjC.cpp lib/Sema/SemaDecl.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp test/Rewriter/rewrite-modern-class.mm test/Rewriter/rewrite-modern-ivars.mm test/Rewriter/rewrite-modern-protocol.mm

Fariborz Jahanian fjahanian at apple.com
Mon Feb 20 12:09:20 PST 2012


Author: fjahanian
Date: Mon Feb 20 14:09:20 2012
New Revision: 150985

URL: http://llvm.org/viewvc/llvm-project?rev=150985&view=rev
Log:
modern objc translator. Finish off first cut of the
modern meta-data translation by commenting out private ivar
declarations in user source. Also, added several tests.

Added:
    cfe/trunk/test/Rewriter/rewrite-modern-class.mm
    cfe/trunk/test/Rewriter/rewrite-modern-ivars.mm
    cfe/trunk/test/Rewriter/rewrite-modern-protocol.mm
Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=150985&r1=150984&r2=150985&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Feb 20 14:09:20 2012
@@ -1283,12 +1283,19 @@
   /// \brief The location of the category name in this declaration.
   SourceLocation CategoryNameLoc;
 
+  /// class extension may have private ivars.
+  SourceLocation IvarLBraceLoc;
+  SourceLocation IvarRBraceLoc;
+  
   ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
                    SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
-                   IdentifierInfo *Id, ObjCInterfaceDecl *IDecl)
+                   IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
+                   SourceLocation IvarLBraceLoc=SourceLocation(),
+                   SourceLocation IvarRBraceLoc=SourceLocation())
     : ObjCContainerDecl(ObjCCategory, DC, Id, ClassNameLoc, AtLoc),
       ClassInterface(IDecl), NextClassCategory(0), HasSynthBitfield(false),
-      CategoryNameLoc(CategoryNameLoc) {
+      CategoryNameLoc(CategoryNameLoc),
+      IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc) {
   }
 public:
 
@@ -1297,7 +1304,9 @@
                                   SourceLocation ClassNameLoc,
                                   SourceLocation CategoryNameLoc,
                                   IdentifierInfo *Id,
-                                  ObjCInterfaceDecl *IDecl);
+                                  ObjCInterfaceDecl *IDecl,
+                                  SourceLocation IvarLBraceLoc=SourceLocation(),
+                                  SourceLocation IvarRBraceLoc=SourceLocation());
   static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
   ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
@@ -1353,6 +1362,11 @@
 
   SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
   void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
+  
+  void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
+  SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
+  void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
+  SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
 
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCCategoryDecl *D) { return true; }
@@ -1521,6 +1535,10 @@
   virtual void anchor();
   /// Implementation Class's super class.
   ObjCInterfaceDecl *SuperClass;
+  /// @implementation may have private ivars.
+  SourceLocation IvarLBraceLoc;
+  SourceLocation IvarRBraceLoc;
+  
   /// Support for ivar initialization.
   /// IvarInitializers - The arguments used to initialize the ivars
   CXXCtorInitializer **IvarInitializers;
@@ -1535,16 +1553,22 @@
   ObjCImplementationDecl(DeclContext *DC,
                          ObjCInterfaceDecl *classInterface,
                          ObjCInterfaceDecl *superDecl,
-                         SourceLocation nameLoc, SourceLocation atStartLoc)
+                         SourceLocation nameLoc, SourceLocation atStartLoc,
+                         SourceLocation IvarLBraceLoc=SourceLocation(), 
+                         SourceLocation IvarRBraceLoc=SourceLocation())
     : ObjCImplDecl(ObjCImplementation, DC, classInterface, nameLoc, atStartLoc),
-       SuperClass(superDecl), IvarInitializers(0), NumIvarInitializers(0),
-       HasCXXStructors(false), HasSynthBitfield(false) {}
+       SuperClass(superDecl), IvarLBraceLoc(IvarLBraceLoc), 
+       IvarRBraceLoc(IvarRBraceLoc),
+       IvarInitializers(0), NumIvarInitializers(0),
+       HasCXXStructors(false), HasSynthBitfield(false){}
 public:
   static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
                                         ObjCInterfaceDecl *classInterface,
                                         ObjCInterfaceDecl *superDecl,
                                         SourceLocation nameLoc,
-                                        SourceLocation atStartLoc);
+                                        SourceLocation atStartLoc,
+                                        SourceLocation IvarLBraceLoc=SourceLocation(), 
+                                        SourceLocation IvarRBraceLoc=SourceLocation());
 
   static ObjCImplementationDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
@@ -1623,6 +1647,11 @@
 
   void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
 
+  void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
+  SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
+  void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
+  SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
+  
   typedef specific_decl_iterator<ObjCIvarDecl> ivar_iterator;
   ivar_iterator ivar_begin() const {
     return ivar_iterator(decls_begin());

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=150985&r1=150984&r2=150985&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Feb 20 14:09:20 2012
@@ -3088,7 +3088,9 @@
                                           Loc, 
                                        Importer.Import(D->getCategoryNameLoc()), 
                                           Name.getAsIdentifierInfo(),
-                                          ToInterface);
+                                          ToInterface,
+                                       Importer.Import(D->getIvarLBraceLoc()),
+                                       Importer.Import(D->getIvarRBraceLoc()));
     ToCategory->setLexicalDeclContext(LexicalDC);
     LexicalDC->addDeclInternal(ToCategory);
     Importer.Imported(D, ToCategory);
@@ -3434,7 +3436,9 @@
                                   Importer.ImportContext(D->getDeclContext()),
                                           Iface, Super,
                                           Importer.Import(D->getLocation()),
-                                          Importer.Import(D->getAtStartLoc()));
+                                          Importer.Import(D->getAtStartLoc()),
+                                          Importer.Import(D->getIvarLBraceLoc()),
+                                          Importer.Import(D->getIvarRBraceLoc()));
     
     if (D->getDeclContext() != D->getLexicalDeclContext()) {
       DeclContext *LexicalDC

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=150985&r1=150984&r2=150985&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Feb 20 14:09:20 2012
@@ -1070,10 +1070,13 @@
                                            SourceLocation ClassNameLoc,
                                            SourceLocation CategoryNameLoc,
                                            IdentifierInfo *Id,
-                                           ObjCInterfaceDecl *IDecl) {
+                                           ObjCInterfaceDecl *IDecl,
+                                           SourceLocation IvarLBraceLoc,
+                                           SourceLocation IvarRBraceLoc) {
   ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc,
                                                        CategoryNameLoc, Id,
-                                                       IDecl);
+                                                       IDecl,
+                                                       IvarLBraceLoc, IvarRBraceLoc);
   if (IDecl) {
     // Link this category into its class's category list.
     CatDecl->NextClassCategory = IDecl->getCategoryList();
@@ -1209,11 +1212,14 @@
                                ObjCInterfaceDecl *ClassInterface,
                                ObjCInterfaceDecl *SuperDecl,
                                SourceLocation nameLoc,
-                               SourceLocation atStartLoc) {
+                               SourceLocation atStartLoc,
+                               SourceLocation IvarLBraceLoc,
+                               SourceLocation IvarRBraceLoc) {
   if (ClassInterface && ClassInterface->hasDefinition())
     ClassInterface = ClassInterface->getDefinition();
   return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
-                                        nameLoc, atStartLoc);
+                                        nameLoc, atStartLoc,
+                                        IvarLBraceLoc, IvarRBraceLoc);
 }
 
 ObjCImplementationDecl *

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=150985&r1=150984&r2=150985&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Mon Feb 20 14:09:20 2012
@@ -934,14 +934,17 @@
 
   // FIXME: handle category headers that are declared across multiple lines.
   ReplaceText(LocStart, 0, "// ");
-
+  if (CatDecl->getIvarLBraceLoc().isValid())
+    InsertText(CatDecl->getIvarLBraceLoc(), "// ");
   for (ObjCCategoryDecl::ivar_iterator
        I = CatDecl->ivar_begin(), E = CatDecl->ivar_end(); I != E; ++I) {
     ObjCIvarDecl *Ivar = (*I);
     SourceLocation LocStart = Ivar->getLocStart();
     ReplaceText(LocStart, 0, "// ");
   } 
-
+  if (CatDecl->getIvarRBraceLoc().isValid())
+    InsertText(CatDecl->getIvarRBraceLoc(), "// ");
+  
   for (ObjCCategoryDecl::prop_iterator I = CatDecl->prop_begin(),
        E = CatDecl->prop_end(); I != E; ++I)
     RewriteProperty(*I);
@@ -1153,12 +1156,16 @@
 
   if (IMD) {
     InsertText(IMD->getLocStart(), "// ");
-      for (ObjCImplementationDecl::ivar_iterator
-           I = IMD->ivar_begin(), E = IMD->ivar_end(); I != E; ++I) {
-        ObjCIvarDecl *Ivar = (*I);
-        SourceLocation LocStart = Ivar->getLocStart();
-        ReplaceText(LocStart, 0, "// ");
+    if (IMD->getIvarLBraceLoc().isValid())
+      InsertText(IMD->getIvarLBraceLoc(), "// ");
+    for (ObjCImplementationDecl::ivar_iterator
+         I = IMD->ivar_begin(), E = IMD->ivar_end(); I != E; ++I) {
+      ObjCIvarDecl *Ivar = (*I);
+      SourceLocation LocStart = Ivar->getLocStart();
+      ReplaceText(LocStart, 0, "// ");
     }
+    if (IMD->getIvarRBraceLoc().isValid())
+      InsertText(IMD->getIvarRBraceLoc(), "// ");
   }
   else
     InsertText(CID->getLocStart(), "// ");

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=150985&r1=150984&r2=150985&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Feb 20 14:09:20 2012
@@ -9585,6 +9585,8 @@
         // Only it is in implementation's lexical context.
         ClsFields[I]->setLexicalDeclContext(IMPDecl);
       CheckImplementationIvars(IMPDecl, ClsFields, RecFields.size(), RBrac);
+      IMPDecl->setIvarLBraceLoc(LBrac);
+      IMPDecl->setIvarRBraceLoc(RBrac);
     } else if (ObjCCategoryDecl *CDecl = 
                 dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
       // case of ivars in class extension; all other cases have been
@@ -9618,6 +9620,8 @@
         ClsFields[i]->setLexicalDeclContext(CDecl);
         CDecl->addDecl(ClsFields[i]);
       }
+      CDecl->setIvarLBraceLoc(LBrac);
+      CDecl->setIvarRBraceLoc(RBrac);
     }
   }
 

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=150985&r1=150984&r2=150985&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Feb 20 14:09:20 2012
@@ -770,6 +770,8 @@
 void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
   VisitObjCContainerDecl(CD);
   CD->setCategoryNameLoc(ReadSourceLocation(Record, Idx));
+  CD->setIvarLBraceLoc(ReadSourceLocation(Record, Idx));
+  CD->setIvarRBraceLoc(ReadSourceLocation(Record, Idx));
   
   // Note that this category has been deserialized. We do this before
   // deserializing the interface declaration, so that it will consider this
@@ -829,6 +831,8 @@
 void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
   VisitObjCImplDecl(D);
   D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>(Record, Idx));
+  D->setIvarLBraceLoc(ReadSourceLocation(Record, Idx));
+  D->setIvarRBraceLoc(ReadSourceLocation(Record, Idx));
   llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
       = Reader.ReadCXXCtorInitializers(F, Record, Idx);
   D->setHasSynthBitfield(Record[Idx++]);

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=150985&r1=150984&r2=150985&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Feb 20 14:09:20 2012
@@ -541,6 +541,8 @@
 void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
   VisitObjCContainerDecl(D);
   Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
+  Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
+  Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
   Writer.AddDeclRef(D->getClassInterface(), Record);
   Record.push_back(D->protocol_size());
   for (ObjCCategoryDecl::protocol_iterator
@@ -593,6 +595,8 @@
 void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
   VisitObjCImplDecl(D);
   Writer.AddDeclRef(D->getSuperClass(), Record);
+  Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
+  Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
   Writer.AddCXXCtorInitializers(D->IvarInitializers, D->NumIvarInitializers,
                                 Record);
   Record.push_back(D->hasSynthBitfield());

Added: cfe/trunk/test/Rewriter/rewrite-modern-class.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-class.mm?rev=150985&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-class.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-modern-class.mm Mon Feb 20 14:09:20 2012
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+
+ at protocol PROTO @end
+
+ at interface empty_root @end
+
+ at interface root_with_ivars
+{
+  id ROOT_IVAR;
+  id ROOT1_IVAR;
+}
+ at end
+
+ at interface MAXIMAL : root_with_ivars<PROTO>
+{
+  double D_IVAR;
+  double D_PROPERTY;
+}
+- (void) V_METH;
+ at end
+
+ at implementation MAXIMAL
+- (void) V_METH {}
+ at end
+//=========================================
+ at interface empty_class @end
+
+ at implementation empty_class @end
+//=========================================
+ at interface class_empty_root : empty_root @end
+
+ at implementation class_empty_root @end
+//=========================================
+ at interface class_with_ivars : empty_root
+{
+  int class_with_ivars_IVAR;
+}
+ at end
+
+ at implementation class_with_ivars @end
+//=========================================
+ at interface class_has_no_ivar : root_with_ivars @end
+
+ at implementation class_has_no_ivar @end
+
+//============================class needs to be synthesized here=====================
+ at interface SUPER  {
+ at public
+  double divar;
+  SUPER *p_super;
+}
+ at end
+
+ at interface INTF @end
+
+ at implementation INTF  
+- (SUPER *) Meth : (SUPER *)arg { 
+  return arg->p_super; 
+}
+ at end

Added: cfe/trunk/test/Rewriter/rewrite-modern-ivars.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-ivars.mm?rev=150985&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-ivars.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-modern-ivars.mm Mon Feb 20 14:09:20 2012
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+
+ at protocol P @end
+ at protocol P1 @end
+ at interface INTF
+{
+  id CLASS_IVAR;
+  id<P, P1> Q_IVAR;
+
+  void (^_block)(id<P>);
+  void (*_fptr)(void (^_block)(id<P>));
+  char CLASS_EXT_IVAR;
+  id<P, P1> (^ext_block)(id<P>, INTF<P,P1>*, INTF*);
+  id IMPL_IVAR;
+  double D_IMPL_IVAR;
+  INTF<P> *(*imp_fptr)(void (^_block)(id<P>, INTF<P,P1>*));
+  id arr[100];
+}
+ at end
+
+ at implementation INTF @end
+
+ at interface MISC_INTF
+{
+  id CLASS_IVAR;
+  id<P, P1> Q_IVAR;
+
+  void (^_block)(id<P>);
+  void (*_fptr)(void (^_block)(id<P>));
+  unsigned int BF : 8;
+}
+ at end
+
+ at interface MISC_INTF()
+{
+  char CLASS_EXT_IVAR;
+  id<P, P1> (^ext_block)(id<P>, MISC_INTF<P,P1>*, MISC_INTF*);
+}
+ at end
+
+ at interface MISC_INTF() {
+  int II1;
+  double DD1; }
+ at end
+
+ at interface MISC_INTF() { int II2; double DD2; }
+ at end
+
+ at interface MISC_INTF() { int II3; 
+  double DD3; }
+ at end
+
+ at interface MISC_INTF() { int II4; double DD4; 
+}
+ at end
+
+ at implementation MISC_INTF
+{
+  id IMPL_IVAR;
+  double D_IMPL_IVAR;
+  MISC_INTF<P> *(*imp_fptr)(void (^_block)(id<P>, MISC_INTF<P,P1>*));
+}
+ at end

Added: cfe/trunk/test/Rewriter/rewrite-modern-protocol.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-protocol.mm?rev=150985&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-protocol.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-modern-protocol.mm Mon Feb 20 14:09:20 2012
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+
+ at protocol ROOT @end
+
+ at protocol P1 @end
+
+ at protocol P2<ROOT> @end
+
+ at class NSObject;
+
+ at protocol PROTO <P1, P2>
+- (id) INST_METHOD;
++ (id) CLASS_METHOD : (id)ARG;
+ at property id Prop_in_PROTO;
+ at optional
+- (id) opt_instance_method;
++ (id) opt_class_method;
+ at property (readonly, retain) NSObject *AnotherProperty;
+ at required
+- (id) req;
+ at optional
+- (id) X_opt_instance_method;
++ (id) X_opt_class_method;
+ at end
+
+ at interface INTF <PROTO, ROOT>
+ at end
+
+ at implementation INTF
+ at end





More information about the cfe-commits mailing list