Coverage Report

Created: 2022-01-18 06:27

/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
362k
                                          const CharSourceRange &R) {
147
  // We want the last character in this location, so we will adjust the
148
  // location accordingly.
149
362k
  SourceLocation EndLoc = R.getEnd();
150
362k
  bool IsTokenRange = R.isTokenRange();
151
362k
  if (EndLoc.isValid() && 
EndLoc.isMacroID()362k
&&
152
362k
      
!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
362k
  if (IsTokenRange && 
EndLoc.isValid()362k
) {
158
362k
    unsigned Length =
159
362k
        Lexer::MeasureTokenLength(SM.getSpellingLoc(EndLoc), SM, LangOpts);
160
362k
    EndLoc = EndLoc.getLocWithOffset(Length);
161
362k
  }
162
163
362k
  CXSourceRange Result = {
164
362k
      {&SM, &LangOpts}, R.getBegin().getRawEncoding(), EndLoc.getRawEncoding()};
165
362k
  return Result;
166
362k
}
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
91.7k
bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) {
196
91.7k
  if (clang_isInvalid(Cursor.kind))
197
1
    return false;
198
199
91.7k
  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
89.8k
  if (RegionOfInterest.isValid() && 
!CheckedRegionOfInterest11.3k
) {
215
9.26k
    SourceRange Range = getRawCursorExtent(Cursor);
216
9.26k
    if (Range.isInvalid() || 
CompareRegionOfInterest(Range)9.26k
)
217
7.15k
      return false;
218
9.26k
  }
219
220
82.7k
  switch (Visitor(Cursor, Parent, ClientData)) {
221
18
  case CXChildVisit_Break:
222
18
    return true;
223
224
6.58k
  case CXChildVisit_Continue:
225
6.58k
    return false;
226
227
76.1k
  case CXChildVisit_Recurse: {
228
76.1k
    bool ret = VisitChildren(Cursor);
229
76.1k
    if (PostChildrenVisitor)
230
1.20k
      if (PostChildrenVisitor(Cursor, ClientData))
231
0
        return true;
232
76.1k
    return ret;
233
76.1k
  }
234
82.7k
  }
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
90.8k
  for (; First != Last; 
++First81.0k
) {
457
81.0k
    if (!FID.isInvalid() && 
!PPRec.isEntityInFileID(First, FID)9.42k
)
458
3.46k
      continue;
459
460
77.5k
    PreprocessedEntity *PPE = *First;
461
77.5k
    if (!PPE)
462
0
      continue;
463
464
77.5k
    if (MacroExpansion *ME = dyn_cast<MacroExpansion>(PPE)) {
465
5.91k
      if (Visit(MakeMacroExpansionCursor(ME, TU)))
466
1
        return true;
467
468
5.91k
      continue;
469
5.91k
    }
470
471
71.6k
    if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(PPE)) {
472
71.3k
      if (Visit(MakeMacroDefinitionCursor(MD, TU)))
473
0
        return true;
474
475
71.3k
      continue;
476
71.3k
    }
477
478
311
    if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
479
311
      if (Visit(MakeInclusionDirectiveCursor(ID, TU)))
480
0
        return true;
481
482
311
      continue;
483
311
    }
484
311
  }
485
486
9.77k
  return false;
487
9.77k
}
488
489
/// Visit the children of the given cursor.
490
///
491
/// \returns true if the visitation should be aborted, false if it
492
/// should continue.
493
76.3k
bool CursorVisitor::VisitChildren(CXCursor Cursor) {
494
76.3k
  if (clang_isReference(Cursor.kind) &&
495
76.3k
      
Cursor.kind != CXCursor_CXXBaseSpecifier2.03k
) {
496
    // By definition, references have no children.
497
1.91k
    return false;
498
1.91k
  }
499
500
  // Set the Parent field to Cursor, then back to its old value once we're
501
  // done.
502
74.3k
  SetParentRAII SetParent(Parent, StmtParent, Cursor);
503
504
74.3k
  if (clang_isDeclaration(Cursor.kind)) {
505
7.33k
    Decl *D = const_cast<Decl *>(getCursorDecl(Cursor));
506
7.33k
    if (!D)
507
0
      return false;
508
509
7.33k
    return VisitAttributes(D) || Visit(D);
510
7.33k
  }
511
512
67.0k
  if (clang_isStatement(Cursor.kind)) {
513
764
    if (const Stmt *S = getCursorStmt(Cursor))
514
764
      return Visit(S);
515
516
0
    return false;
517
764
  }
518
519
66.2k
  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
65.9k
  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
65.7k
  if (Cursor.kind == CXCursor_CXXBaseSpecifier) {
558
121
    if (const CXXBaseSpecifier *Base = getCursorCXXBaseSpecifier(Cursor)) {
559
121
      if (TypeSourceInfo *BaseTSInfo = Base->getTypeSourceInfo()) {
560
121
        return Visit(BaseTSInfo->getTypeLoc());
561
121
      }
562
121
    }
563
121
  }
564
565
65.5k
  if (Cursor.kind == CXCursor_IBOutletCollectionAttr) {
566
3
    const IBOutletCollectionAttr *A =
567
3
        cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(Cursor));
568
3
    if (const ObjCObjectType *ObjT = A->getInterface()->getAs<ObjCObjectType>())
569
2
      return Visit(cxcursor::MakeCursorObjCClassRef(
570
2
          ObjT->getInterface(),
571
2
          A->getInterfaceLoc()->getTypeLoc().getBeginLoc(), TU));
572
3
  }
573
574
  // If pointing inside a macro definition, check if the token is an identifier
575
  // that was ever defined as a macro. In such a case, create a "pseudo" macro
576
  // expansion cursor for that token.
577
65.5k
  SourceLocation BeginLoc = RegionOfInterest.getBegin();
578
65.5k
  if (Cursor.kind == CXCursor_MacroDefinition &&
579
65.5k
      
BeginLoc == RegionOfInterest.getEnd()64.8k
) {
580
64.8k
    SourceLocation Loc = AU->mapLocationToPreamble(BeginLoc);
581
64.8k
    const MacroInfo *MI =
582
64.8k
        getMacroInfo(cxcursor::getCursorMacroDefinition(Cursor), TU);
583
64.8k
    if (MacroDefinitionRecord *MacroDef =
584
64.8k
            checkForMacroInMacroDefinition(MI, Loc, TU))
585
12
      return Visit(cxcursor::MakeMacroExpansionCursor(MacroDef, BeginLoc, TU));
586
64.8k
  }
587
588
  // Nothing to visit at the moment.
589
65.5k
  return false;
590
65.5k
}
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.71k
Optional<bool> CursorVisitor::shouldVisitCursor(CXCursor Cursor) {
604
7.71k
  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.11k
  return true;
624
7.71k
}
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.79k
  for (; I != E; 
++I7.09k
) {
635
7.37k
    Decl *D = *I;
636
7.37k
    if (D->getLexicalDeclContext() != DC)
637
0
      continue;
638
    // Filter out synthesized property accessor redeclarations.
639
7.37k
    if (isa<ObjCImplDecl>(DC))
640
173
      if (auto *OMD = dyn_cast<ObjCMethodDecl>(D))
641
110
        if (OMD->isSynthesizedAccessorStub())
642
41
          continue;
643
7.33k
    const Optional<bool> V = handleDeclForVisitation(D);
644
7.33k
    if (!V.hasValue())
645
7.05k
      continue;
646
284
    return V.getValue();
647
7.33k
  }
648
1.41k
  return false;
649
1.70k
}
650
651
7.62k
Optional<bool> CursorVisitor::handleDeclForVisitation(const Decl *D) {
652
7.62k
  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.62k
  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.60k
  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.44k
  } 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.60k
  const Optional<bool> V = shouldVisitCursor(Cursor);
678
7.60k
  if (!V.hasValue())
679
1.26k
    return None;
680
6.34k
  if (!V.getValue())
681
277
    return false;
682
6.06k
  if (Visit(Cursor, true))
683
7
    return true;
684
6.05k
  return None;
685
6.06k
}
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.10k
bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) {
785
2.10k
  unsigned NumParamList = DD->getNumTemplateParameterLists();
786
2.10k
  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.10k
  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.10k
  if (NestedNameSpecifierLoc QualifierLoc = DD->getQualifierLoc())
798
1
    if (VisitNestedNameSpecifierLoc(QualifierLoc))
799
0
      return true;
800
801
2.10k
  return false;
802
2.10k
}
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.73k
      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.85k
&&
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.57k
bool CursorVisitor::VisitVarDecl(VarDecl *D) {
921
1.57k
  if (VisitDeclaratorDecl(D))
922
0
    return true;
923
924
1.57k
  if (Expr *Init = D->getInit())
925
262
    return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
926
927
1.30k
  return false;
928
1.57k
}
929
930
37
bool CursorVisitor::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
931
37
  if (VisitDeclaratorDecl(D))
932
0
    return true;
933
934
37
  if (D->hasDefaultArgument() && 
!D->defaultArgumentWasInherited()2
)
935
2
    if (Expr *DefArg = D->getDefaultArgument())
936
2
      return Visit(MakeCXCursor(DefArg, StmtParent, TU, RegionOfInterest));
937
938
35
  return false;
939
37
}
940
941
110
bool CursorVisitor::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
942
  // FIXME: Visit the "outer" template parameter lists on the FunctionDecl
943
  // before visiting these template parameters.
944
110
  if (VisitTemplateParameters(D->getTemplateParameters()))
945
0
    return true;
946
947
110
  auto *FD = D->getTemplatedDecl();
948
110
  return VisitAttributes(FD) || VisitFunctionDecl(FD);
949
110
}
950
951
111
bool CursorVisitor::VisitClassTemplateDecl(ClassTemplateDecl *D) {
952
  // FIXME: Visit the "outer" template parameter lists on the TagDecl
953
  // before visiting these template parameters.
954
111
  if (VisitTemplateParameters(D->getTemplateParameters()))
955
0
    return true;
956
957
111
  auto *CD = D->getTemplatedDecl();
958
111
  return VisitAttributes(CD) || VisitCXXRecordDecl(CD);
959
111
}
960
961
23
bool CursorVisitor::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
962
23
  if (VisitTemplateParameters(D->getTemplateParameters()))
963
0
    return true;
964
965
23
  if (D->hasDefaultArgument() && 
!D->defaultArgumentWasInherited()2
&&
966
23
      
VisitTemplateArgumentLoc(D->getDefaultArgument())2
)
967
0
    return true;
968
969
23
  return false;
970
23
}
971
972
11
bool CursorVisitor::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
973
  // Visit the bound, if it's explicit.
974
11
  if (D->hasExplicitBound()) {
975
8
    if (auto TInfo = D->getTypeSourceInfo()) {
976
8
      if (Visit(TInfo->getTypeLoc()))
977
0
        return true;
978
8
    }
979
8
  }
980
981
11
  return false;
982
11
}
983
984
428
bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) {
985
428
  if (TypeSourceInfo *TSInfo = ND->getReturnTypeSourceInfo())
986
266
    if (Visit(TSInfo->getTypeLoc()))
987
0
      return true;
988
989
428
  for (const auto *P : ND->parameters()) {
990
171
    if (Visit(MakeCXCursor(P, TU, RegionOfInterest)))
991
0
      return true;
992
171
  }
993
994
428
  return ND->isThisDeclarationADefinition() &&
995
428
         
Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest))65
;
996
428
}
997
998
template <typename DeclIt>
999
static void addRangedDeclsInContainer(DeclIt *DI_current, DeclIt DE_current,
1000
                                      SourceManager &SM, SourceLocation EndLoc,
1001
555
                                      SmallVectorImpl<Decl *> &Decls) {
1002
555
  DeclIt next = *DI_current;
1003
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
107
bool CursorVisitor::VisitNamespaceDecl(NamespaceDecl *D) {
1229
107
  return VisitDeclContext(D);
1230
107
}
1231
1232
7
bool CursorVisitor::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
1233
  // Visit nested-name-specifier.
1234
7
  if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
1235
2
    if (VisitNestedNameSpecifierLoc(QualifierLoc))
1236
0
      return true;
1237
1238
7
  return Visit(MakeCursorNamespaceRef(D->getAliasedNamespace(),
1239
7
                                      D->getTargetNameLoc(), TU));
1240
7
}
1241
1242
7
bool CursorVisitor::VisitUsingDecl(UsingDecl *D) {
1243
  // Visit nested-name-specifier.
1244
7
  if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) {
1245
7
    if (VisitNestedNameSpecifierLoc(QualifierLoc))
1246
0
      return true;
1247
7
  }
1248
1249
7
  if (Visit(MakeCursorOverloadedDeclRef(D, D->getLocation(), TU)))
1250
0
    return true;
1251
1252
7
  return VisitDeclarationNameInfo(D->getNameInfo());
1253
7
}
1254
1255
5
bool CursorVisitor::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
1256
  // Visit nested-name-specifier.
1257
5
  if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
1258
1
    if (VisitNestedNameSpecifierLoc(QualifierLoc))
1259
0
      return true;
1260
1261
5
  return Visit(MakeCursorNamespaceRef(D->getNominatedNamespaceAsWritten(),
1262
5
                                      D->getIdentLocation(), TU));
1263
5
}
1264
1265
4
bool CursorVisitor::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1266
  // Visit nested-name-specifier.
1267
4
  if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) {
1268
4
    if (VisitNestedNameSpecifierLoc(QualifierLoc))
1269
0
      return true;
1270
4
  }
1271
1272
4
  return VisitDeclarationNameInfo(D->getNameInfo());
1273
4
}
1274
1275
bool CursorVisitor::VisitUnresolvedUsingTypenameDecl(
1276
3
    UnresolvedUsingTypenameDecl *D) {
1277
  // Visit nested-name-specifier.
1278
3
  if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
1279
3
    if (VisitNestedNameSpecifierLoc(QualifierLoc))
1280
0
      return true;
1281
1282
3
  return false;
1283
3
}
1284
1285
1
bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
1286
1
  if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
1287
0
    return true;
1288
1
  if (StringLiteral *Message = D->getMessage())
1289
1
    if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
1290
0
      return true;
1291
1
  return false;
1292
1
}
1293
1294
41
bool CursorVisitor::VisitFriendDecl(FriendDecl *D) {
1295
41
  if (NamedDecl *FriendD = D->getFriendDecl()) {
1296
32
    if (Visit(MakeCXCursor(FriendD, TU, RegionOfInterest)))
1297
0
      return true;
1298
32
  } else 
if (TypeSourceInfo *9
TI9
= D->getFriendType()) {
1299
9
    if (Visit(TI->getTypeLoc()))
1300
0
      return true;
1301
9
  }
1302
41
  return false;
1303
41
}
1304
1305
1
bool CursorVisitor::VisitDecompositionDecl(DecompositionDecl *D) {
1306
2
  for (auto *B : D->bindings()) {
1307
2
    if (Visit(MakeCXCursor(B, TU, RegionOfInterest)))
1308
0
      return true;
1309
2
  }
1310
1
  return VisitVarDecl(D);
1311
1
}
1312
1313
3.59k
bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) {
1314
3.59k
  switch (Name.getName().getNameKind()) {
1315
3.36k
  case clang::DeclarationName::Identifier:
1316
3.37k
  case clang::DeclarationName::CXXLiteralOperatorName:
1317
3.37k
  case clang::DeclarationName::CXXDeductionGuideName:
1318
3.49k
  case clang::DeclarationName::CXXOperatorName:
1319
3.49k
  case clang::DeclarationName::CXXUsingDirective:
1320
3.49k
    return false;
1321
1322
95
  case clang::DeclarationName::CXXConstructorName:
1323
95
  case clang::DeclarationName::CXXDestructorName:
1324
102
  case clang::DeclarationName::CXXConversionFunctionName:
1325
102
    if (TypeSourceInfo *TSInfo = Name.getNamedTypeInfo())
1326
7
      return Visit(TSInfo->getTypeLoc());
1327
95
    return false;
1328
1329
0
  case clang::DeclarationName::ObjCZeroArgSelector:
1330
0
  case clang::DeclarationName::ObjCOneArgSelector:
1331
0
  case clang::DeclarationName::ObjCMultiArgSelector:
1332
    // FIXME: Per-identifier location info?
1333
0
    return false;
1334
3.59k
  }
1335
1336
0
  llvm_unreachable("Invalid DeclarationName::Kind!");
1337
0
}
1338
1339
bool CursorVisitor::VisitNestedNameSpecifier(NestedNameSpecifier *NNS,
1340
0
                                             SourceRange Range) {
1341
  // FIXME: This whole routine is a hack to work around the lack of proper
1342
  // source information in nested-name-specifiers (PR5791). Since we do have
1343
  // a beginning source location, we can visit the first component of the
1344
  // nested-name-specifier, if it's a single-token component.
1345
0
  if (!NNS)
1346
0
    return false;
1347
1348
  // Get the first component in the nested-name-specifier.
1349
0
  while (NestedNameSpecifier *Prefix = NNS->getPrefix())
1350
0
    NNS = Prefix;
1351
1352
0
  switch (NNS->getKind()) {
1353
0
  case NestedNameSpecifier::Namespace:
1354
0
    return Visit(
1355
0
        MakeCursorNamespaceRef(NNS->getAsNamespace(), Range.getBegin(), TU));
1356
1357
0
  case NestedNameSpecifier::NamespaceAlias:
1358
0
    return Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(),
1359
0
                                        Range.getBegin(), TU));
1360
1361
0
  case NestedNameSpecifier::TypeSpec: {
1362
    // If the type has a form where we know that the beginning of the source
1363
    // range matches up with a reference cursor. Visit the appropriate reference
1364
    // cursor.
1365
0
    const Type *T = NNS->getAsType();
1366
0
    if (const TypedefType *Typedef = dyn_cast<TypedefType>(T))
1367
0
      return Visit(MakeCursorTypeRef(Typedef->getDecl(), Range.getBegin(), TU));
1368
0
    if (const TagType *Tag = dyn_cast<TagType>(T))
1369
0
      return Visit(MakeCursorTypeRef(Tag->getDecl(), Range.getBegin(), TU));
1370
0
    if (const TemplateSpecializationType *TST =
1371
0
            dyn_cast<TemplateSpecializationType>(T))
1372
0
      return VisitTemplateName(TST->getTemplateName(), Range.getBegin());
1373
0
    break;
1374
0
  }
1375
1376
0
  case NestedNameSpecifier::TypeSpecWithTemplate:
1377
0
  case NestedNameSpecifier::Global:
1378
0
  case NestedNameSpecifier::Identifier:
1379
0
  case NestedNameSpecifier::Super:
1380
0
    break;
1381
0
  }
1382
1383
0
  return false;
1384
0
}
1385
1386
bool CursorVisitor::VisitNestedNameSpecifierLoc(
1387
376
    NestedNameSpecifierLoc Qualifier) {
1388
376
  SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
1389
650
  for (; Qualifier; 
Qualifier = Qualifier.getPrefix()274
)
1390
274
    Qualifiers.push_back(Qualifier);
1391
1392
650
  while (!Qualifiers.empty()) {
1393
274
    NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
1394
274
    NestedNameSpecifier *NNS = Q.getNestedNameSpecifier();
1395
274
    switch (NNS->getKind()) {
1396
135
    case NestedNameSpecifier::Namespace:
1397
135
      if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(),
1398
135
                                       Q.getLocalBeginLoc(), TU)))
1399
0
        return true;
1400
1401
135
      break;
1402
1403
135
    case NestedNameSpecifier::NamespaceAlias:
1404
17
      if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(),
1405
17
                                       Q.getLocalBeginLoc(), TU)))
1406
0
        return true;
1407
1408
17
      break;
1409
1410
104
    case NestedNameSpecifier::TypeSpec:
1411
106
    case NestedNameSpecifier::TypeSpecWithTemplate:
1412
106
      if (Visit(Q.getTypeLoc()))
1413
0
        return true;
1414
1415
106
      break;
1416
1417
106
    case NestedNameSpecifier::Global:
1418
16
    case NestedNameSpecifier::Identifier:
1419
16
    case NestedNameSpecifier::Super:
1420
16
      break;
1421
274
    }
1422
274
  }
1423
1424
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.54k
bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
1528
3.54k
  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.54k
  QualType VisitType;
1533
3.54k
  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.3k
#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1549
68.3k
#include 
"clang/Basic/AArch64SVEACLETypes.def"1.39k
1550
68.3k
#define PPC_VECTOR_TYPE(Name, Id, Size) 
case BuiltinType::Id:2.78k
1551
68.3k
#include 
"clang/Basic/PPCTypes.def"1.39k
1552
92.0k
#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1553
92.0k
#include 
"clang/Basic/RISCVVTypes.def"1.39k
1554
92.0k
#define BUILTIN_TYPE(Id, SingletonId)
1555
92.0k
#define SIGNED_TYPE(Id, SingletonId) 
case BuiltinType::Id:57.3k
1556
92.0k
#define UNSIGNED_TYPE(Id, SingletonId) 
case BuiltinType::Id:55.3k
1557
92.0k
#define FLOATING_TYPE(Id, SingletonId) 
case BuiltinType::Id:27.8k
1558
92.0k
#define PLACEHOLDER_TYPE(Id, SingletonId) 
case BuiltinType::Id:34.9k
1559
92.0k
#include 
"clang/AST/BuiltinTypes.def"1.39k
1560
3.49k
    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.54k
  }
1574
1575
3.54k
  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.49k
  return false;
1582
3.54k
}
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
639
bool CursorVisitor::VisitTagTypeLoc(TagTypeLoc TL) {
1593
639
  if (TL.isDefinition())
1594
69
    return Visit(MakeCXCursor(TL.getDecl(), TU, RegionOfInterest));
1595
1596
570
  return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
1597
639
}
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
42
bool CursorVisitor::VisitParenTypeLoc(ParenTypeLoc TL) {
1642
42
  return Visit(TL.getInnerLoc());
1643
42
}
1644
1645
0
bool CursorVisitor::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) {
1646
0
  return Visit(TL.getInnerLoc());
1647
0
}
1648
1649
287
bool CursorVisitor::VisitPointerTypeLoc(PointerTypeLoc TL) {
1650
287
  return Visit(TL.getPointeeLoc());
1651
287
}
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
2
bool CursorVisitor::VisitUsingTypeLoc(UsingTypeLoc TL) { return false; }
1670
1671
9
bool CursorVisitor::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
1672
9
  return Visit(TL.getModifiedLoc());
1673
9
}
1674
1675
bool CursorVisitor::VisitFunctionTypeLoc(FunctionTypeLoc TL,
1676
1.92k
                                         bool SkipResultType) {
1677
1.92k
  if (!SkipResultType && 
Visit(TL.getReturnLoc())64
)
1678
0
    return true;
1679
1680
3.42k
  
for (unsigned I = 0, N = TL.getNumParams(); 1.92k
I != N;
++I1.50k
)
1681
1.50k
    if (Decl *D = TL.getParam(I))
1682
1.50k
      if (Visit(MakeCXCursor(D, TU, RegionOfInterest)))
1683
0
        return true;
1684
1685
1.92k
  return false;
1686
1.92k
}
1687
1688
66
bool CursorVisitor::VisitArrayTypeLoc(ArrayTypeLoc TL) {
1689
66
  if (Visit(TL.getElementLoc()))
1690
0
    return true;
1691
1692
66
  if (Expr *Size = TL.getSizeExpr())
1693
39
    return Visit(MakeCXCursor(Size, StmtParent, TU, RegionOfInterest));
1694
1695
27
  return false;
1696
66
}
1697
1698
0
bool CursorVisitor::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
1699
0
  return Visit(TL.getOriginalLoc());
