diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/ARCMigrate/TransGCAttrs.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/ARCMigrate/TransProperties.cpp | 48 | ||||
| -rw-r--r-- | clang/lib/ARCMigrate/Transforms.cpp | 49 | ||||
| -rw-r--r-- | clang/lib/ARCMigrate/Transforms.h | 4 | ||||
| -rw-r--r-- | clang/test/ARCMT/GC-no-arc-runtime.m | 6 | ||||
| -rw-r--r-- | clang/test/ARCMT/GC-no-arc-runtime.m.result | 6 | 
6 files changed, 74 insertions, 49 deletions
diff --git a/clang/lib/ARCMigrate/TransGCAttrs.cpp b/clang/lib/ARCMigrate/TransGCAttrs.cpp index 607e5a0f3d9..1c645ace89a 100644 --- a/clang/lib/ARCMigrate/TransGCAttrs.cpp +++ b/clang/lib/ARCMigrate/TransGCAttrs.cpp @@ -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) { diff --git a/clang/lib/ARCMigrate/TransProperties.cpp b/clang/lib/ARCMigrate/TransProperties.cpp index 8136b31d812..f8bc8a3c5fe 100644 --- a/clang/lib/ARCMigrate/TransProperties.cpp +++ b/clang/lib/ARCMigrate/TransProperties.cpp @@ -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> { diff --git a/clang/lib/ARCMigrate/Transforms.cpp b/clang/lib/ARCMigrate/Transforms.cpp index c1a573c34e9..e208e8471bd 100644 --- a/clang/lib/ARCMigrate/Transforms.cpp +++ b/clang/lib/ARCMigrate/Transforms.cpp @@ -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) diff --git a/clang/lib/ARCMigrate/Transforms.h b/clang/lib/ARCMigrate/Transforms.h index 8c09a4757c5..84912bcd26f 100644 --- a/clang/lib/ARCMigrate/Transforms.h +++ b/clang/lib/ARCMigrate/Transforms.h @@ -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); diff --git a/clang/test/ARCMT/GC-no-arc-runtime.m b/clang/test/ARCMT/GC-no-arc-runtime.m index 2a43f18004f..276f674a55b 100644 --- a/clang/test/ARCMT/GC-no-arc-runtime.m +++ b/clang/test/ARCMT/GC-no-arc-runtime.m @@ -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 diff --git a/clang/test/ARCMT/GC-no-arc-runtime.m.result b/clang/test/ARCMT/GC-no-arc-runtime.m.result index 567f804698c..84208128eba 100644 --- a/clang/test/ARCMT/GC-no-arc-runtime.m.result +++ b/clang/test/ARCMT/GC-no-arc-runtime.m.result @@ -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  | 

