[clang-tools-extra] r348583 - [clang-tidy] Remove duplicated getText implementation, NFC

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 7 03:25:37 PST 2018


Author: hokein
Date: Fri Dec  7 03:25:37 2018
New Revision: 348583

URL: http://llvm.org/viewvc/llvm-project?rev=348583&view=rev
Log:
[clang-tidy] Remove duplicated getText implementation, NFC

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp?rev=348583&r1=348582&r2=348583&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantStringCStrCheck.cpp Fri Dec  7 03:25:37 2018
@@ -13,6 +13,7 @@
 
 #include "RedundantStringCStrCheck.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
 
 using namespace clang::ast_matchers;
 
@@ -22,14 +23,6 @@ namespace readability {
 
 namespace {
 
-template <typename T>
-StringRef getText(const ast_matchers::MatchFinder::MatchResult &Result,
-                  T const &Node) {
-  return Lexer::getSourceText(
-      CharSourceRange::getTokenRange(Node.getSourceRange()),
-      *Result.SourceManager, Result.Context->getLangOpts());
-}
-
 // Return true if expr needs to be put in parens when it is an argument of a
 // prefix unary operator, e.g. when it is a binary or ternary operator
 // syntactically.
@@ -54,10 +47,12 @@ formatDereference(const ast_matchers::Ma
   if (const auto *Op = dyn_cast<clang::UnaryOperator>(&ExprNode)) {
     if (Op->getOpcode() == UO_AddrOf) {
       // Strip leading '&'.
-      return getText(Result, *Op->getSubExpr()->IgnoreParens());
+      return tooling::fixit::getText(*Op->getSubExpr()->IgnoreParens(),
+                                     *Result.Context);
     }
   }
-  StringRef Text = getText(Result, ExprNode);
+  StringRef Text = tooling::fixit::getText(ExprNode, *Result.Context);
+
   if (Text.empty())
     return std::string();
   // Add leading '*'.
@@ -185,7 +180,8 @@ void RedundantStringCStrCheck::check(con
   // Replace the "call" node with the "arg" node, prefixed with '*'
   // if the call was using '->' rather than '.'.
   std::string ArgText =
-      Arrow ? formatDereference(Result, *Arg) : getText(Result, *Arg).str();
+      Arrow ? formatDereference(Result, *Arg)
+            : tooling::fixit::getText(*Arg, *Result.Context).str();
   if (ArgText.empty())
     return;
 




More information about the cfe-commits mailing list