//===--- DurationFactoryScaleCheck.cpp - clang-tidy -----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "DurationFactoryScaleCheck.h" #include "DurationRewriter.h" #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Tooling/FixIt.h" #include <optional> usingnamespaceclang::ast_matchers; namespace clang::tidy::abseil { // Given the name of a duration factory function, return the appropriate // `DurationScale` for that factory. If no factory can be found for // `FactoryName`, return `std::nullopt`. static std::optional<DurationScale> getScaleForFactory(llvm::StringRef FactoryName) { … } // Given either an integer or float literal, return its value. // One and only one of `IntLit` and `FloatLit` should be provided. static double getValue(const IntegerLiteral *IntLit, const FloatingLiteral *FloatLit) { … } // Given the scale of a duration and a `Multiplier`, determine if `Multiplier` // would produce a new scale. If so, return a tuple containing the new scale // and a suitable Multiplier for that scale, otherwise `std::nullopt`. static std::optional<std::tuple<DurationScale, double>> getNewScaleSingleStep(DurationScale OldScale, double Multiplier) { … } // Given the scale of a duration and a `Multiplier`, determine if `Multiplier` // would produce a new scale. If so, return it, otherwise `std::nullopt`. static std::optional<DurationScale> getNewScale(DurationScale OldScale, double Multiplier) { … } void DurationFactoryScaleCheck::registerMatchers(MatchFinder *Finder) { … } void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) { … } } // namespace clang::tidy::abseil