1700
0
}
1701
1702
0
bool CursorVisitor::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
1703
0
  return Visit(TL.getOriginalLoc());
1704
0
}
1705
1706
bool CursorVisitor::VisitDeducedTemplateSpecializationTypeLoc(
1707
0
    DeducedTemplateSpecializationTypeLoc TL) {
1708
0
  if (VisitTemplateName(TL.getTypePtr()->getTemplateName(),
1709
0
                        TL.getTemplateNameLoc()))
1710
0
    return true;
1711
1712
0
  return false;
1713
0
}
1714
1715
bool CursorVisitor::VisitTemplateSpecializationTypeLoc(
1716
152
    TemplateSpecializationTypeLoc TL) {
1717
  // Visit the template name.
1718
152
  if (VisitTemplateName(TL.getTypePtr()->getTemplateName(),
1719
152
                        TL.getTemplateNameLoc()))
1720
0
    return true;
1721
1722
  // Visit the template arguments.
1723
350
  
for (unsigned I = 0, N = TL.getNumArgs(); 152
I != N;
++I198
)
1724
198
    if (VisitTemplateArgumentLoc(TL.getArgLoc(I)))
1725
0
      return true;
1726
1727
152
  return false;
1728
152
}
1729
1730
0
bool CursorVisitor::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
1731
0
  return Visit(MakeCXCursor(TL.getUnderlyingExpr(), StmtParent, TU));
1732
0
}
1733
1734
0
bool CursorVisitor::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
1735
0
  if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo())
1736
0
    return Visit(TSInfo->getTypeLoc());
1737
1738
0
  return false;
1739
0
}
1740
1741
0
bool CursorVisitor::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
1742
0
  if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo())
1743
0
    return Visit(TSInfo->getTypeLoc());
1744
1745
0
  return false;
1746
0
}
1747
1748
21
bool CursorVisitor::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
1749
21
  return VisitNestedNameSpecifierLoc(TL.getQualifierLoc());
1750
21
}
1751
1752
bool CursorVisitor::VisitDependentTemplateSpecializationTypeLoc(
1753
4
    DependentTemplateSpecializationTypeLoc TL) {
1754
  // Visit the nested-name-specifier, if there is one.
1755
4
  if (TL.getQualifierLoc() && VisitNestedNameSpecifierLoc(TL.getQualifierLoc()))
1756
0
    return true;
1757
1758
  // Visit the template arguments.
1759
8
  
for (unsigned I = 0, N = TL.getNumArgs(); 4
I != N;
++I4
)
1760
4
    if (VisitTemplateArgumentLoc(TL.getArgLoc(I)))
1761
0
      return true;
1762
1763
4
  return false;
1764
4
}
1765
1766
264
bool CursorVisitor::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
1767
264
  if (VisitNestedNameSpecifierLoc(TL.getQualifierLoc()))
1768
0
    return true;
1769
1770
264
  return Visit(TL.getNamedTypeLoc());
1771
264
}
1772
1773
1
bool CursorVisitor::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
1774
1
  return Visit(TL.getPatternLoc());
1775
1
}
1776
1777
1
bool CursorVisitor::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
1778
1
  if (Expr *E = TL.getUnderlyingExpr())
1779
1
    return Visit(MakeCXCursor(E, StmtParent, TU));
1780
1781
0
  return false;
1782
1
}
1783
1784
7
bool CursorVisitor::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
1785
7
  return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
1786
7
}
1787
1788
3
bool CursorVisitor::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
1789
3
  return Visit(TL.getValueLoc());
1790
3
}
1791
1792
2
bool CursorVisitor::VisitPipeTypeLoc(PipeTypeLoc TL) {
1793
2
  return Visit(TL.getValueLoc());
1794
2
}
1795
1796
#define DEFAULT_TYPELOC_IMPL(CLASS, PARENT)                                    \
1797
1.02k
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
1.02k
    return Visit##PARENT##Loc(TL);                                             \
1799
1.02k
  }
Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitComplexTypeLoc(clang::ComplexTypeLoc)
clang::cxcursor::CursorVisitor::VisitConstantArrayTypeLoc(clang::ConstantArrayTypeLoc)
Line
Count
Source
1797
31
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
31
    return Visit##PARENT##Loc(TL);                                             \
1799
31
  }
clang::cxcursor::CursorVisitor::VisitIncompleteArrayTypeLoc(clang::IncompleteArrayTypeLoc)
Line
Count
Source
1797
27
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
27
    return Visit##PARENT##Loc(TL);                                             \
1799
27
  }
clang::cxcursor::CursorVisitor::VisitVariableArrayTypeLoc(clang::VariableArrayTypeLoc)
Line
Count
Source
1797
5
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
5
    return Visit##PARENT##Loc(TL);                                             \
1799
5
  }
clang::cxcursor::CursorVisitor::VisitDependentSizedArrayTypeLoc(clang::DependentSizedArrayTypeLoc)
Line
Count
Source
1797
3
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
3
    return Visit##PARENT##Loc(TL);                                             \
1799
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
1797
117
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
117
    return Visit##PARENT##Loc(TL);                                             \
1799
117
  }
clang::cxcursor::CursorVisitor::VisitExtVectorTypeLoc(clang::ExtVectorTypeLoc)
Line
Count
Source
1797
114
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
114
    return Visit##PARENT##Loc(TL);                                             \
1799
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
1797
61
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
61
    return Visit##PARENT##Loc(TL);                                             \
1799
61
  }
clang::cxcursor::CursorVisitor::VisitFunctionNoProtoTypeLoc(clang::FunctionNoProtoTypeLoc)
Line
Count
Source
1797
3
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
3
    return Visit##PARENT##Loc(TL);                                             \
1799
3
  }
clang::cxcursor::CursorVisitor::VisitRecordTypeLoc(clang::RecordTypeLoc)
Line
Count
Source
1797
612
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
612
    return Visit##PARENT##Loc(TL);                                             \
1799
612
  }
clang::cxcursor::CursorVisitor::VisitEnumTypeLoc(clang::EnumTypeLoc)
Line
Count
Source
1797
27
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
27
    return Visit##PARENT##Loc(TL);                                             \
1799
27
  }
clang::cxcursor::CursorVisitor::VisitSubstTemplateTypeParmTypeLoc(clang::SubstTemplateTypeParmTypeLoc)
Line
Count
Source
1797
3
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
3
    return Visit##PARENT##Loc(TL);                                             \
1799
3
  }
Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitSubstTemplateTypeParmPackTypeLoc(clang::SubstTemplateTypeParmPackTypeLoc)
clang::cxcursor::CursorVisitor::VisitAutoTypeLoc(clang::AutoTypeLoc)
Line
Count
Source
1797
24
  bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) {               \
1798
24
    return Visit##PARENT##Loc(TL);                                             \
1799
24
  }
Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitBitIntTypeLoc(clang::BitIntTypeLoc)
Unexecuted instantiation: clang::cxcursor::CursorVisitor::VisitDependentBitIntTypeLoc(clang::DependentBitIntTypeLoc)
1800
1801
DEFAULT_TYPELOC_IMPL(Complex, Type)
1802
DEFAULT_TYPELOC_IMPL(ConstantArray, ArrayType)
1803
DEFAULT_TYPELOC_IMPL(IncompleteArray, ArrayType)
1804
DEFAULT_TYPELOC_IMPL(VariableArray, ArrayType)
1805
DEFAULT_TYPELOC_IMPL(DependentSizedArray, ArrayType)
1806
DEFAULT_TYPELOC_IMPL(DependentAddressSpace, Type)
1807
DEFAULT_TYPELOC_IMPL(DependentVector, Type)
1808
DEFAULT_TYPELOC_IMPL(DependentSizedExtVector, Type)
1809
DEFAULT_TYPELOC_IMPL(Vector, Type)
1810
DEFAULT_TYPELOC_IMPL(ExtVector, VectorType)
1811
DEFAULT_TYPELOC_IMPL(ConstantMatrix, MatrixType)
1812
DEFAULT_TYPELOC_IMPL(DependentSizedMatrix, MatrixType)
1813
DEFAULT_TYPELOC_IMPL(FunctionProto, FunctionType)
1814
DEFAULT_TYPELOC_IMPL(FunctionNoProto, FunctionType)
1815
DEFAULT_TYPELOC_IMPL(Record, TagType)
1816
DEFAULT_TYPELOC_IMPL(Enum, TagType)
1817
DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParm, Type)
1818
DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParmPack, Type)
1819
DEFAULT_TYPELOC_IMPL(Auto, Type)
1820
DEFAULT_TYPELOC_IMPL(BitInt, Type)
1821
DEFAULT_TYPELOC_IMPL(DependentBitInt, Type)
1822
1823
611
bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) {
1824
  // Visit the nested-name-specifier, if present.
1825
611
  if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
1826
1
    if (VisitNestedNameSpecifierLoc(QualifierLoc))
1827
0
      return true;
1828
1829
611
  if (D->isCompleteDefinition()) {
1830
573
    for (const auto &I : D->bases()) {
1831
125
      if (Visit(cxcursor::MakeCursorCXXBaseSpecifier(&I, TU)))
1832
0
        return true;
1833
125
    }
1834
573
  }
1835
1836
611
  return VisitTagDecl(D);
1837
611
}
1838
1839
7.55k
bool CursorVisitor::VisitAttributes(Decl *D) {
1840
7.55k
  for (const auto *I : D->attrs())
1841
188
    if ((TU->ParsingOptions & CXTranslationUnit_VisitImplicitAttributes ||
1842
188
         
!I->isImplicit()186
) &&
1843
188
        
Visit(MakeCXCursor(I, D, TU))180
)
1844
0
      return true;
1845
1846
7.55k
  return false;
1847
7.55k
}
1848
1849
//===----------------------------------------------------------------------===//
1850
// Data-recursive visitor methods.
1851
//===----------------------------------------------------------------------===//
1852
1853
namespace {
1854
#define DEF_JOB(NAME, DATA, KIND)                                              \
1855
  class NAME : public VisitorJob {                                             \
1856
  public:                                                                      \
1857
    NAME(const DATA *d, CXCursor parent)                                       \
1858
26.4k
        : VisitorJob(parent, VisitorJob::KIND, d) {}                           \
CIndex.cpp:(anonymous namespace)::PostChildrenVisit::PostChildrenVisit(void const*, CXCursor)
Line
Count
Source
1858
6.31k
        : VisitorJob(parent, VisitorJob::KIND, d) {}                           \
CIndex.cpp:(anonymous namespace)::StmtVisit::StmtVisit(clang::Stmt const*, CXCursor)
Line
Count
Source
1858
18.4k
        : VisitorJob(parent, VisitorJob::KIND, d) {}                           \
CIndex.cpp:(anonymous namespace)::DeclRefExprParts::DeclRefExprParts(clang::DeclRefExpr const*, CXCursor)
Line
Count
Source
1858
1.20k
        : VisitorJob(parent, VisitorJob::KIND, d) {}                           \
CIndex.cpp:(anonymous namespace)::LambdaExprParts::LambdaExprParts(clang::LambdaExpr const*, CXCursor)
Line
Count
Source
1858
4
        : VisitorJob(parent, VisitorJob::KIND, d) {}                           \
CIndex.cpp:(anonymous namespace)::MemberExprParts::MemberExprParts(clang::MemberExpr const*, CXCursor)
Line
Count
Source
1858
527
        : VisitorJob(parent, VisitorJob::KIND, d) {}                           \
CIndex.cpp:(anonymous namespace)::OverloadExprParts::OverloadExprParts(clang::OverloadExpr const*, CXCursor)
Line
Count
Source
1858
15
        : VisitorJob(parent, VisitorJob::KIND, d) {}                           \
CIndex.cpp:(anonymous namespace)::SizeOfPackExprParts::SizeOfPackExprParts(clang::SizeOfPackExpr const*, CXCursor)
Line
Count
Source
1858
2
        : VisitorJob(parent, VisitorJob::KIND, d) {}                           \
1859
20.1k
    static bool classof(const VisitorJob *VJ) {                                \
1860
20.1k
      return VJ->getKind() == KIND;                                            \
1861
20.1k
    }                                                                          \
CIndex.cpp:(anonymous namespace)::StmtVisit::classof(clang::cxcursor::VisitorJob const*)
Line
Count
Source
1859
18.4k
    static bool classof(const VisitorJob *VJ) {                                \
1860
18.4k
      return VJ->getKind() == KIND;                                            \
1861
18.4k
    }                                                                          \
CIndex.cpp:(anonymous namespace)::MemberExprParts::classof(clang::cxcursor::VisitorJob const*)
Line
Count
Source
1859
527
    static bool classof(const VisitorJob *VJ) {                                \
1860
527
      return VJ->getKind() == KIND;                                            \
1861
527
    }                                                                          \
CIndex.cpp:(anonymous namespace)::DeclRefExprParts::classof(clang::cxcursor::VisitorJob const*)
Line
Count
Source
1859
1.20k
    static bool classof(const VisitorJob *VJ) {                                \
1860
1.20k
      return VJ->getKind() == KIND;                                            \
1861
1.20k
    }                                                                          \
CIndex.cpp:(anonymous namespace)::OverloadExprParts::classof(clang::cxcursor::VisitorJob const*)
Line
Count
Source
1859
15
    static bool classof(const VisitorJob *VJ) {                                \
1860
15
      return VJ->getKind() == KIND;                                            \
1861
15
    }                                                                          \
CIndex.cpp:(anonymous namespace)::SizeOfPackExprParts::classof(clang::cxcursor::VisitorJob const*)
Line
Count
Source
1859
2
    static bool classof(const VisitorJob *VJ) {                                \
1860
2
      return VJ->getKind() == KIND;                                            \
1861
2
    }                                                                          \
CIndex.cpp:(anonymous namespace)::LambdaExprParts::classof(clang::cxcursor::VisitorJob const*)
Line
Count
Source
1859
4
    static bool classof(const VisitorJob *VJ) {                                \
1860
4
      return VJ->getKind() == KIND;                                            \
1861
4
    }                                                                          \
Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::PostChildrenVisit::classof(clang::cxcursor::VisitorJob const*)
1862
20.1k
    const DATA *get() const { return static_cast<const DATA *>(data[0]); }     \
CIndex.cpp:(anonymous namespace)::StmtVisit::get() const
Line
Count
Source
1862
18.4k
    const DATA *get() const { return static_cast<const DATA *>(data[0]); }     \
CIndex.cpp:(anonymous namespace)::MemberExprParts::get() const
Line
Count
Source
1862
527
    const DATA *get() const { return static_cast<const DATA *>(data[0]); }     \
CIndex.cpp:(anonymous namespace)::DeclRefExprParts::get() const
Line
Count
Source
1862
1.20k
    const DATA *get() const { return static_cast<const DATA *>(data[0]); }     \
CIndex.cpp:(anonymous namespace)::OverloadExprParts::get() const
Line
Count
Source
1862
15
    const DATA *get() const { return static_cast<const DATA *>(data[0]); }     \
CIndex.cpp:(anonymous namespace)::SizeOfPackExprParts::get() const
Line
Count
Source
1862
2
    const DATA *get() const { return static_cast<const DATA *>(data[0]); }     \
CIndex.cpp:(anonymous namespace)::LambdaExprParts::get() const
Line
Count
Source
1862
4
    const DATA *get() const { return static_cast<const DATA *>(data[0]); }     \
Unexecuted instantiation: CIndex.cpp:(anonymous namespace)::PostChildrenVisit::get() const
1863
  };
1864
1865
DEF_JOB(StmtVisit, Stmt, StmtVisitKind)
1866
DEF_JOB(MemberExprParts, MemberExpr, MemberExprPartsKind)
1867
DEF_JOB(DeclRefExprParts, DeclRefExpr, DeclRefExprPartsKind)
1868
DEF_JOB(OverloadExprParts, OverloadExpr, OverloadExprPartsKind)
1869
DEF_JOB(SizeOfPackExprParts, SizeOfPackExpr, SizeOfPackExprPartsKind)
1870
DEF_JOB(LambdaExprParts, LambdaExpr, LambdaExprPartsKind)
1871
DEF_JOB(PostChildrenVisit, void, PostChildrenVisitKind)
1872
#undef DEF_JOB
1873
1874
class ExplicitTemplateArgsVisit : public VisitorJob {
1875
public:
1876
  ExplicitTemplateArgsVisit(const TemplateArgumentLoc *Begin,
1877
                            const TemplateArgumentLoc *End, CXCursor parent)
1878
      : VisitorJob(parent, VisitorJob::ExplicitTemplateArgsVisitKind, Begin,
1879
12
                   End) {}
1880
12
  static bool classof(const VisitorJob *VJ) {
1881
12
    return VJ->getKind() == ExplicitTemplateArgsVisitKind;
1882
12
  }
1883
12
  const TemplateArgumentLoc *begin() const {
1884
12
    return static_cast<const TemplateArgumentLoc *>(data[0]);
1885
12
  }
1886
12
  const TemplateArgumentLoc *end() {
1887
12
    return static_cast<const TemplateArgumentLoc *>(data[1]);
1888
12
  }
1889
};
1890
class DeclVisit : public VisitorJob {
1891
public:
1892
  DeclVisit(const Decl *D, CXCursor parent, bool isFirst)
1893
      : VisitorJob(parent, VisitorJob::DeclVisitKind, D,
1894
356
                   isFirst ? (void *)1 : (void *)nullptr) {}
1895
712
  static bool classof(const VisitorJob *VJ) {
1896
712
    return VJ->getKind() == DeclVisitKind;
1897
712
  }
1898
356
  const Decl *get() const { return static_cast<const Decl *>(data[0]); }
1899
356
  bool isFirst() const { return data[1] != nullptr; }
1900
};
1901
class TypeLocVisit : public VisitorJob {
1902
public:
1903
  TypeLocVisit(TypeLoc tl, CXCursor parent)
1904
      : VisitorJob(parent, VisitorJob::TypeLocVisitKind,
1905
186
                   tl.getType().getAsOpaquePtr(), tl.getOpaqueData()) {}
1906
1907
186
  static bool classof(const VisitorJob *VJ) {
1908
186
    return VJ->getKind() == TypeLocVisitKind;
1909
186
  }
1910
1911
186
  TypeLoc get() const {
1912
186
    QualType T = QualType::getFromOpaquePtr(data[0]);
1913
186
    return TypeLoc(T, const_cast<void *>(data[1]));
1914
186
  }
1915
};
1916
1917
class LabelRefVisit : public VisitorJob {
1918
public:
1919
  LabelRefVisit(LabelDecl *LD, SourceLocation labelLoc, CXCursor parent)
1920
      : VisitorJob(parent, VisitorJob::LabelRefVisitKind, LD,
1921
3
                   labelLoc.getPtrEncoding()) {}
1922
1923
5
  static bool classof(const VisitorJob *VJ) {
1924
5
    return VJ->getKind() == VisitorJob::LabelRefVisitKind;
1925
5
  }
1926
3
  const LabelDecl *get() const {
1927
3
    return static_cast<const LabelDecl *>(data[0]);
1928
3
  }
1929
2
  SourceLocation getLoc() const {
1930
2
    return SourceLocation::getFromPtrEncoding(data[1]);
1931
2
  }
1932
};
1933
1934
class NestedNameSpecifierLocVisit : public VisitorJob {
1935
public:
1936
  NestedNameSpecifierLocVisit(NestedNameSpecifierLoc Qualifier, CXCursor parent)
1937
      : VisitorJob(parent, VisitorJob::NestedNameSpecifierLocVisitKind,
1938
                   Qualifier.getNestedNameSpecifier(),
1939
6
                   Qualifier.getOpaqueData()) {}
1940
1941
6
  static bool classof(const VisitorJob *VJ) {
1942
6
    return VJ->getKind() == VisitorJob::NestedNameSpecifierLocVisitKind;
1943
6
  }
1944
1945
6
  NestedNameSpecifierLoc get() const {
1946
6
    return NestedNameSpecifierLoc(
1947
6
        const_cast<NestedNameSpecifier *>(
1948
6
            static_cast<const NestedNameSpecifier *>(data[0])),
1949
6
        const_cast<void *>(data[1]));
1950
6
  }
1951
};
1952
1953
class DeclarationNameInfoVisit : public VisitorJob {
1954
public:
1955
  DeclarationNameInfoVisit(const Stmt *S, CXCursor parent)
1956
6
      : VisitorJob(parent, VisitorJob::DeclarationNameInfoVisitKind, S) {}
1957
6
  static bool classof(const VisitorJob *VJ) {
1958
6
    return VJ->getKind() == VisitorJob::DeclarationNameInfoVisitKind;
1959
6
  }
1960
6
  DeclarationNameInfo get() const {
1961
6
    const Stmt *S = static_cast<const Stmt *>(data[0]);
1962
6
    switch (S->getStmtClass()) {
1963
0
    default:
1964
0
      llvm_unreachable("Unhandled Stmt");
1965
2
    case clang::Stmt::MSDependentExistsStmtClass:
1966
2
      return cast<MSDependentExistsStmt>(S)->getNameInfo();
1967
3
    case Stmt::CXXDependentScopeMemberExprClass:
1968
3
      return cast<CXXDependentScopeMemberExpr>(S)->getMemberNameInfo();
1969
1
    case Stmt::DependentScopeDeclRefExprClass:
1970
1
      return cast<DependentScopeDeclRefExpr>(S)->getNameInfo();
1971
0
    case Stmt::OMPCriticalDirectiveClass:
1972
0
      return cast<OMPCriticalDirective>(S)->getDirectiveName();
1973
6
    }
1974
6
  }
1975
};
1976
class MemberRefVisit : public VisitorJob {
1977
public:
1978
  MemberRefVisit(const FieldDecl *D, SourceLocation L, CXCursor parent)
1979
      : VisitorJob(parent, VisitorJob::MemberRefVisitKind, D,
1980
18
                   L.getPtrEncoding()) {}
1981
18
  static bool classof(const VisitorJob *VJ) {
1982
18
    return VJ->getKind() == VisitorJob::MemberRefVisitKind;
1983
18
  }
1984
18
  const FieldDecl *get() const {
1985
18
    return static_cast<const FieldDecl *>(data[0]);
1986
18
  }
1987
18
  SourceLocation getLoc() const {
1988
18
    return SourceLocation::getFromRawEncoding(
1989
18
        (SourceLocation::UIntTy)(uintptr_t)data[1]);
1990
18
  }
1991
};
1992
class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> {
1993
  friend class OMPClauseEnqueue;
1994
  VisitorWorkList &WL;
1995
  CXCursor Parent;
1996
1997
public:
1998
  EnqueueVisitor(VisitorWorkList &wl, CXCursor parent)
1999
12.9k
      : WL(wl), Parent(parent) {}
2000
2001
  void VisitAddrLabelExpr(const AddrLabelExpr *E);
2002
  void VisitBlockExpr(const BlockExpr *B);
2003
  void VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
2004
  void VisitCompoundStmt(const CompoundStmt *S);
2005
0
  void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { /* Do nothing. */
2006
0
  }
2007
  void VisitMSDependentExistsStmt(const MSDependentExistsStmt *S);
2008
  void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E);
2009
  void VisitCXXNewExpr(const CXXNewExpr *E);
2010
  void VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
2011
  void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *E);
2012
  void VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E);
2013
  void VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
2014
  void VisitCXXTypeidExpr(const CXXTypeidExpr *E);
