[cfe-commits] r145224 - in /cfe/trunk: lib/ARCMigrate/TransGCAttrs.cpp lib/ARCMigrate/TransProperties.cpp lib/ARCMigrate/Transforms.cpp lib/ARCMigrate/Transforms.h test/ARCMT/GC-no-arc-runtime.m test/ARCMT/GC-no-arc-runtime.m.result

Argyrios Kyrtzidis akyrtzi at gmail.com
Sun Nov 27 18:04:36 PST 2011


Author: akirtzidis
Date: Sun Nov 27 20:04:36 2011
New Revision: 145224

URL: http://llvm.org/viewvc/llvm-project?rev=145224&view=rev
Log:
[arcmt] Integrate GC __weak into property attributes even when we don't have
the implementation.

Modified:
    cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp
    cfe/trunk/lib/ARCMigrate/TransProperties.cpp
    cfe/trunk/lib/ARCMigrate/Transforms.cpp
    cfe/trunk/lib/ARCMigrate/Transforms.h
    cfe/trunk/test/ARCMT/GC-no-arc-runtime.m
    cfe/trunk/test/ARCMT/GC-no-arc-runtime.m.result

Modified: cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp?rev=145224&r1=145223&r2=145224&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransGCAttrs.cpp Sun Nov 27 20:04:36 2011
@@ -261,9 +261,12 @@
 
   SmallVector<std::pair<AttributedTypeLoc, ObjCPropertyDecl *>, 4> ATLs;
   bool hasWeak = false, hasStrong = false;
+  ObjCPropertyDecl::PropertyAttributeKind
+    Attrs = ObjCPropertyDecl::OBJC_PR_noattr;
   for (IndivPropsTy::iterator
          PI = IndProps.begin(), PE = IndProps.end(); PI != PE; ++PI) {
     ObjCPropertyDecl *PD = *PI;
+    Attrs = PD->getPropertyAttributesAsWritten();
     TypeSourceInfo *TInfo = PD->getTypeSourceInfo();
     if (!TInfo)
       return;
@@ -300,9 +303,10 @@
       else
         toAttr = "unsafe_unretained";
     }
-    if (!MigrateCtx.rewritePropertyAttribute("assign", toAttr, AtLoc)) {
-      return;
-    }
+    if (Attrs & ObjCPropertyDecl::OBJC_PR_assign)
+      MigrateCtx.rewritePropertyAttribute("assign", toAttr, AtLoc);
+    else
+      MigrateCtx.addPropertyAttribute(toAttr, AtLoc);
   }
 
   for (unsigned i = 0, e = ATLs.size(); i != e; ++i) {

Modified: cfe/trunk/lib/ARCMigrate/TransProperties.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransProperties.cpp?rev=145224&r1=145223&r2=145224&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransProperties.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransProperties.cpp Sun Nov 27 20:04:36 2011
@@ -277,7 +277,7 @@
   }
 
   bool removeAttribute(StringRef fromAttr, SourceLocation atLoc) const {
-    return rewriteAttribute(fromAttr, StringRef(), atLoc);
+    return MigrateCtx.removePropertyAttribute(fromAttr, atLoc);
   }
 
   bool rewriteAttribute(StringRef fromAttr, StringRef toAttr,
@@ -286,51 +286,7 @@
   }
 
   bool addAttribute(StringRef attr, SourceLocation atLoc) const {
-    if (atLoc.isMacroID())
-      return false;
-
-    SourceManager &SM = Pass.Ctx.getSourceManager();
-
-    // Break down the source location.
-    std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
-
-    // Try to load the file buffer.
-    bool invalidTemp = false;
-    StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
-    if (invalidTemp)
-      return false;
-
-    const char *tokenBegin = file.data() + locInfo.second;
-
-    // Lex from the start of the given location.
-    Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
-                Pass.Ctx.getLangOptions(),
-                file.begin(), tokenBegin, file.end());
-    Token tok;
-    lexer.LexFromRawLexer(tok);
-    if (tok.isNot(tok::at)) return false;
-    lexer.LexFromRawLexer(tok);
-    if (tok.isNot(tok::raw_identifier)) return false;
-    if (StringRef(tok.getRawIdentifierData(), tok.getLength())
-          != "property")
-      return false;
-    lexer.LexFromRawLexer(tok);
-
-    if (tok.isNot(tok::l_paren)) {
-      Pass.TA.insert(tok.getLocation(), std::string("(") + attr.str() + ") ");
-      return true;
-    }
-    
-    lexer.LexFromRawLexer(tok);
-    if (tok.is(tok::r_paren)) {
-      Pass.TA.insert(tok.getLocation(), attr);
-      return true;
-    }
-
-    if (tok.isNot(tok::raw_identifier)) return false;
-
-    Pass.TA.insert(tok.getLocation(), std::string(attr) + ", ");
-    return true;
+    return MigrateCtx.addPropertyAttribute(attr, atLoc);
   }
 
   class PlusOneAssign : public RecursiveASTVisitor<PlusOneAssign> {

Modified: cfe/trunk/lib/ARCMigrate/Transforms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.cpp?rev=145224&r1=145223&r2=145224&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/Transforms.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/Transforms.cpp Sun Nov 27 20:04:36 2011
@@ -446,6 +446,55 @@
   return false;
 }
 
