[clang-tidy] NFC: Negate the name and semantics of the isNotInMacro function.
authorHyrum Wright <hwright@google.com>
Fri, 8 Mar 2019 15:37:15 +0000 (15:37 +0000)
committerHyrum Wright <hwright@google.com>
Fri, 8 Mar 2019 15:37:15 +0000 (15:37 +0000)
This function is always used in a context where its result was also
negated, which made for confusing naming and code.

llvm-svn: 355702

clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp
clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp
clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
clang-tools-extra/clang-tidy/abseil/DurationRewriter.h
clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp

index 337f2ca0a2e15ca30426c169fb66028c713f5f43..3b19e5fd05375f65d6b963c959e6b44ef9454018 100644 (file)
@@ -43,8 +43,7 @@ void DurationComparisonCheck::check(const MatchFinder::MatchResult &Result) {
   // want to handle the case of rewriting both sides. This is much simpler if
   // we unconditionally try and rewrite both, and let the rewriter determine
   // if nothing needs to be done.
-  if (!isNotInMacro(Result, Binop->getLHS()) ||
-      !isNotInMacro(Result, Binop->getRHS()))
+  if (isInMacro(Result, Binop->getLHS()) || isInMacro(Result, Binop->getRHS()))
     return;
   std::string LhsReplacement =
       rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS());
index f0ae82c0b11cd8ca4583955e760f0ff75d795c1a..d9e915542109de5fc2b1d226ffab0f593676d1e5 100644 (file)
@@ -37,7 +37,7 @@ void DurationConversionCastCheck::check(
   const auto *MatchedCast =
       Result.Nodes.getNodeAs<ExplicitCastExpr>("cast_expr");
 
-  if (!isNotInMacro(Result, MatchedCast))
+  if (isInMacro(Result, MatchedCast))
     return;
 
   const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>("func_decl");
index ceee2ec861814b1f1083aabf2c92f37610bf0e9c..3466cdbbdcffe7df5eabdbce99aede77379a0ccf 100644 (file)
@@ -302,9 +302,9 @@ std::string rewriteExprFromNumberToTime(
       .str();
 }
 
-bool isNotInMacro(const MatchFinder::MatchResult &Result, const Expr *E) {
+bool isInMacro(const MatchFinder::MatchResult &Result, const Expr *E) {
   if (!E->getBeginLoc().isMacroID())
-    return true;
+    return false;
 
   SourceLocation Loc = E->getBeginLoc();
   // We want to get closer towards the initial macro typed into the source only
@@ -316,7 +316,7 @@ bool isNotInMacro(const MatchFinder::MatchResult &Result, const Expr *E) {
     // because Clang comment says it "should not generally be used by clients."
     Loc = Result.SourceManager->getImmediateMacroCallerLoc(Loc);
   }
-  return !Loc.isMacroID();
+  return Loc.isMacroID();
 }
 
 } // namespace abseil
index 5b4689f3f08665074481189e844be13c0fbd3820..32f8167cdc2b339004e14d76ae57ad891300366a 100644 (file)
@@ -91,10 +91,10 @@ std::string rewriteExprFromNumberToTime(
     const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale,
     const Expr *Node);
 
-/// Return `true` if `E` is a either: not a macro at all; or an argument to
+/// Return `false` if `E` is a either: not a macro at all; or an argument to
 /// one.  In the both cases, we often want to do the transformation.
-bool isNotInMacro(const ast_matchers::MatchFinder::MatchResult &Result,
-                  const Expr *E);
+bool isInMacro(const ast_matchers::MatchFinder::MatchResult &Result,
+               const Expr *E);
 
 AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>,
                      DurationConversionFunction) {
index 83650cd105d2523a977836867a0d767cd73f97dd..ae7619972c21d8942bfaa3eeae614101eca7f198 100644 (file)
@@ -44,7 +44,7 @@ void DurationUnnecessaryConversionCheck::check(
   const auto *OuterCall = Result.Nodes.getNodeAs<Expr>("call");
   const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg");
 
-  if (!isNotInMacro(Result, OuterCall))
+  if (isInMacro(Result, OuterCall))
     return;
 
   diag(OuterCall->getBeginLoc(), "remove unnecessary absl::Duration conversions")