2015
  void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *E);
2016
  void VisitCXXUuidofExpr(const CXXUuidofExpr *E);
2017
  void VisitCXXCatchStmt(const CXXCatchStmt *S);
2018
  void VisitCXXForRangeStmt(const CXXForRangeStmt *S);
2019
  void VisitDeclRefExpr(const DeclRefExpr *D);
2020
  void VisitDeclStmt(const DeclStmt *S);
2021
  void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E);
2022
  void VisitDesignatedInitExpr(const DesignatedInitExpr *E);
2023
  void VisitExplicitCastExpr(const ExplicitCastExpr *E);
2024
  void VisitForStmt(const ForStmt *FS);
2025
  void VisitGotoStmt(const GotoStmt *GS);
2026
  void VisitIfStmt(const IfStmt *If);
2027
  void VisitInitListExpr(const InitListExpr *IE);
2028
  void VisitMemberExpr(const MemberExpr *M);
2029
  void VisitOffsetOfExpr(const OffsetOfExpr *E);
2030
  void VisitObjCEncodeExpr(const ObjCEncodeExpr *E);
2031
  void VisitObjCMessageExpr(const ObjCMessageExpr *M);
2032
  void VisitOverloadExpr(const OverloadExpr *E);
2033
  void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
2034
  void VisitStmt(const Stmt *S);
2035
  void VisitSwitchStmt(const SwitchStmt *S);
2036
  void VisitWhileStmt(const WhileStmt *W);
2037
  void VisitTypeTraitExpr(const TypeTraitExpr *E);
2038
  void VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E);
2039
  void VisitExpressionTraitExpr(const ExpressionTraitExpr *E);
2040
  void VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U);
2041
  void VisitVAArgExpr(const VAArgExpr *E);
2042
  void VisitSizeOfPackExpr(const SizeOfPackExpr *E);
2043
  void VisitPseudoObjectExpr(const PseudoObjectExpr *E);
2044
  void VisitOpaqueValueExpr(const OpaqueValueExpr *E);
2045
  void VisitLambdaExpr(const LambdaExpr *E);
2046
  void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
2047
  void VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *D);
2048
  void VisitOMPLoopDirective(const OMPLoopDirective *D);
2049
  void VisitOMPParallelDirective(const OMPParallelDirective *D);
2050
  void VisitOMPSimdDirective(const OMPSimdDirective *D);
2051
  void
2052
  VisitOMPLoopTransformationDirective(const OMPLoopTransformationDirective *D);
2053
  void VisitOMPTileDirective(const OMPTileDirective *D);
2054
  void VisitOMPUnrollDirective(const OMPUnrollDirective *D);
2055
  void VisitOMPForDirective(const OMPForDirective *D);
2056
  void VisitOMPForSimdDirective(const OMPForSimdDirective *D);
2057
  void VisitOMPSectionsDirective(const OMPSectionsDirective *D);
2058
  void VisitOMPSectionDirective(const OMPSectionDirective *D);
2059
  void VisitOMPSingleDirective(const OMPSingleDirective *D);
2060
  void VisitOMPMasterDirective(const OMPMasterDirective *D);
2061
  void VisitOMPCriticalDirective(const OMPCriticalDirective *D);
2062
  void VisitOMPParallelForDirective(const OMPParallelForDirective *D);
2063
  void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D);
2064
  void VisitOMPParallelMasterDirective(const OMPParallelMasterDirective *D);
2065
  void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D);
2066
  void VisitOMPTaskDirective(const OMPTaskDirective *D);
2067
  void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D);
2068
  void VisitOMPBarrierDirective(const OMPBarrierDirective *D);
2069
  void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D);
2070
  void VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *D);
2071
  void
2072
  VisitOMPCancellationPointDirective(const OMPCancellationPointDirective *D);
2073
  void VisitOMPCancelDirective(const OMPCancelDirective *D);
2074
  void VisitOMPFlushDirective(const OMPFlushDirective *D);
2075
  void VisitOMPDepobjDirective(const OMPDepobjDirective *D);
2076
  void VisitOMPScanDirective(const OMPScanDirective *D);
2077
  void VisitOMPOrderedDirective(const OMPOrderedDirective *D);
2078
  void VisitOMPAtomicDirective(const OMPAtomicDirective *D);
2079
  void VisitOMPTargetDirective(const OMPTargetDirective *D);
2080
  void VisitOMPTargetDataDirective(const OMPTargetDataDirective *D);
2081
  void VisitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective *D);
2082
  void VisitOMPTargetExitDataDirective(const OMPTargetExitDataDirective *D);
2083
  void VisitOMPTargetParallelDirective(const OMPTargetParallelDirective *D);
2084
  void
2085
  VisitOMPTargetParallelForDirective(const OMPTargetParallelForDirective *D);
2086
  void VisitOMPTeamsDirective(const OMPTeamsDirective *D);
2087
  void VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D);
2088
  void VisitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective *D);
2089
  void VisitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective *D);
2090
  void
2091
  VisitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective *D);
2092
  void VisitOMPParallelMasterTaskLoopDirective(
2093
      const OMPParallelMasterTaskLoopDirective *D);
2094
  void VisitOMPParallelMasterTaskLoopSimdDirective(
2095
      const OMPParallelMasterTaskLoopSimdDirective *D);
2096
  void VisitOMPDistributeDirective(const OMPDistributeDirective *D);
2097
  void VisitOMPDistributeParallelForDirective(
2098
      const OMPDistributeParallelForDirective *D);
2099
  void VisitOMPDistributeParallelForSimdDirective(
2100
      const OMPDistributeParallelForSimdDirective *D);
2101
  void VisitOMPDistributeSimdDirective(const OMPDistributeSimdDirective *D);
2102
  void VisitOMPTargetParallelForSimdDirective(
2103
      const OMPTargetParallelForSimdDirective *D);
2104
  void VisitOMPTargetSimdDirective(const OMPTargetSimdDirective *D);
2105
  void VisitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective *D);
2106
  void VisitOMPTeamsDistributeSimdDirective(
2107
      const OMPTeamsDistributeSimdDirective *D);
2108
  void VisitOMPTeamsDistributeParallelForSimdDirective(
2109
      const OMPTeamsDistributeParallelForSimdDirective *D);
2110
  void VisitOMPTeamsDistributeParallelForDirective(
2111
      const OMPTeamsDistributeParallelForDirective *D);
2112
  void VisitOMPTargetTeamsDirective(const OMPTargetTeamsDirective *D);
2113
  void VisitOMPTargetTeamsDistributeDirective(
2114
      const OMPTargetTeamsDistributeDirective *D);
2115
  void VisitOMPTargetTeamsDistributeParallelForDirective(
2116
      const OMPTargetTeamsDistributeParallelForDirective *D);
2117
  void VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2118
      const OMPTargetTeamsDistributeParallelForSimdDirective *D);
2119
  void VisitOMPTargetTeamsDistributeSimdDirective(
2120
      const OMPTargetTeamsDistributeSimdDirective *D);
2121
2122
private:
2123
  void AddDeclarationNameInfo(const Stmt *S);
2124
  void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier);
2125
  void AddExplicitTemplateArgs(const TemplateArgumentLoc *A,
2126
                               unsigned NumTemplateArgs);
2127
  void AddMemberRef(const FieldDecl *D, SourceLocation L);
2128
  void AddStmt(const Stmt *S);
2129
  void AddDecl(const Decl *D, bool isFirst = true);
2130
  void AddTypeLoc(TypeSourceInfo *TI);
2131
  void EnqueueChildren(const Stmt *S);
2132
  void EnqueueChildren(const OMPClause *S);
2133
};
2134
} // namespace
2135
2136
6
void EnqueueVisitor::AddDeclarationNameInfo(const Stmt *S) {
2137
  // 'S' should always be non-null, since it comes from the
2138
  // statement we are visiting.
2139
6
  WL.push_back(DeclarationNameInfoVisit(S, Parent));
2140
6
}
2141
2142
void EnqueueVisitor::AddNestedNameSpecifierLoc(
2143
6
    NestedNameSpecifierLoc Qualifier) {
2144
6
  if (Qualifier)
2145
6
    WL.push_back(NestedNameSpecifierLocVisit(Qualifier, Parent));
2146
6
}
2147
2148
18.4k
void EnqueueVisitor::AddStmt(const Stmt *S) {
2149
18.4k
  if (S)
2150
18.4k
    WL.push_back(StmtVisit(S, Parent));
2151
18.4k
}
2152
376
void EnqueueVisitor::AddDecl(const Decl *D, bool isFirst) {
2153
376
  if (D)
2154
356
    WL.push_back(DeclVisit(D, Parent, isFirst));
2155
376
}
2156
void EnqueueVisitor::AddExplicitTemplateArgs(const TemplateArgumentLoc *A,
2157
12
                                             unsigned NumTemplateArgs) {
2158
12
  WL.push_back(ExplicitTemplateArgsVisit(A, A + NumTemplateArgs, Parent));
2159
12
}
2160
18
void EnqueueVisitor::AddMemberRef(const FieldDecl *D, SourceLocation L) {
2161
18
  if (D)
2162
18
    WL.push_back(MemberRefVisit(D, L, Parent));
2163
18
}
2164
313
void EnqueueVisitor::AddTypeLoc(TypeSourceInfo *TI) {
2165
313
  if (TI)
2166
186
    WL.push_back(TypeLocVisit(TI->getTypeLoc(), Parent));
2167
313
}
2168
5.08k
void EnqueueVisitor::EnqueueChildren(const Stmt *S) {
2169
5.08k
  unsigned size = WL.size();
2170
5.66k
  for (const Stmt *SubStmt : S->children()) {
2171
5.66k
    AddStmt(SubStmt);
2172
5.66k
  }
2173
5.08k
  if (size == WL.size())
2174
1.00k
    return;
2175
  // Now reverse the entries we just added.  This will match the DFS
2176
  // ordering performed by the worklist.
2177
4.08k
  VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
2178
4.08k
  std::reverse(I, E);
2179
4.08k
}
2180
namespace {
2181
class OMPClauseEnqueue : public ConstOMPClauseVisitor<OMPClauseEnqueue> {
2182
  EnqueueVisitor *Visitor;
2183
  /// Process clauses with list of variables.
2184
  template <typename T> void VisitOMPClauseList(T *Node);
2185
2186
public:
2187
1
  OMPClauseEnqueue(EnqueueVisitor *Visitor) : Visitor(Visitor) {}
2188
#define GEN_CLANG_CLAUSE_CLASS
2189
#define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C);
2190
#include "llvm/Frontend/OpenMP/OMP.inc"
2191
  void VisitOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
2192
  void VisitOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
2193
};
2194
2195
void OMPClauseEnqueue::VisitOMPClauseWithPreInit(
2196
0
    const OMPClauseWithPreInit *C) {
2197
0
  Visitor->AddStmt(C->getPreInitStmt());
2198
0
}
2199
2200
void OMPClauseEnqueue::VisitOMPClauseWithPostUpdate(
2201
0
    const OMPClauseWithPostUpdate *C) {
2202
0
  VisitOMPClauseWithPreInit(C);
2203
0
  Visitor->AddStmt(C->getPostUpdateExpr());
2204
0
}
2205
2206
0
void OMPClauseEnqueue::VisitOMPIfClause(const OMPIfClause *C) {
2207
0
  VisitOMPClauseWithPreInit(C);
2208
0
  Visitor->AddStmt(C->getCondition());
2209
0
}
2210
2211
0
void OMPClauseEnqueue::VisitOMPFinalClause(const OMPFinalClause *C) {
2212
0
  Visitor->AddStmt(C->getCondition());
2213
0
}
2214
2215
0
void OMPClauseEnqueue::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
2216
0
  VisitOMPClauseWithPreInit(C);
2217
0
  Visitor->AddStmt(C->getNumThreads());
2218
0
}
2219
2220
0
void OMPClauseEnqueue::VisitOMPSafelenClause(const OMPSafelenClause *C) {
2221
0
  Visitor->AddStmt(C->getSafelen());
2222
0
}
2223
2224
0
void OMPClauseEnqueue::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
2225
0
  Visitor->AddStmt(C->getSimdlen());
2226
0
}
2227
2228
1
void OMPClauseEnqueue::VisitOMPSizesClause(const OMPSizesClause *C) {
2229
1
  for (auto E : C->getSizesRefs())
2230
1
    Visitor->AddStmt(E);
2231
1
}
2232
2233
0
void OMPClauseEnqueue::VisitOMPFullClause(const OMPFullClause *C) {}
2234
2235
0
void OMPClauseEnqueue::VisitOMPPartialClause(const OMPPartialClause *C) {
2236
0
  Visitor->AddStmt(C->getFactor());
2237
0
}
2238
2239
0
void OMPClauseEnqueue::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
2240
0
  Visitor->AddStmt(C->getAllocator());
2241
0
}
2242
2243
0
void OMPClauseEnqueue::VisitOMPCollapseClause(const OMPCollapseClause *C) {
2244
0
  Visitor->AddStmt(C->getNumForLoops());
2245
0
}
2246
2247
0
void OMPClauseEnqueue::VisitOMPDefaultClause(const OMPDefaultClause *C) {}
2248
2249
0
void OMPClauseEnqueue::VisitOMPProcBindClause(const OMPProcBindClause *C) {}
2250
2251
0
void OMPClauseEnqueue::VisitOMPScheduleClause(const OMPScheduleClause *C) {
2252
0
  VisitOMPClauseWithPreInit(C);
2253
0
  Visitor->AddStmt(C->getChunkSize());
2254
0
}
2255
2256
0
void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *C) {
2257
0
  Visitor->AddStmt(C->getNumForLoops());
2258
0
}
2259
2260
0
void OMPClauseEnqueue::VisitOMPDetachClause(const OMPDetachClause *C) {
2261
0
  Visitor->AddStmt(C->getEventHandler());
2262
0
}
2263
2264
0
void OMPClauseEnqueue::VisitOMPNowaitClause(const OMPNowaitClause *) {}
2265
2266
0
void OMPClauseEnqueue::VisitOMPUntiedClause(const OMPUntiedClause *) {}
2267
2268
0
void OMPClauseEnqueue::VisitOMPMergeableClause(const OMPMergeableClause *) {}
2269
2270
0
void OMPClauseEnqueue::VisitOMPReadClause(const OMPReadClause *) {}
2271
2272
0
void OMPClauseEnqueue::VisitOMPWriteClause(const OMPWriteClause *) {}
2273
2274
0
void OMPClauseEnqueue::VisitOMPUpdateClause(const OMPUpdateClause *) {}
2275
2276
0
void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {}
2277
2278
0
void OMPClauseEnqueue::VisitOMPCompareClause(const OMPCompareClause *) {}
2279
2280
0
void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
2281
2282
0
void OMPClauseEnqueue::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
2283
2284
0
void OMPClauseEnqueue::VisitOMPAcquireClause(const OMPAcquireClause *) {}
2285
2286
0
void OMPClauseEnqueue::VisitOMPReleaseClause(const OMPReleaseClause *) {}
2287
2288
0
void OMPClauseEnqueue::VisitOMPRelaxedClause(const OMPRelaxedClause *) {}
2289
2290
0
void OMPClauseEnqueue::VisitOMPThreadsClause(const OMPThreadsClause *) {}
2291
2292
0
void OMPClauseEnqueue::VisitOMPSIMDClause(const OMPSIMDClause *) {}
2293
2294
0
void OMPClauseEnqueue::VisitOMPNogroupClause(const OMPNogroupClause *) {}
2295
2296
0
void OMPClauseEnqueue::VisitOMPInitClause(const OMPInitClause *C) {
2297
0
  VisitOMPClauseList(C);
2298
0
}
2299
2300
0
void OMPClauseEnqueue::VisitOMPUseClause(const OMPUseClause *C) {
2301
0
  Visitor->AddStmt(C->getInteropVar());
2302
0
}
2303
2304
0
void OMPClauseEnqueue::VisitOMPDestroyClause(const OMPDestroyClause *C) {
2305
0
  if (C->getInteropVar())
2306
0
    Visitor->AddStmt(C->getInteropVar());
2307
0
}
2308
2309
0
void OMPClauseEnqueue::VisitOMPNovariantsClause(const OMPNovariantsClause *C) {
2310
0
  Visitor->AddStmt(C->getCondition());
2311
0
}
2312
2313
0
void OMPClauseEnqueue::VisitOMPNocontextClause(const OMPNocontextClause *C) {
2314
0
  Visitor->AddStmt(C->getCondition());
2315
0
}
2316
2317
0
void OMPClauseEnqueue::VisitOMPFilterClause(const OMPFilterClause *C) {
2318
0
  VisitOMPClauseWithPreInit(C);
2319
0
  Visitor->AddStmt(C->getThreadID());
2320
0
}
2321
2322
0
void OMPClauseEnqueue::VisitOMPAlignClause(const OMPAlignClause *C) {
2323
0
  Visitor->AddStmt(C->getAlignment());
2324
0
}
2325
2326
void OMPClauseEnqueue::VisitOMPUnifiedAddressClause(
2327
0
    const OMPUnifiedAddressClause *) {}
2328
2329
void OMPClauseEnqueue::VisitOMPUnifiedSharedMemoryClause(
2330
0
    const OMPUnifiedSharedMemoryClause *) {}
2331
2332
void OMPClauseEnqueue::VisitOMPReverseOffloadClause(
2333
0
    const OMPReverseOffloadClause *) {}
2334
2335
void OMPClauseEnqueue::VisitOMPDynamicAllocatorsClause(
2336
0
    const OMPDynamicAllocatorsClause *) {}
2337
2338
void OMPClauseEnqueue::VisitOMPAtomicDefaultMemOrderClause(
2339
0
    const OMPAtomicDefaultMemOrderClause *) {}
2340
2341
0
void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) {
2342
0
  Visitor->AddStmt(C->getDevice());
2343
0
}
2344
2345
0
void OMPClauseEnqueue::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
2346
0
  VisitOMPClauseWithPreInit(C);
2347
0
  Visitor->AddStmt(C->getNumTeams());
2348
0
}
2349
2350
void OMPClauseEnqueue::VisitOMPThreadLimitClause(
2351
0
    const OMPThreadLimitClause *C) {
2352
0
  VisitOMPClauseWithPreInit(C);
2353
0
  Visitor->AddStmt(C->getThreadLimit());
2354
0
}
2355
2356
0
void OMPClauseEnqueue::VisitOMPPriorityClause(const OMPPriorityClause *C) {
2357
0
  Visitor->AddStmt(C->getPriority());
2358
0
}
2359
2360
0
void OMPClauseEnqueue::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
2361
0
  Visitor->AddStmt(C->getGrainsize());
2362
0
}
2363
2364
0
void OMPClauseEnqueue::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
2365
0
  Visitor->AddStmt(C->getNumTasks());
2366
0
}
2367
2368
0
void OMPClauseEnqueue::VisitOMPHintClause(const OMPHintClause *C) {
2369
0
  Visitor->AddStmt(C->getHint());
2370
0
}
2371
2372
0
template <typename T> void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
2373
0
  for (const auto *I : Node->varlists()) {
2374
0
    Visitor->AddStmt(I);
2375
0
  }
2376
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*)
2377
2378
0
void OMPClauseEnqueue::VisitOMPInclusiveClause(const OMPInclusiveClause *C) {
2379
0
  VisitOMPClauseList(C);
2380
0
}
2381
0
void OMPClauseEnqueue::VisitOMPExclusiveClause(const OMPExclusiveClause *C) {
2382
0
  VisitOMPClauseList(C);
2383
0
}
2384
0
void OMPClauseEnqueue::VisitOMPAllocateClause(const OMPAllocateClause *C) {
2385
0
  VisitOMPClauseList(C);
2386
0
  Visitor->AddStmt(C->getAllocator());
2387
0
}
2388
0
void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) {
2389
0
  VisitOMPClauseList(C);
2390
0
  for (const auto *E : C->private_copies()) {
2391
0
    Visitor->AddStmt(E);
2392
0
  }
2393
0
}
2394
void OMPClauseEnqueue::VisitOMPFirstprivateClause(
2395
0
    const OMPFirstprivateClause *C) {
2396
0
  VisitOMPClauseList(C);
2397
0
  VisitOMPClauseWithPreInit(C);
2398
0
  for (const auto *E : C->private_copies()) {
2399
0
    Visitor->AddStmt(E);
2400
0
  }
2401
0
  for (const auto *E : C->inits()) {
2402
0
    Visitor->AddStmt(E);
2403
0
  }
2404
0
}
2405
void OMPClauseEnqueue::VisitOMPLastprivateClause(
2406
0
    const OMPLastprivateClause *C) {
2407
0
  VisitOMPClauseList(C);
2408
0
  VisitOMPClauseWithPostUpdate(C);
2409
0
  for (auto *E : C->private_copies()) {
2410
0
    Visitor->AddStmt(E);
2411
0
  }
2412
0
  for (auto *E : C->source_exprs()) {
2413
0
    Visitor->AddStmt(E);
2414
0
  }
2415
0
  for (auto *E : C->destination_exprs()) {
2416
0
    Visitor->AddStmt(E);
2417
0
  }
2418
0
  for (auto *E : C->assignment_ops()) {
2419
0
    Visitor->AddStmt(E);
2420
0
  }
2421
0
}
2422
0
void OMPClauseEnqueue::VisitOMPSharedClause(const OMPSharedClause *C) {
2423
0
  VisitOMPClauseList(C);
2424
0
}
2425
0
void OMPClauseEnqueue::VisitOMPReductionClause(const OMPReductionClause *C) {
2426
0
  VisitOMPClauseList(C);
2427
0
  VisitOMPClauseWithPostUpdate(C);
2428
0
  for (auto *E : C->privates()) {
2429
0
    Visitor->AddStmt(E);
2430
0
  }
2431
0
  for (auto *E : C->lhs_exprs()) {
2432
0
    Visitor->AddStmt(E);
2433
0
  }
2434
0
  for (auto *E : C->rhs_exprs()) {
2435
0
    Visitor->AddStmt(E);
2436
0
  }
2437
0
  for (auto *E : C->reduction_ops()) {
2438
0
    Visitor->AddStmt(E);
2439
0
  }
2440
0
  if (C->getModifier() == clang::OMPC_REDUCTION_inscan) {
2441
0
    for (auto *E : C->copy_ops()) {
2442
0
      Visitor->AddStmt(E);
2443
0
    }
2444
0
    for (auto *E : C->copy_array_temps()) {
2445
0
      Visitor->AddStmt(E);
2446
0
    }
2447
0
    for (auto *E : C->copy_array_elems()) {
2448
0
      Visitor->AddStmt(E);
2449
0
    }
2450
0
  }
2451
0
}
2452
void OMPClauseEnqueue::VisitOMPTaskReductionClause(
2453
0
    const OMPTaskReductionClause *C) {
2454
0
  VisitOMPClauseList(C);
2455
0
  VisitOMPClauseWithPostUpdate(C);
2456
0
  for (auto *E : C->privates()) {
2457
0
    Visitor->AddStmt(E);
2458
0
  }
2459
0
  for (auto *E : C->lhs_exprs()) {
2460
0
    Visitor->AddStmt(E);
2461
0
  }
2462
0
  for (auto *E : C->rhs_exprs()) {
2463
0
    Visitor->AddStmt(E);
2464
0
  }
2465
0
  for (auto *E : C->reduction_ops()) {
2466
0
    Visitor->AddStmt(E);
2467
0
  }
2468
0
}
2469
void OMPClauseEnqueue::VisitOMPInReductionClause(
2470
0
    const OMPInReductionClause *C) {
2471
0
  VisitOMPClauseList(C);
2472
0
  VisitOMPClauseWithPostUpdate(C);
2473
0
  for (auto *E : C->privates()) {
2474
0
    Visitor->AddStmt(E);
2475
0
  }
2476
0
  for (auto *E : C->lhs_exprs()) {
2477
0
    Visitor->AddStmt(E);
2478
0
  }
2479
0
  for (auto *E : C->rhs_exprs()) {
2480
0
    Visitor->AddStmt(E);
2481
0
  }
2482
0
  for (auto *E : C->reduction_ops()) {
2483
0
    Visitor->AddStmt(E);
2484
0
  }
2485
0
  for (auto *E : C->taskgroup_descriptors())
2486
0
    Visitor->AddStmt(E);
2487
0
}
2488
0
void OMPClauseEnqueue::VisitOMPLinearClause(const OMPLinearClause *C) {
2489
0
  VisitOMPClauseList(C);
2490
0
  VisitOMPClauseWithPostUpdate(C);
2491
0
  for (const auto *E : C->privates()) {
2492
0
    Visitor->AddStmt(E);
2493
0
  }
2494
0
  for (const auto *E : C->inits()) {
2495
0
    Visitor->AddStmt(E);
2496
0
  }
2497
0
  for (const auto *E : C->updates()) {
2498
0
    Visitor->AddStmt(E);
2499
0
  }
2500
0
  for (const auto *E : C->finals()) {
2501
0
    Visitor->AddStmt(E);
2502
0
  }
2503
0
  Visitor->AddStmt(C->getStep());
2504
0
  Visitor->AddStmt(C->getCalcStep());
2505
0
}
2506
0
void OMPClauseEnqueue::VisitOMPAlignedClause(const OMPAlignedClause *C) {
2507
0
  VisitOMPClauseList(C);
2508
0
  Visitor->AddStmt(C->getAlignment());
2509
0
}
2510
0
void OMPClauseEnqueue::VisitOMPCopyinClause(const OMPCopyinClause *C) {
2511
0
  VisitOMPClauseList(C);
2512
0
  for (auto *E : C->source_exprs()) {
2513
0
    Visitor->AddStmt(E);
2514
0
  }
2515
0
  for (auto *E : C->destination_exprs()) {
2516
0
    Visitor->AddStmt(E);
2517
0
  }
2518
0
  for (auto *E : C->assignment_ops()) {
2519
0
    Visitor->AddStmt(E);
2520
0
  }
2521
0
}
2522
void OMPClauseEnqueue::VisitOMPCopyprivateClause(
2523
0
    const OMPCopyprivateClause *C) {
2524
0
  VisitOMPClauseList(C);
2525
0
  for (auto *E : C->source_exprs()) {
2526
0
    Visitor->AddStmt(E);
2527
0
  }
2528
0
  for (auto *E : C->destination_exprs()) {
2529
0
    Visitor->AddStmt(E);
2530
0
  }
2531
0
  for (auto *E : C->assignment_ops()) {
2532
0
    Visitor->AddStmt(E);
2533
0
  }
2534
0
}
2535
0
void OMPClauseEnqueue::VisitOMPFlushClause(const OMPFlushClause *C) {
2536
0
  VisitOMPClauseList(C);
2537
0
}
2538
0
void OMPClauseEnqueue::VisitOMPDepobjClause(const OMPDepobjClause *C) {
2539
0
  Visitor->AddStmt(C->getDepobj());
2540
0
}
2541
0
void OMPClauseEnqueue::VisitOMPDependClause(const OMPDependClause *C) {
2542
0
  VisitOMPClauseList(C);
2543
0
}
2544
0
void OMPClauseEnqueue::VisitOMPMapClause(const OMPMapClause *C) {
2545
0
  VisitOMPClauseList(C);
2546
0
}
2547
void OMPClauseEnqueue::VisitOMPDistScheduleClause(
2548
0
    const OMPDistScheduleClause *C) {
2549
0
  VisitOMPClauseWithPreInit(C);
2550
0
  Visitor->AddStmt(C->getChunkSize());
2551
0
}
2552
void OMPClauseEnqueue::VisitOMPDefaultmapClause(
2553
0
    const OMPDefaultmapClause * /*C*/) {}
