]> granicus.if.org Git - clang/commitdiff
[arcmt] Integrate GC __weak into property attributes even when we don't have
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Nov 2011 02:04:36 +0000 (02:04 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 28 Nov 2011 02:04:36 +0000 (02:04 +0000)
the implementation.

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

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

index 607e5a0f3d9983e2edb36a4bf1a396ba073afe52..1c645ace89a4e40ff31f7551c7b9985bd96e0dbb 100644 (file)
@@ -261,9 +261,12 @@ static void checkAllAtProps(MigrationContext &MigrateCtx,
 
   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 @@ static void checkAllAtProps(MigrationContext &MigrateCtx,
       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) {
index 8136b31d81246210877b3c1379303702ef12c200..f8bc8a3c5feb22cd04cc020664724dd323d219ea 100644 (file)
@@ -277,7 +277,7 @@ private:
   }
 
   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 @@ private:
   }
 
   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> {
index c1a573c34e9c26c3463f8770da38c82bdd25c527..e208e8471bd78f62bf6fa9b0786f069ed7037664 100644 (file)
@@ -446,6 +446,55 @@ bool MigrationContext::rewritePropertyAttribute(StringRef fromAttr,
   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)
index 8c09a4757c57e2aac6f254861e5f7215e9ad5909..84912bcd26f7d07596086ba5dcdf4713ef775b2b 100644 (file)
@@ -113,8 +113,12 @@ public:
   }
 
   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);
 
index 2a43f18004f46ab7cc302be21d47a82e7620738f..276f674a55bd6d9366e4ddaf9496b0b6910acd96 100644 (file)
@@ -71,3 +71,9 @@ __attribute__((objc_arc_weak_reference_unavailable))
   id x = NSMakeCollectable(cft);
 }
 @end
+
+@interface I5 {
+  __weak id prop;
+}
+@property (readonly) __weak id prop;
+@end
index 567f804698c15d9a231ea90ef24df5d970e80814..84208128eba7f1c341163cb3f6d056252ce56568 100644 (file)
@@ -66,3 +66,9 @@ __attribute__((objc_arc_weak_reference_unavailable))
   id x = CFBridgingRelease(cft);
 }
 @end
+
+@interface I5 {
+  __unsafe_unretained id prop;
+}
+@property (unsafe_unretained, readonly)  id prop;
+@end