Coverage Report

Created: 2021-09-21 08:58

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