Skip to content
Snippets Groups Projects
Commit 8172a0a5 authored by Hyrum Wright's avatar Hyrum Wright
Browse files

[clang-tidy] NFC: Negate the name and semantics of the isNotInMacro function.

This function is always used in a context where its result was also
negated, which made for confusing naming and code.

llvm-svn: 355702
parent e73ae9a1
No related branches found
No related tags found
No related merge requests found
...@@ -43,8 +43,7 @@ void DurationComparisonCheck::check(const MatchFinder::MatchResult &Result) { ...@@ -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 // 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 // we unconditionally try and rewrite both, and let the rewriter determine
// if nothing needs to be done. // if nothing needs to be done.
if (!isNotInMacro(Result, Binop->getLHS()) || if (isInMacro(Result, Binop->getLHS()) || isInMacro(Result, Binop->getRHS()))
!isNotInMacro(Result, Binop->getRHS()))
return; return;
std::string LhsReplacement = std::string LhsReplacement =
rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS()); rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS());
......
...@@ -37,7 +37,7 @@ void DurationConversionCastCheck::check( ...@@ -37,7 +37,7 @@ void DurationConversionCastCheck::check(
const auto *MatchedCast = const auto *MatchedCast =
Result.Nodes.getNodeAs<ExplicitCastExpr>("cast_expr"); Result.Nodes.getNodeAs<ExplicitCastExpr>("cast_expr");
if (!isNotInMacro(Result, MatchedCast)) if (isInMacro(Result, MatchedCast))
return; return;
const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>("func_decl"); const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>("func_decl");
......
...@@ -302,9 +302,9 @@ std::string rewriteExprFromNumberToTime( ...@@ -302,9 +302,9 @@ std::string rewriteExprFromNumberToTime(
.str(); .str();
} }
bool isNotInMacro(const MatchFinder::MatchResult &Result, const Expr *E) { bool isInMacro(const MatchFinder::MatchResult &Result, const Expr *E) {
if (!E->getBeginLoc().isMacroID()) if (!E->getBeginLoc().isMacroID())
return true; return false;
SourceLocation Loc = E->getBeginLoc(); SourceLocation Loc = E->getBeginLoc();
// We want to get closer towards the initial macro typed into the source only // 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) { ...@@ -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." // because Clang comment says it "should not generally be used by clients."
Loc = Result.SourceManager->getImmediateMacroCallerLoc(Loc); Loc = Result.SourceManager->getImmediateMacroCallerLoc(Loc);
} }
return !Loc.isMacroID(); return Loc.isMacroID();
} }
} // namespace abseil } // namespace abseil
......
...@@ -91,10 +91,10 @@ std::string rewriteExprFromNumberToTime( ...@@ -91,10 +91,10 @@ std::string rewriteExprFromNumberToTime(
const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale, const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale,
const Expr *Node); 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. /// one. In the both cases, we often want to do the transformation.
bool isNotInMacro(const ast_matchers::MatchFinder::MatchResult &Result, bool isInMacro(const ast_matchers::MatchFinder::MatchResult &Result,
const Expr *E); const Expr *E);
AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>, AST_MATCHER_FUNCTION(ast_matchers::internal::Matcher<FunctionDecl>,
DurationConversionFunction) { DurationConversionFunction) {
......
...@@ -44,7 +44,7 @@ void DurationUnnecessaryConversionCheck::check( ...@@ -44,7 +44,7 @@ void DurationUnnecessaryConversionCheck::check(
const auto *OuterCall = Result.Nodes.getNodeAs<Expr>("call"); const auto *OuterCall = Result.Nodes.getNodeAs<Expr>("call");
const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg"); const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg");
if (!isNotInMacro(Result, OuterCall)) if (isInMacro(Result, OuterCall))
return; return;
diag(OuterCall->getBeginLoc(), "remove unnecessary absl::Duration conversions") diag(OuterCall->getBeginLoc(), "remove unnecessary absl::Duration conversions")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment