From f6c9b04c8195d1b358213086fde07d033421e53b Mon Sep 17 00:00:00 2001 From: Alessandro Di Federico Date: Sat, 2 Apr 2022 18:22:05 +0200 Subject: [PATCH] Adopt clang-tidy: readability-identifier-naming --- .clang-tidy | 28 +++++++++++++++++++ include/revng/ADT/Concepts.h | 11 ++++---- include/revng/ADT/GenericGraph.h | 2 ++ include/revng/ADT/UpcastablePointer.h | 16 +++++------ include/revng/Model/RelocationType.h | 1 + include/revng/Pipeline/Container.h | 2 +- include/revng/Pipeline/Context.h | 14 +++++----- include/revng/Pipeline/GenericLLVMPipe.h | 8 +++--- include/revng/Pipeline/LLVMContainer.h | 8 +++--- include/revng/Pipeline/LLVMContainerFactory.h | 7 +++-- include/revng/Pipeline/Loader.h | 26 ++++++++--------- include/revng/Pipeline/Pipe.h | 12 ++++---- include/revng/Pipeline/Target.h | 8 +++--- include/revng/PipelineC/.clang-tidy | 1 + include/revng/Support/EnumSwitch.h | 2 +- include/revng/Support/FunctionTags.h | 4 +-- lib/Lift/PTCInterface.h | 1 + lib/PipelineC/.clang-tidy | 1 + lib/Support/Assert.cpp | 9 +++--- tests/abi/tools/revng-abi-verify/Verify.cpp | 14 ++++++---- tests/unit/PipelineC.cpp | 22 +++++++-------- 21 files changed, 118 insertions(+), 79 deletions(-) create mode 100644 .clang-tidy create mode 100644 include/revng/PipelineC/.clang-tidy create mode 100644 lib/PipelineC/.clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..bd9eaf981 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,28 @@ +Checks: '-*,readability-identifier-naming' +CheckOptions: + - key: readability-identifier-naming.GlobalVariableCase + value: CamelCase + - key: readability-identifier-naming.ConstexprVariableIgnoredRegexp + value: '.*_v' + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.ClassIgnoredRegexp + value: 'is_specialization|are_same|is_std_vector|scc_iterator_traits|.*_(false|true)' + - key: readability-identifier-naming.EnumCase + value: CamelCase + - key: readability-identifier-naming.FunctionCase + value: camelBack + - key: readability-identifier-naming.FunctionIgnoredRegexp + value: 'cmp|is_forward_node|has_parent|make_range|make_array|contains_any_of|successor_edges|predecessor_edges|is_bidirectional_node|is_generic_graph|lower_bound|upper_bound|vlower_bound|zipmap_.*|insert_or_assign|batch_insert.*|unique_last|emplace_back|push_back|pop_back|make_blacklist|erase_if|isa_with_op|edge_dest|edge_successors|edge_predecessors|revng_check.*|revng_assert.*|revng_do_abort|get_return_object|get_return_object_on_allocation_failure|unhandled_exception|initial_suspend|final_suspend|await_ready|await_suspend|await_resume|__coro_gro|__promise|yield_value|rethrow_if_exception|throw_exception|init_unit_test|.*_[cr]*(begin|end)|.*_(iterator|range|size)|return_value|return_void|await_transform' + - key: readability-identifier-naming.MemberCase + value: CamelCase + - key: readability-identifier-naming.ParameterCase + value: CamelCase + - key: readability-identifier-naming.UnionCase + value: CamelCase + - key: readability-identifier-naming.VariableCase + value: CamelCase + - key: readability-identifier-naming.IgnoreMainLikeFunctions + value: 1 + - key: readability-identifier-naming.GlobalVariableIgnoredRegexp + value: 'dbg' diff --git a/include/revng/ADT/Concepts.h b/include/revng/ADT/Concepts.h index 8f6153ead..88eb942ac 100644 --- a/include/revng/ADT/Concepts.h +++ b/include/revng/ADT/Concepts.h @@ -4,6 +4,7 @@ // This file is distributed under the MIT License. See LICENSE.md for details. // +#include #include template @@ -28,14 +29,14 @@ concept Integral = std::is_integral_v; namespace ranges { template -concept range = requires(T & t) { - std::begin(t); - std::end(t); +concept range = requires(T &R) { + std::begin(R); + std::end(R); }; template -concept sized_range = ranges::range && requires(T & t) { - std::size(t); +concept sized_range = ranges::range && requires(T &R) { + std::size(R); }; } // namespace ranges diff --git a/include/revng/ADT/GenericGraph.h b/include/revng/ADT/GenericGraph.h index 8534d6e4c..135e00ba7 100644 --- a/include/revng/ADT/GenericGraph.h +++ b/include/revng/ADT/GenericGraph.h @@ -352,6 +352,7 @@ class BidirectionalNode SmallSize, BidirectionalNode>::Result { public: + // NOLINTNEXTLINE static const bool is_bidirectional_node = true; public: @@ -1179,6 +1180,7 @@ template class GenericGraph : public std::conditional_t, Empty> { public: + // NOLINTNEXTLINE static const bool is_generic_graph = true; using NodesContainer = llvm::SmallVector, SmallSize>; using Node = NodeT; diff --git a/include/revng/ADT/UpcastablePointer.h b/include/revng/ADT/UpcastablePointer.h index 715b5dfe6..5f0f2d436 100644 --- a/include/revng/ADT/UpcastablePointer.h +++ b/include/revng/ADT/UpcastablePointer.h @@ -114,18 +114,18 @@ public: private: using concrete_types = concrete_types_traits_t; - static constexpr void (*deleter)(T *) = &destroy; - using inner_pointer = std::unique_ptr; + static constexpr void (*Deleter)(T *) = &destroy; + using inner_pointer = std::unique_ptr; public: using pointer = typename inner_pointer::pointer; using element_type = typename inner_pointer::element_type; public: - constexpr UpcastablePointer() noexcept : Pointer(nullptr, deleter) {} + constexpr UpcastablePointer() noexcept : Pointer(nullptr, Deleter) {} constexpr UpcastablePointer(std::nullptr_t P) noexcept : - Pointer(P, deleter) {} - explicit UpcastablePointer(pointer P) noexcept : Pointer(P, deleter) {} + Pointer(P, Deleter) {} + explicit UpcastablePointer(pointer P) noexcept : Pointer(P, Deleter) {} public: template Q, typename... Args> @@ -137,7 +137,7 @@ public: UpcastablePointer &operator=(const UpcastablePointer &Other) { if (&Other != this) { Pointer.reset(clone(Other.Pointer.get())); - revng_assert(Pointer.get_deleter() == deleter); + revng_assert(Pointer.get_deleter() == Deleter); } return *this; } @@ -150,7 +150,7 @@ public: UpcastablePointer &operator=(UpcastablePointer &&Other) { if (&Other != this) { Pointer.reset(Other.Pointer.release()); - revng_assert(Pointer.get_deleter() == deleter); + revng_assert(Pointer.get_deleter() == Deleter); } return *this; } @@ -180,7 +180,7 @@ public: void reset(pointer Other = pointer()) noexcept { Pointer.reset(Other); - revng_assert(Pointer.get_deleter() == deleter); + revng_assert(Pointer.get_deleter() == Deleter); } private: diff --git a/include/revng/Model/RelocationType.h b/include/revng/Model/RelocationType.h index 41de66d39..b76fef88b 100644 --- a/include/revng/Model/RelocationType.h +++ b/include/revng/Model/RelocationType.h @@ -23,6 +23,7 @@ TUPLE-TREE-YAML */ #include "revng/Model/Generated/Early/RelocationType.h" +// NOLINTNEXTLINE const unsigned char R_MIPS_IMPLICIT_RELATIVE = 255; namespace model::RelocationType { diff --git a/include/revng/Pipeline/Container.h b/include/revng/Pipeline/Container.h index b8430baac..a6c576942 100644 --- a/include/revng/Pipeline/Container.h +++ b/include/revng/Pipeline/Container.h @@ -15,7 +15,7 @@ namespace pipeline { template -concept HasID = requires(T a) { +concept HasID = requires { { T::ID } -> convertible_to; }; diff --git a/include/revng/Pipeline/Context.h b/include/revng/Pipeline/Context.h index a7c5b41ca..a5eec11ca 100644 --- a/include/revng/Pipeline/Context.h +++ b/include/revng/Pipeline/Context.h @@ -47,9 +47,9 @@ private: KindsRegistry TheKindRegistry; private: - explicit Context(KindsRegistry registry) : - TheKindRegistry(std::move(registry)) {} - Context(llvm::ArrayRef Globals, KindsRegistry registry); + explicit Context(KindsRegistry Registry) : + TheKindRegistry(std::move(Registry)) {} + Context(llvm::ArrayRef Globals, KindsRegistry Registry); public: Context(); @@ -57,12 +57,12 @@ public: public: static Context fromRegistry(llvm::ArrayRef Globals, - KindsRegistry registry) { - return Context(Globals, std::move(registry)); + KindsRegistry Registry) { + return Context(Globals, std::move(Registry)); } - static Context fromRegistry(KindsRegistry registry) { - return Context(std::move(registry)); + static Context fromRegistry(KindsRegistry Registry) { + return Context(std::move(Registry)); } template diff --git a/include/revng/Pipeline/GenericLLVMPipe.h b/include/revng/Pipeline/GenericLLVMPipe.h index 17765a799..8d90a7ace 100644 --- a/include/revng/Pipeline/GenericLLVMPipe.h +++ b/include/revng/Pipeline/GenericLLVMPipe.h @@ -35,14 +35,14 @@ public: }; template -concept LLVMPass = requires(T a) { +concept LLVMPass = requires(T P) { { T::Name } -> convertible_to; - { a.registerPasses(std::declval()) }; + { P.registerPasses(std::declval()) }; }; template -concept LLVMPrintablePass = requires(T a) { - { a.print(llvm::outs()) }; +concept LLVMPrintablePass = requires(T P) { + { P.print(llvm::outs()) }; }; class PureLLVMPassWrapper : public LLVMPassWrapperBase { diff --git a/include/revng/Pipeline/LLVMContainer.h b/include/revng/Pipeline/LLVMContainer.h index 36375eec1..748ec9b6a 100644 --- a/include/revng/Pipeline/LLVMContainer.h +++ b/include/revng/Pipeline/LLVMContainer.h @@ -138,19 +138,19 @@ private: ThisType &ToMerge = Other; auto Composite = std::make_unique("llvm-link", Module->getContext()); - std::set globals; + std::set Globals; for (auto &Global : Module->globals()) { if (Global.getLinkage() != llvm::GlobalValue::InternalLinkage) continue; - globals.insert(Global.getName().str()); + Globals.insert(Global.getName().str()); Global.setLinkage(llvm::GlobalValue::ExternalLinkage); } for (auto &Global : ToMerge.getModule().globals()) { if (Global.getLinkage() != llvm::GlobalValue::InternalLinkage) continue; - globals.insert(Global.getName().str()); + Globals.insert(Global.getName().str()); Global.setLinkage(llvm::GlobalValue::ExternalLinkage); } @@ -169,7 +169,7 @@ private: revng_assert(not Failure, "Linker failed"); for (auto &Global : Composite->globals()) { - if (globals.contains(Global.getName().str())) + if (Globals.contains(Global.getName().str())) Global.setLinkage(llvm::GlobalValue::InternalLinkage); } diff --git a/include/revng/Pipeline/LLVMContainerFactory.h b/include/revng/Pipeline/LLVMContainerFactory.h index fe9266bed..465ecaa2c 100644 --- a/include/revng/Pipeline/LLVMContainerFactory.h +++ b/include/revng/Pipeline/LLVMContainerFactory.h @@ -27,7 +27,10 @@ makeLLVMContainerFactory(pipeline::Context &Ctx, llvm::LLVMContext &Context) { &Context); } -inline auto - makeDefaultLLVMContainerFactory = makeLLVMContainerFactory; +inline ContainerFactory +makeDefaultLLVMContainerFactory(pipeline::Context &Ctx, + llvm::LLVMContext &Context) { + return makeLLVMContainerFactory(Ctx, Context); +} } // namespace pipeline diff --git a/include/revng/Pipeline/Loader.h b/include/revng/Pipeline/Loader.h index e4441235a..90d3285e9 100644 --- a/include/revng/Pipeline/Loader.h +++ b/include/revng/Pipeline/Loader.h @@ -166,11 +166,11 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(pipeline::ContainerDeclaration) template<> struct llvm::yaml::MappingTraits { - static void mapping(IO &io, pipeline::PipeInvocation &info) { - io.mapRequired("Type", info.Type); - io.mapRequired("UsedContainers", info.UsedContainers); - io.mapOptional("Passes", info.Passes); - io.mapOptional("EnabledWhen", info.EnabledWhen); + static void mapping(IO &TheIO, pipeline::PipeInvocation &Info) { + TheIO.mapRequired("Type", Info.Type); + TheIO.mapRequired("UsedContainers", Info.UsedContainers); + TheIO.mapOptional("Passes", Info.Passes); + TheIO.mapOptional("EnabledWhen", Info.EnabledWhen); } }; @@ -178,10 +178,10 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(pipeline::PipeInvocation) template<> struct llvm::yaml::MappingTraits { - static void mapping(IO &io, pipeline::StepDeclaration &info) { - io.mapRequired("Name", info.Name); - io.mapOptional("Pipes", info.Pipes); - io.mapOptional("EnabledWhen", info.EnabledWhen); + static void mapping(IO &TheIO, pipeline::StepDeclaration &Info) { + TheIO.mapRequired("Name", Info.Name); + TheIO.mapOptional("Pipes", Info.Pipes); + TheIO.mapOptional("EnabledWhen", Info.EnabledWhen); } }; @@ -191,9 +191,9 @@ INTROSPECTION_NS(pipeline, PipelineDeclaration, Containers, Steps); template<> struct llvm::yaml::MappingTraits : public TupleLikeMappingTraits { - static void mapping(IO &io, pipeline::PipelineDeclaration &info) { - io.mapOptional("From", info.From); - io.mapRequired("Containers", info.Containers); - io.mapRequired("Steps", info.Steps); + static void mapping(IO &TheIO, pipeline::PipelineDeclaration &Info) { + TheIO.mapOptional("From", Info.From); + TheIO.mapRequired("Containers", Info.Containers); + TheIO.mapRequired("Steps", Info.Steps); } }; diff --git a/include/revng/Pipeline/Pipe.h b/include/revng/Pipeline/Pipe.h index 91d145b0a..c62ced3b0 100644 --- a/include/revng/Pipeline/Pipe.h +++ b/include/revng/Pipeline/Pipe.h @@ -41,8 +41,8 @@ concept HasName = requires() { }; template -concept HasContract = requires(T a) { - { llvm::ArrayRef(a.getContract()) }; +concept HasContract = requires(T P) { + { llvm::ArrayRef(P.getContract()) }; }; /// A Pipe is a class with the following characteristics: @@ -135,15 +135,15 @@ public: virtual std::unique_ptr clone() const = 0; virtual std::vector getRunningContainersNames() const = 0; virtual std::string getName() const = 0; - virtual void dump(std::ostream &OS, size_t indents) const = 0; + virtual void dump(std::ostream &OS, size_t Indents) const = 0; virtual void - print(const Context &Ctx, llvm::raw_ostream &OS, size_t indents) const = 0; + print(const Context &Ctx, llvm::raw_ostream &OS, size_t Indents) const = 0; virtual bool areRequirementsMet(const ContainerToTargetsMap &Input) const = 0; }; template -concept Dumpable = requires(T a) { - { a.dump(dbg, 0) }; +concept Dumpable = requires(T D) { + { D.dump(dbg, 0) }; }; template diff --git a/include/revng/Pipeline/Target.h b/include/revng/Pipeline/Target.h index 40c995c0b..cd15860ef 100644 --- a/include/revng/Pipeline/Target.h +++ b/include/revng/Pipeline/Target.h @@ -206,8 +206,8 @@ public: public: template - void emplace_back(Args &&...args) { - Contained.emplace_back(std::forward(args)...); + void emplace_back(Args &&...A) { + Contained.emplace_back(std::forward(A)...); removeDuplicates(); } @@ -219,8 +219,8 @@ public: } template - auto erase(Args &&...args) { - return Contained.erase(std::forward(args)...); + auto erase(Args &&...A) { + return Contained.erase(std::forward(A)...); } public: diff --git a/include/revng/PipelineC/.clang-tidy b/include/revng/PipelineC/.clang-tidy new file mode 100644 index 000000000..612bd0ee8 --- /dev/null +++ b/include/revng/PipelineC/.clang-tidy @@ -0,0 +1 @@ +Checks: '-*' diff --git a/include/revng/Support/EnumSwitch.h b/include/revng/Support/EnumSwitch.h index cd71f2dfb..3e3fb1a95 100644 --- a/include/revng/Support/EnumSwitch.h +++ b/include/revng/Support/EnumSwitch.h @@ -13,7 +13,7 @@ namespace revng::detail { template -concept EnumWithCount = requires(std::decay_t t) { +concept EnumWithCount = requires { requires std::is_enum::type>::value; { std::decay_t::Count } -> convertible_to; }; diff --git a/include/revng/Support/FunctionTags.h b/include/revng/Support/FunctionTags.h index 67d9d4edc..13ce0be56 100644 --- a/include/revng/Support/FunctionTags.h +++ b/include/revng/Support/FunctionTags.h @@ -104,7 +104,7 @@ public: return make_filter_range(M->functions(), Filter); } - auto exact_functions(llvm::Module *M) const { + auto exactFunctions(llvm::Module *M) const { using namespace llvm; auto Filter = [this](Function &F) { return isExactTagOf(&F); }; return make_filter_range(M->functions(), Filter); @@ -116,7 +116,7 @@ public: return make_filter_range(M->globals(), Filter); } - auto exact_globals(llvm::Module *M) const { + auto exactGlobals(llvm::Module *M) const { using namespace llvm; auto Filter = [this](GlobalVariable &G) { return isExactTagOf(&G); }; return make_filter_range(M->globals(), Filter); diff --git a/lib/Lift/PTCInterface.h b/lib/Lift/PTCInterface.h index 9454c7a44..ea3cd535f 100644 --- a/lib/Lift/PTCInterface.h +++ b/lib/Lift/PTCInterface.h @@ -23,4 +23,5 @@ using PTCDestructor = PTCDestructorWrapper<&ptcInstructionListDestructor>; using PTCInstructionListPtr = std::unique_ptr; +// NOLINTNEXTLINE extern PTCInterface ptc; diff --git a/lib/PipelineC/.clang-tidy b/lib/PipelineC/.clang-tidy new file mode 100644 index 000000000..612bd0ee8 --- /dev/null +++ b/lib/PipelineC/.clang-tidy @@ -0,0 +1 @@ +Checks: '-*' diff --git a/lib/Support/Assert.cpp b/lib/Support/Assert.cpp index cff08e0f9..b55677a24 100644 --- a/lib/Support/Assert.cpp +++ b/lib/Support/Assert.cpp @@ -13,7 +13,7 @@ #include "revng/Support/Assert.h" -static AbortHook abortHook = nullptr; +static AbortHook TheAbortHook = nullptr; static void printStackTrace() { llvm::raw_os_ostream Output(std::cerr); @@ -22,14 +22,13 @@ static void printStackTrace() { } void setAbortHook(AbortHook Hook) { - abortHook = Hook; + TheAbortHook = Hook; } [[noreturn]] static void terminate(void) { printStackTrace(); - if (abortHook != nullptr) { - abortHook(); - } + if (TheAbortHook != nullptr) + TheAbortHook(); abort(); } diff --git a/tests/abi/tools/revng-abi-verify/Verify.cpp b/tests/abi/tools/revng-abi-verify/Verify.cpp index 3ebee0950..f317b1141 100644 --- a/tests/abi/tools/revng-abi-verify/Verify.cpp +++ b/tests/abi/tools/revng-abi-verify/Verify.cpp @@ -19,16 +19,18 @@ struct ABIVerificationToolErrorCategory : public std::error_category { return "ABIVerificationToolErrorCategory"; } virtual std::error_condition - default_error_condition(int code) const noexcept { - return std::error_condition(code, *this); + default_error_condition(int Code) const noexcept { + return std::error_condition(Code, *this); } + virtual bool - equivalent(int code, const std::error_condition &condition) const noexcept { - return default_error_condition(code) == condition; + equivalent(int Code, const std::error_condition &Condition) const noexcept { + return default_error_condition(Code) == Condition; } + virtual bool - equivalent(const std::error_code &code, int condition) const noexcept { - return *this == code.category() && code.value() == condition; + equivalent(const std::error_code &Code, int Condition) const noexcept { + return *this == Code.category() && Code.value() == Condition; } virtual std::string message(int) const { return ""; } }; diff --git a/tests/unit/PipelineC.cpp b/tests/unit/PipelineC.cpp index da486c7ae..f7c1ef51e 100644 --- a/tests/unit/PipelineC.cpp +++ b/tests/unit/PipelineC.cpp @@ -26,7 +26,7 @@ Steps: UsedContainers: [Strings1, Strings2] )"; -static rp_manager *runner; +static rp_manager *Runner; struct Fixture { public: @@ -37,24 +37,24 @@ public: const char *LibToLoad[] = {}; rp_initialize(1, Array, 0, LibToLoad); - runner = rp_manager_create_from_string(1, PipelineText, 0, {}, ""); - revng_check(runner != nullptr); + Runner = rp_manager_create_from_string(1, PipelineText, 0, {}, ""); + revng_check(Runner != nullptr); } - ~Fixture() { rp_manager_destroy(runner); } + ~Fixture() { rp_manager_destroy(Runner); } }; BOOST_AUTO_TEST_SUITE(PipelineCTestSuite, *boost::unit_test::fixture()) BOOST_AUTO_TEST_CASE(CAPILoadTest) { - BOOST_TEST(rp_manager_steps_count(runner) == 2); - auto *FirstStep = rp_manager_get_step(runner, 0); - BOOST_TEST(rp_manager_containers_count(runner) == 2); + BOOST_TEST(rp_manager_steps_count(Runner) == 2); + auto *FirstStep = rp_manager_get_step(Runner, 0); + BOOST_TEST(rp_manager_containers_count(Runner) == 2); - BOOST_TEST(rp_manager_step_name_to_index(runner, "begin") == 0); - BOOST_TEST(rp_manager_step_name_to_index(runner, "FirstStep") == 1); - BOOST_TEST(rp_manager_get_kind_from_name(runner, "MISSING") == nullptr); - BOOST_TEST(rp_manager_get_kind_from_name(runner, "Root") != nullptr); + BOOST_TEST(rp_manager_step_name_to_index(Runner, "begin") == 0); + BOOST_TEST(rp_manager_step_name_to_index(Runner, "FirstStep") == 1); + BOOST_TEST(rp_manager_get_kind_from_name(Runner, "MISSING") == nullptr); + BOOST_TEST(rp_manager_get_kind_from_name(Runner, "Root") != nullptr); } BOOST_AUTO_TEST_SUITE_END()