2554
0
void OMPClauseEnqueue::VisitOMPToClause(const OMPToClause *C) {
2555
0
  VisitOMPClauseList(C);
2556
0
}
2557
0
void OMPClauseEnqueue::VisitOMPFromClause(const OMPFromClause *C) {
2558
0
  VisitOMPClauseList(C);
2559
0
}
2560
void OMPClauseEnqueue::VisitOMPUseDevicePtrClause(
2561
0
    const OMPUseDevicePtrClause *C) {
2562
0
  VisitOMPClauseList(C);
2563
0
}
2564
void OMPClauseEnqueue::VisitOMPUseDeviceAddrClause(
2565
0
    const OMPUseDeviceAddrClause *C) {
2566
0
  VisitOMPClauseList(C);
2567
0
}
2568
void OMPClauseEnqueue::VisitOMPIsDevicePtrClause(
2569
0
    const OMPIsDevicePtrClause *C) {
2570
0
  VisitOMPClauseList(C);
2571
0
}
2572
void OMPClauseEnqueue::VisitOMPNontemporalClause(
2573
0
    const OMPNontemporalClause *C) {
2574
0
  VisitOMPClauseList(C);
2575
0
  for (const auto *E : C->private_refs())
2576
0
    Visitor->AddStmt(E);
2577
0
}
2578
0
void OMPClauseEnqueue::VisitOMPOrderClause(const OMPOrderClause *C) {}
2579
void OMPClauseEnqueue::VisitOMPUsesAllocatorsClause(
2580
0
    const OMPUsesAllocatorsClause *C) {
2581
0
  for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
2582
0
    const OMPUsesAllocatorsClause::Data &D = C->getAllocatorData(I);
2583
0
    Visitor->AddStmt(D.Allocator);
2584
0
    Visitor->AddStmt(D.AllocatorTraits);
2585
0
  }
2586
0
}
2587
0
void OMPClauseEnqueue::VisitOMPAffinityClause(const OMPAffinityClause *C) {
2588
0
  Visitor->AddStmt(C->getModifier());
2589
0
  for (const Expr *E : C->varlists())
2590
0
    Visitor->AddStmt(E);
2591
0
}
2592
0
void OMPClauseEnqueue::VisitOMPBindClause(const OMPBindClause *C) {}
2593
2594
} // namespace
2595
2596
1
void EnqueueVisitor::EnqueueChildren(const OMPClause *S) {
2597
1
  unsigned size = WL.size();
2598
1
  OMPClauseEnqueue Visitor(this);
2599
1
  Visitor.Visit(S);
2600
1
  if (size == WL.size())
2601
0
    return;
2602
  // Now reverse the entries we just added.  This will match the DFS
2603
  // ordering performed by the worklist.
2604
1
  VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
2605
1
  std::reverse(I, E);
2606
1
}
2607
1
void EnqueueVisitor::VisitAddrLabelExpr(const AddrLabelExpr *E) {
2608
1
  WL.push_back(LabelRefVisit(E->getLabel(), E->getLabelLoc(), Parent));
2609
1
}
2610
6
void EnqueueVisitor::VisitBlockExpr(const BlockExpr *B) {
2611
6
  AddDecl(B->getBlockDecl());
2612
6
}
2613
4
void EnqueueVisitor::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
2614
4
  EnqueueChildren(E);
2615
4
  AddTypeLoc(E->getTypeSourceInfo());
2616
4
}
2617
804
void EnqueueVisitor::VisitCompoundStmt(const CompoundStmt *S) {
2618
804
  for (auto &I : llvm::reverse(S->body()))
2619
2.32k
    AddStmt(I);
2620
804
}
2621
void EnqueueVisitor::VisitMSDependentExistsStmt(
2622
2
    const MSDependentExistsStmt *S) {
2623
2
  AddStmt(S->getSubStmt());
2624
2
  AddDeclarationNameInfo(S);
2625
2
  if (NestedNameSpecifierLoc QualifierLoc = S->getQualifierLoc())
2626
2
    AddNestedNameSpecifierLoc(QualifierLoc);
2627
2
}
2628
2629
void EnqueueVisitor::VisitCXXDependentScopeMemberExpr(
2630
3
    const CXXDependentScopeMemberExpr *E) {
2631
3
  if (E->hasExplicitTemplateArgs())
2632
1
    AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
2633
3
  AddDeclarationNameInfo(E);
2634
3
  if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc())
2635
2
    AddNestedNameSpecifierLoc(QualifierLoc);
2636
3
  if (!E->isImplicitAccess())
2637
3
    AddStmt(E->getBase());
2638
3
}
2639
5
void EnqueueVisitor::VisitCXXNewExpr(const CXXNewExpr *E) {
2640
  // Enqueue the initializer , if any.
2641
5
  AddStmt(E->getInitializer());
2642
  // Enqueue the array size, if any.
2643
5
  AddStmt(E->getArraySize().getValueOr(nullptr));
2644
  // Enqueue the allocated type.
2645
5
  AddTypeLoc(E->getAllocatedTypeSourceInfo());
2646
  // Enqueue the placement arguments.
2647
6
  for (unsigned I = E->getNumPlacementArgs(); I > 0; 
--I1
)
2648
1
    AddStmt(E->getPlacementArg(I - 1));
2649
5
}
2650
4.89k
void EnqueueVisitor::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *CE) {
2651
4.92k
  for (unsigned I = CE->getNumArgs(); I > 1 /* Yes, this is 1 */; 
--I31
)
2652
31
    AddStmt(CE->getArg(I - 1));
2653
4.89k
  AddStmt(CE->getCallee());
2654
4.89k
  AddStmt(CE->getArg(0));
2655
4.89k
}
2656
void EnqueueVisitor::VisitCXXPseudoDestructorExpr(
2657
2
    const CXXPseudoDestructorExpr *E) {
2658
  // Visit the name of the type being destroyed.
2659
2
  AddTypeLoc(E->getDestroyedTypeInfo());
2660
  // Visit the scope type that looks disturbingly like the nested-name-specifier
2661
  // but isn't.
2662
2
  AddTypeLoc(E->getScopeTypeInfo());
2663
  // Visit the nested-name-specifier.
2664
2
  if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc())
2665
1
    AddNestedNameSpecifierLoc(QualifierLoc);
2666
  // Visit base expression.
2667
2
  AddStmt(E->getBase());
2668
2
}
2669
void EnqueueVisitor::VisitCXXScalarValueInitExpr(
2670
2
    const CXXScalarValueInitExpr *E) {
2671
2
  AddTypeLoc(E->getTypeSourceInfo());
2672
2
}
2673
void EnqueueVisitor::VisitCXXTemporaryObjectExpr(
2674
39
    const CXXTemporaryObjectExpr *E) {
2675
39
  EnqueueChildren(E);
2676
39
  AddTypeLoc(E->getTypeSourceInfo());
2677
39
}
2678
2
void EnqueueVisitor::VisitCXXTypeidExpr(const CXXTypeidExpr *E) {
2679
2
  EnqueueChildren(E);
2680
2
  if (E->isTypeOperand())
2681
1
    AddTypeLoc(E->getTypeOperandSourceInfo());
2682
2
}
2683
2684
void EnqueueVisitor::VisitCXXUnresolvedConstructExpr(
2685
6
    const CXXUnresolvedConstructExpr *E) {
2686
6
  EnqueueChildren(E);
2687
6
  AddTypeLoc(E->getTypeSourceInfo());
2688
6
}
2689
0
void EnqueueVisitor::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
2690
0
  EnqueueChildren(E);
2691
0
  if (E->isTypeOperand())
2692
0
    AddTypeLoc(E->getTypeOperandSourceInfo());
2693
0
}
2694
2695
4
void EnqueueVisitor::VisitCXXCatchStmt(const CXXCatchStmt *S) {
2696
4
  EnqueueChildren(S);
2697
4
  AddDecl(S->getExceptionDecl());
2698
4
}
2699
2700
4
void EnqueueVisitor::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
2701
4
  AddStmt(S->getBody());
2702
4
  AddStmt(S->getRangeInit());
2703
4
  AddDecl(S->getLoopVariable());
2704
4
}
2705
2706
1.20k
void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) {
2707
1.20k
  if (DR->hasExplicitTemplateArgs())
2708
6
    AddExplicitTemplateArgs(DR->getTemplateArgs(), DR->getNumTemplateArgs());
2709
1.20k
  WL.push_back(DeclRefExprParts(DR, Parent));
2710
1.20k
}
2711
void EnqueueVisitor::VisitDependentScopeDeclRefExpr(
2712
1
    const DependentScopeDeclRefExpr *E) {
2713
1
  if (E->hasExplicitTemplateArgs())
2714
1
    AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
2715
1
  AddDeclarationNameInfo(E);
2716
1
  AddNestedNameSpecifierLoc(E->getQualifierLoc());
2717
1
}
2718
324
void EnqueueVisitor::VisitDeclStmt(const DeclStmt *S) {
2719
324
  unsigned size = WL.size();
2720
324
  bool isFirst = true;
2721
336
  for (const auto *D : S->decls()) {
2722
336
    AddDecl(D, isFirst);
2723
336
    isFirst = false;
2724
336
  }
2725
324
  if (size == WL.size())
2726
0
    return;
2727
  // Now reverse the entries we just added.  This will match the DFS
2728
  // ordering performed by the worklist.
2729
324
  VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
2730
324
  std::reverse(I, E);
2731
324
}
2732
14
void EnqueueVisitor::VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
2733
14
  AddStmt(E->getInit());
2734
14
  for (const DesignatedInitExpr::Designator &D :
2735
18
       llvm::reverse(E->designators())) {
2736
18
    if (D.isFieldDesignator()) {
2737
16
      if (FieldDecl *Field = D.getField())
2738
16
        AddMemberRef(Field, D.getFieldLoc());
2739
16
      continue;
2740
16
    }
2741
2
    if (D.isArrayDesignator()) {
2742
2
      AddStmt(E->getArrayIndex(D));
2743
2
      continue;
2744
2
    }
2745
0
    assert(D.isArrayRangeDesignator() && "Unknown designator kind");
2746
0
    AddStmt(E->getArrayRangeEnd(D));
2747
0
    AddStmt(E->getArrayRangeStart(D));
2748
0
  }
2749
14
}
2750
75
void EnqueueVisitor::VisitExplicitCastExpr(const ExplicitCastExpr *E) {
2751
75
  EnqueueChildren(E);
2752
75
  AddTypeLoc(E->getTypeInfoAsWritten());
2753
75
}
2754
2
void EnqueueVisitor::VisitForStmt(const ForStmt *FS) {
2755
2
  AddStmt(FS->getBody());
2756
2
  AddStmt(FS->getInc());
2757
2
  AddStmt(FS->getCond());
2758
2
  AddDecl(FS->getConditionVariable());
2759
2
  AddStmt(FS->getInit());
2760
2
}
2761
2
void EnqueueVisitor::VisitGotoStmt(const GotoStmt *GS) {
2762
2
  WL.push_back(LabelRefVisit(GS->getLabel(), GS->getLabelLoc(), Parent));
2763
2
}
2764
10
void EnqueueVisitor::VisitIfStmt(const IfStmt *If) {
2765
10
  AddStmt(If->getElse());
2766
10
  AddStmt(If->getThen());
2767
10
  AddStmt(If->getCond());
2768
10
  AddStmt(If->getInit());
2769
10
  AddDecl(If->getConditionVariable());
2770
10
}
2771
17
void EnqueueVisitor::VisitInitListExpr(const InitListExpr *IE) {
2772
  // We care about the syntactic form of the initializer list, only.
2773
17
  if (InitListExpr *Syntactic = IE->getSyntacticForm())
2774
15
    IE = Syntactic;
2775
17
  EnqueueChildren(IE);
2776
17
}
2777
527
void EnqueueVisitor::VisitMemberExpr(const MemberExpr *M) {
2778
527
  WL.push_back(MemberExprParts(M, Parent));
2779
2780
  // If the base of the member access expression is an implicit 'this', don't
2781
  // visit it.
2782
  // FIXME: If we ever want to show these implicit accesses, this will be
2783
  // unfortunate. However, clang_getCursor() relies on this behavior.
2784
527
  if (M->isImplicitAccess())
2785
37
    return;
2786
2787
  // Ignore base anonymous struct/union fields, otherwise they will shadow the
2788
  // real field that we are interested in.
2789
490
  if (auto *SubME = dyn_cast<MemberExpr>(M->getBase())) {
2790
4
    if (auto *FD = dyn_cast_or_null<FieldDecl>(SubME->getMemberDecl())) {
2791
4
      if (FD->isAnonymousStructOrUnion()) {
2792
4
        AddStmt(SubME->getBase());
2793
4
        return;
2794
4
      }
2795
4
    }
2796
4
  }
2797
2798
486
  AddStmt(M->getBase());
2799
486
}
2800
1
void EnqueueVisitor::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) {
2801
1
  AddTypeLoc(E->getEncodedTypeSourceInfo());
2802
1
}
2803
155
void EnqueueVisitor::VisitObjCMessageExpr(const ObjCMessageExpr *M) {
2804
155
  EnqueueChildren(M);
2805
155
  AddTypeLoc(M->getClassReceiverTypeInfo());
2806
155
}
2807
1
void EnqueueVisitor::VisitOffsetOfExpr(const OffsetOfExpr *E) {
2808
  // Visit the components of the offsetof expression.
2809
4
  for (unsigned N = E->getNumComponents(), I = N; I > 0; 
--I3
) {
2810
3
    const OffsetOfNode &Node = E->getComponent(I - 1);
2811
3
    switch (Node.getKind()) {
2812
1
    case OffsetOfNode::Array:
2813
1
      AddStmt(E->getIndexExpr(Node.getArrayExprIndex()));
2814
1
      break;
2815
2
    case OffsetOfNode::Field:
2816
2
      AddMemberRef(Node.getField(), Node.getSourceRange().getEnd());
2817
2
      break;
2818
0
    case OffsetOfNode::Identifier:
2819
0
    case OffsetOfNode::Base:
2820
0
      continue;
2821
3
    }
2822
3
  }
2823
  // Visit the type into which we're computing the offset.
2824
1
  AddTypeLoc(E->getTypeSourceInfo());
2825
1
}
2826
15
void EnqueueVisitor::VisitOverloadExpr(const OverloadExpr *E) {
2827
15
  if (E->hasExplicitTemplateArgs())
2828
4
    AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
2829
15
  WL.push_back(OverloadExprParts(E, Parent));
2830
15
}
2831
void EnqueueVisitor::VisitUnaryExprOrTypeTraitExpr(
2832
5
    const UnaryExprOrTypeTraitExpr *E) {
2833
5
  EnqueueChildren(E);
2834
5
  if (E->isArgumentType())
2835
5
    AddTypeLoc(E->getArgumentTypeInfo());
2836
5
}
2837
4.78k
void EnqueueVisitor::VisitStmt(const Stmt *S) { EnqueueChildren(S); }
2838
12
void EnqueueVisitor::VisitSwitchStmt(const SwitchStmt *S) {
2839
12
  AddStmt(S->getBody());
2840
12
  AddStmt(S->getCond());
2841
12
  AddDecl(S->getConditionVariable());
2842
12
}
2843
2844
2
void EnqueueVisitor::VisitWhileStmt(const WhileStmt *W) {
2845
2
  AddStmt(W->getBody());
2846
2
  AddStmt(W->getCond());
2847
2
  AddDecl(W->getConditionVariable());
2848
2
}
2849
2850
6
void EnqueueVisitor::VisitTypeTraitExpr(const TypeTraitExpr *E) {
2851
18
  for (unsigned I = E->getNumArgs(); I > 0; 
--I12
)
2852
12
    AddTypeLoc(E->getArg(I - 1));
2853
6
}
2854
2855
0
void EnqueueVisitor::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) {
2856
0
  AddTypeLoc(E->getQueriedTypeSourceInfo());
2857
0
}
2858
2859
0
void EnqueueVisitor::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) {
2860
0
  EnqueueChildren(E);
2861
0
}
2862
2863
5
void EnqueueVisitor::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U) {
2864
5
  VisitOverloadExpr(U);
2865
5
  if (!U->isImplicitAccess())
2866
4
    AddStmt(U->getBase());
2867
5
}
2868
3
void EnqueueVisitor::VisitVAArgExpr(const VAArgExpr *E) {
2869
3
  AddStmt(E->getSubExpr());
2870
3
  AddTypeLoc(E->getWrittenTypeInfo());
2871
3
}
2872
2
void EnqueueVisitor::VisitSizeOfPackExpr(const SizeOfPackExpr *E) {
2873
2
  WL.push_back(SizeOfPackExprParts(E, Parent));
2874
2
}
2875
50
void EnqueueVisitor::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
2876
  // If the opaque value has a source expression, just transparently
2877
  // visit that.  This is useful for (e.g.) pseudo-object expressions.
2878
50
  if (Expr *SourceExpr = E->getSourceExpr())
2879
48
    return Visit(SourceExpr);
2880
50
}
2881
4
void EnqueueVisitor::VisitLambdaExpr(const LambdaExpr *E) {
2882
4
  AddStmt(E->getBody());
2883
4
  WL.push_back(LambdaExprParts(E, Parent));
2884
4
}
2885
17
void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
2886
  // Treat the expression like its syntactic form.
2887
17
  Visit(E->getSyntacticForm());
