clang-tools  14.0.0git
IncludeFixerContext.h
Go to the documentation of this file.
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 
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.
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.
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.
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
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:38
clang::include_fixer::IncludeFixerContext::getQuerySymbolInfos
const std::vector< QuerySymbolInfo > & getQuerySymbolInfos() const
Get information of symbols being querid.
Definition: IncludeFixerContext.h:70
clang::include_fixer::IncludeFixerContext::IncludeFixerContext
IncludeFixerContext()=default
clang::include_fixer::IncludeFixerContext::QuerySymbolInfo::RawIdentifier
std::string RawIdentifier
The raw symbol name being queried in database.
Definition: IncludeFixerContext.h:36
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:29
clang::include_fixer::IncludeFixerContext::getSymbolRange
tooling::Range getSymbolRange() const
Get replacement range of the symbol.
Definition: IncludeFixerContext.h:59
clang::include_fixer::IncludeFixerContext::QuerySymbolInfo::Range
tooling::Range Range
The replacement range of RawIdentifier.
Definition: IncludeFixerContext.h:45
clang::include_fixer::IncludeFixerContext::QuerySymbolInfo
Definition: IncludeFixerContext.h:32
clang::include_fixer::IncludeFixerContext::HeaderInfo
Definition: IncludeFixerContext.h:24
clang::include_fixer::IncludeFixerContext::QuerySymbolInfo::ScopedQualifiers
std::string ScopedQualifiers
The qualifiers of the scope in which SymbolIdentifier lookup occurs.
Definition: IncludeFixerContext.h:42
SymbolInfo.h
clang::include_fixer::IncludeFixerContext
A context for a file being processed.
Definition: IncludeFixerContext.h:22
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::include_fixer::IncludeFixerContext::getFilePath
StringRef getFilePath() const
Get the file path to the file being processed.
Definition: IncludeFixerContext.h:64
clang::include_fixer::IncludeFixerContext::HeaderInfo::Header
std::string Header
The header where QualifiedName comes from.
Definition: IncludeFixerContext.h:26
clang::include_fixer::IncludeFixerContext::getHeaderInfos
const std::vector< HeaderInfo > & getHeaderInfos() const
Get header information.
Definition: IncludeFixerContext.h:67
clang::include_fixer::IncludeFixerContext::getSymbolIdentifier
llvm::StringRef getSymbolIdentifier() const
Get symbol name.
Definition: IncludeFixerContext.h:54