Mercurial > hg > CbC > CbC_llvm
comparison clang-tools-extra/clangd/Preamble.h @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 0572611fdcc8 |
children | 5f20bc1ed4ff |
comparison
equal
deleted
inserted
replaced
220:42394fc6a535 | 221:79ff65ed7e25 |
---|---|
29 #include "Headers.h" | 29 #include "Headers.h" |
30 #include "index/CanonicalIncludes.h" | 30 #include "index/CanonicalIncludes.h" |
31 #include "support/Path.h" | 31 #include "support/Path.h" |
32 #include "clang/Frontend/CompilerInvocation.h" | 32 #include "clang/Frontend/CompilerInvocation.h" |
33 #include "clang/Frontend/PrecompiledPreamble.h" | 33 #include "clang/Frontend/PrecompiledPreamble.h" |
34 #include "clang/Lex/Lexer.h" | |
34 #include "clang/Tooling/CompilationDatabase.h" | 35 #include "clang/Tooling/CompilationDatabase.h" |
35 #include "llvm/ADT/StringRef.h" | 36 #include "llvm/ADT/StringRef.h" |
36 | 37 |
37 #include <memory> | 38 #include <memory> |
38 #include <string> | 39 #include <string> |
89 bool isPreambleCompatible(const PreambleData &Preamble, | 90 bool isPreambleCompatible(const PreambleData &Preamble, |
90 const ParseInputs &Inputs, PathRef FileName, | 91 const ParseInputs &Inputs, PathRef FileName, |
91 const CompilerInvocation &CI); | 92 const CompilerInvocation &CI); |
92 | 93 |
93 /// Stores information required to parse a TU using a (possibly stale) Baseline | 94 /// Stores information required to parse a TU using a (possibly stale) Baseline |
94 /// preamble. Updates compiler invocation to approximately reflect additions to | 95 /// preamble. Later on this information can be injected into the main file by |
95 /// the preamble section of Modified contents, e.g. new include directives. | 96 /// updating compiler invocation with \c apply. This injected section |
97 /// approximately reflects additions to the preamble in Modified contents, e.g. | |
98 /// new include directives. | |
96 class PreamblePatch { | 99 class PreamblePatch { |
97 public: | 100 public: |
98 // With an empty patch, the preamble is used verbatim. | 101 /// \p Preamble is used verbatim. |
99 PreamblePatch() = default; | 102 static PreamblePatch unmodified(const PreambleData &Preamble); |
100 /// Builds a patch that contains new PP directives introduced to the preamble | 103 /// Builds a patch that contains new PP directives introduced to the preamble |
101 /// section of \p Modified compared to \p Baseline. | 104 /// section of \p Modified compared to \p Baseline. |
102 /// FIXME: This only handles include directives, we should at least handle | 105 /// FIXME: This only handles include directives, we should at least handle |
103 /// define/undef. | 106 /// define/undef. |
104 static PreamblePatch create(llvm::StringRef FileName, | 107 static PreamblePatch create(llvm::StringRef FileName, |
107 /// Adjusts CI (which compiles the modified inputs) to be used with the | 110 /// Adjusts CI (which compiles the modified inputs) to be used with the |
108 /// baseline preamble. This is done by inserting an artifical include to the | 111 /// baseline preamble. This is done by inserting an artifical include to the |
109 /// \p CI that contains new directives calculated in create. | 112 /// \p CI that contains new directives calculated in create. |
110 void apply(CompilerInvocation &CI) const; | 113 void apply(CompilerInvocation &CI) const; |
111 | 114 |
115 /// Returns #include directives from the \c Modified preamble that were | |
116 /// resolved using the \c Baseline preamble. This covers the new locations of | |
117 /// inclusions that were moved around, but not inclusions of new files. Those | |
118 /// will be recorded when parsing the main file: the includes in the injected | |
119 /// section will be resolved back to their spelled positions in the main file | |
120 /// using the presumed-location mechanism. | |
121 std::vector<Inclusion> preambleIncludes() const; | |
122 | |
123 /// Returns preamble bounds for the Modified. | |
124 PreambleBounds modifiedBounds() const { return ModifiedBounds; } | |
125 | |
126 /// Returns textual patch contents. | |
127 llvm::StringRef text() const { return PatchContents; } | |
128 | |
129 /// Whether diagnostics generated using this patch are trustable. | |
130 bool preserveDiagnostics() const { return PatchContents.empty(); } | |
131 | |
112 private: | 132 private: |
133 PreamblePatch() = default; | |
113 std::string PatchContents; | 134 std::string PatchContents; |
114 std::string PatchFileName; | 135 std::string PatchFileName; |
136 /// Includes that are present in both \p Baseline and \p Modified. Used for | |
137 /// patching includes of baseline preamble. | |
138 std::vector<Inclusion> PreambleIncludes; | |
139 PreambleBounds ModifiedBounds = {0, false}; | |
115 }; | 140 }; |
141 | |
142 /// Translates locations inside preamble patch to their main-file equivalent | |
143 /// using presumed locations. Returns \p Loc if it isn't inside preamble patch. | |
144 SourceLocation translatePreamblePatchLocation(SourceLocation Loc, | |
145 const SourceManager &SM); | |
116 | 146 |
117 } // namespace clangd | 147 } // namespace clangd |
118 } // namespace clang | 148 } // namespace clang |
119 | 149 |
120 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREAMBLE_H | 150 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_PREAMBLE_H |