From cd569f2788ece55b9f790b6900164e2b2d5d966c Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 5 Nov 2013 22:28:30 +0000 Subject: [PATCH] ObjectiveC migrator. Please annotation of properties with NS_RETURNS_INNER_POINTER under -objcmt-returns-innerpointer-property flag (off by default), as older compilers do not support such annotations. // rdar://15396636 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194100 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 3 +++ include/clang/Frontend/FrontendOptions.h | 5 ++++- lib/ARCMigrate/ObjCMT.cpp | 3 +++ lib/Frontend/CompilerInvocation.cpp | 2 ++ test/ARCMT/objcmt-ns-returns-inner-pointer.m | 2 +- test/ARCMT/objcmt-ns-returns-inner-pointer.m.result | 2 +- 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 3e37bc5518..cc2de9f914 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -181,6 +181,9 @@ def objcmt_migrate_protocol_conformance : Flag<["-"], "objcmt-migrate-protocol-c def objcmt_atomic_property : Flag<["-"], "objcmt-atomic-property">, Flags<[CC1Option]>, HelpText<"Make migration to 'atomic' properties">; +def objcmt_returns_innerpointer_property : Flag<["-"], "objcmt-returns-innerpointer-property">, Flags<[CC1Option]>, + HelpText<"Enable migration to annotate property with NS_RETURNS_INNER_POINTER">; + // Make sure all other -ccc- options are rejected. def ccc_ : Joined<["-"], "ccc-">, Group, Flags<[Unsupported]>; diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index b77c90b673..eab330d028 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -175,13 +175,16 @@ public: ObjCMT_ProtocolConformance = 0x80, /// \brief prefer 'atomic' property over 'nonatomic'. ObjCMT_AtomicProperty = 0x100, + /// \brief annotate property with NS_RETURNS_INNER_POINTER + ObjCMT_ReturnsInnerPointerProperty = 0x200, ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | ObjCMT_Annotation | ObjCMT_Instancetype | ObjCMT_NsMacros | ObjCMT_ProtocolConformance), ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | ObjCMT_Annotation | ObjCMT_Instancetype | - ObjCMT_NsMacros | ObjCMT_ProtocolConformance) + ObjCMT_NsMacros | ObjCMT_ProtocolConformance | + ObjCMT_ReturnsInnerPointerProperty) }; unsigned ObjCMTAction; diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index f2f355c30f..34cc073044 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -416,6 +416,9 @@ void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx, if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation) migrateNsReturnsInnerPointer(Ctx, Method); } + if (!(ASTMigrateActions & FrontendOptions::ObjCMT_ReturnsInnerPointerProperty)) + return; + for (ObjCContainerDecl::prop_iterator P = D->prop_begin(), E = D->prop_end(); P != E; ++P) { ObjCPropertyDecl *Prop = *P; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index a523acfc43..d419d8a9ea 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -805,6 +805,8 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReadwriteProperty; if (Args.hasArg(OPT_objcmt_migrate_annotation)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Annotation; + if (Args.hasArg(OPT_objcmt_returns_innerpointer_property)) + Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReturnsInnerPointerProperty; if (Args.hasArg(OPT_objcmt_migrate_instancetype)) Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Instancetype; if (Args.hasArg(OPT_objcmt_migrate_nsmacros)) diff --git a/test/ARCMT/objcmt-ns-returns-inner-pointer.m b/test/ARCMT/objcmt-ns-returns-inner-pointer.m index bec0c4b249..bff7d80b94 100644 --- a/test/ARCMT/objcmt-ns-returns-inner-pointer.m +++ b/test/ARCMT/objcmt-ns-returns-inner-pointer.m @@ -1,5 +1,5 @@ // RUN: rm -rf %t -// RUN: %clang_cc1 -objcmt-migrate-annotation -objcmt-migrate-readwrite-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11 +// RUN: %clang_cc1 -objcmt-returns-innerpointer-property -objcmt-migrate-annotation -objcmt-migrate-readwrite-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11 // RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result diff --git a/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result b/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result index 438b5bd5a3..8048e06748 100644 --- a/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result +++ b/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result @@ -1,5 +1,5 @@ // RUN: rm -rf %t -// RUN: %clang_cc1 -objcmt-migrate-annotation -objcmt-migrate-readwrite-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11 +// RUN: %clang_cc1 -objcmt-returns-innerpointer-property -objcmt-migrate-annotation -objcmt-migrate-readwrite-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11 // RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result -- 2.40.0