Debian Codegraph @

clang-tools-extra/clangd/FeatureModule.cpp

raw
1 //===--- FeatureModule.cpp - Plugging features into clangd ----------------===//
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 #include "FeatureModule.h"
10 #include "support/Logger.h"
11
12 namespace clang {
13 namespace clangd {
14
15 void FeatureModule::initialize(const Facilities &F) {
16 assert(!Fac && "Initialized twice");
17 Fac.emplace(F);
18 }
19
20 FeatureModule::Facilities &FeatureModule::facilities() {
21 assert(Fac && "Not initialized yet");
22 return *Fac;
23 }
24
25 void FeatureModuleSet::add(std::unique_ptr<FeatureModule> M) {
26 Modules.push_back(std::move(M));
27 }
28
29 bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr<FeatureModule> M,
30 const char *Source) {
31 if (!Map.try_emplace(Key, M.get()).second) {
32 // Source should (usually) include the name of the concrete module type.
33 elog("Tried to register duplicate feature modules via {0}", Source);
34 return false;
35 }
36 Modules.push_back(std::move(M));
37 return true;
38 }
39
40 FeatureModuleSet FeatureModuleSet::fromRegistry() {
41 FeatureModuleSet ModuleSet;
42 for (FeatureModuleRegistry::entry E : FeatureModuleRegistry::entries()) {
43 vlog("Adding feature module '{0}' ({1})", E.getName(), E.getDesc());
44 ModuleSet.add(E.instantiate());
45 }
46 return ModuleSet;
47 }
48
49 } // namespace clangd
50 } // namespace clang
51
52 LLVM_INSTANTIATE_REGISTRY(clang::clangd::FeatureModuleRegistry)