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