ObjectiveC migrator: some refactoring to reduce

code size.

llvm-svn: 189070
This commit is contained in:
Fariborz Jahanian 2013-08-22 21:40:15 +00:00
parent a74e82aad8
commit 4f64dd2baf
1 changed files with 15 additions and 38 deletions

View File

@ -49,8 +49,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
ObjCMethodDecl *OM, ObjCMethodDecl *OM,
ObjCInstanceTypeFamily OIT_Family = OIT_None); ObjCInstanceTypeFamily OIT_Family = OIT_None);
void migrateCFFunctions(ASTContext &Ctx, void migrateCFAnnotation(ASTContext &Ctx, const Decl *Decl);
const FunctionDecl *FuncDecl);
void AnnotateImplicitBridging(ASTContext &Ctx); void AnnotateImplicitBridging(ASTContext &Ctx);
@ -61,9 +60,6 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
bool migrateAddMethodAnnotation(ASTContext &Ctx, bool migrateAddMethodAnnotation(ASTContext &Ctx,
const ObjCMethodDecl *MethodDecl); const ObjCMethodDecl *MethodDecl);
void migrateMethodForCFAnnotation(ASTContext &Ctx,
const ObjCMethodDecl *MethodDecl);
public: public:
std::string MigrateDir; std::string MigrateDir;
bool MigrateLiterals; bool MigrateLiterals;
@ -832,22 +828,24 @@ void ObjCMigrateASTConsumer::AnnotateImplicitBridging(ASTContext &Ctx) {
CFFunctionIBCandidates.clear(); CFFunctionIBCandidates.clear();
} }
void ObjCMigrateASTConsumer::migrateCFFunctions( void ObjCMigrateASTConsumer::migrateCFAnnotation(ASTContext &Ctx, const Decl *Decl) {
ASTContext &Ctx, if (Decl->hasAttr<CFAuditedTransferAttr>()) {
const FunctionDecl *FuncDecl) {
if (FuncDecl->hasAttr<CFAuditedTransferAttr>()) {
assert(CFFunctionIBCandidates.empty() && assert(CFFunctionIBCandidates.empty() &&
"Cannot have audited functions inside user " "Cannot have audited functions/methods inside user "
"provided CF_IMPLICIT_BRIDGING_ENABLE"); "provided CF_IMPLICIT_BRIDGING_ENABLE");
return; return;
} }
// Finction must be annotated first. // Finction must be annotated first.
bool Audited = migrateAddFunctionAnnotation(Ctx, FuncDecl); bool Audited;
if (const FunctionDecl *FuncDecl = dyn_cast<FunctionDecl>(Decl))
Audited = migrateAddFunctionAnnotation(Ctx, FuncDecl);
else
Audited = migrateAddMethodAnnotation(Ctx, cast<ObjCMethodDecl>(Decl));
if (Audited) { if (Audited) {
CFFunctionIBCandidates.push_back(FuncDecl); CFFunctionIBCandidates.push_back(Decl);
if (!FileId) if (!FileId)
FileId = PP.getSourceManager().getFileID(FuncDecl->getLocation()).getHashValue(); FileId = PP.getSourceManager().getFileID(Decl->getLocation()).getHashValue();
} }
else else
AnnotateImplicitBridging(Ctx); AnnotateImplicitBridging(Ctx);
@ -933,31 +931,10 @@ void ObjCMigrateASTConsumer::migrateARCSafeAnnotation(ASTContext &Ctx,
MEnd = CDecl->meth_end(); MEnd = CDecl->meth_end();
M != MEnd; ++M) { M != MEnd; ++M) {
ObjCMethodDecl *Method = (*M); ObjCMethodDecl *Method = (*M);
migrateMethodForCFAnnotation(Ctx, Method); migrateCFAnnotation(Ctx, Method);
} }
} }
void ObjCMigrateASTConsumer::migrateMethodForCFAnnotation(
ASTContext &Ctx,
const ObjCMethodDecl *MethodDecl) {
if (MethodDecl->hasAttr<CFAuditedTransferAttr>()) {
assert(CFFunctionIBCandidates.empty() &&
"Cannot have audited method inside user "
"provided CF_IMPLICIT_BRIDGING_ENABLE");
return;
}
// Method must be annotated first.
bool Audited = migrateAddMethodAnnotation(Ctx, MethodDecl);
if (Audited) {
CFFunctionIBCandidates.push_back(MethodDecl);
if (!FileId)
FileId = PP.getSourceManager().getFileID(MethodDecl->getLocation()).getHashValue();
}
else
AnnotateImplicitBridging(Ctx);
}
bool ObjCMigrateASTConsumer::migrateAddMethodAnnotation(ASTContext &Ctx, bool ObjCMigrateASTConsumer::migrateAddMethodAnnotation(ASTContext &Ctx,
const ObjCMethodDecl *MethodDecl) { const ObjCMethodDecl *MethodDecl) {
if (MethodDecl->hasBody()) if (MethodDecl->hasBody())
@ -1074,7 +1051,7 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
migrateNSEnumDecl(Ctx, ED, TD); migrateNSEnumDecl(Ctx, ED, TD);
} }
else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D)) else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(*D))
migrateCFFunctions(Ctx, FD); migrateCFAnnotation(Ctx, FD);
if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D)) { if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(*D)) {
// migrate methods which can have instancetype as their result type. // migrate methods which can have instancetype as their result type.