ObjectiveC migrator. Place use of NS_NONATOMIC_IOSONLY

on inferred property attribute under
 -objcmt-ns-nonatomic-iosonly  option.
// rdar://15442742

llvm-svn: 194532
This commit is contained in:
Fariborz Jahanian 2013-11-13 00:08:36 +00:00
parent 008c45f1a1
commit 2e793d6124
6 changed files with 18 additions and 9 deletions

View File

@ -183,6 +183,8 @@ def objcmt_atomic_property : Flag<["-"], "objcmt-atomic-property">,
HelpText<"Make migration to 'atomic' properties">; HelpText<"Make migration to 'atomic' properties">;
def objcmt_returns_innerpointer_property : Flag<["-"], "objcmt-returns-innerpointer-property">, Flags<[CC1Option]>, def objcmt_returns_innerpointer_property : Flag<["-"], "objcmt-returns-innerpointer-property">, Flags<[CC1Option]>,
HelpText<"Enable migration to annotate property with NS_RETURNS_INNER_POINTER">; HelpText<"Enable migration to annotate property with NS_RETURNS_INNER_POINTER">;
def objcmt_ns_nonatomic_iosonly: Flag<["-"], "objcmt-ns-nonatomic-iosonly">, Flags<[CC1Option]>,
HelpText<"Enable migration to use NS_NONATOMIC_IOSONLY macro for setting property's 'atomic' attribute">;
// Make sure all other -ccc- options are rejected. // Make sure all other -ccc- options are rejected.
def ccc_ : Joined<["-"], "ccc-">, Group<internal_Group>, Flags<[Unsupported]>; def ccc_ : Joined<["-"], "ccc-">, Group<internal_Group>, Flags<[Unsupported]>;

View File

@ -177,13 +177,13 @@ public:
ObjCMT_AtomicProperty = 0x100, ObjCMT_AtomicProperty = 0x100,
/// \brief annotate property with NS_RETURNS_INNER_POINTER /// \brief annotate property with NS_RETURNS_INNER_POINTER
ObjCMT_ReturnsInnerPointerProperty = 0x200, ObjCMT_ReturnsInnerPointerProperty = 0x200,
/// \brief use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
ObjCMT_NsAtomicIOSOnlyProperty = 0x400,
ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | ObjCMT_MigrateDecls = (ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty |
ObjCMT_Annotation | ObjCMT_Instancetype | ObjCMT_Annotation | ObjCMT_Instancetype |
ObjCMT_NsMacros | ObjCMT_ProtocolConformance), ObjCMT_NsMacros | ObjCMT_ProtocolConformance |
ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | ObjCMT_NsAtomicIOSOnlyProperty),
ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty | ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting | ObjCMT_MigrateDecls)
ObjCMT_Annotation | ObjCMT_Instancetype |
ObjCMT_NsMacros | ObjCMT_ProtocolConformance)
}; };
unsigned ObjCMTAction; unsigned ObjCMTAction;

View File

@ -278,11 +278,12 @@ static void rewriteToObjCProperty(const ObjCMethodDecl *Getter,
const ObjCMethodDecl *Setter, const ObjCMethodDecl *Setter,
const NSAPI &NS, edit::Commit &commit, const NSAPI &NS, edit::Commit &commit,
unsigned LengthOfPrefix, unsigned LengthOfPrefix,
bool Atomic, bool AvailabilityArgsMatch) { bool Atomic, bool UseNsIosOnlyMacro,
bool AvailabilityArgsMatch) {
ASTContext &Context = NS.getASTContext(); ASTContext &Context = NS.getASTContext();
bool LParenAdded = false; bool LParenAdded = false;
std::string PropertyString = "@property "; std::string PropertyString = "@property ";
if (Context.Idents.get("NS_NONATOMIC_IOSONLY").hasMacroDefinition()) { if (UseNsIosOnlyMacro && Context.Idents.get("NS_NONATOMIC_IOSONLY").hasMacroDefinition()) {
PropertyString += "(NS_NONATOMIC_IOSONLY"; PropertyString += "(NS_NONATOMIC_IOSONLY";
LParenAdded = true; LParenAdded = true;
} else if (!Atomic) { } else if (!Atomic) {
@ -1078,6 +1079,8 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
LengthOfPrefix, LengthOfPrefix,
(ASTMigrateActions & (ASTMigrateActions &
FrontendOptions::ObjCMT_AtomicProperty) != 0, FrontendOptions::ObjCMT_AtomicProperty) != 0,
(ASTMigrateActions &
FrontendOptions::ObjCMT_NsAtomicIOSOnlyProperty) != 0,
AvailabilityArgsMatch); AvailabilityArgsMatch);
Editor->commit(commit); Editor->commit(commit);
return true; return true;
@ -1090,6 +1093,8 @@ bool ObjCMigrateASTConsumer::migrateProperty(ASTContext &Ctx,
LengthOfPrefix, LengthOfPrefix,
(ASTMigrateActions & (ASTMigrateActions &
FrontendOptions::ObjCMT_AtomicProperty) != 0, FrontendOptions::ObjCMT_AtomicProperty) != 0,
(ASTMigrateActions &
FrontendOptions::ObjCMT_NsAtomicIOSOnlyProperty) != 0,
/*AvailabilityArgsMatch*/false); /*AvailabilityArgsMatch*/false);
Editor->commit(commit); Editor->commit(commit);
return true; return true;

View File

@ -815,6 +815,8 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ProtocolConformance; Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ProtocolConformance;
if (Args.hasArg(OPT_objcmt_atomic_property)) if (Args.hasArg(OPT_objcmt_atomic_property))
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_AtomicProperty; Opts.ObjCMTAction |= FrontendOptions::ObjCMT_AtomicProperty;
if (Args.hasArg(OPT_objcmt_ns_nonatomic_iosonly))
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_NsAtomicIOSOnlyProperty;
if (Args.hasArg(OPT_objcmt_migrate_all)) if (Args.hasArg(OPT_objcmt_migrate_all))
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_MigrateDecls; Opts.ObjCMTAction |= FrontendOptions::ObjCMT_MigrateDecls;

View File

@ -1,5 +1,5 @@
// RUN: rm -rf %t // RUN: rm -rf %t
// RUN: %clang_cc1 -fblocks -objcmt-migrate-readwrite-property -objcmt-migrate-readonly-property -objcmt-atomic-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11 // RUN: %clang_cc1 -fblocks -objcmt-migrate-readwrite-property -objcmt-ns-nonatomic-iosonly -objcmt-migrate-readonly-property -objcmt-atomic-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: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result // RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result

View File

@ -1,5 +1,5 @@
// RUN: rm -rf %t // RUN: rm -rf %t
// RUN: %clang_cc1 -fblocks -objcmt-migrate-readwrite-property -objcmt-migrate-readonly-property -objcmt-atomic-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11 // RUN: %clang_cc1 -fblocks -objcmt-migrate-readwrite-property -objcmt-ns-nonatomic-iosonly -objcmt-migrate-readonly-property -objcmt-atomic-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: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
// RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result // RUN: %clang_cc1 -fblocks -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result