2888
17
}
2889
2890
void EnqueueVisitor::VisitOMPExecutableDirective(
2891
1
    const OMPExecutableDirective *D) {
2892
1
  EnqueueChildren(D);
2893
1
  for (ArrayRef<OMPClause *>::iterator I = D->clauses().begin(),
2894
1
                                       E = D->clauses().end();
2895
2
       I != E; 
++I1
)
2896
1
    EnqueueChildren(*I);
2897
1
}
2898
2899
void EnqueueVisitor::VisitOMPLoopBasedDirective(
2900
1
    const OMPLoopBasedDirective *D) {
2901
1
  VisitOMPExecutableDirective(D);
2902
1
}
2903
2904
0
void EnqueueVisitor::VisitOMPLoopDirective(const OMPLoopDirective *D) {
2905
0
  VisitOMPLoopBasedDirective(D);
2906
0
}
2907
2908
0
void EnqueueVisitor::VisitOMPParallelDirective(const OMPParallelDirective *D) {
2909
0
  VisitOMPExecutableDirective(D);
2910
0
}
2911
2912
0
void EnqueueVisitor::VisitOMPSimdDirective(const OMPSimdDirective *D) {
2913
0
  VisitOMPLoopDirective(D);
2914
0
}
2915
2916
void EnqueueVisitor::VisitOMPLoopTransformationDirective(
2917
1
    const OMPLoopTransformationDirective *D) {
2918
1
  VisitOMPLoopBasedDirective(D);
2919
1
}
2920
2921
1
void EnqueueVisitor::VisitOMPTileDirective(const OMPTileDirective *D) {
2922
1
  VisitOMPLoopTransformationDirective(D);
2923
1
}
2924
2925
0
void EnqueueVisitor::VisitOMPUnrollDirective(const OMPUnrollDirective *D) {
2926
0
  VisitOMPLoopTransformationDirective(D);
2927
0
}
2928
2929
0
void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) {
2930
0
  VisitOMPLoopDirective(D);
2931
0
}
2932
2933
0
void EnqueueVisitor::VisitOMPForSimdDirective(const OMPForSimdDirective *D) {
2934
0
  VisitOMPLoopDirective(D);
2935
0
}
2936
2937
0
void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) {
2938
0
  VisitOMPExecutableDirective(D);
2939
0
}
2940
2941
0
void EnqueueVisitor::VisitOMPSectionDirective(const OMPSectionDirective *D) {
2942
0
  VisitOMPExecutableDirective(D);
2943
0
}
2944
2945
0
void EnqueueVisitor::VisitOMPSingleDirective(const OMPSingleDirective *D) {
2946
0
  VisitOMPExecutableDirective(D);
2947
0
}
2948
2949
0
void EnqueueVisitor::VisitOMPMasterDirective(const OMPMasterDirective *D) {
2950
0
  VisitOMPExecutableDirective(D);
2951
0
}
2952
2953
0
void EnqueueVisitor::VisitOMPCriticalDirective(const OMPCriticalDirective *D) {
2954
0
  VisitOMPExecutableDirective(D);
2955
0
  AddDeclarationNameInfo(D);
2956
0
}
2957
2958
void EnqueueVisitor::VisitOMPParallelForDirective(
2959
0
    const OMPParallelForDirective *D) {
2960
0
  VisitOMPLoopDirective(D);
2961
0
}
2962
2963
void EnqueueVisitor::VisitOMPParallelForSimdDirective(
2964
0
    const OMPParallelForSimdDirective *D) {
2965
0
  VisitOMPLoopDirective(D);
2966
0
}
2967
2968
void EnqueueVisitor::VisitOMPParallelMasterDirective(
2969
0
    const OMPParallelMasterDirective *D) {
2970
0
  VisitOMPExecutableDirective(D);
2971
0
}
2972
2973
void EnqueueVisitor::VisitOMPParallelSectionsDirective(
2974
0
    const OMPParallelSectionsDirective *D) {
2975
0
  VisitOMPExecutableDirective(D);
2976
0
}
2977
2978
0
void EnqueueVisitor::VisitOMPTaskDirective(const OMPTaskDirective *D) {
2979
0
  VisitOMPExecutableDirective(D);
2980
0
}
2981
2982
void EnqueueVisitor::VisitOMPTaskyieldDirective(
2983
0
    const OMPTaskyieldDirective *D) {
2984
0
  VisitOMPExecutableDirective(D);
2985
0
}
2986
2987
0
void EnqueueVisitor::VisitOMPBarrierDirective(const OMPBarrierDirective *D) {
2988
0
  VisitOMPExecutableDirective(D);
2989
0
}
2990
2991
0
void EnqueueVisitor::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D) {
2992
0
  VisitOMPExecutableDirective(D);
2993
0
}
2994
2995
void EnqueueVisitor::VisitOMPTaskgroupDirective(
2996
0
    const OMPTaskgroupDirective *D) {
2997
0
  VisitOMPExecutableDirective(D);
2998
0
  if (const Expr *E = D->getReductionRef())
2999
0
    VisitStmt(E);
3000
0
}
3001
3002
0
void EnqueueVisitor::VisitOMPFlushDirective(const OMPFlushDirective *D) {
3003
0
  VisitOMPExecutableDirective(D);
3004
0
}
3005
3006
0
void EnqueueVisitor::VisitOMPDepobjDirective(const OMPDepobjDirective *D) {
3007
0
  VisitOMPExecutableDirective(D);
3008
0
}
3009
3010
0
void EnqueueVisitor::VisitOMPScanDirective(const OMPScanDirective *D) {
3011
0
  VisitOMPExecutableDirective(D);
3012
0
}
3013
3014
0
void EnqueueVisitor::VisitOMPOrderedDirective(const OMPOrderedDirective *D) {
3015
0
  VisitOMPExecutableDirective(D);
3016
0
}
3017
3018
0
void EnqueueVisitor::VisitOMPAtomicDirective(const OMPAtomicDirective *D) {
3019
0
  VisitOMPExecutableDirective(D);
3020
0
}
3021
3022
0
void EnqueueVisitor::VisitOMPTargetDirective(const OMPTargetDirective *D) {
3023
0
  VisitOMPExecutableDirective(D);
3024
0
}
3025
3026
void EnqueueVisitor::VisitOMPTargetDataDirective(
3027
0
    const OMPTargetDataDirective *D) {
3028
0
  VisitOMPExecutableDirective(D);
3029
0
}
3030
3031
void EnqueueVisitor::VisitOMPTargetEnterDataDirective(
3032
0
    const OMPTargetEnterDataDirective *D) {
3033
0
  VisitOMPExecutableDirective(D);
3034
0
}
3035
3036
void EnqueueVisitor::VisitOMPTargetExitDataDirective(
3037
0
    const OMPTargetExitDataDirective *D) {
3038
0
  VisitOMPExecutableDirective(D);
3039
0
}
3040
3041
void EnqueueVisitor::VisitOMPTargetParallelDirective(
3042
0
    const OMPTargetParallelDirective *D) {
3043
0
  VisitOMPExecutableDirective(D);
3044
0
}
3045
3046
void EnqueueVisitor::VisitOMPTargetParallelForDirective(
3047
0
    const OMPTargetParallelForDirective *D) {
3048
0
  VisitOMPLoopDirective(D);
3049
0
}
3050
3051
0
void EnqueueVisitor::VisitOMPTeamsDirective(const OMPTeamsDirective *D) {
3052
0
  VisitOMPExecutableDirective(D);
3053
0
}
3054
3055
void EnqueueVisitor::VisitOMPCancellationPointDirective(
3056
0
    const OMPCancellationPointDirective *D) {
3057
0
  VisitOMPExecutableDirective(D);
3058
0
}
3059
3060
0
void EnqueueVisitor::VisitOMPCancelDirective(const OMPCancelDirective *D) {
3061
0
  VisitOMPExecutableDirective(D);
3062
0
}
3063
3064
0
void EnqueueVisitor::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D) {
3065
0
  VisitOMPLoopDirective(D);
3066
0
}
3067
3068
void EnqueueVisitor::VisitOMPTaskLoopSimdDirective(
3069
0
    const OMPTaskLoopSimdDirective *D) {
3070
0
  VisitOMPLoopDirective(D);
3071
0
}
3072
3073
void EnqueueVisitor::VisitOMPMasterTaskLoopDirective(
3074
0
    const OMPMasterTaskLoopDirective *D) {
3075
0
  VisitOMPLoopDirective(D);
3076
0
}
3077
3078
void EnqueueVisitor::VisitOMPMasterTaskLoopSimdDirective(
3079
0
    const OMPMasterTaskLoopSimdDirective *D) {
3080
0
  VisitOMPLoopDirective(D);
3081
0
}
3082
3083
void EnqueueVisitor::VisitOMPParallelMasterTaskLoopDirective(
3084
0
    const OMPParallelMasterTaskLoopDirective *D) {
3085
0
  VisitOMPLoopDirective(D);
3086
0
}
3087
3088
void EnqueueVisitor::VisitOMPParallelMasterTaskLoopSimdDirective(
3089
0
    const OMPParallelMasterTaskLoopSimdDirective *D) {
3090
0
  VisitOMPLoopDirective(D);
3091
0
}
3092
3093
void EnqueueVisitor::VisitOMPDistributeDirective(
3094
0
    const OMPDistributeDirective *D) {
3095
0
  VisitOMPLoopDirective(D);
3096
0
}
3097
3098
void EnqueueVisitor::VisitOMPDistributeParallelForDirective(
3099
0
    const OMPDistributeParallelForDirective *D) {
3100
0
  VisitOMPLoopDirective(D);
3101
0
}
3102
3103
void EnqueueVisitor::VisitOMPDistributeParallelForSimdDirective(
3104
0
    const OMPDistributeParallelForSimdDirective *D) {
3105
0
  VisitOMPLoopDirective(D);
3106
0
}
3107
3108
void EnqueueVisitor::VisitOMPDistributeSimdDirective(
3109
0
    const OMPDistributeSimdDirective *D) {
3110
0
  VisitOMPLoopDirective(D);
3111
0
}
3112
3113
void EnqueueVisitor::VisitOMPTargetParallelForSimdDirective(
3114
0
    const OMPTargetParallelForSimdDirective *D) {
3115
0
  VisitOMPLoopDirective(D);
3116
0
}
3117
3118
void EnqueueVisitor::VisitOMPTargetSimdDirective(
3119
0
    const OMPTargetSimdDirective *D) {
3120
0
  VisitOMPLoopDirective(D);
3121
0
}
3122
3123
void EnqueueVisitor::VisitOMPTeamsDistributeDirective(
3124
0
    const OMPTeamsDistributeDirective *D) {
3125
0
  VisitOMPLoopDirective(D);
3126
0
}
3127
3128
void EnqueueVisitor::VisitOMPTeamsDistributeSimdDirective(
3129
0
    const OMPTeamsDistributeSimdDirective *D) {
3130
0
  VisitOMPLoopDirective(D);
3131
0
}
3132
3133
void EnqueueVisitor::VisitOMPTeamsDistributeParallelForSimdDirective(
3134
0
    const OMPTeamsDistributeParallelForSimdDirective *D) {
3135
0
  VisitOMPLoopDirective(D);
3136
0
}
3137
3138
void EnqueueVisitor::VisitOMPTeamsDistributeParallelForDirective(
3139
0
    const OMPTeamsDistributeParallelForDirective *D) {
3140
0
  VisitOMPLoopDirective(D);
3141
0
}
3142
3143
void EnqueueVisitor::VisitOMPTargetTeamsDirective(
3144
0
    const OMPTargetTeamsDirective *D) {
3145
0
  VisitOMPExecutableDirective(D);
3146
0
}
3147
3148
void EnqueueVisitor::VisitOMPTargetTeamsDistributeDirective(
3149
0
    const OMPTargetTeamsDistributeDirective *D) {
3150
0
  VisitOMPLoopDirective(D);
3151
0
}
3152
3153
void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForDirective(
3154
0
    const OMPTargetTeamsDistributeParallelForDirective *D) {
3155
0
  VisitOMPLoopDirective(D);
3156
0
}
3157
3158
void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
3159
0
    const OMPTargetTeamsDistributeParallelForSimdDirective *D) {
3160
0
  VisitOMPLoopDirective(D);
3161
0
}
3162
3163
void EnqueueVisitor::VisitOMPTargetTeamsDistributeSimdDirective(
3164
0
    const OMPTargetTeamsDistributeSimdDirective *D) {
3165
0
  VisitOMPLoopDirective(D);
3166
0
}
3167
3168
12.9k
void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) {
3169
12.9k
  EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU, RegionOfInterest))
3170
12.9k
      .Visit(S);
3171
12.9k
}
3172
3173
18.4k
bool CursorVisitor::IsInRegionOfInterest(CXCursor C) {
3174
18.4k
  if (RegionOfInterest.isValid()) {
3175
13.9k
    SourceRange Range = getRawCursorExtent(C);
3176
13.9k
    if (Range.isInvalid() || 
CompareRegionOfInterest(Range)13.9k
)
3177
1.75k
      return false;
3178
13.9k
  }
3179
16.6k
  return true;
3180
18.4k
}
3181
3182
1.16k
bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
3183
28.2k
  while (!WL.empty()) {
3184
    // Dequeue the worklist item.
3185
27.0k
    VisitorJob LI = WL.pop_back_val();
3186
3187
    // Set the Parent field, then back to its old value once we're done.
3188
27.0k
    SetParentRAII SetParent(Parent, StmtParent, LI.getParent());
3189
3190
27.0k
    switch (LI.getKind()) {
3191
356
    case VisitorJob::DeclVisitKind: {
3192
356
      const Decl *D = cast<DeclVisit>(&LI)->get();
3193
356
      if (!D)
3194
0
        continue;
3195
3196
      // For now, perform default visitation for Decls.
3197
356
      if (Visit(MakeCXCursor(D, TU, RegionOfInterest,
3198
356
                             cast<DeclVisit>(&LI)->isFirst())))
3199
1
        return true;
3200
3201
355
      continue;
3202
356
    }
3203
355
    case VisitorJob::ExplicitTemplateArgsVisitKind: {
3204
12
      for (const TemplateArgumentLoc &Arg :
3205
16
           *cast<ExplicitTemplateArgsVisit>(&LI)) {
3206
16
        if (VisitTemplateArgumentLoc(Arg))
3207
0
          return true;
3208
16
      }
3209
12
      continue;
3210
12
    }
3211
186
    case VisitorJob::TypeLocVisitKind: {
3212
      // Perform default visitation for TypeLocs.
3213
186
      if (Visit(cast<TypeLocVisit>(&LI)->get()))
3214
0
        return true;
3215
186
      continue;
3216
186
    }
3217
186
    case VisitorJob::LabelRefVisitKind: {
3218
3
      const LabelDecl *LS = cast<LabelRefVisit>(&LI)->get();
3219
3
      if (LabelStmt *stmt = LS->getStmt()) {
3220
2
        if (Visit(MakeCursorLabelRef(stmt, cast<LabelRefVisit>(&LI)->getLoc(),
3221
2
                                     TU))) {
3222
0
          return true;
3223
0
        }
3224
2
      }
3225
3
      continue;
3226
3
    }
3227
3228
6
    case VisitorJob::NestedNameSpecifierLocVisitKind: {
3229
6
      NestedNameSpecifierLocVisit *V = cast<NestedNameSpecifierLocVisit>(&LI);
3230
6
      if (VisitNestedNameSpecifierLoc(V->get()))
3231
0
        return true;
3232
6
      continue;
3233
6
    }
3234
3235
6
    case VisitorJob::DeclarationNameInfoVisitKind: {
3236
6
      if (VisitDeclarationNameInfo(cast<DeclarationNameInfoVisit>(&LI)->get()))
3237
0
        return true;
3238
6
      continue;
3239
6
    }
3240
18
    case VisitorJob::MemberRefVisitKind: {
3241
18
      MemberRefVisit *V = cast<MemberRefVisit>(&LI);
3242
18
      if (Visit(MakeCursorMemberRef(V->get(), V->getLoc(), TU)))
3243
0
        return true;
3244
18
      continue;
3245
18
    }
3246
18.4k
    case VisitorJob::StmtVisitKind: {
3247
18.4k
      const Stmt *S = cast<StmtVisit>(&LI)->get();
3248
18.4k
      if (!S)
3249
0
        continue;
3250
3251
      // Update the current cursor.
3252
18.4k
      CXCursor Cursor = MakeCXCursor(S, StmtParent, TU, RegionOfInterest);
3253
18.4k
      if (!IsInRegionOfInterest(Cursor))
3254
1.75k
        continue;
3255
16.6k
      switch (Visitor(Cursor, Parent, ClientData)) {
3256
1
      case CXChildVisit_Break:
3257
1
        return true;
3258
4.87k
      case CXChildVisit_Continue:
3259
4.87k
        break;
3260
11.7k
      case CXChildVisit_Recurse:
3261
11.7k
        if (PostChildrenVisitor)
3262
6.31k
          WL.push_back(PostChildrenVisit(nullptr, Cursor));
3263
11.7k
        EnqueueWorkList(WL, S);
3264
11.7k
        break;
3265
16.6k
      }
3266
16.6k
      continue;
3267
16.6k
    }
3268
16.6k
    case VisitorJob::MemberExprPartsKind: {
3269
      // Handle the other pieces in the MemberExpr besides the base.
3270
527
      const MemberExpr *M = cast<MemberExprParts>(&LI)->get();
3271
3272
      // Visit the nested-name-specifier
3273
527
      if (NestedNameSpecifierLoc QualifierLoc = M->getQualifierLoc())
3274
5
        if (VisitNestedNameSpecifierLoc(QualifierLoc))
3275
0
          return true;
3276
3277
      // Visit the declaration name.
3278
527
      if (VisitDeclarationNameInfo(M->getMemberNameInfo()))
3279
0
        return true;
3280
3281
      // Visit the explicitly-specified template arguments, if any.
3282
527
      if (M->hasExplicitTemplateArgs()) {
3283
2
        for (const TemplateArgumentLoc *Arg = M->getTemplateArgs(),
3284
2
                                       *ArgEnd = Arg + M->getNumTemplateArgs();
3285
4
             Arg != ArgEnd; 
++Arg2
) {
3286
2
          if (VisitTemplateArgumentLoc(*Arg))
3287
0
            return true;
3288
2
        }
3289
2
      }
3290
527
      continue;
3291
527
    }
3292
1.20k
    case VisitorJob::DeclRefExprPartsKind: {
3293
1.20k
      const DeclRefExpr *DR = cast<DeclRefExprParts>(&LI)->get();
3294
      // Visit nested-name-specifier, if present.
3295
1.20k
      if (NestedNameSpecifierLoc QualifierLoc = DR->getQualifierLoc())
3296
2
        if (VisitNestedNameSpecifierLoc(QualifierLoc))
3297
0
          return true;
3298
      // Visit declaration name.
3299
1.20k
      if (VisitDeclarationNameInfo(DR->getNameInfo()))
3300
0
        return true;
3301
1.20k
      continue;
3302
1.20k
    }
3303
1.20k
    case VisitorJob::OverloadExprPartsKind: {
3304
15
      const OverloadExpr *O = cast<OverloadExprParts>(&LI)->get();
3305
      // Visit the nested-name-specifier.
3306
15
      if (NestedNameSpecifierLoc QualifierLoc = O->getQualifierLoc())
3307
5
        if (VisitNestedNameSpecifierLoc(QualifierLoc))
3308
0
          return true;
3309
      // Visit the declaration name.
3310
15
      if (VisitDeclarationNameInfo(O->getNameInfo()))
3311
0
        return true;
3312
      // Visit the overloaded declaration reference.
3313
15
      if (Visit(MakeCursorOverloadedDeclRef(O, TU)))
3314
0
        return true;
3315
15
      continue;
3316
15
    }
3317
15
    case VisitorJob::SizeOfPackExprPartsKind: {
3318
2
      const SizeOfPackExpr *E = cast<SizeOfPackExprParts>(&LI)->get();
3319
2
      NamedDecl *Pack = E->getPack();
3320
2
      if (isa<TemplateTypeParmDecl>(Pack)) {
3321
1
        if (Visit(MakeCursorTypeRef(cast<TemplateTypeParmDecl>(Pack),
3322
1
                                    E->getPackLoc(), TU)))
3323
0
          return true;
3324
3325
1
        continue;
3326
1
      }
3327
3328
1
      if (isa<TemplateTemplateParmDecl>(Pack)) {
3329
0
        if (Visit(MakeCursorTemplateRef(cast<TemplateTemplateParmDecl>(Pack),
3330
0
                                        E->getPackLoc(), TU)))
3331
0
          return true;
3332
3333
0
        continue;
3334
0
      }
3335
3336
      // Non-type template parameter packs and function parameter packs are
3337
      // treated like DeclRefExpr cursors.
3338
1
      continue;
3339
1
    }
3340
3341
4
    case VisitorJob::LambdaExprPartsKind: {
3342
      // Visit non-init captures.
3343
4
      const LambdaExpr *E = cast<LambdaExprParts>(&LI)->get();
3344
4
      for (LambdaExpr::capture_iterator C = E->explicit_capture_begin(),
3345
4
                                        CEnd = E->explicit_capture_end();
3346
10
           C != CEnd; 
++C6
) {
3347
6
        if (!C->capturesVariable())
3348
1
          continue;
3349
3350
5
        if (Visit(MakeCursorVariableRef(C->getCapturedVar(), C->getLocation(),
3351
5
                                        TU)))
3352
0
          return true;
3353
5
      }
3354
      // Visit init captures
3355
6
      
for (auto InitExpr : E->capture_inits())4
{
3356
6
        if (InitExpr && 
Visit(InitExpr)5
)
3357
0
          return true;
3358
6
      }
3359
3360
4
      TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
3361
      // Visit parameters and return type, if present.
3362
4
      if (FunctionTypeLoc Proto = TL.getAs<FunctionProtoTypeLoc>()) {
3363
4
        if (E->hasExplicitParameters()) {
3364
          // Visit parameters.
3365
6
          for (unsigned I = 0, N = Proto.getNumParams(); I != N; 
++I3
)
3366
3
            if (Visit(MakeCXCursor(Proto.getParam(I), TU)))
3367
0
              return true;
3368
3
        }
3369
4
        if (E->hasExplicitResultType()) {
3370
          // Visit result type.
3371
2
          if (Visit(Proto.getReturnLoc()))
3372
0
            return true;
3373
2
        }
3374
4
      }
3375
4
      break;
3376
4
    }
3377
3378
6.31k
    case VisitorJob::PostChildrenVisitKind:
3379
6.31k
      if (PostChildrenVisitor(Parent, ClientData))
3380
0
        return true;
3381
6.31k
      break;
3382
27.0k
    }
3383
27.0k
  }
3384
1.16k
  return false;
3385
1.16k
}
3386
3387
1.16k
bool CursorVisitor::Visit(const Stmt *S) {
3388
1.16k
  VisitorWorkList *WL = nullptr;
3389
1.16k
  if (!WorkListFreeList.empty()) {
3390
537
    WL = WorkListFreeList.back();
3391
537
    WL->clear();
3392
537
    WorkListFreeList.pop_back();
3393
628
  } else {
3394
628
    WL = new VisitorWorkList();
3395
628
    WorkListCache.push_back(WL);
3396
628
  }
3397
1.16k
  EnqueueWorkList(*WL, S);
3398
1.16k
  bool result = RunVisitorWorkList(*WL);
3399
1.16k
  WorkListFreeList.push_back(WL);
3400
1.16k
  return result;
3401
1.16k
}
3402
3403
namespace {
3404
typedef SmallVector<SourceRange, 4> RefNamePieces;
3405
RefNamePieces buildPieces(unsigned NameFlags, bool IsMemberRefExpr,
3406
                          const DeclarationNameInfo &NI, SourceRange QLoc,
3407
65.9k
                          const SourceRange *TemplateArgsLoc = nullptr) {
3408
65.9k
  const bool WantQualifier = NameFlags & CXNameRange_WantQualifier;
3409
65.9k
  const bool WantTemplateArgs = NameFlags & CXNameRange_WantTemplateArgs;
3410
65.9k
  const bool WantSinglePiece = NameFlags & CXNameRange_WantSinglePiece;
3411
3412
65.9k
  const DeclarationName::NameKind Kind = NI.getName().getNameKind();
3413
3414
65.9k
  RefNamePieces Pieces;
3415
3416
65.9k
  if (WantQualifier && QLoc.isValid())
3417
86
    Pieces.push_back(QLoc);
3418
3419
65.9k
  if (Kind != DeclarationName::CXXOperatorName || 
IsMemberRefExpr60.6k
)
3420
5.35k
    Pieces.push_back(NI.getLoc());
3421
3422
65.9k
  if (WantTemplateArgs && 
TemplateArgsLoc51.3k
&&
TemplateArgsLoc->isValid()49.0k
)
3423
20
    Pieces.push_back(*TemplateArgsLoc);
3424
3425
65.9k
  if (Kind == DeclarationName::CXXOperatorName) {
3426
60.6k
    Pieces.push_back(NI.getInfo().getCXXOperatorNameBeginLoc());
3427
60.6k
    Pieces.push_back(NI.getInfo().getCXXOperatorNameEndLoc());
3428
60.6k
  }
3429
3430
65.9k
  if (WantSinglePiece) {
3431
13.2k
    SourceRange R(Pieces.front().getBegin(), Pieces.back().getEnd());
3432
13.2k
    Pieces.clear();
3433
13.2k
    Pieces.push_back(R);
3434
13.2k
  }
3435
3436
65.9k
  return Pieces;
3437
65.9k
}
3438
} // namespace
3439
3440
//===----------------------------------------------------------------------===//
3441
// Misc. API hooks.
3442
//===----------------------------------------------------------------------===//
3443
3444
namespace {
3445
struct RegisterFatalErrorHandler {
3446
1.05k
  RegisterFatalErrorHandler() {
3447
1.05k
    clang_install_aborting_llvm_fatal_error_handler();
3448
1.05k
  }
3449
};
3450
} // namespace
3451
3452
static llvm::ManagedStatic<RegisterFatalErrorHandler>
3453
    RegisterFatalErrorHandlerOnce;
