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..74dd503f06832d694e7e022195077539fcfaecf7 |
--- /dev/null |
+++ b/tools/clang/BindMigrate/BindMigrateAction.cpp |
@@ -0,0 +1,121 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include <memory> |
+#include <string> |
+#include <sstream> |
+ |
+#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 "BindMigrateOptions.h" |
+ |
+using namespace std; |
+ |
+namespace clang { |
+ |
+void SplitString(const string &input, char delim, vector<string>* output) { |
+ stringstream stream(input); |
+ string arg; |
+ while(getline(stream, arg, delim)) { |
+ output->push_back(arg); |
+ } |
+} |
+ |
+class BindMigrateAction : public PluginASTAction { |
+ public: |
+ BindMigrateAction() { |
+ } |
+ |
+ virtual ~BindMigrateAction() { |
+ } |
+ |
+ protected: |
+ ASTConsumer *CreateASTConsumer(CompilerInstance &instance, llvm::StringRef) { |
+ return new BindMigrateConsumer(&instance, options_); |
+ } |
+ |
+ virtual bool BeginInvocation(CompilerInstance &instance) { |
+ return true; |
+ } |
+ |
+ virtual bool ParseArgs(const CompilerInstance &instance, |
+ const std::vector<std::string>& args) { |
+ if (!instance.getLangOpts().CPlusPlus) { |
+ return false; |
+ } |
+ for (unsigned i = 0, e = args.size(); i != e; ++i) { |
+ size_t equal_pos = args[i].find("="); |
+ if (equal_pos == string::npos) { |
+ Diagnostic &diagnostics = instance.getDiagnostics(); |
+ unsigned daig_id = diagnostics.getCustomDiagID( |
+ Diagnostic::Error, "invalid argument '" + args[i] + "'"); |
+ diagnostics.Report(daig_id); |
+ continue; |
+ } |
+ |
+ string optname = args[i].substr(0, equal_pos); |
+ string optval = args[i].substr(equal_pos + 1); |
+ |
+ if (optname == "out-dir") { |
+ if (optval.empty()) { |
+ Diagnostic &diagnostics = instance.getDiagnostics(); |
+ unsigned daig_id = diagnostics.getCustomDiagID( |
+ Diagnostic::Error, "out-dir cannot be empty '" + args[i] + "'"); |
+ diagnostics.Report(daig_id); |
+ continue; |
+ } |
+ options_.out_dir = optval; |
+ } else if (optname == "only-path-prefix") { |
+ if (optval.empty()) { |
+ Diagnostic &diagnostics = instance.getDiagnostics(); |
+ unsigned daig_id = diagnostics.getCustomDiagID( |
+ Diagnostic::Error, |
+ "only-path-prefix should be comma separate list: '" + |
+ args[i] + "'"); |
+ diagnostics.Report(daig_id); |
+ continue; |
+ } |
+ SplitString(optval, ',', &options_.only_path_prefix); |
+ } else if (optname == "only_types") { |
+ if (optval.empty()) { |
+ Diagnostic &diagnostics = instance.getDiagnostics(); |
+ unsigned daig_id = diagnostics.getCustomDiagID( |
+ Diagnostic::Error, |
+ "only-types should be comma separate list: '" + args[i] + "'"); |
+ diagnostics.Report(daig_id); |
+ continue; |
+ } |
+ SplitString(optval, ',', &options_.only_types); |
+ } else if (optname == "ignore-path-prefix") { |
+ if (optval.empty()) { |
+ Diagnostic &diagnostics = instance.getDiagnostics(); |
+ unsigned daig_id = diagnostics.getCustomDiagID( |
+ Diagnostic::Error, |
+ "ignore-path-prefix should be comma separate list: '" + |
+ args[i] + "'"); |
+ diagnostics.Report(daig_id); |
+ continue; |
+ } |
+ SplitString(optval, ',', &options_.ignore_path_prefix); |
+ } else if (optname == "mode") { |
+ options_.mode = optval; |
+ } |
+ } |
+ |
+ return true; |
+ } |
+ |
+ private: |
+ BindMigrateOptions options_; |
+}; |
+ |
+} // namespace clang |
+ |
+static clang::FrontendPluginRegistry::Add<clang::BindMigrateAction> |
+X("bind-migrate", "Migrate old callback constructs to base::Bind."); |