1 //===- CheckerManager.h - Static Analyzer Checker Manager -------*- 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 // Defines the Static Analyzer Checker Manager.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
14 #include "clang/StaticAnalyzer/Frontend/CheckerRegistry.h"
15 #include <memory>
16 
17 namespace clang {
18 namespace ento {
19 
20 CheckerManager::CheckerManager(
21     ASTContext &Context, AnalyzerOptions &AOptions,
22     ArrayRef<std::string> plugins,
23     ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns)
24     : Context(&Context), LangOpts(Context.getLangOpts()), AOptions(AOptions),
25       Diags(Context.getDiagnostics()),
26       Registry(
27           std::make_unique<CheckerRegistry>(plugins, Context.getDiagnostics(),
28                                             AOptions, checkerRegistrationFns)) {
29   Registry->initializeRegistry(*this);
30   Registry->initializeManager(*this);
31   finishedCheckerRegistration();
32 }
33 
34 /// Constructs a CheckerManager without requiring an AST. No checker
35 /// registration will take place. Only useful for retrieving the
36 /// CheckerRegistry and print for help flags where the AST is unavalaible.
37 CheckerManager::CheckerManager(AnalyzerOptions &AOptions,
38                                const LangOptions &LangOpts,
39                                DiagnosticsEngine &Diags,
40                                ArrayRef<std::string> plugins)
41     : LangOpts(LangOpts), AOptions(AOptions), Diags(Diags),
42       Registry(std::make_unique<CheckerRegistry>(plugins, Diags, AOptions)) {
43   Registry->initializeRegistry(*this);
44 }
45 
46 CheckerManager::~CheckerManager() {
47   for (const auto &CheckerDtor : CheckerDtors)
48     CheckerDtor();
49 }
50 
51 } // namespace ento
52 } // namespace clang
53