annotate clang-tools-extra/clang-include-fixer/IncludeFixerContext.h @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 0572611fdcc8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===-- IncludeFixerContext.h - Include fixer context -----------*- C++ -*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
anatofuz
parents:
diff changeset
10 #define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 #include "find-all-symbols/SymbolInfo.h"
anatofuz
parents:
diff changeset
13 #include "clang/Tooling/Core/Replacement.h"
anatofuz
parents:
diff changeset
14 #include <string>
anatofuz
parents:
diff changeset
15 #include <vector>
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 namespace clang {
anatofuz
parents:
diff changeset
18 namespace include_fixer {
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 /// A context for a file being processed. It includes all query
anatofuz
parents:
diff changeset
21 /// information, e.g. symbols being queried in database, all header candidates.
anatofuz
parents:
diff changeset
22 class IncludeFixerContext {
anatofuz
parents:
diff changeset
23 public:
anatofuz
parents:
diff changeset
24 struct HeaderInfo {
anatofuz
parents:
diff changeset
25 /// The header where QualifiedName comes from.
anatofuz
parents:
diff changeset
26 std::string Header;
anatofuz
parents:
diff changeset
27 /// A symbol name with completed namespace qualifiers which will
anatofuz
parents:
diff changeset
28 /// replace the original symbol.
anatofuz
parents:
diff changeset
29 std::string QualifiedName;
anatofuz
parents:
diff changeset
30 };
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 struct QuerySymbolInfo {
anatofuz
parents:
diff changeset
33 /// The raw symbol name being queried in database. This name might
anatofuz
parents:
diff changeset
34 /// miss some namespace qualifiers, and will be replaced by a fully
anatofuz
parents:
diff changeset
35 /// qualified one.
anatofuz
parents:
diff changeset
36 std::string RawIdentifier;
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 /// The qualifiers of the scope in which SymbolIdentifier lookup
anatofuz
parents:
diff changeset
39 /// occurs. It is represented as a sequence of names and scope resolution
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
40 /// operators ::, ending with a scope resolution operator (e.g. a::b::).
150
anatofuz
parents:
diff changeset
41 /// Empty if SymbolIdentifier is not in a specific scope.
anatofuz
parents:
diff changeset
42 std::string ScopedQualifiers;
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 /// The replacement range of RawIdentifier.
anatofuz
parents:
diff changeset
45 tooling::Range Range;
anatofuz
parents:
diff changeset
46 };
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 IncludeFixerContext() = default;
anatofuz
parents:
diff changeset
49 IncludeFixerContext(StringRef FilePath,
anatofuz
parents:
diff changeset
50 std::vector<QuerySymbolInfo> QuerySymbols,
anatofuz
parents:
diff changeset
51 std::vector<find_all_symbols::SymbolInfo> Symbols);
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 /// Get symbol name.
anatofuz
parents:
diff changeset
54 llvm::StringRef getSymbolIdentifier() const {
anatofuz
parents:
diff changeset
55 return QuerySymbolInfos.front().RawIdentifier;
anatofuz
parents:
diff changeset
56 }
anatofuz
parents:
diff changeset
57
anatofuz
parents:
diff changeset
58 /// Get replacement range of the symbol.
anatofuz
parents:
diff changeset
59 tooling::Range getSymbolRange() const {
anatofuz
parents:
diff changeset
60 return QuerySymbolInfos.front().Range;
anatofuz
parents:
diff changeset
61 }
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 /// Get the file path to the file being processed.
anatofuz
parents:
diff changeset
64 StringRef getFilePath() const { return FilePath; }
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 /// Get header information.
anatofuz
parents:
diff changeset
67 const std::vector<HeaderInfo> &getHeaderInfos() const { return HeaderInfos; }
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69 /// Get information of symbols being querid.
anatofuz
parents:
diff changeset
70 const std::vector<QuerySymbolInfo> &getQuerySymbolInfos() const {
anatofuz
parents:
diff changeset
71 return QuerySymbolInfos;
anatofuz
parents:
diff changeset
72 }
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 private:
anatofuz
parents:
diff changeset
75 friend struct llvm::yaml::MappingTraits<IncludeFixerContext>;
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 /// The file path to the file being processed.
anatofuz
parents:
diff changeset
78 std::string FilePath;
anatofuz
parents:
diff changeset
79
anatofuz
parents:
diff changeset
80 /// All instances of an unidentified symbol being queried.
anatofuz
parents:
diff changeset
81 std::vector<QuerySymbolInfo> QuerySymbolInfos;
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 /// The symbol candidates which match SymbolIdentifier. The symbols are
anatofuz
parents:
diff changeset
84 /// sorted in a descending order based on the popularity info in SymbolInfo.
anatofuz
parents:
diff changeset
85 std::vector<find_all_symbols::SymbolInfo> MatchedSymbols;
anatofuz
parents:
diff changeset
86
anatofuz
parents:
diff changeset
87 /// The header information.
anatofuz
parents:
diff changeset
88 std::vector<HeaderInfo> HeaderInfos;
anatofuz
parents:
diff changeset
89 };
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 } // namespace include_fixer
anatofuz
parents:
diff changeset
92 } // namespace clang
anatofuz
parents:
diff changeset
93
anatofuz
parents:
diff changeset
94 #endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H