| 1 |
//===-- IncludeFixerContext.h - Include fixer context -----------*- 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_INCLUDEFIXERCONTEXT_H |
| 10 |
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H |
| 11 |
|
| 12 |
#include "find-all-symbols/SymbolInfo.h" |
| 13 |
#include "clang/Tooling/Core/Replacement.h" |
| 14 |
#include <string> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
namespace clang { |
| 18 |
namespace include_fixer { |
| 19 |
|
| 20 |
/// A context for a file being processed. It includes all query |
| 21 |
/// information, e.g. symbols being queried in database, all header candidates. |
| 22 |
class IncludeFixerContext { |
| 23 |
public: |
| 24 |
struct HeaderInfo { |
| 25 |
/// The header where QualifiedName comes from. |
| 26 |
std::string Header; |
| 27 |
/// A symbol name with completed namespace qualifiers which will |
| 28 |
/// replace the original symbol. |
| 29 |
std::string QualifiedName; |
| 30 |
}; |
| 31 |
|
| 32 |
struct QuerySymbolInfo { |
| 33 |
/// The raw symbol name being queried in database. This name might |
| 34 |
/// miss some namespace qualifiers, and will be replaced by a fully |
| 35 |
/// qualified one. |
| 36 |
std::string RawIdentifier; |
| 37 |
|
| 38 |
/// The qualifiers of the scope in which SymbolIdentifier lookup |
| 39 |
/// occurs. It is represented as a sequence of names and scope resolution |
| 40 |
/// operators ::, ending with a scope resolution operator (e.g. a::b::). |
| 41 |
/// Empty if SymbolIdentifier is not in a specific scope. |
| 42 |
std::string ScopedQualifiers; |
| 43 |
|
| 44 |
/// The replacement range of RawIdentifier. |
| 45 |
tooling::Range Range; |
| 46 |
}; |
| 47 |
|
| 48 |
IncludeFixerContext() = default; |
| 49 |
IncludeFixerContext(StringRef FilePath, |
| 50 |
std::vector<QuerySymbolInfo> QuerySymbols, |
| 51 |
std::vector<find_all_symbols::SymbolInfo> Symbols); |
| 52 |
|
| 53 |
/// Get symbol name. |
| 54 |
llvm::StringRef getSymbolIdentifier() const { |
| 55 |
return QuerySymbolInfos.front().RawIdentifier; |
| 56 |
} |
| 57 |
|
| 58 |
/// Get replacement range of the symbol. |
| 59 |
tooling::Range getSymbolRange() const { |
| 60 |
return QuerySymbolInfos.front().Range; |
| 61 |
} |
| 62 |
|
| 63 |
/// Get the file path to the file being processed. |
| 64 |
StringRef getFilePath() const { return FilePath; } |
| 65 |
|
| 66 |
/// Get header information. |
| 67 |
const std::vector<HeaderInfo> &getHeaderInfos() const { return HeaderInfos; } |
| 68 |
|
| 69 |
/// Get information of symbols being querid. |
| 70 |
const std::vector<QuerySymbolInfo> &getQuerySymbolInfos() const { |
| 71 |
return QuerySymbolInfos; |
| 72 |
} |
| 73 |
|
| 74 |
private: |
| 75 |
friend struct llvm::yaml::MappingTraits<IncludeFixerContext>; |
| 76 |
|
| 77 |
/// The file path to the file being processed. |
| 78 |
std::string FilePath; |
| 79 |
|
| 80 |
/// All instances of an unidentified symbol being queried. |
| 81 |
std::vector<QuerySymbolInfo> QuerySymbolInfos; |
| 82 |
|
| 83 |
/// The symbol candidates which match SymbolIdentifier. The symbols are |
| 84 |
/// sorted in a descending order based on the popularity info in SymbolInfo. |
| 85 |
std::vector<find_all_symbols::SymbolInfo> MatchedSymbols; |
| 86 |
|
| 87 |
/// The header information. |
| 88 |
std::vector<HeaderInfo> HeaderInfos; |
| 89 |
}; |
| 90 |
|
| 91 |
} // namespace include_fixer |
| 92 |
} // namespace clang |
| 93 |
|
| 94 |
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H |