clang-tools 8.0.0

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