From: Fariborz Jahanian Date: Thu, 17 Oct 2013 23:13:13 +0000 (+0000) Subject: ObjectiveC migrator. Minor clean up of my last patch. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d33884f1e2e3189ee2db75cc72d90ea854f6bc68;p=clang ObjectiveC migrator. Minor clean up of my last patch. No functional change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192933 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 8356fb6592..382bab759a 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -575,7 +575,7 @@ static bool rewriteToNSEnumDecl(const EnumDecl *EnumDcl, return false; } -static bool rewriteToNSMacroDecl(const EnumDecl *EnumDcl, +static void rewriteToNSMacroDecl(const EnumDecl *EnumDcl, const TypedefDecl *TypedefDcl, const NSAPI &NS, edit::Commit &commit, bool IsNSIntegerType) { @@ -587,7 +587,6 @@ static bool rewriteToNSMacroDecl(const EnumDecl *EnumDcl, commit.replace(R, ClassString); SourceLocation TypedefLoc = TypedefDcl->getLocEnd(); commit.remove(SourceRange(TypedefLoc, TypedefLoc)); - return true; } static bool UseNSOptionsMacro(Preprocessor &PP, ASTContext &Ctx, @@ -1527,26 +1526,27 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { migrateNSEnumDecl(Ctx, ED, /*TypedefDecl */0); } else if (const TypedefDecl *TD = dyn_cast(*D)) { - if (ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros) { - DeclContext::decl_iterator N = D; + if (!(ASTMigrateActions & FrontendOptions::ObjCMT_NsMacros)) + continue; + DeclContext::decl_iterator N = D; + if (++N == DEnd) + continue; + if (const EnumDecl *ED = dyn_cast(*N)) { if (++N != DEnd) - if (const EnumDecl *ED = dyn_cast(*N)) { - if (++N != DEnd) { - if (const TypedefDecl *TD1 = dyn_cast(*N)) { - if (migrateNSEnumDecl(Ctx, ED, TD1)) { - ++D; ++D; - CacheObjCNSIntegerTypedefed(TD); - continue; - } - } - } - if (migrateNSEnumDecl(Ctx, ED, TD)) { - ++D; + if (const TypedefDecl *TDF = dyn_cast(*N)) { + // prefer typedef-follows-enum to enum-follows-typedef pattern. + if (migrateNSEnumDecl(Ctx, ED, TDF)) { + ++D; ++D; + CacheObjCNSIntegerTypedefed(TD); continue; } } - CacheObjCNSIntegerTypedefed(TD); + if (migrateNSEnumDecl(Ctx, ED, TD)) { + ++D; + continue; + } } + CacheObjCNSIntegerTypedefed(TD); } else if (const FunctionDecl *FD = dyn_cast(*D)) { if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation)