blob: 3c44574b8469b5e8e53747b8f4c78361eb85d71d [file] [log] [blame]
Haojian Wu11e9bd22016-05-31 09:31:51 +00001//===-- 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
Haojian Wu627ca962016-07-08 09:10:29 +000013#include "find-all-symbols/SymbolInfo.h"
14#include "clang/Tooling/Core/Replacement.h"
Haojian Wu11e9bd22016-05-31 09:31:51 +000015#include <string>
16#include <vector>
17
18namespace clang {
19namespace include_fixer {
20
Haojian Wuc99f7282016-08-09 08:26:19 +000021/// \brief A context for a file being processed. It includes all query
22/// information, e.g. symbols being queried in database, all header candidates.
Haojian Wu627ca962016-07-08 09:10:29 +000023class IncludeFixerContext {
24public:
Haojian Wu68c34a02016-07-13 16:43:54 +000025 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 };
Haojian Wu5d9482d2016-07-08 14:28:43 +000032
Haojian Wu9e4bd0c2016-07-19 14:49:04 +000033 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;
Haojian Wuc99f7282016-08-09 08:26:19 +000050 IncludeFixerContext(StringRef FilePath,
51 std::vector<QuerySymbolInfo> QuerySymbols,
Haojian Wu20dba052016-07-20 09:00:22 +000052 std::vector<find_all_symbols::SymbolInfo> Symbols);
Haojian Wu9e4bd0c2016-07-19 14:49:04 +000053
Haojian Wu627ca962016-07-08 09:10:29 +000054 /// \brief Get symbol name.
Haojian Wu9e4bd0c2016-07-19 14:49:04 +000055 llvm::StringRef getSymbolIdentifier() const {
Haojian Wu62aee522016-07-21 13:47:09 +000056 return QuerySymbolInfos.front().RawIdentifier;
Haojian Wu9e4bd0c2016-07-19 14:49:04 +000057 }
Haojian Wu627ca962016-07-08 09:10:29 +000058
59 /// \brief Get replacement range of the symbol.
Haojian Wu62aee522016-07-21 13:47:09 +000060 tooling::Range getSymbolRange() const {
61 return QuerySymbolInfos.front().Range;
62 }
Haojian Wu627ca962016-07-08 09:10:29 +000063
Haojian Wuc99f7282016-08-09 08:26:19 +000064 /// \brief Get the file path to the file being processed.
65 StringRef getFilePath() const { return FilePath; }
66
Haojian Wu62aee522016-07-21 13:47:09 +000067 /// \brief Get header information.
Haojian Wu68c34a02016-07-13 16:43:54 +000068 const std::vector<HeaderInfo> &getHeaderInfos() const { return HeaderInfos; }
Haojian Wu627ca962016-07-08 09:10:29 +000069
Haojian Wu62aee522016-07-21 13:47:09 +000070 /// \brief Get information of symbols being querid.
71 const std::vector<QuerySymbolInfo> &getQuerySymbolInfos() const {
72 return QuerySymbolInfos;
73 }
74
Haojian Wu627ca962016-07-08 09:10:29 +000075private:
76 friend struct llvm::yaml::MappingTraits<IncludeFixerContext>;
77
Haojian Wuc99f7282016-08-09 08:26:19 +000078 /// \brief The file path to the file being processed.
79 std::string FilePath;
80
Haojian Wu62aee522016-07-21 13:47:09 +000081 /// \brief All instances of an unidentified symbol being queried.
82 std::vector<QuerySymbolInfo> QuerySymbolInfos;
83
Haojian Wu627ca962016-07-08 09:10:29 +000084 /// \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
Haojian Wu68c34a02016-07-13 16:43:54 +000088 /// \brief The header information.
89 std::vector<HeaderInfo> HeaderInfos;
Haojian Wu11e9bd22016-05-31 09:31:51 +000090};
91
92} // namespace include_fixer
93} // namespace clang
94
95#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H