]>
Commit | Line | Data |
---|---|---|
87fcbcc4 JP |
1 | From 44023c8f43fd8daf8b7be305ea6d99b8b56fa551 Mon Sep 17 00:00:00 2001 |
2 | From: Orgad Shaneh <orgad.shaneh@audiocodes.com> | |
3 | Date: Mon, 17 Feb 2020 23:21:17 +0200 | |
4 | Subject: [PATCH] Clang: Fix build with Clang/LLVM 10 | |
5 | ||
6 | Change-Id: I740286c9dcfd325b1c31ab863fb5c91bf9c6ec70 | |
7 | Reviewed-by: hjk <hjk@qt.io> | |
8 | --- | |
9 | src/plugins/clangformat/clangformatutils.cpp | 8 ++++++ | |
10 | .../source/collectbuilddependencytoolaction.h | 17 ++++++++++- | |
11 | .../source/collectusedmacroactionfactory.h | 12 ++++++++ | |
12 | .../source/generatepchactionfactory.h | 7 +++++ | |
13 | .../source/clangquery.cpp | 3 +- | |
14 | .../source/collectsymbolsaction.h | 6 +++- | |
15 | .../source/indexdataconsumer.cpp | 28 +++++++++++++------ | |
16 | .../source/indexdataconsumer.h | 28 +++++++++++++------ | |
17 | .../source/symbolscollector.cpp | 4 +++ | |
18 | 9 files changed, 92 insertions(+), 21 deletions(-) | |
19 | ||
20 | diff --git a/src/plugins/clangformat/clangformatutils.cpp b/src/plugins/clangformat/clangformatutils.cpp | |
21 | index f087f77a948..0a32d3a9297 100644 | |
22 | --- a/src/plugins/clangformat/clangformatutils.cpp | |
23 | +++ b/src/plugins/clangformat/clangformatutils.cpp | |
24 | @@ -57,7 +57,11 @@ static clang::format::FormatStyle qtcStyle() | |
25 | style.AlignOperands = true; | |
26 | style.AlignTrailingComments = true; | |
27 | style.AllowAllParametersOfDeclarationOnNextLine = true; | |
28 | +#if LLVM_VERSION_MAJOR >= 10 | |
29 | + style.AllowShortBlocksOnASingleLine = FormatStyle::SBS_Never; | |
30 | +#else | |
31 | style.AllowShortBlocksOnASingleLine = false; | |
32 | +#endif | |
33 | style.AllowShortCaseLabelsOnASingleLine = false; | |
34 | style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; | |
35 | #if LLVM_VERSION_MAJOR >= 9 | |
36 | @@ -72,7 +76,11 @@ static clang::format::FormatStyle qtcStyle() | |
37 | style.BinPackArguments = false; | |
38 | style.BinPackParameters = false; | |
39 | style.BraceWrapping.AfterClass = true; | |
40 | +#if LLVM_VERSION_MAJOR >= 10 | |
41 | + style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_Never; | |
42 | +#else | |
43 | style.BraceWrapping.AfterControlStatement = false; | |
44 | +#endif | |
45 | style.BraceWrapping.AfterEnum = false; | |
46 | style.BraceWrapping.AfterFunction = true; | |
47 | style.BraceWrapping.AfterNamespace = false; | |
48 | diff --git a/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h b/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h | |
49 | index 538f2c7d3fa..88ed3d23448 100644 | |
50 | --- a/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h | |
51 | +++ b/src/tools/clangpchmanagerbackend/source/collectbuilddependencytoolaction.h | |
52 | @@ -60,6 +60,16 @@ class CollectBuildDependencyToolAction final : public clang::tooling::FrontendAc | |
53 | diagnosticConsumer); | |
54 | } | |
55 | ||
56 | +#if LLVM_VERSION_MAJOR >= 10 | |
57 | + std::unique_ptr<clang::FrontendAction> create() override | |
58 | + { | |
59 | + return std::make_unique<CollectBuildDependencyAction>( | |
60 | + m_buildDependency, | |
61 | + m_filePathCache, | |
62 | + m_excludedIncludeUIDs, | |
63 | + m_alreadyIncludedFileUIDs); | |
64 | + } | |
65 | +#else | |
66 | clang::FrontendAction *create() override | |
67 | { | |
68 | return new CollectBuildDependencyAction(m_buildDependency, | |
69 | @@ -67,6 +77,7 @@ class CollectBuildDependencyToolAction final : public clang::tooling::FrontendAc | |
70 | m_excludedIncludeUIDs, | |
71 | m_alreadyIncludedFileUIDs); | |
72 | } | |
73 | +#endif | |
74 | ||
75 | std::vector<uint> generateExcludedIncludeFileUIDs(clang::FileManager &fileManager) const | |
76 | { | |
77 | @@ -77,7 +88,11 @@ class CollectBuildDependencyToolAction final : public clang::tooling::FrontendAc | |
78 | NativeFilePath nativeFilePath{filePath}; | |
79 | const clang::FileEntry *file = fileManager.getFile({nativeFilePath.path().data(), | |
80 | nativeFilePath.path().size()}, | |
81 | - true); | |
82 | + true) | |
83 | +#if LLVM_VERSION_MAJOR >= 10 | |
84 | + .get() | |
85 | +#endif | |
86 | + ; | |
87 | ||
88 | if (file) | |
89 | fileUIDs.push_back(file->getUID()); | |
90 | diff --git a/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h b/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h | |
91 | index 423d5f88764..473b8e7df8a 100644 | |
92 | --- a/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h | |
93 | +++ b/src/tools/clangpchmanagerbackend/source/collectusedmacroactionfactory.h | |
94 | @@ -61,6 +61,17 @@ class CollectUsedMacrosToolActionFactory final : public clang::tooling::Frontend | |
95 | diagnosticConsumer); | |
96 | } | |
97 | ||
98 | +#if LLVM_VERSION_MAJOR >= 10 | |
99 | + std::unique_ptr<clang::FrontendAction> create() override | |
100 | + { | |
101 | + return std::make_unique<CollectUsedMacrosAction>( | |
102 | + m_usedMacros, | |
103 | + m_filePathCache, | |
104 | + m_sourceDependencies, | |
105 | + m_sourceFiles, | |
106 | + m_fileStatuses); | |
107 | + } | |
108 | +#else | |
109 | clang::FrontendAction *create() override | |
110 | { | |
111 | return new CollectUsedMacrosAction(m_usedMacros, | |
112 | @@ -69,6 +80,7 @@ class CollectUsedMacrosToolActionFactory final : public clang::tooling::Frontend | |
113 | m_sourceFiles, | |
114 | m_fileStatuses); | |
115 | } | |
116 | +#endif | |
117 | ||
118 | private: | |
119 | UsedMacros &m_usedMacros; | |
120 | diff --git a/src/tools/clangpchmanagerbackend/source/generatepchactionfactory.h b/src/tools/clangpchmanagerbackend/source/generatepchactionfactory.h | |
121 | index c4a8cae0286..f1e4c74457e 100644 | |
122 | --- a/src/tools/clangpchmanagerbackend/source/generatepchactionfactory.h | |
123 | +++ b/src/tools/clangpchmanagerbackend/source/generatepchactionfactory.h | |
124 | @@ -68,10 +68,17 @@ class GeneratePCHActionFactory final : public clang::tooling::FrontendActionFact | |
125 | , m_fileContent(fileContent) | |
126 | {} | |
127 | ||
128 | +#if LLVM_VERSION_MAJOR >= 10 | |
129 | + std::unique_ptr<clang::FrontendAction> create() override | |
130 | + { | |
131 | + return std::make_unique<GeneratePCHAction>(m_filePath, m_fileContent); | |
132 | + } | |
133 | +#else | |
134 | clang::FrontendAction *create() override | |
135 | { | |
136 | return new GeneratePCHAction{m_filePath, m_fileContent}; | |
137 | } | |
138 | +#endif | |
139 | ||
140 | private: | |
141 | llvm::StringRef m_filePath; | |
142 | diff --git a/src/tools/clangrefactoringbackend/source/clangquery.cpp b/src/tools/clangrefactoringbackend/source/clangquery.cpp | |
143 | index 21ebeb83674..78f2350d8de 100644 | |
144 | --- a/src/tools/clangrefactoringbackend/source/clangquery.cpp | |
145 | +++ b/src/tools/clangrefactoringbackend/source/clangquery.cpp | |
146 | @@ -78,7 +78,8 @@ void ClangQuery::findLocations() | |
147 | std::make_move_iterator(asts.end()), | |
148 | [&] (std::unique_ptr<clang::ASTUnit> &&ast) { | |
149 | Diagnostics diagnostics; | |
150 | - auto optionalMatcher = Parser::parseMatcherExpression({m_query.data(), m_query.size()}, | |
151 | + llvm::StringRef query{m_query.data(), m_query.size()}; | |
152 | + auto optionalMatcher = Parser::parseMatcherExpression(query, | |
153 | nullptr, | |
154 | &diagnostics); | |
155 | parseDiagnostics(diagnostics); | |
156 | diff --git a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h | |
157 | index a38f1c4f879..4f36adadf5f 100644 | |
158 | --- a/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h | |
159 | +++ b/src/tools/clangrefactoringbackend/source/collectsymbolsaction.h | |
160 | @@ -48,7 +48,11 @@ class CollectSymbolsAction : public clang::WrapperFrontendAction | |
161 | public: | |
162 | CollectSymbolsAction(std::shared_ptr<IndexDataConsumer> indexDataConsumer) | |
163 | : clang::WrapperFrontendAction( | |
164 | - clang::index::createIndexingAction(indexDataConsumer, createIndexingOptions(), nullptr)) | |
165 | + clang::index::createIndexingAction(indexDataConsumer, createIndexingOptions() | |
166 | +#if LLVM_VERSION_MAJOR < 10 | |
167 | + , nullptr | |
168 | +#endif | |
169 | + )) | |
170 | , m_indexDataConsumer(indexDataConsumer) | |
171 | {} | |
172 | ||
173 | diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp | |
174 | index e2871444625..5d21b30b9c2 100644 | |
175 | --- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp | |
176 | +++ b/src/tools/clangrefactoringbackend/source/indexdataconsumer.cpp | |
177 | @@ -118,11 +118,16 @@ bool IndexDataConsumer::isAlreadyParsed(clang::FileID fileId, SourcesManager &so | |
178 | return sourcesManager.alreadyParsed(filePathId(fileEntry), fileEntry->getModificationTime()); | |
179 | } | |
180 | ||
181 | -bool IndexDataConsumer::handleDeclOccurence(const clang::Decl *declaration, | |
182 | - clang::index::SymbolRoleSet symbolRoles, | |
183 | - llvm::ArrayRef<clang::index::SymbolRelation> /*symbolRelations*/, | |
184 | - clang::SourceLocation sourceLocation, | |
185 | - IndexDataConsumer::ASTNodeInfo /*astNodeInfo*/) | |
186 | +#if LLVM_VERSION_MAJOR >= 10 | |
187 | + bool IndexDataConsumer::handleDeclOccurrence( | |
188 | +#else | |
189 | + bool IndexDataConsumer::handleDeclOccurence( | |
190 | +#endif | |
191 | + const clang::Decl *declaration, | |
192 | + clang::index::SymbolRoleSet symbolRoles, | |
193 | + llvm::ArrayRef<clang::index::SymbolRelation> /*symbolRelations*/, | |
194 | + clang::SourceLocation sourceLocation, | |
195 | + IndexDataConsumer::ASTNodeInfo /*astNodeInfo*/) | |
196 | { | |
197 | const auto *namedDeclaration = clang::dyn_cast<clang::NamedDecl>(declaration); | |
198 | if (namedDeclaration) { | |
199 | @@ -175,10 +180,15 @@ SourceLocationKind macroSymbolType(clang::index::SymbolRoleSet roles) | |
200 | ||
201 | } // namespace | |
202 | ||
203 | -bool IndexDataConsumer::handleMacroOccurence(const clang::IdentifierInfo *identifierInfo, | |
204 | - const clang::MacroInfo *macroInfo, | |
205 | - clang::index::SymbolRoleSet roles, | |
206 | - clang::SourceLocation sourceLocation) | |
207 | +#if LLVM_VERSION_MAJOR >= 10 | |
208 | +bool IndexDataConsumer::handleMacroOccurrence( | |
209 | +#else | |
210 | +bool IndexDataConsumer::handleMacroOccurence( | |
211 | +#endif | |
212 | + const clang::IdentifierInfo *identifierInfo, | |
213 | + const clang::MacroInfo *macroInfo, | |
214 | + clang::index::SymbolRoleSet roles, | |
215 | + clang::SourceLocation sourceLocation) | |
216 | { | |
217 | if (macroInfo && sourceLocation.isFileID() | |
218 | && !isAlreadyParsed(m_sourceManager->getFileID(sourceLocation), m_macroSourcesManager) | |
219 | diff --git a/src/tools/clangrefactoringbackend/source/indexdataconsumer.h b/src/tools/clangrefactoringbackend/source/indexdataconsumer.h | |
220 | index c80e066b6c1..e1d3529806e 100644 | |
221 | --- a/src/tools/clangrefactoringbackend/source/indexdataconsumer.h | |
222 | +++ b/src/tools/clangrefactoringbackend/source/indexdataconsumer.h | |
223 | @@ -57,16 +57,26 @@ class IndexDataConsumer : public clang::index::IndexDataConsumer, | |
224 | IndexDataConsumer(const IndexDataConsumer &) = delete; | |
225 | IndexDataConsumer &operator=(const IndexDataConsumer &) = delete; | |
226 | ||
227 | - bool handleDeclOccurence(const clang::Decl *declaration, | |
228 | - clang::index::SymbolRoleSet symbolRoles, | |
229 | - llvm::ArrayRef<clang::index::SymbolRelation> symbolRelations, | |
230 | - clang::SourceLocation sourceLocation, | |
231 | - ASTNodeInfo astNodeInfo) override; | |
232 | +#if LLVM_VERSION_MAJOR >= 10 | |
233 | + bool handleDeclOccurrence( | |
234 | +#else | |
235 | + bool handleDeclOccurence( | |
236 | +#endif | |
237 | + const clang::Decl *declaration, | |
238 | + clang::index::SymbolRoleSet symbolRoles, | |
239 | + llvm::ArrayRef<clang::index::SymbolRelation> symbolRelations, | |
240 | + clang::SourceLocation sourceLocation, | |
241 | + ASTNodeInfo astNodeInfo) override; | |
242 | ||
243 | - bool handleMacroOccurence(const clang::IdentifierInfo *identifierInfo, | |
244 | - const clang::MacroInfo *macroInfo, | |
245 | - clang::index::SymbolRoleSet roles, | |
246 | - clang::SourceLocation sourceLocation) override; | |
247 | +#if LLVM_VERSION_MAJOR >= 10 | |
248 | + bool handleMacroOccurrence( | |
249 | +#else | |
250 | + bool handleMacroOccurence( | |
251 | +#endif | |
252 | + const clang::IdentifierInfo *identifierInfo, | |
253 | + const clang::MacroInfo *macroInfo, | |
254 | + clang::index::SymbolRoleSet roles, | |
255 | + clang::SourceLocation sourceLocation) override; | |
256 | ||
257 | void finish() override; | |
258 | ||
259 | diff --git a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp | |
260 | index a233f6d8fe5..dffd5838944 100644 | |
261 | --- a/src/tools/clangrefactoringbackend/source/symbolscollector.cpp | |
262 | +++ b/src/tools/clangrefactoringbackend/source/symbolscollector.cpp | |
263 | @@ -74,7 +74,11 @@ std::unique_ptr<clang::tooling::FrontendActionFactory> newFrontendActionFactory( | |
264 | : m_action(consumerFactory) | |
265 | {} | |
266 | ||
267 | +#if LLVM_VERSION_MAJOR >= 10 | |
268 | + std::unique_ptr<clang::FrontendAction> create() override { return std::make_unique<AdaptorAction>(m_action); } | |
269 | +#else | |
270 | clang::FrontendAction *create() override { return new AdaptorAction(m_action); } | |
271 | +#endif | |
272 | ||
273 | private: | |
274 | class AdaptorAction : public clang::ASTFrontendAction |