Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | |
| 2 // Author: ajwong@google.com (Albert Wong) | |
| 3 | |
| 4 #include <string> | |
| 5 | |
| 6 #include "clang/Basic/Diagnostic.h" | |
| 7 #include "clang/Frontend/CompilerInstance.h" | |
| 8 #include "clang/Frontend/FrontendAction.h" | |
| 9 #include "clang/Frontend/FrontendPluginRegistry.h" | |
| 10 #include "llvm/Support/raw_ostream.h" | |
| 11 | |
| 12 #include "BindMigrateConsumer.h" | |
| 13 #include "FileRemapper.h" | |
| 14 | |
| 15 using namespace std; | |
| 16 | |
| 17 namespace clang { | |
| 18 | |
| 19 class BindMigrateAction : public PluginASTAction { | |
| 20 protected: | |
| 21 ASTConsumer *CreateASTConsumer(CompilerInstance &instance, llvm::StringRef) { | |
| 22 return new BindMigrateConsumer(&instance, &remapper_); | |
| 23 } | |
| 24 | |
| 25 bool ParseArgs(const CompilerInstance &instance, | |
| 26 const std::vector<std::string>& args) { | |
| 27 for (unsigned i = 0, e = args.size(); i != e; ++i) { | |
| 28 llvm::errs() << "BindMigrate arg = " << args[i] << "\n"; | |
| 29 | |
| 30 // Example error handling. | |
| 31 if (args[i] == "-an-error") { | |
| 32 Diagnostic &diagnostics = instance.getDiagnostics(); | |
| 33 unsigned daig_id = diagnostics.getCustomDiagID( | |
| 34 Diagnostic::Error, "invalid argument '" + args[i] + "'"); | |
| 35 diagnostics.Report(daig_id); | |
| 36 return false; | |
| 37 } | |
| 38 } | |
| 39 if (args.size() && args[0] == "help") { | |
| 40 PrintHelp(llvm::errs()); | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 remapper_.initFromDisk("/tmp/clang_out", | |
| 45 instance.getDiagnostics(), | |
| 46 /*ignoreIfFilesChanges=*/true); | |
| 47 | |
| 48 return true; | |
| 49 } | |
| 50 | |
| 51 void PrintHelp(llvm::raw_ostream& ros) { | |
| 52 ros << "Help for BindMigrate plugin goes here\n"; | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 arcmt_hack::FileRemapper remapper_; | |
|
Nico
2011/09/16 03:00:54
:-)
If you find that any parts of the ARC stuff a
awong
2011/09/16 10:24:32
FileRemapper is generally useful. So is the rewri
| |
| 57 }; | |
| 58 | |
| 59 } // namespace clang | |
| 60 | |
| 61 static clang::FrontendPluginRegistry::Add<clang::BindMigrateAction> | |
| 62 X("bind-migrate", "Migrate old callback constructs to base::Bind."); | |
| OLD | NEW |