3454
3455
CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
3456
1.05k
                          int displayDiagnostics) {
3457
  // We use crash recovery to make some of our APIs more reliable, implicitly
3458
  // enable it.
3459
1.05k
  if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY"))
3460
1.05k
    llvm::CrashRecoveryContext::Enable();
3461
3462
  // Look through the managed static to trigger construction of the managed
3463
  // static which registers our fatal error handler. This ensures it is only
3464
  // registered once.
3465
1.05k
  (void)*RegisterFatalErrorHandlerOnce;
3466
3467
  // Initialize targets for clang module support.
3468
1.05k
  llvm::InitializeAllTargets();
3469
1.05k
  llvm::InitializeAllTargetMCs();
3470
1.05k
  llvm::InitializeAllAsmPrinters();
3471
1.05k
  llvm::InitializeAllAsmParsers();
3472
3473
1.05k
  CIndexer *CIdxr = new CIndexer();
3474
3475
1.05k
  if (excludeDeclarationsFromPCH)
3476
281
    CIdxr->setOnlyLocalDecls();
3477
1.05k
  if (displayDiagnostics)
3478
501
    CIdxr->setDisplayDiagnostics();
3479
3480
1.05k
  if (getenv("LIBCLANG_BGPRIO_INDEX"))
3481
0
    CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() |
3482
0
                               CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
3483
1.05k
  if (getenv("LIBCLANG_BGPRIO_EDIT"))
3484
0
    CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() |
3485
0
                               CXGlobalOpt_ThreadBackgroundPriorityForEditing);
3486
3487
1.05k
  return CIdxr;
3488
1.05k
}
3489
3490
1.05k
void clang_disposeIndex(CXIndex CIdx) {
3491
1.05k
  if (CIdx)
3492
1.05k
    delete static_cast<CIndexer *>(CIdx);
3493
1.05k
}
3494
3495
0
void clang_CXIndex_setGlobalOptions(CXIndex CIdx, unsigned options) {
3496
0
  if (CIdx)
3497
0
    static_cast<CIndexer *>(CIdx)->setCXGlobalOptFlags(options);
3498
0
}
3499
3500
0
unsigned clang_CXIndex_getGlobalOptions(CXIndex CIdx) {
3501
0
  if (CIdx)
3502
0
    return static_cast<CIndexer *>(CIdx)->getCXGlobalOptFlags();
3503
0
  return 0;
3504
0
}
3505
3506
void clang_CXIndex_setInvocationEmissionPathOption(CXIndex CIdx,
3507
7
                                                   const char *Path) {
3508
7
  if (CIdx)
3509
7
    static_cast<CIndexer *>(CIdx)->setInvocationEmissionPath(Path ? Path : 
""0
);
3510
7
}
3511
3512
2
void clang_toggleCrashRecovery(unsigned isEnabled) {
3513
2
  if (isEnabled)
3514
0
    llvm::CrashRecoveryContext::Enable();
3515
2
  else
3516
2
    llvm::CrashRecoveryContext::Disable();
3517
2
}
3518
3519
CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
3520
2
                                              const char *ast_filename) {
3521
2
  CXTranslationUnit TU;
3522
2
  enum CXErrorCode Result =
3523
2
      clang_createTranslationUnit2(CIdx, ast_filename, &TU);
3524
2
  (void)Result;
3525
2
  assert((TU && Result == CXError_Success) ||
3526
2
         (!TU && Result != CXError_Success));
3527
0
  return TU;
3528
2
}
3529
3530
enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
3531
                                              const char *ast_filename,
3532
36
                                              CXTranslationUnit *out_TU) {
3533
36
  if (out_TU)
3534
35
    *out_TU = nullptr;
3535
3536
36
  if (!CIdx || 
!ast_filename33
||
!out_TU33
)
3537
3
    return CXError_InvalidArguments;
3538
3539
33
  LOG_FUNC_SECTION 
{ *Log << ast_filename; }0
3540
3541
33
  CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
3542
33
  FileSystemOptions FileSystemOpts;
3543
3544
33
  IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
3545
33
      CompilerInstance::createDiagnostics(new DiagnosticOptions());
3546
33
  std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
3547
33
      ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(),
3548
33
      ASTUnit::LoadEverything, Diags, FileSystemOpts, /*UseDebugInfo=*/false,
3549
33
      CXXIdx->getOnlyLocalDecls(), CaptureDiagsKind::All,
3550
33
      /*AllowASTWithCompilerErrors=*/true,
3551
33
      /*UserFilesAreVolatile=*/true);
3552
33
  *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU));
3553
33
  return *out_TU ? 
CXError_Success32
:
CXError_Failure1
;
3554
36
}
3555
3556
126
unsigned clang_defaultEditingTranslationUnitOptions() {
3557
126
  return CXTranslationUnit_PrecompiledPreamble |
3558
126
         CXTranslationUnit_CacheCompletionResults;
3559
126
}
3560
3561
CXTranslationUnit clang_createTranslationUnitFromSourceFile(
3562
    CXIndex CIdx, const char *source_filename, int num_command_line_args,
3563
    const char *const *command_line_args, unsigned num_unsaved_files,
3564
0
    struct CXUnsavedFile *unsaved_files) {
3565
0
  unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord;
3566
0
  return clang_parseTranslationUnit(CIdx, source_filename, command_line_args,
3567
0
                                    num_command_line_args, unsaved_files,
3568
0
                                    num_unsaved_files, Options);
3569
0
}
3570
3571
static CXErrorCode
3572
clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename,
3573
                                const char *const *command_line_args,
3574
                                int num_command_line_args,
3575
                                ArrayRef<CXUnsavedFile> unsaved_files,
3576
992
                                unsigned options, CXTranslationUnit *out_TU) {
3577
  // Set up the initial return values.
3578
992
  if (out_TU)
3579
991
    *out_TU = nullptr;
3580
3581
  // Check arguments.
3582
992
  if (!CIdx || 
!out_TU991
)
3583
1
    return CXError_InvalidArguments;
3584
3585
991
  CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
3586
3587
991
  if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
3588
0
    setThreadBackgroundPriority();
3589
3590
991
  bool PrecompilePreamble = options & CXTranslationUnit_PrecompiledPreamble;
3591
991
  bool CreatePreambleOnFirstParse =
3592
991
      options & CXTranslationUnit_CreatePreambleOnFirstParse;
3593
  // FIXME: Add a flag for modules.
3594
991
  TranslationUnitKind TUKind = (options & (CXTranslationUnit_Incomplete |
3595
991
                                           CXTranslationUnit_SingleFileParse))
3596
991
                                   ? 
TU_Prefix61
3597
991
                                   : 
TU_Complete930
;
3598
991
  bool CacheCodeCompletionResults =
3599
991
      options & CXTranslationUnit_CacheCompletionResults;
3600
991
  bool IncludeBriefCommentsInCodeCompletion =
3601
991
      options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
3602
991
  bool SingleFileParse = options & CXTranslationUnit_SingleFileParse;
3603
991
  bool ForSerialization = options & CXTranslationUnit_ForSerialization;
3604
991
  bool RetainExcludedCB =
3605
991
      options & CXTranslationUnit_RetainExcludedConditionalBlocks;
3606
991
  SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None;
3607
991
  if (options & CXTranslationUnit_SkipFunctionBodies) {
3608
6
    SkipFunctionBodies =
3609
6
        (options & CXTranslationUnit_LimitSkipFunctionBodiesToPreamble)
3610
6
            ? 
SkipFunctionBodiesScope::Preamble1
3611
6
            : 
SkipFunctionBodiesScope::PreambleAndMainFile5
;
3612
6
  }
3613
3614
  // Configure the diagnostics.
3615
991
  IntrusiveRefCntPtr<DiagnosticsEngine> Diags(
3616
991
      CompilerInstance::createDiagnostics(new DiagnosticOptions));
3617
3618
991
  if (options & CXTranslationUnit_KeepGoing)
3619
5
    Diags->setFatalsAsError(true);
3620
3621
991
  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::All;
3622
991
  if (options & CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles)
3623
1
    CaptureDiagnostics = CaptureDiagsKind::AllWithoutNonErrorsFromIncludes;
3624
3625
  // Recover resources if we crash before exiting this function.
3626
991
  llvm::CrashRecoveryContextCleanupRegistrar<
3627
991
      DiagnosticsEngine,
3628
991
      llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine>>
3629
991
      DiagCleanup(Diags.get());
3630
3631
991
  std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles(
3632
991
      new std::vector<ASTUnit::RemappedFile>());
3633
3634
  // Recover resources if we crash before exiting this function.
3635
991
  llvm::CrashRecoveryContextCleanupRegistrar<std::vector<ASTUnit::RemappedFile>>
3636
991
      RemappedCleanup(RemappedFiles.get());
3637
3638
991
  for (auto &UF : unsaved_files) {
3639
4
    std::unique_ptr<llvm::MemoryBuffer> MB =
3640
4
        llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
3641
4
    RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
3642
4
  }
3643
3644
991
  std::unique_ptr<std::vector<const char *>> Args(
3645
991
      new std::vector<const char *>());
3646
3647
  // Recover resources if we crash before exiting this method.
3648
991
  llvm::CrashRecoveryContextCleanupRegistrar<std::vector<const char *>>
3649
991
      ArgsCleanup(Args.get());
3650
3651
  // Since the Clang C library is primarily used by batch tools dealing with
3652
  // (often very broken) source code, where spell-checking can have a
3653
  // significant negative impact on performance (particularly when
3654
  // precompiled headers are involved), we disable it by default.
3655
  // Only do this if we haven't found a spell-checking-related argument.
3656
991
  bool FoundSpellCheckingArgument = false;
3657
3.78k
  for (int I = 0; I != num_command_line_args; 
++I2.79k
) {
3658
2.79k
    if (strcmp(command_line_args[I], "-fno-spell-checking") == 0 ||
3659
2.79k
        strcmp(command_line_args[I], "-fspell-checking") == 0) {
3660
2
      FoundSpellCheckingArgument = true;
3661
2
      break;
3662
2
    }
3663
2.79k
  }
3664
991
  Args->insert(Args->end(), command_line_args,
3665
991
               command_line_args + num_command_line_args);
3666
3667
991
  if (!FoundSpellCheckingArgument)
3668
989
    Args->insert(Args->begin() + 1, "-fno-spell-checking");
3669
3670
  // The 'source_filename' argument is optional.  If the caller does not
3671
  // specify it then it is assumed that the source file is specified
3672
  // in the actual argument list.
3673
  // Put the source file after command_line_args otherwise if '-x' flag is
3674
  // present it will be unused.
3675
991
  if (source_filename)
3676
213
    Args->push_back(source_filename);
3677
3678
  // Do we need the detailed preprocessing record?
3679
991
  if (options & CXTranslationUnit_DetailedPreprocessingRecord) {
3680
989
    Args->push_back("-Xclang");
3681
989
    Args->push_back("-detailed-preprocessing-record");
3682
989
  }
3683
3684
  // Suppress any editor placeholder diagnostics.
3685
991
  Args->push_back("-fallow-editor-placeholders");
3686
3687
991
  unsigned NumErrors = Diags->getClient()->getNumErrors();
3688
991
  std::unique_ptr<ASTUnit> ErrUnit;
3689
  // Unless the user specified that they want the preamble on the first parse
3690
  // set it up to be created on the first reparse. This makes the first parse
3691
  // faster, trading for a slower (first) reparse.
3692
991
  unsigned PrecompilePreambleAfterNParses =
3693
991
      !PrecompilePreamble ? 
0865
:
2 - CreatePreambleOnFirstParse126
;
3694
3695
991
  LibclangInvocationReporter InvocationReporter(
3696
991
      *CXXIdx, LibclangInvocationReporter::OperationKind::ParseOperation,
3697
991
      options, llvm::makeArrayRef(*Args), /*InvocationArgs=*/None,
3698
991
      unsaved_files);
3699
991
  std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCommandLine(
3700
991
      Args->data(), Args->data() + Args->size(),
3701
991
      CXXIdx->getPCHContainerOperations(), Diags,
3702
991
      CXXIdx->getClangResourcesPath(), CXXIdx->getOnlyLocalDecls(),
3703
991
      CaptureDiagnostics, *RemappedFiles.get(),
3704
991
      /*RemappedFilesKeepOriginalName=*/true, PrecompilePreambleAfterNParses,
3705
991
      TUKind, CacheCodeCompletionResults, IncludeBriefCommentsInCodeCompletion,
3706
991
      /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,
3707
991
      /*UserFilesAreVolatile=*/true, ForSerialization, RetainExcludedCB,
3708
991
      CXXIdx->getPCHContainerOperations()->getRawReader().getFormat(),
3709
991
      &ErrUnit));
3710
3711
  // Early failures in LoadFromCommandLine may return with ErrUnit unset.
3712
991
  if (!Unit && 
!ErrUnit2
)
3713
0
    return CXError_ASTReadError;
3714
3715
991
  if (NumErrors != Diags->getClient()->getNumErrors()) {
3716
    // Make sure to check that 'Unit' is non-NULL.
3717
428
    if (CXXIdx->getDisplayDiagnostics())
3718
69
      printDiagsToStderr(Unit ? 
Unit.get()67
:
ErrUnit.get()2
);
3719
428
  }
3720
3721
991
  if (isASTReadError(Unit ? 
Unit.get()982
:
ErrUnit.get()9
))
3722
2
    return CXError_ASTReadError;
3723
3724
989
  *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(Unit));
3725
989
  if (CXTranslationUnitImpl *TU = *out_TU) {
3726
981
    TU->ParsingOptions = options;
3727
981
    TU->Arguments.reserve(Args->size());
3728
981
    for (const char *Arg : *Args)
3729
6.87k
      TU->Arguments.push_back(Arg);
3730
981
    return CXError_Success;
3731
981
  }
3732
8
  return CXError_Failure;
3733
989
}
3734
3735
CXTranslationUnit
3736
clang_parseTranslationUnit(CXIndex CIdx, const char *source_filename,
3737
                           const char *const *command_line_args,
3738
                           int num_command_line_args,
3739
                           struct CXUnsavedFile *unsaved_files,
3740
20
                           unsigned num_unsaved_files, unsigned options) {
3741
20
  CXTranslationUnit TU;
3742
20
  enum CXErrorCode Result = clang_parseTranslationUnit2(
3743
20
      CIdx, source_filename, command_line_args, num_command_line_args,
3744
20
      unsaved_files, num_unsaved_files, options, &TU);
3745
20
  (void)Result;
3746
20
  assert((TU && Result == CXError_Success) ||
3747
20
         (!TU && Result != CXError_Success));
3748
0
  return TU;
3749
20
}
3750
3751
enum CXErrorCode clang_parseTranslationUnit2(
3752
    CXIndex CIdx, const char *source_filename,
3753
    const char *const *command_line_args, int num_command_line_args,
3754
    struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
3755
991
    unsigned options, CXTranslationUnit *out_TU) {
3756
991
  noteBottomOfStack();
3757
991
  SmallVector<const char *, 4> Args;
3758
991
  Args.push_back("clang");
3759
991
  Args.append(command_line_args, command_line_args + num_command_line_args);
3760
991
  return clang_parseTranslationUnit2FullArgv(
3761
991
      CIdx, source_filename, Args.data(), Args.size(), unsaved_files,
3762
991
      num_unsaved_files, options, out_TU);
3763
991
}
3764
3765
enum CXErrorCode clang_parseTranslationUnit2FullArgv(
3766
    CXIndex CIdx, const char *source_filename,
3767
    const char *const *command_line_args, int num_command_line_args,
3768
    struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
3769
992
    unsigned options, CXTranslationUnit *out_TU) {
3770
992
  LOG_FUNC_SECTION {
3771
0
    *Log << source_filename << ": ";
3772
0
    for (int i = 0; i != num_command_line_args; ++i)
3773
0
      *Log << command_line_args[i] << " ";
3774
0
  }
3775
3776
992
  if (num_unsaved_files && 
!unsaved_files4
)
3777
0
    return CXError_InvalidArguments;
3778
3779
992
  CXErrorCode result = CXError_Failure;
3780
992
  auto ParseTranslationUnitImpl = [=, &result] {
3781
992
    noteBottomOfStack();
3782
992
    result = clang_parseTranslationUnit_Impl(
3783
992
        CIdx, source_filename, command_line_args, num_command_line_args,
3784
992
        llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU);
3785
992
  };
3786
3787
992
  llvm::CrashRecoveryContext CRC;
3788
3789
992
  if (!RunSafely(CRC, ParseTranslationUnitImpl)) {
3790
7
    fprintf(stderr, "libclang: crash detected during parsing: {\n");
3791
7
    fprintf(stderr, "  'source_filename' : '%s'\n", source_filename);
3792
7
    fprintf(stderr, "  'command_line_args' : [");
3793
36
    for (int i = 0; i != num_command_line_args; 
++i29
) {
3794
29
      if (i)
3795
22
        fprintf(stderr, ", ");
3796
29
      fprintf(stderr, "'%s'", command_line_args[i]);
3797
29
    }
3798
7
    fprintf(stderr, "],\n");
3799
7
    fprintf(stderr, "  'unsaved_files' : [");
3800
9
    for (unsigned i = 0; i != num_unsaved_files; 
++i2
) {
3801
2
      if (i)
3802
0
        fprintf(stderr, ", ");
3803
2
      fprintf(stderr, "('%s', '...', %ld)", unsaved_files[i].Filename,
3804
2
              unsaved_files[i].Length);
3805
2
    }
3806
7
    fprintf(stderr, "],\n");
3807
7
    fprintf(stderr, "  'options' : %d,\n", options);
3808
7
    fprintf(stderr, "}\n");
3809
3810
7
    return CXError_Crashed;
3811
985
  } else if (getenv("LIBCLANG_RESOURCE_USAGE")) {
3812
0
    if (CXTranslationUnit *TU = out_TU)
3813
0
      PrintLibclangResourceUsage(*TU);
3814
0
  }
3815
3816
985
  return result;
3817
992
}
3818
3819
0
CXString clang_Type_getObjCEncoding(CXType CT) {
3820
0
  CXTranslationUnit tu = static_cast<CXTranslationUnit>(CT.data[1]);
3821
0
  ASTContext &Ctx = getASTUnit(tu)->getASTContext();
3822
0
  std::string encoding;
3823
0
  Ctx.getObjCEncodingForType(QualType::getFromOpaquePtr(CT.data[0]), encoding);
3824
3825
0
  return cxstring::createDup(encoding);
3826
0
}
3827
3828
5
static const IdentifierInfo *getMacroIdentifier(CXCursor C) {
3829
5
  if (C.kind == CXCursor_MacroDefinition) {
3830
2
    if (const MacroDefinitionRecord *MDR = getCursorMacroDefinition(C))
3831
2
      return MDR->getName();
3832
3
  } else if (C.kind == CXCursor_MacroExpansion) {
3833
3
    MacroExpansionCursor ME = getCursorMacroExpansion(C);
3834
3
    return ME.getName();
3835
3
  }
3836
0
  return nullptr;
3837
5
}
3838
3839
2
unsigned clang_Cursor_isMacroFunctionLike(CXCursor C) {
3840
2
  const IdentifierInfo *II = getMacroIdentifier(C);
3841
2
  if (!II) {
3842
0
    return false;
3843
0
  }
3844
2
  ASTUnit *ASTU = getCursorASTUnit(C);
3845
2
  Preprocessor &PP = ASTU->getPreprocessor();
3846
2
  if (const MacroInfo *MI = PP.getMacroInfo(II))
3847
2
    return MI->isFunctionLike();
3848
0
  return false;
3849
2
}
3850
3851
3
unsigned clang_Cursor_isMacroBuiltin(CXCursor C) {
3852
3
  const IdentifierInfo *II = getMacroIdentifier(C);
3853
3
  if (!II) {
3854
0
    return false;
3855
0
  }
3856
3
  ASTUnit *ASTU = getCursorASTUnit(C);
3857
3
  Preprocessor &PP = ASTU->getPreprocessor();
3858
3
  if (const MacroInfo *MI = PP.getMacroInfo(II))
3859
3
    return MI->isBuiltinMacro();
3860
0
  return false;
3861
3
}
3862
3863
0
unsigned clang_Cursor_isFunctionInlined(CXCursor C) {
3864
0
  const Decl *D = getCursorDecl(C);
3865
0
  const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
3866
0
  if (!FD) {
3867
0
    return false;
3868
0
  }
3869
0
  return FD->isInlined();
3870
0
}
3871
3872
0
static StringLiteral *getCFSTR_value(CallExpr *callExpr) {
3873
0
  if (callExpr->getNumArgs() != 1) {
3874
0
    return nullptr;
3875
0
  }
3876
3877
0
  StringLiteral *S = nullptr;
3878
0
  auto *arg = callExpr->getArg(0);
3879
0
  if (arg->getStmtClass() == Stmt::ImplicitCastExprClass) {
3880
0
    ImplicitCastExpr *I = static_cast<ImplicitCastExpr *>(arg);
3881
0
    auto *subExpr = I->getSubExprAsWritten();
3882
3883
0
    if (subExpr->getStmtClass() != Stmt::StringLiteralClass) {
3884
0
      return nullptr;
3885
0
    }
3886
3887
0
    S = static_cast<StringLiteral *>(I->getSubExprAsWritten());
3888
0
  } else if (arg->getStmtClass() == Stmt::StringLiteralClass) {
3889
0
    S = static_cast<StringLiteral *>(callExpr->getArg(0));
3890
0
  } else {
3891
0
    return nullptr;
3892
0
  }
3893
0
  return S;
3894
0
}
3895
3896
struct ExprEvalResult {
3897
  CXEvalResultKind EvalType;
3898
  union {
3899
    unsigned long long unsignedVal;
3900
    long long intVal;
3901
    double floatVal;
3902
    char *stringVal;
3903
  } EvalData;
3904
  bool IsUnsignedInt;
3905
13
  ~ExprEvalResult() {
3906
13
    if (EvalType != CXEval_UnExposed && EvalType != CXEval_Float &&
3907
13
        EvalType != CXEval_Int) {
3908
1
      delete[] EvalData.stringVal;
3909
1
    }
3910
13
  }
3911
};
3912
3913
13
void clang_EvalResult_dispose(CXEvalResult E) {
3914
13
  delete static_cast<ExprEvalResult *>(E);
3915
13
}
3916
3917
13
CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E) {
3918
13
  if (!E) {
3919
0
    return CXEval_UnExposed;
3920
0
  }
3921
13
  return ((ExprEvalResult *)E)->EvalType;
3922
13
}
3923
3924
0
int clang_EvalResult_getAsInt(CXEvalResult E) {
3925
0
  return clang_EvalResult_getAsLongLong(E);
3926
0
}
3927
3928
5
long long clang_EvalResult_getAsLongLong(CXEvalResult E) {
3929
5
  if (!E) {
3930
0
    return 0;
3931
0
  }
3932
5
  ExprEvalResult *Result = (ExprEvalResult *)E;
3933
5
  if (Result->IsUnsignedInt)
3934
0
    return Result->EvalData.unsignedVal;
3935
5
  return Result->EvalData.intVal;
3936
5
}
3937
3938
12
unsigned clang_EvalResult_isUnsignedInt(CXEvalResult E) {
3939
12
  return ((ExprEvalResult *)E)->IsUnsignedInt;
3940
12
}
3941
3942
7
unsigned long long clang_EvalResult_getAsUnsigned(CXEvalResult E) {
3943
7
  if (!E) {
3944
0
    return 0;
3945
0
  }
3946
3947
7
  ExprEvalResult *Result = (ExprEvalResult *)E;
3948
7
  if (Result->IsUnsignedInt)
3949
7
    return Result->EvalData.unsignedVal;
3950
0
  return Result->EvalData.intVal;
3951
7
}
3952
3953
0
double clang_EvalResult_getAsDouble(CXEvalResult E) {
3954
0
  if (!E) {
3955
0
    return 0;
3956
0
  }
3957
0
  return ((ExprEvalResult *)E)->EvalData.floatVal;
3958
0
}
3959
3960
0
const char *clang_EvalResult_getAsStr(CXEvalResult E) {
3961
0
  if (!E) {
3962
0
    return nullptr;
3963
0
  }
3964
0
  return ((ExprEvalResult *)E)->EvalData.stringVal;
3965
0
}
3966
3967
14
static const ExprEvalResult *evaluateExpr(Expr *expr, CXCursor C) {
3968
14
  Expr::EvalResult ER;
3969
14
  ASTContext &ctx = getCursorContext(C);
3970
14
  if (!expr)
3971
0
    return nullptr;
3972
3973
14
  expr = expr->IgnoreParens();
3974
14
  if (expr->isValueDependent())
3975
1
    return nullptr;
3976
13
  if (!expr->EvaluateAsRValue(ER, ctx))
3977
0
    return nullptr;
3978
3979
13
  QualType rettype;
3980
13
  CallExpr *callExpr;
3981
13
  auto result = std::make_unique<ExprEvalResult>();
3982
13
  result->EvalType = CXEval_UnExposed;
3983
13
  result->IsUnsignedInt = false;
3984
3985
13
  if (ER.Val.isInt()) {
3986
12
    result->EvalType = CXEval_Int;
3987
3988
12
    auto &val = ER.Val.getInt();
3989
12
    if (val.isUnsigned()) {
3990
7
      result->IsUnsignedInt = true;
3991
7
      result->EvalData.unsignedVal = val.getZExtValue();
3992
7
    } else {
3993
5
      result->EvalData.intVal = val.getExtValue();
3994
5
    }
3995
3996
12
    return result.release();
3997
12
  }
3998
3999
1
  if (ER.Val.isFloat()) {
4000
0
    llvm::SmallVector<char, 100> Buffer;
4001
0
    ER.Val.getFloat().toString(Buffer);
4002
0
    std::string floatStr(Buffer.data(), Buffer.size());
4003
0
    result->EvalType = CXEval_Float;
4004
0
    bool ignored;
4005
0
    llvm::APFloat apFloat = ER.Val.getFloat();
4006
0
    apFloat.convert(llvm::APFloat::IEEEdouble(),
4007
0
                    llvm::APFloat::rmNearestTiesToEven, &ignored);
4008
0
    result->EvalData.floatVal = apFloat.convertToDouble();
4009
0
    return result.release();
4010
0
  }
4011
4012
1
  if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) {
4013
0
    const ImplicitCastExpr *I = dyn_cast<ImplicitCastExpr>(expr);
4014
0
    auto *subExpr = I->getSubExprAsWritten();
4015
0
    if (subExpr->getStmtClass() == Stmt::StringLiteralClass ||
4016
0
        subExpr->getStmtClass() == Stmt::ObjCStringLiteralClass) {
4017
0
      const StringLiteral *StrE = nullptr;
4018
0
      const ObjCStringLiteral *ObjCExpr;
4019
0
      ObjCExpr = dyn_cast<ObjCStringLiteral>(subExpr);
4020
4021
0
      if (ObjCExpr) {
4022
0
        StrE = ObjCExpr->getString();
4023
0
        result->EvalType = CXEval_ObjCStrLiteral;
4024
0
      } else {
4025
0
        StrE = cast<StringLiteral>(I->getSubExprAsWritten());
4026
0
        result->EvalType = CXEval_StrLiteral;
4027
0
      }
4028
4029
0
      std::string strRef(StrE->getString().str());
4030
0
      result->EvalData.stringVal = new char[strRef.size() + 1];
4031
0
      strncpy((char *)result->EvalData.stringVal, strRef.c_str(),
4032
0
              strRef.size());
4033
0
      result->EvalData.stringVal[strRef.size()] = '\0';
4034
0
      return result.release();
4035
0
    }
4036
1
  } else if (expr->getStmtClass() == Stmt::ObjCStringLiteralClass ||
4037
1
             
expr->getStmtClass() == Stmt::StringLiteralClass0
) {
4038
1
    const StringLiteral *StrE = nullptr;
4039
1
    const ObjCStringLiteral *ObjCExpr;
4040
1
    ObjCExpr = dyn_cast<ObjCStringLiteral>(expr);
4041
4042
1
    if (ObjCExpr) {
4043
1
      StrE = ObjCExpr->getString();
4044
1
      result->EvalType = CXEval_ObjCStrLiteral;
4045
1
    } else {
4046
0
      StrE = cast<StringLiteral>(expr);
4047
0
      result->EvalType = CXEval_StrLiteral;
4048
0
    }
4049
4050
1
    std::string strRef(StrE->getString().str());
4051
1
    result->EvalData.stringVal = new char[strRef.size() + 1];
4052
1
    strncpy((char *)result->EvalData.stringVal, strRef.c_str(), strRef.size());
4053
1
    result->EvalData.stringVal[strRef.size()] = '\0';
4054
1
    return result.release();
4055
1
  }
