1//===-- SymbolIndexManager.h - Managing multiple SymbolIndices --*- 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#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEXMANAGER_H
10#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEXMANAGER_H
11
12#include "SymbolIndex.h"
13#include "find-all-symbols/SymbolInfo.h"
14#include "llvm/ADT/StringRef.h"
15
16#ifdef _MSC_VER
17// Disable warnings from ppltasks.h transitively included by <future>.
18#pragma warning(push)
19#pragma warning(disable:4530)
20#endif
21
22#include <future>
23
24#ifdef _MSC_VER
25#pragma warning(pop)
26#endif
27
28namespace clang {
29namespace include_fixer {
30
31/// This class provides an interface for finding the header files corresponding
32/// to an identifier in the source code from multiple symbol databases.
33class SymbolIndexManager {
34public:
35 void addSymbolIndex(std::function<std::unique_ptr<SymbolIndex>()> F) {
36#if LLVM_ENABLE_THREADS
37 auto Strategy = std::launch::async;
38#else
39 auto Strategy = std::launch::deferred;
40#endif
41 SymbolIndices.push_back(x: std::async(policy: Strategy, fn&: F));
42 }
43
44 /// Search for header files to be included for an identifier.
45 /// \param Identifier The identifier being searched for. May or may not be
46 /// fully qualified.
47 /// \param IsNestedSearch Whether searching nested classes. If true, the
48 /// method tries to strip identifier name parts from the end until it
49 /// finds the corresponding candidates in database (e.g for identifier
50 /// "b::foo", the method will try to find "b" if it fails to find
51 /// "b::foo").
52 ///
53 /// \returns A list of symbol candidates.
54 std::vector<find_all_symbols::SymbolInfo>
55 search(llvm::StringRef Identifier, bool IsNestedSearch = true,
56 llvm::StringRef FileName = "") const;
57
58private:
59 std::vector<std::shared_future<std::unique_ptr<SymbolIndex>>> SymbolIndices;
60};
61
62} // namespace include_fixer
63} // namespace clang
64
65#endif
66

source code of clang-tools-extra/clang-include-fixer/SymbolIndexManager.h