[llvm-branch-commits] [cfe-branch] r159526 - /cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp

Manuel Klimek klimek at google.com
Mon Jul 2 05:58:51 PDT 2012


Author: klimek
Date: Mon Jul  2 07:58:51 2012
New Revision: 159526

URL: http://llvm.org/viewvc/llvm-project?rev=159526&view=rev
Log:
Fixes the style tool to use source locations for the token instead of a range.
Due to the heavy use of macros the ranges can fall into different expansion depths.


Modified:
    cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp

Modified: cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp?rev=159526&r1=159525&r2=159526&view=diff
==============================================================================
--- cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp (original)
+++ cfe/branches/tooling/tools/fix-llvm-style/FixLLVMStyle.cpp Mon Jul  2 07:58:51 2012
@@ -121,7 +121,7 @@
 class FixLLVMStyle: public ast_matchers::MatchFinder::MatchCallback {
  public:
   FixLLVMStyle(tooling::Replacements *Replace)
-      : Replace(Replace), EditFilesExpression(".*/Refactoring.*|.*tools/clang/tools/.*") {}
+      : Replace(Replace), EditFilesExpression(".*/ASTMatchers/.*") {}
 
   virtual void run(const ast_matchers::MatchFinder::MatchResult &Result) {
     if (const CallExpr *Call = Result.Nodes.getStmtAs<CallExpr>("call")) {
@@ -152,7 +152,7 @@
         if (Name == "new") Name = "create";
 
         if (const DeclRefExpr *Reference = Result.Nodes.getStmtAs<DeclRefExpr>("ref")) {
-          ReplaceText = Replacement(*Result.SourceManager, Reference, Name);
+          ReplaceText = Replacement(*Result.SourceManager, CharSourceRange::getTokenRange(SourceRange(Reference->getLocation(), Reference->getLocation())), Name);
         } else if (const Expr *Callee = Result.Nodes.getStmtAs<Expr>("callee")) {
           if (const MemberExpr *Member = dyn_cast<MemberExpr>(Callee)) {
   //          llvm::errs() << OldName << "\n";
@@ -187,7 +187,7 @@
     if (EditFilesExpression.match(ReplaceText.getFilePath())) {
       //llvm::errs() << GetPosition(*Result.Nodes.GetDeclAs<NamedDecl>("declaration"), *Result.SourceManager) << "\n";
       //llvm::errs
-      llvm::errs() << ReplaceText.getFilePath() << ":" << ReplaceText.getOffset() << ", " << ReplaceText.getLength() << ": s/" << OldName << "/" << Name << "/g;\n";
+      llvm::outs() << ReplaceText.getFilePath() << ":" << ReplaceText.getOffset() << ", " << ReplaceText.getLength() << ": s/" << OldName << "/" << Name << "/g;\n";
       Replace->insert(ReplaceText);
     } else {
 //     llvm::errs() << ReplaceText.GetFilePath() << ":" << ReplaceText.GetOffset() << ", " << ReplaceText.GetLength() << ": s/" << OldName << "/" << Name << "/g;\n";
@@ -286,25 +286,18 @@
   tooling::RefactoringTool Tool(*Compilations, SourcePaths);
   ast_matchers::MatchFinder Finder;
 
-  DeclarationMatcher FunctionMatch = Function(Not(HasReturnType(HasClassDeclaration(
-    AnyOf(HasName2("internal::Matcher"),
-                HasName("internal::PolymorphicMatcherWithParam0"),
-                HasName("internal::PolymorphicMatcherWithParam1"),
-                HasName("internal::PolymorphicMatcherWithParam2")
-        )))));
-
   FixLLVMStyle Callback(&Tool.getReplacements());
   Finder.addMatcher(StatementMatcher(AnyOf(
-      StatementMatcher(Id("ref", DeclarationReference(To(Id("declaration", FunctionMatch))))),
-      Call(Callee(Id("declaration", FunctionMatch)),
+      StatementMatcher(Id("ref", DeclarationReference(To(Id("declaration", Function()))))),
+      Call(Callee(Id("declaration", Function())),
            Callee(Id("callee", Expression()))))),
       &Callback);
 
   Finder.addMatcher(
       DeclarationMatcher(AnyOf(
-        Id("declaration", UsingDeclaration(HasAnyUsingShadowDeclaration(HasTargetDeclaration(FunctionMatch)))),
+        Id("declaration", UsingDeclaration(HasAnyUsingShadowDeclaration(HasTargetDeclaration(Function())))),
         AllOf(
-          Id("declaration", FunctionMatch),
+          Id("declaration", Function()),
           Not(Constructor())))
         ),
       &Callback);





More information about the llvm-branch-commits mailing list