r185873 - [Objective-C migrator] replace candidate user setter/getter with
Fariborz Jahanian
fjahanian at apple.com
Mon Jul 8 14:42:08 PDT 2013
Author: fjahanian
Date: Mon Jul 8 16:42:08 2013
New Revision: 185873
URL: http://llvm.org/viewvc/llvm-project?rev=185873&view=rev
Log:
[Objective-C migrator] replace candidate user setter/getter with
their equivalent property declaration. wip.
Added:
cfe/trunk/test/ARCMT/objcmt-property.m
cfe/trunk/test/ARCMT/objcmt-property.m.result
Modified:
cfe/trunk/include/clang/Edit/Commit.h
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/lib/Edit/Commit.cpp
cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
Modified: cfe/trunk/include/clang/Edit/Commit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Edit/Commit.h?rev=185873&r1=185872&r2=185873&view=diff
==============================================================================
--- cfe/trunk/include/clang/Edit/Commit.h (original)
+++ cfe/trunk/include/clang/Edit/Commit.h Mon Jul 8 16:42:08 2013
@@ -13,6 +13,7 @@
#include "clang/Edit/FileOffset.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Allocator.h"
namespace clang {
class LangOptions;
@@ -51,6 +52,8 @@ private:
bool IsCommitable;
SmallVector<Edit, 8> CachedEdits;
+
+ llvm::BumpPtrAllocator StrAlloc;
public:
explicit Commit(EditedSource &Editor);
@@ -131,6 +134,12 @@ private:
SourceLocation *MacroBegin = 0) const;
bool isAtEndOfMacroExpansion(SourceLocation loc,
SourceLocation *MacroEnd = 0) const;
+
+ StringRef copyString(StringRef str) {
+ char *buf = StrAlloc.Allocate<char>(str.size());
+ std::memcpy(buf, str.data(), str.size());
+ return StringRef(buf, str.size());
+ }
};
}
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=185873&r1=185872&r2=185873&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Mon Jul 8 16:42:08 2013
@@ -212,7 +212,7 @@ void ObjCMigrateASTConsumer::migrateObjC
continue;
const ParmVarDecl *argDecl = *SetterMethod->param_begin();
QualType ArgType = argDecl->getType();
- if (!Ctx.hasSameType(ArgType, GRT))
+ if (!Ctx.hasSameUnqualifiedType(ArgType, GRT))
continue;
edit::Commit commit(*Editor);
edit::rewriteToObjCProperty(Method, SetterMethod, *NSAPIObj, commit);
Modified: cfe/trunk/lib/Edit/Commit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/Commit.cpp?rev=185873&r1=185872&r2=185873&view=diff
==============================================================================
--- cfe/trunk/lib/Edit/Commit.cpp (original)
+++ cfe/trunk/lib/Edit/Commit.cpp Mon Jul 8 16:42:08 2013
@@ -183,7 +183,7 @@ void Commit::addInsert(SourceLocation Or
data.Kind = Act_Insert;
data.OrigLoc = OrigLoc;
data.Offset = Offs;
- data.Text = text;
+ data.Text = copyString(text);
data.BeforePrev = beforePreviousInsertions;
CachedEdits.push_back(data);
}
Modified: cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp?rev=185873&r1=185872&r2=185873&view=diff
==============================================================================
--- cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp (original)
+++ cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp Mon Jul 8 16:42:08 2013
@@ -358,7 +358,33 @@ bool edit::rewriteToObjCLiteralSyntax(co
bool edit::rewriteToObjCProperty(const ObjCMethodDecl *Getter,
const ObjCMethodDecl *Setter,
const NSAPI &NS, Commit &commit) {
- return false;
+ std::string PropertyString = "@property";
+ const ParmVarDecl *argDecl = *Setter->param_begin();
+ QualType ArgType = argDecl->getType();
+ Qualifiers::ObjCLifetime propertyLifetime = ArgType.getObjCLifetime();
+ if (propertyLifetime != Qualifiers::OCL_None) {
+ PropertyString += "(";
+ if (propertyLifetime == Qualifiers::OCL_Strong)
+ PropertyString += "strong";
+ else if (propertyLifetime == Qualifiers::OCL_Weak)
+ PropertyString += "weak";
+ else
+ PropertyString += "unsafe_unretained";
+ PropertyString += ")";
+ }
+ QualType PropQT = Getter->getResultType();
+ PropertyString += " ";
+ PropertyString += PropQT.getAsString(NS.getASTContext().getPrintingPolicy());
+ PropertyString += " ";
+ PropertyString += Getter->getNameAsString();
+ 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));
+ return true;
}
/// \brief Returns true if the immediate message arguments of \c Msg should not
Added: cfe/trunk/test/ARCMT/objcmt-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m?rev=185873&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m (added)
+++ cfe/trunk/test/ARCMT/objcmt-property.m Mon Jul 8 16:42:08 2013
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -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
+
+ at class NSString;
+ at interface NSObject @end
+
+ at interface I : NSObject {
+ int ivarVal;
+}
+- (void) setWeakProp : (NSString *__weak)Val;
+- (NSString *__weak) WeakProp;
+
+- (NSString *) StrongProp;
+- (void) setStrongProp : (NSString *)Val;
+ at end
+
+ at implementation I
+ at end
Added: cfe/trunk/test/ARCMT/objcmt-property.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-property.m.result?rev=185873&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-property.m.result (added)
+++ cfe/trunk/test/ARCMT/objcmt-property.m.result Mon Jul 8 16:42:08 2013
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-literals -objcmt-migrate-subscripting -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
+
+ at class NSString;
+ at interface NSObject @end
+
+ at interface I : NSObject {
+ int ivarVal;
+}
+
+ at property(weak) NSString *__weak WeakProp;
+
+ at property(strong) NSString * StrongProp;
+
+ at end
+
+ at implementation I
+ at end
More information about the cfe-commits
mailing list