+bool MigrationContext::addPropertyAttribute(StringRef attr,
+                                            SourceLocation atLoc) {
+  if (atLoc.isMacroID())
+    return false;
+
+  SourceManager &SM = Pass.Ctx.getSourceManager();
+
+  // Break down the source location.
+  std::pair<FileID, unsigned> locInfo = SM.getDecomposedLoc(atLoc);
+
+  // Try to load the file buffer.
+  bool invalidTemp = false;
+  StringRef file = SM.getBufferData(locInfo.first, &invalidTemp);
+  if (invalidTemp)
+    return false;
+
+  const char *tokenBegin = file.data() + locInfo.second;
+
+  // Lex from the start of the given location.
+  Lexer lexer(SM.getLocForStartOfFile(locInfo.first),
+              Pass.Ctx.getLangOptions(),
+              file.begin(), tokenBegin, file.end());
+  Token tok;
+  lexer.LexFromRawLexer(tok);
+  if (tok.isNot(tok::at)) return false;
+  lexer.LexFromRawLexer(tok);
+  if (tok.isNot(tok::raw_identifier)) return false;
+  if (StringRef(tok.getRawIdentifierData(), tok.getLength())
+        != "property")
+    return false;
+  lexer.LexFromRawLexer(tok);
+
+  if (tok.isNot(tok::l_paren)) {
+    Pass.TA.insert(tok.getLocation(), std::string("(") + attr.str() + ") ");
+    return true;
+  }
+  
+  lexer.LexFromRawLexer(tok);
+  if (tok.is(tok::r_paren)) {
+    Pass.TA.insert(tok.getLocation(), attr);
+    return true;
+  }
+
+  if (tok.isNot(tok::raw_identifier)) return false;
+
+  Pass.TA.insert(tok.getLocation(), std::string(attr) + ", ");
+  return true;
+}
+
 void MigrationContext::traverse(TranslationUnitDecl *TU) {
   for (traverser_iterator
          I = traversers_begin(), E = traversers_end(); I != E; ++I)

Modified: cfe/trunk/lib/ARCMigrate/Transforms.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.h?rev=145224&r1=145223&r2=145224&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/Transforms.h (original)
+++ cfe/trunk/lib/ARCMigrate/Transforms.h Sun Nov 27 20:04:36 2011
@@ -113,8 +113,12 @@
   }
 
   bool isGCOwnedNonObjC(QualType T);
+  bool removePropertyAttribute(StringRef fromAttr, SourceLocation atLoc) {
+    return rewritePropertyAttribute(fromAttr, StringRef(), atLoc);
+  }
   bool rewritePropertyAttribute(StringRef fromAttr, StringRef toAttr,
                                 SourceLocation atLoc);
+  bool addPropertyAttribute(StringRef attr, SourceLocation atLoc);
 
   void traverse(TranslationUnitDecl *TU);
 

Modified: cfe/trunk/test/ARCMT/GC-no-arc-runtime.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/GC-no-arc-runtime.m?rev=145224&r1=145223&r2=145224&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/GC-no-arc-runtime.m (original)
+++ cfe/trunk/test/ARCMT/GC-no-arc-runtime.m Sun Nov 27 20:04:36 2011
@@ -71,3 +71,9 @@
   id x = NSMakeCollectable(cft);
 }
 @end
+
+ at interface I5 {
+  __weak id prop;
+}
+ at property (readonly) __weak id prop;
+ at end

Modified: cfe/trunk/test/ARCMT/GC-no-arc-runtime.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/GC-no-arc-runtime.m.result?rev=145224&r1=145223&r2=145224&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/GC-no-arc-runtime.m.result (original)
+++ cfe/trunk/test/ARCMT/GC-no-arc-runtime.m.result Sun Nov 27 20:04:36 2011
@@ -66,3 +66,9 @@
   id x = CFBridgingRelease(cft);
 }
 @end
+
+ at interface I5 {
+  __unsafe_unretained id prop;
+}
+ at property (unsafe_unretained, readonly)  id prop;
+ at end





More information about the cfe-commits mailing list