r189537 - ObjectiveC migrator. This patch infers readonly properties for no-parameter
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 28 16:22:47 PDT 2013
Author: fjahanian
Date: Wed Aug 28 18:22:46 2013
New Revision: 189537
URL: http://llvm.org/viewvc/llvm-project?rev=189537&view=rev
Log:
ObjectiveC migrator. This patch infers readonly properties for no-parameter
instance methods returning non-void. This will be quite noisy. So, it is
placed under a new migrator flag -objcmt-migrate-readonly-property.
Modified:
cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
cfe/trunk/test/ARCMT/objcmt-property.m
cfe/trunk/test/ARCMT/objcmt-property.m.result
Modified: cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h?rev=189537&r1=189536&r2=189537&view=diff
==============================================================================
--- cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h (original)
+++ cfe/trunk/include/clang/ARCMigrate/ARCMTActions.h Wed Aug 28 18:22:46 2013
@@ -60,13 +60,15 @@ class ObjCMigrateAction : public Wrapper
bool MigrateLiterals;
bool MigrateSubscripting;
bool MigrateProperty;
+ bool MigrateReadonlyProperty;
FileRemapper Remapper;
CompilerInstance *CompInst;
public:
ObjCMigrateAction(FrontendAction *WrappedAction, StringRef migrateDir,
bool migrateLiterals,
bool migrateSubscripting,
- bool migrateProperty);
+ bool migrateProperty,
+ bool migrateReadonlyProperty);
protected:
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,StringRef InFile);
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=189537&r1=189536&r2=189537&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Aug 28 18:22:46 2013
@@ -173,6 +173,8 @@ def objcmt_migrate_subscripting : Flag<[
HelpText<"Enable migration to modern ObjC subscripting">;
def objcmt_migrate_property : Flag<["-"], "objcmt-migrate-property">, Flags<[CC1Option]>,
HelpText<"Enable migration to modern ObjC property">;
+def objcmt_migrate_readonly_property : Flag<["-"], "objcmt-migrate-readonly-property">, Flags<[CC1Option]>,
+ HelpText<"Enable migration to modern ObjC readonly property">;
// Make sure all other -ccc- options are rejected.
def ccc_ : Joined<["-"], "ccc-">, Group<internal_Group>, Flags<[Unsupported]>;
Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=189537&r1=189536&r2=189537&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Wed Aug 28 18:22:46 2013
@@ -161,7 +161,9 @@ public:
/// \brief Enable migration to modern ObjC subscripting.
ObjCMT_Subscripting = 0x2,
/// \brief Enable migration to modern ObjC property.
- ObjCMT_Property = 0x4
+ ObjCMT_Property = 0x4,
+ /// \brief Enable migration to modern ObjC readonly property.
+ ObjCMT_ReadonlyProperty = 0x8
};
unsigned ObjCMTAction;
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=189537&r1=189536&r2=189537&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Aug 28 18:22:46 2013
@@ -75,6 +75,7 @@ public:
bool MigrateLiterals;
bool MigrateSubscripting;
bool MigrateProperty;
+ bool MigrateReadonlyProperty;
unsigned FileId;
OwningPtr<NSAPI> NSAPIObj;
OwningPtr<edit::EditedSource> Editor;
@@ -90,6 +91,7 @@ public:
bool migrateLiterals,
bool migrateSubscripting,
bool migrateProperty,
+ bool migrateReadonlyProperty,
FileRemapper &remapper,
FileManager &fileMgr,
const PPConditionalDirectiveRecord *PPRec,
@@ -98,8 +100,9 @@ public:
: MigrateDir(migrateDir),
MigrateLiterals(migrateLiterals),
MigrateSubscripting(migrateSubscripting),
- MigrateProperty(migrateProperty), FileId(0),
- Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP),
+ MigrateProperty(migrateProperty),
+ MigrateReadonlyProperty(migrateReadonlyProperty),
+ FileId(0), Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP),
IsOutputFile(isOutputFile) { }
protected:
@@ -131,10 +134,12 @@ ObjCMigrateAction::ObjCMigrateAction(Fro
StringRef migrateDir,
bool migrateLiterals,
bool migrateSubscripting,
- bool migrateProperty)
+ bool migrateProperty,
+ bool migrateReadonlyProperty)
: WrapperFrontendAction(WrappedAction), MigrateDir(migrateDir),
MigrateLiterals(migrateLiterals), MigrateSubscripting(migrateSubscripting),
MigrateProperty(migrateProperty),
+ MigrateReadonlyProperty(migrateReadonlyProperty),
CompInst(0) {
if (MigrateDir.empty())
MigrateDir = "."; // user current directory if none is given.
@@ -151,6 +156,7 @@ ASTConsumer *ObjCMigrateAction::CreateAS
MigrateLiterals,
MigrateSubscripting,
MigrateProperty,
+ MigrateReadonlyProperty,
Remapper,
CompInst->getFileManager(),
PPRec,
@@ -250,13 +256,17 @@ static bool rewriteToObjCProperty(const
PropertyString += ", getter=";
PropertyString += PropertyNameString;
}
+ // Property with no setter may be suggested as a 'readonly' property.
+ if (!Setter)
+ append_attr(PropertyString, "readonly");
+
// Short circuit properties that contain the name "delegate" or "dataSource",
// or have exact name "target" to have unsafe_unretained attribute.
if (PropertyName.equals("target") ||
(PropertyName.find("delegate") != StringRef::npos) ||
(PropertyName.find("dataSource") != StringRef::npos))
append_attr(PropertyString, "unsafe_unretained");
- else {
+ else if (Setter) {
const ParmVarDecl *argDecl = *Setter->param_begin();
QualType ArgType = Context.getCanonicalType(argDecl->getType());
Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
@@ -308,10 +318,12 @@ static bool rewriteToObjCProperty(const
commit.replace(CharSourceRange::getCharRange(Getter->getLocStart(),
Getter->getDeclaratorEndLoc()),
PropertyString);
- SourceLocation EndLoc = Setter->getDeclaratorEndLoc();
- // Get location past ';'
- EndLoc = EndLoc.getLocWithOffset(1);
- commit.remove(CharSourceRange::getCharRange(Setter->getLocStart(), EndLoc));
+ if (Setter) {
+ SourceLocation EndLoc = Setter->getDeclaratorEndLoc();
+ // Get location past ';'
+ EndLoc = EndLoc.getLocWithOffset(1);
+ commit.remove(CharSourceRange::getCharRange(Setter->getLocStart(), EndLoc));
+ }
return true;
}
@@ -320,7 +332,8 @@ void ObjCMigrateASTConsumer::migrateObjC
for (ObjCContainerDecl::method_iterator M = D->meth_begin(), MEnd = D->meth_end();
M != MEnd; ++M) {
ObjCMethodDecl *Method = (*M);
- if (Method->isPropertyAccessor() || Method->param_size() != 0)
+ if (Method->isPropertyAccessor() || !Method->isInstanceMethod() ||
+ Method->param_size() != 0)
continue;
// Is this method candidate to be a getter?
QualType GRT = Method->getResultType();
@@ -368,7 +381,15 @@ void ObjCMigrateASTConsumer::migrateObjC
rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit,
GetterHasIsPrefix);
Editor->commit(commit);
- }
+ }
+ else if (MigrateReadonlyProperty) {
+ // Try a non-void method with no argument (and no setter or property of same name
+ // as a 'readonly' property.
+ edit::Commit commit(*Editor);
+ rewriteToObjCProperty(Method, 0 /*SetterMethod*/, *NSAPIObj, commit,
+ false /*GetterHasIsPrefix*/);
+ Editor->commit(commit);
+ }
}
}
@@ -1170,6 +1191,7 @@ ASTConsumer *MigrateSourceAction::Create
/*MigrateLiterals=*/true,
/*MigrateSubscripting=*/true,
/*MigrateProperty*/true,
+ /*MigrateReadonlyProperty*/true,
Remapper,
CI.getFileManager(),
PPRec,
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=189537&r1=189536&r2=189537&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Aug 28 18:22:46 2013
@@ -793,6 +793,8 @@ static InputKind ParseFrontendArgs(Front
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Subscripting;
if (Args.hasArg(OPT_objcmt_migrate_property))
Opts.ObjCMTAction |= FrontendOptions::ObjCMT_Property;
+ if (Args.hasArg(OPT_objcmt_migrate_readonly_property))
+ Opts.ObjCMTAction |= FrontendOptions::ObjCMT_ReadonlyProperty;
if (Opts.ARCMTAction != FrontendOptions::ARCMT_None &&
Opts.ObjCMTAction != FrontendOptions::ObjCMT_None) {
Modified: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp?rev=189537&r1=189536&r2=189537&view=diff
==============================================================================
--- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp (original)
+++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp Wed Aug 28 18:22:46 2013
@@ -164,7 +164,8 @@ static FrontendAction *CreateFrontendAct
Act = new arcmt::ObjCMigrateAction(Act, FEOpts.MTMigrateDir,
FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_Literals,
FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_Subscripting,
- FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_Property);
+ FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_Property,
+ FEOpts.ObjCMTAction & FrontendOptions::ObjCMT_ReadonlyProperty);
}
#endif
Modified: cfe/trunk/test/ARCMT/objcmt-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m?rev=189537&r1=189536&r2=189537&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m Wed Aug 28 18:22:46 2013
@@ -1,5 +1,5 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -objcmt-migrate-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties -triple x86_64-apple-darwin11
+// RUN: %clang_cc1 -objcmt-migrate-property -objcmt-migrate-readonly-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties -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 -fobjc-default-synthesize-properties %s.result
@@ -87,4 +87,9 @@ typedef char BOOL;
- (BOOL) isinValid;
- (void) setInValid : (BOOL) arg;
+
+- (void) Nothing;
+- (int) Length;
+- (id) object;
++ (double) D;
@end
Modified: cfe/trunk/test/ARCMT/objcmt-property.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m.result?rev=189537&r1=189536&r2=189537&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Wed Aug 28 18:22:46 2013
@@ -1,5 +1,5 @@
// RUN: rm -rf %t
-// RUN: %clang_cc1 -objcmt-migrate-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties -triple x86_64-apple-darwin11
+// RUN: %clang_cc1 -objcmt-migrate-property -objcmt-migrate-readonly-property -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -fobjc-default-synthesize-properties -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 -fobjc-default-synthesize-properties %s.result
@@ -82,9 +82,14 @@ typedef char BOOL;
@property(nonatomic, getter=isContinuous) BOOL continuous;
-- (id) isAnObject;
+ at property(nonatomic, readonly) id isAnObject;
- (void)setAnObject : (id) object;
-- (BOOL) isinValid;
+ at property(nonatomic, readonly) BOOL isinValid;
- (void) setInValid : (BOOL) arg;
+
+- (void) Nothing;
+ at property(nonatomic, readonly) int Length;
+ at property(nonatomic, readonly) id object;
++ (double) D;
@end
More information about the cfe-commits
mailing list