[clang-tools-extra] r289464 - [clang-move] Use appendArgumentsAdjuster for adding extra arguments

Alexander Shaposhnikov via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 12 11:56:37 PST 2016


Author: alexshap
Date: Mon Dec 12 13:56:37 2016
New Revision: 289464

URL: http://llvm.org/viewvc/llvm-project?rev=289464&view=rev
Log:
[clang-move] Use appendArgumentsAdjuster for adding extra arguments

1. Remove some boilerplate code for appending -fparse-all-comments to the list of arguments.
2. Run clang-format -i against ClangMoveMain.cpp.

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D27669

Modified:
    clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp

Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp?rev=289464&r1=289463&r2=289464&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp (original)
+++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Mon Dec 12 13:56:37 2016
@@ -61,19 +61,19 @@ cl::opt<std::string>
     NewCC("new_cc", cl::desc("The relative/absolute file path of new cc."),
           cl::cat(ClangMoveCategory));
 
-cl::opt<bool> OldDependOnNew(
-    "old_depend_on_new",
-    cl::desc(
-        "Whether old header will depend on new header. If true, clang-move will "
-        "add #include of new header to old header."),
-    cl::init(false), cl::cat(ClangMoveCategory));
-
-cl::opt<bool> NewDependOnOld(
-    "new_depend_on_old",
-    cl::desc(
-        "Whether new header will depend on old header. If true, clang-move will "
-        "add #include of old header to new header."),
-    cl::init(false), cl::cat(ClangMoveCategory));
+cl::opt<bool>
+    OldDependOnNew("old_depend_on_new",
+                   cl::desc("Whether old header will depend on new header. If "
+                            "true, clang-move will "
+                            "add #include of new header to old header."),
+                   cl::init(false), cl::cat(ClangMoveCategory));
+
+cl::opt<bool>
+    NewDependOnOld("new_depend_on_old",
+                   cl::desc("Whether new header will depend on old header. If "
+                            "true, clang-move will "
+                            "add #include of old header to new header."),
+                   cl::init(false), cl::cat(ClangMoveCategory));
 
 cl::opt<std::string>
     Style("style",
@@ -95,18 +95,7 @@ cl::opt<bool> DumpDecls(
 
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
-  // Add "-fparse-all-comments" compile option to make clang parse all comments,
-  // otherwise, ordinary comments like "//" and "/*" won't get parsed (This is
-  // a bit of hacky).
-  std::vector<std::string> ExtraArgs(argv, argv + argc);
-  ExtraArgs.insert(ExtraArgs.begin() + 1, "-extra-arg=-fparse-all-comments");
-  std::unique_ptr<const char *[]> RawExtraArgs(
-      new const char *[ExtraArgs.size()]);
-  for (size_t i = 0; i < ExtraArgs.size(); ++i)
-    RawExtraArgs[i] = ExtraArgs[i].c_str();
-  int Argc = argc + 1;
-  tooling::CommonOptionsParser OptionsParser(Argc, RawExtraArgs.get(),
-                                             ClangMoveCategory);
+  tooling::CommonOptionsParser OptionsParser(argc, argv, ClangMoveCategory);
 
   if (OldDependOnNew && NewDependOnOld) {
     llvm::errs() << "Provide either --old_depend_on_new or "
@@ -117,6 +106,9 @@ int main(int argc, const char **argv) {
 
   tooling::RefactoringTool Tool(OptionsParser.getCompilations(),
                                 OptionsParser.getSourcePathList());
+  // Add "-fparse-all-comments" compile option to make clang parse all comments.
+  Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(
+      "-fparse-all-comments", ArgumentInsertPosition::BEGIN));
   move::MoveDefinitionSpec Spec;
   Spec.Names = {Names.begin(), Names.end()};
   Spec.OldHeader = OldHeader;




More information about the cfe-commits mailing list