forked from OSchip/llvm-project
[Objective-C migrator] replace candidate user setter/getter with
their equivalent property declaration. wip. llvm-svn: 185873
This commit is contained in:
parent
0176708e85
commit
bfaabe40e7
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ void ObjCMigrateASTConsumer::migrateObjCInterfaceDecl(ASTContext &Ctx,
|
|||
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);
|
||||
|
|
|
@ -183,7 +183,7 @@ void Commit::addInsert(SourceLocation OrigLoc, FileOffset Offs, StringRef text,
|
|||
data.Kind = Act_Insert;
|
||||
data.OrigLoc = OrigLoc;
|
||||
data.Offset = Offs;
|
||||
data.Text = text;
|
||||
data.Text = copyString(text);
|
||||
data.BeforePrev = beforePreviousInsertions;
|
||||
CachedEdits.push_back(data);
|
||||
}
|
||||
|
|
|
@ -358,7 +358,33 @@ bool edit::rewriteToObjCLiteralSyntax(const ObjCMessageExpr *Msg,
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
||||
@class NSString;
|
||||
@interface NSObject @end
|
||||
|
||||
@interface I : NSObject {
|
||||
int ivarVal;
|
||||
}
|
||||
- (void) setWeakProp : (NSString *__weak)Val;
|
||||
- (NSString *__weak) WeakProp;
|
||||
|
||||
- (NSString *) StrongProp;
|
||||
- (void) setStrongProp : (NSString *)Val;
|
||||
@end
|
||||
|
||||
@implementation I
|
||||
@end
|
|
@ -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
|
||||
|
||||
@class NSString;
|
||||
@interface NSObject @end
|
||||
|
||||
@interface I : NSObject {
|
||||
int ivarVal;
|
||||
}
|
||||
|
||||
@property(weak) NSString *__weak WeakProp;
|
||||
|
||||
@property(strong) NSString * StrongProp;
|
||||
|
||||
@end
|
||||
|
||||
@implementation I
|
||||
@end
|
Loading…
Reference in New Issue