/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/libclang/CIndex.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- CIndex.cpp - Clang-C Source Indexing Library -----------------------===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file implements the main API hooks in the Clang-C Source Indexing |
10 | | // library. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "CIndexDiagnostic.h" |
15 | | #include "CIndexer.h" |
16 | | #include "CLog.h" |
17 | | #include "CXCursor.h" |
18 | | #include "CXSourceLocation.h" |
19 | | #include "CXString.h" |
20 | | #include "CXTranslationUnit.h" |
21 | | #include "CXType.h" |
22 | | #include "CursorVisitor.h" |
23 | | #include "clang-c/FatalErrorHandler.h" |
24 | | #include "clang/AST/Attr.h" |
25 | | #include "clang/AST/DeclObjCCommon.h" |
26 | | #include "clang/AST/Mangle.h" |
27 | | #include "clang/AST/OpenMPClause.h" |
28 | | #include "clang/AST/StmtVisitor.h" |
29 | | #include "clang/Basic/Diagnostic.h" |
30 | | #include "clang/Basic/DiagnosticCategories.h" |
31 | | #include "clang/Basic/DiagnosticIDs.h" |
32 | | #include "clang/Basic/Stack.h" |
33 | | #include "clang/Basic/TargetInfo.h" |
34 | | #include "clang/Basic/Version.h" |
35 | | #include "clang/Frontend/ASTUnit.h" |
36 | | #include "clang/Frontend/CompilerInstance.h" |
37 | | #include "clang/Index/CommentToXML.h" |
38 | | #include "clang/Lex/HeaderSearch.h" |
39 | | #include "clang/Lex/Lexer.h" |
40 | | #include "clang/Lex/PreprocessingRecord.h" |
41 | | #include "clang/Lex/Preprocessor.h" |
42 | | #include "llvm/ADT/Optional.h" |
43 | | #include "llvm/ADT/STLExtras.h" |
44 | | #include "llvm/ADT/StringSwitch.h" |
45 | | #include "llvm/Config/llvm-config.h" |
46 | | #include "llvm/Support/Compiler.h" |
47 | | #include "llvm/Support/CrashRecoveryContext.h" |
48 | | #include "llvm/Support/Format.h" |
49 | | #include "llvm/Support/ManagedStatic.h" |
50 | | #include "llvm/Support/MemoryBuffer.h" |
51 | | #include "llvm/Support/Program.h" |
52 | | #include "llvm/Support/SaveAndRestore.h" |
53 | | #include "llvm/Support/Signals.h" |
54 | | #include "llvm/Support/TargetSelect.h" |
55 | | #include "llvm/Support/Threading.h" |
56 | | #include "llvm/Support/Timer.h" |
57 | | #include "llvm/Support/raw_ostream.h" |
58 | | #include "llvm/Support/thread.h" |
59 | | #include <mutex> |
60 | | |
61 | | #if LLVM_ENABLE_THREADS != 0 && defined(__APPLE__) |
62 | | #define USE_DARWIN_THREADS |
63 | | #endif |
64 | | |
65 | | #ifdef USE_DARWIN_THREADS |
66 | | #include <pthread.h> |
67 | | #endif |
68 | | |
69 | | using namespace clang; |
70 | | using namespace clang::cxcursor; |
71 | | using namespace clang::cxtu; |
72 | | using namespace clang::cxindex; |
73 | | |
74 | | CXTranslationUnit cxtu::MakeCXTranslationUnit(CIndexer *CIdx, |
75 | 1.05k | std::unique_ptr<ASTUnit> AU) { |
76 | 1.05k | if (!AU) |
77 | 2 | return nullptr; |
78 | 1.05k | assert(CIdx); |
79 | 0 | CXTranslationUnit D = new CXTranslationUnitImpl(); |
80 | 1.05k | D->CIdx = CIdx; |
81 | 1.05k | D->TheASTUnit = AU.release(); |
82 | 1.05k | D->StringPool = new cxstring::CXStringPool(); |
83 | 1.05k | D->Diagnostics = nullptr; |
84 | 1.05k | D->OverridenCursorsPool = createOverridenCXCursorsPool(); |
85 | 1.05k | D->CommentToXML = nullptr; |
86 | 1.05k | D->ParsingOptions = 0; |
87 | 1.05k | D->Arguments = {}; |
88 | 1.05k | return D; |
89 | 1.05k | } |
90 | | |
91 | 1.02k | bool cxtu::isASTReadError(ASTUnit *AU) { |
92 | 1.02k | for (ASTUnit::stored_diag_iterator D = AU->stored_diag_begin(), |
93 | 1.02k | DEnd = AU->stored_diag_end(); |
94 | 6.06k | D != DEnd; ++D5.04k ) { |
95 | 5.04k | if (D->getLevel() >= DiagnosticsEngine::Error && |
96 | 5.04k | DiagnosticIDs::getCategoryNumberForDiag(D->getID()) == |
97 | 1.69k | diag::DiagCat_AST_Deserialization_Issue) |
98 | 2 | return true; |
99 | 5.04k | } |
100 | 1.02k | return false; |
101 | 1.02k | } |
102 | | |
103 | 39 | cxtu::CXTUOwner::~CXTUOwner() { |
104 | 39 | if (TU) |
105 | 39 | clang_disposeTranslationUnit(TU); |
106 | 39 | } |
107 | | |
108 | | /// Compare two source ranges to determine their relative position in |
109 | | /// the translation unit. |
110 | | static RangeComparisonResult RangeCompare(SourceManager &SM, SourceRange R1, |
111 | 36.3k | SourceRange R2) { |
112 | 36.3k | assert(R1.isValid() && "First range is invalid?"); |
113 | 0 | assert(R2.isValid() && "Second range is invalid?"); |
114 | 36.3k | if (R1.getEnd() != R2.getBegin() && |
115 | 36.3k | SM.isBeforeInTranslationUnit(R1.getEnd(), R2.getBegin())35.8k ) |
116 | 16.5k | return RangeBefore; |
117 | 19.7k | if (R2.getEnd() != R1.getBegin() && |
118 | 19.7k | SM.isBeforeInTranslationUnit(R2.getEnd(), R1.getBegin())19.3k ) |
119 | 3.29k | return RangeAfter; |
120 | 16.4k | return RangeOverlap; |
121 | 19.7k | } |
122 | | |
123 | | /// Determine if a source location falls within, before, or after a |
124 | | /// a given source range. |
125 | | static RangeComparisonResult LocationCompare(SourceManager &SM, |
126 | 23.6M | SourceLocation L, SourceRange R) { |
127 | 23.6M | assert(R.isValid() && "First range is invalid?"); |
128 | 0 | assert(L.isValid() && "Second range is invalid?"); |
129 | 23.6M | if (L == R.getBegin() || L == R.getEnd()23.6M ) |
130 | 23.9k | return RangeOverlap; |
131 | 23.6M | if (SM.isBeforeInTranslationUnit(L, R.getBegin())) |
132 | 23.6M | return RangeBefore; |
133 | 24.3k | if (SM.isBeforeInTranslationUnit(R.getEnd(), L)) |
134 | 18.2k | return RangeAfter; |
135 | 6.15k | return RangeOverlap; |
136 | 24.3k | } |
137 | | |
138 | | /// Translate a Clang source range into a CIndex source range. |
139 | | /// |
140 | | /// Clang internally represents ranges where the end location points to the |
141 | | /// start of the token at the end. However, for external clients it is more |
142 | | /// useful to have a CXSourceRange be a proper half-open interval. This routine |
143 | | /// does the appropriate translation. |
144 | | CXSourceRange cxloc::translateSourceRange(const SourceManager &SM, |
145 | | const LangOptions &LangOpts, |
146 | 361k | const CharSourceRange &R) { |
147 | | // We want the last character in this location, so we will adjust the |
148 | | // location accordingly. |
149 | 361k | SourceLocation EndLoc = R.getEnd(); |
150 | 361k | bool IsTokenRange = R.isTokenRange(); |
151 | 361k | if (EndLoc.isValid() && EndLoc.isMacroID()361k && |
152 | 361k | !SM.isMacroArgExpansion(EndLoc)1.37k ) { |
153 | 844 | CharSourceRange Expansion = SM.getExpansionRange(EndLoc); |
154 | 844 | EndLoc = Expansion.getEnd(); |
155 | 844 | IsTokenRange = Expansion.isTokenRange(); |
156 | 844 | } |
157 | 361k | if (IsTokenRange && EndLoc.isValid()361k ) { |
158 | 361k | unsigned Length = |
159 | 361k | Lexer::MeasureTokenLength(SM.getSpellingLoc(EndLoc), SM, LangOpts); |
160 | 361k | EndLoc = EndLoc.getLocWithOffset(Length); |
161 | 361k | } |
162 | | |
163 | 361k | CXSourceRange Result = { |
164 | 361k | {&SM, &LangOpts}, R.getBegin().getRawEncoding(), EndLoc.getRawEncoding()}; |
165 | 361k | return Result; |
166 | 361k | } |
167 | | |
168 | 4 | CharSourceRange cxloc::translateCXRangeToCharRange(CXSourceRange R) { |
169 | 4 | return CharSourceRange::getCharRange( |
170 | 4 | SourceLocation::getFromRawEncoding(R.begin_int_data), |
171 | 4 | SourceLocation::getFromRawEncoding(R.end_int_data)); |
172 | 4 | } |
173 | | |
174 | | //===----------------------------------------------------------------------===// |
175 | | // Cursor visitor. |
176 | | //===----------------------------------------------------------------------===// |
177 | | |
178 | | static SourceRange getRawCursorExtent(CXCursor C); |
179 | | static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr); |
180 | | |
181 | 25.6k | RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) { |
182 | 25.6k | return RangeCompare(AU->getSourceManager(), R, RegionOfInterest); |
183 | 25.6k | } |
184 | | |
185 | | /// Visit the given cursor and, if requested by the visitor, |
186 | | /// its children. |
187 | | /// |
188 | | /// \param Cursor the cursor to visit. |
189 | | /// |
190 | | /// \param CheckedRegionOfInterest if true, then the caller already checked |
191 | | /// that this cursor is within the region of interest. |
192 | | /// |
193 | | /// \returns true if the visitation should be aborted, false if it |
194 | | /// should continue. |
195 | 91.6k | bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) { |
196 | 91.6k | if (clang_isInvalid(Cursor.kind)) |
197 | 1 | return false; |
198 | | |
199 | 91.6k | if (clang_isDeclaration(Cursor.kind)) { |
200 | 9.88k | const Decl *D = getCursorDecl(Cursor); |
201 | 9.88k | if (!D) { |
202 | 0 | assert(0 && "Invalid declaration cursor"); |
203 | 0 | return true; // abort. |
204 | 0 | } |
205 | | |
206 | | // Ignore implicit declarations, unless it's an objc method because |
207 | | // currently we should report implicit methods for properties when indexing. |
208 | 9.88k | if (D->isImplicit() && !isa<ObjCMethodDecl>(D)2.04k ) |
209 | 1.92k | return false; |
210 | 9.88k | } |
211 | | |
212 | | // If we have a range of interest, and this cursor doesn't intersect with it, |
213 | | // we're done. |
214 | 89.7k | if (RegionOfInterest.isValid() && !CheckedRegionOfInterest11.3k ) { |
215 | 9.26k | SourceRange Range = getRawCursorExtent(Cursor); |
216 | 9.26k | if (Range.isInvalid() || CompareRegionOfInterest(Range)9.26k ) |
217 | 7.15k | return false; |
218 | 9.26k | } |
219 | | |
220 | 82.5k | switch (Visitor(Cursor, Parent, ClientData)) { |
221 | 18 | case CXChildVisit_Break: |
222 | 18 | return true; |
223 | | |
224 | 6.58k | case CXChildVisit_Continue: |
225 | 6.58k | return false; |
226 | | |
227 | 75.9k | case CXChildVisit_Recurse: { |
228 | 75.9k | bool ret = VisitChildren(Cursor); |
229 | 75.9k | if (PostChildrenVisitor) |
230 | 1.20k | if (PostChildrenVisitor(Cursor, ClientData)) |
231 | 0 | return true; |
232 | 75.9k | return ret; |
233 | 75.9k | } |
234 | 82.5k | } |
235 | | |
236 | 0 | llvm_unreachable("Invalid CXChildVisitResult!"); |
237 | 0 | } |
238 | | |
239 | | static bool visitPreprocessedEntitiesInRange(SourceRange R, |
240 | | PreprocessingRecord &PPRec, |
241 | 9.57k | CursorVisitor &Visitor) { |
242 | 9.57k | SourceManager &SM = Visitor.getASTUnit()->getSourceManager(); |
243 | 9.57k | FileID FID; |
244 | | |
245 | 9.57k | if (!Visitor.shouldVisitIncludedEntities()) { |
246 | | // If the begin/end of the range lie in the same FileID, do the optimization |
247 | | // where we skip preprocessed entities that do not come from the same |
248 | | // FileID. |
249 | 9.57k | FID = SM.getFileID(SM.getFileLoc(R.getBegin())); |
250 | 9.57k | if (FID != SM.getFileID(SM.getFileLoc(R.getEnd()))) |
251 | 0 | FID = FileID(); |
252 | 9.57k | } |
253 | | |
254 | 9.57k | const auto &Entities = PPRec.getPreprocessedEntitiesInRange(R); |
255 | 9.57k | return Visitor.visitPreprocessedEntities(Entities.begin(), Entities.end(), |
256 | 9.57k | PPRec, FID); |
257 | 9.57k | } |
258 | | |
259 | 9.53k | bool CursorVisitor::visitFileRegion() { |
260 | 9.53k | if (RegionOfInterest.isInvalid()) |
261 | 0 | return false; |
262 | | |
263 | 9.53k | ASTUnit *Unit = cxtu::getASTUnit(TU); |
264 | 9.53k | SourceManager &SM = Unit->getSourceManager(); |
265 | | |
266 | 9.53k | std::pair<FileID, unsigned> Begin = SM.getDecomposedLoc( |
267 | 9.53k | SM.getFileLoc(RegionOfInterest.getBegin())), |
268 | 9.53k | End = SM.getDecomposedLoc( |
269 | 9.53k | SM.getFileLoc(RegionOfInterest.getEnd())); |
270 | | |
271 | 9.53k | if (End.first != Begin.first) { |
272 | | // If the end does not reside in the same file, try to recover by |
273 | | // picking the end of the file of begin location. |
274 | 0 | End.first = Begin.first; |
275 | 0 | End.second = SM.getFileIDSize(Begin.first); |
276 | 0 | } |
277 | | |
278 | 9.53k | assert(Begin.first == End.first); |
279 | 9.53k | if (Begin.second > End.second) |
280 | 0 | return false; |
281 | | |
282 | 9.53k | FileID File = Begin.first; |
283 | 9.53k | unsigned Offset = Begin.second; |
284 | 9.53k | unsigned Length = End.second - Begin.second; |
285 | | |
286 | 9.53k | if (!VisitDeclsOnly && !VisitPreprocessorLast9.50k ) |
287 | 0 | if (visitPreprocessedEntitiesInRegion()) |
288 | 0 | return true; // visitation break. |
289 | | |
290 | 9.53k | if (visitDeclsFromFileRegion(File, Offset, Length)) |
291 | 13 | return true; // visitation break. |
292 | | |
293 | 9.51k | if (!VisitDeclsOnly && VisitPreprocessorLast9.49k ) |
294 | 9.49k | return visitPreprocessedEntitiesInRegion(); |
295 | | |
296 | 24 | return false; |
297 | 9.51k | } |
298 | | |
299 | 10.7k | static bool isInLexicalContext(Decl *D, DeclContext *DC) { |
300 | 10.7k | if (!DC) |
301 | 9.63k | return false; |
302 | | |
303 | 2.26k | for (DeclContext *DeclDC = D->getLexicalDeclContext(); 1.15k DeclDC; |
304 | 1.15k | DeclDC = DeclDC->getLexicalParent()1.11k ) { |
305 | 1.15k | if (DeclDC == DC) |
306 | 40 | return true; |
307 | 1.15k | } |
308 | 1.11k | return false; |
309 | 1.15k | } |
310 | | |
311 | | bool CursorVisitor::visitDeclsFromFileRegion(FileID File, unsigned Offset, |
312 | 9.53k | unsigned Length) { |
313 | 9.53k | ASTUnit *Unit = cxtu::getASTUnit(TU); |
314 | 9.53k | SourceManager &SM = Unit->getSourceManager(); |
315 | 9.53k | SourceRange Range = RegionOfInterest; |
316 | | |
317 | 9.53k | SmallVector<Decl *, 16> Decls; |
318 | 9.53k | Unit->findFileRegionDecls(File, Offset, Length, Decls); |
319 | | |
320 | | // If we didn't find any file level decls for the file, try looking at the |
321 | | // file that it was included from. |
322 | 9.54k | while (Decls.empty() || Decls.front()->isTopLevelDeclInObjCContainer()9.51k ) { |
323 | 29 | bool Invalid = false; |
324 | 29 | const SrcMgr::SLocEntry &SLEntry = SM.getSLocEntry(File, &Invalid); |
325 | 29 | if (Invalid) |
326 | 0 | return false; |
327 | | |
328 | 29 | SourceLocation Outer; |
329 | 29 | if (SLEntry.isFile()) |
330 | 29 | Outer = SLEntry.getFile().getIncludeLoc(); |
331 | 0 | else |
332 | 0 | Outer = SLEntry.getExpansion().getExpansionLocStart(); |
333 | 29 | if (Outer.isInvalid()) |
334 | 14 | return false; |
335 | | |
336 | 15 | std::tie(File, Offset) = SM.getDecomposedExpansionLoc(Outer); |
337 | 15 | Length = 0; |
338 | 15 | Unit->findFileRegionDecls(File, Offset, Length, Decls); |
339 | 15 | } |
340 | | |
341 | 9.51k | assert(!Decls.empty()); |
342 | | |
343 | 0 | bool VisitedAtLeastOnce = false; |
344 | 9.51k | DeclContext *CurDC = nullptr; |
345 | 9.51k | SmallVectorImpl<Decl *>::iterator DIt = Decls.begin(); |
346 | 18.4k | for (SmallVectorImpl<Decl *>::iterator DE = Decls.end(); DIt != DE; ++DIt8.95k ) { |
347 | 10.7k | Decl *D = *DIt; |
348 | 10.7k | if (D->getSourceRange().isInvalid()) |
349 | 0 | continue; |
350 | | |
351 | 10.7k | if (isInLexicalContext(D, CurDC)) |
352 | 40 | continue; |
353 | | |
354 | 10.7k | CurDC = dyn_cast<DeclContext>(D); |
355 | | |
356 | 10.7k | if (TagDecl *TD = dyn_cast<TagDecl>(D)) |
357 | 299 | if (!TD->isFreeStanding()) |
358 | 42 | continue; |
359 | | |
360 | 10.7k | RangeComparisonResult CompRes = |
361 | 10.7k | RangeCompare(SM, D->getSourceRange(), Range); |
362 | 10.7k | if (CompRes == RangeBefore) |
363 | 7.50k | continue; |
364 | 3.20k | if (CompRes == RangeAfter) |
365 | 1.82k | break; |
366 | | |
367 | 1.38k | assert(CompRes == RangeOverlap); |
368 | 0 | VisitedAtLeastOnce = true; |
369 | | |
370 | 1.38k | if (isa<ObjCContainerDecl>(D)) { |
371 | 503 | FileDI_current = &DIt; |
372 | 503 | FileDE_current = DE; |
373 | 879 | } else { |
374 | 879 | FileDI_current = nullptr; |
375 | 879 | } |
376 | | |
377 | 1.38k | if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true)) |
378 | 13 | return true; // visitation break. |
379 | 1.38k | } |
380 | | |
381 | 9.50k | if (VisitedAtLeastOnce) |
382 | 1.11k | return false; |
383 | | |
384 | | // No Decls overlapped with the range. Move up the lexical context until there |
385 | | // is a context that contains the range or we reach the translation unit |
386 | | // level. |
387 | 8.39k | DeclContext *DC = DIt == Decls.begin() |
388 | 8.39k | ? (*DIt)->getLexicalDeclContext()1.08k |
389 | 8.39k | : (*(DIt - 1))->getLexicalDeclContext()7.30k ; |
390 | | |
391 | 8.39k | while (DC && !DC->isTranslationUnit()) { |
392 | 0 | Decl *D = cast<Decl>(DC); |
393 | 0 | SourceRange CurDeclRange = D->getSourceRange(); |
394 | 0 | if (CurDeclRange.isInvalid()) |
395 | 0 | break; |
396 | | |
397 | 0 | if (RangeCompare(SM, CurDeclRange, Range) == RangeOverlap) { |
398 | 0 | if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true)) |
399 | 0 | return true; // visitation break. |
400 | 0 | } |
401 | | |
402 | 0 | DC = D->getLexicalDeclContext(); |
403 | 0 | } |
404 | | |
405 | 8.39k | return false; |
406 | 8.39k | } |
407 | | |
408 | 9.76k | bool CursorVisitor::visitPreprocessedEntitiesInRegion() { |
409 | 9.76k | if (!AU->getPreprocessor().getPreprocessingRecord()) |
410 | 0 | return false; |
411 | | |
412 | 9.76k | PreprocessingRecord &PPRec = *AU->getPreprocessor().getPreprocessingRecord(); |
413 | 9.76k | SourceManager &SM = AU->getSourceManager(); |
414 | | |
415 | 9.76k | if (RegionOfInterest.isValid()) { |
416 | 9.57k | SourceRange MappedRange = AU->mapRangeToPreamble(RegionOfInterest); |
417 | 9.57k | SourceLocation B = MappedRange.getBegin(); |
418 | 9.57k | SourceLocation E = MappedRange.getEnd(); |
419 | | |
420 | 9.57k | if (AU->isInPreambleFileID(B)) { |
421 | 22 | if (SM.isLoadedSourceLocation(E)) |
422 | 15 | return visitPreprocessedEntitiesInRange(SourceRange(B, E), PPRec, |
423 | 15 | *this); |
424 | | |
425 | | // Beginning of range lies in the preamble but it also extends beyond |
426 | | // it into the main file. Split the range into 2 parts, one covering |
427 | | // the preamble and another covering the main file. This allows subsequent |
428 | | // calls to visitPreprocessedEntitiesInRange to accept a source range that |
429 | | // lies in the same FileID, allowing it to skip preprocessed entities that |
430 | | // do not come from the same FileID. |
431 | 7 | bool breaked = visitPreprocessedEntitiesInRange( |
432 | 7 | SourceRange(B, AU->getEndOfPreambleFileID()), PPRec, *this); |
433 | 7 | if (breaked) |
434 | 0 | return true; |
435 | 7 | return visitPreprocessedEntitiesInRange( |
436 | 7 | SourceRange(AU->getStartOfMainFileID(), E), PPRec, *this); |
437 | 7 | } |
438 | | |
439 | 9.55k | return visitPreprocessedEntitiesInRange(SourceRange(B, E), PPRec, *this); |
440 | 9.57k | } |
441 | | |
442 | 196 | bool OnlyLocalDecls = !AU->isMainFileAST() && AU->getOnlyLocalDecls()177 ; |
443 | | |
444 | 196 | if (OnlyLocalDecls) |
445 | 45 | return visitPreprocessedEntities(PPRec.local_begin(), PPRec.local_end(), |
446 | 45 | PPRec); |
447 | | |
448 | 151 | return visitPreprocessedEntities(PPRec.begin(), PPRec.end(), PPRec); |
449 | 196 | } |
450 | | |
451 | | template <typename InputIterator> |
452 | | bool CursorVisitor::visitPreprocessedEntities(InputIterator First, |
453 | | InputIterator Last, |
454 | | PreprocessingRecord &PPRec, |
455 | 9.77k | FileID FID) { |
456 | 90.8k | for (; First != Last; ++First81.0k ) { |
457 | 81.0k | if (!FID.isInvalid() && !PPRec.isEntityInFileID(First, FID)9.42k ) |
458 | 3.46k | continue; |
459 | | |
460 | 77.5k | PreprocessedEntity *PPE = *First; |
461 | 77.5k | if (!PPE) |
462 | 0 | continue; |
463 | | |
464 | 77.5k | if (MacroExpansion *ME = dyn_cast<MacroExpansion>(PPE)) { |
465 | 5.92k | if (Visit(MakeMacroExpansionCursor(ME, TU))) |
466 | 1 | return true; |
467 | | |
468 | 5.92k | continue; |
469 | 5.92k | } |
470 | | |
471 | 71.6k | if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(PPE)) { |
472 | 71.3k | if (Visit(MakeMacroDefinitionCursor(MD, TU))) |
473 | 0 | return true; |
474 | | |
475 | 71.3k | continue; |
476 | 71.3k | } |
477 | | |
478 | 311 | if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) { |
479 | 311 | if (Visit(MakeInclusionDirectiveCursor(ID, TU))) |
480 | 0 | return true; |
481 | | |
482 | 311 | continue; |
483 | 311 | } |
484 | 311 | } |
485 | | |
486 | 9.77k | return false; |
487 | 9.77k | } |
488 | | |
489 | | /// Visit the children of the given cursor. |
490 | | /// |
491 | | /// \returns true if the visitation should be aborted, false if it |
492 | | /// should continue. |
493 | 76.1k | bool CursorVisitor::VisitChildren(CXCursor Cursor) { |
494 | 76.1k | if (clang_isReference(Cursor.kind) && |
495 | 76.1k | Cursor.kind != CXCursor_CXXBaseSpecifier1.98k ) { |
496 | | // By definition, references have no children. |
497 | 1.86k | return false; |
498 | 1.86k | } |
499 | | |
500 | | // Set the Parent field to Cursor, then back to its old value once we're |
501 | | // done. |
502 | 74.2k | SetParentRAII SetParent(Parent, StmtParent, Cursor); |
503 | | |
504 | 74.2k | if (clang_isDeclaration(Cursor.kind)) { |
505 | 7.20k | Decl *D = const_cast<Decl *>(getCursorDecl(Cursor)); |
506 | 7.20k | if (!D) |
507 | 0 | return false; |
508 | | |
509 | 7.20k | return VisitAttributes(D) || Visit(D); |
510 | 7.20k | } |
511 | | |
512 | 67.0k | if (clang_isStatement(Cursor.kind)) { |
513 | 764 | if (const Stmt *S = getCursorStmt(Cursor)) |
514 | 764 | return Visit(S); |
515 | | |
516 | 0 | return false; |
517 | 764 | } |
518 | | |
519 | 66.3k | if (clang_isExpression(Cursor.kind)) { |
520 | 383 | if (const Expr *E = getCursorExpr(Cursor)) |
521 | 383 | return Visit(E); |
522 | | |
523 | 0 | return false; |
524 | 383 | } |
525 | | |
526 | 65.9k | if (clang_isTranslationUnit(Cursor.kind)) { |
527 | 198 | CXTranslationUnit TU = getCursorTU(Cursor); |
528 | 198 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
529 | | |
530 | 198 | int VisitOrder[2] = {VisitPreprocessorLast, !VisitPreprocessorLast}; |
531 | 590 | for (unsigned I = 0; I != 2; ++I392 ) { |
532 | 396 | if (VisitOrder[I]) { |
533 | 198 | if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls()179 && |
534 | 198 | RegionOfInterest.isInvalid()47 ) { |
535 | 47 | for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(), |
536 | 47 | TLEnd = CXXUnit->top_level_end(); |
537 | 232 | TL != TLEnd; ++TL185 ) { |
538 | 185 | const Optional<bool> V = handleDeclForVisitation(*TL); |
539 | 185 | if (!V.hasValue()) |
540 | 185 | continue; |
541 | 0 | return V.getValue(); |
542 | 185 | } |
543 | 151 | } else if (VisitDeclContext( |
544 | 151 | CXXUnit->getASTContext().getTranslationUnitDecl())) |
545 | 4 | return true; |
546 | 194 | continue; |
547 | 198 | } |
548 | | |
549 | | // Walk the preprocessing record. |
550 | 198 | if (CXXUnit->getPreprocessor().getPreprocessingRecord()) |
551 | 196 | visitPreprocessedEntitiesInRegion(); |
552 | 198 | } |
553 | | |
554 | 194 | return false; |
555 | 198 | } |
556 | | |
557 | 65.7k | if (Cursor.kind == CXCursor_CXXBaseSpecifier) { |
558 | 121 | if (const CXXBaseSpecifier *Base = getCursorCXXBaseSpecifier(Cursor)) { |
559 | 121 | if (TypeSourceInfo *BaseTSInfo = Base->getTypeSourceInfo()) { |
560 | 121 | return Visit(BaseTSInfo->getTypeLoc()); |
561 | 121 | } |
562 | 121 | } |
563 | 121 | } |
564 | | |
565 | 65.6k | if (Cursor.kind == CXCursor_IBOutletCollectionAttr) { |
566 | 3 | const IBOutletCollectionAttr *A = |
567 | 3 | cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(Cursor)); |
568 | 3 | if (const ObjCObjectType *ObjT = A->getInterface()->getAs<ObjCObjectType>()) |
569 | 2 | return Visit(cxcursor::MakeCursorObjCClassRef( |
570 | 2 | ObjT->getInterface(), |
571 | 2 | A->getInterfaceLoc()->getTypeLoc().getBeginLoc(), TU)); |
572 | 3 | } |
573 | | |
574 | | // If pointing inside a macro definition, check if the token is an identifier |
575 | | // that was ever defined as a macro. In such a case, create a "pseudo" macro |
576 | | // expansion cursor for that token. |
577 | 65.6k | SourceLocation BeginLoc = RegionOfInterest.getBegin(); |
578 | 65.6k | if (Cursor.kind == CXCursor_MacroDefinition && |
579 | 65.6k | BeginLoc == RegionOfInterest.getEnd()64.9k ) { |
580 | 64.8k | SourceLocation Loc = AU->mapLocationToPreamble(BeginLoc); |
581 | 64.8k | const MacroInfo *MI = |
582 | 64.8k | getMacroInfo(cxcursor::getCursorMacroDefinition(Cursor), TU); |
583 | 64.8k | if (MacroDefinitionRecord *MacroDef = |
584 | 64.8k | checkForMacroInMacroDefinition(MI, Loc, TU)) |
585 | 12 | return Visit(cxcursor::MakeMacroExpansionCursor(MacroDef, BeginLoc, TU)); |
586 | 64.8k | } |
587 | | |
588 | | // Nothing to visit at the moment. |
589 | 65.5k | return false; |
590 | 65.6k | } |
591 | | |
592 | 8 | bool CursorVisitor::VisitBlockDecl(BlockDecl *B) { |
593 | 8 | if (TypeSourceInfo *TSInfo = B->getSignatureAsWritten()) |
594 | 8 | if (Visit(TSInfo->getTypeLoc())) |
595 | 0 | return true; |
596 | | |
597 | 8 | if (Stmt *Body = B->getBody()) |
598 | 8 | return Visit(MakeCXCursor(Body, StmtParent, TU, RegionOfInterest)); |
599 | | |
600 | 0 | return false; |
601 | 8 | } |
602 | | |
603 | 7.59k | Optional<bool> CursorVisitor::shouldVisitCursor(CXCursor Cursor) { |
604 | 7.59k | if (RegionOfInterest.isValid()) { |
605 | 2.40k | SourceRange Range = getFullCursorExtent(Cursor, AU->getSourceManager()); |
606 | 2.40k | if (Range.isInvalid()) |
607 | 8 | return None; |
608 | | |
609 | 2.39k | switch (CompareRegionOfInterest(Range)) { |
610 | 1.30k | case RangeBefore: |
611 | | // This declaration comes before the region of interest; skip it. |
612 | 1.30k | return None; |
613 | | |
614 | 298 | case RangeAfter: |
615 | | // This declaration comes after the region of interest; we're done. |
616 | 298 | return false; |
617 | | |
618 | 798 | case RangeOverlap: |
619 | | // This declaration overlaps the region of interest; visit it. |
620 | 798 | break; |
621 | 2.39k | } |
622 | 2.39k | } |
623 | 5.98k | return true; |
624 | 7.59k | } |
625 | | |
626 | 1.71k | bool CursorVisitor::VisitDeclContext(DeclContext *DC) { |
627 | 1.71k | DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end(); |
628 | | |
629 | | // FIXME: Eventually remove. This part of a hack to support proper |
630 | | // iteration over all Decls contained lexically within an ObjC container. |
631 | 1.71k | SaveAndRestore<DeclContext::decl_iterator *> DI_saved(DI_current, &I); |
632 | 1.71k | SaveAndRestore<DeclContext::decl_iterator> DE_saved(DE_current, E); |
633 | | |
634 | 8.85k | for (; I != E; ++I7.14k ) { |
635 | 7.44k | Decl *D = *I; |
636 | 7.44k | if (D->getLexicalDeclContext() != DC) |
637 | 0 | continue; |
638 | | // Filter out synthesized property accessor redeclarations. |
639 | 7.44k | if (isa<ObjCImplDecl>(DC)) |
640 | 173 | if (auto *OMD = dyn_cast<ObjCMethodDecl>(D)) |
641 | 110 | if (OMD->isSynthesizedAccessorStub()) |
642 | 41 | continue; |
643 | 7.40k | const Optional<bool> V = handleDeclForVisitation(D); |
644 | 7.40k | if (!V.hasValue()) |
645 | 7.09k | continue; |
646 | 305 | return V.getValue(); |
647 | 7.40k | } |
648 | 1.41k | return false; |
649 | 1.71k | } |
650 | | |
651 | 7.58k | Optional<bool> CursorVisitor::handleDeclForVisitation(const Decl *D) { |
652 | 7.58k | CXCursor Cursor = MakeCXCursor(D, TU, RegionOfInterest); |
653 | | |
654 | | // Ignore synthesized ivars here, otherwise if we have something like: |
655 | | // @synthesize prop = _prop; |
656 | | // and '_prop' is not declared, we will encounter a '_prop' ivar before |
657 | | // encountering the 'prop' synthesize declaration and we will think that |
658 | | // we passed the region-of-interest. |
659 | 7.58k | if (auto *ivarD = dyn_cast<ObjCIvarDecl>(D)) { |
660 | 177 | if (ivarD->getSynthesize()) |
661 | 18 | return None; |
662 | 177 | } |
663 | | |
664 | | // FIXME: ObjCClassRef/ObjCProtocolRef for forward class/protocol |
665 | | // declarations is a mismatch with the compiler semantics. |
666 | 7.57k | if (Cursor.kind == CXCursor_ObjCInterfaceDecl) { |
667 | 159 | auto *ID = cast<ObjCInterfaceDecl>(D); |
668 | 159 | if (!ID->isThisDeclarationADefinition()) |
669 | 42 | Cursor = MakeCursorObjCClassRef(ID, ID->getLocation(), TU); |
670 | | |
671 | 7.41k | } else if (Cursor.kind == CXCursor_ObjCProtocolDecl) { |
672 | 16 | auto *PD = cast<ObjCProtocolDecl>(D); |
673 | 16 | if (!PD->isThisDeclarationADefinition()) |
674 | 0 | Cursor = MakeCursorObjCProtocolRef(PD, PD->getLocation(), TU); |
675 | 16 | } |
676 | | |
677 | 7.57k | const Optional<bool> V = shouldVisitCursor(Cursor); |
678 | 7.57k | if (!V.hasValue()) |
679 | 1.29k | return None; |
680 | 6.27k | if (!V.getValue()) |
681 | 298 | return false; |
682 | 5.97k | if (Visit(Cursor, true)) |
683 | 7 | return true; |
684 | 5.96k | return None; |
685 | 5.97k | } |
686 | | |
687 | 0 | bool CursorVisitor::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
688 | 0 | llvm_unreachable("Translation units are visited directly by Visit()"); |
689 | 0 | } |
690 | | |
691 | 13 | bool CursorVisitor::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
692 | 13 | if (VisitTemplateParameters(D->getTemplateParameters())) |
693 | 0 | return true; |
694 | | |
695 | 13 | return Visit(MakeCXCursor(D->getTemplatedDecl(), TU, RegionOfInterest)); |
696 | 13 | } |
697 | | |
698 | 46 | bool CursorVisitor::VisitTypeAliasDecl(TypeAliasDecl *D) { |
699 | 46 | if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo()) |
700 | 46 | return Visit(TSInfo->getTypeLoc()); |
701 | | |
702 | 0 | return false; |
703 | 46 | } |
704 | | |
705 | 300 | bool CursorVisitor::VisitTypedefDecl(TypedefDecl *D) { |
706 | 300 | if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo()) |
707 | 300 | return Visit(TSInfo->getTypeLoc()); |
708 | | |
709 | 0 | return false; |
710 | 300 | } |
711 | | |
712 | 808 | bool CursorVisitor::VisitTagDecl(TagDecl *D) { return VisitDeclContext(D); } |
713 | | |
714 | | bool CursorVisitor::VisitClassTemplateSpecializationDecl( |
715 | 21 | ClassTemplateSpecializationDecl *D) { |
716 | 21 | bool ShouldVisitBody = false; |
717 | 21 | switch (D->getSpecializationKind()) { |
718 | 0 | case TSK_Undeclared: |
719 | 0 | case TSK_ImplicitInstantiation: |
720 | | // Nothing to visit |
721 | 0 | return false; |
722 | | |
723 | 2 | case TSK_ExplicitInstantiationDeclaration: |
724 | 10 | case TSK_ExplicitInstantiationDefinition: |
725 | 10 | break; |
726 | | |
727 | 11 | case TSK_ExplicitSpecialization: |
728 | 11 | ShouldVisitBody = true; |
729 | 11 | break; |
730 | 21 | } |
731 | | |
732 | | // Visit the template arguments used in the specialization. |
733 | 21 | if (TypeSourceInfo *SpecType = D->getTypeAsWritten()) { |
734 | 21 | TypeLoc TL = SpecType->getTypeLoc(); |
735 | 21 | if (TemplateSpecializationTypeLoc TSTLoc = |
736 | 21 | TL.getAs<TemplateSpecializationTypeLoc>()) { |
737 | 52 | for (unsigned I = 0, N = TSTLoc.getNumArgs(); I != N; ++I31 ) |
738 | 31 | if (VisitTemplateArgumentLoc(TSTLoc.getArgLoc(I))) |
739 | 0 | return true; |
740 | 21 | } |
741 | 21 | } |
742 | | |
743 | 21 | return ShouldVisitBody && VisitCXXRecordDecl(D)11 ; |
744 | 21 | } |
745 | | |
746 | | bool CursorVisitor::VisitClassTemplatePartialSpecializationDecl( |
747 | 13 | ClassTemplatePartialSpecializationDecl *D) { |
748 | | // FIXME: Visit the "outer" template parameter lists on the TagDecl |
749 | | // before visiting these template parameters. |
750 | 13 | if (VisitTemplateParameters(D->getTemplateParameters())) |
751 | 0 | return true; |
752 | | |
753 | | // Visit the partial specialization arguments. |
754 | 13 | const ASTTemplateArgumentListInfo *Info = D->getTemplateArgsAsWritten(); |
755 | 13 | const TemplateArgumentLoc *TemplateArgs = Info->getTemplateArgs(); |
756 | 34 | for (unsigned I = 0, N = Info->NumTemplateArgs; I != N; ++I21 ) |
757 | 21 | if (VisitTemplateArgumentLoc(TemplateArgs[I])) |
758 | 0 | return true; |
759 | | |
760 | 13 | return VisitCXXRecordDecl(D); |
761 | 13 | } |
762 | | |
763 | 311 | bool CursorVisitor::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
764 | 311 | if (const auto *TC = D->getTypeConstraint()) |
765 | 0 | if (Visit(MakeCXCursor(TC->getImmediatelyDeclaredConstraint(), StmtParent, |
766 | 0 | TU, RegionOfInterest))) |
767 | 0 | return true; |
768 | | |
769 | | // Visit the default argument. |
770 | 311 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()10 ) |
771 | 10 | if (TypeSourceInfo *DefArg = D->getDefaultArgumentInfo()) |
772 | 10 | if (Visit(DefArg->getTypeLoc())) |
773 | 0 | return true; |
774 | | |
775 | 311 | return false; |
776 | 311 | } |
777 | | |
778 | 279 | bool CursorVisitor::VisitEnumConstantDecl(EnumConstantDecl *D) { |
779 | 279 | if (Expr *Init = D->getInitExpr()) |
780 | 59 | return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest)); |
781 | 220 | return false; |
782 | 279 | } |
783 | | |
784 | 2.07k | bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
785 | 2.07k | unsigned NumParamList = DD->getNumTemplateParameterLists(); |
786 | 2.07k | for (unsigned i = 0; i < NumParamList; i++1 ) { |
787 | 1 | TemplateParameterList *Params = DD->getTemplateParameterList(i); |
788 | 1 | if (VisitTemplateParameters(Params)) |
789 | 0 | return true; |
790 | 1 | } |
791 | | |
792 | 2.07k | if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo()) |
793 | 2.01k | if (Visit(TSInfo->getTypeLoc())) |
794 | 0 | return true; |
795 | | |
796 | | // Visit the nested-name-specifier, if present. |
797 | 2.07k | if (NestedNameSpecifierLoc QualifierLoc = DD->getQualifierLoc()) |
798 | 1 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
799 | 0 | return true; |
800 | | |
801 | 2.07k | return false; |
802 | 2.07k | } |
803 | | |
804 | 1.86k | static bool HasTrailingReturnType(FunctionDecl *ND) { |
805 | 1.86k | const QualType Ty = ND->getType(); |
806 | 1.86k | if (const FunctionType *AFT = Ty->getAs<FunctionType>()) { |
807 | 1.86k | if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(AFT)) |
808 | 1.75k | return FT->hasTrailingReturn(); |
809 | 1.86k | } |
810 | | |
811 | 107 | return false; |
812 | 1.86k | } |
813 | | |
814 | | /// Compare two base or member initializers based on their source order. |
815 | | static int CompareCXXCtorInitializers(CXXCtorInitializer *const *X, |
816 | 10 | CXXCtorInitializer *const *Y) { |
817 | 10 | return (*X)->getSourceOrder() - (*Y)->getSourceOrder(); |
818 | 10 | } |
819 | | |
820 | 1.86k | bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) { |
821 | 1.86k | unsigned NumParamList = ND->getNumTemplateParameterLists(); |
822 | 1.88k | for (unsigned i = 0; i < NumParamList; i++20 ) { |
823 | 20 | TemplateParameterList *Params = ND->getTemplateParameterList(i); |
824 | 20 | if (VisitTemplateParameters(Params)) |
825 | 0 | return true; |
826 | 20 | } |
827 | | |
828 | 1.86k | if (TypeSourceInfo *TSInfo = ND->getTypeSourceInfo()) { |
829 | | // Visit the function declaration's syntactic components in the order |
830 | | // written. This requires a bit of work. |
831 | 1.86k | TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens(); |
832 | 1.86k | FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>(); |
833 | 1.86k | const bool HasTrailingRT = HasTrailingReturnType(ND); |
834 | | |
835 | | // If we have a function declared directly (without the use of a typedef), |
836 | | // visit just the return type. Otherwise, just visit the function's type |
837 | | // now. |
838 | 1.86k | if ((FTL && !isa<CXXConversionDecl>(ND) && !HasTrailingRT1.85k && |
839 | 1.86k | Visit(FTL.getReturnLoc())1.85k ) || |
840 | 1.86k | (!FTL && Visit(TL)0 )) |
841 | 0 | return true; |
842 | | |
843 | | // Visit the nested-name-specifier, if present. |
844 | 1.86k | if (NestedNameSpecifierLoc QualifierLoc = ND->getQualifierLoc()) |
845 | 44 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
846 | 0 | return true; |
847 | | |
848 | | // Visit the declaration name. |
849 | 1.86k | if (!isa<CXXDestructorDecl>(ND)) |
850 | 1.83k | if (VisitDeclarationNameInfo(ND->getNameInfo())) |
851 | 0 | return true; |
852 | | |
853 | | // FIXME: Visit explicitly-specified template arguments! |
854 | | |
855 | | // Visit the function parameters, if we have a function type. |
856 | 1.86k | if (FTL && VisitFunctionTypeLoc(FTL, true)) |
857 | 0 | return true; |
858 | | |
859 | | // Visit the function's trailing return type. |
860 | 1.86k | if (FTL && HasTrailingRT && Visit(FTL.getReturnLoc())3 ) |
861 | 0 | return true; |
862 | | |
863 | | // FIXME: Attributes? |
864 | 1.86k | } |
865 | | |
866 | 1.86k | if (ND->doesThisDeclarationHaveABody() && !ND->isLateTemplateParsed()818 ) { |
867 | 818 | if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ND)) { |
868 | | // Find the initializers that were written in the source. |
869 | 42 | SmallVector<CXXCtorInitializer *, 4> WrittenInits; |
870 | 42 | for (auto *I : Constructor->inits()) { |
871 | 41 | if (!I->isWritten()) |
872 | 5 | continue; |
873 | | |
874 | 36 | WrittenInits.push_back(I); |
875 | 36 | } |
876 | | |
877 | | // Sort the initializers in source order |
878 | 42 | llvm::array_pod_sort(WrittenInits.begin(), WrittenInits.end(), |
879 | 42 | &CompareCXXCtorInitializers); |
880 | | |
881 | | // Visit the initializers in source order |
882 | 78 | for (unsigned I = 0, N = WrittenInits.size(); I != N; ++I36 ) { |
883 | 36 | CXXCtorInitializer *Init = WrittenInits[I]; |
884 | 36 | if (Init->isAnyMemberInitializer()) { |
885 | 22 | if (Visit(MakeCursorMemberRef(Init->getAnyMember(), |
886 | 22 | Init->getMemberLocation(), TU))) |
887 | 0 | return true; |
888 | 22 | } else if (TypeSourceInfo *14 TInfo14 = Init->getTypeSourceInfo()) { |
889 | 14 | if (Visit(TInfo->getTypeLoc())) |
890 | 0 | return true; |
891 | 14 | } |
892 | | |
893 | | // Visit the initializer value. |
894 | 36 | if (Expr *Initializer = Init->getInit()) |
895 | 36 | if (Visit(MakeCXCursor(Initializer, ND, TU, RegionOfInterest))) |
896 | 0 | return true; |
897 | 36 | } |
898 | 42 | } |
899 | | |
900 | 818 | if (Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest))) |
901 | 2 | return true; |
902 | 818 | } |
903 | | |
904 | 1.85k | return false; |
905 | 1.86k | } |
906 | | |
907 | 467 | bool CursorVisitor::VisitFieldDecl(FieldDecl *D) { |
908 | 467 | if (VisitDeclaratorDecl(D)) |
909 | 0 | return true; |
910 | | |
911 | 467 | if (Expr *BitWidth = D->getBitWidth()) |
912 | 20 | return Visit(MakeCXCursor(BitWidth, StmtParent, TU, RegionOfInterest)); |
913 | | |
914 | 447 | if (Expr *Init = D->getInClassInitializer()) |
915 | 5 | return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest)); |
916 | | |
917 | 442 | return false; |
918 | 447 | } |
919 | | |
920 | 1.57k | bool CursorVisitor::VisitVarDecl(VarDecl *D) { |
921 | 1.57k | if (VisitDeclaratorDecl(D)) |
922 | 0 | return true; |
923 | | |
924 | 1.57k | if (Expr *Init = D->getInit()) |
925 | 262 | return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest)); |
926 | | |
927 | 1.30k | return false; |
928 | 1.57k | } |
929 | | |
930 | 37 | bool CursorVisitor::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
931 | 37 | if (VisitDeclaratorDecl(D)) |
932 | 0 | return true; |
933 | | |
934 | 37 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()2 ) |
935 | 2 | if (Expr *DefArg = D->getDefaultArgument()) |
936 | 2 | return Visit(MakeCXCursor(DefArg, StmtParent, TU, RegionOfInterest)); |
937 | | |
938 | 35 | return false; |
939 | 37 | } |
940 | | |
941 | 110 | bool CursorVisitor::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
942 | | // FIXME: Visit the "outer" template parameter lists on the FunctionDecl |
943 | | // before visiting these template parameters. |
944 | 110 | if (VisitTemplateParameters(D->getTemplateParameters())) |
945 | 0 | return true; |
946 | | |
947 | 110 | auto *FD = D->getTemplatedDecl(); |
948 | 110 | return VisitAttributes(FD) || VisitFunctionDecl(FD); |
949 | 110 | } |
950 | | |
951 | 111 | bool CursorVisitor::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
952 | | // FIXME: Visit the "outer" template parameter lists on the TagDecl |
953 | | // before visiting these template parameters. |
954 | 111 | if (VisitTemplateParameters(D->getTemplateParameters())) |
955 | 0 | return true; |
956 | | |
957 | 111 | auto *CD = D->getTemplatedDecl(); |
958 | 111 | return VisitAttributes(CD) || VisitCXXRecordDecl(CD); |
959 | 111 | } |
960 | | |
961 | 23 | bool CursorVisitor::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
962 | 23 | if (VisitTemplateParameters(D->getTemplateParameters())) |
963 | 0 | return true; |
964 | | |
965 | 23 | if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()2 && |
966 | 23 | VisitTemplateArgumentLoc(D->getDefaultArgument())2 ) |
967 | 0 | return true; |
968 | | |
969 | 23 | return false; |
970 | 23 | } |
971 | | |
972 | 11 | bool CursorVisitor::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
973 | | // Visit the bound, if it's explicit. |
974 | 11 | if (D->hasExplicitBound()) { |
975 | 8 | if (auto TInfo = D->getTypeSourceInfo()) { |
976 | 8 | if (Visit(TInfo->getTypeLoc())) |
977 | 0 | return true; |
978 | 8 | } |
979 | 8 | } |
980 | | |
981 | 11 | return false; |
982 | 11 | } |
983 | | |
984 | 428 | bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) { |
985 | 428 | if (TypeSourceInfo *TSInfo = ND->getReturnTypeSourceInfo()) |
986 | 266 | if (Visit(TSInfo->getTypeLoc())) |
987 | 0 | return true; |
988 | | |
989 | 428 | for (const auto *P : ND->parameters()) { |
990 | 171 | if (Visit(MakeCXCursor(P, TU, RegionOfInterest))) |
991 | 0 | return true; |
992 | 171 | } |
993 | | |
994 | 428 | return ND->isThisDeclarationADefinition() && |
995 | 428 | Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest))65 ; |
996 | 428 | } |
997 | | |
998 | | template <typename DeclIt> |
999 | | static void addRangedDeclsInContainer(DeclIt *DI_current, DeclIt DE_current, |
1000 | | SourceManager &SM, SourceLocation EndLoc, |
1001 | 555 | SmallVectorImpl<Decl *> &Decls) { |
1002 | 555 | DeclIt next = *DI_current; |
1003 | 568 | while (++next != DE_current) { |
1004 | 437 | Decl *D_next = *next; |
1005 | 437 | if (!D_next) |
1006 | 0 | break; |
1007 | 437 | SourceLocation L = D_next->getBeginLoc(); |
1008 | 437 | if (!L.isValid()) |
1009 | 0 | break; |
1010 | 437 | if (SM.isBeforeInTranslationUnit(L, EndLoc)) { |
1011 | 13 | *DI_current = next; |
1012 | 13 | Decls.push_back(D_next); |
1013 | 13 | continue; |
1014 | 13 | } |
1015 | 424 | break; |
1016 | 437 | } |
1017 | 555 | } CIndex.cpp:void addRangedDeclsInContainer<clang::DeclContext::decl_iterator>(clang::DeclContext::decl_iterator*, clang::DeclContext::decl_iterator, clang::SourceManager&, clang::SourceLocation, llvm::SmallVectorImpl<clang::Decl*>&) Line | Count | Source | 1001 | 90 | SmallVectorImpl<Decl *> &Decls) { | 1002 | 90 | DeclIt next = *DI_current; | 1003 | 90 | while (++next != DE_current) { | 1004 | 75 | Decl *D_next = *next; | 1005 | 75 | if (!D_next) | 1006 | 0 | break; | 1007 | 75 | SourceLocation L = D_next->getBeginLoc(); | 1008 | 75 | if (!L.isValid()) | 1009 | 0 | break; | 1010 | 75 | if (SM.isBeforeInTranslationUnit(L, EndLoc)) { | 1011 | 0 | *DI_current = next; | 1012 | 0 | Decls.push_back(D_next); | 1013 | 0 | continue; | 1014 | 0 | } | 1015 | 75 | break; | 1016 | 75 | } | 1017 | 90 | } |
CIndex.cpp:void addRangedDeclsInContainer<clang::Decl**>(clang::Decl***, clang::Decl**, clang::SourceManager&, clang::SourceLocation, llvm::SmallVectorImpl<clang::Decl*>&) Line | Count | Source | 1001 | 465 | SmallVectorImpl<Decl *> &Decls) { | 1002 | 465 | DeclIt next = *DI_current; | 1003 | 478 | while (++next != DE_current) { | 1004 | 362 | Decl *D_next = *next; | 1005 | 362 | if (!D_next) | 1006 | 0 | break; | 1007 | 362 | SourceLocation L = D_next->getBeginLoc(); | 1008 | 362 | if (!L.isValid()) | 1009 | 0 | break; | 1010 | 362 | if (SM.isBeforeInTranslationUnit(L, EndLoc)) { | 1011 | 13 | *DI_current = next; | 1012 | 13 | Decls.push_back(D_next); | 1013 | 13 | continue; | 1014 | 13 | } | 1015 | 349 | break; | 1016 | 362 | } | 1017 | 465 | } |
|
1018 | | |
1019 | 649 | bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
1020 | | // FIXME: Eventually convert back to just 'VisitDeclContext()'. Essentially |
1021 | | // an @implementation can lexically contain Decls that are not properly |
1022 | | // nested in the AST. When we identify such cases, we need to retrofit |
1023 | | // this nesting here. |
1024 | 649 | if (!DI_current && !FileDI_current559 ) |
1025 | 94 | return VisitDeclContext(D); |
1026 | | |
1027 | | // Scan the Decls that immediately come after the container |
1028 | | // in the current DeclContext. If any fall within the |
1029 | | // container's lexical region, stash them into a vector |
1030 | | // for later processing. |
1031 | 555 | SmallVector<Decl *, 24> DeclsInContainer; |
1032 | 555 | SourceLocation EndLoc = D->getSourceRange().getEnd(); |
1033 | 555 | SourceManager &SM = AU->getSourceManager(); |
1034 | 555 | if (EndLoc.isValid()) { |
1035 | 555 | if (DI_current) { |
1036 | 90 | addRangedDeclsInContainer(DI_current, DE_current, SM, EndLoc, |
1037 | 90 | DeclsInContainer); |
1038 | 465 | } else { |
1039 | 465 | addRangedDeclsInContainer(FileDI_current, FileDE_current, SM, EndLoc, |
1040 | 465 | DeclsInContainer); |
1041 | 465 | } |
1042 | 555 | } |
1043 | | |
1044 | | // The common case. |
1045 | 555 | if (DeclsInContainer.empty()) |
1046 | 548 | return VisitDeclContext(D); |
1047 | | |
1048 | | // Get all the Decls in the DeclContext, and sort them with the |
1049 | | // additional ones we've collected. Then visit them. |
1050 | 9 | for (auto *SubDecl : D->decls())7 { |
1051 | 9 | if (!SubDecl || SubDecl->getLexicalDeclContext() != D || |
1052 | 9 | SubDecl->getBeginLoc().isInvalid()) |
1053 | 0 | continue; |
1054 | 9 | DeclsInContainer.push_back(SubDecl); |
1055 | 9 | } |
1056 | | |
1057 | | // Now sort the Decls so that they appear in lexical order. |
1058 | 15 | llvm::sort(DeclsInContainer, [&SM](Decl *A, Decl *B) { |
1059 | 15 | SourceLocation L_A = A->getBeginLoc(); |
1060 | 15 | SourceLocation L_B = B->getBeginLoc(); |
1061 | 15 | return L_A != L_B |
1062 | 15 | ? SM.isBeforeInTranslationUnit(L_A, L_B) |
1063 | 15 | : SM.isBeforeInTranslationUnit(A->getEndLoc(), B->getEndLoc())0 ; |
1064 | 15 | }); |
1065 | | |
1066 | | // Now visit the decls. |
1067 | 7 | for (SmallVectorImpl<Decl *>::iterator I = DeclsInContainer.begin(), |
1068 | 7 | E = DeclsInContainer.end(); |
1069 | 29 | I != E; ++I22 ) { |
1070 | 22 | CXCursor Cursor = MakeCXCursor(*I, TU, RegionOfInterest); |
1071 | 22 | const Optional<bool> &V = shouldVisitCursor(Cursor); |
1072 | 22 | if (!V.hasValue()) |
1073 | 11 | continue; |
1074 | 11 | if (!V.getValue()) |
1075 | 0 | return false; |
1076 | 11 | if (Visit(Cursor, true)) |
1077 | 0 | return true; |
1078 | 11 | } |
1079 | 7 | return false; |
1080 | 7 | } |
1081 | | |
1082 | 126 | bool CursorVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) { |
1083 | 126 | if (Visit(MakeCursorObjCClassRef(ND->getClassInterface(), ND->getLocation(), |
1084 | 126 | TU))) |
1085 | 0 | return true; |
1086 | | |
1087 | 126 | if (VisitObjCTypeParamList(ND->getTypeParamList())) |
1088 | 0 | return true; |
1089 | | |
1090 | 126 | ObjCCategoryDecl::protocol_loc_iterator PL = ND->protocol_loc_begin(); |
1091 | 126 | for (ObjCCategoryDecl::protocol_iterator I = ND->protocol_begin(), |
1092 | 126 | E = ND->protocol_end(); |
1093 | 128 | I != E; ++I, ++PL2 ) |
1094 | 2 | if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) |
1095 | 0 | return true; |
1096 | | |
1097 | 126 | return VisitObjCContainerDecl(ND); |
1098 | 126 | } |
1099 | | |
1100 | 106 | bool CursorVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) { |
1101 | 106 | if (!PID->isThisDeclarationADefinition()) |
1102 | 0 | return Visit(MakeCursorObjCProtocolRef(PID, PID->getLocation(), TU)); |
1103 | | |
1104 | 106 | ObjCProtocolDecl::protocol_loc_iterator PL = PID->protocol_loc_begin(); |
1105 | 106 | for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(), |
1106 | 106 | E = PID->protocol_end(); |
1107 | 154 | I != E; ++I, ++PL48 ) |
1108 | 48 | if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) |
1109 | 0 | return true; |
1110 | | |
1111 | 106 | return VisitObjCContainerDecl(PID); |
1112 | 106 | } |
1113 | | |
1114 | 62 | bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) { |
1115 | 62 | if (PD->getTypeSourceInfo() && Visit(PD->getTypeSourceInfo()->getTypeLoc())) |
1116 | 0 | return true; |
1117 | | |
1118 | | // FIXME: This implements a workaround with @property declarations also being |
1119 | | // installed in the DeclContext for the @interface. Eventually this code |
1120 | | // should be removed. |
1121 | 62 | ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(PD->getDeclContext()); |
1122 | 62 | if (!CDecl || !CDecl->IsClassExtension()16 ) |
1123 | 49 | return false; |
1124 | | |
1125 | 13 | ObjCInterfaceDecl *ID = CDecl->getClassInterface(); |
1126 | 13 | if (!ID) |
1127 | 0 | return false; |
1128 | | |
1129 | 13 | IdentifierInfo *PropertyId = PD->getIdentifier(); |
1130 | 13 | ObjCPropertyDecl *prevDecl = ObjCPropertyDecl::findPropertyDecl( |
1131 | 13 | cast<DeclContext>(ID), PropertyId, PD->getQueryKind()); |
1132 | | |
1133 | 13 | if (!prevDecl) |
1134 | 0 | return false; |
1135 | | |
1136 | | // Visit synthesized methods since they will be skipped when visiting |
1137 | | // the @interface. |
1138 | 13 | if (ObjCMethodDecl *MD = prevDecl->getGetterMethodDecl()) |
1139 | 13 | if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl) |
1140 | 10 | if (Visit(MakeCXCursor(MD, TU, RegionOfInterest))) |
1141 | 0 | return true; |
1142 | | |
1143 | 13 | if (ObjCMethodDecl *MD = prevDecl->getSetterMethodDecl()) |
1144 | 13 | if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl) |
1145 | 12 | if (Visit(MakeCXCursor(MD, TU, RegionOfInterest))) |
1146 | 0 | return true; |
1147 | | |
1148 | 13 | return false; |
1149 | 13 | } |
1150 | | |
1151 | 483 | bool CursorVisitor::VisitObjCTypeParamList(ObjCTypeParamList *typeParamList) { |
1152 | 483 | if (!typeParamList) |
1153 | 475 | return false; |
1154 | | |
1155 | 15 | for (auto *typeParam : *typeParamList)8 { |
1156 | | // Visit the type parameter. |
1157 | 15 | if (Visit(MakeCXCursor(typeParam, TU, RegionOfInterest))) |
1158 | 0 | return true; |
1159 | 15 | } |
1160 | | |
1161 | 8 | return false; |
1162 | 8 | } |
1163 | | |
1164 | 387 | bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
1165 | 387 | if (!D->isThisDeclarationADefinition()) { |
1166 | | // Forward declaration is treated like a reference. |
1167 | 30 | return Visit(MakeCursorObjCClassRef(D, D->getLocation(), TU)); |
1168 | 30 | } |
1169 | | |
1170 | | // Objective-C type parameters. |
1171 | 357 | if (VisitObjCTypeParamList(D->getTypeParamListAsWritten())) |
1172 | 0 | return true; |
1173 | | |
1174 | | // Issue callbacks for super class. |
1175 | 357 | if (D->getSuperClass() && Visit(MakeCursorObjCSuperClassRef( |
1176 | 134 | D->getSuperClass(), D->getSuperClassLoc(), TU))) |
1177 | 0 | return true; |
1178 | | |
1179 | 357 | if (TypeSourceInfo *SuperClassTInfo = D->getSuperClassTInfo()) |
1180 | 134 | if (Visit(SuperClassTInfo->getTypeLoc())) |
1181 | 6 | return true; |
1182 | | |
1183 | 351 | ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin(); |
1184 | 351 | for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(), |
1185 | 351 | E = D->protocol_end(); |
1186 | 437 | I != E; ++I, ++PL86 ) |
1187 | 86 | if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU))) |
1188 | 0 | return true; |
1189 | | |
1190 | 351 | return VisitObjCContainerDecl(D); |
1191 | 351 | } |
1192 | | |
1193 | 66 | bool CursorVisitor::VisitObjCImplDecl(ObjCImplDecl *D) { |
1194 | 66 | return VisitObjCContainerDecl(D); |
1195 | 66 | } |
1196 | | |
1197 | 5 | bool CursorVisitor::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
1198 | | // 'ID' could be null when dealing with invalid code. |
1199 | 5 | if (ObjCInterfaceDecl *ID = D->getClassInterface()) |
1200 | 5 | if (Visit(MakeCursorObjCClassRef(ID, D->getLocation(), TU))) |
1201 | 0 | return true; |
1202 | | |
1203 | 5 | return VisitObjCImplDecl(D); |
1204 | 5 | } |
1205 | | |
1206 | 61 | bool CursorVisitor::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
1207 | | #if 0 |
1208 | | // Issue callbacks for super class. |
1209 | | // FIXME: No source location information! |
1210 | | if (D->getSuperClass() && |
1211 | | Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(), |
1212 | | D->getSuperClassLoc(), |
1213 | | TU))) |
1214 | | return true; |
1215 | | #endif |
1216 | | |
1217 | 61 | return VisitObjCImplDecl(D); |
1218 | 61 | } |
1219 | | |
1220 | 18 | bool CursorVisitor::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PD) { |
1221 | 18 | if (ObjCIvarDecl *Ivar = PD->getPropertyIvarDecl()) |
1222 | 14 | if (PD->isIvarNameSpecified()) |
1223 | 10 | return Visit(MakeCursorMemberRef(Ivar, PD->getPropertyIvarDeclLoc(), TU)); |
1224 | | |
1225 | 8 | return false; |
1226 | 18 | } |
1227 | | |
1228 | 107 | bool CursorVisitor::VisitNamespaceDecl(NamespaceDecl *D) { |
1229 | 107 | return VisitDeclContext(D); |
1230 | 107 | } |
1231 | | |
1232 | 7 | bool CursorVisitor::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
1233 | | // Visit nested-name-specifier. |
1234 | 7 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) |
1235 | 2 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
1236 | 0 | return true; |
1237 | | |
1238 | 7 | return Visit(MakeCursorNamespaceRef(D->getAliasedNamespace(), |
1239 | 7 | D->getTargetNameLoc(), TU)); |
1240 | 7 | } |
1241 | | |
1242 | 7 | bool CursorVisitor::VisitUsingDecl(UsingDecl *D) { |
1243 | | // Visit nested-name-specifier. |
1244 | 7 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) { |
1245 | 7 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
1246 | 0 | return true; |
1247 | 7 | } |
1248 | | |
1249 | 7 | if (Visit(MakeCursorOverloadedDeclRef(D, D->getLocation(), TU))) |
1250 | 0 | return true; |
1251 | | |
1252 | 7 | return VisitDeclarationNameInfo(D->getNameInfo()); |
1253 | 7 | } |
1254 | | |
1255 | 5 | bool CursorVisitor::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
1256 | | // Visit nested-name-specifier. |
1257 | 5 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) |
1258 | 1 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
1259 | 0 | return true; |
1260 | | |
1261 | 5 | return Visit(MakeCursorNamespaceRef(D->getNominatedNamespaceAsWritten(), |
1262 | 5 | D->getIdentLocation(), TU)); |
1263 | 5 | } |
1264 | | |
1265 | 4 | bool CursorVisitor::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
1266 | | // Visit nested-name-specifier. |
1267 | 4 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) { |
1268 | 4 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
1269 | 0 | return true; |
1270 | 4 | } |
1271 | | |
1272 | 4 | return VisitDeclarationNameInfo(D->getNameInfo()); |
1273 | 4 | } |
1274 | | |
1275 | | bool CursorVisitor::VisitUnresolvedUsingTypenameDecl( |
1276 | 3 | UnresolvedUsingTypenameDecl *D) { |
1277 | | // Visit nested-name-specifier. |
1278 | 3 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) |
1279 | 3 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
1280 | 0 | return true; |
1281 | | |
1282 | 3 | return false; |
1283 | 3 | } |
1284 | | |
1285 | 1 | bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) { |
1286 | 1 | if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest))) |
1287 | 0 | return true; |
1288 | 1 | if (StringLiteral *Message = D->getMessage()) |
1289 | 1 | if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest))) |
1290 | 0 | return true; |
1291 | 1 | return false; |
1292 | 1 | } |
1293 | | |
1294 | 41 | bool CursorVisitor::VisitFriendDecl(FriendDecl *D) { |
1295 | 41 | if (NamedDecl *FriendD = D->getFriendDecl()) { |
1296 | 32 | if (Visit(MakeCXCursor(FriendD, TU, RegionOfInterest))) |
1297 | 0 | return true; |
1298 | 32 | } else if (TypeSourceInfo *9 TI9 = D->getFriendType()) { |
1299 | 9 | if (Visit(TI->getTypeLoc())) |
1300 | 0 | return true; |
1301 | 9 | } |
1302 | 41 | return false; |
1303 | 41 | } |
1304 | | |
1305 | 1 | bool CursorVisitor::VisitDecompositionDecl(DecompositionDecl *D) { |
1306 | 2 | for (auto *B : D->bindings()) { |
1307 | 2 | if (Visit(MakeCXCursor(B, TU, RegionOfInterest))) |
1308 | 0 | return true; |
1309 | 2 | } |
1310 | 1 | return VisitVarDecl(D); |
1311 | 1 | } |
1312 | | |
1313 | 3.59k | bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) { |
1314 | 3.59k | switch (Name.getName().getNameKind()) { |
1315 | 3.37k | case clang::DeclarationName::Identifier: |
1316 | 3.37k | case clang::DeclarationName::CXXLiteralOperatorName: |
1317 | 3.37k | case clang::DeclarationName::CXXDeductionGuideName: |
1318 | 3.49k | case clang::DeclarationName::CXXOperatorName: |
1319 | 3.49k | case clang::DeclarationName::CXXUsingDirective: |
1320 | 3.49k | return false; |
1321 | | |
1322 | 95 | case clang::DeclarationName::CXXConstructorName: |
1323 | 95 | case clang::DeclarationName::CXXDestructorName: |
1324 | 102 | case clang::DeclarationName::CXXConversionFunctionName: |
1325 | 102 | if (TypeSourceInfo *TSInfo = Name.getNamedTypeInfo()) |
1326 | 7 | return Visit(TSInfo->getTypeLoc()); |
1327 | 95 | return false; |
1328 | | |
1329 | 0 | case clang::DeclarationName::ObjCZeroArgSelector: |
1330 | 0 | case clang::DeclarationName::ObjCOneArgSelector: |
1331 | 0 | case clang::DeclarationName::ObjCMultiArgSelector: |
1332 | | // FIXME: Per-identifier location info? |
1333 | 0 | return false; |
1334 | 3.59k | } |
1335 | | |
1336 | 0 | llvm_unreachable("Invalid DeclarationName::Kind!"); |
1337 | 0 | } |
1338 | | |
1339 | | bool CursorVisitor::VisitNestedNameSpecifier(NestedNameSpecifier *NNS, |
1340 | 0 | SourceRange Range) { |
1341 | | // FIXME: This whole routine is a hack to work around the lack of proper |
1342 | | // source information in nested-name-specifiers (PR5791). Since we do have |
1343 | | // a beginning source location, we can visit the first component of the |
1344 | | // nested-name-specifier, if it's a single-token component. |
1345 | 0 | if (!NNS) |
1346 | 0 | return false; |
1347 | | |
1348 | | // Get the first component in the nested-name-specifier. |
1349 | 0 | while (NestedNameSpecifier *Prefix = NNS->getPrefix()) |
1350 | 0 | NNS = Prefix; |
1351 | |
|
1352 | 0 | switch (NNS->getKind()) { |
1353 | 0 | case NestedNameSpecifier::Namespace: |
1354 | 0 | return Visit( |
1355 | 0 | MakeCursorNamespaceRef(NNS->getAsNamespace(), Range.getBegin(), TU)); |
1356 | | |
1357 | 0 | case NestedNameSpecifier::NamespaceAlias: |
1358 | 0 | return Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(), |
1359 | 0 | Range.getBegin(), TU)); |
1360 | | |
1361 | 0 | case NestedNameSpecifier::TypeSpec: { |
1362 | | // If the type has a form where we know that the beginning of the source |
1363 | | // range matches up with a reference cursor. Visit the appropriate reference |
1364 | | // cursor. |
1365 | 0 | const Type *T = NNS->getAsType(); |
1366 | 0 | if (const TypedefType *Typedef = dyn_cast<TypedefType>(T)) |
1367 | 0 | return Visit(MakeCursorTypeRef(Typedef->getDecl(), Range.getBegin(), TU)); |
1368 | 0 | if (const TagType *Tag = dyn_cast<TagType>(T)) |
1369 | 0 | return Visit(MakeCursorTypeRef(Tag->getDecl(), Range.getBegin(), TU)); |
1370 | 0 | if (const TemplateSpecializationType *TST = |
1371 | 0 | dyn_cast<TemplateSpecializationType>(T)) |
1372 | 0 | return VisitTemplateName(TST->getTemplateName(), Range.getBegin()); |
1373 | 0 | break; |
1374 | 0 | } |
1375 | | |
1376 | 0 | case NestedNameSpecifier::TypeSpecWithTemplate: |
1377 | 0 | case NestedNameSpecifier::Global: |
1378 | 0 | case NestedNameSpecifier::Identifier: |
1379 | 0 | case NestedNameSpecifier::Super: |
1380 | 0 | break; |
1381 | 0 | } |
1382 | | |
1383 | 0 | return false; |
1384 | 0 | } |
1385 | | |
1386 | | bool CursorVisitor::VisitNestedNameSpecifierLoc( |
1387 | 364 | NestedNameSpecifierLoc Qualifier) { |
1388 | 364 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
1389 | 638 | for (; Qualifier; Qualifier = Qualifier.getPrefix()274 ) |
1390 | 274 | Qualifiers.push_back(Qualifier); |
1391 | | |
1392 | 638 | while (!Qualifiers.empty()) { |
1393 | 274 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
1394 | 274 | NestedNameSpecifier *NNS = Q.getNestedNameSpecifier(); |
1395 | 274 | switch (NNS->getKind()) { |
1396 | 135 | case NestedNameSpecifier::Namespace: |
1397 | 135 | if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(), |
1398 | 135 | Q.getLocalBeginLoc(), TU))) |
1399 | 0 | return true; |
1400 | | |
1401 | 135 | break; |
1402 | | |
1403 | 135 | case NestedNameSpecifier::NamespaceAlias: |
1404 | 17 | if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(), |
1405 | 17 | Q.getLocalBeginLoc(), TU))) |
1406 | 0 | return true; |
1407 | | |
1408 | 17 | break; |
1409 | | |
1410 | 104 | case NestedNameSpecifier::TypeSpec: |
1411 | 106 | case NestedNameSpecifier::TypeSpecWithTemplate: |
1412 | 106 | if (Visit(Q.getTypeLoc())) |
1413 | 0 | return true; |
1414 | | |
1415 | 106 | break; |
1416 | | |
1417 | 106 | case NestedNameSpecifier::Global: |
1418 | 16 | case NestedNameSpecifier::Identifier: |
1419 | 16 | case NestedNameSpecifier::Super: |
1420 | 16 | break; |
1421 | 274 | } |
1422 | 274 | } |
1423 | | |
1424 | 364 | return false; |
1425 | 364 | } |
1426 | | |
1427 | | bool CursorVisitor::VisitTemplateParameters( |
1428 | 291 | const TemplateParameterList *Params) { |
1429 | 291 | if (!Params) |
1430 | 0 | return false; |
1431 | | |
1432 | 291 | for (TemplateParameterList::const_iterator P = Params->begin(), |
1433 | 291 | PEnd = Params->end(); |
1434 | 666 | P != PEnd; ++P375 ) { |
1435 | 375 | if (Visit(MakeCXCursor(*P, TU, RegionOfInterest))) |
1436 | 0 | return true; |
1437 | 375 | } |
1438 | | |
1439 | 291 | return false; |
1440 | 291 | } |
1441 | | |
1442 | 158 | bool CursorVisitor::VisitTemplateName(TemplateName Name, SourceLocation Loc) { |
1443 | 158 | switch (Name.getKind()) { |
1444 | 157 | case TemplateName::Template: |
1445 | 157 | case TemplateName::UsingTemplate: |
1446 | 157 | case TemplateName::QualifiedTemplate: // FIXME: Visit nested-name-specifier. |
1447 | 157 | return Visit(MakeCursorTemplateRef(Name.getAsTemplateDecl(), Loc, TU)); |
1448 | | |
1449 | 0 | case TemplateName::OverloadedTemplate: |
1450 | | // Visit the overloaded template set. |
1451 | 0 | if (Visit(MakeCursorOverloadedDeclRef(Name, Loc, TU))) |
1452 | 0 | return true; |
1453 | | |
1454 | 0 | return false; |
1455 | | |
1456 | 0 | case TemplateName::AssumedTemplate: |
1457 | | // FIXME: Visit DeclarationName? |
1458 | 0 | return false; |
1459 | | |
1460 | 1 | case TemplateName::DependentTemplate: |
1461 | | // FIXME: Visit nested-name-specifier. |
1462 | 1 | return false; |
1463 | | |
1464 | 0 | case TemplateName::SubstTemplateTemplateParm: |
1465 | 0 | return Visit(MakeCursorTemplateRef( |
1466 | 0 | Name.getAsSubstTemplateTemplateParm()->getParameter(), Loc, TU)); |
1467 | | |
1468 | 0 | case TemplateName::SubstTemplateTemplateParmPack: |
1469 | 0 | return Visit(MakeCursorTemplateRef( |
1470 | 0 | Name.getAsSubstTemplateTemplateParmPack()->getParameterPack(), Loc, |
1471 | 0 | TU)); |
1472 | 158 | } |
1473 | | |
1474 | 0 | llvm_unreachable("Invalid TemplateName::Kind!"); |
1475 | 0 | } |
1476 | | |
1477 | 274 | bool CursorVisitor::VisitTemplateArgumentLoc(const TemplateArgumentLoc &TAL) { |
1478 | 274 | switch (TAL.getArgument().getKind()) { |
1479 | 0 | case TemplateArgument::Null: |
1480 | 0 | case TemplateArgument::Integral: |
1481 | 0 | case TemplateArgument::Pack: |
1482 | 0 | return false; |
1483 | | |
1484 | 254 | case TemplateArgument::Type: |
1485 | 254 | if (TypeSourceInfo *TSInfo = TAL.getTypeSourceInfo()) |
1486 | 254 | return Visit(TSInfo->getTypeLoc()); |
1487 | 0 | return false; |
1488 | | |
1489 | 0 | case TemplateArgument::Declaration: |
1490 | 0 | if (Expr *E = TAL.getSourceDeclExpression()) |
1491 | 0 | return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest)); |
1492 | 0 | return false; |
1493 | | |
1494 | 0 | case TemplateArgument::NullPtr: |
1495 | 0 | if (Expr *E = TAL.getSourceNullPtrExpression()) |
1496 | 0 | return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest)); |
1497 | 0 | return false; |
1498 | | |
1499 | 14 | case TemplateArgument::Expression: |
1500 | 14 | if (Expr *E = TAL.getSourceExpression()) |
1501 | 14 | return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest)); |
1502 | 0 | return false; |
1503 | | |
1504 | 6 | case TemplateArgument::Template: |
1505 | 6 | case TemplateArgument::TemplateExpansion: |
1506 | 6 | if (VisitNestedNameSpecifierLoc(TAL.getTemplateQualifierLoc())) |
1507 | 0 | return true; |
1508 | | |
1509 | 6 | return VisitTemplateName(TAL.getArgument().getAsTemplateOrTemplatePattern(), |
1510 | 6 | TAL.getTemplateNameLoc()); |
1511 | 274 | } |
1512 | | |
1513 | 0 | llvm_unreachable("Invalid TemplateArgument::Kind!"); |
1514 | 0 | } |
1515 | | |
1516 | 7 | bool CursorVisitor::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
1517 | 7 | return VisitDeclContext(D); |
1518 | 7 | } |
1519 | | |
1520 | 180 | bool CursorVisitor::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
1521 | 180 | return Visit(TL.getUnqualifiedLoc()); |
1522 | 180 | } |
1523 | | |
1524 | 3.48k | bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
1525 | 3.48k | ASTContext &Context = AU->getASTContext(); |
1526 | | |
1527 | | // Some builtin types (such as Objective-C's "id", "sel", and |
1528 | | // "Class") have associated declarations. Create cursors for those. |
1529 | 3.48k | QualType VisitType; |
1530 | 3.48k | switch (TL.getTypePtr()->getKind()) { |
1531 | | |
1532 | 1.34k | case BuiltinType::Void: |
1533 | 1.34k | case BuiltinType::NullPtr: |
1534 | 1.35k | case BuiltinType::Dependent: |
1535 | 1.35k | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
1536 | 49.4k | case BuiltinType::Id: |
1537 | 49.4k | #include "clang/Basic/OpenCLImageTypes.def"1.35k |
1538 | 49.4k | #define EXT_OPAQUE_TYPE(ExtTYpe, Id, Ext) case BuiltinType::Id:16.7k |
1539 | 49.4k | #include "clang/Basic/OpenCLExtensionTypes.def"1.39k |
1540 | 16.7k | case BuiltinType::OCLSampler: |
1541 | 1.39k | case BuiltinType::OCLEvent: |
1542 | 1.39k | case BuiltinType::OCLClkEvent: |
1543 | 1.39k | case BuiltinType::OCLQueue: |
1544 | 1.39k | case BuiltinType::OCLReserveID: |
1545 | 68.2k | #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id: |
1546 | 68.2k | #include "clang/Basic/AArch64SVEACLETypes.def"1.39k |
1547 | 68.2k | #define PPC_VECTOR_TYPE(Name, Id, Size) case BuiltinType::Id:2.78k |
1548 | 68.2k | #include "clang/Basic/PPCTypes.def"1.39k |
1549 | 91.8k | #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id: |
1550 | 91.8k | #include "clang/Basic/RISCVVTypes.def"1.39k |
1551 | 91.8k | #define BUILTIN_TYPE(Id, SingletonId) |
1552 | 91.8k | #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:56.3k |
1553 | 91.8k | #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:54.5k |
1554 | 91.8k | #define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:27.3k |
1555 | 91.8k | #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:34.3k |
1556 | 91.8k | #include "clang/AST/BuiltinTypes.def"1.39k |
1557 | 3.43k | break; |
1558 | | |
1559 | 48 | case BuiltinType::ObjCId: |
1560 | 48 | VisitType = Context.getObjCIdType(); |
1561 | 48 | break; |
1562 | | |
1563 | 0 | case BuiltinType::ObjCClass: |
1564 | 0 | VisitType = Context.getObjCClassType(); |
1565 | 0 | break; |
1566 | | |
1567 | 0 | case BuiltinType::ObjCSel: |
1568 | 0 | VisitType = Context.getObjCSelType(); |
1569 | 0 | break; |
1570 | 3.48k | } |
1571 | | |
1572 | 3.48k | if (!VisitType.isNull()) { |
1573 | 48 | if (const TypedefType *Typedef = VisitType->getAs<TypedefType>()) |
1574 | 48 | return Visit( |
1575 | 48 | MakeCursorTypeRef(Typedef->getDecl(), TL.getBuiltinLoc(), TU)); |
1576 | 48 | } |
1577 | | |
1578 | 3.43k | return false; |
1579 | 3.48k | } |
1580 | | |
1581 | 384 | bool CursorVisitor::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
1582 | 384 | return Visit(MakeCursorTypeRef(TL.getTypedefNameDecl(), TL.getNameLoc(), TU)); |
1583 | 384 | } |
1584 | | |
1585 | 0 | bool CursorVisitor::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
1586 | 0 | return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU)); |
1587 | 0 | } |
1588 | | |
1589 | 627 | bool CursorVisitor::VisitTagTypeLoc(TagTypeLoc TL) { |
1590 | 627 | if (TL.isDefinition()) |
1591 | 68 | return Visit(MakeCXCursor(TL.getDecl(), TU, RegionOfInterest)); |
1592 | | |
1593 | 559 | return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU)); |
1594 | 627 | } |
1595 | | |
1596 | 269 | bool CursorVisitor::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
1597 | 269 | return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU)); |
1598 | 269 | } |
1599 | | |
1600 | 320 | bool CursorVisitor::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
1601 | 320 | return Visit(MakeCursorObjCClassRef(TL.getIFaceDecl(), TL.getNameLoc(), TU)); |
1602 | 320 | } |
1603 | | |
1604 | 5 | bool CursorVisitor::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
1605 | 5 | if (Visit(MakeCursorTypeRef(TL.getDecl(), TL.getBeginLoc(), TU))) |
1606 | 0 | return true; |
1607 | 5 | for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I0 ) { |
1608 | 0 | if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I), |
1609 | 0 | TU))) |
1610 | 0 | return true; |
1611 | 0 | } |
1612 | | |
1613 | 5 | return false; |
1614 | 5 | } |
1615 | | |
1616 | 56 | bool CursorVisitor::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
1617 | 56 | if (TL.hasBaseTypeAsWritten() && Visit(TL.getBaseLoc())) |
1618 | 0 | return true; |
1619 | | |
1620 | 70 | for (unsigned I = 0, N = TL.getNumTypeArgs(); 56 I != N; ++I14 ) { |
1621 | 14 | if (Visit(TL.getTypeArgTInfo(I)->getTypeLoc())) |
1622 | 0 | return true; |
1623 | 14 | } |
1624 | | |
1625 | 106 | for (unsigned I = 0, N = TL.getNumProtocols(); 56 I != N; ++I50 ) { |
1626 | 50 | if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I), |
1627 | 50 | TU))) |
1628 | 0 | return true; |
1629 | 50 | } |
1630 | | |
1631 | 56 | return false; |
1632 | 56 | } |
1633 | | |
1634 | 203 | bool CursorVisitor::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
1635 | 203 | return Visit(TL.getPointeeLoc()); |
1636 | 203 | } |
1637 | | |
1638 | 41 | bool CursorVisitor::VisitParenTypeLoc(ParenTypeLoc TL) { |
1639 | 41 | return Visit(TL.getInnerLoc()); |
1640 | 41 | } |
1641 | | |
1642 | 0 | bool CursorVisitor::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) { |
1643 | 0 | return Visit(TL.getInnerLoc()); |
1644 | 0 | } |
1645 | | |
1646 | 282 | bool CursorVisitor::VisitPointerTypeLoc(PointerTypeLoc TL) { |
1647 | 282 | return Visit(TL.getPointeeLoc()); |
1648 | 282 | } |
1649 | | |
1650 | 4 | bool CursorVisitor::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
1651 | 4 | return Visit(TL.getPointeeLoc()); |
1652 | 4 | } |
1653 | | |
1654 | 3 | bool CursorVisitor::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
1655 | 3 | return Visit(TL.getPointeeLoc()); |
1656 | 3 | } |
1657 | | |
1658 | 113 | bool CursorVisitor::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
1659 | 113 | return Visit(TL.getPointeeLoc()); |
1660 | 113 | } |
1661 | | |
1662 | 4 | bool CursorVisitor::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
1663 | 4 | return Visit(TL.getPointeeLoc()); |
1664 | 4 | } |
1665 | | |
1666 | 2 | bool CursorVisitor::VisitUsingTypeLoc(UsingTypeLoc TL) { return false; } |
1667 | | |
1668 | 10 | bool CursorVisitor::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
1669 | 10 | return Visit(TL.getModifiedLoc()); |
1670 | 10 | } |
1671 | | |
1672 | 0 | bool CursorVisitor::VisitBTFTagAttributedTypeLoc(BTFTagAttributedTypeLoc TL) { |
1673 | 0 | return Visit(TL.getWrappedLoc()); |
1674 | 0 | } |
1675 | | |
1676 | | bool CursorVisitor::VisitFunctionTypeLoc(FunctionTypeLoc TL, |
1677 | 1.92k | bool SkipResultType) { |
1678 | 1.92k | if (!SkipResultType && Visit(TL.getReturnLoc())63 ) |
1679 | 0 | return true; |
1680 | | |
1681 | 3.42k | for (unsigned I = 0, N = TL.getNumParams(); 1.92k I != N; ++I1.50k ) |
1682 | 1.50k | if (Decl *D = TL.getParam(I)) |
1683 | 1.50k | if (Visit(MakeCXCursor(D, TU, RegionOfInterest))) |
1684 | 0 | return true; |
1685 | | |
1686 | 1.92k | return false; |
1687 | 1.92k | } |
1688 | | |
1689 | 53 | bool CursorVisitor::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
1690 | 53 | if (Visit(TL.getElementLoc())) |
1691 | 0 | return true; |
1692 | | |
1693 | 53 | if (Expr *Size = TL.getSizeExpr()) |
1694 | 26 | return Visit(MakeCXCursor(Size, StmtParent, TU, RegionOfInterest)); |
1695 | | |
1696 | 27 | return false; |
1697 | 53 | } |
1698 | | |
1699 | 0 | bool CursorVisitor::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
1700 | 0 | return Visit(TL.getOriginalLoc()); |
1701 | 0 | } |
1702 | | |
1703 | 0 | bool CursorVisitor::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
1704 | 0 | return Visit(TL.getOriginalLoc()); |
1705 | 0 | } |
1706 | | |
1707 | | bool CursorVisitor::VisitDeducedTemplateSpecializationTypeLoc( |
1708 | 0 | DeducedTemplateSpecializationTypeLoc TL) { |
1709 | 0 | if (VisitTemplateName(TL.getTypePtr()->getTemplateName(), |
1710 | 0 | TL.getTemplateNameLoc())) |
1711 | 0 | return true; |
1712 | | |
1713 | 0 | return false; |
1714 | 0 | } |
1715 | | |
1716 | | bool CursorVisitor::VisitTemplateSpecializationTypeLoc( |
1717 | 152 | TemplateSpecializationTypeLoc TL) { |
1718 | | // Visit the template name. |
1719 | 152 | if (VisitTemplateName(TL.getTypePtr()->getTemplateName(), |
1720 | 152 | TL.getTemplateNameLoc())) |
1721 | 0 | return true; |
1722 | | |
1723 | | // Visit the template arguments. |
1724 | 350 | for (unsigned I = 0, N = TL.getNumArgs(); 152 I != N; ++I198 ) |
1725 | 198 | if (VisitTemplateArgumentLoc(TL.getArgLoc(I))) |
1726 | 0 | return true; |
1727 | | |
1728 | 152 | return false; |
1729 | 152 | } |
1730 | | |
1731 | 0 | bool CursorVisitor::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
1732 | 0 | return Visit(MakeCXCursor(TL.getUnderlyingExpr(), StmtParent, TU)); |
1733 | 0 | } |
1734 | | |
1735 | 0 | bool CursorVisitor::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
1736 | 0 | if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo()) |
1737 | 0 | return Visit(TSInfo->getTypeLoc()); |
1738 | | |
1739 | 0 | return false; |
1740 | 0 | } |
1741 | | |
1742 | 0 | bool CursorVisitor::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
1743 | 0 | if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo()) |
1744 | 0 | return Visit(TSInfo->getTypeLoc()); |
1745 | | |
1746 | 0 | return false; |
1747 | 0 | } |
1748 | | |
1749 | 21 | bool CursorVisitor::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
1750 | 21 | return VisitNestedNameSpecifierLoc(TL.getQualifierLoc()); |
1751 | 21 | } |
1752 | | |
1753 | | bool CursorVisitor::VisitDependentTemplateSpecializationTypeLoc( |
1754 | 4 | DependentTemplateSpecializationTypeLoc TL) { |
1755 | | // Visit the nested-name-specifier, if there is one. |
1756 | 4 | if (TL.getQualifierLoc() && VisitNestedNameSpecifierLoc(TL.getQualifierLoc())) |
1757 | 0 | return true; |
1758 | | |
1759 | | // Visit the template arguments. |
1760 | 8 | for (unsigned I = 0, N = TL.getNumArgs(); 4 I != N; ++I4 ) |
1761 | 4 | if (VisitTemplateArgumentLoc(TL.getArgLoc(I))) |
1762 | 0 | return true; |
1763 | | |
1764 | 4 | return false; |
1765 | 4 | } |
1766 | | |
1767 | 252 | bool CursorVisitor::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
1768 | 252 | if (VisitNestedNameSpecifierLoc(TL.getQualifierLoc())) |
1769 | 0 | return true; |
1770 | | |
1771 | 252 | return Visit(TL.getNamedTypeLoc()); |
1772 | 252 | } |
1773 | | |
1774 | 1 | bool CursorVisitor::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
1775 | 1 | return Visit(TL.getPatternLoc()); |
1776 | 1 | } |
1777 | | |
1778 | 1 | bool CursorVisitor::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
1779 | 1 | if (Expr *E = TL.getUnderlyingExpr()) |
1780 | 1 | return Visit(MakeCXCursor(E, StmtParent, TU)); |
1781 | | |
1782 | 0 | return false; |
1783 | 1 | } |
1784 | | |
1785 | 7 | bool CursorVisitor::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
1786 | 7 | return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU)); |
1787 | 7 | } |
1788 | | |
1789 | 3 | bool CursorVisitor::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
1790 | 3 | return Visit(TL.getValueLoc()); |
1791 | 3 | } |
1792 | | |
1793 | 2 | bool CursorVisitor::VisitPipeTypeLoc(PipeTypeLoc TL) { |
1794 | 2 | return Visit(TL.getValueLoc()); |
1795 | 2 | } |
1796 | | |
1797 | | #define DEFAULT_TYPELOC_IMPL(CLASS, PARENT) \ |
1798 | 1.00k | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ |
1799 | 1.00k | return Visit##PARENT##Loc(TL); \ |
1800 | 1.00k | } Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitComplexTypeLoc(clang::ComplexTypeLoc) clang::cxcursor::CursorVisitor::VisitConstantArrayTypeLoc(clang::ConstantArrayTypeLoc) Line | Count | Source | 1798 | 18 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 18 | return Visit##PARENT##Loc(TL); \ | 1800 | 18 | } |
clang::cxcursor::CursorVisitor::VisitIncompleteArrayTypeLoc(clang::IncompleteArrayTypeLoc) Line | Count | Source | 1798 | 27 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 27 | return Visit##PARENT##Loc(TL); \ | 1800 | 27 | } |
clang::cxcursor::CursorVisitor::VisitVariableArrayTypeLoc(clang::VariableArrayTypeLoc) Line | Count | Source | 1798 | 5 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 5 | return Visit##PARENT##Loc(TL); \ | 1800 | 5 | } |
clang::cxcursor::CursorVisitor::VisitDependentSizedArrayTypeLoc(clang::DependentSizedArrayTypeLoc) Line | Count | Source | 1798 | 3 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 3 | return Visit##PARENT##Loc(TL); \ | 1800 | 3 | } |
Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitDependentAddressSpaceTypeLoc(clang::DependentAddressSpaceTypeLoc) Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitDependentVectorTypeLoc(clang::DependentVectorTypeLoc) Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitDependentSizedExtVectorTypeLoc(clang::DependentSizedExtVectorTypeLoc) clang::cxcursor::CursorVisitor::VisitVectorTypeLoc(clang::VectorTypeLoc) Line | Count | Source | 1798 | 117 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 117 | return Visit##PARENT##Loc(TL); \ | 1800 | 117 | } |
clang::cxcursor::CursorVisitor::VisitExtVectorTypeLoc(clang::ExtVectorTypeLoc) Line | Count | Source | 1798 | 114 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 114 | return Visit##PARENT##Loc(TL); \ | 1800 | 114 | } |
Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitConstantMatrixTypeLoc(clang::ConstantMatrixTypeLoc) Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitDependentSizedMatrixTypeLoc(clang::DependentSizedMatrixTypeLoc) clang::cxcursor::CursorVisitor::VisitFunctionProtoTypeLoc(clang::FunctionProtoTypeLoc) Line | Count | Source | 1798 | 60 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 60 | return Visit##PARENT##Loc(TL); \ | 1800 | 60 | } |
clang::cxcursor::CursorVisitor::VisitFunctionNoProtoTypeLoc(clang::FunctionNoProtoTypeLoc) Line | Count | Source | 1798 | 3 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 3 | return Visit##PARENT##Loc(TL); \ | 1800 | 3 | } |
clang::cxcursor::CursorVisitor::VisitRecordTypeLoc(clang::RecordTypeLoc) Line | Count | Source | 1798 | 600 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 600 | return Visit##PARENT##Loc(TL); \ | 1800 | 600 | } |
clang::cxcursor::CursorVisitor::VisitEnumTypeLoc(clang::EnumTypeLoc) Line | Count | Source | 1798 | 27 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 27 | return Visit##PARENT##Loc(TL); \ | 1800 | 27 | } |
clang::cxcursor::CursorVisitor::VisitSubstTemplateTypeParmTypeLoc(clang::SubstTemplateTypeParmTypeLoc) Line | Count | Source | 1798 | 3 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 3 | return Visit##PARENT##Loc(TL); \ | 1800 | 3 | } |
Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitSubstTemplateTypeParmPackTypeLoc(clang::SubstTemplateTypeParmPackTypeLoc) clang::cxcursor::CursorVisitor::VisitAutoTypeLoc(clang::AutoTypeLoc) Line | Count | Source | 1798 | 24 | bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \ | 1799 | 24 | return Visit##PARENT##Loc(TL); \ | 1800 | 24 | } |
Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitBitIntTypeLoc(clang::BitIntTypeLoc) Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitDependentBitIntTypeLoc(clang::DependentBitIntTypeLoc) |
1801 | | |
1802 | | DEFAULT_TYPELOC_IMPL(Complex, Type) |
1803 | | DEFAULT_TYPELOC_IMPL(ConstantArray, ArrayType) |
1804 | | DEFAULT_TYPELOC_IMPL(IncompleteArray, ArrayType) |
1805 | | DEFAULT_TYPELOC_IMPL(VariableArray, ArrayType) |
1806 | | DEFAULT_TYPELOC_IMPL(DependentSizedArray, ArrayType) |
1807 | | DEFAULT_TYPELOC_IMPL(DependentAddressSpace, Type) |
1808 | | DEFAULT_TYPELOC_IMPL(DependentVector, Type) |
1809 | | DEFAULT_TYPELOC_IMPL(DependentSizedExtVector, Type) |
1810 | | DEFAULT_TYPELOC_IMPL(Vector, Type) |
1811 | | DEFAULT_TYPELOC_IMPL(ExtVector, VectorType) |
1812 | | DEFAULT_TYPELOC_IMPL(ConstantMatrix, MatrixType) |
1813 | | DEFAULT_TYPELOC_IMPL(DependentSizedMatrix, MatrixType) |
1814 | | DEFAULT_TYPELOC_IMPL(FunctionProto, FunctionType) |
1815 | | DEFAULT_TYPELOC_IMPL(FunctionNoProto, FunctionType) |
1816 | | DEFAULT_TYPELOC_IMPL(Record, TagType) |
1817 | | DEFAULT_TYPELOC_IMPL(Enum, TagType) |
1818 | | DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParm, Type) |
1819 | | DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParmPack, Type) |
1820 | | DEFAULT_TYPELOC_IMPL(Auto, Type) |
1821 | | DEFAULT_TYPELOC_IMPL(BitInt, Type) |
1822 | | DEFAULT_TYPELOC_IMPL(DependentBitInt, Type) |
1823 | | |
1824 | 611 | bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) { |
1825 | | // Visit the nested-name-specifier, if present. |
1826 | 611 | if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) |
1827 | 1 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
1828 | 0 | return true; |
1829 | | |
1830 | 611 | if (D->isCompleteDefinition()) { |
1831 | 573 | for (const auto &I : D->bases()) { |
1832 | 125 | if (Visit(cxcursor::MakeCursorCXXBaseSpecifier(&I, TU))) |
1833 | 0 | return true; |
1834 | 125 | } |
1835 | 573 | } |
1836 | | |
1837 | 611 | return VisitTagDecl(D); |
1838 | 611 | } |
1839 | | |
1840 | 7.43k | bool CursorVisitor::VisitAttributes(Decl *D) { |
1841 | 7.43k | for (const auto *I : D->attrs()) |
1842 | 188 | if ((TU->ParsingOptions & CXTranslationUnit_VisitImplicitAttributes || |
1843 | 188 | !I->isImplicit()186 ) && |
1844 | 188 | Visit(MakeCXCursor(I, D, TU))180 ) |
1845 | 0 | return true; |
1846 | | |
1847 | 7.43k | return false; |
1848 | 7.43k | } |
1849 | | |
1850 | | //===----------------------------------------------------------------------===// |
1851 | | // Data-recursive visitor methods. |
1852 | | //===----------------------------------------------------------------------===// |
1853 | | |
1854 | | namespace { |
1855 | | #define DEF_JOB(NAME, DATA, KIND) \ |
1856 | | class NAME : public VisitorJob { \ |
1857 | | public: \ |
1858 | | NAME(const DATA *d, CXCursor parent) \ |
1859 | 26.4k | : VisitorJob(parent, VisitorJob::KIND, d) {} \ CIndex.cpp:(anonymous namespace)::PostChildrenVisit::PostChildrenVisit(void const*, CXCursor) Line | Count | Source | 1859 | 6.31k | : VisitorJob(parent, VisitorJob::KIND, d) {} \ |
CIndex.cpp:(anonymous namespace)::StmtVisit::StmtVisit(clang::Stmt const*, CXCursor) Line | Count | Source | 1859 | 18.4k | : VisitorJob(parent, VisitorJob::KIND, d) {} \ |
CIndex.cpp:(anonymous namespace)::DeclRefExprParts::DeclRefExprParts(clang::DeclRefExpr const*, CXCursor) Line | Count | Source | 1859 | 1.20k | : VisitorJob(parent, VisitorJob::KIND, d) {} \ |
CIndex.cpp:(anonymous namespace)::LambdaExprParts::LambdaExprParts(clang::LambdaExpr const*, CXCursor) Line | Count | Source | 1859 | 4 | : VisitorJob(parent, VisitorJob::KIND, d) {} \ |
CIndex.cpp:(anonymous namespace)::MemberExprParts::MemberExprParts(clang::MemberExpr const*, CXCursor) Line | Count | Source | 1859 | 526 | : VisitorJob(parent, VisitorJob::KIND, d) {} \ |
CIndex.cpp:(anonymous namespace)::OverloadExprParts::OverloadExprParts(clang::OverloadExpr const*, CXCursor) Line | Count | Source | 1859 | 15 | : VisitorJob(parent, VisitorJob::KIND, d) {} \ |
CIndex.cpp:(anonymous namespace)::SizeOfPackExprParts::SizeOfPackExprParts(clang::SizeOfPackExpr const*, CXCursor) Line | Count | Source | 1859 | 2 | : VisitorJob(parent, VisitorJob::KIND, d) {} \ |
|
1860 | 0 | static bool classof(const VisitorJob *VJ) { \ |
1861 | 0 | return VJ->getKind() == KIND; \ |
1862 | 0 | } \ Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::StmtVisit::classof(clang::cxcursor::VisitorJob const*) Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::MemberExprParts::classof(clang::cxcursor::VisitorJob const*) Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::DeclRefExprParts::classof(clang::cxcursor::VisitorJob const*) Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::OverloadExprParts::classof(clang::cxcursor::VisitorJob const*) Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::SizeOfPackExprParts::classof(clang::cxcursor::VisitorJob const*) Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::LambdaExprParts::classof(clang::cxcursor::VisitorJob const*) Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::PostChildrenVisit::classof(clang::cxcursor::VisitorJob const*) |
1863 | 20.1k | const DATA *get() const { return static_cast<const DATA *>(data[0]); } \ CIndex.cpp:(anonymous namespace)::StmtVisit::get() const Line | Count | Source | 1863 | 18.4k | const DATA *get() const { return static_cast<const DATA *>(data[0]); } \ |
CIndex.cpp:(anonymous namespace)::MemberExprParts::get() const Line | Count | Source | 1863 | 526 | const DATA *get() const { return static_cast<const DATA *>(data[0]); } \ |
CIndex.cpp:(anonymous namespace)::DeclRefExprParts::get() const Line | Count | Source | 1863 | 1.20k | const DATA *get() const { return static_cast<const DATA *>(data[0]); } \ |
CIndex.cpp:(anonymous namespace)::OverloadExprParts::get() const Line | Count | Source | 1863 | 15 | const DATA *get() const { return static_cast<const DATA *>(data[0]); } \ |
CIndex.cpp:(anonymous namespace)::SizeOfPackExprParts::get() const Line | Count | Source | 1863 | 2 | const DATA *get() const { return static_cast<const DATA *>(data[0]); } \ |
CIndex.cpp:(anonymous namespace)::LambdaExprParts::get() const Line | Count | Source | 1863 | 4 | const DATA *get() const { return static_cast<const DATA *>(data[0]); } \ |
Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::PostChildrenVisit::get() const |
1864 | | }; |
1865 | | |
1866 | | DEF_JOB(StmtVisit, Stmt, StmtVisitKind) |
1867 | | DEF_JOB(MemberExprParts, MemberExpr, MemberExprPartsKind) |
1868 | | DEF_JOB(DeclRefExprParts, DeclRefExpr, DeclRefExprPartsKind) |
1869 | | DEF_JOB(OverloadExprParts, OverloadExpr, OverloadExprPartsKind) |
1870 | | DEF_JOB(SizeOfPackExprParts, SizeOfPackExpr, SizeOfPackExprPartsKind) |
1871 | | DEF_JOB(LambdaExprParts, LambdaExpr, LambdaExprPartsKind) |
1872 | | DEF_JOB(PostChildrenVisit, void, PostChildrenVisitKind) |
1873 | | #undef DEF_JOB |
1874 | | |
1875 | | class ExplicitTemplateArgsVisit : public VisitorJob { |
1876 | | public: |
1877 | | ExplicitTemplateArgsVisit(const TemplateArgumentLoc *Begin, |
1878 | | const TemplateArgumentLoc *End, CXCursor parent) |
1879 | | : VisitorJob(parent, VisitorJob::ExplicitTemplateArgsVisitKind, Begin, |
1880 | 12 | End) {} |
1881 | 0 | static bool classof(const VisitorJob *VJ) { |
1882 | 0 | return VJ->getKind() == ExplicitTemplateArgsVisitKind; |
1883 | 0 | } |
1884 | 12 | const TemplateArgumentLoc *begin() const { |
1885 | 12 | return static_cast<const TemplateArgumentLoc *>(data[0]); |
1886 | 12 | } |
1887 | 12 | const TemplateArgumentLoc *end() { |
1888 | 12 | return static_cast<const TemplateArgumentLoc *>(data[1]); |
1889 | 12 | } |
1890 | | }; |
1891 | | class DeclVisit : public VisitorJob { |
1892 | | public: |
1893 | | DeclVisit(const Decl *D, CXCursor parent, bool isFirst) |
1894 | | : VisitorJob(parent, VisitorJob::DeclVisitKind, D, |
1895 | 356 | isFirst ? (void *)1 : (void *)nullptr) {} |
1896 | 0 | static bool classof(const VisitorJob *VJ) { |
1897 | 0 | return VJ->getKind() == DeclVisitKind; |
1898 | 0 | } |
1899 | 356 | const Decl *get() const { return static_cast<const Decl *>(data[0]); } |
1900 | 356 | bool isFirst() const { return data[1] != nullptr; } |
1901 | | }; |
1902 | | class TypeLocVisit : public VisitorJob { |
1903 | | public: |
1904 | | TypeLocVisit(TypeLoc tl, CXCursor parent) |
1905 | | : VisitorJob(parent, VisitorJob::TypeLocVisitKind, |
1906 | 186 | tl.getType().getAsOpaquePtr(), tl.getOpaqueData()) {} |
1907 | | |
1908 | 0 | static bool classof(const VisitorJob *VJ) { |
1909 | 0 | return VJ->getKind() == TypeLocVisitKind; |
1910 | 0 | } |
1911 | | |
1912 | 186 | TypeLoc get() const { |
1913 | 186 | QualType T = QualType::getFromOpaquePtr(data[0]); |
1914 | 186 | return TypeLoc(T, const_cast<void *>(data[1])); |
1915 | 186 | } |
1916 | | }; |
1917 | | |
1918 | | class LabelRefVisit : public VisitorJob { |
1919 | | public: |
1920 | | LabelRefVisit(LabelDecl *LD, SourceLocation labelLoc, CXCursor parent) |
1921 | | : VisitorJob(parent, VisitorJob::LabelRefVisitKind, LD, |
1922 | 3 | labelLoc.getPtrEncoding()) {} |
1923 | | |
1924 | 0 | static bool classof(const VisitorJob *VJ) { |
1925 | 0 | return VJ->getKind() == VisitorJob::LabelRefVisitKind; |
1926 | 0 | } |
1927 | 3 | const LabelDecl *get() const { |
1928 | 3 | return static_cast<const LabelDecl *>(data[0]); |
1929 | 3 | } |
1930 | 2 | SourceLocation getLoc() const { |
1931 | 2 | return SourceLocation::getFromPtrEncoding(data[1]); |
1932 | 2 | } |
1933 | | }; |
1934 | | |
1935 | | class NestedNameSpecifierLocVisit : public VisitorJob { |
1936 | | public: |
1937 | | NestedNameSpecifierLocVisit(NestedNameSpecifierLoc Qualifier, CXCursor parent) |
1938 | | : VisitorJob(parent, VisitorJob::NestedNameSpecifierLocVisitKind, |
1939 | | Qualifier.getNestedNameSpecifier(), |
1940 | 6 | Qualifier.getOpaqueData()) {} |
1941 | | |
1942 | 0 | static bool classof(const VisitorJob *VJ) { |
1943 | 0 | return VJ->getKind() == VisitorJob::NestedNameSpecifierLocVisitKind; |
1944 | 0 | } |
1945 | | |
1946 | 6 | NestedNameSpecifierLoc get() const { |
1947 | 6 | return NestedNameSpecifierLoc( |
1948 | 6 | const_cast<NestedNameSpecifier *>( |
1949 | 6 | static_cast<const NestedNameSpecifier *>(data[0])), |
1950 | 6 | const_cast<void *>(data[1])); |
1951 | 6 | } |
1952 | | }; |
1953 | | |
1954 | | class DeclarationNameInfoVisit : public VisitorJob { |
1955 | | public: |
1956 | | DeclarationNameInfoVisit(const Stmt *S, CXCursor parent) |
1957 | 6 | : VisitorJob(parent, VisitorJob::DeclarationNameInfoVisitKind, S) {} |
1958 | 0 | static bool classof(const VisitorJob *VJ) { |
1959 | 0 | return VJ->getKind() == VisitorJob::DeclarationNameInfoVisitKind; |
1960 | 0 | } |
1961 | 6 | DeclarationNameInfo get() const { |
1962 | 6 | const Stmt *S = static_cast<const Stmt *>(data[0]); |
1963 | 6 | switch (S->getStmtClass()) { |
1964 | 0 | default: |
1965 | 0 | llvm_unreachable("Unhandled Stmt"); |
1966 | 2 | case clang::Stmt::MSDependentExistsStmtClass: |
1967 | 2 | return cast<MSDependentExistsStmt>(S)->getNameInfo(); |
1968 | 3 | case Stmt::CXXDependentScopeMemberExprClass: |
1969 | 3 | return cast<CXXDependentScopeMemberExpr>(S)->getMemberNameInfo(); |
1970 | 1 | case Stmt::DependentScopeDeclRefExprClass: |
1971 | 1 | return cast<DependentScopeDeclRefExpr>(S)->getNameInfo(); |
1972 | 0 | case Stmt::OMPCriticalDirectiveClass: |
1973 | 0 | return cast<OMPCriticalDirective>(S)->getDirectiveName(); |
1974 | 6 | } |
1975 | 6 | } |
1976 | | }; |
1977 | | class MemberRefVisit : public VisitorJob { |
1978 | | public: |
1979 | | MemberRefVisit(const FieldDecl *D, SourceLocation L, CXCursor parent) |
1980 | | : VisitorJob(parent, VisitorJob::MemberRefVisitKind, D, |
1981 | 18 | L.getPtrEncoding()) {} |
1982 | 0 | static bool classof(const VisitorJob *VJ) { |
1983 | 0 | return VJ->getKind() == VisitorJob::MemberRefVisitKind; |
1984 | 0 | } |
1985 | 18 | const FieldDecl *get() const { |
1986 | 18 | return static_cast<const FieldDecl *>(data[0]); |
1987 | 18 | } |
1988 | 18 | SourceLocation getLoc() const { |
1989 | 18 | return SourceLocation::getFromRawEncoding( |
1990 | 18 | (SourceLocation::UIntTy)(uintptr_t)data[1]); |
1991 | 18 | } |
1992 | | }; |
1993 | | class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> { |
1994 | | friend class OMPClauseEnqueue; |
1995 | | VisitorWorkList &WL; |
1996 | | CXCursor Parent; |
1997 | | |
1998 | | public: |
1999 | | EnqueueVisitor(VisitorWorkList &wl, CXCursor parent) |
2000 | 12.9k | : WL(wl), Parent(parent) {} |
2001 | | |
2002 | | void VisitAddrLabelExpr(const AddrLabelExpr *E); |
2003 | | void VisitBlockExpr(const BlockExpr *B); |
2004 | | void VisitCompoundLiteralExpr(const CompoundLiteralExpr *E); |
2005 | | void VisitCompoundStmt(const CompoundStmt *S); |
2006 | 0 | void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { /* Do nothing. */ |
2007 | 0 | } |
2008 | | void VisitMSDependentExistsStmt(const MSDependentExistsStmt *S); |
2009 | | void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E); |
2010 | | void VisitCXXNewExpr(const CXXNewExpr *E); |
2011 | | void VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E); |
2012 | | void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *E); |
2013 | | void VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E); |
2014 | | void VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E); |
2015 | | void VisitCXXTypeidExpr(const CXXTypeidExpr *E); |
2016 | | void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *E); |
2017 | | void VisitCXXUuidofExpr(const CXXUuidofExpr *E); |
2018 | | void VisitCXXCatchStmt(const CXXCatchStmt *S); |
2019 | | void VisitCXXForRangeStmt(const CXXForRangeStmt *S); |
2020 | | void VisitDeclRefExpr(const DeclRefExpr *D); |
2021 | | void VisitDeclStmt(const DeclStmt *S); |
2022 | | void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E); |
2023 | | void VisitDesignatedInitExpr(const DesignatedInitExpr *E); |
2024 | | void VisitExplicitCastExpr(const ExplicitCastExpr *E); |
2025 | | void VisitForStmt(const ForStmt *FS); |
2026 | | void VisitGotoStmt(const GotoStmt *GS); |
2027 | | void VisitIfStmt(const IfStmt *If); |
2028 | | void VisitInitListExpr(const InitListExpr *IE); |
2029 | | void VisitMemberExpr(const MemberExpr *M); |
2030 | | void VisitOffsetOfExpr(const OffsetOfExpr *E); |
2031 | | void VisitObjCEncodeExpr(const ObjCEncodeExpr *E); |
2032 | | void VisitObjCMessageExpr(const ObjCMessageExpr *M); |
2033 | | void VisitOverloadExpr(const OverloadExpr *E); |
2034 | | void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E); |
2035 | | void VisitStmt(const Stmt *S); |
2036 | | void VisitSwitchStmt(const SwitchStmt *S); |
2037 | | void VisitWhileStmt(const WhileStmt *W); |
2038 | | void VisitTypeTraitExpr(const TypeTraitExpr *E); |
2039 | | void VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E); |
2040 | | void VisitExpressionTraitExpr(const ExpressionTraitExpr *E); |
2041 | | void VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U); |
2042 | | void VisitVAArgExpr(const VAArgExpr *E); |
2043 | | void VisitSizeOfPackExpr(const SizeOfPackExpr *E); |
2044 | | void VisitPseudoObjectExpr(const PseudoObjectExpr *E); |
2045 | | void VisitOpaqueValueExpr(const OpaqueValueExpr *E); |
2046 | | void VisitLambdaExpr(const LambdaExpr *E); |
2047 | | void VisitOMPExecutableDirective(const OMPExecutableDirective *D); |
2048 | | void VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *D); |
2049 | | void VisitOMPLoopDirective(const OMPLoopDirective *D); |
2050 | | void VisitOMPParallelDirective(const OMPParallelDirective *D); |
2051 | | void VisitOMPSimdDirective(const OMPSimdDirective *D); |
2052 | | void |
2053 | | VisitOMPLoopTransformationDirective(const OMPLoopTransformationDirective *D); |
2054 | | void VisitOMPTileDirective(const OMPTileDirective *D); |
2055 | | void VisitOMPUnrollDirective(const OMPUnrollDirective *D); |
2056 | | void VisitOMPForDirective(const OMPForDirective *D); |
2057 | | void VisitOMPForSimdDirective(const OMPForSimdDirective *D); |
2058 | | void VisitOMPSectionsDirective(const OMPSectionsDirective *D); |
2059 | | void VisitOMPSectionDirective(const OMPSectionDirective *D); |
2060 | | void VisitOMPSingleDirective(const OMPSingleDirective *D); |
2061 | | void VisitOMPMasterDirective(const OMPMasterDirective *D); |
2062 | | void VisitOMPCriticalDirective(const OMPCriticalDirective *D); |
2063 | | void VisitOMPParallelForDirective(const OMPParallelForDirective *D); |
2064 | | void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D); |
2065 | | void VisitOMPParallelMasterDirective(const OMPParallelMasterDirective *D); |
2066 | | void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D); |
2067 | | void VisitOMPTaskDirective(const OMPTaskDirective *D); |
2068 | | void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D); |
2069 | | void VisitOMPBarrierDirective(const OMPBarrierDirective *D); |
2070 | | void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D); |
2071 | | void VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *D); |
2072 | | void |
2073 | | VisitOMPCancellationPointDirective(const OMPCancellationPointDirective *D); |
2074 | | void VisitOMPCancelDirective(const OMPCancelDirective *D); |
2075 | | void VisitOMPFlushDirective(const OMPFlushDirective *D); |
2076 | | void VisitOMPDepobjDirective(const OMPDepobjDirective *D); |
2077 | | void VisitOMPScanDirective(const OMPScanDirective *D); |
2078 | | void VisitOMPOrderedDirective(const OMPOrderedDirective *D); |
2079 | | void VisitOMPAtomicDirective(const OMPAtomicDirective *D); |
2080 | | void VisitOMPTargetDirective(const OMPTargetDirective *D); |
2081 | | void VisitOMPTargetDataDirective(const OMPTargetDataDirective *D); |
2082 | | void VisitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective *D); |
2083 | | void VisitOMPTargetExitDataDirective(const OMPTargetExitDataDirective *D); |
2084 | | void VisitOMPTargetParallelDirective(const OMPTargetParallelDirective *D); |
2085 | | void |
2086 | | VisitOMPTargetParallelForDirective(const OMPTargetParallelForDirective *D); |
2087 | | void VisitOMPTeamsDirective(const OMPTeamsDirective *D); |
2088 | | void VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D); |
2089 | | void VisitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective *D); |
2090 | | void VisitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective *D); |
2091 | | void |
2092 | | VisitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective *D); |
2093 | | void VisitOMPParallelMasterTaskLoopDirective( |
2094 | | const OMPParallelMasterTaskLoopDirective *D); |
2095 | | void VisitOMPParallelMasterTaskLoopSimdDirective( |
2096 | | const OMPParallelMasterTaskLoopSimdDirective *D); |
2097 | | void VisitOMPDistributeDirective(const OMPDistributeDirective *D); |
2098 | | void VisitOMPDistributeParallelForDirective( |
2099 | | const OMPDistributeParallelForDirective *D); |
2100 | | void VisitOMPDistributeParallelForSimdDirective( |
2101 | | const OMPDistributeParallelForSimdDirective *D); |
2102 | | void VisitOMPDistributeSimdDirective(const OMPDistributeSimdDirective *D); |
2103 | | void VisitOMPTargetParallelForSimdDirective( |
2104 | | const OMPTargetParallelForSimdDirective *D); |
2105 | | void VisitOMPTargetSimdDirective(const OMPTargetSimdDirective *D); |
2106 | | void VisitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective *D); |
2107 | | void VisitOMPTeamsDistributeSimdDirective( |
2108 | | const OMPTeamsDistributeSimdDirective *D); |
2109 | | void VisitOMPTeamsDistributeParallelForSimdDirective( |
2110 | | const OMPTeamsDistributeParallelForSimdDirective *D); |
2111 | | void VisitOMPTeamsDistributeParallelForDirective( |
2112 | | const OMPTeamsDistributeParallelForDirective *D); |
2113 | | void VisitOMPTargetTeamsDirective(const OMPTargetTeamsDirective *D); |
2114 | | void VisitOMPTargetTeamsDistributeDirective( |
2115 | | const OMPTargetTeamsDistributeDirective *D); |
2116 | | void VisitOMPTargetTeamsDistributeParallelForDirective( |
2117 | | const OMPTargetTeamsDistributeParallelForDirective *D); |
2118 | | void VisitOMPTargetTeamsDistributeParallelForSimdDirective( |
2119 | | const OMPTargetTeamsDistributeParallelForSimdDirective *D); |
2120 | | void VisitOMPTargetTeamsDistributeSimdDirective( |
2121 | | const OMPTargetTeamsDistributeSimdDirective *D); |
2122 | | |
2123 | | private: |
2124 | | void AddDeclarationNameInfo(const Stmt *S); |
2125 | | void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier); |
2126 | | void AddExplicitTemplateArgs(const TemplateArgumentLoc *A, |
2127 | | unsigned NumTemplateArgs); |
2128 | | void AddMemberRef(const FieldDecl *D, SourceLocation L); |
2129 | | void AddStmt(const Stmt *S); |
2130 | | void AddDecl(const Decl *D, bool isFirst = true); |
2131 | | void AddTypeLoc(TypeSourceInfo *TI); |
2132 | | void EnqueueChildren(const Stmt *S); |
2133 | | void EnqueueChildren(const OMPClause *S); |
2134 | | }; |
2135 | | } // namespace |
2136 | | |
2137 | 6 | void EnqueueVisitor::AddDeclarationNameInfo(const Stmt *S) { |
2138 | | // 'S' should always be non-null, since it comes from the |
2139 | | // statement we are visiting. |
2140 | 6 | WL.push_back(DeclarationNameInfoVisit(S, Parent)); |
2141 | 6 | } |
2142 | | |
2143 | | void EnqueueVisitor::AddNestedNameSpecifierLoc( |
2144 | 6 | NestedNameSpecifierLoc Qualifier) { |
2145 | 6 | if (Qualifier) |
2146 | 6 | WL.push_back(NestedNameSpecifierLocVisit(Qualifier, Parent)); |
2147 | 6 | } |
2148 | | |
2149 | 18.4k | void EnqueueVisitor::AddStmt(const Stmt *S) { |
2150 | 18.4k | if (S) |
2151 | 18.4k | WL.push_back(StmtVisit(S, Parent)); |
2152 | 18.4k | } |
2153 | 376 | void EnqueueVisitor::AddDecl(const Decl *D, bool isFirst) { |
2154 | 376 | if (D) |
2155 | 356 | WL.push_back(DeclVisit(D, Parent, isFirst)); |
2156 | 376 | } |
2157 | | void EnqueueVisitor::AddExplicitTemplateArgs(const TemplateArgumentLoc *A, |
2158 | 12 | unsigned NumTemplateArgs) { |
2159 | 12 | WL.push_back(ExplicitTemplateArgsVisit(A, A + NumTemplateArgs, Parent)); |
2160 | 12 | } |
2161 | 18 | void EnqueueVisitor::AddMemberRef(const FieldDecl *D, SourceLocation L) { |
2162 | 18 | if (D) |
2163 | 18 | WL.push_back(MemberRefVisit(D, L, Parent)); |
2164 | 18 | } |
2165 | 313 | void EnqueueVisitor::AddTypeLoc(TypeSourceInfo *TI) { |
2166 | 313 | if (TI) |
2167 | 186 | WL.push_back(TypeLocVisit(TI->getTypeLoc(), Parent)); |
2168 | 313 | } |
2169 | 5.07k | void EnqueueVisitor::EnqueueChildren(const Stmt *S) { |
2170 | 5.07k | unsigned size = WL.size(); |
2171 | 5.66k | for (const Stmt *SubStmt : S->children()) { |
2172 | 5.66k | AddStmt(SubStmt); |
2173 | 5.66k | } |
2174 | 5.07k | if (size == WL.size()) |
2175 | 993 | return; |
2176 | | // Now reverse the entries we just added. This will match the DFS |
2177 | | // ordering performed by the worklist. |
2178 | 4.08k | VisitorWorkList::iterator I = WL.begin() + size, E = WL.end(); |
2179 | 4.08k | std::reverse(I, E); |
2180 | 4.08k | } |
2181 | | namespace { |
2182 | | class OMPClauseEnqueue : public ConstOMPClauseVisitor<OMPClauseEnqueue> { |
2183 | | EnqueueVisitor *Visitor; |
2184 | | /// Process clauses with list of variables. |
2185 | | template <typename T> void VisitOMPClauseList(T *Node); |
2186 | | |
2187 | | public: |
2188 | 1 | OMPClauseEnqueue(EnqueueVisitor *Visitor) : Visitor(Visitor) {} |
2189 | | #define GEN_CLANG_CLAUSE_CLASS |
2190 | | #define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C); |
2191 | | #include "llvm/Frontend/OpenMP/OMP.inc" |
2192 | | void VisitOMPClauseWithPreInit(const OMPClauseWithPreInit *C); |
2193 | | void VisitOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C); |
2194 | | }; |
2195 | | |
2196 | | void OMPClauseEnqueue::VisitOMPClauseWithPreInit( |
2197 | 0 | const OMPClauseWithPreInit *C) { |
2198 | 0 | Visitor->AddStmt(C->getPreInitStmt()); |
2199 | 0 | } |
2200 | | |
2201 | | void OMPClauseEnqueue::VisitOMPClauseWithPostUpdate( |
2202 | 0 | const OMPClauseWithPostUpdate *C) { |
2203 | 0 | VisitOMPClauseWithPreInit(C); |
2204 | 0 | Visitor->AddStmt(C->getPostUpdateExpr()); |
2205 | 0 | } |
2206 | | |
2207 | 0 | void OMPClauseEnqueue::VisitOMPIfClause(const OMPIfClause *C) { |
2208 | 0 | VisitOMPClauseWithPreInit(C); |
2209 | 0 | Visitor->AddStmt(C->getCondition()); |
2210 | 0 | } |
2211 | | |
2212 | 0 | void OMPClauseEnqueue::VisitOMPFinalClause(const OMPFinalClause *C) { |
2213 | 0 | Visitor->AddStmt(C->getCondition()); |
2214 | 0 | } |
2215 | | |
2216 | 0 | void OMPClauseEnqueue::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) { |
2217 | 0 | VisitOMPClauseWithPreInit(C); |
2218 | 0 | Visitor->AddStmt(C->getNumThreads()); |
2219 | 0 | } |
2220 | | |
2221 | 0 | void OMPClauseEnqueue::VisitOMPSafelenClause(const OMPSafelenClause *C) { |
2222 | 0 | Visitor->AddStmt(C->getSafelen()); |
2223 | 0 | } |
2224 | | |
2225 | 0 | void OMPClauseEnqueue::VisitOMPSimdlenClause(const OMPSimdlenClause *C) { |
2226 | 0 | Visitor->AddStmt(C->getSimdlen()); |
2227 | 0 | } |
2228 | | |
2229 | 1 | void OMPClauseEnqueue::VisitOMPSizesClause(const OMPSizesClause *C) { |
2230 | 1 | for (auto E : C->getSizesRefs()) |
2231 | 1 | Visitor->AddStmt(E); |
2232 | 1 | } |
2233 | | |
2234 | 0 | void OMPClauseEnqueue::VisitOMPFullClause(const OMPFullClause *C) {} |
2235 | | |
2236 | 0 | void OMPClauseEnqueue::VisitOMPPartialClause(const OMPPartialClause *C) { |
2237 | 0 | Visitor->AddStmt(C->getFactor()); |
2238 | 0 | } |
2239 | | |
2240 | 0 | void OMPClauseEnqueue::VisitOMPAllocatorClause(const OMPAllocatorClause *C) { |
2241 | 0 | Visitor->AddStmt(C->getAllocator()); |
2242 | 0 | } |
2243 | | |
2244 | 0 | void OMPClauseEnqueue::VisitOMPCollapseClause(const OMPCollapseClause *C) { |
2245 | 0 | Visitor->AddStmt(C->getNumForLoops()); |
2246 | 0 | } |
2247 | | |
2248 | 0 | void OMPClauseEnqueue::VisitOMPDefaultClause(const OMPDefaultClause *C) {} |
2249 | | |
2250 | 0 | void OMPClauseEnqueue::VisitOMPProcBindClause(const OMPProcBindClause *C) {} |
2251 | | |
2252 | 0 | void OMPClauseEnqueue::VisitOMPScheduleClause(const OMPScheduleClause *C) { |
2253 | 0 | VisitOMPClauseWithPreInit(C); |
2254 | 0 | Visitor->AddStmt(C->getChunkSize()); |
2255 | 0 | } |
2256 | | |
2257 | 0 | void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *C) { |
2258 | 0 | Visitor->AddStmt(C->getNumForLoops()); |
2259 | 0 | } |
2260 | | |
2261 | 0 | void OMPClauseEnqueue::VisitOMPDetachClause(const OMPDetachClause *C) { |
2262 | 0 | Visitor->AddStmt(C->getEventHandler()); |
2263 | 0 | } |
2264 | | |
2265 | 0 | void OMPClauseEnqueue::VisitOMPNowaitClause(const OMPNowaitClause *) {} |
2266 | | |
2267 | 0 | void OMPClauseEnqueue::VisitOMPUntiedClause(const OMPUntiedClause *) {} |
2268 | | |
2269 | 0 | void OMPClauseEnqueue::VisitOMPMergeableClause(const OMPMergeableClause *) {} |
2270 | | |
2271 | 0 | void OMPClauseEnqueue::VisitOMPReadClause(const OMPReadClause *) {} |
2272 | | |
2273 | 0 | void OMPClauseEnqueue::VisitOMPWriteClause(const OMPWriteClause *) {} |
2274 | | |
2275 | 0 | void OMPClauseEnqueue::VisitOMPUpdateClause(const OMPUpdateClause *) {} |
2276 | | |
2277 | 0 | void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {} |
2278 | | |
2279 | 0 | void OMPClauseEnqueue::VisitOMPCompareClause(const OMPCompareClause *) {} |
2280 | | |
2281 | 0 | void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {} |
2282 | | |
2283 | 0 | void OMPClauseEnqueue::VisitOMPAcqRelClause(const OMPAcqRelClause *) {} |
2284 | | |
2285 | 0 | void OMPClauseEnqueue::VisitOMPAcquireClause(const OMPAcquireClause *) {} |
2286 | | |
2287 | 0 | void OMPClauseEnqueue::VisitOMPReleaseClause(const OMPReleaseClause *) {} |
2288 | | |
2289 | 0 | void OMPClauseEnqueue::VisitOMPRelaxedClause(const OMPRelaxedClause *) {} |
2290 | | |
2291 | 0 | void OMPClauseEnqueue::VisitOMPThreadsClause(const OMPThreadsClause *) {} |
2292 | | |
2293 | 0 | void OMPClauseEnqueue::VisitOMPSIMDClause(const OMPSIMDClause *) {} |
2294 | | |
2295 | 0 | void OMPClauseEnqueue::VisitOMPNogroupClause(const OMPNogroupClause *) {} |
2296 | | |
2297 | 0 | void OMPClauseEnqueue::VisitOMPInitClause(const OMPInitClause *C) { |
2298 | 0 | VisitOMPClauseList(C); |
2299 | 0 | } |
2300 | | |
2301 | 0 | void OMPClauseEnqueue::VisitOMPUseClause(const OMPUseClause *C) { |
2302 | 0 | Visitor->AddStmt(C->getInteropVar()); |
2303 | 0 | } |
2304 | | |
2305 | 0 | void OMPClauseEnqueue::VisitOMPDestroyClause(const OMPDestroyClause *C) { |
2306 | 0 | if (C->getInteropVar()) |
2307 | 0 | Visitor->AddStmt(C->getInteropVar()); |
2308 | 0 | } |
2309 | | |
2310 | 0 | void OMPClauseEnqueue::VisitOMPNovariantsClause(const OMPNovariantsClause *C) { |
2311 | 0 | Visitor->AddStmt(C->getCondition()); |
2312 | 0 | } |
2313 | | |
2314 | 0 | void OMPClauseEnqueue::VisitOMPNocontextClause(const OMPNocontextClause *C) { |
2315 | 0 | Visitor->AddStmt(C->getCondition()); |
2316 | 0 | } |
2317 | | |
2318 | 0 | void OMPClauseEnqueue::VisitOMPFilterClause(const OMPFilterClause *C) { |
2319 | 0 | VisitOMPClauseWithPreInit(C); |
2320 | 0 | Visitor->AddStmt(C->getThreadID()); |
2321 | 0 | } |
2322 | | |
2323 | 0 | void OMPClauseEnqueue::VisitOMPAlignClause(const OMPAlignClause *C) { |
2324 | 0 | Visitor->AddStmt(C->getAlignment()); |
2325 | 0 | } |
2326 | | |
2327 | | void OMPClauseEnqueue::VisitOMPUnifiedAddressClause( |
2328 | 0 | const OMPUnifiedAddressClause *) {} |
2329 | | |
2330 | | void OMPClauseEnqueue::VisitOMPUnifiedSharedMemoryClause( |
2331 | 0 | const OMPUnifiedSharedMemoryClause *) {} |
2332 | | |
2333 | | void OMPClauseEnqueue::VisitOMPReverseOffloadClause( |
2334 | 0 | const OMPReverseOffloadClause *) {} |
2335 | | |
2336 | | void OMPClauseEnqueue::VisitOMPDynamicAllocatorsClause( |
2337 | 0 | const OMPDynamicAllocatorsClause *) {} |
2338 | | |
2339 | | void OMPClauseEnqueue::VisitOMPAtomicDefaultMemOrderClause( |
2340 | 0 | const OMPAtomicDefaultMemOrderClause *) {} |
2341 | | |
2342 | 0 | void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) { |
2343 | 0 | Visitor->AddStmt(C->getDevice()); |
2344 | 0 | } |
2345 | | |
2346 | 0 | void OMPClauseEnqueue::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) { |
2347 | 0 | VisitOMPClauseWithPreInit(C); |
2348 | 0 | Visitor->AddStmt(C->getNumTeams()); |
2349 | 0 | } |
2350 | | |
2351 | | void OMPClauseEnqueue::VisitOMPThreadLimitClause( |
2352 | 0 | const OMPThreadLimitClause *C) { |
2353 | 0 | VisitOMPClauseWithPreInit(C); |
2354 | 0 | Visitor->AddStmt(C->getThreadLimit()); |
2355 | 0 | } |
2356 | | |
2357 | 0 | void OMPClauseEnqueue::VisitOMPPriorityClause(const OMPPriorityClause *C) { |
2358 | 0 | Visitor->AddStmt(C->getPriority()); |
2359 | 0 | } |
2360 | | |
2361 | 0 | void OMPClauseEnqueue::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) { |
2362 | 0 | Visitor->AddStmt(C->getGrainsize()); |
2363 | 0 | } |
2364 | | |
2365 | 0 | void OMPClauseEnqueue::VisitOMPNumTasksClause(const OMPNumTasksClause *C) { |
2366 | 0 | Visitor->AddStmt(C->getNumTasks()); |
2367 | 0 | } |
2368 | | |
2369 | 0 | void OMPClauseEnqueue::VisitOMPHintClause(const OMPHintClause *C) { |
2370 | 0 | Visitor->AddStmt(C->getHint()); |
2371 | 0 | } |
2372 | | |
2373 | 0 | template <typename T> void OMPClauseEnqueue::VisitOMPClauseList(T *Node) { |
2374 | 0 | for (const auto *I : Node->varlists()) { |
2375 | 0 | Visitor->AddStmt(I); |
2376 | 0 | } |
2377 | 0 | } Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPAlignedClause const>(clang::OMPAlignedClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPAllocateClause const>(clang::OMPAllocateClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPCopyprivateClause const>(clang::OMPCopyprivateClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPCopyinClause const>(clang::OMPCopyinClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPDependClause const>(clang::OMPDependClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPExclusiveClause const>(clang::OMPExclusiveClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPFirstprivateClause const>(clang::OMPFirstprivateClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPFlushClause const>(clang::OMPFlushClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPFromClause const>(clang::OMPFromClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPHasDeviceAddrClause const>(clang::OMPHasDeviceAddrClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPInReductionClause const>(clang::OMPInReductionClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPInclusiveClause const>(clang::OMPInclusiveClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPInitClause const>(clang::OMPInitClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPIsDevicePtrClause const>(clang::OMPIsDevicePtrClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPLastprivateClause const>(clang::OMPLastprivateClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPLinearClause const>(clang::OMPLinearClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPMapClause const>(clang::OMPMapClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPNontemporalClause const>(clang::OMPNontemporalClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPPrivateClause const>(clang::OMPPrivateClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPReductionClause const>(clang::OMPReductionClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPSharedClause const>(clang::OMPSharedClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPTaskReductionClause const>(clang::OMPTaskReductionClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPToClause const>(clang::OMPToClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPUseDeviceAddrClause const>(clang::OMPUseDeviceAddrClause const*) Unexecuted instantiation: CIndex.cpp:void (anonymous namespace)::OMPClauseEnqueue::VisitOMPClauseList<clang::OMPUseDevicePtrClause const>(clang::OMPUseDevicePtrClause const*) |
2378 | | |
2379 | 0 | void OMPClauseEnqueue::VisitOMPInclusiveClause(const OMPInclusiveClause *C) { |
2380 | 0 | VisitOMPClauseList(C); |
2381 | 0 | } |
2382 | 0 | void OMPClauseEnqueue::VisitOMPExclusiveClause(const OMPExclusiveClause *C) { |
2383 | 0 | VisitOMPClauseList(C); |
2384 | 0 | } |
2385 | 0 | void OMPClauseEnqueue::VisitOMPAllocateClause(const OMPAllocateClause *C) { |
2386 | 0 | VisitOMPClauseList(C); |
2387 | 0 | Visitor->AddStmt(C->getAllocator()); |
2388 | 0 | } |
2389 | 0 | void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) { |
2390 | 0 | VisitOMPClauseList(C); |
2391 | 0 | for (const auto *E : C->private_copies()) { |
2392 | 0 | Visitor->AddStmt(E); |
2393 | 0 | } |
2394 | 0 | } |
2395 | | void OMPClauseEnqueue::VisitOMPFirstprivateClause( |
2396 | 0 | const OMPFirstprivateClause *C) { |
2397 | 0 | VisitOMPClauseList(C); |
2398 | 0 | VisitOMPClauseWithPreInit(C); |
2399 | 0 | for (const auto *E : C->private_copies()) { |
2400 | 0 | Visitor->AddStmt(E); |
2401 | 0 | } |
2402 | 0 | for (const auto *E : C->inits()) { |
2403 | 0 | Visitor->AddStmt(E); |
2404 | 0 | } |
2405 | 0 | } |
2406 | | void OMPClauseEnqueue::VisitOMPLastprivateClause( |
2407 | 0 | const OMPLastprivateClause *C) { |
2408 | 0 | VisitOMPClauseList(C); |
2409 | 0 | VisitOMPClauseWithPostUpdate(C); |
2410 | 0 | for (auto *E : C->private_copies()) { |
2411 | 0 | Visitor->AddStmt(E); |
2412 | 0 | } |
2413 | 0 | for (auto *E : C->source_exprs()) { |
2414 | 0 | Visitor->AddStmt(E); |
2415 | 0 | } |
2416 | 0 | for (auto *E : C->destination_exprs()) { |
2417 | 0 | Visitor->AddStmt(E); |
2418 | 0 | } |
2419 | 0 | for (auto *E : C->assignment_ops()) { |
2420 | 0 | Visitor->AddStmt(E); |
2421 | 0 | } |
2422 | 0 | } |
2423 | 0 | void OMPClauseEnqueue::VisitOMPSharedClause(const OMPSharedClause *C) { |
2424 | 0 | VisitOMPClauseList(C); |
2425 | 0 | } |
2426 | 0 | void OMPClauseEnqueue::VisitOMPReductionClause(const OMPReductionClause *C) { |
2427 | 0 | VisitOMPClauseList(C); |
2428 | 0 | VisitOMPClauseWithPostUpdate(C); |
2429 | 0 | for (auto *E : C->privates()) { |
2430 | 0 | Visitor->AddStmt(E); |
2431 | 0 | } |
2432 | 0 | for (auto *E : C->lhs_exprs()) { |
2433 | 0 | Visitor->AddStmt(E); |
2434 | 0 | } |
2435 | 0 | for (auto *E : C->rhs_exprs()) { |
2436 | 0 | Visitor->AddStmt(E); |
2437 | 0 | } |
2438 | 0 | for (auto *E : C->reduction_ops()) { |
2439 | 0 | Visitor->AddStmt(E); |
2440 | 0 | } |
2441 | 0 | if (C->getModifier() == clang::OMPC_REDUCTION_inscan) { |
2442 | 0 | for (auto *E : C->copy_ops()) { |
2443 | 0 | Visitor->AddStmt(E); |
2444 | 0 | } |
2445 | 0 | for (auto *E : C->copy_array_temps()) { |
2446 | 0 | Visitor->AddStmt(E); |
2447 | 0 | } |
2448 | 0 | for (auto *E : C->copy_array_elems()) { |
2449 | 0 | Visitor->AddStmt(E); |
2450 | 0 | } |
2451 | 0 | } |
2452 | 0 | } |
2453 | | void OMPClauseEnqueue::VisitOMPTaskReductionClause( |
2454 | 0 | const OMPTaskReductionClause *C) { |
2455 | 0 | VisitOMPClauseList(C); |
2456 | 0 | VisitOMPClauseWithPostUpdate(C); |
2457 | 0 | for (auto *E : C->privates()) { |
2458 | 0 | Visitor->AddStmt(E); |
2459 | 0 | } |
2460 | 0 | for (auto *E : C->lhs_exprs()) { |
2461 | 0 | Visitor->AddStmt(E); |
2462 | 0 | } |
2463 | 0 | for (auto *E : C->rhs_exprs()) { |
2464 | 0 | Visitor->AddStmt(E); |
2465 | 0 | } |
2466 | 0 | for (auto *E : C->reduction_ops()) { |
2467 | 0 | Visitor->AddStmt(E); |
2468 | 0 | } |
2469 | 0 | } |
2470 | | void OMPClauseEnqueue::VisitOMPInReductionClause( |
2471 | 0 | const OMPInReductionClause *C) { |
2472 | 0 | VisitOMPClauseList(C); |
2473 | 0 | VisitOMPClauseWithPostUpdate(C); |
2474 | 0 | for (auto *E : C->privates()) { |
2475 | 0 | Visitor->AddStmt(E); |
2476 | 0 | } |
2477 | 0 | for (auto *E : C->lhs_exprs()) { |
2478 | 0 | Visitor->AddStmt(E); |
2479 | 0 | } |
2480 | 0 | for (auto *E : C->rhs_exprs()) { |
2481 | 0 | Visitor->AddStmt(E); |
2482 | 0 | } |
2483 | 0 | for (auto *E : C->reduction_ops()) { |
2484 | 0 | Visitor->AddStmt(E); |
2485 | 0 | } |
2486 | 0 | for (auto *E : C->taskgroup_descriptors()) |
2487 | 0 | Visitor->AddStmt(E); |
2488 | 0 | } |
2489 | 0 | void OMPClauseEnqueue::VisitOMPLinearClause(const OMPLinearClause *C) { |
2490 | 0 | VisitOMPClauseList(C); |
2491 | 0 | VisitOMPClauseWithPostUpdate(C); |
2492 | 0 | for (const auto *E : C->privates()) { |
2493 | 0 | Visitor->AddStmt(E); |
2494 | 0 | } |
2495 | 0 | for (const auto *E : C->inits()) { |
2496 | 0 | Visitor->AddStmt(E); |
2497 | 0 | } |
2498 | 0 | for (const auto *E : C->updates()) { |
2499 | 0 | Visitor->AddStmt(E); |
2500 | 0 | } |
2501 | 0 | for (const auto *E : C->finals()) { |
2502 | 0 | Visitor->AddStmt(E); |
2503 | 0 | } |
2504 | 0 | Visitor->AddStmt(C->getStep()); |
2505 | 0 | Visitor->AddStmt(C->getCalcStep()); |
2506 | 0 | } |
2507 | 0 | void OMPClauseEnqueue::VisitOMPAlignedClause(const OMPAlignedClause *C) { |
2508 | 0 | VisitOMPClauseList(C); |
2509 | 0 | Visitor->AddStmt(C->getAlignment()); |
2510 | 0 | } |
2511 | 0 | void OMPClauseEnqueue::VisitOMPCopyinClause(const OMPCopyinClause *C) { |
2512 | 0 | VisitOMPClauseList(C); |
2513 | 0 | for (auto *E : C->source_exprs()) { |
2514 | 0 | Visitor->AddStmt(E); |
2515 | 0 | } |
2516 | 0 | for (auto *E : C->destination_exprs()) { |
2517 | 0 | Visitor->AddStmt(E); |
2518 | 0 | } |
2519 | 0 | for (auto *E : C->assignment_ops()) { |
2520 | 0 | Visitor->AddStmt(E); |
2521 | 0 | } |
2522 | 0 | } |
2523 | | void OMPClauseEnqueue::VisitOMPCopyprivateClause( |
2524 | 0 | const OMPCopyprivateClause *C) { |
2525 | 0 | VisitOMPClauseList(C); |
2526 | 0 | for (auto *E : C->source_exprs()) { |
2527 | 0 | Visitor->AddStmt(E); |
2528 | 0 | } |
2529 | 0 | for (auto *E : C->destination_exprs()) { |
2530 | 0 | Visitor->AddStmt(E); |
2531 | 0 | } |
2532 | 0 | for (auto *E : C->assignment_ops()) { |
2533 | 0 | Visitor->AddStmt(E); |
2534 | 0 | } |
2535 | 0 | } |
2536 | 0 | void OMPClauseEnqueue::VisitOMPFlushClause(const OMPFlushClause *C) { |
2537 | 0 | VisitOMPClauseList(C); |
2538 | 0 | } |
2539 | 0 | void OMPClauseEnqueue::VisitOMPDepobjClause(const OMPDepobjClause *C) { |
2540 | 0 | Visitor->AddStmt(C->getDepobj()); |
2541 | 0 | } |
2542 | 0 | void OMPClauseEnqueue::VisitOMPDependClause(const OMPDependClause *C) { |
2543 | 0 | VisitOMPClauseList(C); |
2544 | 0 | } |
2545 | 0 | void OMPClauseEnqueue::VisitOMPMapClause(const OMPMapClause *C) { |
2546 | 0 | VisitOMPClauseList(C); |
2547 | 0 | } |
2548 | | void OMPClauseEnqueue::VisitOMPDistScheduleClause( |
2549 | 0 | const OMPDistScheduleClause *C) { |
2550 | 0 | VisitOMPClauseWithPreInit(C); |
2551 | 0 | Visitor->AddStmt(C->getChunkSize()); |
2552 | 0 | } |
2553 | | void OMPClauseEnqueue::VisitOMPDefaultmapClause( |
2554 | 0 | const OMPDefaultmapClause * /*C*/) {} |
2555 | 0 | void OMPClauseEnqueue::VisitOMPToClause(const OMPToClause *C) { |
2556 | 0 | VisitOMPClauseList(C); |
2557 | 0 | } |
2558 | 0 | void OMPClauseEnqueue::VisitOMPFromClause(const OMPFromClause *C) { |
2559 | 0 | VisitOMPClauseList(C); |
2560 | 0 | } |
2561 | | void OMPClauseEnqueue::VisitOMPUseDevicePtrClause( |
2562 | 0 | const OMPUseDevicePtrClause *C) { |
2563 | 0 | VisitOMPClauseList(C); |
2564 | 0 | } |
2565 | | void OMPClauseEnqueue::VisitOMPUseDeviceAddrClause( |
2566 | 0 | const OMPUseDeviceAddrClause *C) { |
2567 | 0 | VisitOMPClauseList(C); |
2568 | 0 | } |
2569 | | void OMPClauseEnqueue::VisitOMPIsDevicePtrClause( |
2570 | 0 | const OMPIsDevicePtrClause *C) { |
2571 | 0 | VisitOMPClauseList(C); |
2572 | 0 | } |
2573 | | void OMPClauseEnqueue::VisitOMPHasDeviceAddrClause( |
2574 | 0 | const OMPHasDeviceAddrClause *C) { |
2575 | 0 | VisitOMPClauseList(C); |
2576 | 0 | } |
2577 | | void OMPClauseEnqueue::VisitOMPNontemporalClause( |
2578 | 0 | const OMPNontemporalClause *C) { |
2579 | 0 | VisitOMPClauseList(C); |
2580 | 0 | for (const auto *E : C->private_refs()) |
2581 | 0 | Visitor->AddStmt(E); |
2582 | 0 | } |
2583 | 0 | void OMPClauseEnqueue::VisitOMPOrderClause(const OMPOrderClause *C) {} |
2584 | | void OMPClauseEnqueue::VisitOMPUsesAllocatorsClause( |
2585 | 0 | const OMPUsesAllocatorsClause *C) { |
2586 | 0 | for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) { |
2587 | 0 | const OMPUsesAllocatorsClause::Data &D = C->getAllocatorData(I); |
2588 | 0 | Visitor->AddStmt(D.Allocator); |
2589 | 0 | Visitor->AddStmt(D.AllocatorTraits); |
2590 | 0 | } |
2591 | 0 | } |
2592 | 0 | void OMPClauseEnqueue::VisitOMPAffinityClause(const OMPAffinityClause *C) { |
2593 | 0 | Visitor->AddStmt(C->getModifier()); |
2594 | 0 | for (const Expr *E : C->varlists()) |
2595 | 0 | Visitor->AddStmt(E); |
2596 | 0 | } |
2597 | 0 | void OMPClauseEnqueue::VisitOMPBindClause(const OMPBindClause *C) {} |
2598 | | |
2599 | | } // namespace |
2600 | | |
2601 | 1 | void EnqueueVisitor::EnqueueChildren(const OMPClause *S) { |
2602 | 1 | unsigned size = WL.size(); |
2603 | 1 | OMPClauseEnqueue Visitor(this); |
2604 | 1 | Visitor.Visit(S); |
2605 | 1 | if (size == WL.size()) |
2606 | 0 | return; |
2607 | | // Now reverse the entries we just added. This will match the DFS |
2608 | | // ordering performed by the worklist. |
2609 | 1 | VisitorWorkList::iterator I = WL.begin() + size, E = WL.end(); |
2610 | 1 | std::reverse(I, E); |
2611 | 1 | } |
2612 | 1 | void EnqueueVisitor::VisitAddrLabelExpr(const AddrLabelExpr *E) { |
2613 | 1 | WL.push_back(LabelRefVisit(E->getLabel(), E->getLabelLoc(), Parent)); |
2614 | 1 | } |
2615 | 6 | void EnqueueVisitor::VisitBlockExpr(const BlockExpr *B) { |
2616 | 6 | AddDecl(B->getBlockDecl()); |
2617 | 6 | } |
2618 | 4 | void EnqueueVisitor::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) { |
2619 | 4 | EnqueueChildren(E); |
2620 | 4 | AddTypeLoc(E->getTypeSourceInfo()); |
2621 | 4 | } |
2622 | 804 | void EnqueueVisitor::VisitCompoundStmt(const CompoundStmt *S) { |
2623 | 804 | for (auto &I : llvm::reverse(S->body())) |
2624 | 2.32k | AddStmt(I); |
2625 | 804 | } |
2626 | | void EnqueueVisitor::VisitMSDependentExistsStmt( |
2627 | 2 | const MSDependentExistsStmt *S) { |
2628 | 2 | AddStmt(S->getSubStmt()); |
2629 | 2 | AddDeclarationNameInfo(S); |
2630 | 2 | if (NestedNameSpecifierLoc QualifierLoc = S->getQualifierLoc()) |
2631 | 2 | AddNestedNameSpecifierLoc(QualifierLoc); |
2632 | 2 | } |
2633 | | |
2634 | | void EnqueueVisitor::VisitCXXDependentScopeMemberExpr( |
2635 | 3 | const CXXDependentScopeMemberExpr *E) { |
2636 | 3 | if (E->hasExplicitTemplateArgs()) |
2637 | 1 | AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs()); |
2638 | 3 | AddDeclarationNameInfo(E); |
2639 | 3 | if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc()) |
2640 | 2 | AddNestedNameSpecifierLoc(QualifierLoc); |
2641 | 3 | if (!E->isImplicitAccess()) |
2642 | 3 | AddStmt(E->getBase()); |
2643 | 3 | } |
2644 | 5 | void EnqueueVisitor::VisitCXXNewExpr(const CXXNewExpr *E) { |
2645 | | // Enqueue the initializer , if any. |
2646 | 5 | AddStmt(E->getInitializer()); |
2647 | | // Enqueue the array size, if any. |
2648 | 5 | AddStmt(E->getArraySize().getValueOr(nullptr)); |
2649 | | // Enqueue the allocated type. |
2650 | 5 | AddTypeLoc(E->getAllocatedTypeSourceInfo()); |
2651 | | // Enqueue the placement arguments. |
2652 | 6 | for (unsigned I = E->getNumPlacementArgs(); I > 0; --I1 ) |
2653 | 1 | AddStmt(E->getPlacementArg(I - 1)); |
2654 | 5 | } |
2655 | 4.89k | void EnqueueVisitor::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *CE) { |
2656 | 4.92k | for (unsigned I = CE->getNumArgs(); I > 1 /* Yes, this is 1 */; --I31 ) |
2657 | 31 | AddStmt(CE->getArg(I - 1)); |
2658 | 4.89k | AddStmt(CE->getCallee()); |
2659 | 4.89k | AddStmt(CE->getArg(0)); |
2660 | 4.89k | } |
2661 | | void EnqueueVisitor::VisitCXXPseudoDestructorExpr( |
2662 | 2 | const CXXPseudoDestructorExpr *E) { |
2663 | | // Visit the name of the type being destroyed. |
2664 | 2 | AddTypeLoc(E->getDestroyedTypeInfo()); |
2665 | | // Visit the scope type that looks disturbingly like the nested-name-specifier |
2666 | | // but isn't. |
2667 | 2 | AddTypeLoc(E->getScopeTypeInfo()); |
2668 | | // Visit the nested-name-specifier. |
2669 | 2 | if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc()) |
2670 | 1 | AddNestedNameSpecifierLoc(QualifierLoc); |
2671 | | // Visit base expression. |
2672 | 2 | AddStmt(E->getBase()); |
2673 | 2 | } |
2674 | | void EnqueueVisitor::VisitCXXScalarValueInitExpr( |
2675 | 2 | const CXXScalarValueInitExpr *E) { |
2676 | 2 | AddTypeLoc(E->getTypeSourceInfo()); |
2677 | 2 | } |
2678 | | void EnqueueVisitor::VisitCXXTemporaryObjectExpr( |
2679 | 39 | const CXXTemporaryObjectExpr *E) { |
2680 | 39 | EnqueueChildren(E); |
2681 | 39 | AddTypeLoc(E->getTypeSourceInfo()); |
2682 | 39 | } |
2683 | 2 | void EnqueueVisitor::VisitCXXTypeidExpr(const CXXTypeidExpr *E) { |
2684 | 2 | EnqueueChildren(E); |
2685 | 2 | if (E->isTypeOperand()) |
2686 | 1 | AddTypeLoc(E->getTypeOperandSourceInfo()); |
2687 | 2 | } |
2688 | | |
2689 | | void EnqueueVisitor::VisitCXXUnresolvedConstructExpr( |
2690 | 6 | const CXXUnresolvedConstructExpr *E) { |
2691 | 6 | EnqueueChildren(E); |
2692 | 6 | AddTypeLoc(E->getTypeSourceInfo()); |
2693 | 6 | } |
2694 | 0 | void EnqueueVisitor::VisitCXXUuidofExpr(const CXXUuidofExpr *E) { |
2695 | 0 | EnqueueChildren(E); |
2696 | 0 | if (E->isTypeOperand()) |
2697 | 0 | AddTypeLoc(E->getTypeOperandSourceInfo()); |
2698 | 0 | } |
2699 | | |
2700 | 4 | void EnqueueVisitor::VisitCXXCatchStmt(const CXXCatchStmt *S) { |
2701 | 4 | EnqueueChildren(S); |
2702 | 4 | AddDecl(S->getExceptionDecl()); |
2703 | 4 | } |
2704 | | |
2705 | 4 | void EnqueueVisitor::VisitCXXForRangeStmt(const CXXForRangeStmt *S) { |
2706 | 4 | AddStmt(S->getBody()); |
2707 | 4 | AddStmt(S->getRangeInit()); |
2708 | 4 | AddDecl(S->getLoopVariable()); |
2709 | 4 | } |
2710 | | |
2711 | 1.20k | void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) { |
2712 | 1.20k | if (DR->hasExplicitTemplateArgs()) |
2713 | 6 | AddExplicitTemplateArgs(DR->getTemplateArgs(), DR->getNumTemplateArgs()); |
2714 | 1.20k | WL.push_back(DeclRefExprParts(DR, Parent)); |
2715 | 1.20k | } |
2716 | | void EnqueueVisitor::VisitDependentScopeDeclRefExpr( |
2717 | 1 | const DependentScopeDeclRefExpr *E) { |
2718 | 1 | if (E->hasExplicitTemplateArgs()) |
2719 | 1 | AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs()); |
2720 | 1 | AddDeclarationNameInfo(E); |
2721 | 1 | AddNestedNameSpecifierLoc(E->getQualifierLoc()); |
2722 | 1 | } |
2723 | 324 | void EnqueueVisitor::VisitDeclStmt(const DeclStmt *S) { |
2724 | 324 | unsigned size = WL.size(); |
2725 | 324 | bool isFirst = true; |
2726 | 336 | for (const auto *D : S->decls()) { |
2727 | 336 | AddDecl(D, isFirst); |
2728 | 336 | isFirst = false; |
2729 | 336 | } |
2730 | 324 | if (size == WL.size()) |
2731 | 0 | return; |
2732 | | // Now reverse the entries we just added. This will match the DFS |
2733 | | // ordering performed by the worklist. |
2734 | 324 | VisitorWorkList::iterator I = WL.begin() + size, E = WL.end(); |
2735 | 324 | std::reverse(I, E); |
2736 | 324 | } |
2737 | 14 | void EnqueueVisitor::VisitDesignatedInitExpr(const DesignatedInitExpr *E) { |
2738 | 14 | AddStmt(E->getInit()); |
2739 | 14 | for (const DesignatedInitExpr::Designator &D : |
2740 | 18 | llvm::reverse(E->designators())) { |
2741 | 18 | if (D.isFieldDesignator()) { |
2742 | 16 | if (FieldDecl *Field = D.getField()) |
2743 | 16 | AddMemberRef(Field, D.getFieldLoc()); |
2744 | 16 | continue; |
2745 | 16 | } |
2746 | 2 | if (D.isArrayDesignator()) { |
2747 | 2 | AddStmt(E->getArrayIndex(D)); |
2748 | 2 | continue; |
2749 | 2 | } |
2750 | 0 | assert(D.isArrayRangeDesignator() && "Unknown designator kind"); |
2751 | 0 | AddStmt(E->getArrayRangeEnd(D)); |
2752 | 0 | AddStmt(E->getArrayRangeStart(D)); |
2753 | 0 | } |
2754 | 14 | } |
2755 | 75 | void EnqueueVisitor::VisitExplicitCastExpr(const ExplicitCastExpr *E) { |
2756 | 75 | EnqueueChildren(E); |
2757 | 75 | AddTypeLoc(E->getTypeInfoAsWritten()); |
2758 | 75 | } |
2759 | 2 | void EnqueueVisitor::VisitForStmt(const ForStmt *FS) { |
2760 | 2 | AddStmt(FS->getBody()); |
2761 | 2 | AddStmt(FS->getInc()); |
2762 | 2 | AddStmt(FS->getCond()); |
2763 | 2 | AddDecl(FS->getConditionVariable()); |
2764 | 2 | AddStmt(FS->getInit()); |
2765 | 2 | } |
2766 | 2 | void EnqueueVisitor::VisitGotoStmt(const GotoStmt *GS) { |
2767 | 2 | WL.push_back(LabelRefVisit(GS->getLabel(), GS->getLabelLoc(), Parent)); |
2768 | 2 | } |
2769 | 10 | void EnqueueVisitor::VisitIfStmt(const IfStmt *If) { |
2770 | 10 | AddStmt(If->getElse()); |
2771 | 10 | AddStmt(If->getThen()); |
2772 | 10 | AddStmt(If->getCond()); |
2773 | 10 | AddStmt(If->getInit()); |
2774 | 10 | AddDecl(If->getConditionVariable()); |
2775 | 10 | } |
2776 | 17 | void EnqueueVisitor::VisitInitListExpr(const InitListExpr *IE) { |
2777 | | // We care about the syntactic form of the initializer list, only. |
2778 | 17 | if (InitListExpr *Syntactic = IE->getSyntacticForm()) |
2779 | 15 | IE = Syntactic; |
2780 | 17 | EnqueueChildren(IE); |
2781 | 17 | } |
2782 | 526 | void EnqueueVisitor::VisitMemberExpr(const MemberExpr *M) { |
2783 | 526 | WL.push_back(MemberExprParts(M, Parent)); |
2784 | | |
2785 | | // If the base of the member access expression is an implicit 'this', don't |
2786 | | // visit it. |
2787 | | // FIXME: If we ever want to show these implicit accesses, this will be |
2788 | | // unfortunate. However, clang_getCursor() relies on this behavior. |
2789 | 526 | if (M->isImplicitAccess()) |
2790 | 37 | return; |
2791 | | |
2792 | | // Ignore base anonymous struct/union fields, otherwise they will shadow the |
2793 | | // real field that we are interested in. |
2794 | 489 | if (auto *SubME = dyn_cast<MemberExpr>(M->getBase())) { |
2795 | 4 | if (auto *FD = dyn_cast_or_null<FieldDecl>(SubME->getMemberDecl())) { |
2796 | 4 | if (FD->isAnonymousStructOrUnion()) { |
2797 | 4 | AddStmt(SubME->getBase()); |
2798 | 4 | return; |
2799 | 4 | } |
2800 | 4 | } |
2801 | 4 | } |
2802 | | |
2803 | 485 | AddStmt(M->getBase()); |
2804 | 485 | } |
2805 | 1 | void EnqueueVisitor::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) { |
2806 | 1 | AddTypeLoc(E->getEncodedTypeSourceInfo()); |
2807 | 1 | } |
2808 | 155 | void EnqueueVisitor::VisitObjCMessageExpr(const ObjCMessageExpr *M) { |
2809 | 155 | EnqueueChildren(M); |
2810 | 155 | AddTypeLoc(M->getClassReceiverTypeInfo()); |
2811 | 155 | } |
2812 | 1 | void EnqueueVisitor::VisitOffsetOfExpr(const OffsetOfExpr *E) { |
2813 | | // Visit the components of the offsetof expression. |
2814 | 4 | for (unsigned N = E->getNumComponents(), I = N; I > 0; --I3 ) { |
2815 | 3 | const OffsetOfNode &Node = E->getComponent(I - 1); |
2816 | 3 | switch (Node.getKind()) { |
2817 | 1 | case OffsetOfNode::Array: |
2818 | 1 | AddStmt(E->getIndexExpr(Node.getArrayExprIndex())); |
2819 | 1 | break; |
2820 | 2 | case OffsetOfNode::Field: |
2821 | 2 | AddMemberRef(Node.getField(), Node.getSourceRange().getEnd()); |
2822 | 2 | break; |
2823 | 0 | case OffsetOfNode::Identifier: |
2824 | 0 | case OffsetOfNode::Base: |
2825 | 0 | continue; |
2826 | 3 | } |
2827 | 3 | } |
2828 | | // Visit the type into which we're computing the offset. |
2829 | 1 | AddTypeLoc(E->getTypeSourceInfo()); |
2830 | 1 | } |
2831 | 15 | void EnqueueVisitor::VisitOverloadExpr(const OverloadExpr *E) { |
2832 | 15 | if (E->hasExplicitTemplateArgs()) |
2833 | 4 | AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs()); |
2834 | 15 | WL.push_back(OverloadExprParts(E, Parent)); |
2835 | 15 | } |
2836 | | void EnqueueVisitor::VisitUnaryExprOrTypeTraitExpr( |
2837 | 5 | const UnaryExprOrTypeTraitExpr *E) { |
2838 | 5 | EnqueueChildren(E); |
2839 | 5 | if (E->isArgumentType()) |
2840 | 5 | AddTypeLoc(E->getArgumentTypeInfo()); |
2841 | 5 | } |
2842 | 4.76k | void EnqueueVisitor::VisitStmt(const Stmt *S) { EnqueueChildren(S); } |
2843 | 12 | void EnqueueVisitor::VisitSwitchStmt(const SwitchStmt *S) { |
2844 | 12 | AddStmt(S->getBody()); |
2845 | 12 | AddStmt(S->getCond()); |
2846 | 12 | AddDecl(S->getConditionVariable()); |
2847 | 12 | } |
2848 | | |
2849 | 2 | void EnqueueVisitor::VisitWhileStmt(const WhileStmt *W) { |
2850 | 2 | AddStmt(W->getBody()); |
2851 | 2 | AddStmt(W->getCond()); |
2852 | 2 | AddDecl(W->getConditionVariable()); |
2853 | 2 | } |
2854 | | |
2855 | 6 | void EnqueueVisitor::VisitTypeTraitExpr(const TypeTraitExpr *E) { |
2856 | 18 | for (unsigned I = E->getNumArgs(); I > 0; --I12 ) |
2857 | 12 | AddTypeLoc(E->getArg(I - 1)); |
2858 | 6 | } |
2859 | | |
2860 | 0 | void EnqueueVisitor::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) { |
2861 | 0 | AddTypeLoc(E->getQueriedTypeSourceInfo()); |
2862 | 0 | } |
2863 | | |
2864 | 0 | void EnqueueVisitor::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) { |
2865 | 0 | EnqueueChildren(E); |
2866 | 0 | } |
2867 | | |
2868 | 5 | void EnqueueVisitor::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U) { |
2869 | 5 | VisitOverloadExpr(U); |
2870 | 5 | if (!U->isImplicitAccess()) |
2871 | 4 | AddStmt(U->getBase()); |
2872 | 5 | } |
2873 | 3 | void EnqueueVisitor::VisitVAArgExpr(const VAArgExpr *E) { |
2874 | 3 | AddStmt(E->getSubExpr()); |
2875 | 3 | AddTypeLoc(E->getWrittenTypeInfo()); |
2876 | 3 | } |
2877 | 2 | void EnqueueVisitor::VisitSizeOfPackExpr(const SizeOfPackExpr *E) { |
2878 | 2 | WL.push_back(SizeOfPackExprParts(E, Parent)); |
2879 | 2 | } |
2880 | 50 | void EnqueueVisitor::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { |
2881 | | // If the opaque value has a source expression, just transparently |
2882 | | // visit that. This is useful for (e.g.) pseudo-object expressions. |
2883 | 50 | if (Expr *SourceExpr = E->getSourceExpr()) |
2884 | 48 | return Visit(SourceExpr); |
2885 | 50 | } |
2886 | 4 | void EnqueueVisitor::VisitLambdaExpr(const LambdaExpr *E) { |
2887 | 4 | AddStmt(E->getBody()); |
2888 | 4 | WL.push_back(LambdaExprParts(E, Parent)); |
2889 | 4 | } |
2890 | 17 | void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) { |
2891 | | // Treat the expression like its syntactic form. |
2892 | 17 | Visit(E->getSyntacticForm()); |
2893 | 17 | } |
2894 | | |
2895 | | void EnqueueVisitor::VisitOMPExecutableDirective( |
2896 | 1 | const OMPExecutableDirective *D) { |
2897 | 1 | EnqueueChildren(D); |
2898 | 1 | for (ArrayRef<OMPClause *>::iterator I = D->clauses().begin(), |
2899 | 1 | E = D->clauses().end(); |
2900 | 2 | I != E; ++I1 ) |
2901 | 1 | EnqueueChildren(*I); |
2902 | 1 | } |
2903 | | |
2904 | | void EnqueueVisitor::VisitOMPLoopBasedDirective( |
2905 | 1 | const OMPLoopBasedDirective *D) { |
2906 | 1 | VisitOMPExecutableDirective(D); |
2907 | 1 | } |
2908 | | |
2909 | 0 | void EnqueueVisitor::VisitOMPLoopDirective(const OMPLoopDirective *D) { |
2910 | 0 | VisitOMPLoopBasedDirective(D); |
2911 | 0 | } |
2912 | | |
2913 | 0 | void EnqueueVisitor::VisitOMPParallelDirective(const OMPParallelDirective *D) { |
2914 | 0 | VisitOMPExecutableDirective(D); |
2915 | 0 | } |
2916 | | |
2917 | 0 | void EnqueueVisitor::VisitOMPSimdDirective(const OMPSimdDirective *D) { |
2918 | 0 | VisitOMPLoopDirective(D); |
2919 | 0 | } |
2920 | | |
2921 | | void EnqueueVisitor::VisitOMPLoopTransformationDirective( |
2922 | 1 | const OMPLoopTransformationDirective *D) { |
2923 | 1 | VisitOMPLoopBasedDirective(D); |
2924 | 1 | } |
2925 | | |
2926 | 1 | void EnqueueVisitor::VisitOMPTileDirective(const OMPTileDirective *D) { |
2927 | 1 | VisitOMPLoopTransformationDirective(D); |
2928 | 1 | } |
2929 | | |
2930 | 0 | void EnqueueVisitor::VisitOMPUnrollDirective(const OMPUnrollDirective *D) { |
2931 | 0 | VisitOMPLoopTransformationDirective(D); |
2932 | 0 | } |
2933 | | |
2934 | 0 | void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) { |
2935 | 0 | VisitOMPLoopDirective(D); |
2936 | 0 | } |
2937 | | |
2938 | 0 | void EnqueueVisitor::VisitOMPForSimdDirective(const OMPForSimdDirective *D) { |
2939 | 0 | VisitOMPLoopDirective(D); |
2940 | 0 | } |
2941 | | |
2942 | 0 | void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) { |
2943 | 0 | VisitOMPExecutableDirective(D); |
2944 | 0 | } |
2945 | | |
2946 | 0 | void EnqueueVisitor::VisitOMPSectionDirective(const OMPSectionDirective *D) { |
2947 | 0 | VisitOMPExecutableDirective(D); |
2948 | 0 | } |
2949 | | |
2950 | 0 | void EnqueueVisitor::VisitOMPSingleDirective(const OMPSingleDirective *D) { |
2951 | 0 | VisitOMPExecutableDirective(D); |
2952 | 0 | } |
2953 | | |
2954 | 0 | void EnqueueVisitor::VisitOMPMasterDirective(const OMPMasterDirective *D) { |
2955 | 0 | VisitOMPExecutableDirective(D); |
2956 | 0 | } |
2957 | | |
2958 | 0 | void EnqueueVisitor::VisitOMPCriticalDirective(const OMPCriticalDirective *D) { |
2959 | 0 | VisitOMPExecutableDirective(D); |
2960 | 0 | AddDeclarationNameInfo(D); |
2961 | 0 | } |
2962 | | |
2963 | | void EnqueueVisitor::VisitOMPParallelForDirective( |
2964 | 0 | const OMPParallelForDirective *D) { |
2965 | 0 | VisitOMPLoopDirective(D); |
2966 | 0 | } |
2967 | | |
2968 | | void EnqueueVisitor::VisitOMPParallelForSimdDirective( |
2969 | 0 | const OMPParallelForSimdDirective *D) { |
2970 | 0 | VisitOMPLoopDirective(D); |
2971 | 0 | } |
2972 | | |
2973 | | void EnqueueVisitor::VisitOMPParallelMasterDirective( |
2974 | 0 | const OMPParallelMasterDirective *D) { |
2975 | 0 | VisitOMPExecutableDirective(D); |
2976 | 0 | } |
2977 | | |
2978 | | void EnqueueVisitor::VisitOMPParallelSectionsDirective( |
2979 | 0 | const OMPParallelSectionsDirective *D) { |
2980 | 0 | VisitOMPExecutableDirective(D); |
2981 | 0 | } |
2982 | | |
2983 | 0 | void EnqueueVisitor::VisitOMPTaskDirective(const OMPTaskDirective *D) { |
2984 | 0 | VisitOMPExecutableDirective(D); |
2985 | 0 | } |
2986 | | |
2987 | | void EnqueueVisitor::VisitOMPTaskyieldDirective( |
2988 | 0 | const OMPTaskyieldDirective *D) { |
2989 | 0 | VisitOMPExecutableDirective(D); |
2990 | 0 | } |
2991 | | |
2992 | 0 | void EnqueueVisitor::VisitOMPBarrierDirective(const OMPBarrierDirective *D) { |
2993 | 0 | VisitOMPExecutableDirective(D); |
2994 | 0 | } |
2995 | | |
2996 | 0 | void EnqueueVisitor::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D) { |
2997 | 0 | VisitOMPExecutableDirective(D); |
2998 | 0 | } |
2999 | | |
3000 | | void EnqueueVisitor::VisitOMPTaskgroupDirective( |
3001 | 0 | const OMPTaskgroupDirective *D) { |
3002 | 0 | VisitOMPExecutableDirective(D); |
3003 | 0 | if (const Expr *E = D->getReductionRef()) |
3004 | 0 | VisitStmt(E); |
3005 | 0 | } |
3006 | | |
3007 | 0 | void EnqueueVisitor::VisitOMPFlushDirective(const OMPFlushDirective *D) { |
3008 | 0 | VisitOMPExecutableDirective(D); |
3009 | 0 | } |
3010 | | |
3011 | 0 | void EnqueueVisitor::VisitOMPDepobjDirective(const OMPDepobjDirective *D) { |
3012 | 0 | VisitOMPExecutableDirective(D); |
3013 | 0 | } |
3014 | | |
3015 | 0 | void EnqueueVisitor::VisitOMPScanDirective(const OMPScanDirective *D) { |
3016 | 0 | VisitOMPExecutableDirective(D); |
3017 | 0 | } |
3018 | | |
3019 | 0 | void EnqueueVisitor::VisitOMPOrderedDirective(const OMPOrderedDirective *D) { |
3020 | 0 | VisitOMPExecutableDirective(D); |
3021 | 0 | } |
3022 | | |
3023 | 0 | void EnqueueVisitor::VisitOMPAtomicDirective(const OMPAtomicDirective *D) { |
3024 | 0 | VisitOMPExecutableDirective(D); |
3025 | 0 | } |
3026 | | |
3027 | 0 | void EnqueueVisitor::VisitOMPTargetDirective(const OMPTargetDirective *D) { |
3028 | 0 | VisitOMPExecutableDirective(D); |
3029 | 0 | } |
3030 | | |
3031 | | void EnqueueVisitor::VisitOMPTargetDataDirective( |
3032 | 0 | const OMPTargetDataDirective *D) { |
3033 | 0 | VisitOMPExecutableDirective(D); |
3034 | 0 | } |
3035 | | |
3036 | | void EnqueueVisitor::VisitOMPTargetEnterDataDirective( |
3037 | 0 | const OMPTargetEnterDataDirective *D) { |
3038 | 0 | VisitOMPExecutableDirective(D); |
3039 | 0 | } |
3040 | | |
3041 | | void EnqueueVisitor::VisitOMPTargetExitDataDirective( |
3042 | 0 | const OMPTargetExitDataDirective *D) { |
3043 | 0 | VisitOMPExecutableDirective(D); |
3044 | 0 | } |
3045 | | |
3046 | | void EnqueueVisitor::VisitOMPTargetParallelDirective( |
3047 | 0 | const OMPTargetParallelDirective *D) { |
3048 | 0 | VisitOMPExecutableDirective(D); |
3049 | 0 | } |
3050 | | |
3051 | | void EnqueueVisitor::VisitOMPTargetParallelForDirective( |
3052 | 0 | const OMPTargetParallelForDirective *D) { |
3053 | 0 | VisitOMPLoopDirective(D); |
3054 | 0 | } |
3055 | | |
3056 | 0 | void EnqueueVisitor::VisitOMPTeamsDirective(const OMPTeamsDirective *D) { |
3057 | 0 | VisitOMPExecutableDirective(D); |
3058 | 0 | } |
3059 | | |
3060 | | void EnqueueVisitor::VisitOMPCancellationPointDirective( |
3061 | 0 | const OMPCancellationPointDirective *D) { |
3062 | 0 | VisitOMPExecutableDirective(D); |
3063 | 0 | } |
3064 | | |
3065 | 0 | void EnqueueVisitor::VisitOMPCancelDirective(const OMPCancelDirective *D) { |
3066 | 0 | VisitOMPExecutableDirective(D); |
3067 | 0 | } |
3068 | | |
3069 | 0 | void EnqueueVisitor::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D) { |
3070 | 0 | VisitOMPLoopDirective(D); |
3071 | 0 | } |
3072 | | |
3073 | | void EnqueueVisitor::VisitOMPTaskLoopSimdDirective( |
3074 | 0 | const OMPTaskLoopSimdDirective *D) { |
3075 | 0 | VisitOMPLoopDirective(D); |
3076 | 0 | } |
3077 | | |
3078 | | void EnqueueVisitor::VisitOMPMasterTaskLoopDirective( |
3079 | 0 | const OMPMasterTaskLoopDirective *D) { |
3080 | 0 | VisitOMPLoopDirective(D); |
3081 | 0 | } |
3082 | | |
3083 | | void EnqueueVisitor::VisitOMPMasterTaskLoopSimdDirective( |
3084 | 0 | const OMPMasterTaskLoopSimdDirective *D) { |
3085 | 0 | VisitOMPLoopDirective(D); |
3086 | 0 | } |
3087 | | |
3088 | | void EnqueueVisitor::VisitOMPParallelMasterTaskLoopDirective( |
3089 | 0 | const OMPParallelMasterTaskLoopDirective *D) { |
3090 | 0 | VisitOMPLoopDirective(D); |
3091 | 0 | } |
3092 | | |
3093 | | void EnqueueVisitor::VisitOMPParallelMasterTaskLoopSimdDirective( |
3094 | 0 | const OMPParallelMasterTaskLoopSimdDirective *D) { |
3095 | 0 | VisitOMPLoopDirective(D); |
3096 | 0 | } |
3097 | | |
3098 | | void EnqueueVisitor::VisitOMPDistributeDirective( |
3099 | 0 | const OMPDistributeDirective *D) { |
3100 | 0 | VisitOMPLoopDirective(D); |
3101 | 0 | } |
3102 | | |
3103 | | void EnqueueVisitor::VisitOMPDistributeParallelForDirective( |
3104 | 0 | const OMPDistributeParallelForDirective *D) { |
3105 | 0 | VisitOMPLoopDirective(D); |
3106 | 0 | } |
3107 | | |
3108 | | void EnqueueVisitor::VisitOMPDistributeParallelForSimdDirective( |
3109 | 0 | const OMPDistributeParallelForSimdDirective *D) { |
3110 | 0 | VisitOMPLoopDirective(D); |
3111 | 0 | } |
3112 | | |
3113 | | void EnqueueVisitor::VisitOMPDistributeSimdDirective( |
3114 | 0 | const OMPDistributeSimdDirective *D) { |
3115 | 0 | VisitOMPLoopDirective(D); |
3116 | 0 | } |
3117 | | |
3118 | | void EnqueueVisitor::VisitOMPTargetParallelForSimdDirective( |
3119 | 0 | const OMPTargetParallelForSimdDirective *D) { |
3120 | 0 | VisitOMPLoopDirective(D); |
3121 | 0 | } |
3122 | | |
3123 | | void EnqueueVisitor::VisitOMPTargetSimdDirective( |
3124 | 0 | const OMPTargetSimdDirective *D) { |
3125 | 0 | VisitOMPLoopDirective(D); |
3126 | 0 | } |
3127 | | |
3128 | | void EnqueueVisitor::VisitOMPTeamsDistributeDirective( |
3129 | 0 | const OMPTeamsDistributeDirective *D) { |
3130 | 0 | VisitOMPLoopDirective(D); |
3131 | 0 | } |
3132 | | |
3133 | | void EnqueueVisitor::VisitOMPTeamsDistributeSimdDirective( |
3134 | 0 | const OMPTeamsDistributeSimdDirective *D) { |
3135 | 0 | VisitOMPLoopDirective(D); |
3136 | 0 | } |
3137 | | |
3138 | | void EnqueueVisitor::VisitOMPTeamsDistributeParallelForSimdDirective( |
3139 | 0 | const OMPTeamsDistributeParallelForSimdDirective *D) { |
3140 | 0 | VisitOMPLoopDirective(D); |
3141 | 0 | } |
3142 | | |
3143 | | void EnqueueVisitor::VisitOMPTeamsDistributeParallelForDirective( |
3144 | 0 | const OMPTeamsDistributeParallelForDirective *D) { |
3145 | 0 | VisitOMPLoopDirective(D); |
3146 | 0 | } |
3147 | | |
3148 | | void EnqueueVisitor::VisitOMPTargetTeamsDirective( |
3149 | 0 | const OMPTargetTeamsDirective *D) { |
3150 | 0 | VisitOMPExecutableDirective(D); |
3151 | 0 | } |
3152 | | |
3153 | | void EnqueueVisitor::VisitOMPTargetTeamsDistributeDirective( |
3154 | 0 | const OMPTargetTeamsDistributeDirective *D) { |
3155 | 0 | VisitOMPLoopDirective(D); |
3156 | 0 | } |
3157 | | |
3158 | | void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForDirective( |
3159 | 0 | const OMPTargetTeamsDistributeParallelForDirective *D) { |
3160 | 0 | VisitOMPLoopDirective(D); |
3161 | 0 | } |
3162 | | |
3163 | | void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForSimdDirective( |
3164 | 0 | const OMPTargetTeamsDistributeParallelForSimdDirective *D) { |
3165 | 0 | VisitOMPLoopDirective(D); |
3166 | 0 | } |
3167 | | |
3168 | | void EnqueueVisitor::VisitOMPTargetTeamsDistributeSimdDirective( |
3169 | 0 | const OMPTargetTeamsDistributeSimdDirective *D) { |
3170 | 0 | VisitOMPLoopDirective(D); |
3171 | 0 | } |
3172 | | |
3173 | 12.9k | void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) { |
3174 | 12.9k | EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU, RegionOfInterest)) |
3175 | 12.9k | .Visit(S); |
3176 | 12.9k | } |
3177 | | |
3178 | 18.4k | bool CursorVisitor::IsInRegionOfInterest(CXCursor C) { |
3179 | 18.4k | if (RegionOfInterest.isValid()) { |
3180 | 13.9k | SourceRange Range = getRawCursorExtent(C); |
3181 | 13.9k | if (Range.isInvalid() || CompareRegionOfInterest(Range)13.9k ) |
3182 | 1.75k | return false; |
3183 | 13.9k | } |
3184 | 16.6k | return true; |
3185 | 18.4k | } |
3186 | | |
3187 | 1.15k | bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) { |
3188 | 28.2k | while (!WL.empty()) { |
3189 | | // Dequeue the worklist item. |
3190 | 27.0k | VisitorJob LI = WL.pop_back_val(); |
3191 | | |
3192 | | // Set the Parent field, then back to its old value once we're done. |
3193 | 27.0k | SetParentRAII SetParent(Parent, StmtParent, LI.getParent()); |
3194 | | |
3195 | 27.0k | switch (LI.getKind()) { |
3196 | 356 | case VisitorJob::DeclVisitKind: { |
3197 | 356 | const Decl *D = cast<DeclVisit>(&LI)->get(); |
3198 | 356 | if (!D) |
3199 | 0 | continue; |
3200 | | |
3201 | | // For now, perform default visitation for Decls. |
3202 | 356 | if (Visit(MakeCXCursor(D, TU, RegionOfInterest, |
3203 | 356 | cast<DeclVisit>(&LI)->isFirst()))) |
3204 | 1 | return true; |
3205 | | |
3206 | 355 | continue; |
3207 | 356 | } |
3208 | 355 | case VisitorJob::ExplicitTemplateArgsVisitKind: { |
3209 | 12 | for (const TemplateArgumentLoc &Arg : |
3210 | 16 | *cast<ExplicitTemplateArgsVisit>(&LI)) { |
3211 | 16 | if (VisitTemplateArgumentLoc(Arg)) |
3212 | 0 | return true; |
3213 | 16 | } |
3214 | 12 | continue; |
3215 | 12 | } |
3216 | 186 | case VisitorJob::TypeLocVisitKind: { |
3217 | | // Perform default visitation for TypeLocs. |
3218 | 186 | if (Visit(cast<TypeLocVisit>(&LI)->get())) |
3219 | 0 | return true; |
3220 | 186 | continue; |
3221 | 186 | } |
3222 | 186 | case VisitorJob::LabelRefVisitKind: { |
3223 | 3 | const LabelDecl *LS = cast<LabelRefVisit>(&LI)->get(); |
3224 | 3 | if (LabelStmt *stmt = LS->getStmt()) { |
3225 | 2 | if (Visit(MakeCursorLabelRef(stmt, cast<LabelRefVisit>(&LI)->getLoc(), |
3226 | 2 | TU))) { |
3227 | 0 | return true; |
3228 | 0 | } |
3229 | 2 | } |
3230 | 3 | continue; |
3231 | 3 | } |
3232 | | |
3233 | 6 | case VisitorJob::NestedNameSpecifierLocVisitKind: { |
3234 | 6 | NestedNameSpecifierLocVisit *V = cast<NestedNameSpecifierLocVisit>(&LI); |
3235 | 6 | if (VisitNestedNameSpecifierLoc(V->get())) |
3236 | 0 | return true; |
3237 | 6 | continue; |
3238 | 6 | } |
3239 | | |
3240 | 6 | case VisitorJob::DeclarationNameInfoVisitKind: { |
3241 | 6 | if (VisitDeclarationNameInfo(cast<DeclarationNameInfoVisit>(&LI)->get())) |
3242 | 0 | return true; |
3243 | 6 | continue; |
3244 | 6 | } |
3245 | 18 | case VisitorJob::MemberRefVisitKind: { |
3246 | 18 | MemberRefVisit *V = cast<MemberRefVisit>(&LI); |
3247 | 18 | if (Visit(MakeCursorMemberRef(V->get(), V->getLoc(), TU))) |
3248 | 0 | return true; |
3249 | 18 | continue; |
3250 | 18 | } |
3251 | 18.4k | case VisitorJob::StmtVisitKind: { |
3252 | 18.4k | const Stmt *S = cast<StmtVisit>(&LI)->get(); |
3253 | 18.4k | if (!S) |
3254 | 0 | continue; |
3255 | | |
3256 | | // Update the current cursor. |
3257 | 18.4k | CXCursor Cursor = MakeCXCursor(S, StmtParent, TU, RegionOfInterest); |
3258 | 18.4k | if (!IsInRegionOfInterest(Cursor)) |
3259 | 1.75k | continue; |
3260 | 16.6k | switch (Visitor(Cursor, Parent, ClientData)) { |
3261 | 1 | case CXChildVisit_Break: |
3262 | 1 | return true; |
3263 | 4.87k | case CXChildVisit_Continue: |
3264 | 4.87k | break; |
3265 | 11.7k | case CXChildVisit_Recurse: |
3266 | 11.7k | if (PostChildrenVisitor) |
3267 | 6.31k | WL.push_back(PostChildrenVisit(nullptr, Cursor)); |
3268 | 11.7k | EnqueueWorkList(WL, S); |
3269 | 11.7k | break; |
3270 | 16.6k | } |
3271 | 16.6k | continue; |
3272 | 16.6k | } |
3273 | 16.6k | case VisitorJob::MemberExprPartsKind: { |
3274 | | // Handle the other pieces in the MemberExpr besides the base. |
3275 | 526 | const MemberExpr *M = cast<MemberExprParts>(&LI)->get(); |
3276 | | |
3277 | | // Visit the nested-name-specifier |
3278 | 526 | if (NestedNameSpecifierLoc QualifierLoc = M->getQualifierLoc()) |
3279 | 5 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
3280 | 0 | return true; |
3281 | | |
3282 | | // Visit the declaration name. |
3283 | 526 | if (VisitDeclarationNameInfo(M->getMemberNameInfo())) |
3284 | 0 | return true; |
3285 | | |
3286 | | // Visit the explicitly-specified template arguments, if any. |
3287 | 526 | if (M->hasExplicitTemplateArgs()) { |
3288 | 2 | for (const TemplateArgumentLoc *Arg = M->getTemplateArgs(), |
3289 | 2 | *ArgEnd = Arg + M->getNumTemplateArgs(); |
3290 | 4 | Arg != ArgEnd; ++Arg2 ) { |
3291 | 2 | if (VisitTemplateArgumentLoc(*Arg)) |
3292 | 0 | return true; |
3293 | 2 | } |
3294 | 2 | } |
3295 | 526 | continue; |
3296 | 526 | } |
3297 | 1.20k | case VisitorJob::DeclRefExprPartsKind: { |
3298 | 1.20k | const DeclRefExpr *DR = cast<DeclRefExprParts>(&LI)->get(); |
3299 | | // Visit nested-name-specifier, if present. |
3300 | 1.20k | if (NestedNameSpecifierLoc QualifierLoc = DR->getQualifierLoc()) |
3301 | 2 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
3302 | 0 | return true; |
3303 | | // Visit declaration name. |
3304 | 1.20k | if (VisitDeclarationNameInfo(DR->getNameInfo())) |
3305 | 0 | return true; |
3306 | 1.20k | continue; |
3307 | 1.20k | } |
3308 | 1.20k | case VisitorJob::OverloadExprPartsKind: { |
3309 | 15 | const OverloadExpr *O = cast<OverloadExprParts>(&LI)->get(); |
3310 | | // Visit the nested-name-specifier. |
3311 | 15 | if (NestedNameSpecifierLoc QualifierLoc = O->getQualifierLoc()) |
3312 | 5 | if (VisitNestedNameSpecifierLoc(QualifierLoc)) |
3313 | 0 | return true; |
3314 | | // Visit the declaration name. |
3315 | 15 | if (VisitDeclarationNameInfo(O->getNameInfo())) |
3316 | 0 | return true; |
3317 | | // Visit the overloaded declaration reference. |
3318 | 15 | if (Visit(MakeCursorOverloadedDeclRef(O, TU))) |
3319 | 0 | return true; |
3320 | 15 | continue; |
3321 | 15 | } |
3322 | 15 | case VisitorJob::SizeOfPackExprPartsKind: { |
3323 | 2 | const SizeOfPackExpr *E = cast<SizeOfPackExprParts>(&LI)->get(); |
3324 | 2 | NamedDecl *Pack = E->getPack(); |
3325 | 2 | if (isa<TemplateTypeParmDecl>(Pack)) { |
3326 | 1 | if (Visit(MakeCursorTypeRef(cast<TemplateTypeParmDecl>(Pack), |
3327 | 1 | E->getPackLoc(), TU))) |
3328 | 0 | return true; |
3329 | | |
3330 | 1 | continue; |
3331 | 1 | } |
3332 | | |
3333 | 1 | if (isa<TemplateTemplateParmDecl>(Pack)) { |
3334 | 0 | if (Visit(MakeCursorTemplateRef(cast<TemplateTemplateParmDecl>(Pack), |
3335 | 0 | E->getPackLoc(), TU))) |
3336 | 0 | return true; |
3337 | | |
3338 | 0 | continue; |
3339 | 0 | } |
3340 | | |
3341 | | // Non-type template parameter packs and function parameter packs are |
3342 | | // treated like DeclRefExpr cursors. |
3343 | 1 | continue; |
3344 | 1 | } |
3345 | | |
3346 | 4 | case VisitorJob::LambdaExprPartsKind: { |
3347 | | // Visit non-init captures. |
3348 | 4 | const LambdaExpr *E = cast<LambdaExprParts>(&LI)->get(); |
3349 | 4 | for (LambdaExpr::capture_iterator C = E->explicit_capture_begin(), |
3350 | 4 | CEnd = E->explicit_capture_end(); |
3351 | 10 | C != CEnd; ++C6 ) { |
3352 | 6 | if (!C->capturesVariable()) |
3353 | 1 | continue; |
3354 | | |
3355 | 5 | if (Visit(MakeCursorVariableRef(C->getCapturedVar(), C->getLocation(), |
3356 | 5 | TU))) |
3357 | 0 | return true; |
3358 | 5 | } |
3359 | | // Visit init captures |
3360 | 6 | for (auto InitExpr : E->capture_inits())4 { |
3361 | 6 | if (InitExpr && Visit(InitExpr)5 ) |
3362 | 0 | return true; |
3363 | 6 | } |
3364 | | |
3365 | 4 | TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc(); |
3366 | | // Visit parameters and return type, if present. |
3367 | 4 | if (FunctionTypeLoc Proto = TL.getAs<FunctionProtoTypeLoc>()) { |
3368 | 4 | if (E->hasExplicitParameters()) { |
3369 | | // Visit parameters. |
3370 | 6 | for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I3 ) |
3371 | 3 | if (Visit(MakeCXCursor(Proto.getParam(I), TU))) |
3372 | 0 | return true; |
3373 | 3 | } |
3374 | 4 | if (E->hasExplicitResultType()) { |
3375 | | // Visit result type. |
3376 | 2 | if (Visit(Proto.getReturnLoc())) |
3377 | 0 | return true; |
3378 | 2 | } |
3379 | 4 | } |
3380 | 4 | break; |
3381 | 4 | } |
3382 | | |
3383 | 6.31k | case VisitorJob::PostChildrenVisitKind: |
3384 | 6.31k | if (PostChildrenVisitor(Parent, ClientData)) |
3385 | 0 | return true; |
3386 | 6.31k | break; |
3387 | 27.0k | } |
3388 | 27.0k | } |
3389 | 1.15k | return false; |
3390 | 1.15k | } |
3391 | | |
3392 | 1.15k | bool CursorVisitor::Visit(const Stmt *S) { |
3393 | 1.15k | VisitorWorkList *WL = nullptr; |
3394 | 1.15k | if (!WorkListFreeList.empty()) { |
3395 | 525 | WL = WorkListFreeList.back(); |
3396 | 525 | WL->clear(); |
3397 | 525 | WorkListFreeList.pop_back(); |
3398 | 627 | } else { |
3399 | 627 | WL = new VisitorWorkList(); |
3400 | 627 | WorkListCache.push_back(WL); |
3401 | 627 | } |
3402 | 1.15k | EnqueueWorkList(*WL, S); |
3403 | 1.15k | bool result = RunVisitorWorkList(*WL); |
3404 | 1.15k | WorkListFreeList.push_back(WL); |
3405 | 1.15k | return result; |
3406 | 1.15k | } |
3407 | | |
3408 | | namespace { |
3409 | | typedef SmallVector<SourceRange, 4> RefNamePieces; |
3410 | | RefNamePieces buildPieces(unsigned NameFlags, bool IsMemberRefExpr, |
3411 | | const DeclarationNameInfo &NI, SourceRange QLoc, |
3412 | 65.9k | const SourceRange *TemplateArgsLoc = nullptr) { |
3413 | 65.9k | const bool WantQualifier = NameFlags & CXNameRange_WantQualifier; |
3414 | 65.9k | const bool WantTemplateArgs = NameFlags & CXNameRange_WantTemplateArgs; |
3415 | 65.9k | const bool WantSinglePiece = NameFlags & CXNameRange_WantSinglePiece; |
3416 | | |
3417 | 65.9k | const DeclarationName::NameKind Kind = NI.getName().getNameKind(); |
3418 | | |
3419 | 65.9k | RefNamePieces Pieces; |
3420 | | |
3421 | 65.9k | if (WantQualifier && QLoc.isValid()) |
3422 | 86 | Pieces.push_back(QLoc); |
3423 | | |
3424 | 65.9k | if (Kind != DeclarationName::CXXOperatorName || IsMemberRefExpr60.6k ) |
3425 | 5.34k | Pieces.push_back(NI.getLoc()); |
3426 | | |
3427 | 65.9k | if (WantTemplateArgs && TemplateArgsLoc51.3k && TemplateArgsLoc->isValid()49.0k ) |
3428 | 20 | Pieces.push_back(*TemplateArgsLoc); |
3429 | | |
3430 | 65.9k | if (Kind == DeclarationName::CXXOperatorName) { |
3431 | 60.6k | Pieces.push_back(NI.getInfo().getCXXOperatorNameBeginLoc()); |
3432 | 60.6k | Pieces.push_back(NI.getInfo().getCXXOperatorNameEndLoc()); |
3433 | 60.6k | } |
3434 | | |
3435 | 65.9k | if (WantSinglePiece) { |
3436 | 13.2k | SourceRange R(Pieces.front().getBegin(), Pieces.back().getEnd()); |
3437 | 13.2k | Pieces.clear(); |
3438 | 13.2k | Pieces.push_back(R); |
3439 | 13.2k | } |
3440 | | |
3441 | 65.9k | return Pieces; |
3442 | 65.9k | } |
3443 | | } // namespace |
3444 | | |
3445 | | //===----------------------------------------------------------------------===// |
3446 | | // Misc. API hooks. |
3447 | | //===----------------------------------------------------------------------===// |
3448 | | |
3449 | | namespace { |
3450 | | struct RegisterFatalErrorHandler { |
3451 | 1.05k | RegisterFatalErrorHandler() { |
3452 | 1.05k | clang_install_aborting_llvm_fatal_error_handler(); |
3453 | 1.05k | } |
3454 | | }; |
3455 | | } // namespace |
3456 | | |
3457 | | static llvm::ManagedStatic<RegisterFatalErrorHandler> |
3458 | | RegisterFatalErrorHandlerOnce; |
3459 | | |
3460 | | CXIndex clang_createIndex(int excludeDeclarationsFromPCH, |
3461 | 1.06k | int displayDiagnostics) { |
3462 | | // We use crash recovery to make some of our APIs more reliable, implicitly |
3463 | | // enable it. |
3464 | 1.06k | if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY")) |
3465 | 1.05k | llvm::CrashRecoveryContext::Enable(); |
3466 | | |
3467 | | // Look through the managed static to trigger construction of the managed |
3468 | | // static which registers our fatal error handler. This ensures it is only |
3469 | | // registered once. |
3470 | 1.06k | (void)*RegisterFatalErrorHandlerOnce; |
3471 | | |
3472 | | // Initialize targets for clang module support. |
3473 | 1.06k | llvm::InitializeAllTargets(); |
3474 | 1.06k | llvm::InitializeAllTargetMCs(); |
3475 | 1.06k | llvm::InitializeAllAsmPrinters(); |
3476 | 1.06k | llvm::InitializeAllAsmParsers(); |
3477 | | |
3478 | 1.06k | CIndexer *CIdxr = new CIndexer(); |
3479 | | |
3480 | 1.06k | if (excludeDeclarationsFromPCH) |
3481 | 282 | CIdxr->setOnlyLocalDecls(); |
3482 | 1.06k | if (displayDiagnostics) |
3483 | 502 | CIdxr->setDisplayDiagnostics(); |
3484 | | |
3485 | 1.06k | if (getenv("LIBCLANG_BGPRIO_INDEX")) |
3486 | 0 | CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() | |
3487 | 0 | CXGlobalOpt_ThreadBackgroundPriorityForIndexing); |
3488 | 1.06k | if (getenv("LIBCLANG_BGPRIO_EDIT")) |
3489 | 0 | CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() | |
3490 | 0 | CXGlobalOpt_ThreadBackgroundPriorityForEditing); |
3491 | | |
3492 | 1.06k | return CIdxr; |
3493 | 1.06k | } |
3494 | | |
3495 | 1.05k | void clang_disposeIndex(CXIndex CIdx) { |
3496 | 1.05k | if (CIdx) |
3497 | 1.05k | delete static_cast<CIndexer *>(CIdx); |
3498 | 1.05k | } |
3499 | | |
3500 | 0 | void clang_CXIndex_setGlobalOptions(CXIndex CIdx, unsigned options) { |
3501 | 0 | if (CIdx) |
3502 | 0 | static_cast<CIndexer *>(CIdx)->setCXGlobalOptFlags(options); |
3503 | 0 | } |
3504 | | |
3505 | 0 | unsigned clang_CXIndex_getGlobalOptions(CXIndex CIdx) { |
3506 | 0 | if (CIdx) |
3507 | 0 | return static_cast<CIndexer *>(CIdx)->getCXGlobalOptFlags(); |
3508 | 0 | return 0; |
3509 | 0 | } |
3510 | | |
3511 | | void clang_CXIndex_setInvocationEmissionPathOption(CXIndex CIdx, |
3512 | 7 | const char *Path) { |
3513 | 7 | if (CIdx) |
3514 | 7 | static_cast<CIndexer *>(CIdx)->setInvocationEmissionPath(Path ? Path : ""0 ); |
3515 | 7 | } |
3516 | | |
3517 | 2 | void clang_toggleCrashRecovery(unsigned isEnabled) { |
3518 | 2 | if (isEnabled) |
3519 | 0 | llvm::CrashRecoveryContext::Enable(); |
3520 | 2 | else |
3521 | 2 | llvm::CrashRecoveryContext::Disable(); |
3522 | 2 | } |
3523 | | |
3524 | | CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx, |
3525 | 2 | const char *ast_filename) { |
3526 | 2 | CXTranslationUnit TU; |
3527 | 2 | enum CXErrorCode Result = |
3528 | 2 | clang_createTranslationUnit2(CIdx, ast_filename, &TU); |
3529 | 2 | (void)Result; |
3530 | 2 | assert((TU && Result == CXError_Success) || |
3531 | 2 | (!TU && Result != CXError_Success)); |
3532 | 0 | return TU; |
3533 | 2 | } |
3534 | | |
3535 | | enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx, |
3536 | | const char *ast_filename, |
3537 | 36 | CXTranslationUnit *out_TU) { |
3538 | 36 | if (out_TU) |
3539 | 35 | *out_TU = nullptr; |
3540 | | |
3541 | 36 | if (!CIdx || !ast_filename33 || !out_TU33 ) |
3542 | 3 | return CXError_InvalidArguments; |
3543 | | |
3544 | 33 | LOG_FUNC_SECTION { *Log << ast_filename; }0 |
3545 | | |
3546 | 33 | CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx); |
3547 | 33 | FileSystemOptions FileSystemOpts; |
3548 | | |
3549 | 33 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags = |
3550 | 33 | CompilerInstance::createDiagnostics(new DiagnosticOptions()); |
3551 | 33 | std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile( |
3552 | 33 | ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), |
3553 | 33 | ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false, |
3554 | 33 | CXXIdx->getOnlyLocalDecls(), CaptureDiagsKind::All, |
3555 | 33 | /*AllowASTWithCompilerErrors=*/true, |
3556 | 33 | /*UserFilesAreVolatile=*/true); |
3557 | 33 | *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU)); |
3558 | 33 | return *out_TU ? CXError_Success32 : CXError_Failure1 ; |
3559 | 36 | } |
3560 | | |
3561 | 127 | unsigned clang_defaultEditingTranslationUnitOptions() { |
3562 | 127 | return CXTranslationUnit_PrecompiledPreamble | |
3563 | 127 | CXTranslationUnit_CacheCompletionResults; |
3564 | 127 | } |
3565 | | |
3566 | | CXTranslationUnit clang_createTranslationUnitFromSourceFile( |
3567 | | CXIndex CIdx, const char *source_filename, int num_command_line_args, |
3568 | | const char *const *command_line_args, unsigned num_unsaved_files, |
3569 | 0 | struct CXUnsavedFile *unsaved_files) { |
3570 | 0 | unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord; |
3571 | 0 | return clang_parseTranslationUnit(CIdx, source_filename, command_line_args, |
3572 | 0 | num_command_line_args, unsaved_files, |
3573 | 0 | num_unsaved_files, Options); |
3574 | 0 | } |
3575 | | |
3576 | | static CXErrorCode |
3577 | | clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename, |
3578 | | const char *const *command_line_args, |
3579 | | int num_command_line_args, |
3580 | | ArrayRef<CXUnsavedFile> unsaved_files, |
3581 | 993 | unsigned options, CXTranslationUnit *out_TU) { |
3582 | | // Set up the initial return values. |
3583 | 993 | if (out_TU) |
3584 | 992 | *out_TU = nullptr; |
3585 | | |
3586 | | // Check arguments. |
3587 | 993 | if (!CIdx || !out_TU992 ) |
3588 | 1 | return CXError_InvalidArguments; |
3589 | | |
3590 | 992 | CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx); |
3591 | | |
3592 | 992 | if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing)) |
3593 | 0 | setThreadBackgroundPriority(); |
3594 | | |
3595 | 992 | bool PrecompilePreamble = options & CXTranslationUnit_PrecompiledPreamble; |
3596 | 992 | bool CreatePreambleOnFirstParse = |
3597 | 992 | options & CXTranslationUnit_CreatePreambleOnFirstParse; |
3598 | | // FIXME: Add a flag for modules. |
3599 | 992 | TranslationUnitKind TUKind = (options & (CXTranslationUnit_Incomplete | |
3600 | 992 | CXTranslationUnit_SingleFileParse)) |
3601 | 992 | ? TU_Prefix61 |
3602 | 992 | : TU_Complete931 ; |
3603 | 992 | bool CacheCodeCompletionResults = |
3604 | 992 | options & CXTranslationUnit_CacheCompletionResults; |
3605 | 992 | bool IncludeBriefCommentsInCodeCompletion = |
3606 | 992 | options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion; |
3607 | 992 | bool SingleFileParse = options & CXTranslationUnit_SingleFileParse; |
3608 | 992 | bool ForSerialization = options & CXTranslationUnit_ForSerialization; |
3609 | 992 | bool RetainExcludedCB = |
3610 | 992 | options & CXTranslationUnit_RetainExcludedConditionalBlocks; |
3611 | 992 | SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None; |
3612 | 992 | if (options & CXTranslationUnit_SkipFunctionBodies) { |
3613 | 6 | SkipFunctionBodies = |
3614 | 6 | (options & CXTranslationUnit_LimitSkipFunctionBodiesToPreamble) |
3615 | 6 | ? SkipFunctionBodiesScope::Preamble1 |
3616 | 6 | : SkipFunctionBodiesScope::PreambleAndMainFile5 ; |
3617 | 6 | } |
3618 | | |
3619 | | // Configure the diagnostics. |
3620 | 992 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
3621 | 992 | CompilerInstance::createDiagnostics(new DiagnosticOptions)); |
3622 | | |
3623 | 992 | if (options & CXTranslationUnit_KeepGoing) |
3624 | 5 | Diags->setFatalsAsError(true); |
3625 | | |
3626 | 992 | CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::All; |
3627 | 992 | if (options & CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles) |
3628 | 1 | CaptureDiagnostics = CaptureDiagsKind::AllWithoutNonErrorsFromIncludes; |
3629 | | |
3630 | | // Recover resources if we crash before exiting this function. |
3631 | 992 | llvm::CrashRecoveryContextCleanupRegistrar< |
3632 | 992 | DiagnosticsEngine, |
3633 | 992 | llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine>> |
3634 | 992 | DiagCleanup(Diags.get()); |
3635 | | |
3636 | 992 | std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles( |
3637 | 992 | new std::vector<ASTUnit::RemappedFile>()); |
3638 | | |
3639 | | // Recover resources if we crash before exiting this function. |
3640 | 992 | llvm::CrashRecoveryContextCleanupRegistrar<std::vector<ASTUnit::RemappedFile>> |
3641 | 992 | RemappedCleanup(RemappedFiles.get()); |
3642 | | |
3643 | 992 | for (auto &UF : unsaved_files) { |
3644 | 4 | std::unique_ptr<llvm::MemoryBuffer> MB = |
3645 | 4 | llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename); |
3646 | 4 | RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release())); |
3647 | 4 | } |
3648 | | |
3649 | 992 | std::unique_ptr<std::vector<const char *>> Args( |
3650 | 992 | new std::vector<const char *>()); |
3651 | | |
3652 | | // Recover resources if we crash before exiting this method. |
3653 | 992 | llvm::CrashRecoveryContextCleanupRegistrar<std::vector<const char *>> |
3654 | 992 | ArgsCleanup(Args.get()); |
3655 | | |
3656 | | // Since the Clang C library is primarily used by batch tools dealing with |
3657 | | // (often very broken) source code, where spell-checking can have a |
3658 | | // significant negative impact on performance (particularly when |
3659 | | // precompiled headers are involved), we disable it by default. |
3660 | | // Only do this if we haven't found a spell-checking-related argument. |
3661 | 992 | bool FoundSpellCheckingArgument = false; |
3662 | 3.78k | for (int I = 0; I != num_command_line_args; ++I2.79k ) { |
3663 | 2.79k | if (strcmp(command_line_args[I], "-fno-spell-checking") == 0 || |
3664 | 2.79k | strcmp(command_line_args[I], "-fspell-checking") == 0) { |
3665 | 2 | FoundSpellCheckingArgument = true; |
3666 | 2 | break; |
3667 | 2 | } |
3668 | 2.79k | } |
3669 | 992 | Args->insert(Args->end(), command_line_args, |
3670 | 992 | command_line_args + num_command_line_args); |
3671 | | |
3672 | 992 | if (!FoundSpellCheckingArgument) |
3673 | 990 | Args->insert(Args->begin() + 1, "-fno-spell-checking"); |
3674 | | |
3675 | | // The 'source_filename' argument is optional. If the caller does not |
3676 | | // specify it then it is assumed that the source file is specified |
3677 | | // in the actual argument list. |
3678 | | // Put the source file after command_line_args otherwise if '-x' flag is |
3679 | | // present it will be unused. |
3680 | 992 | if (source_filename) |
3681 | 213 | Args->push_back(source_filename); |
3682 | | |
3683 | | // Do we need the detailed preprocessing record? |
3684 | 992 | if (options & CXTranslationUnit_DetailedPreprocessingRecord) { |
3685 | 990 | Args->push_back("-Xclang"); |
3686 | 990 | Args->push_back("-detailed-preprocessing-record"); |
3687 | 990 | } |
3688 | | |
3689 | | // Suppress any editor placeholder diagnostics. |
3690 | 992 | Args->push_back("-fallow-editor-placeholders"); |
3691 | | |
3692 | 992 | unsigned NumErrors = Diags->getClient()->getNumErrors(); |
3693 | 992 | std::unique_ptr<ASTUnit> ErrUnit; |
3694 | | // Unless the user specified that they want the preamble on the first parse |
3695 | | // set it up to be created on the first reparse. This makes the first parse |
3696 | | // faster, trading for a slower (first) reparse. |
3697 | 992 | unsigned PrecompilePreambleAfterNParses = |
3698 | 992 | !PrecompilePreamble ? 0865 : 2 - CreatePreambleOnFirstParse127 ; |
3699 | | |
3700 | 992 | LibclangInvocationReporter InvocationReporter( |
3701 | 992 | *CXXIdx, LibclangInvocationReporter::OperationKind::ParseOperation, |
3702 | 992 | options, llvm::makeArrayRef(*Args), /*InvocationArgs=*/None, |
3703 | 992 | unsaved_files); |
3704 | 992 | std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCommandLine( |
3705 | 992 | Args->data(), Args->data() + Args->size(), |
3706 | 992 | CXXIdx->getPCHContainerOperations(), Diags, |
3707 | 992 | CXXIdx->getClangResourcesPath(), CXXIdx->getOnlyLocalDecls(), |
3708 | 992 | CaptureDiagnostics, *RemappedFiles.get(), |
3709 | 992 | /*RemappedFilesKeepOriginalName=*/true, PrecompilePreambleAfterNParses, |
3710 | 992 | TUKind, CacheCodeCompletionResults, IncludeBriefCommentsInCodeCompletion, |
3711 | 992 | /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse, |
3712 | 992 | /*UserFilesAreVolatile=*/true, ForSerialization, RetainExcludedCB, |
3713 | 992 | CXXIdx->getPCHContainerOperations()->getRawReader().getFormat(), |
3714 | 992 | &ErrUnit)); |
3715 | | |
3716 | | // Early failures in LoadFromCommandLine may return with ErrUnit unset. |
3717 | 992 | if (!Unit && !ErrUnit2 ) |
3718 | 0 | return CXError_ASTReadError; |
3719 | | |
3720 | 992 | if (NumErrors != Diags->getClient()->getNumErrors()) { |
3721 | | // Make sure to check that 'Unit' is non-NULL. |
3722 | 429 | if (CXXIdx->getDisplayDiagnostics()) |
3723 | 70 | printDiagsToStderr(Unit ? Unit.get()68 : ErrUnit.get()2 ); |
3724 | 429 | } |
3725 | | |
3726 | 992 | if (isASTReadError(Unit ? Unit.get()983 : ErrUnit.get()9 )) |
3727 | 2 | return CXError_ASTReadError; |
3728 | | |
3729 | 990 | *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(Unit)); |
3730 | 990 | if (CXTranslationUnitImpl *TU = *out_TU) { |
3731 | 982 | TU->ParsingOptions = options; |
3732 | 982 | TU->Arguments.reserve(Args->size()); |
3733 | 982 | for (const char *Arg : *Args) |
3734 | 6.87k | TU->Arguments.push_back(Arg); |
3735 | 982 | return CXError_Success; |
3736 | 982 | } |
3737 | 8 | return CXError_Failure; |
3738 | 990 | } |
3739 | | |
3740 | | CXTranslationUnit |
3741 | | clang_parseTranslationUnit(CXIndex CIdx, const char *source_filename, |
3742 | | const char *const *command_line_args, |
3743 | | int num_command_line_args, |
3744 | | struct CXUnsavedFile *unsaved_files, |
3745 | 20 | unsigned num_unsaved_files, unsigned options) { |
3746 | 20 | CXTranslationUnit TU; |
3747 | 20 | enum CXErrorCode Result = clang_parseTranslationUnit2( |
3748 | 20 | CIdx, source_filename, command_line_args, num_command_line_args, |
3749 | 20 | unsaved_files, num_unsaved_files, options, &TU); |
3750 | 20 | (void)Result; |
3751 | 20 | assert((TU && Result == CXError_Success) || |
3752 | 20 | (!TU && Result != CXError_Success)); |
3753 | 0 | return TU; |
3754 | 20 | } |
3755 | | |
3756 | | enum CXErrorCode clang_parseTranslationUnit2( |
3757 | | CXIndex CIdx, const char *source_filename, |
3758 | | const char *const *command_line_args, int num_command_line_args, |
3759 | | struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files, |
3760 | 992 | unsigned options, CXTranslationUnit *out_TU) { |
3761 | 992 | noteBottomOfStack(); |
3762 | 992 | SmallVector<const char *, 4> Args; |
3763 | 992 | Args.push_back("clang"); |
3764 | 992 | Args.append(command_line_args, command_line_args + num_command_line_args); |
3765 | 992 | return clang_parseTranslationUnit2FullArgv( |
3766 | 992 | CIdx, source_filename, Args.data(), Args.size(), unsaved_files, |
3767 | 992 | num_unsaved_files, options, out_TU); |
3768 | 992 | } |
3769 | | |
3770 | | enum CXErrorCode clang_parseTranslationUnit2FullArgv( |
3771 | | CXIndex CIdx, const char *source_filename, |
3772 | | const char *const *command_line_args, int num_command_line_args, |
3773 | | struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files, |
3774 | 993 | unsigned options, CXTranslationUnit *out_TU) { |
3775 | 993 | LOG_FUNC_SECTION { |
3776 | 0 | *Log << source_filename << ": "; |
3777 | 0 | for (int i = 0; i != num_command_line_args; ++i) |
3778 | 0 | *Log << command_line_args[i] << " "; |
3779 | 0 | } |
3780 | | |
3781 | 993 | if (num_unsaved_files && !unsaved_files4 ) |
3782 | 0 | return CXError_InvalidArguments; |
3783 | | |
3784 | 993 | CXErrorCode result = CXError_Failure; |
3785 | 993 | auto ParseTranslationUnitImpl = [=, &result] { |
3786 | 993 | noteBottomOfStack(); |
3787 | 993 | result = clang_parseTranslationUnit_Impl( |
3788 | 993 | CIdx, source_filename, command_line_args, num_command_line_args, |
3789 | 993 | llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU); |
3790 | 993 | }; |
3791 | | |
3792 | 993 | llvm::CrashRecoveryContext CRC; |
3793 | | |
3794 | 993 | if (!RunSafely(CRC, ParseTranslationUnitImpl)) { |
3795 | 7 | fprintf(stderr, "libclang: crash detected during parsing: {\n"); |
3796 | 7 | fprintf(stderr, " 'source_filename' : '%s'\n", source_filename); |
3797 | 7 | fprintf(stderr, " 'command_line_args' : ["); |
3798 | 36 | for (int i = 0; i != num_command_line_args; ++i29 ) { |
3799 | 29 | if (i) |
3800 | 22 | fprintf(stderr, ", "); |
3801 | 29 | fprintf(stderr, "'%s'", command_line_args[i]); |
3802 | 29 | } |
3803 | 7 | fprintf(stderr, "],\n"); |
3804 | 7 | fprintf(stderr, " 'unsaved_files' : ["); |
3805 | 9 | for (unsigned i = 0; i != num_unsaved_files; ++i2 ) { |
3806 | 2 | if (i) |
3807 | 0 | fprintf(stderr, ", "); |
3808 | 2 | fprintf(stderr, "('%s', '...', %ld)", unsaved_files[i].Filename, |
3809 | 2 | unsaved_files[i].Length); |
3810 | 2 | } |
3811 | 7 | fprintf(stderr, "],\n"); |
3812 | 7 | fprintf(stderr, " 'options' : %d,\n", options); |
3813 | 7 | fprintf(stderr, "}\n"); |
3814 | | |
3815 | 7 | return CXError_Crashed; |
3816 | 986 | } else if (getenv("LIBCLANG_RESOURCE_USAGE")) { |
3817 | 0 | if (CXTranslationUnit *TU = out_TU) |
3818 | 0 | PrintLibclangResourceUsage(*TU); |
3819 | 0 | } |
3820 | | |
3821 | 986 | return result; |
3822 | 993 | } |
3823 | | |
3824 | 0 | CXString clang_Type_getObjCEncoding(CXType CT) { |
3825 | 0 | CXTranslationUnit tu = static_cast<CXTranslationUnit>(CT.data[1]); |
3826 | 0 | ASTContext &Ctx = getASTUnit(tu)->getASTContext(); |
3827 | 0 | std::string encoding; |
3828 | 0 | Ctx.getObjCEncodingForType(QualType::getFromOpaquePtr(CT.data[0]), encoding); |
3829 | |
|
3830 | 0 | return cxstring::createDup(encoding); |
3831 | 0 | } |
3832 | | |
3833 | 5 | static const IdentifierInfo *getMacroIdentifier(CXCursor C) { |
3834 | 5 | if (C.kind == CXCursor_MacroDefinition) { |
3835 | 2 | if (const MacroDefinitionRecord *MDR = getCursorMacroDefinition(C)) |
3836 | 2 | return MDR->getName(); |
3837 | 3 | } else if (C.kind == CXCursor_MacroExpansion) { |
3838 | 3 | MacroExpansionCursor ME = getCursorMacroExpansion(C); |
3839 | 3 | return ME.getName(); |
3840 | 3 | } |
3841 | 0 | return nullptr; |
3842 | 5 | } |
3843 | | |
3844 | 2 | unsigned clang_Cursor_isMacroFunctionLike(CXCursor C) { |
3845 | 2 | const IdentifierInfo *II = getMacroIdentifier(C); |
3846 | 2 | if (!II) { |
3847 | 0 | return false; |
3848 | 0 | } |
3849 | 2 | ASTUnit *ASTU = getCursorASTUnit(C); |
3850 | 2 | Preprocessor &PP = ASTU->getPreprocessor(); |
3851 | 2 | if (const MacroInfo *MI = PP.getMacroInfo(II)) |
3852 | 2 | return MI->isFunctionLike(); |
3853 | 0 | return false; |
3854 | 2 | } |
3855 | | |
3856 | 3 | unsigned clang_Cursor_isMacroBuiltin(CXCursor C) { |
3857 | 3 | const IdentifierInfo *II = getMacroIdentifier(C); |
3858 | 3 | if (!II) { |
3859 | 0 | return false; |
3860 | 0 | } |
3861 | 3 | ASTUnit *ASTU = getCursorASTUnit(C); |
3862 | 3 | Preprocessor &PP = ASTU->getPreprocessor(); |
3863 | 3 | if (const MacroInfo *MI = PP.getMacroInfo(II)) |
3864 | 3 | return MI->isBuiltinMacro(); |
3865 | 0 | return false; |
3866 | 3 | } |
3867 | | |
3868 | 0 | unsigned clang_Cursor_isFunctionInlined(CXCursor C) { |
3869 | 0 | const Decl *D = getCursorDecl(C); |
3870 | 0 | const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D); |
3871 | 0 | if (!FD) { |
3872 | 0 | return false; |
3873 | 0 | } |
3874 | 0 | return FD->isInlined(); |
3875 | 0 | } |
3876 | | |
3877 | 0 | static StringLiteral *getCFSTR_value(CallExpr *callExpr) { |
3878 | 0 | if (callExpr->getNumArgs() != 1) { |
3879 | 0 | return nullptr; |
3880 | 0 | } |
3881 | | |
3882 | 0 | StringLiteral *S = nullptr; |
3883 | 0 | auto *arg = callExpr->getArg(0); |
3884 | 0 | if (arg->getStmtClass() == Stmt::ImplicitCastExprClass) { |
3885 | 0 | ImplicitCastExpr *I = static_cast<ImplicitCastExpr *>(arg); |
3886 | 0 | auto *subExpr = I->getSubExprAsWritten(); |
3887 | |
|
3888 | 0 | if (subExpr->getStmtClass() != Stmt::StringLiteralClass) { |
3889 | 0 | return nullptr; |
3890 | 0 | } |
3891 | | |
3892 | 0 | S = static_cast<StringLiteral *>(I->getSubExprAsWritten()); |
3893 | 0 | } else if (arg->getStmtClass() == Stmt::StringLiteralClass) { |
3894 | 0 | S = static_cast<StringLiteral *>(callExpr->getArg(0)); |
3895 | 0 | } else { |
3896 | 0 | return nullptr; |
3897 | 0 | } |
3898 | 0 | return S; |
3899 | 0 | } |
3900 | | |
3901 | | struct ExprEvalResult { |
3902 | | CXEvalResultKind EvalType; |
3903 | | union { |
3904 | | unsigned long long unsignedVal; |
3905 | | long long intVal; |
3906 | | double floatVal; |
3907 | | char *stringVal; |
3908 | | } EvalData; |
3909 | | bool IsUnsignedInt; |
3910 | 13 | ~ExprEvalResult() { |
3911 | 13 | if (EvalType != CXEval_UnExposed && EvalType != CXEval_Float && |
3912 | 13 | EvalType != CXEval_Int) { |
3913 | 1 | delete[] EvalData.stringVal; |
3914 | 1 | } |
3915 | 13 | } |
3916 | | }; |
3917 | | |
3918 | 13 | void clang_EvalResult_dispose(CXEvalResult E) { |
3919 | 13 | delete static_cast<ExprEvalResult *>(E); |
3920 | 13 | } |
3921 | | |
3922 | 13 | CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E) { |
3923 | 13 | if (!E) { |
3924 | 0 | return CXEval_UnExposed; |
3925 | 0 | } |
3926 | 13 | return ((ExprEvalResult *)E)->EvalType; |
3927 | 13 | } |
3928 | | |
3929 | 0 | int clang_EvalResult_getAsInt(CXEvalResult E) { |
3930 | 0 | return clang_EvalResult_getAsLongLong(E); |
3931 | 0 | } |
3932 | | |
3933 | 5 | long long clang_EvalResult_getAsLongLong(CXEvalResult E) { |
3934 | 5 | if (!E) { |
3935 | 0 | return 0; |
3936 | 0 | } |
3937 | 5 | ExprEvalResult *Result = (ExprEvalResult *)E; |
3938 | 5 | if (Result->IsUnsignedInt) |
3939 | 0 | return Result->EvalData.unsignedVal; |
3940 | 5 | return Result->EvalData.intVal; |
3941 | 5 | } |
3942 | | |
3943 | 12 | unsigned clang_EvalResult_isUnsignedInt(CXEvalResult E) { |
3944 | 12 | return ((ExprEvalResult *)E)->IsUnsignedInt; |
3945 | 12 | } |
3946 | | |
3947 | 7 | unsigned long long clang_EvalResult_getAsUnsigned(CXEvalResult E) { |
3948 | 7 | if (!E) { |
3949 | 0 | return 0; |
3950 | 0 | } |
3951 | | |
3952 | 7 | ExprEvalResult *Result = (ExprEvalResult *)E; |
3953 | 7 | if (Result->IsUnsignedInt) |
3954 | 7 | return Result->EvalData.unsignedVal; |
3955 | 0 | return Result->EvalData.intVal; |
3956 | 7 | } |
3957 | | |
3958 | 0 | double clang_EvalResult_getAsDouble(CXEvalResult E) { |
3959 | 0 | if (!E) { |
3960 | 0 | return 0; |
3961 | 0 | } |
3962 | 0 | return ((ExprEvalResult *)E)->EvalData.floatVal; |
3963 | 0 | } |
3964 | | |
3965 | 0 | const char *clang_EvalResult_getAsStr(CXEvalResult E) { |
3966 | 0 | if (!E) { |
3967 | 0 | return nullptr; |
3968 | 0 | } |
3969 | 0 | return ((ExprEvalResult *)E)->EvalData.stringVal; |
3970 | 0 | } |
3971 | | |
3972 | 14 | static const ExprEvalResult *evaluateExpr(Expr *expr, CXCursor C) { |
3973 | 14 | Expr::EvalResult ER; |
3974 | 14 | ASTContext &ctx = getCursorContext(C); |
3975 | 14 | if (!expr) |
3976 | 0 | return nullptr; |
3977 | | |
3978 | 14 | expr = expr->IgnoreParens(); |
3979 | 14 | if (expr->isValueDependent()) |
3980 | 1 | return nullptr; |
3981 | 13 | if (!expr->EvaluateAsRValue(ER, ctx)) |
3982 | 0 | return nullptr; |
3983 | | |
3984 | 13 | QualType rettype; |
3985 | 13 | CallExpr *callExpr; |
3986 | 13 | auto result = std::make_unique<ExprEvalResult>(); |
3987 | 13 | result->EvalType = CXEval_UnExposed; |
3988 | 13 | result->IsUnsignedInt = false; |
3989 | | |
3990 | 13 | if (ER.Val.isInt()) { |
3991 | 12 | result->EvalType = CXEval_Int; |
3992 | | |
3993 | 12 | auto &val = ER.Val.getInt(); |
3994 | 12 | if (val.isUnsigned()) { |
3995 | 7 | result->IsUnsignedInt = true; |
3996 | 7 | result->EvalData.unsignedVal = val.getZExtValue(); |
3997 | 7 | } else { |
3998 | 5 | result->EvalData.intVal = val.getExtValue(); |
3999 | 5 | } |
4000 | | |
4001 | 12 | return result.release(); |
4002 | 12 | } |
4003 | | |
4004 | 1 | if (ER.Val.isFloat()) { |
4005 | 0 | llvm::SmallVector<char, 100> Buffer; |
4006 | 0 | ER.Val.getFloat().toString(Buffer); |
4007 | 0 | std::string floatStr(Buffer.data(), Buffer.size()); |
4008 | 0 | result->EvalType = CXEval_Float; |
4009 | 0 | bool ignored; |
4010 | 0 | llvm::APFloat apFloat = ER.Val.getFloat(); |
4011 | 0 | apFloat.convert(llvm::APFloat::IEEEdouble(), |
4012 | 0 | llvm::APFloat::rmNearestTiesToEven, &ignored); |
4013 | 0 | result->EvalData.floatVal = apFloat.convertToDouble(); |
4014 | 0 | return result.release(); |
4015 | 0 | } |
4016 | | |
4017 | 1 | if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) { |
4018 | 0 | const auto *I = cast<ImplicitCastExpr>(expr); |
4019 | 0 | auto *subExpr = I->getSubExprAsWritten(); |
4020 | 0 | if (subExpr->getStmtClass() == Stmt::StringLiteralClass || |
4021 | 0 | subExpr->getStmtClass() == Stmt::ObjCStringLiteralClass) { |
4022 | 0 | const StringLiteral *StrE = nullptr; |
4023 | 0 | const ObjCStringLiteral *ObjCExpr; |
4024 | 0 | ObjCExpr = dyn_cast<ObjCStringLiteral>(subExpr); |
4025 | |
|
4026 | 0 | if (ObjCExpr) { |
4027 | 0 | StrE = ObjCExpr->getString(); |
4028 | 0 | result->EvalType = CXEval_ObjCStrLiteral; |
4029 | 0 | } else { |
4030 | 0 | StrE = cast<StringLiteral>(I->getSubExprAsWritten()); |
4031 | 0 | result->EvalType = CXEval_StrLiteral; |
4032 | 0 | } |
4033 | |
|
4034 | 0 | std::string strRef(StrE->getString().str()); |
4035 | 0 | result->EvalData.stringVal = new char[strRef.size() + 1]; |
4036 | 0 | strncpy((char *)result->EvalData.stringVal, strRef.c_str(), |
4037 | 0 | strRef.size()); |
4038 | 0 | result->EvalData.stringVal[strRef.size()] = '\0'; |
4039 | 0 | return result.release(); |
4040 | 0 | } |
4041 | 1 | } else if (expr->getStmtClass() == Stmt::ObjCStringLiteralClass || |
4042 | 1 | expr->getStmtClass() == Stmt::StringLiteralClass0 ) { |
4043 | 1 | const StringLiteral *StrE = nullptr; |
4044 | 1 | const ObjCStringLiteral *ObjCExpr; |
4045 | 1 | ObjCExpr = dyn_cast<ObjCStringLiteral>(expr); |
4046 | | |
4047 | 1 | if (ObjCExpr) { |
4048 | 1 | StrE = ObjCExpr->getString(); |
4049 | 1 | result->EvalType = CXEval_ObjCStrLiteral; |
4050 | 1 | } else { |
4051 | 0 | StrE = cast<StringLiteral>(expr); |
4052 | 0 | result->EvalType = CXEval_StrLiteral; |
4053 | 0 | } |
4054 | | |
4055 | 1 | std::string strRef(StrE->getString().str()); |
4056 | 1 | result->EvalData.stringVal = new char[strRef.size() + 1]; |
4057 | 1 | strncpy((char *)result->EvalData.stringVal, strRef.c_str(), strRef.size()); |
4058 | 1 | result->EvalData.stringVal[strRef.size()] = '\0'; |
4059 | 1 | return result.release(); |
4060 | 1 | } |
4061 | | |
4062 | 0 | if (expr->getStmtClass() == Stmt::CStyleCastExprClass) { |
4063 | 0 | CStyleCastExpr *CC = static_cast<CStyleCastExpr *>(expr); |
4064 | |
|
4065 | 0 | rettype = CC->getType(); |
4066 | 0 | if (rettype.getAsString() == "CFStringRef" && |
4067 | 0 | CC->getSubExpr()->getStmtClass() == Stmt::CallExprClass) { |
4068 | |
|
4069 | 0 | callExpr = static_cast<CallExpr *>(CC->getSubExpr()); |
4070 | 0 | StringLiteral *S = getCFSTR_value(callExpr); |
4071 | 0 | if (S) { |
4072 | 0 | std::string strLiteral(S->getString().str()); |
4073 | 0 | result->EvalType = CXEval_CFStr; |
4074 | |
|
4075 | 0 | result->EvalData.stringVal = new char[strLiteral.size() + 1]; |
4076 | 0 | strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(), |
4077 | 0 | strLiteral.size()); |
4078 | 0 | result->EvalData.stringVal[strLiteral.size()] = '\0'; |
4079 | 0 | return result.release(); |
4080 | 0 | } |
4081 | 0 | } |
4082 | |
|
4083 | 0 | } else if (expr->getStmtClass() == Stmt::CallExprClass) { |
4084 | 0 | callExpr = static_cast<CallExpr *>(expr); |
4085 | 0 | rettype = callExpr->getCallReturnType(ctx); |
4086 | |
|
4087 | 0 | if (rettype->isVectorType() || callExpr->getNumArgs() > 1) |
4088 | 0 | return nullptr; |
4089 | | |
4090 | 0 | if (rettype->isIntegralType(ctx) || rettype->isRealFloatingType()) { |
4091 | 0 | if (callExpr->getNumArgs() == 1 && |
4092 | 0 | !callExpr->getArg(0)->getType()->isIntegralType(ctx)) |
4093 | 0 | return nullptr; |
4094 | 0 | } else if (rettype.getAsString() == "CFStringRef") { |
4095 | |
|
4096 | 0 | StringLiteral *S = getCFSTR_value(callExpr); |
4097 | 0 | if (S) { |
4098 | 0 | std::string strLiteral(S->getString().str()); |
4099 | 0 | result->EvalType = CXEval_CFStr; |
4100 | 0 | result->EvalData.stringVal = new char[strLiteral.size() + 1]; |
4101 | 0 | strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(), |
4102 | 0 | strLiteral.size()); |
4103 | 0 | result->EvalData.stringVal[strLiteral.size()] = '\0'; |
4104 | 0 | return result.release(); |
4105 | 0 | } |
4106 | 0 | } |
4107 | 0 | } else if (expr->getStmtClass() == Stmt::DeclRefExprClass) { |
4108 | 0 | DeclRefExpr *D = static_cast<DeclRefExpr *>(expr); |
4109 | 0 | ValueDecl *V = D->getDecl(); |
4110 | 0 | if (V->getKind() == Decl::Function) { |
4111 | 0 | std::string strName = V->getNameAsString(); |
4112 | 0 | result->EvalType = CXEval_Other; |
4113 | 0 | result->EvalData.stringVal = new char[strName.size() + 1]; |
4114 | 0 | strncpy(result->EvalData.stringVal, strName.c_str(), strName.size()); |
4115 | 0 | result->EvalData.stringVal[strName.size()] = '\0'; |
4116 | 0 | return result.release(); |
4117 | 0 | } |
4118 | 0 | } |
4119 | | |
4120 | 0 | return nullptr; |
4121 | 0 | } |
4122 | | |
4123 | 9 | static const Expr *evaluateDeclExpr(const Decl *D) { |
4124 | 9 | if (!D) |
4125 | 0 | return nullptr; |
4126 | 9 | if (auto *Var = dyn_cast<VarDecl>(D)) |
4127 | 8 | return Var->getInit(); |
4128 | 1 | else if (auto *Field = dyn_cast<FieldDecl>(D)) |
4129 | 1 | return Field->getInClassInitializer(); |
4130 | 0 | return nullptr; |
4131 | 9 | } |
4132 | | |
4133 | 1 | static const Expr *evaluateCompoundStmtExpr(const CompoundStmt *CS) { |
4134 | 1 | assert(CS && "invalid compound statement"); |
4135 | 1 | for (auto *bodyIterator : CS->body()) { |
4136 | 1 | if (const auto *E = dyn_cast<Expr>(bodyIterator)) |
4137 | 1 | return E; |
4138 | 1 | } |
4139 | 0 | return nullptr; |
4140 | 1 | } |
4141 | | |
4142 | 15 | CXEvalResult clang_Cursor_Evaluate(CXCursor C) { |
4143 | 15 | const Expr *E = nullptr; |
4144 | 15 | if (clang_getCursorKind(C) == CXCursor_CompoundStmt) |
4145 | 1 | E = evaluateCompoundStmtExpr(cast<CompoundStmt>(getCursorStmt(C))); |
4146 | 14 | else if (clang_isDeclaration(C.kind)) |
4147 | 9 | E = evaluateDeclExpr(getCursorDecl(C)); |
4148 | 5 | else if (clang_isExpression(C.kind)) |
4149 | 4 | E = getCursorExpr(C); |
4150 | 15 | if (E) |
4151 | 14 | return const_cast<CXEvalResult>( |
4152 | 14 | reinterpret_cast<const void *>(evaluateExpr(const_cast<Expr *>(E), C))); |
4153 | 1 | return nullptr; |
4154 | 15 | } |
4155 | | |
4156 | 0 | unsigned clang_Cursor_hasAttrs(CXCursor C) { |
4157 | 0 | const Decl *D = getCursorDecl(C); |
4158 | 0 | if (!D) { |
4159 | 0 | return 0; |
4160 | 0 | } |
4161 | | |
4162 | 0 | if (D->hasAttrs()) { |
4163 | 0 | return 1; |
4164 | 0 | } |
4165 | | |
4166 | 0 | return 0; |
4167 | 0 | } |
4168 | 59 | unsigned clang_defaultSaveOptions(CXTranslationUnit TU) { |
4169 | 59 | return CXSaveTranslationUnit_None; |
4170 | 59 | } |
4171 | | |
4172 | | static CXSaveError clang_saveTranslationUnit_Impl(CXTranslationUnit TU, |
4173 | | const char *FileName, |
4174 | 59 | unsigned options) { |
4175 | 59 | CIndexer *CXXIdx = TU->CIdx; |
4176 | 59 | if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing)) |
4177 | 0 | setThreadBackgroundPriority(); |
4178 | | |
4179 | 59 | bool hadError = cxtu::getASTUnit(TU)->Save(FileName); |
4180 | 59 | return hadError ? CXSaveError_Unknown0 : CXSaveError_None; |
4181 | 59 | } |
4182 | | |
4183 | | int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName, |
4184 | 59 | unsigned options) { |
4185 | 59 | LOG_FUNC_SECTION { *Log << TU << ' ' << FileName; }0 |
4186 | | |
4187 | 59 | if (isNotUsableTU(TU)) { |
4188 | 0 | LOG_BAD_TU(TU); |
4189 | 0 | return CXSaveError_InvalidTU; |
4190 | 0 | } |
4191 | | |
4192 | 59 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
4193 | 59 | ASTUnit::ConcurrencyCheck Check(*CXXUnit); |
4194 | 59 | if (!CXXUnit->hasSema()) |
4195 | 0 | return CXSaveError_InvalidTU; |
4196 | | |
4197 | 59 | CXSaveError result; |
4198 | 59 | auto SaveTranslationUnitImpl = [=, &result]() { |
4199 | 59 | result = clang_saveTranslationUnit_Impl(TU, FileName, options); |
4200 | 59 | }; |
4201 | | |
4202 | 59 | if (!CXXUnit->getDiagnostics().hasUnrecoverableErrorOccurred()) { |
4203 | 54 | SaveTranslationUnitImpl(); |
4204 | | |
4205 | 54 | if (getenv("LIBCLANG_RESOURCE_USAGE")) |
4206 | 0 | PrintLibclangResourceUsage(TU); |
4207 | | |
4208 | 54 | return result; |
4209 | 54 | } |
4210 | | |
4211 | | // We have an AST that has invalid nodes due to compiler errors. |
4212 | | // Use a crash recovery thread for protection. |
4213 | | |
4214 | 5 | llvm::CrashRecoveryContext CRC; |
4215 | | |
4216 | 5 | if (!RunSafely(CRC, SaveTranslationUnitImpl)) { |
4217 | 0 | fprintf(stderr, "libclang: crash detected during AST saving: {\n"); |
4218 | 0 | fprintf(stderr, " 'filename' : '%s'\n", FileName); |
4219 | 0 | fprintf(stderr, " 'options' : %d,\n", options); |
4220 | 0 | fprintf(stderr, "}\n"); |
4221 | |
|
4222 | 0 | return CXSaveError_Unknown; |
4223 | |
|
4224 | 5 | } else if (getenv("LIBCLANG_RESOURCE_USAGE")) { |
4225 | 0 | PrintLibclangResourceUsage(TU); |
4226 | 0 | } |
4227 | | |
4228 | 5 | return result; |
4229 | 5 | } |
4230 | | |
4231 | 1.05k | void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) { |
4232 | 1.05k | if (CTUnit) { |
4233 | | // If the translation unit has been marked as unsafe to free, just discard |
4234 | | // it. |
4235 | 1.04k | ASTUnit *Unit = cxtu::getASTUnit(CTUnit); |
4236 | 1.04k | if (Unit && Unit->isUnsafeToFree()) |
4237 | 1 | return; |
4238 | | |
4239 | 1.04k | delete cxtu::getASTUnit(CTUnit); |
4240 | 1.04k | delete CTUnit->StringPool; |
4241 | 1.04k | delete static_cast<CXDiagnosticSetImpl *>(CTUnit->Diagnostics); |
4242 | 1.04k | disposeOverridenCXCursorsPool(CTUnit->OverridenCursorsPool); |
4243 | 1.04k | delete CTUnit->CommentToXML; |
4244 | 1.04k | delete CTUnit; |
4245 | 1.04k | } |
4246 | 1.05k | } |
4247 | | |
4248 | 30 | unsigned clang_suspendTranslationUnit(CXTranslationUnit CTUnit) { |
4249 | 30 | if (CTUnit) { |
4250 | 30 | ASTUnit *Unit = cxtu::getASTUnit(CTUnit); |
4251 | | |
4252 | 30 | if (Unit && Unit->isUnsafeToFree()) |
4253 | 0 | return false; |
4254 | | |
4255 | 30 | Unit->ResetForParse(); |
4256 | 30 | return true; |
4257 | 30 | } |
4258 | | |
4259 | 0 | return false; |
4260 | 30 | } |
4261 | | |
4262 | 819 | unsigned clang_defaultReparseOptions(CXTranslationUnit TU) { |
4263 | 819 | return CXReparse_None; |
4264 | 819 | } |
4265 | | |
4266 | | static CXErrorCode |
4267 | | clang_reparseTranslationUnit_Impl(CXTranslationUnit TU, |
4268 | | ArrayRef<CXUnsavedFile> unsaved_files, |
4269 | 819 | unsigned options) { |
4270 | | // Check arguments. |
4271 | 819 | if (isNotUsableTU(TU)) { |
4272 | 0 | LOG_BAD_TU(TU); |
4273 | 0 | return CXError_InvalidArguments; |
4274 | 0 | } |
4275 | | |
4276 | | // Reset the associated diagnostics. |
4277 | 819 | delete static_cast<CXDiagnosticSetImpl *>(TU->Diagnostics); |
4278 | 819 | TU->Diagnostics = nullptr; |
4279 | | |
4280 | 819 | CIndexer *CXXIdx = TU->CIdx; |
4281 | 819 | if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing)) |
4282 | 0 | setThreadBackgroundPriority(); |
4283 | | |
4284 | 819 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
4285 | 819 | ASTUnit::ConcurrencyCheck Check(*CXXUnit); |
4286 | | |
4287 | 819 | std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles( |
4288 | 819 | new std::vector<ASTUnit::RemappedFile>()); |
4289 | | |
4290 | | // Recover resources if we crash before exiting this function. |
4291 | 819 | llvm::CrashRecoveryContextCleanupRegistrar<std::vector<ASTUnit::RemappedFile>> |
4292 | 819 | RemappedCleanup(RemappedFiles.get()); |
4293 | | |
4294 | 819 | for (auto &UF : unsaved_files) { |
4295 | 12 | std::unique_ptr<llvm::MemoryBuffer> MB = |
4296 | 12 | llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename); |
4297 | 12 | RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release())); |
4298 | 12 | } |
4299 | | |
4300 | 819 | if (!CXXUnit->Reparse(CXXIdx->getPCHContainerOperations(), |
4301 | 819 | *RemappedFiles.get())) |
4302 | 818 | return CXError_Success; |
4303 | 1 | if (isASTReadError(CXXUnit)) |
4304 | 0 | return CXError_ASTReadError; |
4305 | 1 | return CXError_Failure; |
4306 | 1 | } |
4307 | | |
4308 | | int clang_reparseTranslationUnit(CXTranslationUnit TU, |
4309 | | unsigned num_unsaved_files, |
4310 | | struct CXUnsavedFile *unsaved_files, |
4311 | 819 | unsigned options) { |
4312 | 819 | LOG_FUNC_SECTION { *Log << TU; }0 |
4313 | | |
4314 | 819 | if (num_unsaved_files && !unsaved_files12 ) |
4315 | 0 | return CXError_InvalidArguments; |
4316 | | |
4317 | 819 | CXErrorCode result; |
4318 | 819 | auto ReparseTranslationUnitImpl = [=, &result]() { |
4319 | 819 | result = clang_reparseTranslationUnit_Impl( |
4320 | 819 | TU, llvm::makeArrayRef(unsaved_files, num_unsaved_files), options); |
4321 | 819 | }; |
4322 | | |
4323 | 819 | llvm::CrashRecoveryContext CRC; |
4324 | | |
4325 | 819 | if (!RunSafely(CRC, ReparseTranslationUnitImpl)) { |
4326 | 1 | fprintf(stderr, "libclang: crash detected during reparsing\n"); |
4327 | 1 | cxtu::getASTUnit(TU)->setUnsafeToFree(true); |
4328 | 1 | return CXError_Crashed; |
4329 | 818 | } else if (getenv("LIBCLANG_RESOURCE_USAGE")) |
4330 | 0 | PrintLibclangResourceUsage(TU); |
4331 | | |
4332 | 818 | return result; |
4333 | 819 | } |
4334 | | |
4335 | 0 | CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) { |
4336 | 0 | if (isNotUsableTU(CTUnit)) { |
4337 | 0 | LOG_BAD_TU(CTUnit); |
4338 | 0 | return cxstring::createEmpty(); |
4339 | 0 | } |
4340 | | |
4341 | 0 | ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit); |
4342 | 0 | return cxstring::createDup(CXXUnit->getOriginalSourceFileName()); |
4343 | 0 | } |
4344 | | |
4345 | 201 | CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) { |
4346 | 201 | if (isNotUsableTU(TU)) { |
4347 | 0 | LOG_BAD_TU(TU); |
4348 | 0 | return clang_getNullCursor(); |
4349 | 0 | } |
4350 | | |
4351 | 201 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
4352 | 201 | return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU); |
4353 | 201 | } |
4354 | | |
4355 | 2 | CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit) { |
4356 | 2 | if (isNotUsableTU(CTUnit)) { |
4357 | 0 | LOG_BAD_TU(CTUnit); |
4358 | 0 | return nullptr; |
4359 | 0 | } |
4360 | | |
4361 | 2 | CXTargetInfoImpl *impl = new CXTargetInfoImpl(); |
4362 | 2 | impl->TranslationUnit = CTUnit; |
4363 | 2 | return impl; |
4364 | 2 | } |
4365 | | |
4366 | 2 | CXString clang_TargetInfo_getTriple(CXTargetInfo TargetInfo) { |
4367 | 2 | if (!TargetInfo) |
4368 | 0 | return cxstring::createEmpty(); |
4369 | | |
4370 | 2 | CXTranslationUnit CTUnit = TargetInfo->TranslationUnit; |
4371 | 2 | assert(!isNotUsableTU(CTUnit) && |
4372 | 2 | "Unexpected unusable translation unit in TargetInfo"); |
4373 | | |
4374 | 0 | ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit); |
4375 | 2 | std::string Triple = |
4376 | 2 | CXXUnit->getASTContext().getTargetInfo().getTriple().normalize(); |
4377 | 2 | return cxstring::createDup(Triple); |
4378 | 2 | } |
4379 | | |
4380 | 2 | int clang_TargetInfo_getPointerWidth(CXTargetInfo TargetInfo) { |
4381 | 2 | if (!TargetInfo) |
4382 | 0 | return -1; |
4383 | | |
4384 | 2 | CXTranslationUnit CTUnit = TargetInfo->TranslationUnit; |
4385 | 2 | assert(!isNotUsableTU(CTUnit) && |
4386 | 2 | "Unexpected unusable translation unit in TargetInfo"); |
4387 | | |
4388 | 0 | ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit); |
4389 | 2 | return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth(); |
4390 | 2 | } |
4391 | | |
4392 | 2 | void clang_TargetInfo_dispose(CXTargetInfo TargetInfo) { |
4393 | 2 | if (!TargetInfo) |
4394 | 0 | return; |
4395 | | |
4396 | 2 | delete TargetInfo; |
4397 | 2 | } |
4398 | | |
4399 | | //===----------------------------------------------------------------------===// |
4400 | | // CXFile Operations. |
4401 | | //===----------------------------------------------------------------------===// |
4402 | | |
4403 | 68.0k | CXString clang_getFileName(CXFile SFile) { |
4404 | 68.0k | if (!SFile) |
4405 | 54.1k | return cxstring::createNull(); |
4406 | | |
4407 | 13.9k | FileEntry *FEnt = static_cast<FileEntry *>(SFile); |
4408 | 13.9k | return cxstring::createRef(FEnt->getName()); |
4409 | 68.0k | } |
4410 | | |
4411 | 0 | time_t clang_getFileTime(CXFile SFile) { |
4412 | 0 | if (!SFile) |
4413 | 0 | return 0; |
4414 | | |
4415 | 0 | FileEntry *FEnt = static_cast<FileEntry *>(SFile); |
4416 | 0 | return FEnt->getModificationTime(); |
4417 | 0 | } |
4418 | | |
4419 | 473 | CXFile clang_getFile(CXTranslationUnit TU, const char *file_name) { |
4420 | 473 | if (isNotUsableTU(TU)) { |
4421 | 0 | LOG_BAD_TU(TU); |
4422 | 0 | return nullptr; |
4423 | 0 | } |
4424 | | |
4425 | 473 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
4426 | | |
4427 | 473 | FileManager &FMgr = CXXUnit->getFileManager(); |
4428 | 473 | auto File = FMgr.getFile(file_name); |
4429 | 473 | if (!File) |
4430 | 0 | return nullptr; |
4431 | 473 | return const_cast<FileEntry *>(*File); |
4432 | 473 | } |
4433 | | |
4434 | | const char *clang_getFileContents(CXTranslationUnit TU, CXFile file, |
4435 | 0 | size_t *size) { |
4436 | 0 | if (isNotUsableTU(TU)) { |
4437 | 0 | LOG_BAD_TU(TU); |
4438 | 0 | return nullptr; |
4439 | 0 | } |
4440 | | |
4441 | 0 | const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager(); |
4442 | 0 | FileID fid = SM.translateFile(static_cast<FileEntry *>(file)); |
4443 | 0 | llvm::Optional<llvm::MemoryBufferRef> buf = SM.getBufferOrNone(fid); |
4444 | 0 | if (!buf) { |
4445 | 0 | if (size) |
4446 | 0 | *size = 0; |
4447 | 0 | return nullptr; |
4448 | 0 | } |
4449 | 0 | if (size) |
4450 | 0 | *size = buf->getBufferSize(); |
4451 | 0 | return buf->getBufferStart(); |
4452 | 0 | } |
4453 | | |
4454 | 329 | unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU, CXFile file) { |
4455 | 329 | if (isNotUsableTU(TU)) { |
4456 | 0 | LOG_BAD_TU(TU); |
4457 | 0 | return 0; |
4458 | 0 | } |
4459 | | |
4460 | 329 | if (!file) |
4461 | 4 | return 0; |
4462 | | |
4463 | 325 | ASTUnit *CXXUnit = cxtu::getASTUnit(TU); |
4464 | 325 | FileEntry *FEnt = static_cast<FileEntry *>(file); |
4465 | 325 | return CXXUnit->getPreprocessor() |
4466 | 325 | .getHeaderSearchInfo() |
4467 | 325 | .isFileMultipleIncludeGuarded(FEnt); |
4468 | 329 | } |
4469 | | |
4470 | 0 | int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID) { |
4471 | 0 | if (!file || !outID) |
4472 | 0 | return 1; |
4473 | | |
4474 | 0 | FileEntry *FEnt = static_cast<FileEntry *>(file); |
4475 | 0 | const llvm::sys::fs::UniqueID &ID = FEnt->getUniqueID(); |
4476 | 0 | outID->data[0] = ID.getDevice(); |
4477 | 0 | outID->data[1] = ID.getFile(); |
4478 | 0 | outID->data[2] = FEnt->getModificationTime(); |
4479 | 0 | return 0; |
4480 | 0 | } |
4481 | | |
4482 | 0 | int clang_File_isEqual(CXFile file1, CXFile file2) { |
4483 | 0 | if (file1 == file2) |
4484 | 0 | return true; |
4485 | | |
4486 | 0 | if (!file1 || !file2) |
4487 | 0 | return false; |
4488 | | |
4489 | 0 | FileEntry *FEnt1 = static_cast<FileEntry *>(file1); |
4490 | 0 | FileEntry *FEnt2 = static_cast<FileEntry *>(file2); |
4491 | 0 | return FEnt1->getUniqueID() == FEnt2->getUniqueID(); |
4492 | 0 | } |
4493 | | |
4494 | 1 | CXString clang_File_tryGetRealPathName(CXFile SFile) { |
4495 | 1 | if (!SFile) |
4496 | 0 | return cxstring::createNull(); |
4497 | | |
4498 | 1 | FileEntry *FEnt = static_cast<FileEntry *>(SFile); |
4499 | 1 | return cxstring::createRef(FEnt->tryGetRealPathName()); |
4500 | 1 | } |
4501 | | |
4502 | | //===----------------------------------------------------------------------===// |
4503 | | // CXCursor Operations. |
4504 | | //===----------------------------------------------------------------------===// |
4505 | | |
4506 | 38.7k | static const Decl *getDeclFromExpr(const Stmt *E) { |
4507 | 38.7k | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) |
4508 | 2.60k | return getDeclFromExpr(CE->getSubExpr()); |
4509 | | |
4510 | 36.0k | if (const DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E)) |
4511 | 26.5k | return RefExpr->getDecl(); |
4512 | 9.52k | if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) |
4513 | 2.55k | return ME->getMemberDecl(); |
4514 | 6.97k | if (const ObjCIvarRefExpr *RE = dyn_cast<ObjCIvarRefExpr>(E)) |
4515 | 4 | return RE->getDecl(); |
4516 | 6.96k | if (const ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(E)) { |
4517 | 19 | if (PRE->isExplicitProperty()) |
4518 | 10 | return PRE->getExplicitProperty(); |
4519 | | // It could be messaging both getter and setter as in: |
4520 | | // ++myobj.myprop; |
4521 | | // in which case prefer to associate the setter since it is less obvious |
4522 | | // from inspecting the source that the setter is going to get called. |
4523 | 9 | if (PRE->isMessagingSetter()) |
4524 | 6 | return PRE->getImplicitPropertySetter(); |
4525 | 3 | return PRE->getImplicitPropertyGetter(); |
4526 | 9 | } |
4527 | 6.94k | if (const PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E)) |
4528 | 0 | return getDeclFromExpr(POE->getSyntacticForm()); |
4529 | 6.94k | if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(E)) |
4530 | 2 | if (Expr *Src = OVE->getSourceExpr()) |
4531 | 2 | return getDeclFromExpr(Src); |
4532 | | |
4533 | 6.94k | if (const CallExpr *CE = dyn_cast<CallExpr>(E)) |
4534 | 960 | return getDeclFromExpr(CE->getCallee()); |
4535 | 5.98k | if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E)) |
4536 | 198 | if (!CE->isElidable()) |
4537 | 172 | return CE->getConstructor(); |
4538 | 5.81k | if (const CXXInheritedCtorInitExpr *CE = |
4539 | 5.81k | dyn_cast<CXXInheritedCtorInitExpr>(E)) |
4540 | 0 | return CE->getConstructor(); |
4541 | 5.81k | if (const ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(E)) |
4542 | 210 | return OME->getMethodDecl(); |
4543 | | |
4544 | 5.60k | if (const ObjCProtocolExpr *PE = dyn_cast<ObjCProtocolExpr>(E)) |
4545 | 12 | return PE->getProtocol(); |
4546 | 5.59k | if (const SubstNonTypeTemplateParmPackExpr *NTTP = |
4547 | 5.59k | dyn_cast<SubstNonTypeTemplateParmPackExpr>(E)) |
4548 | 0 | return NTTP->getParameterPack(); |
4549 | 5.59k | if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E)) |
4550 | 18 | if (isa<NonTypeTemplateParmDecl>(SizeOfPack->getPack()) || |
4551 | 18 | isa<ParmVarDecl>(SizeOfPack->getPack())) |
4552 | 10 | return SizeOfPack->getPack(); |
4553 | | |
4554 | 5.58k | return nullptr; |
4555 | 5.59k | } |
4556 | | |
4557 | 10.4k | static SourceLocation getLocationFromExpr(const Expr *E) { |
4558 | 10.4k | if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) |
4559 | 2.29k | return getLocationFromExpr(CE->getSubExpr()); |
4560 | | |
4561 | 8.15k | if (const ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E)) |
4562 | 46 | return /*FIXME:*/ Msg->getLeftLoc(); |
4563 | 8.10k | if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) |
4564 | 2.43k | return DRE->getLocation(); |
4565 | 5.66k | if (const MemberExpr *Member = dyn_cast<MemberExpr>(E)) |
4566 | 817 | return Member->getMemberLoc(); |
4567 | 4.84k | if (const ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E)) |
4568 | 0 | return Ivar->getLocation(); |
4569 | 4.84k | if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E)) |
4570 | 0 | return SizeOfPack->getPackLoc(); |
4571 | 4.84k | if (const ObjCPropertyRefExpr *PropRef = dyn_cast<ObjCPropertyRefExpr>(E)) |
4572 | 10 | return PropRef->getLocation(); |
4573 | | |
4574 | 4.83k | return E->getBeginLoc(); |
4575 | 4.84k | } |
4576 | | |
4577 | | extern "C" { |
4578 | | |
4579 | | unsigned clang_visitChildren(CXCursor parent, CXCursorVisitor visitor, |
4580 | 206 | CXClientData client_data) { |
4581 | 206 | CursorVisitor CursorVis(getCursorTU(parent), visitor, client_data, |
4582 | 206 | /*VisitPreprocessorLast=*/false); |
4583 | 206 | return CursorVis.VisitChildren(parent); |
4584 | 206 | } |
4585 | | |
4586 | | #ifndef __has_feature |
4587 | | #define __has_feature(x) 0 |
4588 | | #endif |
4589 | | #if __has_feature(blocks) |
4590 | | typedef enum CXChildVisitResult (^CXCursorVisitorBlock)(CXCursor cursor, |
4591 | | CXCursor parent); |
4592 | | |
4593 | | static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent, |
4594 | 0 | CXClientData client_data) { |
4595 | 0 | CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data; |
4596 | 0 | return block(cursor, parent); |
4597 | 0 | } |
4598 | | #else |
4599 | | // If we are compiled with a compiler that doesn't have native blocks support, |
4600 | | // define and call the block manually, so the |
4601 | | typedef struct _CXChildVisitResult { |
4602 | | void *isa; |
4603 | | int flags; |
4604 | | int reserved; |
4605 | | enum CXChildVisitResult (*invoke)(struct _CXChildVisitResult *, CXCursor, |
4606 | | CXCursor); |
4607 | | } * CXCursorVisitorBlock; |
4608 | | |
4609 | | static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent, |
4610 | | CXClientData client_data) { |
4611 | | CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data; |
4612 | | return block->invoke(block, cursor, parent); |
4613 | | } |
4614 | | #endif |
4615 | | |
4616 | | unsigned clang_visitChildrenWithBlock(CXCursor parent, |
4617 | 0 | CXCursorVisitorBlock block) { |
4618 | 0 | return clang_visitChildren(parent, visitWithBlock, block); |
4619 | 0 | } |
4620 | | |
4621 | 22.3k | static CXString getDeclSpelling(const Decl *D) { |
4622 | 22.3k | if (!D) |
4623 | 0 | return cxstring::createEmpty(); |
4624 | | |
4625 | 22.3k | const NamedDecl *ND = dyn_cast<NamedDecl>(D); |
4626 | 22.3k | if (!ND) { |
4627 | 193 | if (const ObjCPropertyImplDecl *PropImpl = |
4628 | 193 | dyn_cast<ObjCPropertyImplDecl>(D)) |
4629 | 28 | if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl()) |
4630 | 28 | return cxstring::createDup(Property->getIdentifier()->getName()); |
4631 | | |
4632 | 165 | if (const ImportDecl *ImportD = dyn_cast<ImportDecl>(D)) |
4633 | 15 | if (Module *Mod = ImportD->getImportedModule()) |
4634 | 15 | return cxstring::createDup(Mod->getFullModuleName()); |
4635 | | |
4636 | 150 | return cxstring::createEmpty(); |
4637 | 165 | } |
4638 | | |
4639 | 22.1k | if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND)) |
4640 | 516 | return cxstring::createDup(OMD->getSelector().getAsString()); |
4641 | | |
4642 | 21.6k | if (const ObjCCategoryImplDecl *CIMP = dyn_cast<ObjCCategoryImplDecl>(ND)) |
4643 | | // No, this isn't the same as the code below. getIdentifier() is non-virtual |
4644 | | // and returns different names. NamedDecl returns the class name and |
4645 | | // ObjCCategoryImplDecl returns the category name. |
4646 | 5 | return cxstring::createRef(CIMP->getIdentifier()->getNameStart()); |
4647 | | |
4648 | 21.5k | if (isa<UsingDirectiveDecl>(D)) |
4649 | 8 | return cxstring::createEmpty(); |
4650 | | |
4651 | 21.5k | SmallString<1024> S; |
4652 | 21.5k | llvm::raw_svector_ostream os(S); |
4653 | 21.5k | ND->printName(os); |
4654 | | |
4655 | 21.5k | return cxstring::createDup(os.str()); |
4656 | 21.5k | } |
4657 | | |
4658 | 88.7k | CXString clang_getCursorSpelling(CXCursor C) { |
4659 | 88.7k | if (clang_isTranslationUnit(C.kind)) |
4660 | 0 | return clang_getTranslationUnitSpelling(getCursorTU(C)); |
4661 | | |
4662 | 88.7k | if (clang_isReference(C.kind)) { |
4663 | 1.80k | switch (C.kind) { |
4664 | 25 | case CXCursor_ObjCSuperClassRef: { |
4665 | 25 | const ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first; |
4666 | 25 | return cxstring::createRef(Super->getIdentifier()->getNameStart()); |
4667 | 0 | } |
4668 | 215 | case CXCursor_ObjCClassRef: { |
4669 | 215 | const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first; |
4670 | 215 | return cxstring::createRef(Class->getIdentifier()->getNameStart()); |
4671 | 0 | } |
4672 | 29 | case CXCursor_ObjCProtocolRef: { |
4673 | 29 | const ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first; |
4674 | 29 | assert(OID && "getCursorSpelling(): Missing protocol decl"); |
4675 | 0 | return cxstring::createRef(OID->getIdentifier()->getNameStart()); |
4676 | 0 | } |
4677 | 166 | case CXCursor_CXXBaseSpecifier: { |
4678 | 166 | const CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C); |
4679 | 166 | return cxstring::createDup(B->getType().getAsString()); |
4680 | 0 | } |
4681 | 1.02k | case CXCursor_TypeRef: { |
4682 | 1.02k | const TypeDecl *Type = getCursorTypeRef(C).first; |
4683 | 1.02k | assert(Type && "Missing type decl"); |
4684 | | |
4685 | 0 | return cxstring::createDup( |
4686 | 1.02k | getCursorContext(C).getTypeDeclType(Type).getAsString()); |
4687 | 0 | } |
4688 | 138 | case CXCursor_TemplateRef: { |
4689 | 138 | const TemplateDecl *Template = getCursorTemplateRef(C).first; |
4690 | 138 | assert(Template && "Missing template decl"); |
4691 | | |
4692 | 0 | return cxstring::createDup(Template->getNameAsString()); |
4693 | 0 | } |
4694 | | |
4695 | 130 | case CXCursor_NamespaceRef: { |
4696 | 130 | const NamedDecl *NS = getCursorNamespaceRef(C).first; |
4697 | 130 | assert(NS && "Missing namespace decl"); |
4698 | | |
4699 | 0 | return cxstring::createDup(NS->getNameAsString()); |
4700 | 0 | } |
4701 | | |
4702 | 46 | case CXCursor_MemberRef: { |
4703 | 46 | const FieldDecl *Field = getCursorMemberRef(C).first; |
4704 | 46 | assert(Field && "Missing member decl"); |
4705 | | |
4706 | 0 | return cxstring::createDup(Field->getNameAsString()); |
4707 | 0 | } |
4708 | | |
4709 | 2 | case CXCursor_LabelRef: { |
4710 | 2 | const LabelStmt *Label = getCursorLabelRef(C).first; |
4711 | 2 | assert(Label && "Missing label"); |
4712 | | |
4713 | 0 | return cxstring::createRef(Label->getName()); |
4714 | 0 | } |
4715 | | |
4716 | 21 | case CXCursor_OverloadedDeclRef: { |
4717 | 21 | OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first; |
4718 | 21 | if (const Decl *D = Storage.dyn_cast<const Decl *>()) { |
4719 | 6 | if (const NamedDecl *ND = dyn_cast<NamedDecl>(D)) |
4720 | 6 | return cxstring::createDup(ND->getNameAsString()); |
4721 | 0 | return cxstring::createEmpty(); |
4722 | 6 | } |
4723 | 15 | if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>()) |
4724 | 15 | return cxstring::createDup(E->getName().getAsString()); |
4725 | 0 | OverloadedTemplateStorage *Ovl = |
4726 | 0 | Storage.get<OverloadedTemplateStorage *>(); |
4727 | 0 | if (Ovl->size() == 0) |
4728 | 0 | return cxstring::createEmpty(); |
4729 | 0 | return cxstring::createDup((*Ovl->begin())->getNameAsString()); |
4730 | 0 | } |
4731 | | |
4732 | 14 | case CXCursor_VariableRef: { |
4733 | 14 | const VarDecl *Var = getCursorVariableRef(C).first; |
4734 | 14 | assert(Var && "Missing variable decl"); |
4735 | | |
4736 | 0 | return cxstring::createDup(Var->getNameAsString()); |
4737 | 0 | } |
4738 | | |
4739 | 0 | default: |
4740 | 0 | return cxstring::createRef("<not implemented>"); |
4741 | 1.80k | } |
4742 | 1.80k | } |
4743 | | |
4744 | 86.9k | if (clang_isExpression(C.kind)) { |
4745 | 17.4k | const Expr *E = getCursorExpr(C); |
4746 | | |
4747 | 17.4k | if (C.kind == CXCursor_ObjCStringLiteral || |
4748 | 17.4k | C.kind == CXCursor_StringLiteral17.4k ) { |
4749 | 173 | const StringLiteral *SLit; |
4750 | 173 | if (const ObjCStringLiteral *OSL = dyn_cast<ObjCStringLiteral>(E)) { |
4751 | 2 | SLit = OSL->getString(); |
4752 | 171 | } else { |
4753 | 171 | SLit = cast<StringLiteral>(E); |
4754 | 171 | } |
4755 | 173 | SmallString<256> Buf; |
4756 | 173 | llvm::raw_svector_ostream OS(Buf); |
4757 | 173 | SLit->outputString(OS); |
4758 | 173 | return cxstring::createDup(OS.str()); |
4759 | 173 | } |
4760 | | |
4761 | 17.2k | const Decl *D = getDeclFromExpr(getCursorExpr(C)); |
4762 | 17.2k | if (D) |
4763 | 14.6k | return getDeclSpelling(D); |
4764 | 2.63k | return cxstring::createEmpty(); |
4765 | 17.2k | } |
4766 | | |
4767 | 69.4k | if (clang_isStatement(C.kind)) { |
4768 | 851 | const Stmt *S = getCursorStmt(C); |
4769 | 851 | if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) |
4770 | 1 | return cxstring::createRef(Label->getName()); |
4771 | | |
4772 | 850 | return cxstring::createEmpty(); |
4773 | 851 | } |
4774 | | |
4775 | 68.6k | if (C.kind == CXCursor_MacroExpansion) |
4776 | 245 | return cxstring::createRef( |
4777 | 245 | getCursorMacroExpansion(C).getName()->getNameStart()); |
4778 | | |
4779 | 68.3k | if (C.kind == CXCursor_MacroDefinition) |
4780 | 60.0k | return cxstring::createRef( |
4781 | 60.0k | getCursorMacroDefinition(C)->getName()->getNameStart()); |
4782 | | |
4783 | 8.38k | if (C.kind == CXCursor_InclusionDirective) |
4784 | 333 | return cxstring::createDup(getCursorInclusionDirective(C)->getFileName()); |
4785 | | |
4786 | 8.04k | if (clang_isDeclaration(C.kind)) |
4787 | 7.68k | return getDeclSpelling(getCursorDecl(C)); |
4788 | | |
4789 | 363 | if (C.kind == CXCursor_AnnotateAttr) { |
4790 | 15 | const AnnotateAttr *AA = cast<AnnotateAttr>(cxcursor::getCursorAttr(C)); |
4791 | 15 | return cxstring::createDup(AA->getAnnotation()); |
4792 | 15 | } |
4793 | | |
4794 | 348 | if (C.kind == CXCursor_AsmLabelAttr) { |
4795 | 1 | const AsmLabelAttr *AA = cast<AsmLabelAttr>(cxcursor::getCursorAttr(C)); |
4796 | 1 | return cxstring::createDup(AA->getLabel()); |
4797 | 1 | } |
4798 | | |
4799 | 347 | if (C.kind == CXCursor_PackedAttr) { |
4800 | 13 | return cxstring::createRef("packed"); |
4801 | 13 | } |
4802 | | |
4803 | 334 | if (C.kind == CXCursor_VisibilityAttr) { |
4804 | 12 | const VisibilityAttr *AA = cast<VisibilityAttr>(cxcursor::getCursorAttr(C)); |
4805 | 12 | switch (AA->getVisibility()) { |
4806 | 6 | case VisibilityAttr::VisibilityType::Default: |
4807 | 6 | return cxstring::createRef("default"); |
4808 | 4 | case VisibilityAttr::VisibilityType::Hidden: |
4809 | 4 | return cxstring::createRef("hidden"); |
4810 | 2 | case VisibilityAttr::VisibilityType::Protected: |
4811 | 2 | return cxstring::createRef("protected"); |
4812 | 12 | } |
4813 | 0 | llvm_unreachable("unknown visibility type"); |
4814 | 0 | } |
4815 | | |
4816 | 322 | return cxstring::createEmpty(); |
4817 | 334 | } |
4818 | | |
4819 | | CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C, unsigned pieceIndex, |
4820 | 490 | unsigned options) { |
4821 | 490 | if (clang_Cursor_isNull(C)) |
4822 | 0 | return clang_getNullRange(); |
4823 | | |
4824 | 490 | ASTContext &Ctx = getCursorContext(C); |
4825 | | |
4826 | 490 | if (clang_isStatement(C.kind)) { |
4827 | 0 | const Stmt *S = getCursorStmt(C); |
4828 | 0 | if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) { |
4829 | 0 | if (pieceIndex > 0) |
4830 | 0 | return clang_getNullRange(); |
4831 | 0 | return cxloc::translateSourceRange(Ctx, Label->getIdentLoc()); |
4832 | 0 | } |
4833 | | |
4834 | 0 | return clang_getNullRange(); |
4835 | 0 | } |
4836 | | |
4837 | 490 | if (C.kind == CXCursor_ObjCMessageExpr) { |
4838 | 41 | if (const ObjCMessageExpr *ME = |
4839 | 41 | dyn_cast_or_null<ObjCMessageExpr>(getCursorExpr(C))) { |
4840 | 41 | if (pieceIndex >= ME->getNumSelectorLocs()) |
4841 | 20 | return clang_getNullRange(); |
4842 | 21 | return cxloc::translateSourceRange(Ctx, ME->getSelectorLoc(pieceIndex)); |
4843 | 41 | } |
4844 | 41 | } |
4845 | | |
4846 | 449 | if (C.kind == CXCursor_ObjCInstanceMethodDecl || |
4847 | 449 | C.kind == CXCursor_ObjCClassMethodDecl428 ) { |
4848 | 21 | if (const ObjCMethodDecl *MD = |
4849 | 21 | dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(C))) { |
4850 | 21 | if (pieceIndex >= MD->getNumSelectorLocs()) |
4851 | 10 | return clang_getNullRange(); |
4852 | 11 | return cxloc::translateSourceRange(Ctx, MD->getSelectorLoc(pieceIndex)); |
4853 | 21 | } |
4854 | 21 | } |
4855 | | |
4856 | 428 | if (C.kind == CXCursor_ObjCCategoryDecl || |
4857 | 428 | C.kind == CXCursor_ObjCCategoryImplDecl426 ) { |
4858 | 4 | if (pieceIndex > 0) |
4859 | 2 | return clang_getNullRange(); |
4860 | 2 | if (const ObjCCategoryDecl *CD = |
4861 | 2 | dyn_cast_or_null<ObjCCategoryDecl>(getCursorDecl(C))) |
4862 | 1 | return cxloc::translateSourceRange(Ctx, CD->getCategoryNameLoc()); |
4863 | 1 | if (const ObjCCategoryImplDecl *CID = |
4864 | 1 | dyn_cast_or_null<ObjCCategoryImplDecl>(getCursorDecl(C))) |
4865 | 1 | return cxloc::translateSourceRange(Ctx, CID->getCategoryNameLoc()); |
4866 | 1 | } |
4867 | | |
4868 | 424 | if (C.kind == CXCursor_ModuleImportDecl) { |
4869 | 2 | if (pieceIndex > 0) |
4870 | 1 | return clang_getNullRange(); |
4871 | 1 | if (const ImportDecl *ImportD = |
4872 | 1 | dyn_cast_or_null<ImportDecl>(getCursorDecl(C))) { |
4873 | 1 | ArrayRef<SourceLocation> Locs = ImportD->getIdentifierLocs(); |
4874 | 1 | if (!Locs.empty()) |
4875 | 1 | return cxloc::translateSourceRange( |
4876 | 1 | Ctx, SourceRange(Locs.front(), Locs.back())); |
4877 | 1 | } |
4878 | 0 | return clang_getNullRange(); |
4879 | 1 | } |
4880 | | |
4881 | 422 | if (C.kind == CXCursor_CXXMethod || C.kind == CXCursor_Destructor330 || |
4882 | 422 | C.kind == CXCursor_ConversionFunction328 || |
4883 | 422 | C.kind == CXCursor_FunctionDecl326 ) { |
4884 | 110 | if (pieceIndex > 0) |
4885 | 55 | return clang_getNullRange(); |
4886 | 55 | if (const FunctionDecl *FD = |
4887 | 55 | dyn_cast_or_null<FunctionDecl>(getCursorDecl(C))) { |
4888 | 55 | DeclarationNameInfo FunctionName = FD->getNameInfo(); |
4889 | 55 | return cxloc::translateSourceRange(Ctx, FunctionName.getSourceRange()); |
4890 | 55 | } |
4891 | 0 | return clang_getNullRange(); |
4892 | 55 | } |
4893 | | |
4894 | | // FIXME: A CXCursor_InclusionDirective should give the location of the |
4895 | | // filename, but we don't keep track of this. |
4896 | | |
4897 | | // FIXME: A CXCursor_AnnotateAttr should give the location of the annotation |
4898 | | // but we don't keep track of this. |
4899 | | |
4900 | | // FIXME: A CXCursor_AsmLabelAttr should give the location of the label |
4901 | | // but we don't keep track of this. |
4902 | | |
4903 | | // Default handling, give the location of the cursor. |
4904 | | |
4905 | 312 | if (pieceIndex > 0) |
4906 | 156 | return clang_getNullRange(); |
4907 | | |
4908 | 156 | CXSourceLocation CXLoc = clang_getCursorLocation(C); |
4909 | 156 | SourceLocation Loc = cxloc::translateSourceLocation(CXLoc); |
4910 | 156 | return cxloc::translateSourceRange(Ctx, Loc); |
4911 | 312 | } |
4912 | | |
4913 | 1.20k | CXString clang_Cursor_getMangling(CXCursor C) { |
4914 | 1.20k | if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind)) |
4915 | 1.19k | return cxstring::createEmpty(); |
4916 | | |
4917 | | // Mangling only works for functions and variables. |
4918 | 15 | const Decl *D = getCursorDecl(C); |
4919 | 15 | if (!D || !(isa<FunctionDecl>(D) || isa<VarDecl>(D)3 )) |
4920 | 3 | return cxstring::createEmpty(); |
4921 | | |
4922 | 12 | ASTContext &Ctx = D->getASTContext(); |
4923 | 12 | ASTNameGenerator ASTNameGen(Ctx); |
4924 | 12 | return cxstring::createDup(ASTNameGen.getName(D)); |
4925 | 15 | } |
4926 | | |
4927 | 64 | CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) { |
4928 | 64 | if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind)) |
4929 | 0 | return nullptr; |
4930 | | |
4931 | 64 | const Decl *D = getCursorDecl(C); |
4932 | 64 | if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D)43 )) |
4933 | 4 | return nullptr; |
4934 | | |
4935 | 60 | ASTContext &Ctx = D->getASTContext(); |
4936 | 60 | ASTNameGenerator ASTNameGen(Ctx); |
4937 | 60 | std::vector<std::string> Manglings = ASTNameGen.getAllManglings(D); |
4938 | 60 | return cxstring::createSet(Manglings); |
4939 | 64 | } |
4940 | | |
4941 | 64 | CXStringSet *clang_Cursor_getObjCManglings(CXCursor C) { |
4942 | 64 | if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind)) |
4943 | 0 | return nullptr; |
4944 | | |
4945 | 64 | const Decl *D = getCursorDecl(C); |
4946 | 64 | if (!(isa<ObjCInterfaceDecl>(D) || isa<ObjCImplementationDecl>(D)62 )) |
4947 | 60 | return nullptr; |
4948 | | |
4949 | 4 | ASTContext &Ctx = D->getASTContext(); |
4950 | 4 | ASTNameGenerator ASTNameGen(Ctx); |
4951 | 4 | std::vector<std::string> Manglings = ASTNameGen.getAllManglings(D); |
4952 | 4 | return cxstring::createSet(Manglings); |
4953 | 64 | } |
4954 | | |
4955 | 431 | CXPrintingPolicy clang_getCursorPrintingPolicy(CXCursor C) { |
4956 | 431 | if (clang_Cursor_isNull(C)) |
4957 | 0 | return nullptr; |
4958 | 431 | return new PrintingPolicy(getCursorContext(C).getPrintingPolicy()); |
4959 | 431 | } |
4960 | | |
4961 | 431 | void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy) { |
4962 | 431 | if (Policy) |
4963 | 431 | delete static_cast<PrintingPolicy *>(Policy); |
4964 | 431 | } |
4965 | | |
4966 | | unsigned |
4967 | | clang_PrintingPolicy_getProperty(CXPrintingPolicy Policy, |
4968 | 50 | enum CXPrintingPolicyProperty Property) { |
4969 | 50 | if (!Policy) |
4970 | 0 | return 0; |
4971 | | |
4972 | 50 | PrintingPolicy *P = static_cast<PrintingPolicy *>(Policy); |
4973 | 50 | switch (Property) { |
4974 | 2 | case CXPrintingPolicy_Indentation: |
4975 | 2 | return P->Indentation; |
4976 | 2 | case CXPrintingPolicy_SuppressSpecifiers: |
4977 | 2 | return P->SuppressSpecifiers; |
4978 | 2 | case CXPrintingPolicy_SuppressTagKeyword: |
4979 | 2 | return P->SuppressTagKeyword; |
4980 | 2 | case CXPrintingPolicy_IncludeTagDefinition: |
4981 | 2 | return P->IncludeTagDefinition; |
4982 | 2 | case CXPrintingPolicy_SuppressScope: |
4983 | 2 | return P->SuppressScope; |
4984 | 2 | case CXPrintingPolicy_SuppressUnwrittenScope: |
4985 | 2 | return P->SuppressUnwrittenScope; |
4986 | 2 | case CXPrintingPolicy_SuppressInitializers: |
<