4056
4057
0
  if (expr->getStmtClass() == Stmt::CStyleCastExprClass) {
4058
0
    CStyleCastExpr *CC = static_cast<CStyleCastExpr *>(expr);
4059
4060
0
    rettype = CC->getType();
4061
0
    if (rettype.getAsString() == "CFStringRef" &&
4062
0
        CC->getSubExpr()->getStmtClass() == Stmt::CallExprClass) {
4063
4064
0
      callExpr = static_cast<CallExpr *>(CC->getSubExpr());
4065
0
      StringLiteral *S = getCFSTR_value(callExpr);
4066
0
      if (S) {
4067
0
        std::string strLiteral(S->getString().str());
4068
0
        result->EvalType = CXEval_CFStr;
4069
4070
0
        result->EvalData.stringVal = new char[strLiteral.size() + 1];
4071
0
        strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(),
4072
0
                strLiteral.size());
4073
0
        result->EvalData.stringVal[strLiteral.size()] = '\0';
4074
0
        return result.release();
4075
0
      }
4076
0
    }
4077
4078
0
  } else if (expr->getStmtClass() == Stmt::CallExprClass) {
4079
0
    callExpr = static_cast<CallExpr *>(expr);
4080
0
    rettype = callExpr->getCallReturnType(ctx);
4081
4082
0
    if (rettype->isVectorType() || callExpr->getNumArgs() > 1)
4083
0
      return nullptr;
4084
4085
0
    if (rettype->isIntegralType(ctx) || rettype->isRealFloatingType()) {
4086
0
      if (callExpr->getNumArgs() == 1 &&
4087
0
          !callExpr->getArg(0)->getType()->isIntegralType(ctx))
4088
0
        return nullptr;
4089
0
    } else if (rettype.getAsString() == "CFStringRef") {
4090
4091
0
      StringLiteral *S = getCFSTR_value(callExpr);
4092
0
      if (S) {
4093
0
        std::string strLiteral(S->getString().str());
4094
0
        result->EvalType = CXEval_CFStr;
4095
0
        result->EvalData.stringVal = new char[strLiteral.size() + 1];
4096
0
        strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(),
4097
0
                strLiteral.size());
4098
0
        result->EvalData.stringVal[strLiteral.size()] = '\0';
4099
0
        return result.release();
4100
0
      }
4101
0
    }
4102
0
  } else if (expr->getStmtClass() == Stmt::DeclRefExprClass) {
4103
0
    DeclRefExpr *D = static_cast<DeclRefExpr *>(expr);
4104
0
    ValueDecl *V = D->getDecl();
4105
0
    if (V->getKind() == Decl::Function) {
4106
0
      std::string strName = V->getNameAsString();
4107
0
      result->EvalType = CXEval_Other;
4108
0
      result->EvalData.stringVal = new char[strName.size() + 1];
4109
0
      strncpy(result->EvalData.stringVal, strName.c_str(), strName.size());
4110
0
      result->EvalData.stringVal[strName.size()] = '\0';
4111
0
      return result.release();
4112
0
    }
4113
0
  }
4114
4115
0
  return nullptr;
4116
0
}
4117
4118
9
static const Expr *evaluateDeclExpr(const Decl *D) {
4119
9
  if (!D)
4120
0
    return nullptr;
4121
9
  if (auto *Var = dyn_cast<VarDecl>(D))
4122
8
    return Var->getInit();
4123
1
  else if (auto *Field = dyn_cast<FieldDecl>(D))
4124
1
    return Field->getInClassInitializer();
4125
0
  return nullptr;
4126
9
}
4127
4128
1
static const Expr *evaluateCompoundStmtExpr(const CompoundStmt *CS) {
4129
1
  assert(CS && "invalid compound statement");
4130
1
  for (auto *bodyIterator : CS->body()) {
4131
1
    if (const auto *E = dyn_cast<Expr>(bodyIterator))
4132
1
      return E;
4133
1
  }
4134
0
  return nullptr;
4135
1
}
4136
4137
15
CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
4138
15
  const Expr *E = nullptr;
4139
15
  if (clang_getCursorKind(C) == CXCursor_CompoundStmt)
4140
1
    E = evaluateCompoundStmtExpr(cast<CompoundStmt>(getCursorStmt(C)));
4141
14
  else if (clang_isDeclaration(C.kind))
4142
9
    E = evaluateDeclExpr(getCursorDecl(C));
4143
5
  else if (clang_isExpression(C.kind))
4144
4
    E = getCursorExpr(C);
4145
15
  if (E)
4146
14
    return const_cast<CXEvalResult>(
4147
14
        reinterpret_cast<const void *>(evaluateExpr(const_cast<Expr *>(E), C)));
4148
1
  return nullptr;
4149
15
}
4150
4151
0
unsigned clang_Cursor_hasAttrs(CXCursor C) {
4152
0
  const Decl *D = getCursorDecl(C);
4153
0
  if (!D) {
4154
0
    return 0;
4155
0
  }
4156
4157
0
  if (D->hasAttrs()) {
4158
0
    return 1;
4159
0
  }
4160
4161
0
  return 0;
4162
0
}
4163
59
unsigned clang_defaultSaveOptions(CXTranslationUnit TU) {
4164
59
  return CXSaveTranslationUnit_None;
4165
59
}
4166
4167
static CXSaveError clang_saveTranslationUnit_Impl(CXTranslationUnit TU,
4168
                                                  const char *FileName,
4169
59
                                                  unsigned options) {
4170
59
  CIndexer *CXXIdx = TU->CIdx;
4171
59
  if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
4172
0
    setThreadBackgroundPriority();
4173
4174
59
  bool hadError = cxtu::getASTUnit(TU)->Save(FileName);
4175
59
  return hadError ? 
CXSaveError_Unknown0
: CXSaveError_None;
4176
59
}
4177
4178
int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName,
4179
59
                              unsigned options) {
4180
59
  LOG_FUNC_SECTION 
{ *Log << TU << ' ' << FileName; }0
4181
4182
59
  if (isNotUsableTU(TU)) {
4183
0
    LOG_BAD_TU(TU);
4184
0
    return CXSaveError_InvalidTU;
4185
0
  }
4186
4187
59
  ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4188
59
  ASTUnit::ConcurrencyCheck Check(*CXXUnit);
4189
59
  if (!CXXUnit->hasSema())
4190
0
    return CXSaveError_InvalidTU;
4191
4192
59
  CXSaveError result;
4193
59
  auto SaveTranslationUnitImpl = [=, &result]() {
4194
59
    result = clang_saveTranslationUnit_Impl(TU, FileName, options);
4195
59
  };
4196
4197
59
  if (!CXXUnit->getDiagnostics().hasUnrecoverableErrorOccurred()) {
4198
54
    SaveTranslationUnitImpl();
4199
4200
54
    if (getenv("LIBCLANG_RESOURCE_USAGE"))
4201
0
      PrintLibclangResourceUsage(TU);
4202
4203
54
    return result;
4204
54
  }
4205
4206
  // We have an AST that has invalid nodes due to compiler errors.
4207
  // Use a crash recovery thread for protection.
4208
4209
5
  llvm::CrashRecoveryContext CRC;
4210
4211
5
  if (!RunSafely(CRC, SaveTranslationUnitImpl)) {
4212
0
    fprintf(stderr, "libclang: crash detected during AST saving: {\n");
4213
0
    fprintf(stderr, "  'filename' : '%s'\n", FileName);
4214
0
    fprintf(stderr, "  'options' : %d,\n", options);
4215
0
    fprintf(stderr, "}\n");
4216
4217
0
    return CXSaveError_Unknown;
4218
4219
5
  } else if (getenv("LIBCLANG_RESOURCE_USAGE")) {
4220
0
    PrintLibclangResourceUsage(TU);
4221
0
  }
4222
4223
5
  return result;
4224
5
}
4225
4226
1.05k
void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
4227
1.05k
  if (CTUnit) {
4228
    // If the translation unit has been marked as unsafe to free, just discard
4229
    // it.
4230
1.04k
    ASTUnit *Unit = cxtu::getASTUnit(CTUnit);
4231
1.04k
    if (Unit && Unit->isUnsafeToFree())
4232
1
      return;
4233
4234
1.04k
    delete cxtu::getASTUnit(CTUnit);
4235
1.04k
    delete CTUnit->StringPool;
4236
1.04k
    delete static_cast<CXDiagnosticSetImpl *>(CTUnit->Diagnostics);
4237
1.04k
    disposeOverridenCXCursorsPool(CTUnit->OverridenCursorsPool);
4238
1.04k
    delete CTUnit->CommentToXML;
4239
1.04k
    delete CTUnit;
4240
1.04k
  }
4241
1.05k
}
4242
4243
25
unsigned clang_suspendTranslationUnit(CXTranslationUnit CTUnit) {
4244
25
  if (CTUnit) {
4245
25
    ASTUnit *Unit = cxtu::getASTUnit(CTUnit);
4246
4247
25
    if (Unit && Unit->isUnsafeToFree())
4248
0
      return false;
4249
4250
25
    Unit->ResetForParse();
4251
25
    return true;
4252
25
  }
4253
4254
0
  return false;
4255
25
}
4256
4257
814
unsigned clang_defaultReparseOptions(CXTranslationUnit TU) {
4258
814
  return CXReparse_None;
4259
814
}
4260
4261
static CXErrorCode
4262
clang_reparseTranslationUnit_Impl(CXTranslationUnit TU,
4263
                                  ArrayRef<CXUnsavedFile> unsaved_files,
4264
814
                                  unsigned options) {
4265
  // Check arguments.
4266
814
  if (isNotUsableTU(TU)) {
4267
0
    LOG_BAD_TU(TU);
4268
0
    return CXError_InvalidArguments;
4269
0
  }
4270
4271
  // Reset the associated diagnostics.
4272
814
  delete static_cast<CXDiagnosticSetImpl *>(TU->Diagnostics);
4273
814
  TU->Diagnostics = nullptr;
4274
4275
814
  CIndexer *CXXIdx = TU->CIdx;
4276
814
  if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing))
4277
0
    setThreadBackgroundPriority();
4278
4279
814
  ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4280
814
  ASTUnit::ConcurrencyCheck Check(*CXXUnit);
4281
4282
814
  std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles(
4283
814
      new std::vector<ASTUnit::RemappedFile>());
4284
4285
  // Recover resources if we crash before exiting this function.
4286
814
  llvm::CrashRecoveryContextCleanupRegistrar<std::vector<ASTUnit::RemappedFile>>
4287
814
      RemappedCleanup(RemappedFiles.get());
4288
4289
814
  for (auto &UF : unsaved_files) {
4290
12
    std::unique_ptr<llvm::MemoryBuffer> MB =
4291
12
        llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
4292
12
    RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
4293
12
  }
4294
4295
814
  if (!CXXUnit->Reparse(CXXIdx->getPCHContainerOperations(),
4296
814
                        *RemappedFiles.get()))
4297
813
    return CXError_Success;
4298
1
  if (isASTReadError(CXXUnit))
4299
0
    return CXError_ASTReadError;
4300
1
  return CXError_Failure;
4301
1
}
4302
4303
int clang_reparseTranslationUnit(CXTranslationUnit TU,
4304
                                 unsigned num_unsaved_files,
4305
                                 struct CXUnsavedFile *unsaved_files,
4306
814
                                 unsigned options) {
4307
814
  LOG_FUNC_SECTION 
{ *Log << TU; }0
4308
4309
814
  if (num_unsaved_files && 
!unsaved_files12
)
4310
0
    return CXError_InvalidArguments;
4311
4312
814
  CXErrorCode result;
4313
814
  auto ReparseTranslationUnitImpl = [=, &result]() {
4314
814
    result = clang_reparseTranslationUnit_Impl(
4315
814
        TU, llvm::makeArrayRef(unsaved_files, num_unsaved_files), options);
4316
814
  };
4317
4318
814
  llvm::CrashRecoveryContext CRC;
4319
4320
814
  if (!RunSafely(CRC, ReparseTranslationUnitImpl)) {
4321
1
    fprintf(stderr, "libclang: crash detected during reparsing\n");
4322
1
    cxtu::getASTUnit(TU)->setUnsafeToFree(true);
4323
1
    return CXError_Crashed;
4324
813
  } else if (getenv("LIBCLANG_RESOURCE_USAGE"))
4325
0
    PrintLibclangResourceUsage(TU);
4326
4327
813
  return result;
4328
814
}
4329
4330
0
CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) {
4331
0
  if (isNotUsableTU(CTUnit)) {
4332
0
    LOG_BAD_TU(CTUnit);
4333
0
    return cxstring::createEmpty();
4334
0
  }
4335
4336
0
  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
4337
0
  return cxstring::createDup(CXXUnit->getOriginalSourceFileName());
4338
0
}
4339
4340
200
CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
4341
200
  if (isNotUsableTU(TU)) {
4342
0
    LOG_BAD_TU(TU);
4343
0
    return clang_getNullCursor();
4344
0
  }
4345
4346
200
  ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4347
200
  return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
4348
200
}
4349
4350
2
CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit) {
4351
2
  if (isNotUsableTU(CTUnit)) {
4352
0
    LOG_BAD_TU(CTUnit);
4353
0
    return nullptr;
4354
0
  }
4355
4356
2
  CXTargetInfoImpl *impl = new CXTargetInfoImpl();
4357
2
  impl->TranslationUnit = CTUnit;
4358
2
  return impl;
4359
2
}
4360
4361
2
CXString clang_TargetInfo_getTriple(CXTargetInfo TargetInfo) {
4362
2
  if (!TargetInfo)
4363
0
    return cxstring::createEmpty();
4364
4365
2
  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
4366
2
  assert(!isNotUsableTU(CTUnit) &&
4367
2
         "Unexpected unusable translation unit in TargetInfo");
4368
4369
0
  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
4370
2
  std::string Triple =
4371
2
      CXXUnit->getASTContext().getTargetInfo().getTriple().normalize();
4372
2
  return cxstring::createDup(Triple);
4373
2
}
4374
4375
2
int clang_TargetInfo_getPointerWidth(CXTargetInfo TargetInfo) {
4376
2
  if (!TargetInfo)
4377
0
    return -1;
4378
4379
2
  CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
4380
2
  assert(!isNotUsableTU(CTUnit) &&
4381
2
         "Unexpected unusable translation unit in TargetInfo");
4382
4383
0
  ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
4384
2
  return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth();
4385
2
}
4386
4387
2
void clang_TargetInfo_dispose(CXTargetInfo TargetInfo) {
4388
2
  if (!TargetInfo)
4389
0
    return;
4390
4391
2
  delete TargetInfo;
4392
2
}
4393
4394
//===----------------------------------------------------------------------===//
4395
// CXFile Operations.
4396
//===----------------------------------------------------------------------===//
4397
4398
68.2k
CXString clang_getFileName(CXFile SFile) {
4399
68.2k
  if (!SFile)
4400
54.1k
    return cxstring::createNull();
4401
4402
14.1k
  FileEntry *FEnt = static_cast<FileEntry *>(SFile);
4403
14.1k
  return cxstring::createRef(FEnt->getName());
4404
68.2k
}
4405
4406
0
time_t clang_getFileTime(CXFile SFile) {
4407
0
  if (!SFile)
4408
0
    return 0;
4409
4410
0
  FileEntry *FEnt = static_cast<FileEntry *>(SFile);
4411
0
  return FEnt->getModificationTime();
4412
0
}
4413
4414
473
CXFile clang_getFile(CXTranslationUnit TU, const char *file_name) {
4415
473
  if (isNotUsableTU(TU)) {
4416
0
    LOG_BAD_TU(TU);
4417
0
    return nullptr;
4418
0
  }
4419
4420
473
  ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4421
4422
473
  FileManager &FMgr = CXXUnit->getFileManager();
4423
473
  auto File = FMgr.getFile(file_name);
4424
473
  if (!File)
4425
0
    return nullptr;
4426
473
  return const_cast<FileEntry *>(*File);
4427
473
}
4428
4429
const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
4430
0
                                  size_t *size) {
4431
0
  if (isNotUsableTU(TU)) {
4432
0
    LOG_BAD_TU(TU);
4433
0
    return nullptr;
4434
0
  }
4435
4436
0
  const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
4437
0
  FileID fid = SM.translateFile(static_cast<FileEntry *>(file));
4438
0
  llvm::Optional<llvm::MemoryBufferRef> buf = SM.getBufferOrNone(fid);
4439
0
  if (!buf) {
4440
0
    if (size)
4441
0
      *size = 0;
4442
0
    return nullptr;
4443
0
  }
4444
0
  if (size)
4445
0
    *size = buf->getBufferSize();
4446
0
  return buf->getBufferStart();
4447
0
}
4448
4449
329
unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU, CXFile file) {
4450
329
  if (isNotUsableTU(TU)) {
4451
0
    LOG_BAD_TU(TU);
4452
0
    return 0;
4453
0
  }
4454
4455
329
  if (!file)
4456
4
    return 0;
4457
4458
325
  ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4459
325
  FileEntry *FEnt = static_cast<FileEntry *>(file);
4460
325
  return CXXUnit->getPreprocessor()
4461
325
      .getHeaderSearchInfo()
4462
325
      .isFileMultipleIncludeGuarded(FEnt);
4463
329
}
4464
4465
0
int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID) {
4466
0
  if (!file || !outID)
4467
0
    return 1;
4468
4469
0
  FileEntry *FEnt = static_cast<FileEntry *>(file);
4470
0
  const llvm::sys::fs::UniqueID &ID = FEnt->getUniqueID();
4471
0
  outID->data[0] = ID.getDevice();
4472
0
  outID->data[1] = ID.getFile();
4473
0
  outID->data[2] = FEnt->getModificationTime();
4474
0
  return 0;
4475
0
}
4476
4477
0
int clang_File_isEqual(CXFile file1, CXFile file2) {
4478
0
  if (file1 == file2)
4479
0
    return true;
4480
4481
0
  if (!file1 || !file2)
4482
0
    return false;
4483
4484
0
  FileEntry *FEnt1 = static_cast<FileEntry *>(file1);
4485
0
  FileEntry *FEnt2 = static_cast<FileEntry *>(file2);
4486
0
  return FEnt1->getUniqueID() == FEnt2->getUniqueID();
4487
0
}
4488
4489
1
CXString clang_File_tryGetRealPathName(CXFile SFile) {
4490
1
  if (!SFile)
4491
0
    return cxstring::createNull();
4492
4493
1
  FileEntry *FEnt = static_cast<FileEntry *>(SFile);
4494
1
  return cxstring::createRef(FEnt->tryGetRealPathName());
4495
1
}
4496
4497
//===----------------------------------------------------------------------===//
4498
// CXCursor Operations.
4499
//===----------------------------------------------------------------------===//
4500
4501
38.7k
static const Decl *getDeclFromExpr(const Stmt *E) {
4502
38.7k
  if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
4503
2.60k
    return getDeclFromExpr(CE->getSubExpr());
4504
4505
36.1k
  if (const DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E))
