diff options
Diffstat (limited to 'lib/ARCMigrate/ObjCMT.cpp')
-rw-r--r-- | lib/ARCMigrate/ObjCMT.cpp | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index dfe14e2..57fac03 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -8,19 +8,21 @@ //===----------------------------------------------------------------------===// #include "clang/ARCMigrate/ARCMTActions.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Frontend/MultiplexConsumer.h" +#include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/RecursiveASTVisitor.h" #include "clang/AST/NSAPI.h" -#include "clang/AST/ASTConsumer.h" -#include "clang/Edit/Rewriters.h" -#include "clang/Edit/EditedSource.h" +#include "clang/AST/ParentMap.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/Basic/FileManager.h" #include "clang/Edit/Commit.h" +#include "clang/Edit/EditedSource.h" #include "clang/Edit/EditsReceiver.h" -#include "clang/Rewrite/Core/Rewriter.h" +#include "clang/Edit/Rewriters.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/MultiplexConsumer.h" +#include "clang/Lex/PPConditionalDirectiveRecord.h" #include "clang/Lex/Preprocessor.h" -#include "clang/Basic/FileManager.h" +#include "clang/Rewrite/Core/Rewriter.h" #include "llvm/ADT/SmallString.h" using namespace clang; @@ -35,11 +37,11 @@ public: std::string MigrateDir; bool MigrateLiterals; bool MigrateSubscripting; - llvm::OwningPtr<NSAPI> NSAPIObj; - llvm::OwningPtr<edit::EditedSource> Editor; + OwningPtr<NSAPI> NSAPIObj; + OwningPtr<edit::EditedSource> Editor; FileRemapper &Remapper; FileManager &FileMgr; - const PreprocessingRecord *PPRec; + const PPConditionalDirectiveRecord *PPRec; bool IsOutputFile; ObjCMigrateASTConsumer(StringRef migrateDir, @@ -47,7 +49,7 @@ public: bool migrateSubscripting, FileRemapper &remapper, FileManager &fileMgr, - const PreprocessingRecord *PPRec, + const PPConditionalDirectiveRecord *PPRec, bool isOutputFile = false) : MigrateDir(migrateDir), MigrateLiterals(migrateLiterals), @@ -93,6 +95,9 @@ ObjCMigrateAction::ObjCMigrateAction(FrontendAction *WrappedAction, ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { + PPConditionalDirectiveRecord * + PPRec = new PPConditionalDirectiveRecord(CompInst->getSourceManager()); + CompInst->getPreprocessor().addPPCallbacks(PPRec); ASTConsumer * WrappedConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile); ASTConsumer *MTConsumer = new ObjCMigrateASTConsumer(MigrateDir, @@ -100,7 +105,7 @@ ASTConsumer *ObjCMigrateAction::CreateASTConsumer(CompilerInstance &CI, MigrateSubscripting, Remapper, CompInst->getFileManager(), - CompInst->getPreprocessor().getPreprocessingRecord()); + PPRec); ASTConsumer *Consumers[] = { MTConsumer, WrappedConsumer }; return new MultiplexConsumer(Consumers); } @@ -110,17 +115,17 @@ bool ObjCMigrateAction::BeginInvocation(CompilerInstance &CI) { /*ignoreIfFilesChanges=*/true); CompInst = &CI; CI.getDiagnostics().setIgnoreAllWarnings(true); - CI.getPreprocessorOpts().DetailedRecord = true; - CI.getPreprocessorOpts().DetailedRecordConditionalDirectives = true; return true; } namespace { class ObjCMigrator : public RecursiveASTVisitor<ObjCMigrator> { ObjCMigrateASTConsumer &Consumer; + ParentMap &PMap; public: - ObjCMigrator(ObjCMigrateASTConsumer &consumer) : Consumer(consumer) { } + ObjCMigrator(ObjCMigrateASTConsumer &consumer, ParentMap &PMap) + : Consumer(consumer), PMap(PMap) { } bool shouldVisitTemplateInstantiations() const { return false; } bool shouldWalkTypesOfTypeLocs() const { return false; } @@ -128,7 +133,7 @@ public: bool VisitObjCMessageExpr(ObjCMessageExpr *E) { if (Consumer.MigrateLiterals) { edit::Commit commit(*Consumer.Editor); - edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit); + edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit, &PMap); Consumer.Editor->commit(commit); } @@ -151,6 +156,23 @@ public: return WalkUpFromObjCMessageExpr(E); } }; + +class BodyMigrator : public RecursiveASTVisitor<BodyMigrator> { + ObjCMigrateASTConsumer &Consumer; + OwningPtr<ParentMap> PMap; + +public: + BodyMigrator(ObjCMigrateASTConsumer &consumer) : Consumer(consumer) { } + + bool shouldVisitTemplateInstantiations() const { return false; } + bool shouldWalkTypesOfTypeLocs() const { return false; } + + bool TraverseStmt(Stmt *S) { + PMap.reset(new ParentMap(S)); + ObjCMigrator(Consumer, *PMap).TraverseStmt(S); + return true; + } +}; } void ObjCMigrateASTConsumer::migrateDecl(Decl *D) { @@ -159,7 +181,7 @@ void ObjCMigrateASTConsumer::migrateDecl(Decl *D) { if (isa<ObjCMethodDecl>(D)) return; // Wait for the ObjC container declaration. - ObjCMigrator(*this).TraverseDecl(D); + BodyMigrator(*this).TraverseDecl(D); } namespace { @@ -191,13 +213,13 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { RewriteBuffer &buf = I->second; const FileEntry *file = Ctx.getSourceManager().getFileEntryForID(FID); assert(file); - llvm::SmallString<512> newText; + SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); buf.write(vecOS); vecOS.flush(); llvm::MemoryBuffer *memBuf = llvm::MemoryBuffer::getMemBufferCopy( StringRef(newText.data(), newText.size()), file->getName()); - llvm::SmallString<64> filePath(file->getName()); + SmallString<64> filePath(file->getName()); FileMgr.FixupRelativePath(filePath); Remapper.remap(filePath.str(), memBuf); } @@ -211,18 +233,19 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { bool MigrateSourceAction::BeginInvocation(CompilerInstance &CI) { CI.getDiagnostics().setIgnoreAllWarnings(true); - CI.getPreprocessorOpts().DetailedRecord = true; - CI.getPreprocessorOpts().DetailedRecordConditionalDirectives = true; return true; } ASTConsumer *MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { + PPConditionalDirectiveRecord * + PPRec = new PPConditionalDirectiveRecord(CI.getSourceManager()); + CI.getPreprocessor().addPPCallbacks(PPRec); return new ObjCMigrateASTConsumer(CI.getFrontendOpts().OutputFile, /*MigrateLiterals=*/true, /*MigrateSubscripting=*/true, Remapper, CI.getFileManager(), - CI.getPreprocessor().getPreprocessingRecord(), + PPRec, /*isOutputFile=*/true); } |