blob: f5d3e91835d55a13b0cebda6d3d6252eaa43f148 [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
21/// \brief A context for the symbol being queried.
Haojian Wu627ca962016-07-08 09:10:29 +000022class IncludeFixerContext {
23public:
Haojian Wu783d4312016-07-08 13:11:38 +000024 IncludeFixerContext() = default;
Haojian Wu627ca962016-07-08 09:10:29 +000025 IncludeFixerContext(llvm::StringRef Name, llvm::StringRef ScopeQualifiers,
26 const std::vector<find_all_symbols::SymbolInfo> Symbols,
Haojian Wu783d4312016-07-08 13:11:38 +000027 tooling::Range Range);
Haojian Wu627ca962016-07-08 09:10:29 +000028
Haojian Wu68c34a02016-07-13 16:43:54 +000029 struct HeaderInfo {
30 /// \brief The header where QualifiedName comes from.
31 std::string Header;
32 /// \brief A symbol name with completed namespace qualifiers which will
33 /// replace the original symbol.
34 std::string QualifiedName;
35 };
Haojian Wu5d9482d2016-07-08 14:28:43 +000036
Haojian Wu627ca962016-07-08 09:10:29 +000037 /// \brief Get symbol name.
38 llvm::StringRef getSymbolIdentifier() const { return SymbolIdentifier; }
39
40 /// \brief Get replacement range of the symbol.
41 tooling::Range getSymbolRange() const { return SymbolRange; }
42
Haojian Wu68c34a02016-07-13 16:43:54 +000043 const std::vector<HeaderInfo> &getHeaderInfos() const { return HeaderInfos; }
Haojian Wu627ca962016-07-08 09:10:29 +000044
45private:
46 friend struct llvm::yaml::MappingTraits<IncludeFixerContext>;
47
Haojian Wu68c34a02016-07-13 16:43:54 +000048 /// \brief The raw symbol name being queried in database. This name might miss
49 /// some namespace qualifiers, and will be replaced by a fully qualified one.
Haojian Wu17a54e32016-06-01 11:43:10 +000050 std::string SymbolIdentifier;
Haojian Wu627ca962016-07-08 09:10:29 +000051
52 /// \brief The qualifiers of the scope in which SymbolIdentifier lookup
53 /// occurs. It is represented as a sequence of names and scope resolution
54 /// operatiors ::, ending with a scope resolution operator (e.g. a::b::).
55 /// Empty if SymbolIdentifier is not in a specific scope.
56 std::string SymbolScopedQualifiers;
57
Haojian Wu627ca962016-07-08 09:10:29 +000058 /// \brief The symbol candidates which match SymbolIdentifier. The symbols are
59 /// sorted in a descending order based on the popularity info in SymbolInfo.
60 std::vector<find_all_symbols::SymbolInfo> MatchedSymbols;
61
62 /// \brief The replacement range of SymbolIdentifier.
63 tooling::Range SymbolRange;
Haojian Wu68c34a02016-07-13 16:43:54 +000064
65 /// \brief The header information.
66 std::vector<HeaderInfo> HeaderInfos;
Haojian Wu11e9bd22016-05-31 09:31:51 +000067};
68
69} // namespace include_fixer
70} // namespace clang
71
72#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXERCONTEXT_H