4506
26.5k
    return RefExpr->getDecl();
4507
9.55k
  if (const MemberExpr *ME = dyn_cast<MemberExpr>(E))
4508
2.55k
    return ME->getMemberDecl();
4509
7.00k
  if (const ObjCIvarRefExpr *RE = dyn_cast<ObjCIvarRefExpr>(E))
4510
4
    return RE->getDecl();
4511
6.99k
  if (const ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(E)) {
4512
19
    if (PRE->isExplicitProperty())
4513
10
      return PRE->getExplicitProperty();
4514
    // It could be messaging both getter and setter as in:
4515
    // ++myobj.myprop;
4516
    // in which case prefer to associate the setter since it is less obvious
4517
    // from inspecting the source that the setter is going to get called.
4518
9
    if (PRE->isMessagingSetter())
4519
6
      return PRE->getImplicitPropertySetter();
4520
3
    return PRE->getImplicitPropertyGetter();
4521
9
  }
4522
6.97k
  if (const PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E))
4523
0
    return getDeclFromExpr(POE->getSyntacticForm());
4524
6.97k
  if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(E))
4525
2
    if (Expr *Src = OVE->getSourceExpr())
4526
2
      return getDeclFromExpr(Src);
4527
4528
6.97k
  if (const CallExpr *CE = dyn_cast<CallExpr>(E))
4529
962
    return getDeclFromExpr(CE->getCallee());
4530
6.01k
  if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E))
4531
198
    if (!CE->isElidable())
4532
172
      return CE->getConstructor();
4533
5.84k
  if (const CXXInheritedCtorInitExpr *CE =
4534
5.84k
          dyn_cast<CXXInheritedCtorInitExpr>(E))
4535
0
    return CE->getConstructor();
4536
5.84k
  if (const ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(E))
4537
210
    return OME->getMethodDecl();
4538
4539
5.63k
  if (const ObjCProtocolExpr *PE = dyn_cast<ObjCProtocolExpr>(E))
4540
12
    return PE->getProtocol();
4541
5.61k
  if (const SubstNonTypeTemplateParmPackExpr *NTTP =
4542
5.61k
          dyn_cast<SubstNonTypeTemplateParmPackExpr>(E))
4543
0
    return NTTP->getParameterPack();
4544
5.61k
  if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E))
4545
18
    if (isa<NonTypeTemplateParmDecl>(SizeOfPack->getPack()) ||
4546
18
        isa<ParmVarDecl>(SizeOfPack->getPack()))
4547
10
      return SizeOfPack->getPack();
4548
4549
5.60k
  return nullptr;
4550
5.61k
}
4551
4552
10.4k
static SourceLocation getLocationFromExpr(const Expr *E) {
4553
10.4k
  if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
4554
2.29k
    return getLocationFromExpr(CE->getSubExpr());
4555
4556
8.18k
  if (const ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
4557
46
    return /*FIXME:*/ Msg->getLeftLoc();
4558
8.13k
  if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
4559
2.44k
    return DRE->getLocation();
4560
5.69k
  if (const MemberExpr *Member = dyn_cast<MemberExpr>(E))
4561
819
    return Member->getMemberLoc();
4562
4.87k
  if (const ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
4563
0
    return Ivar->getLocation();
4564
4.87k
  if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E))
4565
0
    return SizeOfPack->getPackLoc();
4566
4.87k
  if (const ObjCPropertyRefExpr *PropRef = dyn_cast<ObjCPropertyRefExpr>(E))
4567
10
    return PropRef->getLocation();
4568
4569
4.86k
  return E->getBeginLoc();
4570
4.87k
}
4571
4572
extern "C" {
4573
4574
unsigned clang_visitChildren(CXCursor parent, CXCursorVisitor visitor,
4575
205
                             CXClientData client_data) {
4576
205
  CursorVisitor CursorVis(getCursorTU(parent), visitor, client_data,
4577
205
                          /*VisitPreprocessorLast=*/false);
4578
205
  return CursorVis.VisitChildren(parent);
4579
205
}
4580
4581
#ifndef __has_feature
4582
#define __has_feature(x) 0
4583
#endif
4584
#if __has_feature(blocks)
4585
typedef enum CXChildVisitResult (^CXCursorVisitorBlock)(CXCursor cursor,
4586
                                                        CXCursor parent);
4587
4588
static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent,
4589
0
                                              CXClientData client_data) {
4590
0
  CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data;
4591
0
  return block(cursor, parent);
4592
0
}
4593
#else
4594
// If we are compiled with a compiler that doesn't have native blocks support,
4595
// define and call the block manually, so the
4596
typedef struct _CXChildVisitResult {
4597
  void *isa;
4598
  int flags;
4599
  int reserved;
4600
  enum CXChildVisitResult (*invoke)(struct _CXChildVisitResult *, CXCursor,
4601
                                    CXCursor);
4602
} * CXCursorVisitorBlock;
4603
4604
static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent,
4605
                                              CXClientData client_data) {
4606
  CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data;
4607
  return block->invoke(block, cursor, parent);
4608
}
4609
#endif
4610
4611
unsigned clang_visitChildrenWithBlock(CXCursor parent,
4612
0
                                      CXCursorVisitorBlock block) {
4613
0
  return clang_visitChildren(parent, visitWithBlock, block);
4614
0
}
4615
4616
22.4k
static CXString getDeclSpelling(const Decl *D) {
4617
22.4k
  if (!D)
4618
0
    return cxstring::createEmpty();
4619
4620
22.4k
  const NamedDecl *ND = dyn_cast<NamedDecl>(D);
4621
22.4k
  if (!ND) {
4622
193
    if (const ObjCPropertyImplDecl *PropImpl =
4623
193
            dyn_cast<ObjCPropertyImplDecl>(D))
4624
28
      if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl())
4625
28
        return cxstring::createDup(Property->getIdentifier()->getName());
4626
4627
165
    if (const ImportDecl *ImportD = dyn_cast<ImportDecl>(D))
4628
15
      if (Module *Mod = ImportD->getImportedModule())
4629
15
        return cxstring::createDup(Mod->getFullModuleName());
4630
4631
150
    return cxstring::createEmpty();
4632
165
  }
4633
4634
22.2k
  if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND))
4635
516
    return cxstring::createDup(OMD->getSelector().getAsString());
4636
4637
21.7k
  if (const ObjCCategoryImplDecl *CIMP = dyn_cast<ObjCCategoryImplDecl>(ND))
4638
    // No, this isn't the same as the code below. getIdentifier() is non-virtual
4639
    // and returns different names. NamedDecl returns the class name and
4640
    // ObjCCategoryImplDecl returns the category name.
4641
5
    return cxstring::createRef(CIMP->getIdentifier()->getNameStart());
4642
4643
21.7k
  if (isa<UsingDirectiveDecl>(D))
4644
8
    return cxstring::createEmpty();
4645
4646
21.7k
  SmallString<1024> S;
4647
21.7k
  llvm::raw_svector_ostream os(S);
4648
21.7k
  ND->printName(os);
4649
4650
21.7k
  return cxstring::createDup(os.str());
4651
21.7k
}
4652
4653
88.8k
CXString clang_getCursorSpelling(CXCursor C) {
4654
88.8k
  if (clang_isTranslationUnit(C.kind))
4655
0
    return clang_getTranslationUnitSpelling(getCursorTU(C));
4656
4657
88.8k
  if (clang_isReference(C.kind)) {
4658
1.86k
    switch (C.kind) {
4659
25
    case CXCursor_ObjCSuperClassRef: {
4660
25
      const ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first;
4661
25
      return cxstring::createRef(Super->getIdentifier()->getNameStart());
4662
0
    }
4663
215
    case CXCursor_ObjCClassRef: {
4664
215
      const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
4665
215
      return cxstring::createRef(Class->getIdentifier()->getNameStart());
4666
0
    }
4667
29
    case CXCursor_ObjCProtocolRef: {
4668
29
      const ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first;
4669
29
      assert(OID && "getCursorSpelling(): Missing protocol decl");
4670
0
      return cxstring::createRef(OID->getIdentifier()->getNameStart());
4671
0
    }
4672
166
    case CXCursor_CXXBaseSpecifier: {
4673
166
      const CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C);
4674
166
      return cxstring::createDup(B->getType().getAsString());
4675
0
    }
4676
1.07k
    case CXCursor_TypeRef: {
4677
1.07k
      const TypeDecl *Type = getCursorTypeRef(C).first;
4678
1.07k
      assert(Type && "Missing type decl");
4679
4680
0
      return cxstring::createDup(
4681
1.07k
          getCursorContext(C).getTypeDeclType(Type).getAsString());
4682
0
    }
4683
138
    case CXCursor_TemplateRef: {
4684
138
      const TemplateDecl *Template = getCursorTemplateRef(C).first;
4685
138
      assert(Template && "Missing template decl");
4686
4687
0
      return cxstring::createDup(Template->getNameAsString());
4688
0
    }
4689
4690
130
    case CXCursor_NamespaceRef: {
4691
130
      const NamedDecl *NS = getCursorNamespaceRef(C).first;
4692
130
      assert(NS && "Missing namespace decl");
4693
4694
0
      return cxstring::createDup(NS->getNameAsString());
4695
0
    }
4696
4697
46
    case CXCursor_MemberRef: {
4698
46
      const FieldDecl *Field = getCursorMemberRef(C).first;
4699
46
      assert(Field && "Missing member decl");
4700
4701
0
      return cxstring::createDup(Field->getNameAsString());
4702
0
    }
4703
4704
2
    case CXCursor_LabelRef: {
4705
2
      const LabelStmt *Label = getCursorLabelRef(C).first;
4706
2
      assert(Label && "Missing label");
4707
4708
0
      return cxstring::createRef(Label->getName());
4709
0
    }
4710
4711
21
    case CXCursor_OverloadedDeclRef: {
4712
21
      OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first;
4713
21
      if (const Decl *D = Storage.dyn_cast<const Decl *>()) {
4714
6
        if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
4715
6
          return cxstring::createDup(ND->getNameAsString());
4716
0
        return cxstring::createEmpty();
4717
6
      }
4718
15
      if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
4719
15
        return cxstring::createDup(E->getName().getAsString());
4720
0
      OverloadedTemplateStorage *Ovl =
4721
0
          Storage.get<OverloadedTemplateStorage *>();
4722
0
      if (Ovl->size() == 0)
4723
0
        return cxstring::createEmpty();
4724
0
      return cxstring::createDup((*Ovl->begin())->getNameAsString());
4725
0
    }
4726
4727
14
    case CXCursor_VariableRef: {
4728
14
      const VarDecl *Var = getCursorVariableRef(C).first;
4729
14
      assert(Var && "Missing variable decl");
4730
4731
0
      return cxstring::createDup(Var->getNameAsString());
4732
0
    }
4733
4734
0
    default:
4735
0
      return cxstring::createRef("<not implemented>");
4736
1.86k
    }
4737
1.86k
  }
4738
4739
87.0k
  if (clang_isExpression(C.kind)) {
4740
17.4k
    const Expr *E = getCursorExpr(C);
4741
4742
17.4k
    if (C.kind == CXCursor_ObjCStringLiteral ||
4743
17.4k
        
C.kind == CXCursor_StringLiteral17.4k
) {
4744
173
      const StringLiteral *SLit;
4745
173
      if (const ObjCStringLiteral *OSL = dyn_cast<ObjCStringLiteral>(E)) {
4746
2
        SLit = OSL->getString();
4747
171
      } else {
4748
171
        SLit = cast<StringLiteral>(E);
4749
171
      }
4750
173
      SmallString<256> Buf;
4751
173
      llvm::raw_svector_ostream OS(Buf);
4752
173
      SLit->outputString(OS);
4753
173
      return cxstring::createDup(OS.str());
4754
173
    }
4755
4756
17.2k
    const Decl *D = getDeclFromExpr(getCursorExpr(C));
4757
17.2k
    if (D)
4758
14.6k
      return getDeclSpelling(D);
4759
2.64k
    return cxstring::createEmpty();
4760
17.2k
  }
4761
4762
69.5k
  if (clang_isStatement(C.kind)) {
4763
851
    const Stmt *S = getCursorStmt(C);
4764
851
    if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
4765
1
      return cxstring::createRef(Label->getName());
4766
4767
850
    return cxstring::createEmpty();
4768
851
  }
4769
4770
68.7k
  if (C.kind == CXCursor_MacroExpansion)
4771
237
    return cxstring::createRef(
4772
237
        getCursorMacroExpansion(C).getName()->getNameStart());
4773
4774
68.4k
  if (C.kind == CXCursor_MacroDefinition)
4775
59.9k
    return cxstring::createRef(
4776
59.9k
        getCursorMacroDefinition(C)->getName()->getNameStart());
4777
4778
8.51k
  if (C.kind == CXCursor_InclusionDirective)
4779
333
    return cxstring::createDup(getCursorInclusionDirective(C)->getFileName());
4780
4781
8.17k
  if (clang_isDeclaration(C.kind))
4782
7.81k
    return getDeclSpelling(getCursorDecl(C));
4783
4784
363
  if (C.kind == CXCursor_AnnotateAttr) {
4785
15
    const AnnotateAttr *AA = cast<AnnotateAttr>(cxcursor::getCursorAttr(C));
4786
15
    return cxstring::createDup(AA->getAnnotation());
4787
15
  }
4788
4789
348
  if (C.kind == CXCursor_AsmLabelAttr) {
4790
1
    const AsmLabelAttr *AA = cast<AsmLabelAttr>(cxcursor::getCursorAttr(C));
4791
1
    return cxstring::createDup(AA->getLabel());
4792
1
  }
4793
4794
347
  if (C.kind == CXCursor_PackedAttr) {
4795
13
    return cxstring::createRef("packed");
4796
13
  }
4797
4798
334
  if (C.kind == CXCursor_VisibilityAttr) {
4799
12
    const VisibilityAttr *AA = cast<VisibilityAttr>(cxcursor::getCursorAttr(C));
4800
12
    switch (AA->getVisibility()) {
4801
6
    case VisibilityAttr::VisibilityType::Default:
4802
6
      return cxstring::createRef("default");
4803
4
    case VisibilityAttr::VisibilityType::Hidden:
4804
4
      return cxstring::createRef("hidden");
4805
2
    case VisibilityAttr::VisibilityType::Protected:
4806
2
      return cxstring::createRef("protected");
4807
12
    }
4808
0
    llvm_unreachable("unknown visibility type");
4809
0
  }
4810
4811
322
  return cxstring::createEmpty();
4812
334
}
4813
4814
CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C, unsigned pieceIndex,
4815
490
                                                unsigned options) {
4816
490
  if (clang_Cursor_isNull(C))
4817
0
    return clang_getNullRange();
4818
4819
490
  ASTContext &Ctx = getCursorContext(C);
4820
4821
490
  if (clang_isStatement(C.kind)) {
4822
0
    const Stmt *S = getCursorStmt(C);
4823
0
    if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) {
4824
0
      if (pieceIndex > 0)
4825
0
        return clang_getNullRange();
4826
0
      return cxloc::translateSourceRange(Ctx, Label->getIdentLoc());
4827
0
    }
4828
4829
0
    return clang_getNullRange();
4830
0
  }
4831
4832
490
  if (C.kind == CXCursor_ObjCMessageExpr) {
4833
41
    if (const ObjCMessageExpr *ME =
4834
41
            dyn_cast_or_null<ObjCMessageExpr>(getCursorExpr(C))) {
4835
41
      if (pieceIndex >= ME->getNumSelectorLocs())
4836
20
        return clang_getNullRange();
4837
21
      return cxloc::translateSourceRange(Ctx, ME->getSelectorLoc(pieceIndex));
4838
41
    }
4839
41
  }
4840
4841
449
  if (C.kind == CXCursor_ObjCInstanceMethodDecl ||
4842
449
      
C.kind == CXCursor_ObjCClassMethodDecl428
) {
4843
21
    if (const ObjCMethodDecl *MD =
4844
21
            dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(C))) {
4845
21
      if (pieceIndex >= MD->getNumSelectorLocs())
4846
10
        return clang_getNullRange();
4847
11
      return cxloc::translateSourceRange(Ctx, MD->getSelectorLoc(pieceIndex));
4848
21
    }
4849
21
  }
4850
4851
428
  if (C.kind == CXCursor_ObjCCategoryDecl ||
4852
428
      
C.kind == CXCursor_ObjCCategoryImplDecl426
) {
4853
4
    if (pieceIndex > 0)
4854
2
      return clang_getNullRange();
4855
2
    if (const ObjCCategoryDecl *CD =
4856
2
            dyn_cast_or_null<ObjCCategoryDecl>(getCursorDecl(C)))
4857
1
      return cxloc::translateSourceRange(Ctx, CD->getCategoryNameLoc());
4858
1
    if (const ObjCCategoryImplDecl *CID =
4859
1
            dyn_cast_or_null<ObjCCategoryImplDecl>(getCursorDecl(C)))
4860
1
      return cxloc::translateSourceRange(Ctx, CID->getCategoryNameLoc());
4861
1
  }
4862
4863
424
  if (C.kind == CXCursor_ModuleImportDecl) {
4864
2
    if (pieceIndex > 0)
4865
1
      return clang_getNullRange();
4866
1
    if (const ImportDecl *ImportD =
4867
1
            dyn_cast_or_null<ImportDecl>(getCursorDecl(C))) {
4868
1
      ArrayRef<SourceLocation> Locs = ImportD->getIdentifierLocs();
4869
1
      if (!Locs.empty())
4870
1
        return cxloc::translateSourceRange(
4871
1
            Ctx, SourceRange(Locs.front(), Locs.back()));
4872
1
    }
4873
0
    return clang_getNullRange();
4874
1
  }
4875
4876
422
  if (C.kind == CXCursor_CXXMethod || 
C.kind == CXCursor_Destructor330
||
4877
422
      
C.kind == CXCursor_ConversionFunction328
||
4878
422
      
C.kind == CXCursor_FunctionDecl326
) {
4879
110
    if (pieceIndex > 0)
4880
55
      return clang_getNullRange();
4881
55
    if (const FunctionDecl *FD =
4882
55
            dyn_cast_or_null<FunctionDecl>(getCursorDecl(C))) {
4883
55
      DeclarationNameInfo FunctionName = FD->getNameInfo();
4884
55
      return cxloc::translateSourceRange(Ctx, FunctionName.getSourceRange());
4885
55
    }
4886
0
    return clang_getNullRange();
4887
55
  }
4888
4889
  // FIXME: A CXCursor_InclusionDirective should give the location of the
4890
  // filename, but we don't keep track of this.
4891
4892
  // FIXME: A CXCursor_AnnotateAttr should give the location of the annotation
4893
  // but we don't keep track of this.
4894
4895
  // FIXME: A CXCursor_AsmLabelAttr should give the location of the label
4896
  // but we don't keep track of this.
4897
4898
  // Default handling, give the location of the cursor.
4899
4900
312
  if (pieceIndex > 0)
4901
156
    return clang_getNullRange();
4902
4903
156
  CXSourceLocation CXLoc = clang_getCursorLocation(C);
4904
156
  SourceLocation Loc = cxloc::translateSourceLocation(CXLoc);
4905
156
  return cxloc::translateSourceRange(Ctx, Loc);
4906
312
}
4907
4908
1.20k
CXString clang_Cursor_getMangling(CXCursor C) {
4909
1.20k
  if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
4910
1.18k
    return cxstring::createEmpty();
4911
4912
  // Mangling only works for functions and variables.
4913
15
  const Decl *D = getCursorDecl(C);
4914
15
  if (!D || !(isa<FunctionDecl>(D) || 
isa<VarDecl>(D)3
))
4915
3
    return cxstring::createEmpty();
4916
4917
12
  ASTContext &Ctx = D->getASTContext();
4918
12
  ASTNameGenerator ASTNameGen(Ctx);
4919
12
  return cxstring::createDup(ASTNameGen.getName(D));
4920
15
}
4921
4922
64
CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) {
4923
64
  if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
4924
0
    return nullptr;
4925
4926
64
  const Decl *D = getCursorDecl(C);
4927
64
  if (!(isa<CXXRecordDecl>(D) || 
isa<CXXMethodDecl>(D)43
))
4928
4
    return nullptr;
4929
4930
60
  ASTContext &Ctx = D->getASTContext();
4931
60
  ASTNameGenerator ASTNameGen(Ctx);
4932
60
  std::vector<std::string> Manglings = ASTNameGen.getAllManglings(D);
4933
60
  return cxstring::createSet(Manglings);
4934
64
}
4935
4936
64
CXStringSet *clang_Cursor_getObjCManglings(CXCursor C) {
4937
64
  if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
4938
0
    return nullptr;
4939
4940
64
  const Decl *D = getCursorDecl(C);
4941
64
  if (!(isa<ObjCInterfaceDecl>(D) || 
isa<ObjCImplementationDecl>(D)62
))
4942
60
    return nullptr;
4943
4944
4
  ASTContext &Ctx = D->getASTContext();
4945
4
  ASTNameGenerator ASTNameGen(Ctx);
4946
4
  std::vector<std::string> Manglings = ASTNameGen.getAllManglings(D);
4947
4
  return cxstring::createSet(Manglings);
4948
64
}
4949
4950
431
CXPrintingPolicy clang_getCursorPrintingPolicy(CXCursor C) {
4951
431
  if (clang_Cursor_isNull(C))
4952
0
    return nullptr;
4953
431
  return new PrintingPolicy(getCursorContext(C).getPrintingPolicy());
4954
431
}
4955
4956
431
void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy) {
4957
431
  if (Policy)
4958
431
    delete static_cast<PrintingPolicy *>(Policy);
4959
431
}
4960
4961
unsigned
4962
clang_PrintingPolicy_getProperty(CXPrintingPolicy Policy,
4963
50
                                 enum CXPrintingPolicyProperty Property) {
4964
50
  if (!Policy)
4965
0
    return 0;