r188838 - ObjectiveC migrator: make sure audited pragams are

Fariborz Jahanian fjahanian at apple.com
Tue Aug 20 15:42:13 PDT 2013


Author: fjahanian
Date: Tue Aug 20 17:42:13 2013
New Revision: 188838

URL: http://llvm.org/viewvc/llvm-project?rev=188838&view=rev
Log:
ObjectiveC migrator: make sure audited pragams are
dumped for last declarations in the current TU. wip.

Modified:
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
    cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m
    cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=188838&r1=188837&r2=188838&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Tue Aug 20 17:42:13 2013
@@ -52,6 +52,8 @@ class ObjCMigrateASTConsumer : public AS
   void migrateCFFunctions(ASTContext &Ctx,
                           const FunctionDecl *FuncDecl);
   
+  void AnnotateImplicitBridging(ASTContext &Ctx);
+  
   bool migrateAddFunctionAnnotation(ASTContext &Ctx,
                                     const FunctionDecl *FuncDecl);
   
@@ -794,9 +796,39 @@ AuditedType (QualType AT, bool &IsPonite
   return true;
 }
 
+void ObjCMigrateASTConsumer::AnnotateImplicitBridging(ASTContext &Ctx) {
+  if (!Ctx.Idents.get("CF_IMPLICIT_BRIDGING_ENABLED").hasMacroDefinition()) {
+    CFFunctionIBCandidates.clear();
+    return;
+  }
+  // Insert CF_IMPLICIT_BRIDGING_ENABLE/CF_IMPLICIT_BRIDGING_DISABLED
+  const FunctionDecl *FirstFD = CFFunctionIBCandidates[0];
+  const FunctionDecl *LastFD  =
+  CFFunctionIBCandidates[CFFunctionIBCandidates.size()-1];
+  const char *PragmaString = "\nCF_IMPLICIT_BRIDGING_ENABLED\n\n";
+  edit::Commit commit(*Editor);
+  commit.insertBefore(FirstFD->getLocStart(), PragmaString);
+  PragmaString = "\n\nCF_IMPLICIT_BRIDGING_DISABLED\n";
+  SourceLocation EndLoc = LastFD->getLocEnd();
+  // get location just past end of function location.
+  EndLoc = PP.getLocForEndOfToken(EndLoc);
+  Token Tok;
+  // get locaiton of token that comes after end of function.
+  bool Failed = PP.getRawToken(EndLoc, Tok, /*IgnoreWhiteSpace=*/true);
+  if (!Failed)
+    EndLoc = Tok.getLocation();
+  commit.insertAfterToken(EndLoc, PragmaString);
+  Editor->commit(commit);
+  
+  CFFunctionIBCandidates.clear();
+}
+
 void ObjCMigrateASTConsumer::migrateCFFunctions(
                                ASTContext &Ctx,
                                const FunctionDecl *FuncDecl) {
+  
+  // FileID FID = PP.getSourceManager().getFileID(FuncDecl->getLocation());
+  
   if (FuncDecl->hasAttr<CFAuditedTransferAttr>()) {
     assert(CFFunctionIBCandidates.empty() &&
            "Cannot have audited functions inside user "
@@ -808,34 +840,8 @@ void ObjCMigrateASTConsumer::migrateCFFu
   bool Audited = migrateAddFunctionAnnotation(Ctx, FuncDecl);
   if (Audited)
     CFFunctionIBCandidates.push_back(FuncDecl);
-  else if (!CFFunctionIBCandidates.empty()) {
-    if (!Ctx.Idents.get("CF_IMPLICIT_BRIDGING_ENABLED").hasMacroDefinition()) {
-      CFFunctionIBCandidates.clear();
-      return;
-    }
-    // Insert CF_IMPLICIT_BRIDGING_ENABLE/CF_IMPLICIT_BRIDGING_DISABLED
-    const FunctionDecl *FirstFD = CFFunctionIBCandidates[0];
-    const FunctionDecl *LastFD  =
-      CFFunctionIBCandidates[CFFunctionIBCandidates.size()-1];
-    const char *PragmaString = "\nCF_IMPLICIT_BRIDGING_ENABLED\n\n";
-    edit::Commit commit(*Editor);
-    commit.insertBefore(FirstFD->getLocStart(), PragmaString);
-    PragmaString = "\n\nCF_IMPLICIT_BRIDGING_DISABLED\n";
-    SourceLocation EndLoc = LastFD->getLocEnd();
-    // get location just past end of function location.
-    EndLoc = PP.getLocForEndOfToken(EndLoc);
-    Token Tok;
-    // get locaiton of token that comes after end of function.
-    bool Failed = PP.getRawToken(EndLoc, Tok, /*IgnoreWhiteSpace=*/true);
-    if (!Failed)
-      EndLoc = Tok.getLocation();
-    commit.insertAfterToken(EndLoc, PragmaString);
-    Editor->commit(commit);
-    
-    CFFunctionIBCandidates.clear();
-  }
-  // FIXME. Also must insert CF_IMPLICIT_BRIDGING_ENABLE/CF_IMPLICIT_BRIDGING_DISABLED
-  // when leaving current file.
+  else if (!CFFunctionIBCandidates.empty())
+    AnnotateImplicitBridging(Ctx);
 }
 
 bool ObjCMigrateASTConsumer::migrateAddFunctionAnnotation(
@@ -929,7 +935,7 @@ public:
 void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
   
   TranslationUnitDecl *TU = Ctx.getTranslationUnitDecl();
-  if (MigrateProperty)
+  if (MigrateProperty) {
     for (DeclContext::decl_iterator D = TU->decls_begin(), DEnd = TU->decls_end();
          D != DEnd; ++D) {
       if (ObjCInterfaceDecl *CDecl = dyn_cast<ObjCInterfaceDecl>(*D))
@@ -955,6 +961,9 @@ void ObjCMigrateASTConsumer::HandleTrans
       if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D))
         migrateInstanceType(Ctx, CDecl);
     }
+    if (!CFFunctionIBCandidates.empty())
+      AnnotateImplicitBridging(Ctx);
+  }
   
   Rewriter rewriter(Ctx.getSourceManager(), Ctx.getLangOpts());
   RewritesReceiver Rec(rewriter);

Modified: cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m?rev=188838&r1=188837&r2=188838&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m Tue Aug 20 17:42:13 2013
@@ -2037,7 +2037,4 @@ void rdar13783514(xpc_connection_t conne
   xpc_connection_set_finalizer_f(connection, releaseAfterXPC);
 } // no-warning
 
-CFAttributedStringRef CFAttributedCreate(long attributes) CF_RETURNS_RETAINED;
-CFTypeID CFGetTypeID(void) {
-  return 0;
-}
+CFAttributedStringRef CFAttributedCreate(void *CFObj CF_CONSUMED) CF_RETURNS_RETAINED;

Modified: cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result?rev=188838&r1=188837&r2=188838&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result Tue Aug 20 17:42:13 2013
@@ -2100,10 +2100,7 @@ void rdar13783514(xpc_connection_t conne
 
 CF_IMPLICIT_BRIDGING_ENABLED
 
-CFAttributedStringRef CFAttributedCreate(long attributes) CF_RETURNS_RETAINED;
+CFAttributedStringRef CFAttributedCreate(void *CFObj CF_CONSUMED) CF_RETURNS_RETAINED;
 
 CF_IMPLICIT_BRIDGING_DISABLED
 
-CFTypeID CFGetTypeID(void) {
-  return 0;
-}





More information about the cfe-commits mailing list