23 return !clang::Lexer::makeFileCharRange(
24 clang::CharSourceRange::getCharRange(Range),
25 *Result.SourceManager, Result.Context->getLangOpts())
35 return selectFirst<const Expr>(
38 callExpr(hasParent(materializeTemporaryExpr(hasParent(
39 cxxConstructExpr(hasParent(exprWithCleanups(
40 hasParent(varDecl()))))))))
42 callExpr(hasParent(varDecl())).bind(
"e"))),
43 *Node, *Result.Context)) !=
nullptr;
46static bool isArgument(
const MatchFinder::MatchResult &Result,
50 return selectFirst<const Expr>(
54 expr(hasParent(materializeTemporaryExpr(
55 hasParent(cxxConstructExpr(
56 hasParent(callExpr()),
57 unless(hasParent(cxxOperatorCallExpr())))))))
59 expr(hasParent(callExpr()),
60 unless(hasParent(cxxOperatorCallExpr())))
62 *Node, *Result.Context)) !=
nullptr;
65static bool isReturn(
const MatchFinder::MatchResult &Result,
const Expr *Node) {
68 return selectFirst<const Expr>(
71 expr(hasParent(materializeTemporaryExpr(hasParent(
72 cxxConstructExpr(hasParent(exprWithCleanups(
73 hasParent(returnStmt()))))))))
75 expr(hasParent(returnStmt())).bind(
"e"))),
76 *Node, *Result.Context)) !=
nullptr;
94 for (
const char *ScaleName :
95 {
"Hours",
"Minutes",
"Seconds",
"Millis",
"Micros",
"Nanos"}) {
96 std::string TimeInverse = (llvm::Twine(
"ToUnix") + ScaleName).str();
98 assert(Scale &&
"Unknown scale encountered");
100 auto TimeInverseMatcher = callExpr(callee(
101 functionDecl(hasName((llvm::Twine(
"::absl::") + TimeInverse).str()))
102 .bind(
"func_decl")));
112 hasArgument(0, binaryOperator(hasOperatorName(
"-"),
113 hasLHS(TimeInverseMatcher))
116 Finder->addMatcher(CallMatcher,
this);
121 auto OperandMatcher =
122 binaryOperator(hasOperatorName(
"-"), hasRHS(TimeInverseMatcher))
124 Finder->addMatcher(OperandMatcher,
this);
129 const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>(
"binop");
130 std::string InverseName =
131 Result.Nodes.getNodeAs<FunctionDecl>(
"func_decl")->getNameAsString();
139 const auto *OuterCall = Result.Nodes.getNodeAs<CallExpr>(
"outer_call");
151 (llvm::Twine(NeedParens ?
"(" :
"") +
154 (NeedParens ?
")" :
""))
160 const auto *MaybeCallArg = selectFirst<const CallExpr>(
161 "arg", match(expr(hasAncestor(
162 callExpr(callee(functionDecl(hasName(
165 *BinOp, *Result.Context));
166 if (MaybeCallArg && MaybeCallArg->getArg(0)->IgnoreImpCasts() == BinOp &&
176 (llvm::Twine(NeedParens ?
"(" :
"") +
180 (NeedParens ?
")" :
""))
std::string rewriteExprFromNumberToTime(const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale, const Expr *Node)
Assuming Node has a type int representing a time instant of Scale since The Epoch,...