Chromium Code Reviews| Index: tools/clang/BindMigrate/BindMigrateAction.cpp |
| diff --git a/tools/clang/BindMigrate/BindMigrateAction.cpp b/tools/clang/BindMigrate/BindMigrateAction.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2bf96180edb799b087f0b3d8ca336a2c385321c8 |
| --- /dev/null |
| +++ b/tools/clang/BindMigrate/BindMigrateAction.cpp |
| @@ -0,0 +1,62 @@ |
| +// Copyright 2011 Google Inc. All Rights Reserved. |
| +// Author: ajwong@google.com (Albert Wong) |
| + |
| +#include <string> |
| + |
| +#include "clang/Basic/Diagnostic.h" |
| +#include "clang/Frontend/CompilerInstance.h" |
| +#include "clang/Frontend/FrontendAction.h" |
| +#include "clang/Frontend/FrontendPluginRegistry.h" |
| +#include "llvm/Support/raw_ostream.h" |
| + |
| +#include "BindMigrateConsumer.h" |
| +#include "FileRemapper.h" |
| + |
| +using namespace std; |
| + |
| +namespace clang { |
| + |
| +class BindMigrateAction : public PluginASTAction { |
| +protected: |
| + ASTConsumer *CreateASTConsumer(CompilerInstance &instance, llvm::StringRef) { |
| + return new BindMigrateConsumer(&instance, &remapper_); |
| + } |
| + |
| + bool ParseArgs(const CompilerInstance &instance, |
| + const std::vector<std::string>& args) { |
| + for (unsigned i = 0, e = args.size(); i != e; ++i) { |
| + llvm::errs() << "BindMigrate arg = " << args[i] << "\n"; |
| + |
| + // Example error handling. |
| + if (args[i] == "-an-error") { |
| + Diagnostic &diagnostics = instance.getDiagnostics(); |
| + unsigned daig_id = diagnostics.getCustomDiagID( |
| + Diagnostic::Error, "invalid argument '" + args[i] + "'"); |
| + diagnostics.Report(daig_id); |
| + return false; |
| + } |
| + } |
| + if (args.size() && args[0] == "help") { |
| + PrintHelp(llvm::errs()); |
| + return true; |
| + } |
| + |
| + remapper_.initFromDisk("/tmp/clang_out", |
| + instance.getDiagnostics(), |
| + /*ignoreIfFilesChanges=*/true); |
| + |
| + return true; |
| + } |
| + |
| + void PrintHelp(llvm::raw_ostream& ros) { |
| + ros << "Help for BindMigrate plugin goes here\n"; |
| + } |
| + |
| + private: |
| + 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
|
| +}; |
| + |
| +} // namespace clang |
| + |
| +static clang::FrontendPluginRegistry::Add<clang::BindMigrateAction> |
| +X("bind-migrate", "Migrate old callback constructs to base::Bind."); |