clang 24.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_SCALABLESTATICANALYSIS_CORE_SUMMARYDATA_SUMMARYDATABUILDERREGISTRY_H
23#define LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_SUMMARYDATA_SUMMARYDATABUILDERREGISTRY_H
24
27#include "llvm/Support/Registry.h"
28#include <memory>
29#include <string>
30
31LLVM_DECLARE_REGISTRY_EX(CLANG_ABI_EXPORT,
32 llvm::Registry<clang::ssaf::SummaryDataBuilderBase>)
33
34namespace clang::ssaf {
35
36/// Registry for SummaryDataBuilder implementations.
37///
38/// Provides an Add helper that derives the registry entry name from
39/// BuilderT::summaryName(), eliminating the possibility of registering a
40/// builder under the wrong name.
41class SummaryDataBuilderRegistry {
42 using RegistryT = llvm::Registry<SummaryDataBuilderBase>;
43
44 SummaryDataBuilderRegistry() = delete;
45
46public:
47 /// Registers \p BuilderT under the name returned by
48 /// \c BuilderT::summaryName(). Only a description is required.
49 ///
50 /// \c Add objects must be declared \c static at namespace scope — they
51 /// register an entry in a global linked list on construction and are
52 /// not copyable or movable.
53 template <typename BuilderT> struct Add {
54 explicit Add(llvm::StringRef Desc)
55 : Name(BuilderT::summaryName().str().str()), Node(Name, Desc) {}
56
57 Add(const Add &) = delete;
58 Add &operator=(const Add &) = delete;
59
60 private:
61 std::string Name;
62 RegistryT::Add<BuilderT> Node;
63 };
64
65 /// Returns true if a builder is registered under \p Name.
66 static bool contains(llvm::StringRef Name);
67
68 /// Instantiates the builder registered under \p Name, or returns nullptr
69 /// if no such builder is registered.
70 static std::unique_ptr<SummaryDataBuilderBase>
71 instantiate(llvm::StringRef Name);
72};
73
74} // namespace clang::ssaf
75
76#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_SUMMARYDATA_SUMMARYDATABUILDERREGISTRY_H
LLVM_DECLARE_REGISTRY_EX(CLANG_ABI_EXPORT, llvm::Registry< clang::ssaf::JSONFormat::FormatInfo >) LLVM_DECLARE_REGISTRY_EX(CLANG_ABI_EXPORT
static bool contains(const std::set< tok::TokenKind > &Terminators, const Token &Tok)
llvm::Registry< SummaryDataBuilderBase > RegistryT
bool Add(InterpState &S, CodePtr OpPC)
Definition Interp.h:407