[cfe-commits] r155921 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/rewrite-modern-private-ivars.mm

Fariborz Jahanian fjahanian at apple.com
Tue May 1 10:46:45 PDT 2012


Author: fjahanian
Date: Tue May  1 12:46:45 2012
New Revision: 155921

URL: http://llvm.org/viewvc/llvm-project?rev=155921&view=rev
Log:
modern objective-c translation of private ivars.
// rdar://11351299

Added:
    cfe/trunk/test/Rewriter/rewrite-modern-private-ivars.mm
Modified:
    cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp

Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=155921&r1=155920&r2=155921&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Tue May  1 12:46:45 2012
@@ -346,7 +346,7 @@
                                       std::string &Result);
     
     void RewriteObjCFieldDecl(FieldDecl *fieldDecl, std::string &Result);
-    bool IsTagDefinedInsideClass(ObjCInterfaceDecl *IDecl, TagDecl *Tag,
+    bool IsTagDefinedInsideClass(ObjCContainerDecl *IDecl, TagDecl *Tag,
                                  bool &IsNamedDefinition);
     void RewriteLocallyDefinedNamedAggregates(FieldDecl *fieldDecl, 
                                               std::string &Result);
@@ -988,17 +988,13 @@
   SourceLocation LocStart = CatDecl->getLocStart();
 
   // 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();
+  if (CatDecl->getIvarRBraceLoc().isValid()) {
+    ReplaceText(LocStart, 1, "/** ");
+    ReplaceText(CatDecl->getIvarRBraceLoc(), 1, "**/ ");
+  }
+  else {
     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)
@@ -1224,17 +1220,13 @@
   ObjCCategoryImplDecl *CID = dyn_cast<ObjCCategoryImplDecl>(OID);
 
   if (IMD) {
-    InsertText(IMD->getLocStart(), "// ");
-    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()) {
+      ReplaceText(IMD->getLocStart(), 1, "/** ");
+      ReplaceText(IMD->getIvarRBraceLoc(), 1, "**/ ");
+    }
+    else {
+      InsertText(IMD->getLocStart(), "// ");
     }
-    if (IMD->getIvarRBraceLoc().isValid())
-      InsertText(IMD->getIvarRBraceLoc(), "// ");
   }
   else
     InsertText(CID->getLocStart(), "// ");
@@ -3500,7 +3492,7 @@
 
 /// IsTagDefinedInsideClass - This routine checks that a named tagged type 
 /// is defined inside an objective-c class. If so, it returns true. 
-bool RewriteModernObjC::IsTagDefinedInsideClass(ObjCInterfaceDecl *IDecl, 
+bool RewriteModernObjC::IsTagDefinedInsideClass(ObjCContainerDecl *IDecl, 
                                                 TagDecl *Tag,
                                                 bool &IsNamedDefinition) {
   if (!IDecl)
@@ -3628,8 +3620,8 @@
   QualType Type = fieldDecl->getType();
   if (Type->isArrayType())
     Type = Context->getBaseElementType(Type);
-  ObjCInterfaceDecl *IDecl = 
-    dyn_cast<ObjCInterfaceDecl>(fieldDecl->getDeclContext());
+  ObjCContainerDecl *IDecl = 
+    dyn_cast<ObjCContainerDecl>(fieldDecl->getDeclContext());
   
   TagDecl *TD = 0;
   if (Type->isRecordType()) {

Added: cfe/trunk/test/Rewriter/rewrite-modern-private-ivars.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-modern-private-ivars.mm?rev=155921&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-modern-private-ivars.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-modern-private-ivars.mm Tue May  1 12:46:45 2012
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -fblocks -rewrite-objc -fms-extensions %s -o %t-rw.cpp
+// RUN: %clang_cc1 -Werror -fsyntax-only -Wno-address-of-temporary -Wno-c++11-narrowing -std=c++11 -D"Class=void*" -D"id=void*" -D"SEL=void*" -U__declspec -D"__declspec(X)=" %t-rw.cpp
+// rdar://11351299
+
+struct Q {
+  int x;
+};
+
+ at interface I
+ at end
+
+ at interface I() {
+
+  struct {
+    int x;
+  } unnamed;
+
+  struct S {
+    int x;
+  } foo;
+
+  double dd;
+
+  struct S foo1;
+}
+ at end
+
+ at implementation I 
+{
+  struct P {
+    int x;
+  } bar;
+
+  double ee;
+
+  struct Q bar1;
+
+  struct {
+    int x;
+  } noname;
+}
+
+- (void) Meth { 
+  foo.x = 1; 
+  bar.x = 2; 
+  dd = 1.23; 
+  ee = 0.0; 
+  foo1.x = 3;
+  bar1.x = 4;
+  noname.x = 3;
+  unnamed.x = 10;
+}
+ at end





More information about the cfe-commits mailing list