[PATCH] Clang Rename Tool

Matthew Plant mplant at google.com
Wed Aug 13 11:19:25 PDT 2014

Comment at: clang-rename/ClangRename.cpp:16-42
@@ +15,29 @@
+#include "USRFindingAction.h"
+#include "RenamingAction.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/Frontend/CommandLineSourceLoc.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Parse/ParseAST.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/Support/Host.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string>
+#include <vector>
Manuel Klimek wrote:
> Matthew Plant wrote:
> > Manuel Klimek wrote:
> > > Are all of these still needed?
> > Not entirely sure. The only real way to determine is to remove one at a time, or manually go through and determine if each is actually used.
> > Isn't there a clang tool for this? remove-unused-headers or something?
> Not yet :) Patches welcome!
Oh man I'll totally do that at some point. 

Comment at: clang-rename/ClangRename.cpp:141-145
@@ +140,7 @@
+  const auto &USRs = USRAction.getUSRs();
+  const auto &PrevName = USRAction.getUSRSpelling();
+  if (PrevName.empty())
+    // An error should have already been printed.
+    exit(1);
Manuel Klimek wrote:
> We really need to convert this to Diagnostics (fine in a follow-up patch though).
That sounds fine for a follow up patch.

Comment at: clang-rename/USRFinder.cpp:41
@@ +40,3 @@
+                                      const SourceLocation Point,
+                                      const clang::NamedDecl **Result)
+      : Result(nullptr), SourceMgr(SourceMgr), LangOpts(LangOpts),
Manuel Klimek wrote:
> Use a class member and getter for the result.
I already did! Funnily enough, you'll notice the Result argument is discarded, and the Result member is a single pointer! I just forgot to remove the constructor argument. oops!

Comment at: clang-rename/USRLocFinder.cpp:43-47
@@ +42,7 @@
+    if (getUSRForDecl(Decl) == USR) {
+      // Because we traverse the AST from top to bottom, it follows that the
+      // current locations must be further down (or right) than the previous one
+      // inspected. This has the effect of keeping LocationsFound sorted by
+      // line first column second with no effort of our own.
+      // This is correct as of 2014-06-27
+      LocationsFound.push_back(Decl->getLocation());
Manuel Klimek wrote:
> This somehow sneaked back in?
Yeah oops.


More information about the cfe-commits mailing list