Coverage Report

Created: 2023-09-30 09:22

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