clang 23.0.0git
SummaryDataBuilderRegistry.h
Go to the documentation of this file.
1//===- SummaryDataBuilderRegistry.h -----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Registry for SummaryDataBuilders.
10//
11// To register a builder, add a static Add<BuilderT> in the builder's
12// translation unit:
13//
14// static SummaryDataBuilderRegistry::Add<MyDataBuilder>
15// Registered("Data builder for MyAnalysis");
16//
17// The registry entry name is derived automatically from
18// MyDataBuilder::summaryName(), which returns MyData::summaryName().
19//
20//===----------------------------------------------------------------------===//
21
22#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SUMMARYDATA_SUMMARYDATABUILDERREGISTRY_H
23#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SUMMARYDATA_SUMMARYDATABUILDERREGISTRY_H
24
26#include "llvm/Support/Registry.h"
27#include <memory>
28#include <string>
29
30LLVM_DECLARE_REGISTRY(llvm::Registry<clang::ssaf::SummaryDataBuilderBase>)
31
32namespace clang::ssaf {
33
34/// Registry for SummaryDataBuilder implementations.
35///
36/// Provides an Add helper that derives the registry entry name from
37/// BuilderT::summaryName(), eliminating the possibility of registering a
38/// builder under the wrong name.
39class SummaryDataBuilderRegistry {
40 using RegistryT = llvm::Registry<SummaryDataBuilderBase>;
41
42 SummaryDataBuilderRegistry() = delete;
43
44public:
45 /// Registers \p BuilderT under the name returned by
46 /// \c BuilderT::summaryName(). Only a description is required.
47 ///
48 /// \c Add objects must be declared \c static at namespace scope — they
49 /// register an entry in a global linked list on construction and are
50 /// not copyable or movable.
51 template <typename BuilderT> struct Add {
52 explicit Add(llvm::StringRef Desc)
53 : Name(BuilderT::summaryName().str().str()), Node(Name, Desc) {}
54
55 Add(const Add &) = delete;
56 Add &operator=(const Add &) = delete;
57
58 private:
59 std::string Name;
60 RegistryT::Add<BuilderT> Node;
61 };
62
63 /// Returns true if a builder is registered under \p Name.
64 static bool contains(llvm::StringRef Name);
65
66 /// Instantiates the builder registered under \p Name, or returns nullptr
67 /// if no such builder is registered.
68 static std::unique_ptr<SummaryDataBuilderBase>
69 instantiate(llvm::StringRef Name);
70};
71
72} // namespace clang::ssaf
73
74#endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_SUMMARYDATA_SUMMARYDATABUILDERREGISTRY_H
static bool contains(llvm::StringRef Name)
Returns true if a builder is registered under Name.
static std::unique_ptr< SummaryDataBuilderBase > instantiate(llvm::StringRef Name)
Instantiates the builder registered under Name, or returns nullptr if no such builder is registered.