Bug Summary

File:tools/clang/tools/libclang/CIndex.cpp
Warning:line 1410, column 7
Null pointer passed as an argument to a 'nonnull' parameter

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name CIndex.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D CLANG_TOOL_EXTRA_BUILD -D _CINDEX_LIB_ -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/tools/libclang -I /build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang -I /build/llvm-toolchain-snapshot-7~svn326246/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn326246/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn326246/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/tools/libclang -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-02-28-041547-14988-1 -x c++ /build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp

/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp

1//===- CIndex.cpp - Clang-C Source Indexing Library -----------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the main API hooks in the Clang-C Source Indexing
11// library.
12//
13//===----------------------------------------------------------------------===//
14
15#include "CIndexDiagnostic.h"
16#include "CIndexer.h"
17#include "CLog.h"
18#include "CXCursor.h"
19#include "CXSourceLocation.h"
20#include "CXString.h"
21#include "CXTranslationUnit.h"
22#include "CXType.h"
23#include "CursorVisitor.h"
24#include "clang/AST/Attr.h"
25#include "clang/AST/StmtVisitor.h"
26#include "clang/Basic/Diagnostic.h"
27#include "clang/Basic/DiagnosticCategories.h"
28#include "clang/Basic/DiagnosticIDs.h"
29#include "clang/Basic/TargetInfo.h"
30#include "clang/Basic/Version.h"
31#include "clang/Frontend/ASTUnit.h"
32#include "clang/Frontend/CompilerInstance.h"
33#include "clang/Frontend/FrontendDiagnostic.h"
34#include "clang/Index/CodegenNameGenerator.h"
35#include "clang/Index/CommentToXML.h"
36#include "clang/Lex/HeaderSearch.h"
37#include "clang/Lex/Lexer.h"
38#include "clang/Lex/PreprocessingRecord.h"
39#include "clang/Lex/Preprocessor.h"
40#include "clang/Serialization/SerializationDiagnostic.h"
41#include "llvm/ADT/Optional.h"
42#include "llvm/ADT/STLExtras.h"
43#include "llvm/ADT/StringSwitch.h"
44#include "llvm/Config/llvm-config.h"
45#include "llvm/Support/Compiler.h"
46#include "llvm/Support/CrashRecoveryContext.h"
47#include "llvm/Support/Format.h"
48#include "llvm/Support/ManagedStatic.h"
49#include "llvm/Support/MemoryBuffer.h"
50#include "llvm/Support/Mutex.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
59#if LLVM_ENABLE_THREADS1 != 0 && defined(__APPLE__)
60#define USE_DARWIN_THREADS
61#endif
62
63#ifdef USE_DARWIN_THREADS
64#include <pthread.h>
65#endif
66
67using namespace clang;
68using namespace clang::cxcursor;
69using namespace clang::cxtu;
70using namespace clang::cxindex;
71
72CXTranslationUnit cxtu::MakeCXTranslationUnit(CIndexer *CIdx,
73 std::unique_ptr<ASTUnit> AU) {
74 if (!AU)
75 return nullptr;
76 assert(CIdx)(static_cast <bool> (CIdx) ? void (0) : __assert_fail (
"CIdx", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 76, __extension__ __PRETTY_FUNCTION__))
;
77 CXTranslationUnit D = new CXTranslationUnitImpl();
78 D->CIdx = CIdx;
79 D->TheASTUnit = AU.release();
80 D->StringPool = new cxstring::CXStringPool();
81 D->Diagnostics = nullptr;
82 D->OverridenCursorsPool = createOverridenCXCursorsPool();
83 D->CommentToXML = nullptr;
84 D->ParsingOptions = 0;
85 D->Arguments = {};
86 return D;
87}
88
89bool cxtu::isASTReadError(ASTUnit *AU) {
90 for (ASTUnit::stored_diag_iterator D = AU->stored_diag_begin(),
91 DEnd = AU->stored_diag_end();
92 D != DEnd; ++D) {
93 if (D->getLevel() >= DiagnosticsEngine::Error &&
94 DiagnosticIDs::getCategoryNumberForDiag(D->getID()) ==
95 diag::DiagCat_AST_Deserialization_Issue)
96 return true;
97 }
98 return false;
99}
100
101cxtu::CXTUOwner::~CXTUOwner() {
102 if (TU)
103 clang_disposeTranslationUnit(TU);
104}
105
106/// \brief Compare two source ranges to determine their relative position in
107/// the translation unit.
108static RangeComparisonResult RangeCompare(SourceManager &SM,
109 SourceRange R1,
110 SourceRange R2) {
111 assert(R1.isValid() && "First range is invalid?")(static_cast <bool> (R1.isValid() && "First range is invalid?"
) ? void (0) : __assert_fail ("R1.isValid() && \"First range is invalid?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 111, __extension__ __PRETTY_FUNCTION__))
;
112 assert(R2.isValid() && "Second range is invalid?")(static_cast <bool> (R2.isValid() && "Second range is invalid?"
) ? void (0) : __assert_fail ("R2.isValid() && \"Second range is invalid?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 112, __extension__ __PRETTY_FUNCTION__))
;
113 if (R1.getEnd() != R2.getBegin() &&
114 SM.isBeforeInTranslationUnit(R1.getEnd(), R2.getBegin()))
115 return RangeBefore;
116 if (R2.getEnd() != R1.getBegin() &&
117 SM.isBeforeInTranslationUnit(R2.getEnd(), R1.getBegin()))
118 return RangeAfter;
119 return RangeOverlap;
120}
121
122/// \brief Determine if a source location falls within, before, or after a
123/// a given source range.
124static RangeComparisonResult LocationCompare(SourceManager &SM,
125 SourceLocation L, SourceRange R) {
126 assert(R.isValid() && "First range is invalid?")(static_cast <bool> (R.isValid() && "First range is invalid?"
) ? void (0) : __assert_fail ("R.isValid() && \"First range is invalid?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 126, __extension__ __PRETTY_FUNCTION__))
;
127 assert(L.isValid() && "Second range is invalid?")(static_cast <bool> (L.isValid() && "Second range is invalid?"
) ? void (0) : __assert_fail ("L.isValid() && \"Second range is invalid?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 127, __extension__ __PRETTY_FUNCTION__))
;
128 if (L == R.getBegin() || L == R.getEnd())
129 return RangeOverlap;
130 if (SM.isBeforeInTranslationUnit(L, R.getBegin()))
131 return RangeBefore;
132 if (SM.isBeforeInTranslationUnit(R.getEnd(), L))
133 return RangeAfter;
134 return RangeOverlap;
135}
136
137/// \brief Translate a Clang source range into a CIndex source range.
138///
139/// Clang internally represents ranges where the end location points to the
140/// start of the token at the end. However, for external clients it is more
141/// useful to have a CXSourceRange be a proper half-open interval. This routine
142/// does the appropriate translation.
143CXSourceRange cxloc::translateSourceRange(const SourceManager &SM,
144 const LangOptions &LangOpts,
145 const CharSourceRange &R) {
146 // We want the last character in this location, so we will adjust the
147 // location accordingly.
148 SourceLocation EndLoc = R.getEnd();
149 if (EndLoc.isValid() && EndLoc.isMacroID() && !SM.isMacroArgExpansion(EndLoc))
150 EndLoc = SM.getExpansionRange(EndLoc).second;
151 if (R.isTokenRange() && EndLoc.isValid()) {
152 unsigned Length = Lexer::MeasureTokenLength(SM.getSpellingLoc(EndLoc),
153 SM, LangOpts);
154 EndLoc = EndLoc.getLocWithOffset(Length);
155 }
156
157 CXSourceRange Result = {
158 { &SM, &LangOpts },
159 R.getBegin().getRawEncoding(),
160 EndLoc.getRawEncoding()
161 };
162 return Result;
163}
164
165//===----------------------------------------------------------------------===//
166// Cursor visitor.
167//===----------------------------------------------------------------------===//
168
169static SourceRange getRawCursorExtent(CXCursor C);
170static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr);
171
172
173RangeComparisonResult CursorVisitor::CompareRegionOfInterest(SourceRange R) {
174 return RangeCompare(AU->getSourceManager(), R, RegionOfInterest);
175}
176
177/// \brief Visit the given cursor and, if requested by the visitor,
178/// its children.
179///
180/// \param Cursor the cursor to visit.
181///
182/// \param CheckedRegionOfInterest if true, then the caller already checked
183/// that this cursor is within the region of interest.
184///
185/// \returns true if the visitation should be aborted, false if it
186/// should continue.
187bool CursorVisitor::Visit(CXCursor Cursor, bool CheckedRegionOfInterest) {
188 if (clang_isInvalid(Cursor.kind))
189 return false;
190
191 if (clang_isDeclaration(Cursor.kind)) {
192 const Decl *D = getCursorDecl(Cursor);
193 if (!D) {
194 assert(0 && "Invalid declaration cursor")(static_cast <bool> (0 && "Invalid declaration cursor"
) ? void (0) : __assert_fail ("0 && \"Invalid declaration cursor\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 194, __extension__ __PRETTY_FUNCTION__))
;
195 return true; // abort.
196 }
197
198 // Ignore implicit declarations, unless it's an objc method because
199 // currently we should report implicit methods for properties when indexing.
200 if (D->isImplicit() && !isa<ObjCMethodDecl>(D))
201 return false;
202 }
203
204 // If we have a range of interest, and this cursor doesn't intersect with it,
205 // we're done.
206 if (RegionOfInterest.isValid() && !CheckedRegionOfInterest) {
207 SourceRange Range = getRawCursorExtent(Cursor);
208 if (Range.isInvalid() || CompareRegionOfInterest(Range))
209 return false;
210 }
211
212 switch (Visitor(Cursor, Parent, ClientData)) {
213 case CXChildVisit_Break:
214 return true;
215
216 case CXChildVisit_Continue:
217 return false;
218
219 case CXChildVisit_Recurse: {
220 bool ret = VisitChildren(Cursor);
221 if (PostChildrenVisitor)
222 if (PostChildrenVisitor(Cursor, ClientData))
223 return true;
224 return ret;
225 }
226 }
227
228 llvm_unreachable("Invalid CXChildVisitResult!")::llvm::llvm_unreachable_internal("Invalid CXChildVisitResult!"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 228)
;
229}
230
231static bool visitPreprocessedEntitiesInRange(SourceRange R,
232 PreprocessingRecord &PPRec,
233 CursorVisitor &Visitor) {
234 SourceManager &SM = Visitor.getASTUnit()->getSourceManager();
235 FileID FID;
236
237 if (!Visitor.shouldVisitIncludedEntities()) {
238 // If the begin/end of the range lie in the same FileID, do the optimization
239 // where we skip preprocessed entities that do not come from the same FileID.
240 FID = SM.getFileID(SM.getFileLoc(R.getBegin()));
241 if (FID != SM.getFileID(SM.getFileLoc(R.getEnd())))
242 FID = FileID();
243 }
244
245 const auto &Entities = PPRec.getPreprocessedEntitiesInRange(R);
246 return Visitor.visitPreprocessedEntities(Entities.begin(), Entities.end(),
247 PPRec, FID);
248}
249
250bool CursorVisitor::visitFileRegion() {
251 if (RegionOfInterest.isInvalid())
252 return false;
253
254 ASTUnit *Unit = cxtu::getASTUnit(TU);
255 SourceManager &SM = Unit->getSourceManager();
256
257 std::pair<FileID, unsigned>
258 Begin = SM.getDecomposedLoc(SM.getFileLoc(RegionOfInterest.getBegin())),
259 End = SM.getDecomposedLoc(SM.getFileLoc(RegionOfInterest.getEnd()));
260
261 if (End.first != Begin.first) {
262 // If the end does not reside in the same file, try to recover by
263 // picking the end of the file of begin location.
264 End.first = Begin.first;
265 End.second = SM.getFileIDSize(Begin.first);
266 }
267
268 assert(Begin.first == End.first)(static_cast <bool> (Begin.first == End.first) ? void (
0) : __assert_fail ("Begin.first == End.first", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 268, __extension__ __PRETTY_FUNCTION__))
;
269 if (Begin.second > End.second)
270 return false;
271
272 FileID File = Begin.first;
273 unsigned Offset = Begin.second;
274 unsigned Length = End.second - Begin.second;
275
276 if (!VisitDeclsOnly && !VisitPreprocessorLast)
277 if (visitPreprocessedEntitiesInRegion())
278 return true; // visitation break.
279
280 if (visitDeclsFromFileRegion(File, Offset, Length))
281 return true; // visitation break.
282
283 if (!VisitDeclsOnly && VisitPreprocessorLast)
284 return visitPreprocessedEntitiesInRegion();
285
286 return false;
287}
288
289static bool isInLexicalContext(Decl *D, DeclContext *DC) {
290 if (!DC)
291 return false;
292
293 for (DeclContext *DeclDC = D->getLexicalDeclContext();
294 DeclDC; DeclDC = DeclDC->getLexicalParent()) {
295 if (DeclDC == DC)
296 return true;
297 }
298 return false;
299}
300
301bool CursorVisitor::visitDeclsFromFileRegion(FileID File,
302 unsigned Offset, unsigned Length) {
303 ASTUnit *Unit = cxtu::getASTUnit(TU);
304 SourceManager &SM = Unit->getSourceManager();
305 SourceRange Range = RegionOfInterest;
306
307 SmallVector<Decl *, 16> Decls;
308 Unit->findFileRegionDecls(File, Offset, Length, Decls);
309
310 // If we didn't find any file level decls for the file, try looking at the
311 // file that it was included from.
312 while (Decls.empty() || Decls.front()->isTopLevelDeclInObjCContainer()) {
313 bool Invalid = false;
314 const SrcMgr::SLocEntry &SLEntry = SM.getSLocEntry(File, &Invalid);
315 if (Invalid)
316 return false;
317
318 SourceLocation Outer;
319 if (SLEntry.isFile())
320 Outer = SLEntry.getFile().getIncludeLoc();
321 else
322 Outer = SLEntry.getExpansion().getExpansionLocStart();
323 if (Outer.isInvalid())
324 return false;
325
326 std::tie(File, Offset) = SM.getDecomposedExpansionLoc(Outer);
327 Length = 0;
328 Unit->findFileRegionDecls(File, Offset, Length, Decls);
329 }
330
331 assert(!Decls.empty())(static_cast <bool> (!Decls.empty()) ? void (0) : __assert_fail
("!Decls.empty()", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 331, __extension__ __PRETTY_FUNCTION__))
;
332
333 bool VisitedAtLeastOnce = false;
334 DeclContext *CurDC = nullptr;
335 SmallVectorImpl<Decl *>::iterator DIt = Decls.begin();
336 for (SmallVectorImpl<Decl *>::iterator DE = Decls.end(); DIt != DE; ++DIt) {
337 Decl *D = *DIt;
338 if (D->getSourceRange().isInvalid())
339 continue;
340
341 if (isInLexicalContext(D, CurDC))
342 continue;
343
344 CurDC = dyn_cast<DeclContext>(D);
345
346 if (TagDecl *TD = dyn_cast<TagDecl>(D))
347 if (!TD->isFreeStanding())
348 continue;
349
350 RangeComparisonResult CompRes = RangeCompare(SM, D->getSourceRange(),Range);
351 if (CompRes == RangeBefore)
352 continue;
353 if (CompRes == RangeAfter)
354 break;
355
356 assert(CompRes == RangeOverlap)(static_cast <bool> (CompRes == RangeOverlap) ? void (0
) : __assert_fail ("CompRes == RangeOverlap", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 356, __extension__ __PRETTY_FUNCTION__))
;
357 VisitedAtLeastOnce = true;
358
359 if (isa<ObjCContainerDecl>(D)) {
360 FileDI_current = &DIt;
361 FileDE_current = DE;
362 } else {
363 FileDI_current = nullptr;
364 }
365
366 if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true))
367 return true; // visitation break.
368 }
369
370 if (VisitedAtLeastOnce)
371 return false;
372
373 // No Decls overlapped with the range. Move up the lexical context until there
374 // is a context that contains the range or we reach the translation unit
375 // level.
376 DeclContext *DC = DIt == Decls.begin() ? (*DIt)->getLexicalDeclContext()
377 : (*(DIt-1))->getLexicalDeclContext();
378
379 while (DC && !DC->isTranslationUnit()) {
380 Decl *D = cast<Decl>(DC);
381 SourceRange CurDeclRange = D->getSourceRange();
382 if (CurDeclRange.isInvalid())
383 break;
384
385 if (RangeCompare(SM, CurDeclRange, Range) == RangeOverlap) {
386 if (Visit(MakeCXCursor(D, TU, Range), /*CheckedRegionOfInterest=*/true))
387 return true; // visitation break.
388 }
389
390 DC = D->getLexicalDeclContext();
391 }
392
393 return false;
394}
395
396bool CursorVisitor::visitPreprocessedEntitiesInRegion() {
397 if (!AU->getPreprocessor().getPreprocessingRecord())
398 return false;
399
400 PreprocessingRecord &PPRec
401 = *AU->getPreprocessor().getPreprocessingRecord();
402 SourceManager &SM = AU->getSourceManager();
403
404 if (RegionOfInterest.isValid()) {
405 SourceRange MappedRange = AU->mapRangeToPreamble(RegionOfInterest);
406 SourceLocation B = MappedRange.getBegin();
407 SourceLocation E = MappedRange.getEnd();
408
409 if (AU->isInPreambleFileID(B)) {
410 if (SM.isLoadedSourceLocation(E))
411 return visitPreprocessedEntitiesInRange(SourceRange(B, E),
412 PPRec, *this);
413
414 // Beginning of range lies in the preamble but it also extends beyond
415 // it into the main file. Split the range into 2 parts, one covering
416 // the preamble and another covering the main file. This allows subsequent
417 // calls to visitPreprocessedEntitiesInRange to accept a source range that
418 // lies in the same FileID, allowing it to skip preprocessed entities that
419 // do not come from the same FileID.
420 bool breaked =
421 visitPreprocessedEntitiesInRange(
422 SourceRange(B, AU->getEndOfPreambleFileID()),
423 PPRec, *this);
424 if (breaked) return true;
425 return visitPreprocessedEntitiesInRange(
426 SourceRange(AU->getStartOfMainFileID(), E),
427 PPRec, *this);
428 }
429
430 return visitPreprocessedEntitiesInRange(SourceRange(B, E), PPRec, *this);
431 }
432
433 bool OnlyLocalDecls
434 = !AU->isMainFileAST() && AU->getOnlyLocalDecls();
435
436 if (OnlyLocalDecls)
437 return visitPreprocessedEntities(PPRec.local_begin(), PPRec.local_end(),
438 PPRec);
439
440 return visitPreprocessedEntities(PPRec.begin(), PPRec.end(), PPRec);
441}
442
443template<typename InputIterator>
444bool CursorVisitor::visitPreprocessedEntities(InputIterator First,
445 InputIterator Last,
446 PreprocessingRecord &PPRec,
447 FileID FID) {
448 for (; First != Last; ++First) {
449 if (!FID.isInvalid() && !PPRec.isEntityInFileID(First, FID))
450 continue;
451
452 PreprocessedEntity *PPE = *First;
453 if (!PPE)
454 continue;
455
456 if (MacroExpansion *ME = dyn_cast<MacroExpansion>(PPE)) {
457 if (Visit(MakeMacroExpansionCursor(ME, TU)))
458 return true;
459
460 continue;
461 }
462
463 if (MacroDefinitionRecord *MD = dyn_cast<MacroDefinitionRecord>(PPE)) {
464 if (Visit(MakeMacroDefinitionCursor(MD, TU)))
465 return true;
466
467 continue;
468 }
469
470 if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
471 if (Visit(MakeInclusionDirectiveCursor(ID, TU)))
472 return true;
473
474 continue;
475 }
476 }
477
478 return false;
479}
480
481/// \brief Visit the children of the given cursor.
482///
483/// \returns true if the visitation should be aborted, false if it
484/// should continue.
485bool CursorVisitor::VisitChildren(CXCursor Cursor) {
486 if (clang_isReference(Cursor.kind) &&
487 Cursor.kind != CXCursor_CXXBaseSpecifier) {
488 // By definition, references have no children.
489 return false;
490 }
491
492 // Set the Parent field to Cursor, then back to its old value once we're
493 // done.
494 SetParentRAII SetParent(Parent, StmtParent, Cursor);
495
496 if (clang_isDeclaration(Cursor.kind)) {
497 Decl *D = const_cast<Decl *>(getCursorDecl(Cursor));
498 if (!D)
499 return false;
500
501 return VisitAttributes(D) || Visit(D);
502 }
503
504 if (clang_isStatement(Cursor.kind)) {
505 if (const Stmt *S = getCursorStmt(Cursor))
506 return Visit(S);
507
508 return false;
509 }
510
511 if (clang_isExpression(Cursor.kind)) {
512 if (const Expr *E = getCursorExpr(Cursor))
513 return Visit(E);
514
515 return false;
516 }
517
518 if (clang_isTranslationUnit(Cursor.kind)) {
519 CXTranslationUnit TU = getCursorTU(Cursor);
520 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
521
522 int VisitOrder[2] = { VisitPreprocessorLast, !VisitPreprocessorLast };
523 for (unsigned I = 0; I != 2; ++I) {
524 if (VisitOrder[I]) {
525 if (!CXXUnit->isMainFileAST() && CXXUnit->getOnlyLocalDecls() &&
526 RegionOfInterest.isInvalid()) {
527 for (ASTUnit::top_level_iterator TL = CXXUnit->top_level_begin(),
528 TLEnd = CXXUnit->top_level_end();
529 TL != TLEnd; ++TL) {
530 const Optional<bool> V = handleDeclForVisitation(*TL);
531 if (!V.hasValue())
532 continue;
533 return V.getValue();
534 }
535 } else if (VisitDeclContext(
536 CXXUnit->getASTContext().getTranslationUnitDecl()))
537 return true;
538 continue;
539 }
540
541 // Walk the preprocessing record.
542 if (CXXUnit->getPreprocessor().getPreprocessingRecord())
543 visitPreprocessedEntitiesInRegion();
544 }
545
546 return false;
547 }
548
549 if (Cursor.kind == CXCursor_CXXBaseSpecifier) {
550 if (const CXXBaseSpecifier *Base = getCursorCXXBaseSpecifier(Cursor)) {
551 if (TypeSourceInfo *BaseTSInfo = Base->getTypeSourceInfo()) {
552 return Visit(BaseTSInfo->getTypeLoc());
553 }
554 }
555 }
556
557 if (Cursor.kind == CXCursor_IBOutletCollectionAttr) {
558 const IBOutletCollectionAttr *A =
559 cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(Cursor));
560 if (const ObjCObjectType *ObjT = A->getInterface()->getAs<ObjCObjectType>())
561 return Visit(cxcursor::MakeCursorObjCClassRef(
562 ObjT->getInterface(),
563 A->getInterfaceLoc()->getTypeLoc().getLocStart(), TU));
564 }
565
566 // If pointing inside a macro definition, check if the token is an identifier
567 // that was ever defined as a macro. In such a case, create a "pseudo" macro
568 // expansion cursor for that token.
569 SourceLocation BeginLoc = RegionOfInterest.getBegin();
570 if (Cursor.kind == CXCursor_MacroDefinition &&
571 BeginLoc == RegionOfInterest.getEnd()) {
572 SourceLocation Loc = AU->mapLocationToPreamble(BeginLoc);
573 const MacroInfo *MI =
574 getMacroInfo(cxcursor::getCursorMacroDefinition(Cursor), TU);
575 if (MacroDefinitionRecord *MacroDef =
576 checkForMacroInMacroDefinition(MI, Loc, TU))
577 return Visit(cxcursor::MakeMacroExpansionCursor(MacroDef, BeginLoc, TU));
578 }
579
580 // Nothing to visit at the moment.
581 return false;
582}
583
584bool CursorVisitor::VisitBlockDecl(BlockDecl *B) {
585 if (TypeSourceInfo *TSInfo = B->getSignatureAsWritten())
586 if (Visit(TSInfo->getTypeLoc()))
587 return true;
588
589 if (Stmt *Body = B->getBody())
590 return Visit(MakeCXCursor(Body, StmtParent, TU, RegionOfInterest));
591
592 return false;
593}
594
595Optional<bool> CursorVisitor::shouldVisitCursor(CXCursor Cursor) {
596 if (RegionOfInterest.isValid()) {
597 SourceRange Range = getFullCursorExtent(Cursor, AU->getSourceManager());
598 if (Range.isInvalid())
599 return None;
600
601 switch (CompareRegionOfInterest(Range)) {
602 case RangeBefore:
603 // This declaration comes before the region of interest; skip it.
604 return None;
605
606 case RangeAfter:
607 // This declaration comes after the region of interest; we're done.
608 return false;
609
610 case RangeOverlap:
611 // This declaration overlaps the region of interest; visit it.
612 break;
613 }
614 }
615 return true;
616}
617
618bool CursorVisitor::VisitDeclContext(DeclContext *DC) {
619 DeclContext::decl_iterator I = DC->decls_begin(), E = DC->decls_end();
620
621 // FIXME: Eventually remove. This part of a hack to support proper
622 // iteration over all Decls contained lexically within an ObjC container.
623 SaveAndRestore<DeclContext::decl_iterator*> DI_saved(DI_current, &I);
624 SaveAndRestore<DeclContext::decl_iterator> DE_saved(DE_current, E);
625
626 for ( ; I != E; ++I) {
627 Decl *D = *I;
628 if (D->getLexicalDeclContext() != DC)
629 continue;
630 const Optional<bool> V = handleDeclForVisitation(D);
631 if (!V.hasValue())
632 continue;
633 return V.getValue();
634 }
635 return false;
636}
637
638Optional<bool> CursorVisitor::handleDeclForVisitation(const Decl *D) {
639 CXCursor Cursor = MakeCXCursor(D, TU, RegionOfInterest);
640
641 // Ignore synthesized ivars here, otherwise if we have something like:
642 // @synthesize prop = _prop;
643 // and '_prop' is not declared, we will encounter a '_prop' ivar before
644 // encountering the 'prop' synthesize declaration and we will think that
645 // we passed the region-of-interest.
646 if (auto *ivarD = dyn_cast<ObjCIvarDecl>(D)) {
647 if (ivarD->getSynthesize())
648 return None;
649 }
650
651 // FIXME: ObjCClassRef/ObjCProtocolRef for forward class/protocol
652 // declarations is a mismatch with the compiler semantics.
653 if (Cursor.kind == CXCursor_ObjCInterfaceDecl) {
654 auto *ID = cast<ObjCInterfaceDecl>(D);
655 if (!ID->isThisDeclarationADefinition())
656 Cursor = MakeCursorObjCClassRef(ID, ID->getLocation(), TU);
657
658 } else if (Cursor.kind == CXCursor_ObjCProtocolDecl) {
659 auto *PD = cast<ObjCProtocolDecl>(D);
660 if (!PD->isThisDeclarationADefinition())
661 Cursor = MakeCursorObjCProtocolRef(PD, PD->getLocation(), TU);
662 }
663
664 const Optional<bool> V = shouldVisitCursor(Cursor);
665 if (!V.hasValue())
666 return None;
667 if (!V.getValue())
668 return false;
669 if (Visit(Cursor, true))
670 return true;
671 return None;
672}
673
674bool CursorVisitor::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
675 llvm_unreachable("Translation units are visited directly by Visit()")::llvm::llvm_unreachable_internal("Translation units are visited directly by Visit()"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 675)
;
676}
677
678bool CursorVisitor::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
679 if (VisitTemplateParameters(D->getTemplateParameters()))
680 return true;
681
682 return Visit(MakeCXCursor(D->getTemplatedDecl(), TU, RegionOfInterest));
683}
684
685bool CursorVisitor::VisitTypeAliasDecl(TypeAliasDecl *D) {
686 if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo())
687 return Visit(TSInfo->getTypeLoc());
688
689 return false;
690}
691
692bool CursorVisitor::VisitTypedefDecl(TypedefDecl *D) {
693 if (TypeSourceInfo *TSInfo = D->getTypeSourceInfo())
694 return Visit(TSInfo->getTypeLoc());
695
696 return false;
697}
698
699bool CursorVisitor::VisitTagDecl(TagDecl *D) {
700 return VisitDeclContext(D);
701}
702
703bool CursorVisitor::VisitClassTemplateSpecializationDecl(
704 ClassTemplateSpecializationDecl *D) {
705 bool ShouldVisitBody = false;
706 switch (D->getSpecializationKind()) {
707 case TSK_Undeclared:
708 case TSK_ImplicitInstantiation:
709 // Nothing to visit
710 return false;
711
712 case TSK_ExplicitInstantiationDeclaration:
713 case TSK_ExplicitInstantiationDefinition:
714 break;
715
716 case TSK_ExplicitSpecialization:
717 ShouldVisitBody = true;
718 break;
719 }
720
721 // Visit the template arguments used in the specialization.
722 if (TypeSourceInfo *SpecType = D->getTypeAsWritten()) {
723 TypeLoc TL = SpecType->getTypeLoc();
724 if (TemplateSpecializationTypeLoc TSTLoc =
725 TL.getAs<TemplateSpecializationTypeLoc>()) {
726 for (unsigned I = 0, N = TSTLoc.getNumArgs(); I != N; ++I)
727 if (VisitTemplateArgumentLoc(TSTLoc.getArgLoc(I)))
728 return true;
729 }
730 }
731
732 return ShouldVisitBody && VisitCXXRecordDecl(D);
733}
734
735bool CursorVisitor::VisitClassTemplatePartialSpecializationDecl(
736 ClassTemplatePartialSpecializationDecl *D) {
737 // FIXME: Visit the "outer" template parameter lists on the TagDecl
738 // before visiting these template parameters.
739 if (VisitTemplateParameters(D->getTemplateParameters()))
740 return true;
741
742 // Visit the partial specialization arguments.
743 const ASTTemplateArgumentListInfo *Info = D->getTemplateArgsAsWritten();
744 const TemplateArgumentLoc *TemplateArgs = Info->getTemplateArgs();
745 for (unsigned I = 0, N = Info->NumTemplateArgs; I != N; ++I)
746 if (VisitTemplateArgumentLoc(TemplateArgs[I]))
747 return true;
748
749 return VisitCXXRecordDecl(D);
750}
751
752bool CursorVisitor::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
753 // Visit the default argument.
754 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
755 if (TypeSourceInfo *DefArg = D->getDefaultArgumentInfo())
756 if (Visit(DefArg->getTypeLoc()))
757 return true;
758
759 return false;
760}
761
762bool CursorVisitor::VisitEnumConstantDecl(EnumConstantDecl *D) {
763 if (Expr *Init = D->getInitExpr())
764 return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
765 return false;
766}
767
768bool CursorVisitor::VisitDeclaratorDecl(DeclaratorDecl *DD) {
769 unsigned NumParamList = DD->getNumTemplateParameterLists();
770 for (unsigned i = 0; i < NumParamList; i++) {
771 TemplateParameterList* Params = DD->getTemplateParameterList(i);
772 if (VisitTemplateParameters(Params))
773 return true;
774 }
775
776 if (TypeSourceInfo *TSInfo = DD->getTypeSourceInfo())
777 if (Visit(TSInfo->getTypeLoc()))
778 return true;
779
780 // Visit the nested-name-specifier, if present.
781 if (NestedNameSpecifierLoc QualifierLoc = DD->getQualifierLoc())
782 if (VisitNestedNameSpecifierLoc(QualifierLoc))
783 return true;
784
785 return false;
786}
787
788static bool HasTrailingReturnType(FunctionDecl *ND) {
789 const QualType Ty = ND->getType();
790 if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
791 if (const FunctionProtoType *FT = dyn_cast<FunctionProtoType>(AFT))
792 return FT->hasTrailingReturn();
793 }
794
795 return false;
796}
797
798/// \brief Compare two base or member initializers based on their source order.
799static int CompareCXXCtorInitializers(CXXCtorInitializer *const *X,
800 CXXCtorInitializer *const *Y) {
801 return (*X)->getSourceOrder() - (*Y)->getSourceOrder();
802}
803
804bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
805 unsigned NumParamList = ND->getNumTemplateParameterLists();
806 for (unsigned i = 0; i < NumParamList; i++) {
807 TemplateParameterList* Params = ND->getTemplateParameterList(i);
808 if (VisitTemplateParameters(Params))
809 return true;
810 }
811
812 if (TypeSourceInfo *TSInfo = ND->getTypeSourceInfo()) {
813 // Visit the function declaration's syntactic components in the order
814 // written. This requires a bit of work.
815 TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
816 FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>();
817 const bool HasTrailingRT = HasTrailingReturnType(ND);
818
819 // If we have a function declared directly (without the use of a typedef),
820 // visit just the return type. Otherwise, just visit the function's type
821 // now.
822 if ((FTL && !isa<CXXConversionDecl>(ND) && !HasTrailingRT &&
823 Visit(FTL.getReturnLoc())) ||
824 (!FTL && Visit(TL)))
825 return true;
826
827 // Visit the nested-name-specifier, if present.
828 if (NestedNameSpecifierLoc QualifierLoc = ND->getQualifierLoc())
829 if (VisitNestedNameSpecifierLoc(QualifierLoc))
830 return true;
831
832 // Visit the declaration name.
833 if (!isa<CXXDestructorDecl>(ND))
834 if (VisitDeclarationNameInfo(ND->getNameInfo()))
835 return true;
836
837 // FIXME: Visit explicitly-specified template arguments!
838
839 // Visit the function parameters, if we have a function type.
840 if (FTL && VisitFunctionTypeLoc(FTL, true))
841 return true;
842
843 // Visit the function's trailing return type.
844 if (FTL && HasTrailingRT && Visit(FTL.getReturnLoc()))
845 return true;
846
847 // FIXME: Attributes?
848 }
849
850 if (ND->doesThisDeclarationHaveABody() && !ND->isLateTemplateParsed()) {
851 if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(ND)) {
852 // Find the initializers that were written in the source.
853 SmallVector<CXXCtorInitializer *, 4> WrittenInits;
854 for (auto *I : Constructor->inits()) {
855 if (!I->isWritten())
856 continue;
857
858 WrittenInits.push_back(I);
859 }
860
861 // Sort the initializers in source order
862 llvm::array_pod_sort(WrittenInits.begin(), WrittenInits.end(),
863 &CompareCXXCtorInitializers);
864
865 // Visit the initializers in source order
866 for (unsigned I = 0, N = WrittenInits.size(); I != N; ++I) {
867 CXXCtorInitializer *Init = WrittenInits[I];
868 if (Init->isAnyMemberInitializer()) {
869 if (Visit(MakeCursorMemberRef(Init->getAnyMember(),
870 Init->getMemberLocation(), TU)))
871 return true;
872 } else if (TypeSourceInfo *TInfo = Init->getTypeSourceInfo()) {
873 if (Visit(TInfo->getTypeLoc()))
874 return true;
875 }
876
877 // Visit the initializer value.
878 if (Expr *Initializer = Init->getInit())
879 if (Visit(MakeCXCursor(Initializer, ND, TU, RegionOfInterest)))
880 return true;
881 }
882 }
883
884 if (Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest)))
885 return true;
886 }
887
888 return false;
889}
890
891bool CursorVisitor::VisitFieldDecl(FieldDecl *D) {
892 if (VisitDeclaratorDecl(D))
893 return true;
894
895 if (Expr *BitWidth = D->getBitWidth())
896 return Visit(MakeCXCursor(BitWidth, StmtParent, TU, RegionOfInterest));
897
898 if (Expr *Init = D->getInClassInitializer())
899 return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
900
901 return false;
902}
903
904bool CursorVisitor::VisitVarDecl(VarDecl *D) {
905 if (VisitDeclaratorDecl(D))
906 return true;
907
908 if (Expr *Init = D->getInit())
909 return Visit(MakeCXCursor(Init, StmtParent, TU, RegionOfInterest));
910
911 return false;
912}
913
914bool CursorVisitor::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
915 if (VisitDeclaratorDecl(D))
916 return true;
917
918 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
919 if (Expr *DefArg = D->getDefaultArgument())
920 return Visit(MakeCXCursor(DefArg, StmtParent, TU, RegionOfInterest));
921
922 return false;
923}
924
925bool CursorVisitor::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
926 // FIXME: Visit the "outer" template parameter lists on the FunctionDecl
927 // before visiting these template parameters.
928 if (VisitTemplateParameters(D->getTemplateParameters()))
929 return true;
930
931 auto* FD = D->getTemplatedDecl();
932 return VisitAttributes(FD) || VisitFunctionDecl(FD);
933}
934
935bool CursorVisitor::VisitClassTemplateDecl(ClassTemplateDecl *D) {
936 // FIXME: Visit the "outer" template parameter lists on the TagDecl
937 // before visiting these template parameters.
938 if (VisitTemplateParameters(D->getTemplateParameters()))
939 return true;
940
941 auto* CD = D->getTemplatedDecl();
942 return VisitAttributes(CD) || VisitCXXRecordDecl(CD);
943}
944
945bool CursorVisitor::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
946 if (VisitTemplateParameters(D->getTemplateParameters()))
947 return true;
948
949 if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited() &&
950 VisitTemplateArgumentLoc(D->getDefaultArgument()))
951 return true;
952
953 return false;
954}
955
956bool CursorVisitor::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
957 // Visit the bound, if it's explicit.
958 if (D->hasExplicitBound()) {
959 if (auto TInfo = D->getTypeSourceInfo()) {
960 if (Visit(TInfo->getTypeLoc()))
961 return true;
962 }
963 }
964
965 return false;
966}
967
968bool CursorVisitor::VisitObjCMethodDecl(ObjCMethodDecl *ND) {
969 if (TypeSourceInfo *TSInfo = ND->getReturnTypeSourceInfo())
970 if (Visit(TSInfo->getTypeLoc()))
971 return true;
972
973 for (const auto *P : ND->parameters()) {
974 if (Visit(MakeCXCursor(P, TU, RegionOfInterest)))
975 return true;
976 }
977
978 return ND->isThisDeclarationADefinition() &&
979 Visit(MakeCXCursor(ND->getBody(), StmtParent, TU, RegionOfInterest));
980}
981
982template <typename DeclIt>
983static void addRangedDeclsInContainer(DeclIt *DI_current, DeclIt DE_current,
984 SourceManager &SM, SourceLocation EndLoc,
985 SmallVectorImpl<Decl *> &Decls) {
986 DeclIt next = *DI_current;
987 while (++next != DE_current) {
988 Decl *D_next = *next;
989 if (!D_next)
990 break;
991 SourceLocation L = D_next->getLocStart();
992 if (!L.isValid())
993 break;
994 if (SM.isBeforeInTranslationUnit(L, EndLoc)) {
995 *DI_current = next;
996 Decls.push_back(D_next);
997 continue;
998 }
999 break;
1000 }
1001}
1002
1003bool CursorVisitor::VisitObjCContainerDecl(ObjCContainerDecl *D) {
1004 // FIXME: Eventually convert back to just 'VisitDeclContext()'. Essentially
1005 // an @implementation can lexically contain Decls that are not properly
1006 // nested in the AST. When we identify such cases, we need to retrofit
1007 // this nesting here.
1008 if (!DI_current && !FileDI_current)
1009 return VisitDeclContext(D);
1010
1011 // Scan the Decls that immediately come after the container
1012 // in the current DeclContext. If any fall within the
1013 // container's lexical region, stash them into a vector
1014 // for later processing.
1015 SmallVector<Decl *, 24> DeclsInContainer;
1016 SourceLocation EndLoc = D->getSourceRange().getEnd();
1017 SourceManager &SM = AU->getSourceManager();
1018 if (EndLoc.isValid()) {
1019 if (DI_current) {
1020 addRangedDeclsInContainer(DI_current, DE_current, SM, EndLoc,
1021 DeclsInContainer);
1022 } else {
1023 addRangedDeclsInContainer(FileDI_current, FileDE_current, SM, EndLoc,
1024 DeclsInContainer);
1025 }
1026 }
1027
1028 // The common case.
1029 if (DeclsInContainer.empty())
1030 return VisitDeclContext(D);
1031
1032 // Get all the Decls in the DeclContext, and sort them with the
1033 // additional ones we've collected. Then visit them.
1034 for (auto *SubDecl : D->decls()) {
1035 if (!SubDecl || SubDecl->getLexicalDeclContext() != D ||
1036 SubDecl->getLocStart().isInvalid())
1037 continue;
1038 DeclsInContainer.push_back(SubDecl);
1039 }
1040
1041 // Now sort the Decls so that they appear in lexical order.
1042 std::sort(DeclsInContainer.begin(), DeclsInContainer.end(),
1043 [&SM](Decl *A, Decl *B) {
1044 SourceLocation L_A = A->getLocStart();
1045 SourceLocation L_B = B->getLocStart();
1046 return L_A != L_B ?
1047 SM.isBeforeInTranslationUnit(L_A, L_B) :
1048 SM.isBeforeInTranslationUnit(A->getLocEnd(), B->getLocEnd());
1049 });
1050
1051 // Now visit the decls.
1052 for (SmallVectorImpl<Decl*>::iterator I = DeclsInContainer.begin(),
1053 E = DeclsInContainer.end(); I != E; ++I) {
1054 CXCursor Cursor = MakeCXCursor(*I, TU, RegionOfInterest);
1055 const Optional<bool> &V = shouldVisitCursor(Cursor);
1056 if (!V.hasValue())
1057 continue;
1058 if (!V.getValue())
1059 return false;
1060 if (Visit(Cursor, true))
1061 return true;
1062 }
1063 return false;
1064}
1065
1066bool CursorVisitor::VisitObjCCategoryDecl(ObjCCategoryDecl *ND) {
1067 if (Visit(MakeCursorObjCClassRef(ND->getClassInterface(), ND->getLocation(),
1068 TU)))
1069 return true;
1070
1071 if (VisitObjCTypeParamList(ND->getTypeParamList()))
1072 return true;
1073
1074 ObjCCategoryDecl::protocol_loc_iterator PL = ND->protocol_loc_begin();
1075 for (ObjCCategoryDecl::protocol_iterator I = ND->protocol_begin(),
1076 E = ND->protocol_end(); I != E; ++I, ++PL)
1077 if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
1078 return true;
1079
1080 return VisitObjCContainerDecl(ND);
1081}
1082
1083bool CursorVisitor::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
1084 if (!PID->isThisDeclarationADefinition())
1085 return Visit(MakeCursorObjCProtocolRef(PID, PID->getLocation(), TU));
1086
1087 ObjCProtocolDecl::protocol_loc_iterator PL = PID->protocol_loc_begin();
1088 for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
1089 E = PID->protocol_end(); I != E; ++I, ++PL)
1090 if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
1091 return true;
1092
1093 return VisitObjCContainerDecl(PID);
1094}
1095
1096bool CursorVisitor::VisitObjCPropertyDecl(ObjCPropertyDecl *PD) {
1097 if (PD->getTypeSourceInfo() && Visit(PD->getTypeSourceInfo()->getTypeLoc()))
1098 return true;
1099
1100 // FIXME: This implements a workaround with @property declarations also being
1101 // installed in the DeclContext for the @interface. Eventually this code
1102 // should be removed.
1103 ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(PD->getDeclContext());
1104 if (!CDecl || !CDecl->IsClassExtension())
1105 return false;
1106
1107 ObjCInterfaceDecl *ID = CDecl->getClassInterface();
1108 if (!ID)
1109 return false;
1110
1111 IdentifierInfo *PropertyId = PD->getIdentifier();
1112 ObjCPropertyDecl *prevDecl =
1113 ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(ID), PropertyId,
1114 PD->getQueryKind());
1115
1116 if (!prevDecl)
1117 return false;
1118
1119 // Visit synthesized methods since they will be skipped when visiting
1120 // the @interface.
1121 if (ObjCMethodDecl *MD = prevDecl->getGetterMethodDecl())
1122 if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl)
1123 if (Visit(MakeCXCursor(MD, TU, RegionOfInterest)))
1124 return true;
1125
1126 if (ObjCMethodDecl *MD = prevDecl->getSetterMethodDecl())
1127 if (MD->isPropertyAccessor() && MD->getLexicalDeclContext() == CDecl)
1128 if (Visit(MakeCXCursor(MD, TU, RegionOfInterest)))
1129 return true;
1130
1131 return false;
1132}
1133
1134bool CursorVisitor::VisitObjCTypeParamList(ObjCTypeParamList *typeParamList) {
1135 if (!typeParamList)
1136 return false;
1137
1138 for (auto *typeParam : *typeParamList) {
1139 // Visit the type parameter.
1140 if (Visit(MakeCXCursor(typeParam, TU, RegionOfInterest)))
1141 return true;
1142 }
1143
1144 return false;
1145}
1146
1147bool CursorVisitor::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
1148 if (!D->isThisDeclarationADefinition()) {
1149 // Forward declaration is treated like a reference.
1150 return Visit(MakeCursorObjCClassRef(D, D->getLocation(), TU));
1151 }
1152
1153 // Objective-C type parameters.
1154 if (VisitObjCTypeParamList(D->getTypeParamListAsWritten()))
1155 return true;
1156
1157 // Issue callbacks for super class.
1158 if (D->getSuperClass() &&
1159 Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(),
1160 D->getSuperClassLoc(),
1161 TU)))
1162 return true;
1163
1164 if (TypeSourceInfo *SuperClassTInfo = D->getSuperClassTInfo())
1165 if (Visit(SuperClassTInfo->getTypeLoc()))
1166 return true;
1167
1168 ObjCInterfaceDecl::protocol_loc_iterator PL = D->protocol_loc_begin();
1169 for (ObjCInterfaceDecl::protocol_iterator I = D->protocol_begin(),
1170 E = D->protocol_end(); I != E; ++I, ++PL)
1171 if (Visit(MakeCursorObjCProtocolRef(*I, *PL, TU)))
1172 return true;
1173
1174 return VisitObjCContainerDecl(D);
1175}
1176
1177bool CursorVisitor::VisitObjCImplDecl(ObjCImplDecl *D) {
1178 return VisitObjCContainerDecl(D);
1179}
1180
1181bool CursorVisitor::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
1182 // 'ID' could be null when dealing with invalid code.
1183 if (ObjCInterfaceDecl *ID = D->getClassInterface())
1184 if (Visit(MakeCursorObjCClassRef(ID, D->getLocation(), TU)))
1185 return true;
1186
1187 return VisitObjCImplDecl(D);
1188}
1189
1190bool CursorVisitor::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
1191#if 0
1192 // Issue callbacks for super class.
1193 // FIXME: No source location information!
1194 if (D->getSuperClass() &&
1195 Visit(MakeCursorObjCSuperClassRef(D->getSuperClass(),
1196 D->getSuperClassLoc(),
1197 TU)))
1198 return true;
1199#endif
1200
1201 return VisitObjCImplDecl(D);
1202}
1203
1204bool CursorVisitor::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PD) {
1205 if (ObjCIvarDecl *Ivar = PD->getPropertyIvarDecl())
1206 if (PD->isIvarNameSpecified())
1207 return Visit(MakeCursorMemberRef(Ivar, PD->getPropertyIvarDeclLoc(), TU));
1208
1209 return false;
1210}
1211
1212bool CursorVisitor::VisitNamespaceDecl(NamespaceDecl *D) {
1213 return VisitDeclContext(D);
1214}
1215
1216bool CursorVisitor::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
1217 // Visit nested-name-specifier.
1218 if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
1219 if (VisitNestedNameSpecifierLoc(QualifierLoc))
1220 return true;
1221
1222 return Visit(MakeCursorNamespaceRef(D->getAliasedNamespace(),
1223 D->getTargetNameLoc(), TU));
1224}
1225
1226bool CursorVisitor::VisitUsingDecl(UsingDecl *D) {
1227 // Visit nested-name-specifier.
1228 if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) {
1229 if (VisitNestedNameSpecifierLoc(QualifierLoc))
1230 return true;
1231 }
1232
1233 if (Visit(MakeCursorOverloadedDeclRef(D, D->getLocation(), TU)))
1234 return true;
1235
1236 return VisitDeclarationNameInfo(D->getNameInfo());
1237}
1238
1239bool CursorVisitor::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
1240 // Visit nested-name-specifier.
1241 if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
1242 if (VisitNestedNameSpecifierLoc(QualifierLoc))
1243 return true;
1244
1245 return Visit(MakeCursorNamespaceRef(D->getNominatedNamespaceAsWritten(),
1246 D->getIdentLocation(), TU));
1247}
1248
1249bool CursorVisitor::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1250 // Visit nested-name-specifier.
1251 if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc()) {
1252 if (VisitNestedNameSpecifierLoc(QualifierLoc))
1253 return true;
1254 }
1255
1256 return VisitDeclarationNameInfo(D->getNameInfo());
1257}
1258
1259bool CursorVisitor::VisitUnresolvedUsingTypenameDecl(
1260 UnresolvedUsingTypenameDecl *D) {
1261 // Visit nested-name-specifier.
1262 if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
1263 if (VisitNestedNameSpecifierLoc(QualifierLoc))
1264 return true;
1265
1266 return false;
1267}
1268
1269bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
1270 if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
1271 return true;
1272 if (StringLiteral *Message = D->getMessage())
1273 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
1274 return true;
1275 return false;
1276}
1277
1278bool CursorVisitor::VisitFriendDecl(FriendDecl *D) {
1279 if (NamedDecl *FriendD = D->getFriendDecl()) {
1280 if (Visit(MakeCXCursor(FriendD, TU, RegionOfInterest)))
1281 return true;
1282 } else if (TypeSourceInfo *TI = D->getFriendType()) {
1283 if (Visit(TI->getTypeLoc()))
1284 return true;
1285 }
1286 return false;
1287}
1288
1289bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) {
1290 switch (Name.getName().getNameKind()) {
1291 case clang::DeclarationName::Identifier:
1292 case clang::DeclarationName::CXXLiteralOperatorName:
1293 case clang::DeclarationName::CXXDeductionGuideName:
1294 case clang::DeclarationName::CXXOperatorName:
1295 case clang::DeclarationName::CXXUsingDirective:
1296 return false;
1297
1298 case clang::DeclarationName::CXXConstructorName:
1299 case clang::DeclarationName::CXXDestructorName:
1300 case clang::DeclarationName::CXXConversionFunctionName:
1301 if (TypeSourceInfo *TSInfo = Name.getNamedTypeInfo())
1302 return Visit(TSInfo->getTypeLoc());
1303 return false;
1304
1305 case clang::DeclarationName::ObjCZeroArgSelector:
1306 case clang::DeclarationName::ObjCOneArgSelector:
1307 case clang::DeclarationName::ObjCMultiArgSelector:
1308 // FIXME: Per-identifier location info?
1309 return false;
1310 }
1311
1312 llvm_unreachable("Invalid DeclarationName::Kind!")::llvm::llvm_unreachable_internal("Invalid DeclarationName::Kind!"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 1312)
;
1313}
1314
1315bool CursorVisitor::VisitNestedNameSpecifier(NestedNameSpecifier *NNS,
1316 SourceRange Range) {
1317 // FIXME: This whole routine is a hack to work around the lack of proper
1318 // source information in nested-name-specifiers (PR5791). Since we do have
1319 // a beginning source location, we can visit the first component of the
1320 // nested-name-specifier, if it's a single-token component.
1321 if (!NNS)
1322 return false;
1323
1324 // Get the first component in the nested-name-specifier.
1325 while (NestedNameSpecifier *Prefix = NNS->getPrefix())
1326 NNS = Prefix;
1327
1328 switch (NNS->getKind()) {
1329 case NestedNameSpecifier::Namespace:
1330 return Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(), Range.getBegin(),
1331 TU));
1332
1333 case NestedNameSpecifier::NamespaceAlias:
1334 return Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(),
1335 Range.getBegin(), TU));
1336
1337 case NestedNameSpecifier::TypeSpec: {
1338 // If the type has a form where we know that the beginning of the source
1339 // range matches up with a reference cursor. Visit the appropriate reference
1340 // cursor.
1341 const Type *T = NNS->getAsType();
1342 if (const TypedefType *Typedef = dyn_cast<TypedefType>(T))
1343 return Visit(MakeCursorTypeRef(Typedef->getDecl(), Range.getBegin(), TU));
1344 if (const TagType *Tag = dyn_cast<TagType>(T))
1345 return Visit(MakeCursorTypeRef(Tag->getDecl(), Range.getBegin(), TU));
1346 if (const TemplateSpecializationType *TST
1347 = dyn_cast<TemplateSpecializationType>(T))
1348 return VisitTemplateName(TST->getTemplateName(), Range.getBegin());
1349 break;
1350 }
1351
1352 case NestedNameSpecifier::TypeSpecWithTemplate:
1353 case NestedNameSpecifier::Global:
1354 case NestedNameSpecifier::Identifier:
1355 case NestedNameSpecifier::Super:
1356 break;
1357 }
1358
1359 return false;
1360}
1361
1362bool
1363CursorVisitor::VisitNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier) {
1364 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
1365 for (; Qualifier; Qualifier = Qualifier.getPrefix())
1366 Qualifiers.push_back(Qualifier);
1367
1368 while (!Qualifiers.empty()) {
1369 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
1370 NestedNameSpecifier *NNS = Q.getNestedNameSpecifier();
1371 switch (NNS->getKind()) {
1372 case NestedNameSpecifier::Namespace:
1373 if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespace(),
1374 Q.getLocalBeginLoc(),
1375 TU)))
1376 return true;
1377
1378 break;
1379
1380 case NestedNameSpecifier::NamespaceAlias:
1381 if (Visit(MakeCursorNamespaceRef(NNS->getAsNamespaceAlias(),
1382 Q.getLocalBeginLoc(),
1383 TU)))
1384 return true;
1385
1386 break;
1387
1388 case NestedNameSpecifier::TypeSpec:
1389 case NestedNameSpecifier::TypeSpecWithTemplate:
1390 if (Visit(Q.getTypeLoc()))
1391 return true;
1392
1393 break;
1394
1395 case NestedNameSpecifier::Global:
1396 case NestedNameSpecifier::Identifier:
1397 case NestedNameSpecifier::Super:
1398 break;
1399 }
1400 }
1401
1402 return false;
1403}
1404
1405bool CursorVisitor::VisitTemplateParameters(
1406 const TemplateParameterList *Params) {
1407 if (!Params)
1408 return false;
1409
1410 for (TemplateParameterList::const_iterator P = Params->begin(),
1411 PEnd = Params->end();
1412 P != PEnd; ++P) {
1413 if (Visit(MakeCXCursor(*P, TU, RegionOfInterest)))
1414 return true;
1415 }
1416
1417 return false;
1418}
1419
1420bool CursorVisitor::VisitTemplateName(TemplateName Name, SourceLocation Loc) {
1421 switch (Name.getKind()) {
1422 case TemplateName::Template:
1423 return Visit(MakeCursorTemplateRef(Name.getAsTemplateDecl(), Loc, TU));
1424
1425 case TemplateName::OverloadedTemplate:
1426 // Visit the overloaded template set.
1427 if (Visit(MakeCursorOverloadedDeclRef(Name, Loc, TU)))
1428 return true;
1429
1430 return false;
1431
1432 case TemplateName::DependentTemplate:
1433 // FIXME: Visit nested-name-specifier.
1434 return false;
1435
1436 case TemplateName::QualifiedTemplate:
1437 // FIXME: Visit nested-name-specifier.
1438 return Visit(MakeCursorTemplateRef(
1439 Name.getAsQualifiedTemplateName()->getDecl(),
1440 Loc, TU));
1441
1442 case TemplateName::SubstTemplateTemplateParm:
1443 return Visit(MakeCursorTemplateRef(
1444 Name.getAsSubstTemplateTemplateParm()->getParameter(),
1445 Loc, TU));
1446
1447 case TemplateName::SubstTemplateTemplateParmPack:
1448 return Visit(MakeCursorTemplateRef(
1449 Name.getAsSubstTemplateTemplateParmPack()->getParameterPack(),
1450 Loc, TU));
1451 }
1452
1453 llvm_unreachable("Invalid TemplateName::Kind!")::llvm::llvm_unreachable_internal("Invalid TemplateName::Kind!"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 1453)
;
1454}
1455
1456bool CursorVisitor::VisitTemplateArgumentLoc(const TemplateArgumentLoc &TAL) {
1457 switch (TAL.getArgument().getKind()) {
1458 case TemplateArgument::Null:
1459 case TemplateArgument::Integral:
1460 case TemplateArgument::Pack:
1461 return false;
1462
1463 case TemplateArgument::Type:
1464 if (TypeSourceInfo *TSInfo = TAL.getTypeSourceInfo())
1465 return Visit(TSInfo->getTypeLoc());
1466 return false;
1467
1468 case TemplateArgument::Declaration:
1469 if (Expr *E = TAL.getSourceDeclExpression())
1470 return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
1471 return false;
1472
1473 case TemplateArgument::NullPtr:
1474 if (Expr *E = TAL.getSourceNullPtrExpression())
1475 return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
1476 return false;
1477
1478 case TemplateArgument::Expression:
1479 if (Expr *E = TAL.getSourceExpression())
1480 return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
1481 return false;
1482
1483 case TemplateArgument::Template:
1484 case TemplateArgument::TemplateExpansion:
1485 if (VisitNestedNameSpecifierLoc(TAL.getTemplateQualifierLoc()))
1486 return true;
1487
1488 return VisitTemplateName(TAL.getArgument().getAsTemplateOrTemplatePattern(),
1489 TAL.getTemplateNameLoc());
1490 }
1491
1492 llvm_unreachable("Invalid TemplateArgument::Kind!")::llvm::llvm_unreachable_internal("Invalid TemplateArgument::Kind!"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 1492)
;
1493}
1494
1495bool CursorVisitor::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1496 return VisitDeclContext(D);
1497}
1498
1499bool CursorVisitor::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) {
1500 return Visit(TL.getUnqualifiedLoc());
1501}
1502
1503bool CursorVisitor::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
1504 ASTContext &Context = AU->getASTContext();
1505
1506 // Some builtin types (such as Objective-C's "id", "sel", and
1507 // "Class") have associated declarations. Create cursors for those.
1508 QualType VisitType;
1509 switch (TL.getTypePtr()->getKind()) {
1510
1511 case BuiltinType::Void:
1512 case BuiltinType::NullPtr:
1513 case BuiltinType::Dependent:
1514#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1515 case BuiltinType::Id:
1516#include "clang/Basic/OpenCLImageTypes.def"
1517 case BuiltinType::OCLSampler:
1518 case BuiltinType::OCLEvent:
1519 case BuiltinType::OCLClkEvent:
1520 case BuiltinType::OCLQueue:
1521 case BuiltinType::OCLReserveID:
1522#define BUILTIN_TYPE(Id, SingletonId)
1523#define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
1524#define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
1525#define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
1526#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
1527#include "clang/AST/BuiltinTypes.def"
1528 break;
1529
1530 case BuiltinType::ObjCId:
1531 VisitType = Context.getObjCIdType();
1532 break;
1533
1534 case BuiltinType::ObjCClass:
1535 VisitType = Context.getObjCClassType();
1536 break;
1537
1538 case BuiltinType::ObjCSel:
1539 VisitType = Context.getObjCSelType();
1540 break;
1541 }
1542
1543 if (!VisitType.isNull()) {
1544 if (const TypedefType *Typedef = VisitType->getAs<TypedefType>())
1545 return Visit(MakeCursorTypeRef(Typedef->getDecl(), TL.getBuiltinLoc(),
1546 TU));
1547 }
1548
1549 return false;
1550}
1551
1552bool CursorVisitor::VisitTypedefTypeLoc(TypedefTypeLoc TL) {
1553 return Visit(MakeCursorTypeRef(TL.getTypedefNameDecl(), TL.getNameLoc(), TU));
1554}
1555
1556bool CursorVisitor::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
1557 return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
1558}
1559
1560bool CursorVisitor::VisitTagTypeLoc(TagTypeLoc TL) {
1561 if (TL.isDefinition())
1562 return Visit(MakeCXCursor(TL.getDecl(), TU, RegionOfInterest));
1563
1564 return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
1565}
1566
1567bool CursorVisitor::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
1568 return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
1569}
1570
1571bool CursorVisitor::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) {
1572 return Visit(MakeCursorObjCClassRef(TL.getIFaceDecl(), TL.getNameLoc(), TU));
1573}
1574
1575bool CursorVisitor::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) {
1576 if (Visit(MakeCursorTypeRef(TL.getDecl(), TL.getLocStart(), TU)))
1577 return true;
1578 for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
1579 if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I),
1580 TU)))
1581 return true;
1582 }
1583
1584 return false;
1585}
1586
1587bool CursorVisitor::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) {
1588 if (TL.hasBaseTypeAsWritten() && Visit(TL.getBaseLoc()))
1589 return true;
1590
1591 for (unsigned I = 0, N = TL.getNumTypeArgs(); I != N; ++I) {
1592 if (Visit(TL.getTypeArgTInfo(I)->getTypeLoc()))
1593 return true;
1594 }
1595
1596 for (unsigned I = 0, N = TL.getNumProtocols(); I != N; ++I) {
1597 if (Visit(MakeCursorObjCProtocolRef(TL.getProtocol(I), TL.getProtocolLoc(I),
1598 TU)))
1599 return true;
1600 }
1601
1602 return false;
1603}
1604
1605bool CursorVisitor::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) {
1606 return Visit(TL.getPointeeLoc());
1607}
1608
1609bool CursorVisitor::VisitParenTypeLoc(ParenTypeLoc TL) {
1610 return Visit(TL.getInnerLoc());
1611}
1612
1613bool CursorVisitor::VisitPointerTypeLoc(PointerTypeLoc TL) {
1614 return Visit(TL.getPointeeLoc());
1615}
1616
1617bool CursorVisitor::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) {
1618 return Visit(TL.getPointeeLoc());
1619}
1620
1621bool CursorVisitor::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) {
1622 return Visit(TL.getPointeeLoc());
1623}
1624
1625bool CursorVisitor::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
1626 return Visit(TL.getPointeeLoc());
1627}
1628
1629bool CursorVisitor::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) {
1630 return Visit(TL.getPointeeLoc());
1631}
1632
1633bool CursorVisitor::VisitAttributedTypeLoc(AttributedTypeLoc TL) {
1634 return Visit(TL.getModifiedLoc());
1635}
1636
1637bool CursorVisitor::VisitFunctionTypeLoc(FunctionTypeLoc TL,
1638 bool SkipResultType) {
1639 if (!SkipResultType && Visit(TL.getReturnLoc()))
1640 return true;
1641
1642 for (unsigned I = 0, N = TL.getNumParams(); I != N; ++I)
1643 if (Decl *D = TL.getParam(I))
1644 if (Visit(MakeCXCursor(D, TU, RegionOfInterest)))
1645 return true;
1646
1647 return false;
1648}
1649
1650bool CursorVisitor::VisitArrayTypeLoc(ArrayTypeLoc TL) {
1651 if (Visit(TL.getElementLoc()))
1652 return true;
1653
1654 if (Expr *Size = TL.getSizeExpr())
1655 return Visit(MakeCXCursor(Size, StmtParent, TU, RegionOfInterest));
1656
1657 return false;
1658}
1659
1660bool CursorVisitor::VisitDecayedTypeLoc(DecayedTypeLoc TL) {
1661 return Visit(TL.getOriginalLoc());
1662}
1663
1664bool CursorVisitor::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) {
1665 return Visit(TL.getOriginalLoc());
1666}
1667
1668bool CursorVisitor::VisitDeducedTemplateSpecializationTypeLoc(
1669 DeducedTemplateSpecializationTypeLoc TL) {
1670 if (VisitTemplateName(TL.getTypePtr()->getTemplateName(),
1671 TL.getTemplateNameLoc()))
1672 return true;
1673
1674 return false;
1675}
1676
1677bool CursorVisitor::VisitTemplateSpecializationTypeLoc(
1678 TemplateSpecializationTypeLoc TL) {
1679 // Visit the template name.
1680 if (VisitTemplateName(TL.getTypePtr()->getTemplateName(),
1681 TL.getTemplateNameLoc()))
1682 return true;
1683
1684 // Visit the template arguments.
1685 for (unsigned I = 0, N = TL.getNumArgs(); I != N; ++I)
1686 if (VisitTemplateArgumentLoc(TL.getArgLoc(I)))
1687 return true;
1688
1689 return false;
1690}
1691
1692bool CursorVisitor::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) {
1693 return Visit(MakeCXCursor(TL.getUnderlyingExpr(), StmtParent, TU));
1694}
1695
1696bool CursorVisitor::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) {
1697 if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo())
1698 return Visit(TSInfo->getTypeLoc());
1699
1700 return false;
1701}
1702
1703bool CursorVisitor::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) {
1704 if (TypeSourceInfo *TSInfo = TL.getUnderlyingTInfo())
1705 return Visit(TSInfo->getTypeLoc());
1706
1707 return false;
1708}
1709
1710bool CursorVisitor::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
1711 return VisitNestedNameSpecifierLoc(TL.getQualifierLoc());
1712}
1713
1714bool CursorVisitor::VisitDependentTemplateSpecializationTypeLoc(
1715 DependentTemplateSpecializationTypeLoc TL) {
1716 // Visit the nested-name-specifier, if there is one.
1717 if (TL.getQualifierLoc() &&
1718 VisitNestedNameSpecifierLoc(TL.getQualifierLoc()))
1719 return true;
1720
1721 // Visit the template arguments.
1722 for (unsigned I = 0, N = TL.getNumArgs(); I != N; ++I)
1723 if (VisitTemplateArgumentLoc(TL.getArgLoc(I)))
1724 return true;
1725
1726 return false;
1727}
1728
1729bool CursorVisitor::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) {
1730 if (VisitNestedNameSpecifierLoc(TL.getQualifierLoc()))
1731 return true;
1732
1733 return Visit(TL.getNamedTypeLoc());
1734}
1735
1736bool CursorVisitor::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) {
1737 return Visit(TL.getPatternLoc());
1738}
1739
1740bool CursorVisitor::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) {
1741 if (Expr *E = TL.getUnderlyingExpr())
1742 return Visit(MakeCXCursor(E, StmtParent, TU));
1743
1744 return false;
1745}
1746
1747bool CursorVisitor::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
1748 return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
1749}
1750
1751bool CursorVisitor::VisitAtomicTypeLoc(AtomicTypeLoc TL) {
1752 return Visit(TL.getValueLoc());
1753}
1754
1755bool CursorVisitor::VisitPipeTypeLoc(PipeTypeLoc TL) {
1756 return Visit(TL.getValueLoc());
1757}
1758
1759#define DEFAULT_TYPELOC_IMPL(CLASS, PARENT)bool CursorVisitor::VisitCLASSTypeLoc(CLASSTypeLoc TL) { return
VisitPARENTLoc(TL); }
\
1760bool CursorVisitor::Visit##CLASS##TypeLoc(CLASS##TypeLoc TL) { \
1761 return Visit##PARENT##Loc(TL); \
1762}
1763
1764DEFAULT_TYPELOC_IMPL(Complex, Type)bool CursorVisitor::VisitComplexTypeLoc(ComplexTypeLoc TL) { return
VisitTypeLoc(TL); }
1765DEFAULT_TYPELOC_IMPL(ConstantArray, ArrayType)bool CursorVisitor::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc
TL) { return VisitArrayTypeLoc(TL); }
1766DEFAULT_TYPELOC_IMPL(IncompleteArray, ArrayType)bool CursorVisitor::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc
TL) { return VisitArrayTypeLoc(TL); }
1767DEFAULT_TYPELOC_IMPL(VariableArray, ArrayType)bool CursorVisitor::VisitVariableArrayTypeLoc(VariableArrayTypeLoc
TL) { return VisitArrayTypeLoc(TL); }
1768DEFAULT_TYPELOC_IMPL(DependentSizedArray, ArrayType)bool CursorVisitor::VisitDependentSizedArrayTypeLoc(DependentSizedArrayTypeLoc
TL) { return VisitArrayTypeLoc(TL); }
1769DEFAULT_TYPELOC_IMPL(DependentAddressSpace, Type)bool CursorVisitor::VisitDependentAddressSpaceTypeLoc(DependentAddressSpaceTypeLoc
TL) { return VisitTypeLoc(TL); }
1770DEFAULT_TYPELOC_IMPL(DependentSizedExtVector, Type)bool CursorVisitor::VisitDependentSizedExtVectorTypeLoc(DependentSizedExtVectorTypeLoc
TL) { return VisitTypeLoc(TL); }
1771DEFAULT_TYPELOC_IMPL(Vector, Type)bool CursorVisitor::VisitVectorTypeLoc(VectorTypeLoc TL) { return
VisitTypeLoc(TL); }
1772DEFAULT_TYPELOC_IMPL(ExtVector, VectorType)bool CursorVisitor::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL
) { return VisitVectorTypeLoc(TL); }
1773DEFAULT_TYPELOC_IMPL(FunctionProto, FunctionType)bool CursorVisitor::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc
TL) { return VisitFunctionTypeLoc(TL); }
1774DEFAULT_TYPELOC_IMPL(FunctionNoProto, FunctionType)bool CursorVisitor::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc
TL) { return VisitFunctionTypeLoc(TL); }
1775DEFAULT_TYPELOC_IMPL(Record, TagType)bool CursorVisitor::VisitRecordTypeLoc(RecordTypeLoc TL) { return
VisitTagTypeLoc(TL); }
1776DEFAULT_TYPELOC_IMPL(Enum, TagType)bool CursorVisitor::VisitEnumTypeLoc(EnumTypeLoc TL) { return
VisitTagTypeLoc(TL); }
1777DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParm, Type)bool CursorVisitor::VisitSubstTemplateTypeParmTypeLoc(SubstTemplateTypeParmTypeLoc
TL) { return VisitTypeLoc(TL); }
1778DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParmPack, Type)bool CursorVisitor::VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc
TL) { return VisitTypeLoc(TL); }
1779DEFAULT_TYPELOC_IMPL(Auto, Type)bool CursorVisitor::VisitAutoTypeLoc(AutoTypeLoc TL) { return
VisitTypeLoc(TL); }
1780
1781bool CursorVisitor::VisitCXXRecordDecl(CXXRecordDecl *D) {
1782 // Visit the nested-name-specifier, if present.
1783 if (NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc())
1784 if (VisitNestedNameSpecifierLoc(QualifierLoc))
1785 return true;
1786
1787 if (D->isCompleteDefinition()) {
1788 for (const auto &I : D->bases()) {
1789 if (Visit(cxcursor::MakeCursorCXXBaseSpecifier(&I, TU)))
1790 return true;
1791 }
1792 }
1793
1794 return VisitTagDecl(D);
1795}
1796
1797bool CursorVisitor::VisitAttributes(Decl *D) {
1798 for (const auto *I : D->attrs())
1799 if (Visit(MakeCXCursor(I, D, TU)))
1800 return true;
1801
1802 return false;
1803}
1804
1805//===----------------------------------------------------------------------===//
1806// Data-recursive visitor methods.
1807//===----------------------------------------------------------------------===//
1808
1809namespace {
1810#define DEF_JOB(NAME, DATA, KIND)\
1811class NAME : public VisitorJob {\
1812public:\
1813 NAME(const DATA *d, CXCursor parent) : \
1814 VisitorJob(parent, VisitorJob::KIND, d) {} \
1815 static bool classof(const VisitorJob *VJ) { return VJ->getKind() == KIND; }\
1816 const DATA *get() const { return static_cast<const DATA*>(data[0]); }\
1817};
1818
1819DEF_JOB(StmtVisit, Stmt, StmtVisitKind)
1820DEF_JOB(MemberExprParts, MemberExpr, MemberExprPartsKind)
1821DEF_JOB(DeclRefExprParts, DeclRefExpr, DeclRefExprPartsKind)
1822DEF_JOB(OverloadExprParts, OverloadExpr, OverloadExprPartsKind)
1823DEF_JOB(SizeOfPackExprParts, SizeOfPackExpr, SizeOfPackExprPartsKind)
1824DEF_JOB(LambdaExprParts, LambdaExpr, LambdaExprPartsKind)
1825DEF_JOB(PostChildrenVisit, void, PostChildrenVisitKind)
1826#undef DEF_JOB
1827
1828class ExplicitTemplateArgsVisit : public VisitorJob {
1829public:
1830 ExplicitTemplateArgsVisit(const TemplateArgumentLoc *Begin,
1831 const TemplateArgumentLoc *End, CXCursor parent)
1832 : VisitorJob(parent, VisitorJob::ExplicitTemplateArgsVisitKind, Begin,
1833 End) {}
1834 static bool classof(const VisitorJob *VJ) {
1835 return VJ->getKind() == ExplicitTemplateArgsVisitKind;
1836 }
1837 const TemplateArgumentLoc *begin() const {
1838 return static_cast<const TemplateArgumentLoc *>(data[0]);
1839 }
1840 const TemplateArgumentLoc *end() {
1841 return static_cast<const TemplateArgumentLoc *>(data[1]);
1842 }
1843};
1844class DeclVisit : public VisitorJob {
1845public:
1846 DeclVisit(const Decl *D, CXCursor parent, bool isFirst) :
1847 VisitorJob(parent, VisitorJob::DeclVisitKind,
1848 D, isFirst ? (void*) 1 : (void*) nullptr) {}
1849 static bool classof(const VisitorJob *VJ) {
1850 return VJ->getKind() == DeclVisitKind;
1851 }
1852 const Decl *get() const { return static_cast<const Decl *>(data[0]); }
1853 bool isFirst() const { return data[1] != nullptr; }
1854};
1855class TypeLocVisit : public VisitorJob {
1856public:
1857 TypeLocVisit(TypeLoc tl, CXCursor parent) :
1858 VisitorJob(parent, VisitorJob::TypeLocVisitKind,
1859 tl.getType().getAsOpaquePtr(), tl.getOpaqueData()) {}
1860
1861 static bool classof(const VisitorJob *VJ) {
1862 return VJ->getKind() == TypeLocVisitKind;
1863 }
1864
1865 TypeLoc get() const {
1866 QualType T = QualType::getFromOpaquePtr(data[0]);
1867 return TypeLoc(T, const_cast<void *>(data[1]));
1868 }
1869};
1870
1871class LabelRefVisit : public VisitorJob {
1872public:
1873 LabelRefVisit(LabelDecl *LD, SourceLocation labelLoc, CXCursor parent)
1874 : VisitorJob(parent, VisitorJob::LabelRefVisitKind, LD,
1875 labelLoc.getPtrEncoding()) {}
1876
1877 static bool classof(const VisitorJob *VJ) {
1878 return VJ->getKind() == VisitorJob::LabelRefVisitKind;
1879 }
1880 const LabelDecl *get() const {
1881 return static_cast<const LabelDecl *>(data[0]);
1882 }
1883 SourceLocation getLoc() const {
1884 return SourceLocation::getFromPtrEncoding(data[1]); }
1885};
1886
1887class NestedNameSpecifierLocVisit : public VisitorJob {
1888public:
1889 NestedNameSpecifierLocVisit(NestedNameSpecifierLoc Qualifier, CXCursor parent)
1890 : VisitorJob(parent, VisitorJob::NestedNameSpecifierLocVisitKind,
1891 Qualifier.getNestedNameSpecifier(),
1892 Qualifier.getOpaqueData()) { }
1893
1894 static bool classof(const VisitorJob *VJ) {
1895 return VJ->getKind() == VisitorJob::NestedNameSpecifierLocVisitKind;
1896 }
1897
1898 NestedNameSpecifierLoc get() const {
1899 return NestedNameSpecifierLoc(
1900 const_cast<NestedNameSpecifier *>(
1901 static_cast<const NestedNameSpecifier *>(data[0])),
1902 const_cast<void *>(data[1]));
1903 }
1904};
1905
1906class DeclarationNameInfoVisit : public VisitorJob {
1907public:
1908 DeclarationNameInfoVisit(const Stmt *S, CXCursor parent)
1909 : VisitorJob(parent, VisitorJob::DeclarationNameInfoVisitKind, S) {}
1910 static bool classof(const VisitorJob *VJ) {
1911 return VJ->getKind() == VisitorJob::DeclarationNameInfoVisitKind;
1912 }
1913 DeclarationNameInfo get() const {
1914 const Stmt *S = static_cast<const Stmt *>(data[0]);
1915 switch (S->getStmtClass()) {
1916 default:
1917 llvm_unreachable("Unhandled Stmt")::llvm::llvm_unreachable_internal("Unhandled Stmt", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 1917)
;
1918 case clang::Stmt::MSDependentExistsStmtClass:
1919 return cast<MSDependentExistsStmt>(S)->getNameInfo();
1920 case Stmt::CXXDependentScopeMemberExprClass:
1921 return cast<CXXDependentScopeMemberExpr>(S)->getMemberNameInfo();
1922 case Stmt::DependentScopeDeclRefExprClass:
1923 return cast<DependentScopeDeclRefExpr>(S)->getNameInfo();
1924 case Stmt::OMPCriticalDirectiveClass:
1925 return cast<OMPCriticalDirective>(S)->getDirectiveName();
1926 }
1927 }
1928};
1929class MemberRefVisit : public VisitorJob {
1930public:
1931 MemberRefVisit(const FieldDecl *D, SourceLocation L, CXCursor parent)
1932 : VisitorJob(parent, VisitorJob::MemberRefVisitKind, D,
1933 L.getPtrEncoding()) {}
1934 static bool classof(const VisitorJob *VJ) {
1935 return VJ->getKind() == VisitorJob::MemberRefVisitKind;
1936 }
1937 const FieldDecl *get() const {
1938 return static_cast<const FieldDecl *>(data[0]);
1939 }
1940 SourceLocation getLoc() const {
1941 return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t) data[1]);
1942 }
1943};
1944class EnqueueVisitor : public ConstStmtVisitor<EnqueueVisitor, void> {
1945 friend class OMPClauseEnqueue;
1946 VisitorWorkList &WL;
1947 CXCursor Parent;
1948public:
1949 EnqueueVisitor(VisitorWorkList &wl, CXCursor parent)
1950 : WL(wl), Parent(parent) {}
1951
1952 void VisitAddrLabelExpr(const AddrLabelExpr *E);
1953 void VisitBlockExpr(const BlockExpr *B);
1954 void VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
1955 void VisitCompoundStmt(const CompoundStmt *S);
1956 void VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E) { /* Do nothing. */ }
1957 void VisitMSDependentExistsStmt(const MSDependentExistsStmt *S);
1958 void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E);
1959 void VisitCXXNewExpr(const CXXNewExpr *E);
1960 void VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
1961 void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *E);
1962 void VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *E);
1963 void VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
1964 void VisitCXXTypeidExpr(const CXXTypeidExpr *E);
1965 void VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr *E);
1966 void VisitCXXUuidofExpr(const CXXUuidofExpr *E);
1967 void VisitCXXCatchStmt(const CXXCatchStmt *S);
1968 void VisitCXXForRangeStmt(const CXXForRangeStmt *S);
1969 void VisitDeclRefExpr(const DeclRefExpr *D);
1970 void VisitDeclStmt(const DeclStmt *S);
1971 void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E);
1972 void VisitDesignatedInitExpr(const DesignatedInitExpr *E);
1973 void VisitExplicitCastExpr(const ExplicitCastExpr *E);
1974 void VisitForStmt(const ForStmt *FS);
1975 void VisitGotoStmt(const GotoStmt *GS);
1976 void VisitIfStmt(const IfStmt *If);
1977 void VisitInitListExpr(const InitListExpr *IE);
1978 void VisitMemberExpr(const MemberExpr *M);
1979 void VisitOffsetOfExpr(const OffsetOfExpr *E);
1980 void VisitObjCEncodeExpr(const ObjCEncodeExpr *E);
1981 void VisitObjCMessageExpr(const ObjCMessageExpr *M);
1982 void VisitOverloadExpr(const OverloadExpr *E);
1983 void VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
1984 void VisitStmt(const Stmt *S);
1985 void VisitSwitchStmt(const SwitchStmt *S);
1986 void VisitWhileStmt(const WhileStmt *W);
1987 void VisitTypeTraitExpr(const TypeTraitExpr *E);
1988 void VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E);
1989 void VisitExpressionTraitExpr(const ExpressionTraitExpr *E);
1990 void VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U);
1991 void VisitVAArgExpr(const VAArgExpr *E);
1992 void VisitSizeOfPackExpr(const SizeOfPackExpr *E);
1993 void VisitPseudoObjectExpr(const PseudoObjectExpr *E);
1994 void VisitOpaqueValueExpr(const OpaqueValueExpr *E);
1995 void VisitLambdaExpr(const LambdaExpr *E);
1996 void VisitOMPExecutableDirective(const OMPExecutableDirective *D);
1997 void VisitOMPLoopDirective(const OMPLoopDirective *D);
1998 void VisitOMPParallelDirective(const OMPParallelDirective *D);
1999 void VisitOMPSimdDirective(const OMPSimdDirective *D);
2000 void VisitOMPForDirective(const OMPForDirective *D);
2001 void VisitOMPForSimdDirective(const OMPForSimdDirective *D);
2002 void VisitOMPSectionsDirective(const OMPSectionsDirective *D);
2003 void VisitOMPSectionDirective(const OMPSectionDirective *D);
2004 void VisitOMPSingleDirective(const OMPSingleDirective *D);
2005 void VisitOMPMasterDirective(const OMPMasterDirective *D);
2006 void VisitOMPCriticalDirective(const OMPCriticalDirective *D);
2007 void VisitOMPParallelForDirective(const OMPParallelForDirective *D);
2008 void VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective *D);
2009 void VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective *D);
2010 void VisitOMPTaskDirective(const OMPTaskDirective *D);
2011 void VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D);
2012 void VisitOMPBarrierDirective(const OMPBarrierDirective *D);
2013 void VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D);
2014 void VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *D);
2015 void
2016 VisitOMPCancellationPointDirective(const OMPCancellationPointDirective *D);
2017 void VisitOMPCancelDirective(const OMPCancelDirective *D);
2018 void VisitOMPFlushDirective(const OMPFlushDirective *D);
2019 void VisitOMPOrderedDirective(const OMPOrderedDirective *D);
2020 void VisitOMPAtomicDirective(const OMPAtomicDirective *D);
2021 void VisitOMPTargetDirective(const OMPTargetDirective *D);
2022 void VisitOMPTargetDataDirective(const OMPTargetDataDirective *D);
2023 void VisitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective *D);
2024 void VisitOMPTargetExitDataDirective(const OMPTargetExitDataDirective *D);
2025 void VisitOMPTargetParallelDirective(const OMPTargetParallelDirective *D);
2026 void
2027 VisitOMPTargetParallelForDirective(const OMPTargetParallelForDirective *D);
2028 void VisitOMPTeamsDirective(const OMPTeamsDirective *D);
2029 void VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D);
2030 void VisitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective *D);
2031 void VisitOMPDistributeDirective(const OMPDistributeDirective *D);
2032 void VisitOMPDistributeParallelForDirective(
2033 const OMPDistributeParallelForDirective *D);
2034 void VisitOMPDistributeParallelForSimdDirective(
2035 const OMPDistributeParallelForSimdDirective *D);
2036 void VisitOMPDistributeSimdDirective(const OMPDistributeSimdDirective *D);
2037 void VisitOMPTargetParallelForSimdDirective(
2038 const OMPTargetParallelForSimdDirective *D);
2039 void VisitOMPTargetSimdDirective(const OMPTargetSimdDirective *D);
2040 void VisitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective *D);
2041 void VisitOMPTeamsDistributeSimdDirective(
2042 const OMPTeamsDistributeSimdDirective *D);
2043 void VisitOMPTeamsDistributeParallelForSimdDirective(
2044 const OMPTeamsDistributeParallelForSimdDirective *D);
2045 void VisitOMPTeamsDistributeParallelForDirective(
2046 const OMPTeamsDistributeParallelForDirective *D);
2047 void VisitOMPTargetTeamsDirective(const OMPTargetTeamsDirective *D);
2048 void VisitOMPTargetTeamsDistributeDirective(
2049 const OMPTargetTeamsDistributeDirective *D);
2050 void VisitOMPTargetTeamsDistributeParallelForDirective(
2051 const OMPTargetTeamsDistributeParallelForDirective *D);
2052 void VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2053 const OMPTargetTeamsDistributeParallelForSimdDirective *D);
2054 void VisitOMPTargetTeamsDistributeSimdDirective(
2055 const OMPTargetTeamsDistributeSimdDirective *D);
2056
2057private:
2058 void AddDeclarationNameInfo(const Stmt *S);
2059 void AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier);
2060 void AddExplicitTemplateArgs(const TemplateArgumentLoc *A,
2061 unsigned NumTemplateArgs);
2062 void AddMemberRef(const FieldDecl *D, SourceLocation L);
2063 void AddStmt(const Stmt *S);
2064 void AddDecl(const Decl *D, bool isFirst = true);
2065 void AddTypeLoc(TypeSourceInfo *TI);
2066 void EnqueueChildren(const Stmt *S);
2067 void EnqueueChildren(const OMPClause *S);
2068};
2069} // end anonyous namespace
2070
2071void EnqueueVisitor::AddDeclarationNameInfo(const Stmt *S) {
2072 // 'S' should always be non-null, since it comes from the
2073 // statement we are visiting.
2074 WL.push_back(DeclarationNameInfoVisit(S, Parent));
2075}
2076
2077void
2078EnqueueVisitor::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc Qualifier) {
2079 if (Qualifier)
2080 WL.push_back(NestedNameSpecifierLocVisit(Qualifier, Parent));
2081}
2082
2083void EnqueueVisitor::AddStmt(const Stmt *S) {
2084 if (S)
2085 WL.push_back(StmtVisit(S, Parent));
2086}
2087void EnqueueVisitor::AddDecl(const Decl *D, bool isFirst) {
2088 if (D)
2089 WL.push_back(DeclVisit(D, Parent, isFirst));
2090}
2091void EnqueueVisitor::AddExplicitTemplateArgs(const TemplateArgumentLoc *A,
2092 unsigned NumTemplateArgs) {
2093 WL.push_back(ExplicitTemplateArgsVisit(A, A + NumTemplateArgs, Parent));
2094}
2095void EnqueueVisitor::AddMemberRef(const FieldDecl *D, SourceLocation L) {
2096 if (D)
2097 WL.push_back(MemberRefVisit(D, L, Parent));
2098}
2099void EnqueueVisitor::AddTypeLoc(TypeSourceInfo *TI) {
2100 if (TI)
2101 WL.push_back(TypeLocVisit(TI->getTypeLoc(), Parent));
2102 }
2103void EnqueueVisitor::EnqueueChildren(const Stmt *S) {
2104 unsigned size = WL.size();
2105 for (const Stmt *SubStmt : S->children()) {
2106 AddStmt(SubStmt);
2107 }
2108 if (size == WL.size())
2109 return;
2110 // Now reverse the entries we just added. This will match the DFS
2111 // ordering performed by the worklist.
2112 VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
2113 std::reverse(I, E);
2114}
2115namespace {
2116class OMPClauseEnqueue : public ConstOMPClauseVisitor<OMPClauseEnqueue> {
2117 EnqueueVisitor *Visitor;
2118 /// \brief Process clauses with list of variables.
2119 template <typename T>
2120 void VisitOMPClauseList(T *Node);
2121public:
2122 OMPClauseEnqueue(EnqueueVisitor *Visitor) : Visitor(Visitor) { }
2123#define OPENMP_CLAUSE(Name, Class) \
2124 void Visit##Class(const Class *C);
2125#include "clang/Basic/OpenMPKinds.def"
2126 void VisitOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
2127 void VisitOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
2128};
2129
2130void OMPClauseEnqueue::VisitOMPClauseWithPreInit(
2131 const OMPClauseWithPreInit *C) {
2132 Visitor->AddStmt(C->getPreInitStmt());
2133}
2134
2135void OMPClauseEnqueue::VisitOMPClauseWithPostUpdate(
2136 const OMPClauseWithPostUpdate *C) {
2137 VisitOMPClauseWithPreInit(C);
2138 Visitor->AddStmt(C->getPostUpdateExpr());
2139}
2140
2141void OMPClauseEnqueue::VisitOMPIfClause(const OMPIfClause *C) {
2142 VisitOMPClauseWithPreInit(C);
2143 Visitor->AddStmt(C->getCondition());
2144}
2145
2146void OMPClauseEnqueue::VisitOMPFinalClause(const OMPFinalClause *C) {
2147 Visitor->AddStmt(C->getCondition());
2148}
2149
2150void OMPClauseEnqueue::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
2151 VisitOMPClauseWithPreInit(C);
2152 Visitor->AddStmt(C->getNumThreads());
2153}
2154
2155void OMPClauseEnqueue::VisitOMPSafelenClause(const OMPSafelenClause *C) {
2156 Visitor->AddStmt(C->getSafelen());
2157}
2158
2159void OMPClauseEnqueue::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
2160 Visitor->AddStmt(C->getSimdlen());
2161}
2162
2163void OMPClauseEnqueue::VisitOMPCollapseClause(const OMPCollapseClause *C) {
2164 Visitor->AddStmt(C->getNumForLoops());
2165}
2166
2167void OMPClauseEnqueue::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
2168
2169void OMPClauseEnqueue::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
2170
2171void OMPClauseEnqueue::VisitOMPScheduleClause(const OMPScheduleClause *C) {
2172 VisitOMPClauseWithPreInit(C);
2173 Visitor->AddStmt(C->getChunkSize());
2174}
2175
2176void OMPClauseEnqueue::VisitOMPOrderedClause(const OMPOrderedClause *C) {
2177 Visitor->AddStmt(C->getNumForLoops());
2178}
2179
2180void OMPClauseEnqueue::VisitOMPNowaitClause(const OMPNowaitClause *) {}
2181
2182void OMPClauseEnqueue::VisitOMPUntiedClause(const OMPUntiedClause *) {}
2183
2184void OMPClauseEnqueue::VisitOMPMergeableClause(const OMPMergeableClause *) {}
2185
2186void OMPClauseEnqueue::VisitOMPReadClause(const OMPReadClause *) {}
2187
2188void OMPClauseEnqueue::VisitOMPWriteClause(const OMPWriteClause *) {}
2189
2190void OMPClauseEnqueue::VisitOMPUpdateClause(const OMPUpdateClause *) {}
2191
2192void OMPClauseEnqueue::VisitOMPCaptureClause(const OMPCaptureClause *) {}
2193
2194void OMPClauseEnqueue::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
2195
2196void OMPClauseEnqueue::VisitOMPThreadsClause(const OMPThreadsClause *) {}
2197
2198void OMPClauseEnqueue::VisitOMPSIMDClause(const OMPSIMDClause *) {}
2199
2200void OMPClauseEnqueue::VisitOMPNogroupClause(const OMPNogroupClause *) {}
2201
2202void OMPClauseEnqueue::VisitOMPDeviceClause(const OMPDeviceClause *C) {
2203 Visitor->AddStmt(C->getDevice());
2204}
2205
2206void OMPClauseEnqueue::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
2207 VisitOMPClauseWithPreInit(C);
2208 Visitor->AddStmt(C->getNumTeams());
2209}
2210
2211void OMPClauseEnqueue::VisitOMPThreadLimitClause(const OMPThreadLimitClause *C) {
2212 VisitOMPClauseWithPreInit(C);
2213 Visitor->AddStmt(C->getThreadLimit());
2214}
2215
2216void OMPClauseEnqueue::VisitOMPPriorityClause(const OMPPriorityClause *C) {
2217 Visitor->AddStmt(C->getPriority());
2218}
2219
2220void OMPClauseEnqueue::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
2221 Visitor->AddStmt(C->getGrainsize());
2222}
2223
2224void OMPClauseEnqueue::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
2225 Visitor->AddStmt(C->getNumTasks());
2226}
2227
2228void OMPClauseEnqueue::VisitOMPHintClause(const OMPHintClause *C) {
2229 Visitor->AddStmt(C->getHint());
2230}
2231
2232template<typename T>
2233void OMPClauseEnqueue::VisitOMPClauseList(T *Node) {
2234 for (const auto *I : Node->varlists()) {
2235 Visitor->AddStmt(I);
2236 }
2237}
2238
2239void OMPClauseEnqueue::VisitOMPPrivateClause(const OMPPrivateClause *C) {
2240 VisitOMPClauseList(C);
2241 for (const auto *E : C->private_copies()) {
2242 Visitor->AddStmt(E);
2243 }
2244}
2245void OMPClauseEnqueue::VisitOMPFirstprivateClause(
2246 const OMPFirstprivateClause *C) {
2247 VisitOMPClauseList(C);
2248 VisitOMPClauseWithPreInit(C);
2249 for (const auto *E : C->private_copies()) {
2250 Visitor->AddStmt(E);
2251 }
2252 for (const auto *E : C->inits()) {
2253 Visitor->AddStmt(E);
2254 }
2255}
2256void OMPClauseEnqueue::VisitOMPLastprivateClause(
2257 const OMPLastprivateClause *C) {
2258 VisitOMPClauseList(C);
2259 VisitOMPClauseWithPostUpdate(C);
2260 for (auto *E : C->private_copies()) {
2261 Visitor->AddStmt(E);
2262 }
2263 for (auto *E : C->source_exprs()) {
2264 Visitor->AddStmt(E);
2265 }
2266 for (auto *E : C->destination_exprs()) {
2267 Visitor->AddStmt(E);
2268 }
2269 for (auto *E : C->assignment_ops()) {
2270 Visitor->AddStmt(E);
2271 }
2272}
2273void OMPClauseEnqueue::VisitOMPSharedClause(const OMPSharedClause *C) {
2274 VisitOMPClauseList(C);
2275}
2276void OMPClauseEnqueue::VisitOMPReductionClause(const OMPReductionClause *C) {
2277 VisitOMPClauseList(C);
2278 VisitOMPClauseWithPostUpdate(C);
2279 for (auto *E : C->privates()) {
2280 Visitor->AddStmt(E);
2281 }
2282 for (auto *E : C->lhs_exprs()) {
2283 Visitor->AddStmt(E);
2284 }
2285 for (auto *E : C->rhs_exprs()) {
2286 Visitor->AddStmt(E);
2287 }
2288 for (auto *E : C->reduction_ops()) {
2289 Visitor->AddStmt(E);
2290 }
2291}
2292void OMPClauseEnqueue::VisitOMPTaskReductionClause(
2293 const OMPTaskReductionClause *C) {
2294 VisitOMPClauseList(C);
2295 VisitOMPClauseWithPostUpdate(C);
2296 for (auto *E : C->privates()) {
2297 Visitor->AddStmt(E);
2298 }
2299 for (auto *E : C->lhs_exprs()) {
2300 Visitor->AddStmt(E);
2301 }
2302 for (auto *E : C->rhs_exprs()) {
2303 Visitor->AddStmt(E);
2304 }
2305 for (auto *E : C->reduction_ops()) {
2306 Visitor->AddStmt(E);
2307 }
2308}
2309void OMPClauseEnqueue::VisitOMPInReductionClause(
2310 const OMPInReductionClause *C) {
2311 VisitOMPClauseList(C);
2312 VisitOMPClauseWithPostUpdate(C);
2313 for (auto *E : C->privates()) {
2314 Visitor->AddStmt(E);
2315 }
2316 for (auto *E : C->lhs_exprs()) {
2317 Visitor->AddStmt(E);
2318 }
2319 for (auto *E : C->rhs_exprs()) {
2320 Visitor->AddStmt(E);
2321 }
2322 for (auto *E : C->reduction_ops()) {
2323 Visitor->AddStmt(E);
2324 }
2325 for (auto *E : C->taskgroup_descriptors())
2326 Visitor->AddStmt(E);
2327}
2328void OMPClauseEnqueue::VisitOMPLinearClause(const OMPLinearClause *C) {
2329 VisitOMPClauseList(C);
2330 VisitOMPClauseWithPostUpdate(C);
2331 for (const auto *E : C->privates()) {
2332 Visitor->AddStmt(E);
2333 }
2334 for (const auto *E : C->inits()) {
2335 Visitor->AddStmt(E);
2336 }
2337 for (const auto *E : C->updates()) {
2338 Visitor->AddStmt(E);
2339 }
2340 for (const auto *E : C->finals()) {
2341 Visitor->AddStmt(E);
2342 }
2343 Visitor->AddStmt(C->getStep());
2344 Visitor->AddStmt(C->getCalcStep());
2345}
2346void OMPClauseEnqueue::VisitOMPAlignedClause(const OMPAlignedClause *C) {
2347 VisitOMPClauseList(C);
2348 Visitor->AddStmt(C->getAlignment());
2349}
2350void OMPClauseEnqueue::VisitOMPCopyinClause(const OMPCopyinClause *C) {
2351 VisitOMPClauseList(C);
2352 for (auto *E : C->source_exprs()) {
2353 Visitor->AddStmt(E);
2354 }
2355 for (auto *E : C->destination_exprs()) {
2356 Visitor->AddStmt(E);
2357 }
2358 for (auto *E : C->assignment_ops()) {
2359 Visitor->AddStmt(E);
2360 }
2361}
2362void
2363OMPClauseEnqueue::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
2364 VisitOMPClauseList(C);
2365 for (auto *E : C->source_exprs()) {
2366 Visitor->AddStmt(E);
2367 }
2368 for (auto *E : C->destination_exprs()) {
2369 Visitor->AddStmt(E);
2370 }
2371 for (auto *E : C->assignment_ops()) {
2372 Visitor->AddStmt(E);
2373 }
2374}
2375void OMPClauseEnqueue::VisitOMPFlushClause(const OMPFlushClause *C) {
2376 VisitOMPClauseList(C);
2377}
2378void OMPClauseEnqueue::VisitOMPDependClause(const OMPDependClause *C) {
2379 VisitOMPClauseList(C);
2380}
2381void OMPClauseEnqueue::VisitOMPMapClause(const OMPMapClause *C) {
2382 VisitOMPClauseList(C);
2383}
2384void OMPClauseEnqueue::VisitOMPDistScheduleClause(
2385 const OMPDistScheduleClause *C) {
2386 VisitOMPClauseWithPreInit(C);
2387 Visitor->AddStmt(C->getChunkSize());
2388}
2389void OMPClauseEnqueue::VisitOMPDefaultmapClause(
2390 const OMPDefaultmapClause * /*C*/) {}
2391void OMPClauseEnqueue::VisitOMPToClause(const OMPToClause *C) {
2392 VisitOMPClauseList(C);
2393}
2394void OMPClauseEnqueue::VisitOMPFromClause(const OMPFromClause *C) {
2395 VisitOMPClauseList(C);
2396}
2397void OMPClauseEnqueue::VisitOMPUseDevicePtrClause(const OMPUseDevicePtrClause *C) {
2398 VisitOMPClauseList(C);
2399}
2400void OMPClauseEnqueue::VisitOMPIsDevicePtrClause(const OMPIsDevicePtrClause *C) {
2401 VisitOMPClauseList(C);
2402}
2403}
2404
2405void EnqueueVisitor::EnqueueChildren(const OMPClause *S) {
2406 unsigned size = WL.size();
2407 OMPClauseEnqueue Visitor(this);
2408 Visitor.Visit(S);
2409 if (size == WL.size())
2410 return;
2411 // Now reverse the entries we just added. This will match the DFS
2412 // ordering performed by the worklist.
2413 VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
2414 std::reverse(I, E);
2415}
2416void EnqueueVisitor::VisitAddrLabelExpr(const AddrLabelExpr *E) {
2417 WL.push_back(LabelRefVisit(E->getLabel(), E->getLabelLoc(), Parent));
2418}
2419void EnqueueVisitor::VisitBlockExpr(const BlockExpr *B) {
2420 AddDecl(B->getBlockDecl());
2421}
2422void EnqueueVisitor::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
2423 EnqueueChildren(E);
2424 AddTypeLoc(E->getTypeSourceInfo());
2425}
2426void EnqueueVisitor::VisitCompoundStmt(const CompoundStmt *S) {
2427 for (auto &I : llvm::reverse(S->body()))
2428 AddStmt(I);
2429}
2430void EnqueueVisitor::
2431VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
2432 AddStmt(S->getSubStmt());
2433 AddDeclarationNameInfo(S);
2434 if (NestedNameSpecifierLoc QualifierLoc = S->getQualifierLoc())
2435 AddNestedNameSpecifierLoc(QualifierLoc);
2436}
2437
2438void EnqueueVisitor::
2439VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) {
2440 if (E->hasExplicitTemplateArgs())
2441 AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
2442 AddDeclarationNameInfo(E);
2443 if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc())
2444 AddNestedNameSpecifierLoc(QualifierLoc);
2445 if (!E->isImplicitAccess())
2446 AddStmt(E->getBase());
2447}
2448void EnqueueVisitor::VisitCXXNewExpr(const CXXNewExpr *E) {
2449 // Enqueue the initializer , if any.
2450 AddStmt(E->getInitializer());
2451 // Enqueue the array size, if any.
2452 AddStmt(E->getArraySize());
2453 // Enqueue the allocated type.
2454 AddTypeLoc(E->getAllocatedTypeSourceInfo());
2455 // Enqueue the placement arguments.
2456 for (unsigned I = E->getNumPlacementArgs(); I > 0; --I)
2457 AddStmt(E->getPlacementArg(I-1));
2458}
2459void EnqueueVisitor::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *CE) {
2460 for (unsigned I = CE->getNumArgs(); I > 1 /* Yes, this is 1 */; --I)
2461 AddStmt(CE->getArg(I-1));
2462 AddStmt(CE->getCallee());
2463 AddStmt(CE->getArg(0));
2464}
2465void EnqueueVisitor::VisitCXXPseudoDestructorExpr(
2466 const CXXPseudoDestructorExpr *E) {
2467 // Visit the name of the type being destroyed.
2468 AddTypeLoc(E->getDestroyedTypeInfo());
2469 // Visit the scope type that looks disturbingly like the nested-name-specifier
2470 // but isn't.
2471 AddTypeLoc(E->getScopeTypeInfo());
2472 // Visit the nested-name-specifier.
2473 if (NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc())
2474 AddNestedNameSpecifierLoc(QualifierLoc);
2475 // Visit base expression.
2476 AddStmt(E->getBase());
2477}
2478void EnqueueVisitor::VisitCXXScalarValueInitExpr(
2479 const CXXScalarValueInitExpr *E) {
2480 AddTypeLoc(E->getTypeSourceInfo());
2481}
2482void EnqueueVisitor::VisitCXXTemporaryObjectExpr(
2483 const CXXTemporaryObjectExpr *E) {
2484 EnqueueChildren(E);
2485 AddTypeLoc(E->getTypeSourceInfo());
2486}
2487void EnqueueVisitor::VisitCXXTypeidExpr(const CXXTypeidExpr *E) {
2488 EnqueueChildren(E);
2489 if (E->isTypeOperand())
2490 AddTypeLoc(E->getTypeOperandSourceInfo());
2491}
2492
2493void EnqueueVisitor::VisitCXXUnresolvedConstructExpr(
2494 const CXXUnresolvedConstructExpr *E) {
2495 EnqueueChildren(E);
2496 AddTypeLoc(E->getTypeSourceInfo());
2497}
2498void EnqueueVisitor::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
2499 EnqueueChildren(E);
2500 if (E->isTypeOperand())
2501 AddTypeLoc(E->getTypeOperandSourceInfo());
2502}
2503
2504void EnqueueVisitor::VisitCXXCatchStmt(const CXXCatchStmt *S) {
2505 EnqueueChildren(S);
2506 AddDecl(S->getExceptionDecl());
2507}
2508
2509void EnqueueVisitor::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
2510 AddStmt(S->getBody());
2511 AddStmt(S->getRangeInit());
2512 AddDecl(S->getLoopVariable());
2513}
2514
2515void EnqueueVisitor::VisitDeclRefExpr(const DeclRefExpr *DR) {
2516 if (DR->hasExplicitTemplateArgs())
2517 AddExplicitTemplateArgs(DR->getTemplateArgs(), DR->getNumTemplateArgs());
2518 WL.push_back(DeclRefExprParts(DR, Parent));
2519}
2520void EnqueueVisitor::VisitDependentScopeDeclRefExpr(
2521 const DependentScopeDeclRefExpr *E) {
2522 if (E->hasExplicitTemplateArgs())
2523 AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
2524 AddDeclarationNameInfo(E);
2525 AddNestedNameSpecifierLoc(E->getQualifierLoc());
2526}
2527void EnqueueVisitor::VisitDeclStmt(const DeclStmt *S) {
2528 unsigned size = WL.size();
2529 bool isFirst = true;
2530 for (const auto *D : S->decls()) {
2531 AddDecl(D, isFirst);
2532 isFirst = false;
2533 }
2534 if (size == WL.size())
2535 return;
2536 // Now reverse the entries we just added. This will match the DFS
2537 // ordering performed by the worklist.
2538 VisitorWorkList::iterator I = WL.begin() + size, E = WL.end();
2539 std::reverse(I, E);
2540}
2541void EnqueueVisitor::VisitDesignatedInitExpr(const DesignatedInitExpr *E) {
2542 AddStmt(E->getInit());
2543 for (const DesignatedInitExpr::Designator &D :
2544 llvm::reverse(E->designators())) {
2545 if (D.isFieldDesignator()) {
2546 if (FieldDecl *Field = D.getField())
2547 AddMemberRef(Field, D.getFieldLoc());
2548 continue;
2549 }
2550 if (D.isArrayDesignator()) {
2551 AddStmt(E->getArrayIndex(D));
2552 continue;
2553 }
2554 assert(D.isArrayRangeDesignator() && "Unknown designator kind")(static_cast <bool> (D.isArrayRangeDesignator() &&
"Unknown designator kind") ? void (0) : __assert_fail ("D.isArrayRangeDesignator() && \"Unknown designator kind\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 2554, __extension__ __PRETTY_FUNCTION__))
;
2555 AddStmt(E->getArrayRangeEnd(D));
2556 AddStmt(E->getArrayRangeStart(D));
2557 }
2558}
2559void EnqueueVisitor::VisitExplicitCastExpr(const ExplicitCastExpr *E) {
2560 EnqueueChildren(E);
2561 AddTypeLoc(E->getTypeInfoAsWritten());
2562}
2563void EnqueueVisitor::VisitForStmt(const ForStmt *FS) {
2564 AddStmt(FS->getBody());
2565 AddStmt(FS->getInc());
2566 AddStmt(FS->getCond());
2567 AddDecl(FS->getConditionVariable());
2568 AddStmt(FS->getInit());
2569}
2570void EnqueueVisitor::VisitGotoStmt(const GotoStmt *GS) {
2571 WL.push_back(LabelRefVisit(GS->getLabel(), GS->getLabelLoc(), Parent));
2572}
2573void EnqueueVisitor::VisitIfStmt(const IfStmt *If) {
2574 AddStmt(If->getElse());
2575 AddStmt(If->getThen());
2576 AddStmt(If->getCond());
2577 AddDecl(If->getConditionVariable());
2578}
2579void EnqueueVisitor::VisitInitListExpr(const InitListExpr *IE) {
2580 // We care about the syntactic form of the initializer list, only.
2581 if (InitListExpr *Syntactic = IE->getSyntacticForm())
2582 IE = Syntactic;
2583 EnqueueChildren(IE);
2584}
2585void EnqueueVisitor::VisitMemberExpr(const MemberExpr *M) {
2586 WL.push_back(MemberExprParts(M, Parent));
2587
2588 // If the base of the member access expression is an implicit 'this', don't
2589 // visit it.
2590 // FIXME: If we ever want to show these implicit accesses, this will be
2591 // unfortunate. However, clang_getCursor() relies on this behavior.
2592 if (M->isImplicitAccess())
2593 return;
2594
2595 // Ignore base anonymous struct/union fields, otherwise they will shadow the
2596 // real field that that we are interested in.
2597 if (auto *SubME = dyn_cast<MemberExpr>(M->getBase())) {
2598 if (auto *FD = dyn_cast_or_null<FieldDecl>(SubME->getMemberDecl())) {
2599 if (FD->isAnonymousStructOrUnion()) {
2600 AddStmt(SubME->getBase());
2601 return;
2602 }
2603 }
2604 }
2605
2606 AddStmt(M->getBase());
2607}
2608void EnqueueVisitor::VisitObjCEncodeExpr(const ObjCEncodeExpr *E) {
2609 AddTypeLoc(E->getEncodedTypeSourceInfo());
2610}
2611void EnqueueVisitor::VisitObjCMessageExpr(const ObjCMessageExpr *M) {
2612 EnqueueChildren(M);
2613 AddTypeLoc(M->getClassReceiverTypeInfo());
2614}
2615void EnqueueVisitor::VisitOffsetOfExpr(const OffsetOfExpr *E) {
2616 // Visit the components of the offsetof expression.
2617 for (unsigned N = E->getNumComponents(), I = N; I > 0; --I) {
2618 const OffsetOfNode &Node = E->getComponent(I-1);
2619 switch (Node.getKind()) {
2620 case OffsetOfNode::Array:
2621 AddStmt(E->getIndexExpr(Node.getArrayExprIndex()));
2622 break;
2623 case OffsetOfNode::Field:
2624 AddMemberRef(Node.getField(), Node.getSourceRange().getEnd());
2625 break;
2626 case OffsetOfNode::Identifier:
2627 case OffsetOfNode::Base:
2628 continue;
2629 }
2630 }
2631 // Visit the type into which we're computing the offset.
2632 AddTypeLoc(E->getTypeSourceInfo());
2633}
2634void EnqueueVisitor::VisitOverloadExpr(const OverloadExpr *E) {
2635 if (E->hasExplicitTemplateArgs())
2636 AddExplicitTemplateArgs(E->getTemplateArgs(), E->getNumTemplateArgs());
2637 WL.push_back(OverloadExprParts(E, Parent));
2638}
2639void EnqueueVisitor::VisitUnaryExprOrTypeTraitExpr(
2640 const UnaryExprOrTypeTraitExpr *E) {
2641 EnqueueChildren(E);
2642 if (E->isArgumentType())
2643 AddTypeLoc(E->getArgumentTypeInfo());
2644}
2645void EnqueueVisitor::VisitStmt(const Stmt *S) {
2646 EnqueueChildren(S);
2647}
2648void EnqueueVisitor::VisitSwitchStmt(const SwitchStmt *S) {
2649 AddStmt(S->getBody());
2650 AddStmt(S->getCond());
2651 AddDecl(S->getConditionVariable());
2652}
2653
2654void EnqueueVisitor::VisitWhileStmt(const WhileStmt *W) {
2655 AddStmt(W->getBody());
2656 AddStmt(W->getCond());
2657 AddDecl(W->getConditionVariable());
2658}
2659
2660void EnqueueVisitor::VisitTypeTraitExpr(const TypeTraitExpr *E) {
2661 for (unsigned I = E->getNumArgs(); I > 0; --I)
2662 AddTypeLoc(E->getArg(I-1));
2663}
2664
2665void EnqueueVisitor::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) {
2666 AddTypeLoc(E->getQueriedTypeSourceInfo());
2667}
2668
2669void EnqueueVisitor::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) {
2670 EnqueueChildren(E);
2671}
2672
2673void EnqueueVisitor::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *U) {
2674 VisitOverloadExpr(U);
2675 if (!U->isImplicitAccess())
2676 AddStmt(U->getBase());
2677}
2678void EnqueueVisitor::VisitVAArgExpr(const VAArgExpr *E) {
2679 AddStmt(E->getSubExpr());
2680 AddTypeLoc(E->getWrittenTypeInfo());
2681}
2682void EnqueueVisitor::VisitSizeOfPackExpr(const SizeOfPackExpr *E) {
2683 WL.push_back(SizeOfPackExprParts(E, Parent));
2684}
2685void EnqueueVisitor::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
2686 // If the opaque value has a source expression, just transparently
2687 // visit that. This is useful for (e.g.) pseudo-object expressions.
2688 if (Expr *SourceExpr = E->getSourceExpr())
2689 return Visit(SourceExpr);
2690}
2691void EnqueueVisitor::VisitLambdaExpr(const LambdaExpr *E) {
2692 AddStmt(E->getBody());
2693 WL.push_back(LambdaExprParts(E, Parent));
2694}
2695void EnqueueVisitor::VisitPseudoObjectExpr(const PseudoObjectExpr *E) {
2696 // Treat the expression like its syntactic form.
2697 Visit(E->getSyntacticForm());
2698}
2699
2700void EnqueueVisitor::VisitOMPExecutableDirective(
2701 const OMPExecutableDirective *D) {
2702 EnqueueChildren(D);
2703 for (ArrayRef<OMPClause *>::iterator I = D->clauses().begin(),
2704 E = D->clauses().end();
2705 I != E; ++I)
2706 EnqueueChildren(*I);
2707}
2708
2709void EnqueueVisitor::VisitOMPLoopDirective(const OMPLoopDirective *D) {
2710 VisitOMPExecutableDirective(D);
2711}
2712
2713void EnqueueVisitor::VisitOMPParallelDirective(const OMPParallelDirective *D) {
2714 VisitOMPExecutableDirective(D);
2715}
2716
2717void EnqueueVisitor::VisitOMPSimdDirective(const OMPSimdDirective *D) {
2718 VisitOMPLoopDirective(D);
2719}
2720
2721void EnqueueVisitor::VisitOMPForDirective(const OMPForDirective *D) {
2722 VisitOMPLoopDirective(D);
2723}
2724
2725void EnqueueVisitor::VisitOMPForSimdDirective(const OMPForSimdDirective *D) {
2726 VisitOMPLoopDirective(D);
2727}
2728
2729void EnqueueVisitor::VisitOMPSectionsDirective(const OMPSectionsDirective *D) {
2730 VisitOMPExecutableDirective(D);
2731}
2732
2733void EnqueueVisitor::VisitOMPSectionDirective(const OMPSectionDirective *D) {
2734 VisitOMPExecutableDirective(D);
2735}
2736
2737void EnqueueVisitor::VisitOMPSingleDirective(const OMPSingleDirective *D) {
2738 VisitOMPExecutableDirective(D);
2739}
2740
2741void EnqueueVisitor::VisitOMPMasterDirective(const OMPMasterDirective *D) {
2742 VisitOMPExecutableDirective(D);
2743}
2744
2745void EnqueueVisitor::VisitOMPCriticalDirective(const OMPCriticalDirective *D) {
2746 VisitOMPExecutableDirective(D);
2747 AddDeclarationNameInfo(D);
2748}
2749
2750void
2751EnqueueVisitor::VisitOMPParallelForDirective(const OMPParallelForDirective *D) {
2752 VisitOMPLoopDirective(D);
2753}
2754
2755void EnqueueVisitor::VisitOMPParallelForSimdDirective(
2756 const OMPParallelForSimdDirective *D) {
2757 VisitOMPLoopDirective(D);
2758}
2759
2760void EnqueueVisitor::VisitOMPParallelSectionsDirective(
2761 const OMPParallelSectionsDirective *D) {
2762 VisitOMPExecutableDirective(D);
2763}
2764
2765void EnqueueVisitor::VisitOMPTaskDirective(const OMPTaskDirective *D) {
2766 VisitOMPExecutableDirective(D);
2767}
2768
2769void
2770EnqueueVisitor::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *D) {
2771 VisitOMPExecutableDirective(D);
2772}
2773
2774void EnqueueVisitor::VisitOMPBarrierDirective(const OMPBarrierDirective *D) {
2775 VisitOMPExecutableDirective(D);
2776}
2777
2778void EnqueueVisitor::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *D) {
2779 VisitOMPExecutableDirective(D);
2780}
2781
2782void EnqueueVisitor::VisitOMPTaskgroupDirective(
2783 const OMPTaskgroupDirective *D) {
2784 VisitOMPExecutableDirective(D);
2785 if (const Expr *E = D->getReductionRef())
2786 VisitStmt(E);
2787}
2788
2789void EnqueueVisitor::VisitOMPFlushDirective(const OMPFlushDirective *D) {
2790 VisitOMPExecutableDirective(D);
2791}
2792
2793void EnqueueVisitor::VisitOMPOrderedDirective(const OMPOrderedDirective *D) {
2794 VisitOMPExecutableDirective(D);
2795}
2796
2797void EnqueueVisitor::VisitOMPAtomicDirective(const OMPAtomicDirective *D) {
2798 VisitOMPExecutableDirective(D);
2799}
2800
2801void EnqueueVisitor::VisitOMPTargetDirective(const OMPTargetDirective *D) {
2802 VisitOMPExecutableDirective(D);
2803}
2804
2805void EnqueueVisitor::VisitOMPTargetDataDirective(const
2806 OMPTargetDataDirective *D) {
2807 VisitOMPExecutableDirective(D);
2808}
2809
2810void EnqueueVisitor::VisitOMPTargetEnterDataDirective(
2811 const OMPTargetEnterDataDirective *D) {
2812 VisitOMPExecutableDirective(D);
2813}
2814
2815void EnqueueVisitor::VisitOMPTargetExitDataDirective(
2816 const OMPTargetExitDataDirective *D) {
2817 VisitOMPExecutableDirective(D);
2818}
2819
2820void EnqueueVisitor::VisitOMPTargetParallelDirective(
2821 const OMPTargetParallelDirective *D) {
2822 VisitOMPExecutableDirective(D);
2823}
2824
2825void EnqueueVisitor::VisitOMPTargetParallelForDirective(
2826 const OMPTargetParallelForDirective *D) {
2827 VisitOMPLoopDirective(D);
2828}
2829
2830void EnqueueVisitor::VisitOMPTeamsDirective(const OMPTeamsDirective *D) {
2831 VisitOMPExecutableDirective(D);
2832}
2833
2834void EnqueueVisitor::VisitOMPCancellationPointDirective(
2835 const OMPCancellationPointDirective *D) {
2836 VisitOMPExecutableDirective(D);
2837}
2838
2839void EnqueueVisitor::VisitOMPCancelDirective(const OMPCancelDirective *D) {
2840 VisitOMPExecutableDirective(D);
2841}
2842
2843void EnqueueVisitor::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *D) {
2844 VisitOMPLoopDirective(D);
2845}
2846
2847void EnqueueVisitor::VisitOMPTaskLoopSimdDirective(
2848 const OMPTaskLoopSimdDirective *D) {
2849 VisitOMPLoopDirective(D);
2850}
2851
2852void EnqueueVisitor::VisitOMPDistributeDirective(
2853 const OMPDistributeDirective *D) {
2854 VisitOMPLoopDirective(D);
2855}
2856
2857void EnqueueVisitor::VisitOMPDistributeParallelForDirective(
2858 const OMPDistributeParallelForDirective *D) {
2859 VisitOMPLoopDirective(D);
2860}
2861
2862void EnqueueVisitor::VisitOMPDistributeParallelForSimdDirective(
2863 const OMPDistributeParallelForSimdDirective *D) {
2864 VisitOMPLoopDirective(D);
2865}
2866
2867void EnqueueVisitor::VisitOMPDistributeSimdDirective(
2868 const OMPDistributeSimdDirective *D) {
2869 VisitOMPLoopDirective(D);
2870}
2871
2872void EnqueueVisitor::VisitOMPTargetParallelForSimdDirective(
2873 const OMPTargetParallelForSimdDirective *D) {
2874 VisitOMPLoopDirective(D);
2875}
2876
2877void EnqueueVisitor::VisitOMPTargetSimdDirective(
2878 const OMPTargetSimdDirective *D) {
2879 VisitOMPLoopDirective(D);
2880}
2881
2882void EnqueueVisitor::VisitOMPTeamsDistributeDirective(
2883 const OMPTeamsDistributeDirective *D) {
2884 VisitOMPLoopDirective(D);
2885}
2886
2887void EnqueueVisitor::VisitOMPTeamsDistributeSimdDirective(
2888 const OMPTeamsDistributeSimdDirective *D) {
2889 VisitOMPLoopDirective(D);
2890}
2891
2892void EnqueueVisitor::VisitOMPTeamsDistributeParallelForSimdDirective(
2893 const OMPTeamsDistributeParallelForSimdDirective *D) {
2894 VisitOMPLoopDirective(D);
2895}
2896
2897void EnqueueVisitor::VisitOMPTeamsDistributeParallelForDirective(
2898 const OMPTeamsDistributeParallelForDirective *D) {
2899 VisitOMPLoopDirective(D);
2900}
2901
2902void EnqueueVisitor::VisitOMPTargetTeamsDirective(
2903 const OMPTargetTeamsDirective *D) {
2904 VisitOMPExecutableDirective(D);
2905}
2906
2907void EnqueueVisitor::VisitOMPTargetTeamsDistributeDirective(
2908 const OMPTargetTeamsDistributeDirective *D) {
2909 VisitOMPLoopDirective(D);
2910}
2911
2912void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForDirective(
2913 const OMPTargetTeamsDistributeParallelForDirective *D) {
2914 VisitOMPLoopDirective(D);
2915}
2916
2917void EnqueueVisitor::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
2918 const OMPTargetTeamsDistributeParallelForSimdDirective *D) {
2919 VisitOMPLoopDirective(D);
2920}
2921
2922void EnqueueVisitor::VisitOMPTargetTeamsDistributeSimdDirective(
2923 const OMPTargetTeamsDistributeSimdDirective *D) {
2924 VisitOMPLoopDirective(D);
2925}
2926
2927void CursorVisitor::EnqueueWorkList(VisitorWorkList &WL, const Stmt *S) {
2928 EnqueueVisitor(WL, MakeCXCursor(S, StmtParent, TU,RegionOfInterest)).Visit(S);
2929}
2930
2931bool CursorVisitor::IsInRegionOfInterest(CXCursor C) {
2932 if (RegionOfInterest.isValid()) {
2933 SourceRange Range = getRawCursorExtent(C);
2934 if (Range.isInvalid() || CompareRegionOfInterest(Range))
2935 return false;
2936 }
2937 return true;
2938}
2939
2940bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
2941 while (!WL.empty()) {
2942 // Dequeue the worklist item.
2943 VisitorJob LI = WL.pop_back_val();
2944
2945 // Set the Parent field, then back to its old value once we're done.
2946 SetParentRAII SetParent(Parent, StmtParent, LI.getParent());
2947
2948 switch (LI.getKind()) {
2949 case VisitorJob::DeclVisitKind: {
2950 const Decl *D = cast<DeclVisit>(&LI)->get();
2951 if (!D)
2952 continue;
2953
2954 // For now, perform default visitation for Decls.
2955 if (Visit(MakeCXCursor(D, TU, RegionOfInterest,
2956 cast<DeclVisit>(&LI)->isFirst())))
2957 return true;
2958
2959 continue;
2960 }
2961 case VisitorJob::ExplicitTemplateArgsVisitKind: {
2962 for (const TemplateArgumentLoc &Arg :
2963 *cast<ExplicitTemplateArgsVisit>(&LI)) {
2964 if (VisitTemplateArgumentLoc(Arg))
2965 return true;
2966 }
2967 continue;
2968 }
2969 case VisitorJob::TypeLocVisitKind: {
2970 // Perform default visitation for TypeLocs.
2971 if (Visit(cast<TypeLocVisit>(&LI)->get()))
2972 return true;
2973 continue;
2974 }
2975 case VisitorJob::LabelRefVisitKind: {
2976 const LabelDecl *LS = cast<LabelRefVisit>(&LI)->get();
2977 if (LabelStmt *stmt = LS->getStmt()) {
2978 if (Visit(MakeCursorLabelRef(stmt, cast<LabelRefVisit>(&LI)->getLoc(),
2979 TU))) {
2980 return true;
2981 }
2982 }
2983 continue;
2984 }
2985
2986 case VisitorJob::NestedNameSpecifierLocVisitKind: {
2987 NestedNameSpecifierLocVisit *V = cast<NestedNameSpecifierLocVisit>(&LI);
2988 if (VisitNestedNameSpecifierLoc(V->get()))
2989 return true;
2990 continue;
2991 }
2992
2993 case VisitorJob::DeclarationNameInfoVisitKind: {
2994 if (VisitDeclarationNameInfo(cast<DeclarationNameInfoVisit>(&LI)
2995 ->get()))
2996 return true;
2997 continue;
2998 }
2999 case VisitorJob::MemberRefVisitKind: {
3000 MemberRefVisit *V = cast<MemberRefVisit>(&LI);
3001 if (Visit(MakeCursorMemberRef(V->get(), V->getLoc(), TU)))
3002 return true;
3003 continue;
3004 }
3005 case VisitorJob::StmtVisitKind: {
3006 const Stmt *S = cast<StmtVisit>(&LI)->get();
3007 if (!S)
3008 continue;
3009
3010 // Update the current cursor.
3011 CXCursor Cursor = MakeCXCursor(S, StmtParent, TU, RegionOfInterest);
3012 if (!IsInRegionOfInterest(Cursor))
3013 continue;
3014 switch (Visitor(Cursor, Parent, ClientData)) {
3015 case CXChildVisit_Break: return true;
3016 case CXChildVisit_Continue: break;
3017 case CXChildVisit_Recurse:
3018 if (PostChildrenVisitor)
3019 WL.push_back(PostChildrenVisit(nullptr, Cursor));
3020 EnqueueWorkList(WL, S);
3021 break;
3022 }
3023 continue;
3024 }
3025 case VisitorJob::MemberExprPartsKind: {
3026 // Handle the other pieces in the MemberExpr besides the base.
3027 const MemberExpr *M = cast<MemberExprParts>(&LI)->get();
3028
3029 // Visit the nested-name-specifier
3030 if (NestedNameSpecifierLoc QualifierLoc = M->getQualifierLoc())
3031 if (VisitNestedNameSpecifierLoc(QualifierLoc))
3032 return true;
3033
3034 // Visit the declaration name.
3035 if (VisitDeclarationNameInfo(M->getMemberNameInfo()))
3036 return true;
3037
3038 // Visit the explicitly-specified template arguments, if any.
3039 if (M->hasExplicitTemplateArgs()) {
3040 for (const TemplateArgumentLoc *Arg = M->getTemplateArgs(),
3041 *ArgEnd = Arg + M->getNumTemplateArgs();
3042 Arg != ArgEnd; ++Arg) {
3043 if (VisitTemplateArgumentLoc(*Arg))
3044 return true;
3045 }
3046 }
3047 continue;
3048 }
3049 case VisitorJob::DeclRefExprPartsKind: {
3050 const DeclRefExpr *DR = cast<DeclRefExprParts>(&LI)->get();
3051 // Visit nested-name-specifier, if present.
3052 if (NestedNameSpecifierLoc QualifierLoc = DR->getQualifierLoc())
3053 if (VisitNestedNameSpecifierLoc(QualifierLoc))
3054 return true;
3055 // Visit declaration name.
3056 if (VisitDeclarationNameInfo(DR->getNameInfo()))
3057 return true;
3058 continue;
3059 }
3060 case VisitorJob::OverloadExprPartsKind: {
3061 const OverloadExpr *O = cast<OverloadExprParts>(&LI)->get();
3062 // Visit the nested-name-specifier.
3063 if (NestedNameSpecifierLoc QualifierLoc = O->getQualifierLoc())
3064 if (VisitNestedNameSpecifierLoc(QualifierLoc))
3065 return true;
3066 // Visit the declaration name.
3067 if (VisitDeclarationNameInfo(O->getNameInfo()))
3068 return true;
3069 // Visit the overloaded declaration reference.
3070 if (Visit(MakeCursorOverloadedDeclRef(O, TU)))
3071 return true;
3072 continue;
3073 }
3074 case VisitorJob::SizeOfPackExprPartsKind: {
3075 const SizeOfPackExpr *E = cast<SizeOfPackExprParts>(&LI)->get();
3076 NamedDecl *Pack = E->getPack();
3077 if (isa<TemplateTypeParmDecl>(Pack)) {
3078 if (Visit(MakeCursorTypeRef(cast<TemplateTypeParmDecl>(Pack),
3079 E->getPackLoc(), TU)))
3080 return true;
3081
3082 continue;
3083 }
3084
3085 if (isa<TemplateTemplateParmDecl>(Pack)) {
3086 if (Visit(MakeCursorTemplateRef(cast<TemplateTemplateParmDecl>(Pack),
3087 E->getPackLoc(), TU)))
3088 return true;
3089
3090 continue;
3091 }
3092
3093 // Non-type template parameter packs and function parameter packs are
3094 // treated like DeclRefExpr cursors.
3095 continue;
3096 }
3097
3098 case VisitorJob::LambdaExprPartsKind: {
3099 // Visit captures.
3100 const LambdaExpr *E = cast<LambdaExprParts>(&LI)->get();
3101 for (LambdaExpr::capture_iterator C = E->explicit_capture_begin(),
3102 CEnd = E->explicit_capture_end();
3103 C != CEnd; ++C) {
3104 // FIXME: Lambda init-captures.
3105 if (!C->capturesVariable())
3106 continue;
3107
3108 if (Visit(MakeCursorVariableRef(C->getCapturedVar(),
3109 C->getLocation(),
3110 TU)))
3111 return true;
3112 }
3113
3114 // Visit parameters and return type, if present.
3115 if (E->hasExplicitParameters() || E->hasExplicitResultType()) {
3116 TypeLoc TL = E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
3117 if (E->hasExplicitParameters() && E->hasExplicitResultType()) {
3118 // Visit the whole type.
3119 if (Visit(TL))
3120 return true;
3121 } else if (FunctionProtoTypeLoc Proto =
3122 TL.getAs<FunctionProtoTypeLoc>()) {
3123 if (E->hasExplicitParameters()) {
3124 // Visit parameters.
3125 for (unsigned I = 0, N = Proto.getNumParams(); I != N; ++I)
3126 if (Visit(MakeCXCursor(Proto.getParam(I), TU)))
3127 return true;
3128 } else {
3129 // Visit result type.
3130 if (Visit(Proto.getReturnLoc()))
3131 return true;
3132 }
3133 }
3134 }
3135 break;
3136 }
3137
3138 case VisitorJob::PostChildrenVisitKind:
3139 if (PostChildrenVisitor(Parent, ClientData))
3140 return true;
3141 break;
3142 }
3143 }
3144 return false;
3145}
3146
3147bool CursorVisitor::Visit(const Stmt *S) {
3148 VisitorWorkList *WL = nullptr;
3149 if (!WorkListFreeList.empty()) {
3150 WL = WorkListFreeList.back();
3151 WL->clear();
3152 WorkListFreeList.pop_back();
3153 }
3154 else {
3155 WL = new VisitorWorkList();
3156 WorkListCache.push_back(WL);
3157 }
3158 EnqueueWorkList(*WL, S);
3159 bool result = RunVisitorWorkList(*WL);
3160 WorkListFreeList.push_back(WL);
3161 return result;
3162}
3163
3164namespace {
3165typedef SmallVector<SourceRange, 4> RefNamePieces;
3166RefNamePieces buildPieces(unsigned NameFlags, bool IsMemberRefExpr,
3167 const DeclarationNameInfo &NI, SourceRange QLoc,
3168 const SourceRange *TemplateArgsLoc = nullptr) {
3169 const bool WantQualifier = NameFlags & CXNameRange_WantQualifier;
3170 const bool WantTemplateArgs = NameFlags & CXNameRange_WantTemplateArgs;
3171 const bool WantSinglePiece = NameFlags & CXNameRange_WantSinglePiece;
3172
3173 const DeclarationName::NameKind Kind = NI.getName().getNameKind();
3174
3175 RefNamePieces Pieces;
3176
3177 if (WantQualifier && QLoc.isValid())
3178 Pieces.push_back(QLoc);
3179
3180 if (Kind != DeclarationName::CXXOperatorName || IsMemberRefExpr)
3181 Pieces.push_back(NI.getLoc());
3182
3183 if (WantTemplateArgs && TemplateArgsLoc && TemplateArgsLoc->isValid())
3184 Pieces.push_back(*TemplateArgsLoc);
3185
3186 if (Kind == DeclarationName::CXXOperatorName) {
3187 Pieces.push_back(SourceLocation::getFromRawEncoding(
3188 NI.getInfo().CXXOperatorName.BeginOpNameLoc));
3189 Pieces.push_back(SourceLocation::getFromRawEncoding(
3190 NI.getInfo().CXXOperatorName.EndOpNameLoc));
3191 }
3192
3193 if (WantSinglePiece) {
3194 SourceRange R(Pieces.front().getBegin(), Pieces.back().getEnd());
3195 Pieces.clear();
3196 Pieces.push_back(R);
3197 }
3198
3199 return Pieces;
3200}
3201}
3202
3203//===----------------------------------------------------------------------===//
3204// Misc. API hooks.
3205//===----------------------------------------------------------------------===//
3206
3207static void fatal_error_handler(void *user_data, const std::string& reason,
3208 bool gen_crash_diag) {
3209 // Write the result out to stderr avoiding errs() because raw_ostreams can
3210 // call report_fatal_error.
3211 fprintf(stderrstderr, "LIBCLANG FATAL ERROR: %s\n", reason.c_str());
3212 ::abort();
3213}
3214
3215namespace {
3216struct RegisterFatalErrorHandler {
3217 RegisterFatalErrorHandler() {
3218 llvm::install_fatal_error_handler(fatal_error_handler, nullptr);
3219 }
3220};
3221}
3222
3223static llvm::ManagedStatic<RegisterFatalErrorHandler> RegisterFatalErrorHandlerOnce;
3224
3225CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
3226 int displayDiagnostics) {
3227 // We use crash recovery to make some of our APIs more reliable, implicitly
3228 // enable it.
3229 if (!getenv("LIBCLANG_DISABLE_CRASH_RECOVERY"))
3230 llvm::CrashRecoveryContext::Enable();
3231
3232 // Look through the managed static to trigger construction of the managed
3233 // static which registers our fatal error handler. This ensures it is only
3234 // registered once.
3235 (void)*RegisterFatalErrorHandlerOnce;
3236
3237 // Initialize targets for clang module support.
3238 llvm::InitializeAllTargets();
3239 llvm::InitializeAllTargetMCs();
3240 llvm::InitializeAllAsmPrinters();
3241 llvm::InitializeAllAsmParsers();
3242
3243 CIndexer *CIdxr = new CIndexer();
3244
3245 if (excludeDeclarationsFromPCH)
3246 CIdxr->setOnlyLocalDecls();
3247 if (displayDiagnostics)
3248 CIdxr->setDisplayDiagnostics();
3249
3250 if (getenv("LIBCLANG_BGPRIO_INDEX"))
3251 CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() |
3252 CXGlobalOpt_ThreadBackgroundPriorityForIndexing);
3253 if (getenv("LIBCLANG_BGPRIO_EDIT"))
3254 CIdxr->setCXGlobalOptFlags(CIdxr->getCXGlobalOptFlags() |
3255 CXGlobalOpt_ThreadBackgroundPriorityForEditing);
3256
3257 return CIdxr;
3258}
3259
3260void clang_disposeIndex(CXIndex CIdx) {
3261 if (CIdx)
3262 delete static_cast<CIndexer *>(CIdx);
3263}
3264
3265void clang_CXIndex_setGlobalOptions(CXIndex CIdx, unsigned options) {
3266 if (CIdx)
3267 static_cast<CIndexer *>(CIdx)->setCXGlobalOptFlags(options);
3268}
3269
3270unsigned clang_CXIndex_getGlobalOptions(CXIndex CIdx) {
3271 if (CIdx)
3272 return static_cast<CIndexer *>(CIdx)->getCXGlobalOptFlags();
3273 return 0;
3274}
3275
3276void clang_CXIndex_setInvocationEmissionPathOption(CXIndex CIdx,
3277 const char *Path) {
3278 if (CIdx)
3279 static_cast<CIndexer *>(CIdx)->setInvocationEmissionPath(Path ? Path : "");
3280}
3281
3282void clang_toggleCrashRecovery(unsigned isEnabled) {
3283 if (isEnabled)
3284 llvm::CrashRecoveryContext::Enable();
3285 else
3286 llvm::CrashRecoveryContext::Disable();
3287}
3288
3289CXTranslationUnit clang_createTranslationUnit(CXIndex CIdx,
3290 const char *ast_filename) {
3291 CXTranslationUnit TU;
3292 enum CXErrorCode Result =
3293 clang_createTranslationUnit2(CIdx, ast_filename, &TU);
3294 (void)Result;
3295 assert((TU && Result == CXError_Success) ||(static_cast <bool> ((TU && Result == CXError_Success
) || (!TU && Result != CXError_Success)) ? void (0) :
__assert_fail ("(TU && Result == CXError_Success) || (!TU && Result != CXError_Success)"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 3296, __extension__ __PRETTY_FUNCTION__))
3296 (!TU && Result != CXError_Success))(static_cast <bool> ((TU && Result == CXError_Success
) || (!TU && Result != CXError_Success)) ? void (0) :
__assert_fail ("(TU && Result == CXError_Success) || (!TU && Result != CXError_Success)"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 3296, __extension__ __PRETTY_FUNCTION__))
;
3297 return TU;
3298}
3299
3300enum CXErrorCode clang_createTranslationUnit2(CXIndex CIdx,
3301 const char *ast_filename,
3302 CXTranslationUnit *out_TU) {
3303 if (out_TU)
3304 *out_TU = nullptr;
3305
3306 if (!CIdx || !ast_filename || !out_TU)
3307 return CXError_InvalidArguments;
3308
3309 LOG_FUNC_SECTIONif (clang::cxindex::LogRef Log = clang::cxindex::Logger::make
(__func__))
{
3310 *Log << ast_filename;
3311 }
3312
3313 CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
3314 FileSystemOptions FileSystemOpts;
3315
3316 IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
3317 CompilerInstance::createDiagnostics(new DiagnosticOptions());
3318 std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
3319 ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(),
3320 ASTUnit::LoadEverything, Diags,
3321 FileSystemOpts, /*UseDebugInfo=*/false,
3322 CXXIdx->getOnlyLocalDecls(), None,
3323 /*CaptureDiagnostics=*/true,
3324 /*AllowPCHWithCompilerErrors=*/true,
3325 /*UserFilesAreVolatile=*/true);
3326 *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(AU));
3327 return *out_TU ? CXError_Success : CXError_Failure;
3328}
3329
3330unsigned clang_defaultEditingTranslationUnitOptions() {
3331 return CXTranslationUnit_PrecompiledPreamble |
3332 CXTranslationUnit_CacheCompletionResults;
3333}
3334
3335CXTranslationUnit
3336clang_createTranslationUnitFromSourceFile(CXIndex CIdx,
3337 const char *source_filename,
3338 int num_command_line_args,
3339 const char * const *command_line_args,
3340 unsigned num_unsaved_files,
3341 struct CXUnsavedFile *unsaved_files) {
3342 unsigned Options = CXTranslationUnit_DetailedPreprocessingRecord;
3343 return clang_parseTranslationUnit(CIdx, source_filename,
3344 command_line_args, num_command_line_args,
3345 unsaved_files, num_unsaved_files,
3346 Options);
3347}
3348
3349static CXErrorCode
3350clang_parseTranslationUnit_Impl(CXIndex CIdx, const char *source_filename,
3351 const char *const *command_line_args,
3352 int num_command_line_args,
3353 ArrayRef<CXUnsavedFile> unsaved_files,
3354 unsigned options, CXTranslationUnit *out_TU) {
3355 // Set up the initial return values.
3356 if (out_TU)
3357 *out_TU = nullptr;
3358
3359 // Check arguments.
3360 if (!CIdx || !out_TU)
3361 return CXError_InvalidArguments;
3362
3363 CIndexer *CXXIdx = static_cast<CIndexer *>(CIdx);
3364
3365 if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
3366 setThreadBackgroundPriority();
3367
3368 bool PrecompilePreamble = options & CXTranslationUnit_PrecompiledPreamble;
3369 bool CreatePreambleOnFirstParse =
3370 options & CXTranslationUnit_CreatePreambleOnFirstParse;
3371 // FIXME: Add a flag for modules.
3372 TranslationUnitKind TUKind
3373 = (options & (CXTranslationUnit_Incomplete |
3374 CXTranslationUnit_SingleFileParse))? TU_Prefix : TU_Complete;
3375 bool CacheCodeCompletionResults
3376 = options & CXTranslationUnit_CacheCompletionResults;
3377 bool IncludeBriefCommentsInCodeCompletion
3378 = options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
3379 bool SkipFunctionBodies = options & CXTranslationUnit_SkipFunctionBodies;
3380 bool SingleFileParse = options & CXTranslationUnit_SingleFileParse;
3381 bool ForSerialization = options & CXTranslationUnit_ForSerialization;
3382
3383 // Configure the diagnostics.
3384 IntrusiveRefCntPtr<DiagnosticsEngine>
3385 Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions));
3386
3387 if (options & CXTranslationUnit_KeepGoing)
3388 Diags->setSuppressAfterFatalError(false);
3389
3390 // Recover resources if we crash before exiting this function.
3391 llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
3392 llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
3393 DiagCleanup(Diags.get());
3394
3395 std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles(
3396 new std::vector<ASTUnit::RemappedFile>());
3397
3398 // Recover resources if we crash before exiting this function.
3399 llvm::CrashRecoveryContextCleanupRegistrar<
3400 std::vector<ASTUnit::RemappedFile> > RemappedCleanup(RemappedFiles.get());
3401
3402 for (auto &UF : unsaved_files) {
3403 std::unique_ptr<llvm::MemoryBuffer> MB =
3404 llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
3405 RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
3406 }
3407
3408 std::unique_ptr<std::vector<const char *>> Args(
3409 new std::vector<const char *>());
3410
3411 // Recover resources if we crash before exiting this method.
3412 llvm::CrashRecoveryContextCleanupRegistrar<std::vector<const char*> >
3413 ArgsCleanup(Args.get());
3414
3415 // Since the Clang C library is primarily used by batch tools dealing with
3416 // (often very broken) source code, where spell-checking can have a
3417 // significant negative impact on performance (particularly when
3418 // precompiled headers are involved), we disable it by default.
3419 // Only do this if we haven't found a spell-checking-related argument.
3420 bool FoundSpellCheckingArgument = false;
3421 for (int I = 0; I != num_command_line_args; ++I) {
3422 if (strcmp(command_line_args[I], "-fno-spell-checking") == 0 ||
3423 strcmp(command_line_args[I], "-fspell-checking") == 0) {
3424 FoundSpellCheckingArgument = true;
3425 break;
3426 }
3427 }
3428 Args->insert(Args->end(), command_line_args,
3429 command_line_args + num_command_line_args);
3430
3431 if (!FoundSpellCheckingArgument)
3432 Args->insert(Args->begin() + 1, "-fno-spell-checking");
3433
3434 // The 'source_filename' argument is optional. If the caller does not
3435 // specify it then it is assumed that the source file is specified
3436 // in the actual argument list.
3437 // Put the source file after command_line_args otherwise if '-x' flag is
3438 // present it will be unused.
3439 if (source_filename)
3440 Args->push_back(source_filename);
3441
3442 // Do we need the detailed preprocessing record?
3443 if (options & CXTranslationUnit_DetailedPreprocessingRecord) {
3444 Args->push_back("-Xclang");
3445 Args->push_back("-detailed-preprocessing-record");
3446 }
3447
3448 // Suppress any editor placeholder diagnostics.
3449 Args->push_back("-fallow-editor-placeholders");
3450
3451 unsigned NumErrors = Diags->getClient()->getNumErrors();
3452 std::unique_ptr<ASTUnit> ErrUnit;
3453 // Unless the user specified that they want the preamble on the first parse
3454 // set it up to be created on the first reparse. This makes the first parse
3455 // faster, trading for a slower (first) reparse.
3456 unsigned PrecompilePreambleAfterNParses =
3457 !PrecompilePreamble ? 0 : 2 - CreatePreambleOnFirstParse;
3458
3459 LibclangInvocationReporter InvocationReporter(
3460 *CXXIdx, LibclangInvocationReporter::OperationKind::ParseOperation,
3461 options, llvm::makeArrayRef(*Args), /*InvocationArgs=*/None,
3462 unsaved_files);
3463 std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCommandLine(
3464 Args->data(), Args->data() + Args->size(),
3465 CXXIdx->getPCHContainerOperations(), Diags,
3466 CXXIdx->getClangResourcesPath(), CXXIdx->getOnlyLocalDecls(),
3467 /*CaptureDiagnostics=*/true, *RemappedFiles.get(),
3468 /*RemappedFilesKeepOriginalName=*/true, PrecompilePreambleAfterNParses,
3469 TUKind, CacheCodeCompletionResults, IncludeBriefCommentsInCodeCompletion,
3470 /*AllowPCHWithCompilerErrors=*/true, SkipFunctionBodies, SingleFileParse,
3471 /*UserFilesAreVolatile=*/true, ForSerialization,
3472 CXXIdx->getPCHContainerOperations()->getRawReader().getFormat(),
3473 &ErrUnit));
3474
3475 // Early failures in LoadFromCommandLine may return with ErrUnit unset.
3476 if (!Unit && !ErrUnit)
3477 return CXError_ASTReadError;
3478
3479 if (NumErrors != Diags->getClient()->getNumErrors()) {
3480 // Make sure to check that 'Unit' is non-NULL.
3481 if (CXXIdx->getDisplayDiagnostics())
3482 printDiagsToStderr(Unit ? Unit.get() : ErrUnit.get());
3483 }
3484
3485 if (isASTReadError(Unit ? Unit.get() : ErrUnit.get()))
3486 return CXError_ASTReadError;
3487
3488 *out_TU = MakeCXTranslationUnit(CXXIdx, std::move(Unit));
3489 if (CXTranslationUnitImpl *TU = *out_TU) {
3490 TU->ParsingOptions = options;
3491 TU->Arguments.reserve(Args->size());
3492 for (const char *Arg : *Args)
3493 TU->Arguments.push_back(Arg);
3494 return CXError_Success;
3495 }
3496 return CXError_Failure;
3497}
3498
3499CXTranslationUnit
3500clang_parseTranslationUnit(CXIndex CIdx,
3501 const char *source_filename,
3502 const char *const *command_line_args,
3503 int num_command_line_args,
3504 struct CXUnsavedFile *unsaved_files,
3505 unsigned num_unsaved_files,
3506 unsigned options) {
3507 CXTranslationUnit TU;
3508 enum CXErrorCode Result = clang_parseTranslationUnit2(
3509 CIdx, source_filename, command_line_args, num_command_line_args,
3510 unsaved_files, num_unsaved_files, options, &TU);
3511 (void)Result;
3512 assert((TU && Result == CXError_Success) ||(static_cast <bool> ((TU && Result == CXError_Success
) || (!TU && Result != CXError_Success)) ? void (0) :
__assert_fail ("(TU && Result == CXError_Success) || (!TU && Result != CXError_Success)"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 3513, __extension__ __PRETTY_FUNCTION__))
3513 (!TU && Result != CXError_Success))(static_cast <bool> ((TU && Result == CXError_Success
) || (!TU && Result != CXError_Success)) ? void (0) :
__assert_fail ("(TU && Result == CXError_Success) || (!TU && Result != CXError_Success)"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 3513, __extension__ __PRETTY_FUNCTION__))
;
3514 return TU;
3515}
3516
3517enum CXErrorCode clang_parseTranslationUnit2(
3518 CXIndex CIdx, const char *source_filename,
3519 const char *const *command_line_args, int num_command_line_args,
3520 struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
3521 unsigned options, CXTranslationUnit *out_TU) {
3522 SmallVector<const char *, 4> Args;
3523 Args.push_back("clang");
3524 Args.append(command_line_args, command_line_args + num_command_line_args);
3525 return clang_parseTranslationUnit2FullArgv(
3526 CIdx, source_filename, Args.data(), Args.size(), unsaved_files,
3527 num_unsaved_files, options, out_TU);
3528}
3529
3530enum CXErrorCode clang_parseTranslationUnit2FullArgv(
3531 CXIndex CIdx, const char *source_filename,
3532 const char *const *command_line_args, int num_command_line_args,
3533 struct CXUnsavedFile *unsaved_files, unsigned num_unsaved_files,
3534 unsigned options, CXTranslationUnit *out_TU) {
3535 LOG_FUNC_SECTIONif (clang::cxindex::LogRef Log = clang::cxindex::Logger::make
(__func__))
{
3536 *Log << source_filename << ": ";
3537 for (int i = 0; i != num_command_line_args; ++i)
3538 *Log << command_line_args[i] << " ";
3539 }
3540
3541 if (num_unsaved_files && !unsaved_files)
3542 return CXError_InvalidArguments;
3543
3544 CXErrorCode result = CXError_Failure;
3545 auto ParseTranslationUnitImpl = [=, &result] {
3546 result = clang_parseTranslationUnit_Impl(
3547 CIdx, source_filename, command_line_args, num_command_line_args,
3548 llvm::makeArrayRef(unsaved_files, num_unsaved_files), options, out_TU);
3549 };
3550
3551 llvm::CrashRecoveryContext CRC;
3552
3553 if (!RunSafely(CRC, ParseTranslationUnitImpl)) {
3554 fprintf(stderrstderr, "libclang: crash detected during parsing: {\n");
3555 fprintf(stderrstderr, " 'source_filename' : '%s'\n", source_filename);
3556 fprintf(stderrstderr, " 'command_line_args' : [");
3557 for (int i = 0; i != num_command_line_args; ++i) {
3558 if (i)
3559 fprintf(stderrstderr, ", ");
3560 fprintf(stderrstderr, "'%s'", command_line_args[i]);
3561 }
3562 fprintf(stderrstderr, "],\n");
3563 fprintf(stderrstderr, " 'unsaved_files' : [");
3564 for (unsigned i = 0; i != num_unsaved_files; ++i) {
3565 if (i)
3566 fprintf(stderrstderr, ", ");
3567 fprintf(stderrstderr, "('%s', '...', %ld)", unsaved_files[i].Filename,
3568 unsaved_files[i].Length);
3569 }
3570 fprintf(stderrstderr, "],\n");
3571 fprintf(stderrstderr, " 'options' : %d,\n", options);
3572 fprintf(stderrstderr, "}\n");
3573
3574 return CXError_Crashed;
3575 } else if (getenv("LIBCLANG_RESOURCE_USAGE")) {
3576 if (CXTranslationUnit *TU = out_TU)
3577 PrintLibclangResourceUsage(*TU);
3578 }
3579
3580 return result;
3581}
3582
3583CXString clang_Type_getObjCEncoding(CXType CT) {
3584 CXTranslationUnit tu = static_cast<CXTranslationUnit>(CT.data[1]);
3585 ASTContext &Ctx = getASTUnit(tu)->getASTContext();
3586 std::string encoding;
3587 Ctx.getObjCEncodingForType(QualType::getFromOpaquePtr(CT.data[0]),
3588 encoding);
3589
3590 return cxstring::createDup(encoding);
3591}
3592
3593static const IdentifierInfo *getMacroIdentifier(CXCursor C) {
3594 if (C.kind == CXCursor_MacroDefinition) {
3595 if (const MacroDefinitionRecord *MDR = getCursorMacroDefinition(C))
3596 return MDR->getName();
3597 } else if (C.kind == CXCursor_MacroExpansion) {
3598 MacroExpansionCursor ME = getCursorMacroExpansion(C);
3599 return ME.getName();
3600 }
3601 return nullptr;
3602}
3603
3604unsigned clang_Cursor_isMacroFunctionLike(CXCursor C) {
3605 const IdentifierInfo *II = getMacroIdentifier(C);
3606 if (!II) {
3607 return false;
3608 }
3609 ASTUnit *ASTU = getCursorASTUnit(C);
3610 Preprocessor &PP = ASTU->getPreprocessor();
3611 if (const MacroInfo *MI = PP.getMacroInfo(II))
3612 return MI->isFunctionLike();
3613 return false;
3614}
3615
3616unsigned clang_Cursor_isMacroBuiltin(CXCursor C) {
3617 const IdentifierInfo *II = getMacroIdentifier(C);
3618 if (!II) {
3619 return false;
3620 }
3621 ASTUnit *ASTU = getCursorASTUnit(C);
3622 Preprocessor &PP = ASTU->getPreprocessor();
3623 if (const MacroInfo *MI = PP.getMacroInfo(II))
3624 return MI->isBuiltinMacro();
3625 return false;
3626}
3627
3628unsigned clang_Cursor_isFunctionInlined(CXCursor C) {
3629 const Decl *D = getCursorDecl(C);
3630 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
3631 if (!FD) {
3632 return false;
3633 }
3634 return FD->isInlined();
3635}
3636
3637static StringLiteral* getCFSTR_value(CallExpr *callExpr) {
3638 if (callExpr->getNumArgs() != 1) {
3639 return nullptr;
3640 }
3641
3642 StringLiteral *S = nullptr;
3643 auto *arg = callExpr->getArg(0);
3644 if (arg->getStmtClass() == Stmt::ImplicitCastExprClass) {
3645 ImplicitCastExpr *I = static_cast<ImplicitCastExpr *>(arg);
3646 auto *subExpr = I->getSubExprAsWritten();
3647
3648 if(subExpr->getStmtClass() != Stmt::StringLiteralClass){
3649 return nullptr;
3650 }
3651
3652 S = static_cast<StringLiteral *>(I->getSubExprAsWritten());
3653 } else if (arg->getStmtClass() == Stmt::StringLiteralClass) {
3654 S = static_cast<StringLiteral *>(callExpr->getArg(0));
3655 } else {
3656 return nullptr;
3657 }
3658 return S;
3659}
3660
3661struct ExprEvalResult {
3662 CXEvalResultKind EvalType;
3663 union {
3664 unsigned long long unsignedVal;
3665 long long intVal;
3666 double floatVal;
3667 char *stringVal;
3668 } EvalData;
3669 bool IsUnsignedInt;
3670 ~ExprEvalResult() {
3671 if (EvalType != CXEval_UnExposed && EvalType != CXEval_Float &&
3672 EvalType != CXEval_Int) {
3673 delete EvalData.stringVal;
3674 }
3675 }
3676};
3677
3678void clang_EvalResult_dispose(CXEvalResult E) {
3679 delete static_cast<ExprEvalResult *>(E);
3680}
3681
3682CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E) {
3683 if (!E) {
3684 return CXEval_UnExposed;
3685 }
3686 return ((ExprEvalResult *)E)->EvalType;
3687}
3688
3689int clang_EvalResult_getAsInt(CXEvalResult E) {
3690 return clang_EvalResult_getAsLongLong(E);
3691}
3692
3693long long clang_EvalResult_getAsLongLong(CXEvalResult E) {
3694 if (!E) {
3695 return 0;
3696 }
3697 ExprEvalResult *Result = (ExprEvalResult*)E;
3698 if (Result->IsUnsignedInt)
3699 return Result->EvalData.unsignedVal;
3700 return Result->EvalData.intVal;
3701}
3702
3703unsigned clang_EvalResult_isUnsignedInt(CXEvalResult E) {
3704 return ((ExprEvalResult *)E)->IsUnsignedInt;
3705}
3706
3707unsigned long long clang_EvalResult_getAsUnsigned(CXEvalResult E) {
3708 if (!E) {
3709 return 0;
3710 }
3711
3712 ExprEvalResult *Result = (ExprEvalResult*)E;
3713 if (Result->IsUnsignedInt)
3714 return Result->EvalData.unsignedVal;
3715 return Result->EvalData.intVal;
3716}
3717
3718double clang_EvalResult_getAsDouble(CXEvalResult E) {
3719 if (!E) {
3720 return 0;
3721 }
3722 return ((ExprEvalResult *)E)->EvalData.floatVal;
3723}
3724
3725const char* clang_EvalResult_getAsStr(CXEvalResult E) {
3726 if (!E) {
3727 return nullptr;
3728 }
3729 return ((ExprEvalResult *)E)->EvalData.stringVal;
3730}
3731
3732static const ExprEvalResult* evaluateExpr(Expr *expr, CXCursor C) {
3733 Expr::EvalResult ER;
3734 ASTContext &ctx = getCursorContext(C);
3735 if (!expr)
3736 return nullptr;
3737
3738 expr = expr->IgnoreParens();
3739 if (!expr->EvaluateAsRValue(ER, ctx))
3740 return nullptr;
3741
3742 QualType rettype;
3743 CallExpr *callExpr;
3744 auto result = llvm::make_unique<ExprEvalResult>();
3745 result->EvalType = CXEval_UnExposed;
3746 result->IsUnsignedInt = false;
3747
3748 if (ER.Val.isInt()) {
3749 result->EvalType = CXEval_Int;
3750
3751 auto& val = ER.Val.getInt();
3752 if (val.isUnsigned()) {
3753 result->IsUnsignedInt = true;
3754 result->EvalData.unsignedVal = val.getZExtValue();
3755 } else {
3756 result->EvalData.intVal = val.getExtValue();
3757 }
3758
3759 return result.release();
3760 }
3761
3762 if (ER.Val.isFloat()) {
3763 llvm::SmallVector<char, 100> Buffer;
3764 ER.Val.getFloat().toString(Buffer);
3765 std::string floatStr(Buffer.data(), Buffer.size());
3766 result->EvalType = CXEval_Float;
3767 bool ignored;
3768 llvm::APFloat apFloat = ER.Val.getFloat();
3769 apFloat.convert(llvm::APFloat::IEEEdouble(),
3770 llvm::APFloat::rmNearestTiesToEven, &ignored);
3771 result->EvalData.floatVal = apFloat.convertToDouble();
3772 return result.release();
3773 }
3774
3775 if (expr->getStmtClass() == Stmt::ImplicitCastExprClass) {
3776 const ImplicitCastExpr *I = dyn_cast<ImplicitCastExpr>(expr);
3777 auto *subExpr = I->getSubExprAsWritten();
3778 if (subExpr->getStmtClass() == Stmt::StringLiteralClass ||
3779 subExpr->getStmtClass() == Stmt::ObjCStringLiteralClass) {
3780 const StringLiteral *StrE = nullptr;
3781 const ObjCStringLiteral *ObjCExpr;
3782 ObjCExpr = dyn_cast<ObjCStringLiteral>(subExpr);
3783
3784 if (ObjCExpr) {
3785 StrE = ObjCExpr->getString();
3786 result->EvalType = CXEval_ObjCStrLiteral;
3787 } else {
3788 StrE = cast<StringLiteral>(I->getSubExprAsWritten());
3789 result->EvalType = CXEval_StrLiteral;
3790 }
3791
3792 std::string strRef(StrE->getString().str());
3793 result->EvalData.stringVal = new char[strRef.size() + 1];
3794 strncpy((char *)result->EvalData.stringVal, strRef.c_str(),
3795 strRef.size());
3796 result->EvalData.stringVal[strRef.size()] = '\0';
3797 return result.release();
3798 }
3799 } else if (expr->getStmtClass() == Stmt::ObjCStringLiteralClass ||
3800 expr->getStmtClass() == Stmt::StringLiteralClass) {
3801 const StringLiteral *StrE = nullptr;
3802 const ObjCStringLiteral *ObjCExpr;
3803 ObjCExpr = dyn_cast<ObjCStringLiteral>(expr);
3804
3805 if (ObjCExpr) {
3806 StrE = ObjCExpr->getString();
3807 result->EvalType = CXEval_ObjCStrLiteral;
3808 } else {
3809 StrE = cast<StringLiteral>(expr);
3810 result->EvalType = CXEval_StrLiteral;
3811 }
3812
3813 std::string strRef(StrE->getString().str());
3814 result->EvalData.stringVal = new char[strRef.size() + 1];
3815 strncpy((char *)result->EvalData.stringVal, strRef.c_str(), strRef.size());
3816 result->EvalData.stringVal[strRef.size()] = '\0';
3817 return result.release();
3818 }
3819
3820 if (expr->getStmtClass() == Stmt::CStyleCastExprClass) {
3821 CStyleCastExpr *CC = static_cast<CStyleCastExpr *>(expr);
3822
3823 rettype = CC->getType();
3824 if (rettype.getAsString() == "CFStringRef" &&
3825 CC->getSubExpr()->getStmtClass() == Stmt::CallExprClass) {
3826
3827 callExpr = static_cast<CallExpr *>(CC->getSubExpr());
3828 StringLiteral *S = getCFSTR_value(callExpr);
3829 if (S) {
3830 std::string strLiteral(S->getString().str());
3831 result->EvalType = CXEval_CFStr;
3832
3833 result->EvalData.stringVal = new char[strLiteral.size() + 1];
3834 strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(),
3835 strLiteral.size());
3836 result->EvalData.stringVal[strLiteral.size()] = '\0';
3837 return result.release();
3838 }
3839 }
3840
3841 } else if (expr->getStmtClass() == Stmt::CallExprClass) {
3842 callExpr = static_cast<CallExpr *>(expr);
3843 rettype = callExpr->getCallReturnType(ctx);
3844
3845 if (rettype->isVectorType() || callExpr->getNumArgs() > 1)
3846 return nullptr;
3847
3848 if (rettype->isIntegralType(ctx) || rettype->isRealFloatingType()) {
3849 if (callExpr->getNumArgs() == 1 &&
3850 !callExpr->getArg(0)->getType()->isIntegralType(ctx))
3851 return nullptr;
3852 } else if (rettype.getAsString() == "CFStringRef") {
3853
3854 StringLiteral *S = getCFSTR_value(callExpr);
3855 if (S) {
3856 std::string strLiteral(S->getString().str());
3857 result->EvalType = CXEval_CFStr;
3858 result->EvalData.stringVal = new char[strLiteral.size() + 1];
3859 strncpy((char *)result->EvalData.stringVal, strLiteral.c_str(),
3860 strLiteral.size());
3861 result->EvalData.stringVal[strLiteral.size()] = '\0';
3862 return result.release();
3863 }
3864 }
3865 } else if (expr->getStmtClass() == Stmt::DeclRefExprClass) {
3866 DeclRefExpr *D = static_cast<DeclRefExpr *>(expr);
3867 ValueDecl *V = D->getDecl();
3868 if (V->getKind() == Decl::Function) {
3869 std::string strName = V->getNameAsString();
3870 result->EvalType = CXEval_Other;
3871 result->EvalData.stringVal = new char[strName.size() + 1];
3872 strncpy(result->EvalData.stringVal, strName.c_str(), strName.size());
3873 result->EvalData.stringVal[strName.size()] = '\0';
3874 return result.release();
3875 }
3876 }
3877
3878 return nullptr;
3879}
3880
3881CXEvalResult clang_Cursor_Evaluate(CXCursor C) {
3882 const Decl *D = getCursorDecl(C);
3883 if (D) {
3884 const Expr *expr = nullptr;
3885 if (auto *Var = dyn_cast<VarDecl>(D)) {
3886 expr = Var->getInit();
3887 } else if (auto *Field = dyn_cast<FieldDecl>(D)) {
3888 expr = Field->getInClassInitializer();
3889 }
3890 if (expr)
3891 return const_cast<CXEvalResult>(reinterpret_cast<const void *>(
3892 evaluateExpr(const_cast<Expr *>(expr), C)));
3893 return nullptr;
3894 }
3895
3896 const CompoundStmt *compoundStmt = dyn_cast_or_null<CompoundStmt>(getCursorStmt(C));
3897 if (compoundStmt) {
3898 Expr *expr = nullptr;
3899 for (auto *bodyIterator : compoundStmt->body()) {
3900 if ((expr = dyn_cast<Expr>(bodyIterator))) {
3901 break;
3902 }
3903 }
3904 if (expr)
3905 return const_cast<CXEvalResult>(
3906 reinterpret_cast<const void *>(evaluateExpr(expr, C)));
3907 }
3908 return nullptr;
3909}
3910
3911unsigned clang_Cursor_hasAttrs(CXCursor C) {
3912 const Decl *D = getCursorDecl(C);
3913 if (!D) {
3914 return 0;
3915 }
3916
3917 if (D->hasAttrs()) {
3918 return 1;
3919 }
3920
3921 return 0;
3922}
3923unsigned clang_defaultSaveOptions(CXTranslationUnit TU) {
3924 return CXSaveTranslationUnit_None;
3925}
3926
3927static CXSaveError clang_saveTranslationUnit_Impl(CXTranslationUnit TU,
3928 const char *FileName,
3929 unsigned options) {
3930 CIndexer *CXXIdx = TU->CIdx;
3931 if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
3932 setThreadBackgroundPriority();
3933
3934 bool hadError = cxtu::getASTUnit(TU)->Save(FileName);
3935 return hadError ? CXSaveError_Unknown : CXSaveError_None;
3936}
3937
3938int clang_saveTranslationUnit(CXTranslationUnit TU, const char *FileName,
3939 unsigned options) {
3940 LOG_FUNC_SECTIONif (clang::cxindex::LogRef Log = clang::cxindex::Logger::make
(__func__))
{
3941 *Log << TU << ' ' << FileName;
3942 }
3943
3944 if (isNotUsableTU(TU)) {
3945 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
3946 return CXSaveError_InvalidTU;
3947 }
3948
3949 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
3950 ASTUnit::ConcurrencyCheck Check(*CXXUnit);
3951 if (!CXXUnit->hasSema())
3952 return CXSaveError_InvalidTU;
3953
3954 CXSaveError result;
3955 auto SaveTranslationUnitImpl = [=, &result]() {
3956 result = clang_saveTranslationUnit_Impl(TU, FileName, options);
3957 };
3958
3959 if (!CXXUnit->getDiagnostics().hasUnrecoverableErrorOccurred()) {
3960 SaveTranslationUnitImpl();
3961
3962 if (getenv("LIBCLANG_RESOURCE_USAGE"))
3963 PrintLibclangResourceUsage(TU);
3964
3965 return result;
3966 }
3967
3968 // We have an AST that has invalid nodes due to compiler errors.
3969 // Use a crash recovery thread for protection.
3970
3971 llvm::CrashRecoveryContext CRC;
3972
3973 if (!RunSafely(CRC, SaveTranslationUnitImpl)) {
3974 fprintf(stderrstderr, "libclang: crash detected during AST saving: {\n");
3975 fprintf(stderrstderr, " 'filename' : '%s'\n", FileName);
3976 fprintf(stderrstderr, " 'options' : %d,\n", options);
3977 fprintf(stderrstderr, "}\n");
3978
3979 return CXSaveError_Unknown;
3980
3981 } else if (getenv("LIBCLANG_RESOURCE_USAGE")) {
3982 PrintLibclangResourceUsage(TU);
3983 }
3984
3985 return result;
3986}
3987
3988void clang_disposeTranslationUnit(CXTranslationUnit CTUnit) {
3989 if (CTUnit) {
3990 // If the translation unit has been marked as unsafe to free, just discard
3991 // it.
3992 ASTUnit *Unit = cxtu::getASTUnit(CTUnit);
3993 if (Unit && Unit->isUnsafeToFree())
3994 return;
3995
3996 delete cxtu::getASTUnit(CTUnit);
3997 delete CTUnit->StringPool;
3998 delete static_cast<CXDiagnosticSetImpl *>(CTUnit->Diagnostics);
3999 disposeOverridenCXCursorsPool(CTUnit->OverridenCursorsPool);
4000 delete CTUnit->CommentToXML;
4001 delete CTUnit;
4002 }
4003}
4004
4005unsigned clang_suspendTranslationUnit(CXTranslationUnit CTUnit) {
4006 if (CTUnit) {
4007 ASTUnit *Unit = cxtu::getASTUnit(CTUnit);
4008
4009 if (Unit && Unit->isUnsafeToFree())
4010 return false;
4011
4012 Unit->ResetForParse();
4013 return true;
4014 }
4015
4016 return false;
4017}
4018
4019unsigned clang_defaultReparseOptions(CXTranslationUnit TU) {
4020 return CXReparse_None;
4021}
4022
4023static CXErrorCode
4024clang_reparseTranslationUnit_Impl(CXTranslationUnit TU,
4025 ArrayRef<CXUnsavedFile> unsaved_files,
4026 unsigned options) {
4027 // Check arguments.
4028 if (isNotUsableTU(TU)) {
4029 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
4030 return CXError_InvalidArguments;
4031 }
4032
4033 // Reset the associated diagnostics.
4034 delete static_cast<CXDiagnosticSetImpl*>(TU->Diagnostics);
4035 TU->Diagnostics = nullptr;
4036
4037 CIndexer *CXXIdx = TU->CIdx;
4038 if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing))
4039 setThreadBackgroundPriority();
4040
4041 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4042 ASTUnit::ConcurrencyCheck Check(*CXXUnit);
4043
4044 std::unique_ptr<std::vector<ASTUnit::RemappedFile>> RemappedFiles(
4045 new std::vector<ASTUnit::RemappedFile>());
4046
4047 // Recover resources if we crash before exiting this function.
4048 llvm::CrashRecoveryContextCleanupRegistrar<
4049 std::vector<ASTUnit::RemappedFile> > RemappedCleanup(RemappedFiles.get());
4050
4051 for (auto &UF : unsaved_files) {
4052 std::unique_ptr<llvm::MemoryBuffer> MB =
4053 llvm::MemoryBuffer::getMemBufferCopy(getContents(UF), UF.Filename);
4054 RemappedFiles->push_back(std::make_pair(UF.Filename, MB.release()));
4055 }
4056
4057 if (!CXXUnit->Reparse(CXXIdx->getPCHContainerOperations(),
4058 *RemappedFiles.get()))
4059 return CXError_Success;
4060 if (isASTReadError(CXXUnit))
4061 return CXError_ASTReadError;
4062 return CXError_Failure;
4063}
4064
4065int clang_reparseTranslationUnit(CXTranslationUnit TU,
4066 unsigned num_unsaved_files,
4067 struct CXUnsavedFile *unsaved_files,
4068 unsigned options) {
4069 LOG_FUNC_SECTIONif (clang::cxindex::LogRef Log = clang::cxindex::Logger::make
(__func__))
{
4070 *Log << TU;
4071 }
4072
4073 if (num_unsaved_files && !unsaved_files)
4074 return CXError_InvalidArguments;
4075
4076 CXErrorCode result;
4077 auto ReparseTranslationUnitImpl = [=, &result]() {
4078 result = clang_reparseTranslationUnit_Impl(
4079 TU, llvm::makeArrayRef(unsaved_files, num_unsaved_files), options);
4080 };
4081
4082 llvm::CrashRecoveryContext CRC;
4083
4084 if (!RunSafely(CRC, ReparseTranslationUnitImpl)) {
4085 fprintf(stderrstderr, "libclang: crash detected during reparsing\n");
4086 cxtu::getASTUnit(TU)->setUnsafeToFree(true);
4087 return CXError_Crashed;
4088 } else if (getenv("LIBCLANG_RESOURCE_USAGE"))
4089 PrintLibclangResourceUsage(TU);
4090
4091 return result;
4092}
4093
4094
4095CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) {
4096 if (isNotUsableTU(CTUnit)) {
4097 LOG_BAD_TU(CTUnit)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
CTUnit; } } while(false)
;
4098 return cxstring::createEmpty();
4099 }
4100
4101 ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
4102 return cxstring::createDup(CXXUnit->getOriginalSourceFileName());
4103}
4104
4105CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
4106 if (isNotUsableTU(TU)) {
4107 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
4108 return clang_getNullCursor();
4109 }
4110
4111 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4112 return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
4113}
4114
4115CXTargetInfo clang_getTranslationUnitTargetInfo(CXTranslationUnit CTUnit) {
4116 if (isNotUsableTU(CTUnit)) {
4117 LOG_BAD_TU(CTUnit)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
CTUnit; } } while(false)
;
4118 return nullptr;
4119 }
4120
4121 CXTargetInfoImpl* impl = new CXTargetInfoImpl();
4122 impl->TranslationUnit = CTUnit;
4123 return impl;
4124}
4125
4126CXString clang_TargetInfo_getTriple(CXTargetInfo TargetInfo) {
4127 if (!TargetInfo)
4128 return cxstring::createEmpty();
4129
4130 CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
4131 assert(!isNotUsableTU(CTUnit) &&(static_cast <bool> (!isNotUsableTU(CTUnit) && "Unexpected unusable translation unit in TargetInfo"
) ? void (0) : __assert_fail ("!isNotUsableTU(CTUnit) && \"Unexpected unusable translation unit in TargetInfo\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4132, __extension__ __PRETTY_FUNCTION__))
4132 "Unexpected unusable translation unit in TargetInfo")(static_cast <bool> (!isNotUsableTU(CTUnit) && "Unexpected unusable translation unit in TargetInfo"
) ? void (0) : __assert_fail ("!isNotUsableTU(CTUnit) && \"Unexpected unusable translation unit in TargetInfo\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4132, __extension__ __PRETTY_FUNCTION__))
;
4133
4134 ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
4135 std::string Triple =
4136 CXXUnit->getASTContext().getTargetInfo().getTriple().normalize();
4137 return cxstring::createDup(Triple);
4138}
4139
4140int clang_TargetInfo_getPointerWidth(CXTargetInfo TargetInfo) {
4141 if (!TargetInfo)
4142 return -1;
4143
4144 CXTranslationUnit CTUnit = TargetInfo->TranslationUnit;
4145 assert(!isNotUsableTU(CTUnit) &&(static_cast <bool> (!isNotUsableTU(CTUnit) && "Unexpected unusable translation unit in TargetInfo"
) ? void (0) : __assert_fail ("!isNotUsableTU(CTUnit) && \"Unexpected unusable translation unit in TargetInfo\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4146, __extension__ __PRETTY_FUNCTION__))
4146 "Unexpected unusable translation unit in TargetInfo")(static_cast <bool> (!isNotUsableTU(CTUnit) && "Unexpected unusable translation unit in TargetInfo"
) ? void (0) : __assert_fail ("!isNotUsableTU(CTUnit) && \"Unexpected unusable translation unit in TargetInfo\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4146, __extension__ __PRETTY_FUNCTION__))
;
4147
4148 ASTUnit *CXXUnit = cxtu::getASTUnit(CTUnit);
4149 return CXXUnit->getASTContext().getTargetInfo().getMaxPointerWidth();
4150}
4151
4152void clang_TargetInfo_dispose(CXTargetInfo TargetInfo) {
4153 if (!TargetInfo)
4154 return;
4155
4156 delete TargetInfo;
4157}
4158
4159//===----------------------------------------------------------------------===//
4160// CXFile Operations.
4161//===----------------------------------------------------------------------===//
4162
4163CXString clang_getFileName(CXFile SFile) {
4164 if (!SFile)
4165 return cxstring::createNull();
4166
4167 FileEntry *FEnt = static_cast<FileEntry *>(SFile);
4168 return cxstring::createRef(FEnt->getName());
4169}
4170
4171time_t clang_getFileTime(CXFile SFile) {
4172 if (!SFile)
4173 return 0;
4174
4175 FileEntry *FEnt = static_cast<FileEntry *>(SFile);
4176 return FEnt->getModificationTime();
4177}
4178
4179CXFile clang_getFile(CXTranslationUnit TU, const char *file_name) {
4180 if (isNotUsableTU(TU)) {
4181 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
4182 return nullptr;
4183 }
4184
4185 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4186
4187 FileManager &FMgr = CXXUnit->getFileManager();
4188 return const_cast<FileEntry *>(FMgr.getFile(file_name));
4189}
4190
4191const char *clang_getFileContents(CXTranslationUnit TU, CXFile file,
4192 size_t *size) {
4193 if (isNotUsableTU(TU)) {
4194 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
4195 return nullptr;
4196 }
4197
4198 const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager();
4199 FileID fid = SM.translateFile(static_cast<FileEntry *>(file));
4200 bool Invalid = true;
4201 llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid);
4202 if (Invalid) {
4203 if (size)
4204 *size = 0;
4205 return nullptr;
4206 }
4207 if (size)
4208 *size = buf->getBufferSize();
4209 return buf->getBufferStart();
4210}
4211
4212unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit TU,
4213 CXFile file) {
4214 if (isNotUsableTU(TU)) {
4215 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
4216 return 0;
4217 }
4218
4219 if (!file)
4220 return 0;
4221
4222 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
4223 FileEntry *FEnt = static_cast<FileEntry *>(file);
4224 return CXXUnit->getPreprocessor().getHeaderSearchInfo()
4225 .isFileMultipleIncludeGuarded(FEnt);
4226}
4227
4228int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID) {
4229 if (!file || !outID)
4230 return 1;
4231
4232 FileEntry *FEnt = static_cast<FileEntry *>(file);
4233 const llvm::sys::fs::UniqueID &ID = FEnt->getUniqueID();
4234 outID->data[0] = ID.getDevice();
4235 outID->data[1] = ID.getFile();
4236 outID->data[2] = FEnt->getModificationTime();
4237 return 0;
4238}
4239
4240int clang_File_isEqual(CXFile file1, CXFile file2) {
4241 if (file1 == file2)
4242 return true;
4243
4244 if (!file1 || !file2)
4245 return false;
4246
4247 FileEntry *FEnt1 = static_cast<FileEntry *>(file1);
4248 FileEntry *FEnt2 = static_cast<FileEntry *>(file2);
4249 return FEnt1->getUniqueID() == FEnt2->getUniqueID();
4250}
4251
4252//===----------------------------------------------------------------------===//
4253// CXCursor Operations.
4254//===----------------------------------------------------------------------===//
4255
4256static const Decl *getDeclFromExpr(const Stmt *E) {
4257 if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
4258 return getDeclFromExpr(CE->getSubExpr());
4259
4260 if (const DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E))
4261 return RefExpr->getDecl();
4262 if (const MemberExpr *ME = dyn_cast<MemberExpr>(E))
4263 return ME->getMemberDecl();
4264 if (const ObjCIvarRefExpr *RE = dyn_cast<ObjCIvarRefExpr>(E))
4265 return RE->getDecl();
4266 if (const ObjCPropertyRefExpr *PRE = dyn_cast<ObjCPropertyRefExpr>(E)) {
4267 if (PRE->isExplicitProperty())
4268 return PRE->getExplicitProperty();
4269 // It could be messaging both getter and setter as in:
4270 // ++myobj.myprop;
4271 // in which case prefer to associate the setter since it is less obvious
4272 // from inspecting the source that the setter is going to get called.
4273 if (PRE->isMessagingSetter())
4274 return PRE->getImplicitPropertySetter();
4275 return PRE->getImplicitPropertyGetter();
4276 }
4277 if (const PseudoObjectExpr *POE = dyn_cast<PseudoObjectExpr>(E))
4278 return getDeclFromExpr(POE->getSyntacticForm());
4279 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(E))
4280 if (Expr *Src = OVE->getSourceExpr())
4281 return getDeclFromExpr(Src);
4282
4283 if (const CallExpr *CE = dyn_cast<CallExpr>(E))
4284 return getDeclFromExpr(CE->getCallee());
4285 if (const CXXConstructExpr *CE = dyn_cast<CXXConstructExpr>(E))
4286 if (!CE->isElidable())
4287 return CE->getConstructor();
4288 if (const CXXInheritedCtorInitExpr *CE =
4289 dyn_cast<CXXInheritedCtorInitExpr>(E))
4290 return CE->getConstructor();
4291 if (const ObjCMessageExpr *OME = dyn_cast<ObjCMessageExpr>(E))
4292 return OME->getMethodDecl();
4293
4294 if (const ObjCProtocolExpr *PE = dyn_cast<ObjCProtocolExpr>(E))
4295 return PE->getProtocol();
4296 if (const SubstNonTypeTemplateParmPackExpr *NTTP
4297 = dyn_cast<SubstNonTypeTemplateParmPackExpr>(E))
4298 return NTTP->getParameterPack();
4299 if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E))
4300 if (isa<NonTypeTemplateParmDecl>(SizeOfPack->getPack()) ||
4301 isa<ParmVarDecl>(SizeOfPack->getPack()))
4302 return SizeOfPack->getPack();
4303
4304 return nullptr;
4305}
4306
4307static SourceLocation getLocationFromExpr(const Expr *E) {
4308 if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
4309 return getLocationFromExpr(CE->getSubExpr());
4310
4311 if (const ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
4312 return /*FIXME:*/Msg->getLeftLoc();
4313 if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
4314 return DRE->getLocation();
4315 if (const MemberExpr *Member = dyn_cast<MemberExpr>(E))
4316 return Member->getMemberLoc();
4317 if (const ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
4318 return Ivar->getLocation();
4319 if (const SizeOfPackExpr *SizeOfPack = dyn_cast<SizeOfPackExpr>(E))
4320 return SizeOfPack->getPackLoc();
4321 if (const ObjCPropertyRefExpr *PropRef = dyn_cast<ObjCPropertyRefExpr>(E))
4322 return PropRef->getLocation();
4323
4324 return E->getLocStart();
4325}
4326
4327extern "C" {
4328
4329unsigned clang_visitChildren(CXCursor parent,
4330 CXCursorVisitor visitor,
4331 CXClientData client_data) {
4332 CursorVisitor CursorVis(getCursorTU(parent), visitor, client_data,
4333 /*VisitPreprocessorLast=*/false);
4334 return CursorVis.VisitChildren(parent);
4335}
4336
4337#ifndef __has_feature
4338#define0 __has_feature(x)0 0
4339#endif
4340#if __has_feature(blocks)0
4341typedef enum CXChildVisitResult
4342 (^CXCursorVisitorBlock)(CXCursor cursor, CXCursor parent);
4343
4344static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent,
4345 CXClientData client_data) {
4346 CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data;
4347 return block(cursor, parent);
4348}
4349#else
4350// If we are compiled with a compiler that doesn't have native blocks support,
4351// define and call the block manually, so the
4352typedef struct _CXChildVisitResult
4353{
4354 void *isa;
4355 int flags;
4356 int reserved;
4357 enum CXChildVisitResult(*invoke)(struct _CXChildVisitResult*, CXCursor,
4358 CXCursor);
4359} *CXCursorVisitorBlock;
4360
4361static enum CXChildVisitResult visitWithBlock(CXCursor cursor, CXCursor parent,
4362 CXClientData client_data) {
4363 CXCursorVisitorBlock block = (CXCursorVisitorBlock)client_data;
4364 return block->invoke(block, cursor, parent);
4365}
4366#endif
4367
4368
4369unsigned clang_visitChildrenWithBlock(CXCursor parent,
4370 CXCursorVisitorBlock block) {
4371 return clang_visitChildren(parent, visitWithBlock, block);
4372}
4373
4374static CXString getDeclSpelling(const Decl *D) {
4375 if (!D)
4376 return cxstring::createEmpty();
4377
4378 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
4379 if (!ND) {
4380 if (const ObjCPropertyImplDecl *PropImpl =
4381 dyn_cast<ObjCPropertyImplDecl>(D))
4382 if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl())
4383 return cxstring::createDup(Property->getIdentifier()->getName());
4384
4385 if (const ImportDecl *ImportD = dyn_cast<ImportDecl>(D))
4386 if (Module *Mod = ImportD->getImportedModule())
4387 return cxstring::createDup(Mod->getFullModuleName());
4388
4389 return cxstring::createEmpty();
4390 }
4391
4392 if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND))
4393 return cxstring::createDup(OMD->getSelector().getAsString());
4394
4395 if (const ObjCCategoryImplDecl *CIMP = dyn_cast<ObjCCategoryImplDecl>(ND))
4396 // No, this isn't the same as the code below. getIdentifier() is non-virtual
4397 // and returns different names. NamedDecl returns the class name and
4398 // ObjCCategoryImplDecl returns the category name.
4399 return cxstring::createRef(CIMP->getIdentifier()->getNameStart());
4400
4401 if (isa<UsingDirectiveDecl>(D))
4402 return cxstring::createEmpty();
4403
4404 SmallString<1024> S;
4405 llvm::raw_svector_ostream os(S);
4406 ND->printName(os);
4407
4408 return cxstring::createDup(os.str());
4409}
4410
4411CXString clang_getCursorSpelling(CXCursor C) {
4412 if (clang_isTranslationUnit(C.kind))
4413 return clang_getTranslationUnitSpelling(getCursorTU(C));
4414
4415 if (clang_isReference(C.kind)) {
4416 switch (C.kind) {
4417 case CXCursor_ObjCSuperClassRef: {
4418 const ObjCInterfaceDecl *Super = getCursorObjCSuperClassRef(C).first;
4419 return cxstring::createRef(Super->getIdentifier()->getNameStart());
4420 }
4421 case CXCursor_ObjCClassRef: {
4422 const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
4423 return cxstring::createRef(Class->getIdentifier()->getNameStart());
4424 }
4425 case CXCursor_ObjCProtocolRef: {
4426 const ObjCProtocolDecl *OID = getCursorObjCProtocolRef(C).first;
4427 assert(OID && "getCursorSpelling(): Missing protocol decl")(static_cast <bool> (OID && "getCursorSpelling(): Missing protocol decl"
) ? void (0) : __assert_fail ("OID && \"getCursorSpelling(): Missing protocol decl\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4427, __extension__ __PRETTY_FUNCTION__))
;
4428 return cxstring::createRef(OID->getIdentifier()->getNameStart());
4429 }
4430 case CXCursor_CXXBaseSpecifier: {
4431 const CXXBaseSpecifier *B = getCursorCXXBaseSpecifier(C);
4432 return cxstring::createDup(B->getType().getAsString());
4433 }
4434 case CXCursor_TypeRef: {
4435 const TypeDecl *Type = getCursorTypeRef(C).first;
4436 assert(Type && "Missing type decl")(static_cast <bool> (Type && "Missing type decl"
) ? void (0) : __assert_fail ("Type && \"Missing type decl\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4436, __extension__ __PRETTY_FUNCTION__))
;
4437
4438 return cxstring::createDup(getCursorContext(C).getTypeDeclType(Type).
4439 getAsString());
4440 }
4441 case CXCursor_TemplateRef: {
4442 const TemplateDecl *Template = getCursorTemplateRef(C).first;
4443 assert(Template && "Missing template decl")(static_cast <bool> (Template && "Missing template decl"
) ? void (0) : __assert_fail ("Template && \"Missing template decl\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4443, __extension__ __PRETTY_FUNCTION__))
;
4444
4445 return cxstring::createDup(Template->getNameAsString());
4446 }
4447
4448 case CXCursor_NamespaceRef: {
4449 const NamedDecl *NS = getCursorNamespaceRef(C).first;
4450 assert(NS && "Missing namespace decl")(static_cast <bool> (NS && "Missing namespace decl"
) ? void (0) : __assert_fail ("NS && \"Missing namespace decl\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4450, __extension__ __PRETTY_FUNCTION__))
;
4451
4452 return cxstring::createDup(NS->getNameAsString());
4453 }
4454
4455 case CXCursor_MemberRef: {
4456 const FieldDecl *Field = getCursorMemberRef(C).first;
4457 assert(Field && "Missing member decl")(static_cast <bool> (Field && "Missing member decl"
) ? void (0) : __assert_fail ("Field && \"Missing member decl\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4457, __extension__ __PRETTY_FUNCTION__))
;
4458
4459 return cxstring::createDup(Field->getNameAsString());
4460 }
4461
4462 case CXCursor_LabelRef: {
4463 const LabelStmt *Label = getCursorLabelRef(C).first;
4464 assert(Label && "Missing label")(static_cast <bool> (Label && "Missing label") ?
void (0) : __assert_fail ("Label && \"Missing label\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4464, __extension__ __PRETTY_FUNCTION__))
;
4465
4466 return cxstring::createRef(Label->getName());
4467 }
4468
4469 case CXCursor_OverloadedDeclRef: {
4470 OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first;
4471 if (const Decl *D = Storage.dyn_cast<const Decl *>()) {
4472 if (const NamedDecl *ND = dyn_cast<NamedDecl>(D))
4473 return cxstring::createDup(ND->getNameAsString());
4474 return cxstring::createEmpty();
4475 }
4476 if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
4477 return cxstring::createDup(E->getName().getAsString());
4478 OverloadedTemplateStorage *Ovl
4479 = Storage.get<OverloadedTemplateStorage*>();
4480 if (Ovl->size() == 0)
4481 return cxstring::createEmpty();
4482 return cxstring::createDup((*Ovl->begin())->getNameAsString());
4483 }
4484
4485 case CXCursor_VariableRef: {
4486 const VarDecl *Var = getCursorVariableRef(C).first;
4487 assert(Var && "Missing variable decl")(static_cast <bool> (Var && "Missing variable decl"
) ? void (0) : __assert_fail ("Var && \"Missing variable decl\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4487, __extension__ __PRETTY_FUNCTION__))
;
4488
4489 return cxstring::createDup(Var->getNameAsString());
4490 }
4491
4492 default:
4493 return cxstring::createRef("<not implemented>");
4494 }
4495 }
4496
4497 if (clang_isExpression(C.kind)) {
4498 const Expr *E = getCursorExpr(C);
4499
4500 if (C.kind == CXCursor_ObjCStringLiteral ||
4501 C.kind == CXCursor_StringLiteral) {
4502 const StringLiteral *SLit;
4503 if (const ObjCStringLiteral *OSL = dyn_cast<ObjCStringLiteral>(E)) {
4504 SLit = OSL->getString();
4505 } else {
4506 SLit = cast<StringLiteral>(E);
4507 }
4508 SmallString<256> Buf;
4509 llvm::raw_svector_ostream OS(Buf);
4510 SLit->outputString(OS);
4511 return cxstring::createDup(OS.str());
4512 }
4513
4514 const Decl *D = getDeclFromExpr(getCursorExpr(C));
4515 if (D)
4516 return getDeclSpelling(D);
4517 return cxstring::createEmpty();
4518 }
4519
4520 if (clang_isStatement(C.kind)) {
4521 const Stmt *S = getCursorStmt(C);
4522 if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S))
4523 return cxstring::createRef(Label->getName());
4524
4525 return cxstring::createEmpty();
4526 }
4527
4528 if (C.kind == CXCursor_MacroExpansion)
4529 return cxstring::createRef(getCursorMacroExpansion(C).getName()
4530 ->getNameStart());
4531
4532 if (C.kind == CXCursor_MacroDefinition)
4533 return cxstring::createRef(getCursorMacroDefinition(C)->getName()
4534 ->getNameStart());
4535
4536 if (C.kind == CXCursor_InclusionDirective)
4537 return cxstring::createDup(getCursorInclusionDirective(C)->getFileName());
4538
4539 if (clang_isDeclaration(C.kind))
4540 return getDeclSpelling(getCursorDecl(C));
4541
4542 if (C.kind == CXCursor_AnnotateAttr) {
4543 const AnnotateAttr *AA = cast<AnnotateAttr>(cxcursor::getCursorAttr(C));
4544 return cxstring::createDup(AA->getAnnotation());
4545 }
4546
4547 if (C.kind == CXCursor_AsmLabelAttr) {
4548 const AsmLabelAttr *AA = cast<AsmLabelAttr>(cxcursor::getCursorAttr(C));
4549 return cxstring::createDup(AA->getLabel());
4550 }
4551
4552 if (C.kind == CXCursor_PackedAttr) {
4553 return cxstring::createRef("packed");
4554 }
4555
4556 if (C.kind == CXCursor_VisibilityAttr) {
4557 const VisibilityAttr *AA = cast<VisibilityAttr>(cxcursor::getCursorAttr(C));
4558 switch (AA->getVisibility()) {
4559 case VisibilityAttr::VisibilityType::Default:
4560 return cxstring::createRef("default");
4561 case VisibilityAttr::VisibilityType::Hidden:
4562 return cxstring::createRef("hidden");
4563 case VisibilityAttr::VisibilityType::Protected:
4564 return cxstring::createRef("protected");
4565 }
4566 llvm_unreachable("unknown visibility type")::llvm::llvm_unreachable_internal("unknown visibility type", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4566)
;
4567 }
4568
4569 return cxstring::createEmpty();
4570}
4571
4572CXSourceRange clang_Cursor_getSpellingNameRange(CXCursor C,
4573 unsigned pieceIndex,
4574 unsigned options) {
4575 if (clang_Cursor_isNull(C))
4576 return clang_getNullRange();
4577
4578 ASTContext &Ctx = getCursorContext(C);
4579
4580 if (clang_isStatement(C.kind)) {
4581 const Stmt *S = getCursorStmt(C);
4582 if (const LabelStmt *Label = dyn_cast_or_null<LabelStmt>(S)) {
4583 if (pieceIndex > 0)
4584 return clang_getNullRange();
4585 return cxloc::translateSourceRange(Ctx, Label->getIdentLoc());
4586 }
4587
4588 return clang_getNullRange();
4589 }
4590
4591 if (C.kind == CXCursor_ObjCMessageExpr) {
4592 if (const ObjCMessageExpr *
4593 ME = dyn_cast_or_null<ObjCMessageExpr>(getCursorExpr(C))) {
4594 if (pieceIndex >= ME->getNumSelectorLocs())
4595 return clang_getNullRange();
4596 return cxloc::translateSourceRange(Ctx, ME->getSelectorLoc(pieceIndex));
4597 }
4598 }
4599
4600 if (C.kind == CXCursor_ObjCInstanceMethodDecl ||
4601 C.kind == CXCursor_ObjCClassMethodDecl) {
4602 if (const ObjCMethodDecl *
4603 MD = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(C))) {
4604 if (pieceIndex >= MD->getNumSelectorLocs())
4605 return clang_getNullRange();
4606 return cxloc::translateSourceRange(Ctx, MD->getSelectorLoc(pieceIndex));
4607 }
4608 }
4609
4610 if (C.kind == CXCursor_ObjCCategoryDecl ||
4611 C.kind == CXCursor_ObjCCategoryImplDecl) {
4612 if (pieceIndex > 0)
4613 return clang_getNullRange();
4614 if (const ObjCCategoryDecl *
4615 CD = dyn_cast_or_null<ObjCCategoryDecl>(getCursorDecl(C)))
4616 return cxloc::translateSourceRange(Ctx, CD->getCategoryNameLoc());
4617 if (const ObjCCategoryImplDecl *
4618 CID = dyn_cast_or_null<ObjCCategoryImplDecl>(getCursorDecl(C)))
4619 return cxloc::translateSourceRange(Ctx, CID->getCategoryNameLoc());
4620 }
4621
4622 if (C.kind == CXCursor_ModuleImportDecl) {
4623 if (pieceIndex > 0)
4624 return clang_getNullRange();
4625 if (const ImportDecl *ImportD =
4626 dyn_cast_or_null<ImportDecl>(getCursorDecl(C))) {
4627 ArrayRef<SourceLocation> Locs = ImportD->getIdentifierLocs();
4628 if (!Locs.empty())
4629 return cxloc::translateSourceRange(Ctx,
4630 SourceRange(Locs.front(), Locs.back()));
4631 }
4632 return clang_getNullRange();
4633 }
4634
4635 if (C.kind == CXCursor_CXXMethod || C.kind == CXCursor_Destructor ||
4636 C.kind == CXCursor_ConversionFunction ||
4637 C.kind == CXCursor_FunctionDecl) {
4638 if (pieceIndex > 0)
4639 return clang_getNullRange();
4640 if (const FunctionDecl *FD =
4641 dyn_cast_or_null<FunctionDecl>(getCursorDecl(C))) {
4642 DeclarationNameInfo FunctionName = FD->getNameInfo();
4643 return cxloc::translateSourceRange(Ctx, FunctionName.getSourceRange());
4644 }
4645 return clang_getNullRange();
4646 }
4647
4648 // FIXME: A CXCursor_InclusionDirective should give the location of the
4649 // filename, but we don't keep track of this.
4650
4651 // FIXME: A CXCursor_AnnotateAttr should give the location of the annotation
4652 // but we don't keep track of this.
4653
4654 // FIXME: A CXCursor_AsmLabelAttr should give the location of the label
4655 // but we don't keep track of this.
4656
4657 // Default handling, give the location of the cursor.
4658
4659 if (pieceIndex > 0)
4660 return clang_getNullRange();
4661
4662 CXSourceLocation CXLoc = clang_getCursorLocation(C);
4663 SourceLocation Loc = cxloc::translateSourceLocation(CXLoc);
4664 return cxloc::translateSourceRange(Ctx, Loc);
4665}
4666
4667CXString clang_Cursor_getMangling(CXCursor C) {
4668 if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
4669 return cxstring::createEmpty();
4670
4671 // Mangling only works for functions and variables.
4672 const Decl *D = getCursorDecl(C);
4673 if (!D || !(isa<FunctionDecl>(D) || isa<VarDecl>(D)))
4674 return cxstring::createEmpty();
4675
4676 ASTContext &Ctx = D->getASTContext();
4677 index::CodegenNameGenerator CGNameGen(Ctx);
4678 return cxstring::createDup(CGNameGen.getName(D));
4679}
4680
4681CXStringSet *clang_Cursor_getCXXManglings(CXCursor C) {
4682 if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
4683 return nullptr;
4684
4685 const Decl *D = getCursorDecl(C);
4686 if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D)))
4687 return nullptr;
4688
4689 ASTContext &Ctx = D->getASTContext();
4690 index::CodegenNameGenerator CGNameGen(Ctx);
4691 std::vector<std::string> Manglings = CGNameGen.getAllManglings(D);
4692 return cxstring::createSet(Manglings);
4693}
4694
4695CXStringSet *clang_Cursor_getObjCManglings(CXCursor C) {
4696 if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
4697 return nullptr;
4698
4699 const Decl *D = getCursorDecl(C);
4700 if (!(isa<ObjCInterfaceDecl>(D) || isa<ObjCImplementationDecl>(D)))
4701 return nullptr;
4702
4703 ASTContext &Ctx = D->getASTContext();
4704 index::CodegenNameGenerator CGNameGen(Ctx);
4705 std::vector<std::string> Manglings = CGNameGen.getAllManglings(D);
4706 return cxstring::createSet(Manglings);
4707}
4708
4709CXPrintingPolicy clang_getCursorPrintingPolicy(CXCursor C) {
4710 if (clang_Cursor_isNull(C))
4711 return 0;
4712 return new PrintingPolicy(getCursorContext(C).getPrintingPolicy());
4713}
4714
4715void clang_PrintingPolicy_dispose(CXPrintingPolicy Policy) {
4716 if (Policy)
4717 delete static_cast<PrintingPolicy *>(Policy);
4718}
4719
4720unsigned
4721clang_PrintingPolicy_getProperty(CXPrintingPolicy Policy,
4722 enum CXPrintingPolicyProperty Property) {
4723 if (!Policy)
4724 return 0;
4725
4726 PrintingPolicy *P = static_cast<PrintingPolicy *>(Policy);
4727 switch (Property) {
4728 case CXPrintingPolicy_Indentation:
4729 return P->Indentation;
4730 case CXPrintingPolicy_SuppressSpecifiers:
4731 return P->SuppressSpecifiers;
4732 case CXPrintingPolicy_SuppressTagKeyword:
4733 return P->SuppressTagKeyword;
4734 case CXPrintingPolicy_IncludeTagDefinition:
4735 return P->IncludeTagDefinition;
4736 case CXPrintingPolicy_SuppressScope:
4737 return P->SuppressScope;
4738 case CXPrintingPolicy_SuppressUnwrittenScope:
4739 return P->SuppressUnwrittenScope;
4740 case CXPrintingPolicy_SuppressInitializers:
4741 return P->SuppressInitializers;
4742 case CXPrintingPolicy_ConstantArraySizeAsWritten:
4743 return P->ConstantArraySizeAsWritten;
4744 case CXPrintingPolicy_AnonymousTagLocations:
4745 return P->AnonymousTagLocations;
4746 case CXPrintingPolicy_SuppressStrongLifetime:
4747 return P->SuppressStrongLifetime;
4748 case CXPrintingPolicy_SuppressLifetimeQualifiers:
4749 return P->SuppressLifetimeQualifiers;
4750 case CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors:
4751 return P->SuppressTemplateArgsInCXXConstructors;
4752 case CXPrintingPolicy_Bool:
4753 return P->Bool;
4754 case CXPrintingPolicy_Restrict:
4755 return P->Restrict;
4756 case CXPrintingPolicy_Alignof:
4757 return P->Alignof;
4758 case CXPrintingPolicy_UnderscoreAlignof:
4759 return P->UnderscoreAlignof;
4760 case CXPrintingPolicy_UseVoidForZeroParams:
4761 return P->UseVoidForZeroParams;
4762 case CXPrintingPolicy_TerseOutput:
4763 return P->TerseOutput;
4764 case CXPrintingPolicy_PolishForDeclaration:
4765 return P->PolishForDeclaration;
4766 case CXPrintingPolicy_Half:
4767 return P->Half;
4768 case CXPrintingPolicy_MSWChar:
4769 return P->MSWChar;
4770 case CXPrintingPolicy_IncludeNewlines:
4771 return P->IncludeNewlines;
4772 case CXPrintingPolicy_MSVCFormatting:
4773 return P->MSVCFormatting;
4774 case CXPrintingPolicy_ConstantsAsWritten:
4775 return P->ConstantsAsWritten;
4776 case CXPrintingPolicy_SuppressImplicitBase:
4777 return P->SuppressImplicitBase;
4778 case CXPrintingPolicy_FullyQualifiedName:
4779 return P->FullyQualifiedName;
4780 }
4781
4782 assert(false && "Invalid CXPrintingPolicyProperty")(static_cast <bool> (false && "Invalid CXPrintingPolicyProperty"
) ? void (0) : __assert_fail ("false && \"Invalid CXPrintingPolicyProperty\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4782, __extension__ __PRETTY_FUNCTION__))
;
4783 return 0;
4784}
4785
4786void clang_PrintingPolicy_setProperty(CXPrintingPolicy Policy,
4787 enum CXPrintingPolicyProperty Property,
4788 unsigned Value) {
4789 if (!Policy)
4790 return;
4791
4792 PrintingPolicy *P = static_cast<PrintingPolicy *>(Policy);
4793 switch (Property) {
4794 case CXPrintingPolicy_Indentation:
4795 P->Indentation = Value;
4796 return;
4797 case CXPrintingPolicy_SuppressSpecifiers:
4798 P->SuppressSpecifiers = Value;
4799 return;
4800 case CXPrintingPolicy_SuppressTagKeyword:
4801 P->SuppressTagKeyword = Value;
4802 return;
4803 case CXPrintingPolicy_IncludeTagDefinition:
4804 P->IncludeTagDefinition = Value;
4805 return;
4806 case CXPrintingPolicy_SuppressScope:
4807 P->SuppressScope = Value;
4808 return;
4809 case CXPrintingPolicy_SuppressUnwrittenScope:
4810 P->SuppressUnwrittenScope = Value;
4811 return;
4812 case CXPrintingPolicy_SuppressInitializers:
4813 P->SuppressInitializers = Value;
4814 return;
4815 case CXPrintingPolicy_ConstantArraySizeAsWritten:
4816 P->ConstantArraySizeAsWritten = Value;
4817 return;
4818 case CXPrintingPolicy_AnonymousTagLocations:
4819 P->AnonymousTagLocations = Value;
4820 return;
4821 case CXPrintingPolicy_SuppressStrongLifetime:
4822 P->SuppressStrongLifetime = Value;
4823 return;
4824 case CXPrintingPolicy_SuppressLifetimeQualifiers:
4825 P->SuppressLifetimeQualifiers = Value;
4826 return;
4827 case CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors:
4828 P->SuppressTemplateArgsInCXXConstructors = Value;
4829 return;
4830 case CXPrintingPolicy_Bool:
4831 P->Bool = Value;
4832 return;
4833 case CXPrintingPolicy_Restrict:
4834 P->Restrict = Value;
4835 return;
4836 case CXPrintingPolicy_Alignof:
4837 P->Alignof = Value;
4838 return;
4839 case CXPrintingPolicy_UnderscoreAlignof:
4840 P->UnderscoreAlignof = Value;
4841 return;
4842 case CXPrintingPolicy_UseVoidForZeroParams:
4843 P->UseVoidForZeroParams = Value;
4844 return;
4845 case CXPrintingPolicy_TerseOutput:
4846 P->TerseOutput = Value;
4847 return;
4848 case CXPrintingPolicy_PolishForDeclaration:
4849 P->PolishForDeclaration = Value;
4850 return;
4851 case CXPrintingPolicy_Half:
4852 P->Half = Value;
4853 return;
4854 case CXPrintingPolicy_MSWChar:
4855 P->MSWChar = Value;
4856 return;
4857 case CXPrintingPolicy_IncludeNewlines:
4858 P->IncludeNewlines = Value;
4859 return;
4860 case CXPrintingPolicy_MSVCFormatting:
4861 P->MSVCFormatting = Value;
4862 return;
4863 case CXPrintingPolicy_ConstantsAsWritten:
4864 P->ConstantsAsWritten = Value;
4865 return;
4866 case CXPrintingPolicy_SuppressImplicitBase:
4867 P->SuppressImplicitBase = Value;
4868 return;
4869 case CXPrintingPolicy_FullyQualifiedName:
4870 P->FullyQualifiedName = Value;
4871 return;
4872 }
4873
4874 assert(false && "Invalid CXPrintingPolicyProperty")(static_cast <bool> (false && "Invalid CXPrintingPolicyProperty"
) ? void (0) : __assert_fail ("false && \"Invalid CXPrintingPolicyProperty\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 4874, __extension__ __PRETTY_FUNCTION__))
;
4875}
4876
4877CXString clang_getCursorPrettyPrinted(CXCursor C, CXPrintingPolicy cxPolicy) {
4878 if (clang_Cursor_isNull(C))
4879 return cxstring::createEmpty();
4880
4881 if (clang_isDeclaration(C.kind)) {
4882 const Decl *D = getCursorDecl(C);
4883 if (!D)
4884 return cxstring::createEmpty();
4885
4886 SmallString<128> Str;
4887 llvm::raw_svector_ostream OS(Str);
4888 PrintingPolicy *UserPolicy = static_cast<PrintingPolicy *>(cxPolicy);
4889 D->print(OS, UserPolicy ? *UserPolicy
4890 : getCursorContext(C).getPrintingPolicy());
4891
4892 return cxstring::createDup(OS.str());
4893 }
4894
4895 return cxstring::createEmpty();
4896}
4897
4898CXString clang_getCursorDisplayName(CXCursor C) {
4899 if (!clang_isDeclaration(C.kind))
4900 return clang_getCursorSpelling(C);
4901
4902 const Decl *D = getCursorDecl(C);
4903 if (!D)
4904 return cxstring::createEmpty();
4905
4906 PrintingPolicy Policy = getCursorContext(C).getPrintingPolicy();
4907 if (const FunctionTemplateDecl *FunTmpl = dyn_cast<FunctionTemplateDecl>(D))
4908 D = FunTmpl->getTemplatedDecl();
4909
4910 if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(D)) {
4911 SmallString<64> Str;
4912 llvm::raw_svector_ostream OS(Str);
4913 OS << *Function;
4914 if (Function->getPrimaryTemplate())
4915 OS << "<>";
4916 OS << "(";
4917 for (unsigned I = 0, N = Function->getNumParams(); I != N; ++I) {
4918 if (I)
4919 OS << ", ";
4920 OS << Function->getParamDecl(I)->getType().getAsString(Policy);
4921 }
4922
4923 if (Function->isVariadic()) {
4924 if (Function->getNumParams())
4925 OS << ", ";
4926 OS << "...";
4927 }
4928 OS << ")";
4929 return cxstring::createDup(OS.str());
4930 }
4931
4932 if (const ClassTemplateDecl *ClassTemplate = dyn_cast<ClassTemplateDecl>(D)) {
4933 SmallString<64> Str;
4934 llvm::raw_svector_ostream OS(Str);
4935 OS << *ClassTemplate;
4936 OS << "<";
4937 TemplateParameterList *Params = ClassTemplate->getTemplateParameters();
4938 for (unsigned I = 0, N = Params->size(); I != N; ++I) {
4939 if (I)
4940 OS << ", ";
4941
4942 NamedDecl *Param = Params->getParam(I);
4943 if (Param->getIdentifier()) {
4944 OS << Param->getIdentifier()->getName();
4945 continue;
4946 }
4947
4948 // There is no parameter name, which makes this tricky. Try to come up
4949 // with something useful that isn't too long.
4950 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Param))
4951 OS << (TTP->wasDeclaredWithTypename()? "typename" : "class");
4952 else if (NonTypeTemplateParmDecl *NTTP
4953 = dyn_cast<NonTypeTemplateParmDecl>(Param))
4954 OS << NTTP->getType().getAsString(Policy);
4955 else
4956 OS << "template<...> class";
4957 }
4958
4959 OS << ">";
4960 return cxstring::createDup(OS.str());
4961 }
4962
4963 if (const ClassTemplateSpecializationDecl *ClassSpec
4964 = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
4965 // If the type was explicitly written, use that.
4966 if (TypeSourceInfo *TSInfo = ClassSpec->getTypeAsWritten())
4967 return cxstring::createDup(TSInfo->getType().getAsString(Policy));
4968
4969 SmallString<128> Str;
4970 llvm::raw_svector_ostream OS(Str);
4971 OS << *ClassSpec;
4972 printTemplateArgumentList(OS, ClassSpec->getTemplateArgs().asArray(),
4973 Policy);
4974 return cxstring::createDup(OS.str());
4975 }
4976
4977 return clang_getCursorSpelling(C);
4978}
4979
4980CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
4981 switch (Kind) {
4982 case CXCursor_FunctionDecl:
4983 return cxstring::createRef("FunctionDecl");
4984 case CXCursor_TypedefDecl:
4985 return cxstring::createRef("TypedefDecl");
4986 case CXCursor_EnumDecl:
4987 return cxstring::createRef("EnumDecl");
4988 case CXCursor_EnumConstantDecl:
4989 return cxstring::createRef("EnumConstantDecl");
4990 case CXCursor_StructDecl:
4991 return cxstring::createRef("StructDecl");
4992 case CXCursor_UnionDecl:
4993 return cxstring::createRef("UnionDecl");
4994 case CXCursor_ClassDecl:
4995 return cxstring::createRef("ClassDecl");
4996 case CXCursor_FieldDecl:
4997 return cxstring::createRef("FieldDecl");
4998 case CXCursor_VarDecl:
4999 return cxstring::createRef("VarDecl");
5000 case CXCursor_ParmDecl:
5001 return cxstring::createRef("ParmDecl");
5002 case CXCursor_ObjCInterfaceDecl:
5003 return cxstring::createRef("ObjCInterfaceDecl");
5004 case CXCursor_ObjCCategoryDecl:
5005 return cxstring::createRef("ObjCCategoryDecl");
5006 case CXCursor_ObjCProtocolDecl:
5007 return cxstring::createRef("ObjCProtocolDecl");
5008 case CXCursor_ObjCPropertyDecl:
5009 return cxstring::createRef("ObjCPropertyDecl");
5010 case CXCursor_ObjCIvarDecl:
5011 return cxstring::createRef("ObjCIvarDecl");
5012 case CXCursor_ObjCInstanceMethodDecl:
5013 return cxstring::createRef("ObjCInstanceMethodDecl");
5014 case CXCursor_ObjCClassMethodDecl:
5015 return cxstring::createRef("ObjCClassMethodDecl");
5016 case CXCursor_ObjCImplementationDecl:
5017 return cxstring::createRef("ObjCImplementationDecl");
5018 case CXCursor_ObjCCategoryImplDecl:
5019 return cxstring::createRef("ObjCCategoryImplDecl");
5020 case CXCursor_CXXMethod:
5021 return cxstring::createRef("CXXMethod");
5022 case CXCursor_UnexposedDecl:
5023 return cxstring::createRef("UnexposedDecl");
5024 case CXCursor_ObjCSuperClassRef:
5025 return cxstring::createRef("ObjCSuperClassRef");
5026 case CXCursor_ObjCProtocolRef:
5027 return cxstring::createRef("ObjCProtocolRef");
5028 case CXCursor_ObjCClassRef:
5029 return cxstring::createRef("ObjCClassRef");
5030 case CXCursor_TypeRef:
5031 return cxstring::createRef("TypeRef");
5032 case CXCursor_TemplateRef:
5033 return cxstring::createRef("TemplateRef");
5034 case CXCursor_NamespaceRef:
5035 return cxstring::createRef("NamespaceRef");
5036 case CXCursor_MemberRef:
5037 return cxstring::createRef("MemberRef");
5038 case CXCursor_LabelRef:
5039 return cxstring::createRef("LabelRef");
5040 case CXCursor_OverloadedDeclRef:
5041 return cxstring::createRef("OverloadedDeclRef");
5042 case CXCursor_VariableRef:
5043 return cxstring::createRef("VariableRef");
5044 case CXCursor_IntegerLiteral:
5045 return cxstring::createRef("IntegerLiteral");
5046 case CXCursor_FloatingLiteral:
5047 return cxstring::createRef("FloatingLiteral");
5048 case CXCursor_ImaginaryLiteral:
5049 return cxstring::createRef("ImaginaryLiteral");
5050 case CXCursor_StringLiteral:
5051 return cxstring::createRef("StringLiteral");
5052 case CXCursor_CharacterLiteral:
5053 return cxstring::createRef("CharacterLiteral");
5054 case CXCursor_ParenExpr:
5055 return cxstring::createRef("ParenExpr");
5056 case CXCursor_UnaryOperator:
5057 return cxstring::createRef("UnaryOperator");
5058 case CXCursor_ArraySubscriptExpr:
5059 return cxstring::createRef("ArraySubscriptExpr");
5060 case CXCursor_OMPArraySectionExpr:
5061 return cxstring::createRef("OMPArraySectionExpr");
5062 case CXCursor_BinaryOperator:
5063 return cxstring::createRef("BinaryOperator");
5064 case CXCursor_CompoundAssignOperator:
5065 return cxstring::createRef("CompoundAssignOperator");
5066 case CXCursor_ConditionalOperator:
5067 return cxstring::createRef("ConditionalOperator");
5068 case CXCursor_CStyleCastExpr:
5069 return cxstring::createRef("CStyleCastExpr");
5070 case CXCursor_CompoundLiteralExpr:
5071 return cxstring::createRef("CompoundLiteralExpr");
5072 case CXCursor_InitListExpr:
5073 return cxstring::createRef("InitListExpr");
5074 case CXCursor_AddrLabelExpr:
5075 return cxstring::createRef("AddrLabelExpr");
5076 case CXCursor_StmtExpr:
5077 return cxstring::createRef("StmtExpr");
5078 case CXCursor_GenericSelectionExpr:
5079 return cxstring::createRef("GenericSelectionExpr");
5080 case CXCursor_GNUNullExpr:
5081 return cxstring::createRef("GNUNullExpr");
5082 case CXCursor_CXXStaticCastExpr:
5083 return cxstring::createRef("CXXStaticCastExpr");
5084 case CXCursor_CXXDynamicCastExpr:
5085 return cxstring::createRef("CXXDynamicCastExpr");
5086 case CXCursor_CXXReinterpretCastExpr:
5087 return cxstring::createRef("CXXReinterpretCastExpr");
5088 case CXCursor_CXXConstCastExpr:
5089 return cxstring::createRef("CXXConstCastExpr");
5090 case CXCursor_CXXFunctionalCastExpr:
5091 return cxstring::createRef("CXXFunctionalCastExpr");
5092 case CXCursor_CXXTypeidExpr:
5093 return cxstring::createRef("CXXTypeidExpr");
5094 case CXCursor_CXXBoolLiteralExpr:
5095 return cxstring::createRef("CXXBoolLiteralExpr");
5096 case CXCursor_CXXNullPtrLiteralExpr:
5097 return cxstring::createRef("CXXNullPtrLiteralExpr");
5098 case CXCursor_CXXThisExpr:
5099 return cxstring::createRef("CXXThisExpr");
5100 case CXCursor_CXXThrowExpr:
5101 return cxstring::createRef("CXXThrowExpr");
5102 case CXCursor_CXXNewExpr:
5103 return cxstring::createRef("CXXNewExpr");
5104 case CXCursor_CXXDeleteExpr:
5105 return cxstring::createRef("CXXDeleteExpr");
5106 case CXCursor_UnaryExpr:
5107 return cxstring::createRef("UnaryExpr");
5108 case CXCursor_ObjCStringLiteral:
5109 return cxstring::createRef("ObjCStringLiteral");
5110 case CXCursor_ObjCBoolLiteralExpr:
5111 return cxstring::createRef("ObjCBoolLiteralExpr");
5112 case CXCursor_ObjCAvailabilityCheckExpr:
5113 return cxstring::createRef("ObjCAvailabilityCheckExpr");
5114 case CXCursor_ObjCSelfExpr:
5115 return cxstring::createRef("ObjCSelfExpr");
5116 case CXCursor_ObjCEncodeExpr:
5117 return cxstring::createRef("ObjCEncodeExpr");
5118 case CXCursor_ObjCSelectorExpr:
5119 return cxstring::createRef("ObjCSelectorExpr");
5120 case CXCursor_ObjCProtocolExpr:
5121 return cxstring::createRef("ObjCProtocolExpr");
5122 case CXCursor_ObjCBridgedCastExpr:
5123 return cxstring::createRef("ObjCBridgedCastExpr");
5124 case CXCursor_BlockExpr:
5125 return cxstring::createRef("BlockExpr");
5126 case CXCursor_PackExpansionExpr:
5127 return cxstring::createRef("PackExpansionExpr");
5128 case CXCursor_SizeOfPackExpr:
5129 return cxstring::createRef("SizeOfPackExpr");
5130 case CXCursor_LambdaExpr:
5131 return cxstring::createRef("LambdaExpr");
5132 case CXCursor_UnexposedExpr:
5133 return cxstring::createRef("UnexposedExpr");
5134 case CXCursor_DeclRefExpr:
5135 return cxstring::createRef("DeclRefExpr");
5136 case CXCursor_MemberRefExpr:
5137 return cxstring::createRef("MemberRefExpr");
5138 case CXCursor_CallExpr:
5139 return cxstring::createRef("CallExpr");
5140 case CXCursor_ObjCMessageExpr:
5141 return cxstring::createRef("ObjCMessageExpr");
5142 case CXCursor_UnexposedStmt:
5143 return cxstring::createRef("UnexposedStmt");
5144 case CXCursor_DeclStmt:
5145 return cxstring::createRef("DeclStmt");
5146 case CXCursor_LabelStmt:
5147 return cxstring::createRef("LabelStmt");
5148 case CXCursor_CompoundStmt:
5149 return cxstring::createRef("CompoundStmt");
5150 case CXCursor_CaseStmt:
5151 return cxstring::createRef("CaseStmt");
5152 case CXCursor_DefaultStmt:
5153 return cxstring::createRef("DefaultStmt");
5154 case CXCursor_IfStmt:
5155 return cxstring::createRef("IfStmt");
5156 case CXCursor_SwitchStmt:
5157 return cxstring::createRef("SwitchStmt");
5158 case CXCursor_WhileStmt:
5159 return cxstring::createRef("WhileStmt");
5160 case CXCursor_DoStmt:
5161 return cxstring::createRef("DoStmt");
5162 case CXCursor_ForStmt:
5163 return cxstring::createRef("ForStmt");
5164 case CXCursor_GotoStmt:
5165 return cxstring::createRef("GotoStmt");
5166 case CXCursor_IndirectGotoStmt:
5167 return cxstring::createRef("IndirectGotoStmt");
5168 case CXCursor_ContinueStmt:
5169 return cxstring::createRef("ContinueStmt");
5170 case CXCursor_BreakStmt:
5171 return cxstring::createRef("BreakStmt");
5172 case CXCursor_ReturnStmt:
5173 return cxstring::createRef("ReturnStmt");
5174 case CXCursor_GCCAsmStmt:
5175 return cxstring::createRef("GCCAsmStmt");
5176 case CXCursor_MSAsmStmt:
5177 return cxstring::createRef("MSAsmStmt");
5178 case CXCursor_ObjCAtTryStmt:
5179 return cxstring::createRef("ObjCAtTryStmt");
5180 case CXCursor_ObjCAtCatchStmt:
5181 return cxstring::createRef("ObjCAtCatchStmt");
5182 case CXCursor_ObjCAtFinallyStmt:
5183 return cxstring::createRef("ObjCAtFinallyStmt");
5184 case CXCursor_ObjCAtThrowStmt:
5185 return cxstring::createRef("ObjCAtThrowStmt");
5186 case CXCursor_ObjCAtSynchronizedStmt:
5187 return cxstring::createRef("ObjCAtSynchronizedStmt");
5188 case CXCursor_ObjCAutoreleasePoolStmt:
5189 return cxstring::createRef("ObjCAutoreleasePoolStmt");
5190 case CXCursor_ObjCForCollectionStmt:
5191 return cxstring::createRef("ObjCForCollectionStmt");
5192 case CXCursor_CXXCatchStmt:
5193 return cxstring::createRef("CXXCatchStmt");
5194 case CXCursor_CXXTryStmt:
5195 return cxstring::createRef("CXXTryStmt");
5196 case CXCursor_CXXForRangeStmt:
5197 return cxstring::createRef("CXXForRangeStmt");
5198 case CXCursor_SEHTryStmt:
5199 return cxstring::createRef("SEHTryStmt");
5200 case CXCursor_SEHExceptStmt:
5201 return cxstring::createRef("SEHExceptStmt");
5202 case CXCursor_SEHFinallyStmt:
5203 return cxstring::createRef("SEHFinallyStmt");
5204 case CXCursor_SEHLeaveStmt:
5205 return cxstring::createRef("SEHLeaveStmt");
5206 case CXCursor_NullStmt:
5207 return cxstring::createRef("NullStmt");
5208 case CXCursor_InvalidFile:
5209 return cxstring::createRef("InvalidFile");
5210 case CXCursor_InvalidCode:
5211 return cxstring::createRef("InvalidCode");
5212 case CXCursor_NoDeclFound:
5213 return cxstring::createRef("NoDeclFound");
5214 case CXCursor_NotImplemented:
5215 return cxstring::createRef("NotImplemented");
5216 case CXCursor_TranslationUnit:
5217 return cxstring::createRef("TranslationUnit");
5218 case CXCursor_UnexposedAttr:
5219 return cxstring::createRef("UnexposedAttr");
5220 case CXCursor_IBActionAttr:
5221 return cxstring::createRef("attribute(ibaction)");
5222 case CXCursor_IBOutletAttr:
5223 return cxstring::createRef("attribute(iboutlet)");
5224 case CXCursor_IBOutletCollectionAttr:
5225 return cxstring::createRef("attribute(iboutletcollection)");
5226 case CXCursor_CXXFinalAttr:
5227 return cxstring::createRef("attribute(final)");
5228 case CXCursor_CXXOverrideAttr:
5229 return cxstring::createRef("attribute(override)");
5230 case CXCursor_AnnotateAttr:
5231 return cxstring::createRef("attribute(annotate)");
5232 case CXCursor_AsmLabelAttr:
5233 return cxstring::createRef("asm label");
5234 case CXCursor_PackedAttr:
5235 return cxstring::createRef("attribute(packed)");
5236 case CXCursor_PureAttr:
5237 return cxstring::createRef("attribute(pure)");
5238 case CXCursor_ConstAttr:
5239 return cxstring::createRef("attribute(const)");
5240 case CXCursor_NoDuplicateAttr:
5241 return cxstring::createRef("attribute(noduplicate)");
5242 case CXCursor_CUDAConstantAttr:
5243 return cxstring::createRef("attribute(constant)");
5244 case CXCursor_CUDADeviceAttr:
5245 return cxstring::createRef("attribute(device)");
5246 case CXCursor_CUDAGlobalAttr:
5247 return cxstring::createRef("attribute(global)");
5248 case CXCursor_CUDAHostAttr:
5249 return cxstring::createRef("attribute(host)");
5250 case CXCursor_CUDASharedAttr:
5251 return cxstring::createRef("attribute(shared)");
5252 case CXCursor_VisibilityAttr:
5253 return cxstring::createRef("attribute(visibility)");
5254 case CXCursor_DLLExport:
5255 return cxstring::createRef("attribute(dllexport)");
5256 case CXCursor_DLLImport:
5257 return cxstring::createRef("attribute(dllimport)");
5258 case CXCursor_PreprocessingDirective:
5259 return cxstring::createRef("preprocessing directive");
5260 case CXCursor_MacroDefinition:
5261 return cxstring::createRef("macro definition");
5262 case CXCursor_MacroExpansion:
5263 return cxstring::createRef("macro expansion");
5264 case CXCursor_InclusionDirective:
5265 return cxstring::createRef("inclusion directive");
5266 case CXCursor_Namespace:
5267 return cxstring::createRef("Namespace");
5268 case CXCursor_LinkageSpec:
5269 return cxstring::createRef("LinkageSpec");
5270 case CXCursor_CXXBaseSpecifier:
5271 return cxstring::createRef("C++ base class specifier");
5272 case CXCursor_Constructor:
5273 return cxstring::createRef("CXXConstructor");
5274 case CXCursor_Destructor:
5275 return cxstring::createRef("CXXDestructor");
5276 case CXCursor_ConversionFunction:
5277 return cxstring::createRef("CXXConversion");
5278 case CXCursor_TemplateTypeParameter:
5279 return cxstring::createRef("TemplateTypeParameter");
5280 case CXCursor_NonTypeTemplateParameter:
5281 return cxstring::createRef("NonTypeTemplateParameter");
5282 case CXCursor_TemplateTemplateParameter:
5283 return cxstring::createRef("TemplateTemplateParameter");
5284 case CXCursor_FunctionTemplate:
5285 return cxstring::createRef("FunctionTemplate");
5286 case CXCursor_ClassTemplate:
5287 return cxstring::createRef("ClassTemplate");
5288 case CXCursor_ClassTemplatePartialSpecialization:
5289 return cxstring::createRef("ClassTemplatePartialSpecialization");
5290 case CXCursor_NamespaceAlias:
5291 return cxstring::createRef("NamespaceAlias");
5292 case CXCursor_UsingDirective:
5293 return cxstring::createRef("UsingDirective");
5294 case CXCursor_UsingDeclaration:
5295 return cxstring::createRef("UsingDeclaration");
5296 case CXCursor_TypeAliasDecl:
5297 return cxstring::createRef("TypeAliasDecl");
5298 case CXCursor_ObjCSynthesizeDecl:
5299 return cxstring::createRef("ObjCSynthesizeDecl");
5300 case CXCursor_ObjCDynamicDecl:
5301 return cxstring::createRef("ObjCDynamicDecl");
5302 case CXCursor_CXXAccessSpecifier:
5303 return cxstring::createRef("CXXAccessSpecifier");
5304 case CXCursor_ModuleImportDecl:
5305 return cxstring::createRef("ModuleImport");
5306 case CXCursor_OMPParallelDirective:
5307 return cxstring::createRef("OMPParallelDirective");
5308 case CXCursor_OMPSimdDirective:
5309 return cxstring::createRef("OMPSimdDirective");
5310 case CXCursor_OMPForDirective:
5311 return cxstring::createRef("OMPForDirective");
5312 case CXCursor_OMPForSimdDirective:
5313 return cxstring::createRef("OMPForSimdDirective");
5314 case CXCursor_OMPSectionsDirective:
5315 return cxstring::createRef("OMPSectionsDirective");
5316 case CXCursor_OMPSectionDirective:
5317 return cxstring::createRef("OMPSectionDirective");
5318 case CXCursor_OMPSingleDirective:
5319 return cxstring::createRef("OMPSingleDirective");
5320 case CXCursor_OMPMasterDirective:
5321 return cxstring::createRef("OMPMasterDirective");
5322 case CXCursor_OMPCriticalDirective:
5323 return cxstring::createRef("OMPCriticalDirective");
5324 case CXCursor_OMPParallelForDirective:
5325 return cxstring::createRef("OMPParallelForDirective");
5326 case CXCursor_OMPParallelForSimdDirective:
5327 return cxstring::createRef("OMPParallelForSimdDirective");
5328 case CXCursor_OMPParallelSectionsDirective:
5329 return cxstring::createRef("OMPParallelSectionsDirective");
5330 case CXCursor_OMPTaskDirective:
5331 return cxstring::createRef("OMPTaskDirective");
5332 case CXCursor_OMPTaskyieldDirective:
5333 return cxstring::createRef("OMPTaskyieldDirective");
5334 case CXCursor_OMPBarrierDirective:
5335 return cxstring::createRef("OMPBarrierDirective");
5336 case CXCursor_OMPTaskwaitDirective:
5337 return cxstring::createRef("OMPTaskwaitDirective");
5338 case CXCursor_OMPTaskgroupDirective:
5339 return cxstring::createRef("OMPTaskgroupDirective");
5340 case CXCursor_OMPFlushDirective:
5341 return cxstring::createRef("OMPFlushDirective");
5342 case CXCursor_OMPOrderedDirective:
5343 return cxstring::createRef("OMPOrderedDirective");
5344 case CXCursor_OMPAtomicDirective:
5345 return cxstring::createRef("OMPAtomicDirective");
5346 case CXCursor_OMPTargetDirective:
5347 return cxstring::createRef("OMPTargetDirective");
5348 case CXCursor_OMPTargetDataDirective:
5349 return cxstring::createRef("OMPTargetDataDirective");
5350 case CXCursor_OMPTargetEnterDataDirective:
5351 return cxstring::createRef("OMPTargetEnterDataDirective");
5352 case CXCursor_OMPTargetExitDataDirective:
5353 return cxstring::createRef("OMPTargetExitDataDirective");
5354 case CXCursor_OMPTargetParallelDirective:
5355 return cxstring::createRef("OMPTargetParallelDirective");
5356 case CXCursor_OMPTargetParallelForDirective:
5357 return cxstring::createRef("OMPTargetParallelForDirective");
5358 case CXCursor_OMPTargetUpdateDirective:
5359 return cxstring::createRef("OMPTargetUpdateDirective");
5360 case CXCursor_OMPTeamsDirective:
5361 return cxstring::createRef("OMPTeamsDirective");
5362 case CXCursor_OMPCancellationPointDirective:
5363 return cxstring::createRef("OMPCancellationPointDirective");
5364 case CXCursor_OMPCancelDirective:
5365 return cxstring::createRef("OMPCancelDirective");
5366 case CXCursor_OMPTaskLoopDirective:
5367 return cxstring::createRef("OMPTaskLoopDirective");
5368 case CXCursor_OMPTaskLoopSimdDirective:
5369 return cxstring::createRef("OMPTaskLoopSimdDirective");
5370 case CXCursor_OMPDistributeDirective:
5371 return cxstring::createRef("OMPDistributeDirective");
5372 case CXCursor_OMPDistributeParallelForDirective:
5373 return cxstring::createRef("OMPDistributeParallelForDirective");
5374 case CXCursor_OMPDistributeParallelForSimdDirective:
5375 return cxstring::createRef("OMPDistributeParallelForSimdDirective");
5376 case CXCursor_OMPDistributeSimdDirective:
5377 return cxstring::createRef("OMPDistributeSimdDirective");
5378 case CXCursor_OMPTargetParallelForSimdDirective:
5379 return cxstring::createRef("OMPTargetParallelForSimdDirective");
5380 case CXCursor_OMPTargetSimdDirective:
5381 return cxstring::createRef("OMPTargetSimdDirective");
5382 case CXCursor_OMPTeamsDistributeDirective:
5383 return cxstring::createRef("OMPTeamsDistributeDirective");
5384 case CXCursor_OMPTeamsDistributeSimdDirective:
5385 return cxstring::createRef("OMPTeamsDistributeSimdDirective");
5386 case CXCursor_OMPTeamsDistributeParallelForSimdDirective:
5387 return cxstring::createRef("OMPTeamsDistributeParallelForSimdDirective");
5388 case CXCursor_OMPTeamsDistributeParallelForDirective:
5389 return cxstring::createRef("OMPTeamsDistributeParallelForDirective");
5390 case CXCursor_OMPTargetTeamsDirective:
5391 return cxstring::createRef("OMPTargetTeamsDirective");
5392 case CXCursor_OMPTargetTeamsDistributeDirective:
5393 return cxstring::createRef("OMPTargetTeamsDistributeDirective");
5394 case CXCursor_OMPTargetTeamsDistributeParallelForDirective:
5395 return cxstring::createRef("OMPTargetTeamsDistributeParallelForDirective");
5396 case CXCursor_OMPTargetTeamsDistributeParallelForSimdDirective:
5397 return cxstring::createRef(
5398 "OMPTargetTeamsDistributeParallelForSimdDirective");
5399 case CXCursor_OMPTargetTeamsDistributeSimdDirective:
5400 return cxstring::createRef("OMPTargetTeamsDistributeSimdDirective");
5401 case CXCursor_OverloadCandidate:
5402 return cxstring::createRef("OverloadCandidate");
5403 case CXCursor_TypeAliasTemplateDecl:
5404 return cxstring::createRef("TypeAliasTemplateDecl");
5405 case CXCursor_StaticAssert:
5406 return cxstring::createRef("StaticAssert");
5407 case CXCursor_FriendDecl:
5408 return cxstring::createRef("FriendDecl");
5409 }
5410
5411 llvm_unreachable("Unhandled CXCursorKind")::llvm::llvm_unreachable_internal("Unhandled CXCursorKind", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 5411)
;
5412}
5413
5414struct GetCursorData {
5415 SourceLocation TokenBeginLoc;
5416 bool PointsAtMacroArgExpansion;
5417 bool VisitedObjCPropertyImplDecl;
5418 SourceLocation VisitedDeclaratorDeclStartLoc;
5419 CXCursor &BestCursor;
5420
5421 GetCursorData(SourceManager &SM,
5422 SourceLocation tokenBegin, CXCursor &outputCursor)
5423 : TokenBeginLoc(tokenBegin), BestCursor(outputCursor) {
5424 PointsAtMacroArgExpansion = SM.isMacroArgExpansion(tokenBegin);
5425 VisitedObjCPropertyImplDecl = false;
5426 }
5427};
5428
5429static enum CXChildVisitResult GetCursorVisitor(CXCursor cursor,
5430 CXCursor parent,
5431 CXClientData client_data) {
5432 GetCursorData *Data = static_cast<GetCursorData *>(client_data);
5433 CXCursor *BestCursor = &Data->BestCursor;
5434
5435 // If we point inside a macro argument we should provide info of what the
5436 // token is so use the actual cursor, don't replace it with a macro expansion
5437 // cursor.
5438 if (cursor.kind == CXCursor_MacroExpansion && Data->PointsAtMacroArgExpansion)
5439 return CXChildVisit_Recurse;
5440
5441 if (clang_isDeclaration(cursor.kind)) {
5442 // Avoid having the implicit methods override the property decls.
5443 if (const ObjCMethodDecl *MD
5444 = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(cursor))) {
5445 if (MD->isImplicit())
5446 return CXChildVisit_Break;
5447
5448 } else if (const ObjCInterfaceDecl *ID
5449 = dyn_cast_or_null<ObjCInterfaceDecl>(getCursorDecl(cursor))) {
5450 // Check that when we have multiple @class references in the same line,
5451 // that later ones do not override the previous ones.
5452 // If we have:
5453 // @class Foo, Bar;
5454 // source ranges for both start at '@', so 'Bar' will end up overriding
5455 // 'Foo' even though the cursor location was at 'Foo'.
5456 if (BestCursor->kind == CXCursor_ObjCInterfaceDecl ||
5457 BestCursor->kind == CXCursor_ObjCClassRef)
5458 if (const ObjCInterfaceDecl *PrevID
5459 = dyn_cast_or_null<ObjCInterfaceDecl>(getCursorDecl(*BestCursor))){
5460 if (PrevID != ID &&
5461 !PrevID->isThisDeclarationADefinition() &&
5462 !ID->isThisDeclarationADefinition())
5463 return CXChildVisit_Break;
5464 }
5465
5466 } else if (const DeclaratorDecl *DD
5467 = dyn_cast_or_null<DeclaratorDecl>(getCursorDecl(cursor))) {
5468 SourceLocation StartLoc = DD->getSourceRange().getBegin();
5469 // Check that when we have multiple declarators in the same line,
5470 // that later ones do not override the previous ones.
5471 // If we have:
5472 // int Foo, Bar;
5473 // source ranges for both start at 'int', so 'Bar' will end up overriding
5474 // 'Foo' even though the cursor location was at 'Foo'.
5475 if (Data->VisitedDeclaratorDeclStartLoc == StartLoc)
5476 return CXChildVisit_Break;
5477 Data->VisitedDeclaratorDeclStartLoc = StartLoc;
5478
5479 } else if (const ObjCPropertyImplDecl *PropImp
5480 = dyn_cast_or_null<ObjCPropertyImplDecl>(getCursorDecl(cursor))) {
5481 (void)PropImp;
5482 // Check that when we have multiple @synthesize in the same line,
5483 // that later ones do not override the previous ones.
5484 // If we have:
5485 // @synthesize Foo, Bar;
5486 // source ranges for both start at '@', so 'Bar' will end up overriding
5487 // 'Foo' even though the cursor location was at 'Foo'.
5488 if (Data->VisitedObjCPropertyImplDecl)
5489 return CXChildVisit_Break;
5490 Data->VisitedObjCPropertyImplDecl = true;
5491 }
5492 }
5493
5494 if (clang_isExpression(cursor.kind) &&
5495 clang_isDeclaration(BestCursor->kind)) {
5496 if (const Decl *D = getCursorDecl(*BestCursor)) {
5497 // Avoid having the cursor of an expression replace the declaration cursor
5498 // when the expression source range overlaps the declaration range.
5499 // This can happen for C++ constructor expressions whose range generally
5500 // include the variable declaration, e.g.:
5501 // MyCXXClass foo; // Make sure pointing at 'foo' returns a VarDecl cursor.
5502 if (D->getLocation().isValid() && Data->TokenBeginLoc.isValid() &&
5503 D->getLocation() == Data->TokenBeginLoc)
5504 return CXChildVisit_Break;
5505 }
5506 }
5507
5508 // If our current best cursor is the construction of a temporary object,
5509 // don't replace that cursor with a type reference, because we want
5510 // clang_getCursor() to point at the constructor.
5511 if (clang_isExpression(BestCursor->kind) &&
5512 isa<CXXTemporaryObjectExpr>(getCursorExpr(*BestCursor)) &&
5513 cursor.kind == CXCursor_TypeRef) {
5514 // Keep the cursor pointing at CXXTemporaryObjectExpr but also mark it
5515 // as having the actual point on the type reference.
5516 *BestCursor = getTypeRefedCallExprCursor(*BestCursor);
5517 return CXChildVisit_Recurse;
5518 }
5519
5520 // If we already have an Objective-C superclass reference, don't
5521 // update it further.
5522 if (BestCursor->kind == CXCursor_ObjCSuperClassRef)
5523 return CXChildVisit_Break;
5524
5525 *BestCursor = cursor;
5526 return CXChildVisit_Recurse;
5527}
5528
5529CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) {
5530 if (isNotUsableTU(TU)) {
5531 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
5532 return clang_getNullCursor();
5533 }
5534
5535 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
5536 ASTUnit::ConcurrencyCheck Check(*CXXUnit);
5537
5538 SourceLocation SLoc = cxloc::translateSourceLocation(Loc);
5539 CXCursor Result = cxcursor::getCursor(TU, SLoc);
5540
5541 LOG_FUNC_SECTIONif (clang::cxindex::LogRef Log = clang::cxindex::Logger::make
(__func__))
{
5542 CXFile SearchFile;
5543 unsigned SearchLine, SearchColumn;
5544 CXFile ResultFile;
5545 unsigned ResultLine, ResultColumn;
5546 CXString SearchFileName, ResultFileName, KindSpelling, USR;
5547 const char *IsDef = clang_isCursorDefinition(Result)? " (Definition)" : "";
5548 CXSourceLocation ResultLoc = clang_getCursorLocation(Result);
5549
5550 clang_getFileLocation(Loc, &SearchFile, &SearchLine, &SearchColumn,
5551 nullptr);
5552 clang_getFileLocation(ResultLoc, &ResultFile, &ResultLine,
5553 &ResultColumn, nullptr);
5554 SearchFileName = clang_getFileName(SearchFile);
5555 ResultFileName = clang_getFileName(ResultFile);
5556 KindSpelling = clang_getCursorKindSpelling(Result.kind);
5557 USR = clang_getCursorUSR(Result);
5558 *Log << llvm::format("(%s:%d:%d) = %s",
5559 clang_getCString(SearchFileName), SearchLine, SearchColumn,
5560 clang_getCString(KindSpelling))
5561 << llvm::format("(%s:%d:%d):%s%s",
5562 clang_getCString(ResultFileName), ResultLine, ResultColumn,
5563 clang_getCString(USR), IsDef);
5564 clang_disposeString(SearchFileName);
5565 clang_disposeString(ResultFileName);
5566 clang_disposeString(KindSpelling);
5567 clang_disposeString(USR);
5568
5569 CXCursor Definition = clang_getCursorDefinition(Result);
5570 if (!clang_equalCursors(Definition, clang_getNullCursor())) {
5571 CXSourceLocation DefinitionLoc = clang_getCursorLocation(Definition);
5572 CXString DefinitionKindSpelling
5573 = clang_getCursorKindSpelling(Definition.kind);
5574 CXFile DefinitionFile;
5575 unsigned DefinitionLine, DefinitionColumn;
5576 clang_getFileLocation(DefinitionLoc, &DefinitionFile,
5577 &DefinitionLine, &DefinitionColumn, nullptr);
5578 CXString DefinitionFileName = clang_getFileName(DefinitionFile);
5579 *Log << llvm::format(" -> %s(%s:%d:%d)",
5580 clang_getCString(DefinitionKindSpelling),
5581 clang_getCString(DefinitionFileName),
5582 DefinitionLine, DefinitionColumn);
5583 clang_disposeString(DefinitionFileName);
5584 clang_disposeString(DefinitionKindSpelling);
5585 }
5586 }
5587
5588 return Result;
5589}
5590
5591CXCursor clang_getNullCursor(void) {
5592 return MakeCXCursorInvalid(CXCursor_InvalidFile);
5593}
5594
5595unsigned clang_equalCursors(CXCursor X, CXCursor Y) {
5596 // Clear out the "FirstInDeclGroup" part in a declaration cursor, since we
5597 // can't set consistently. For example, when visiting a DeclStmt we will set
5598 // it but we don't set it on the result of clang_getCursorDefinition for
5599 // a reference of the same declaration.
5600 // FIXME: Setting "FirstInDeclGroup" in CXCursors is a hack that only works
5601 // when visiting a DeclStmt currently, the AST should be enhanced to be able
5602 // to provide that kind of info.
5603 if (clang_isDeclaration(X.kind))
5604 X.data[1] = nullptr;
5605 if (clang_isDeclaration(Y.kind))
5606 Y.data[1] = nullptr;
5607
5608 return X == Y;
5609}
5610
5611unsigned clang_hashCursor(CXCursor C) {
5612 unsigned Index = 0;
5613 if (clang_isExpression(C.kind) || clang_isStatement(C.kind))
5614 Index = 1;
5615
5616 return llvm::DenseMapInfo<std::pair<unsigned, const void*> >::getHashValue(
5617 std::make_pair(C.kind, C.data[Index]));
5618}
5619
5620unsigned clang_isInvalid(enum CXCursorKind K) {
5621 return K >= CXCursor_FirstInvalid && K <= CXCursor_LastInvalid;
5622}
5623
5624unsigned clang_isDeclaration(enum CXCursorKind K) {
5625 return (K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl) ||
5626 (K >= CXCursor_FirstExtraDecl && K <= CXCursor_LastExtraDecl);
5627}
5628
5629unsigned clang_isInvalidDeclaration(CXCursor C) {
5630 if (clang_isDeclaration(C.kind)) {
5631 if (const Decl *D = getCursorDecl(C))
5632 return D->isInvalidDecl();
5633 }
5634
5635 return 0;
5636}
5637
5638unsigned clang_isReference(enum CXCursorKind K) {
5639 return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
5640}
5641
5642unsigned clang_isExpression(enum CXCursorKind K) {
5643 return K >= CXCursor_FirstExpr && K <= CXCursor_LastExpr;
5644}
5645
5646unsigned clang_isStatement(enum CXCursorKind K) {
5647 return K >= CXCursor_FirstStmt && K <= CXCursor_LastStmt;
5648}
5649
5650unsigned clang_isAttribute(enum CXCursorKind K) {
5651 return K >= CXCursor_FirstAttr && K <= CXCursor_LastAttr;
5652}
5653
5654unsigned clang_isTranslationUnit(enum CXCursorKind K) {
5655 return K == CXCursor_TranslationUnit;
5656}
5657
5658unsigned clang_isPreprocessing(enum CXCursorKind K) {
5659 return K >= CXCursor_FirstPreprocessing && K <= CXCursor_LastPreprocessing;
5660}
5661
5662unsigned clang_isUnexposed(enum CXCursorKind K) {
5663 switch (K) {
5664 case CXCursor_UnexposedDecl:
5665 case CXCursor_UnexposedExpr:
5666 case CXCursor_UnexposedStmt:
5667 case CXCursor_UnexposedAttr:
5668 return true;
5669 default:
5670 return false;
5671 }
5672}
5673
5674CXCursorKind clang_getCursorKind(CXCursor C) {
5675 return C.kind;
5676}
5677
5678CXSourceLocation clang_getCursorLocation(CXCursor C) {
5679 if (clang_isReference(C.kind)) {
5680 switch (C.kind) {
5681 case CXCursor_ObjCSuperClassRef: {
5682 std::pair<const ObjCInterfaceDecl *, SourceLocation> P
5683 = getCursorObjCSuperClassRef(C);
5684 return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
5685 }
5686
5687 case CXCursor_ObjCProtocolRef: {
5688 std::pair<const ObjCProtocolDecl *, SourceLocation> P
5689 = getCursorObjCProtocolRef(C);
5690 return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
5691 }
5692
5693 case CXCursor_ObjCClassRef: {
5694 std::pair<const ObjCInterfaceDecl *, SourceLocation> P
5695 = getCursorObjCClassRef(C);
5696 return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
5697 }
5698
5699 case CXCursor_TypeRef: {
5700 std::pair<const TypeDecl *, SourceLocation> P = getCursorTypeRef(C);
5701 return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
5702 }
5703
5704 case CXCursor_TemplateRef: {
5705 std::pair<const TemplateDecl *, SourceLocation> P =
5706 getCursorTemplateRef(C);
5707 return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
5708 }
5709
5710 case CXCursor_NamespaceRef: {
5711 std::pair<const NamedDecl *, SourceLocation> P = getCursorNamespaceRef(C);
5712 return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
5713 }
5714
5715 case CXCursor_MemberRef: {
5716 std::pair<const FieldDecl *, SourceLocation> P = getCursorMemberRef(C);
5717 return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
5718 }
5719
5720 case CXCursor_VariableRef: {
5721 std::pair<const VarDecl *, SourceLocation> P = getCursorVariableRef(C);
5722 return cxloc::translateSourceLocation(P.first->getASTContext(), P.second);
5723 }
5724
5725 case CXCursor_CXXBaseSpecifier: {
5726 const CXXBaseSpecifier *BaseSpec = getCursorCXXBaseSpecifier(C);
5727 if (!BaseSpec)
5728 return clang_getNullLocation();
5729
5730 if (TypeSourceInfo *TSInfo = BaseSpec->getTypeSourceInfo())
5731 return cxloc::translateSourceLocation(getCursorContext(C),
5732 TSInfo->getTypeLoc().getBeginLoc());
5733
5734 return cxloc::translateSourceLocation(getCursorContext(C),
5735 BaseSpec->getLocStart());
5736 }
5737
5738 case CXCursor_LabelRef: {
5739 std::pair<const LabelStmt *, SourceLocation> P = getCursorLabelRef(C);
5740 return cxloc::translateSourceLocation(getCursorContext(C), P.second);
5741 }
5742
5743 case CXCursor_OverloadedDeclRef:
5744 return cxloc::translateSourceLocation(getCursorContext(C),
5745 getCursorOverloadedDeclRef(C).second);
5746
5747 default:
5748 // FIXME: Need a way to enumerate all non-reference cases.
5749 llvm_unreachable("Missed a reference kind")::llvm::llvm_unreachable_internal("Missed a reference kind", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 5749)
;
5750 }
5751 }
5752
5753 if (clang_isExpression(C.kind))
5754 return cxloc::translateSourceLocation(getCursorContext(C),
5755 getLocationFromExpr(getCursorExpr(C)));
5756
5757 if (clang_isStatement(C.kind))
5758 return cxloc::translateSourceLocation(getCursorContext(C),
5759 getCursorStmt(C)->getLocStart());
5760
5761 if (C.kind == CXCursor_PreprocessingDirective) {
5762 SourceLocation L = cxcursor::getCursorPreprocessingDirective(C).getBegin();
5763 return cxloc::translateSourceLocation(getCursorContext(C), L);
5764 }
5765
5766 if (C.kind == CXCursor_MacroExpansion) {
5767 SourceLocation L
5768 = cxcursor::getCursorMacroExpansion(C).getSourceRange().getBegin();
5769 return cxloc::translateSourceLocation(getCursorContext(C), L);
5770 }
5771
5772 if (C.kind == CXCursor_MacroDefinition) {
5773 SourceLocation L = cxcursor::getCursorMacroDefinition(C)->getLocation();
5774 return cxloc::translateSourceLocation(getCursorContext(C), L);
5775 }
5776
5777 if (C.kind == CXCursor_InclusionDirective) {
5778 SourceLocation L
5779 = cxcursor::getCursorInclusionDirective(C)->getSourceRange().getBegin();
5780 return cxloc::translateSourceLocation(getCursorContext(C), L);
5781 }
5782
5783 if (clang_isAttribute(C.kind)) {
5784 SourceLocation L
5785 = cxcursor::getCursorAttr(C)->getLocation();
5786 return cxloc::translateSourceLocation(getCursorContext(C), L);
5787 }
5788
5789 if (!clang_isDeclaration(C.kind))
5790 return clang_getNullLocation();
5791
5792 const Decl *D = getCursorDecl(C);
5793 if (!D)
5794 return clang_getNullLocation();
5795
5796 SourceLocation Loc = D->getLocation();
5797 // FIXME: Multiple variables declared in a single declaration
5798 // currently lack the information needed to correctly determine their
5799 // ranges when accounting for the type-specifier. We use context
5800 // stored in the CXCursor to determine if the VarDecl is in a DeclGroup,
5801 // and if so, whether it is the first decl.
5802 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
5803 if (!cxcursor::isFirstInDeclGroup(C))
5804 Loc = VD->getLocation();
5805 }
5806
5807 // For ObjC methods, give the start location of the method name.
5808 if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
5809 Loc = MD->getSelectorStartLoc();
5810
5811 return cxloc::translateSourceLocation(getCursorContext(C), Loc);
5812}
5813
5814} // end extern "C"
5815
5816CXCursor cxcursor::getCursor(CXTranslationUnit TU, SourceLocation SLoc) {
5817 assert(TU)(static_cast <bool> (TU) ? void (0) : __assert_fail ("TU"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 5817, __extension__ __PRETTY_FUNCTION__))
;
5818
5819 // Guard against an invalid SourceLocation, or we may assert in one
5820 // of the following calls.
5821 if (SLoc.isInvalid())
5822 return clang_getNullCursor();
5823
5824 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
5825
5826 // Translate the given source location to make it point at the beginning of
5827 // the token under the cursor.
5828 SLoc = Lexer::GetBeginningOfToken(SLoc, CXXUnit->getSourceManager(),
5829 CXXUnit->getASTContext().getLangOpts());
5830
5831 CXCursor Result = MakeCXCursorInvalid(CXCursor_NoDeclFound);
5832 if (SLoc.isValid()) {
5833 GetCursorData ResultData(CXXUnit->getSourceManager(), SLoc, Result);
5834 CursorVisitor CursorVis(TU, GetCursorVisitor, &ResultData,
5835 /*VisitPreprocessorLast=*/true,
5836 /*VisitIncludedEntities=*/false,
5837 SourceLocation(SLoc));
5838 CursorVis.visitFileRegion();
5839 }
5840
5841 return Result;
5842}
5843
5844static SourceRange getRawCursorExtent(CXCursor C) {
5845 if (clang_isReference(C.kind)) {
5846 switch (C.kind) {
5847 case CXCursor_ObjCSuperClassRef:
5848 return getCursorObjCSuperClassRef(C).second;
5849
5850 case CXCursor_ObjCProtocolRef:
5851 return getCursorObjCProtocolRef(C).second;
5852
5853 case CXCursor_ObjCClassRef:
5854 return getCursorObjCClassRef(C).second;
5855
5856 case CXCursor_TypeRef:
5857 return getCursorTypeRef(C).second;
5858
5859 case CXCursor_TemplateRef:
5860 return getCursorTemplateRef(C).second;
5861
5862 case CXCursor_NamespaceRef:
5863 return getCursorNamespaceRef(C).second;
5864
5865 case CXCursor_MemberRef:
5866 return getCursorMemberRef(C).second;
5867
5868 case CXCursor_CXXBaseSpecifier:
5869 return getCursorCXXBaseSpecifier(C)->getSourceRange();
5870
5871 case CXCursor_LabelRef:
5872 return getCursorLabelRef(C).second;
5873
5874 case CXCursor_OverloadedDeclRef:
5875 return getCursorOverloadedDeclRef(C).second;
5876
5877 case CXCursor_VariableRef:
5878 return getCursorVariableRef(C).second;
5879
5880 default:
5881 // FIXME: Need a way to enumerate all non-reference cases.
5882 llvm_unreachable("Missed a reference kind")::llvm::llvm_unreachable_internal("Missed a reference kind", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 5882)
;
5883 }
5884 }
5885
5886 if (clang_isExpression(C.kind))
5887 return getCursorExpr(C)->getSourceRange();
5888
5889 if (clang_isStatement(C.kind))
5890 return getCursorStmt(C)->getSourceRange();
5891
5892 if (clang_isAttribute(C.kind))
5893 return getCursorAttr(C)->getRange();
5894
5895 if (C.kind == CXCursor_PreprocessingDirective)
5896 return cxcursor::getCursorPreprocessingDirective(C);
5897
5898 if (C.kind == CXCursor_MacroExpansion) {
5899 ASTUnit *TU = getCursorASTUnit(C);
5900 SourceRange Range = cxcursor::getCursorMacroExpansion(C).getSourceRange();
5901 return TU->mapRangeFromPreamble(Range);
5902 }
5903
5904 if (C.kind == CXCursor_MacroDefinition) {
5905 ASTUnit *TU = getCursorASTUnit(C);
5906 SourceRange Range = cxcursor::getCursorMacroDefinition(C)->getSourceRange();
5907 return TU->mapRangeFromPreamble(Range);
5908 }
5909
5910 if (C.kind == CXCursor_InclusionDirective) {
5911 ASTUnit *TU = getCursorASTUnit(C);
5912 SourceRange Range = cxcursor::getCursorInclusionDirective(C)->getSourceRange();
5913 return TU->mapRangeFromPreamble(Range);
5914 }
5915
5916 if (C.kind == CXCursor_TranslationUnit) {
5917 ASTUnit *TU = getCursorASTUnit(C);
5918 FileID MainID = TU->getSourceManager().getMainFileID();
5919 SourceLocation Start = TU->getSourceManager().getLocForStartOfFile(MainID);
5920 SourceLocation End = TU->getSourceManager().getLocForEndOfFile(MainID);
5921 return SourceRange(Start, End);
5922 }
5923
5924 if (clang_isDeclaration(C.kind)) {
5925 const Decl *D = cxcursor::getCursorDecl(C);
5926 if (!D)
5927 return SourceRange();
5928
5929 SourceRange R = D->getSourceRange();
5930 // FIXME: Multiple variables declared in a single declaration
5931 // currently lack the information needed to correctly determine their
5932 // ranges when accounting for the type-specifier. We use context
5933 // stored in the CXCursor to determine if the VarDecl is in a DeclGroup,
5934 // and if so, whether it is the first decl.
5935 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
5936 if (!cxcursor::isFirstInDeclGroup(C))
5937 R.setBegin(VD->getLocation());
5938 }
5939 return R;
5940 }
5941 return SourceRange();
5942}
5943
5944/// \brief Retrieves the "raw" cursor extent, which is then extended to include
5945/// the decl-specifier-seq for declarations.
5946static SourceRange getFullCursorExtent(CXCursor C, SourceManager &SrcMgr) {
5947 if (clang_isDeclaration(C.kind)) {
5948 const Decl *D = cxcursor::getCursorDecl(C);
5949 if (!D)
5950 return SourceRange();
5951
5952 SourceRange R = D->getSourceRange();
5953
5954 // Adjust the start of the location for declarations preceded by
5955 // declaration specifiers.
5956 SourceLocation StartLoc;
5957 if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
5958 if (TypeSourceInfo *TI = DD->getTypeSourceInfo())
5959 StartLoc = TI->getTypeLoc().getLocStart();
5960 } else if (const TypedefDecl *Typedef = dyn_cast<TypedefDecl>(D)) {
5961 if (TypeSourceInfo *TI = Typedef->getTypeSourceInfo())
5962 StartLoc = TI->getTypeLoc().getLocStart();
5963 }
5964
5965 if (StartLoc.isValid() && R.getBegin().isValid() &&
5966 SrcMgr.isBeforeInTranslationUnit(StartLoc, R.getBegin()))
5967 R.setBegin(StartLoc);
5968
5969 // FIXME: Multiple variables declared in a single declaration
5970 // currently lack the information needed to correctly determine their
5971 // ranges when accounting for the type-specifier. We use context
5972 // stored in the CXCursor to determine if the VarDecl is in a DeclGroup,
5973 // and if so, whether it is the first decl.
5974 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
5975 if (!cxcursor::isFirstInDeclGroup(C))
5976 R.setBegin(VD->getLocation());
5977 }
5978
5979 return R;
5980 }
5981
5982 return getRawCursorExtent(C);
5983}
5984
5985CXSourceRange clang_getCursorExtent(CXCursor C) {
5986 SourceRange R = getRawCursorExtent(C);
5987 if (R.isInvalid())
5988 return clang_getNullRange();
5989
5990 return cxloc::translateSourceRange(getCursorContext(C), R);
5991}
5992
5993CXCursor clang_getCursorReferenced(CXCursor C) {
5994 if (clang_isInvalid(C.kind))
5995 return clang_getNullCursor();
5996
5997 CXTranslationUnit tu = getCursorTU(C);
5998 if (clang_isDeclaration(C.kind)) {
5999 const Decl *D = getCursorDecl(C);
6000 if (!D)
6001 return clang_getNullCursor();
6002 if (const UsingDecl *Using = dyn_cast<UsingDecl>(D))
6003 return MakeCursorOverloadedDeclRef(Using, D->getLocation(), tu);
6004 if (const ObjCPropertyImplDecl *PropImpl =
6005 dyn_cast<ObjCPropertyImplDecl>(D))
6006 if (ObjCPropertyDecl *Property = PropImpl->getPropertyDecl())
6007 return MakeCXCursor(Property, tu);
6008
6009 return C;
6010 }
6011
6012 if (clang_isExpression(C.kind)) {
6013 const Expr *E = getCursorExpr(C);
6014 const Decl *D = getDeclFromExpr(E);
6015 if (D) {
6016 CXCursor declCursor = MakeCXCursor(D, tu);
6017 declCursor = getSelectorIdentifierCursor(getSelectorIdentifierIndex(C),
6018 declCursor);
6019 return declCursor;
6020 }
6021
6022 if (const OverloadExpr *Ovl = dyn_cast_or_null<OverloadExpr>(E))
6023 return MakeCursorOverloadedDeclRef(Ovl, tu);
6024
6025 return clang_getNullCursor();
6026 }
6027
6028 if (clang_isStatement(C.kind)) {
6029 const Stmt *S = getCursorStmt(C);
6030 if (const GotoStmt *Goto = dyn_cast_or_null<GotoStmt>(S))
6031 if (LabelDecl *label = Goto->getLabel())
6032 if (LabelStmt *labelS = label->getStmt())
6033 return MakeCXCursor(labelS, getCursorDecl(C), tu);
6034
6035 return clang_getNullCursor();
6036 }
6037
6038 if (C.kind == CXCursor_MacroExpansion) {
6039 if (const MacroDefinitionRecord *Def =
6040 getCursorMacroExpansion(C).getDefinition())
6041 return MakeMacroDefinitionCursor(Def, tu);
6042 }
6043
6044 if (!clang_isReference(C.kind))
6045 return clang_getNullCursor();
6046
6047 switch (C.kind) {
6048 case CXCursor_ObjCSuperClassRef:
6049 return MakeCXCursor(getCursorObjCSuperClassRef(C).first, tu);
6050
6051 case CXCursor_ObjCProtocolRef: {
6052 const ObjCProtocolDecl *Prot = getCursorObjCProtocolRef(C).first;
6053 if (const ObjCProtocolDecl *Def = Prot->getDefinition())
6054 return MakeCXCursor(Def, tu);
6055
6056 return MakeCXCursor(Prot, tu);
6057 }
6058
6059 case CXCursor_ObjCClassRef: {
6060 const ObjCInterfaceDecl *Class = getCursorObjCClassRef(C).first;
6061 if (const ObjCInterfaceDecl *Def = Class->getDefinition())
6062 return MakeCXCursor(Def, tu);
6063
6064 return MakeCXCursor(Class, tu);
6065 }
6066
6067 case CXCursor_TypeRef:
6068 return MakeCXCursor(getCursorTypeRef(C).first, tu );
6069
6070 case CXCursor_TemplateRef:
6071 return MakeCXCursor(getCursorTemplateRef(C).first, tu );
6072
6073 case CXCursor_NamespaceRef:
6074 return MakeCXCursor(getCursorNamespaceRef(C).first, tu );
6075
6076 case CXCursor_MemberRef:
6077 return MakeCXCursor(getCursorMemberRef(C).first, tu );
6078
6079 case CXCursor_CXXBaseSpecifier: {
6080 const CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C);
6081 return clang_getTypeDeclaration(cxtype::MakeCXType(B->getType(),
6082 tu ));
6083 }
6084
6085 case CXCursor_LabelRef:
6086 // FIXME: We end up faking the "parent" declaration here because we
6087 // don't want to make CXCursor larger.
6088 return MakeCXCursor(getCursorLabelRef(C).first,
6089 cxtu::getASTUnit(tu)->getASTContext()
6090 .getTranslationUnitDecl(),
6091 tu);
6092
6093 case CXCursor_OverloadedDeclRef:
6094 return C;
6095
6096 case CXCursor_VariableRef:
6097 return MakeCXCursor(getCursorVariableRef(C).first, tu);
6098
6099 default:
6100 // We would prefer to enumerate all non-reference cursor kinds here.
6101 llvm_unreachable("Unhandled reference cursor kind")::llvm::llvm_unreachable_internal("Unhandled reference cursor kind"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6101)
;
6102 }
6103}
6104
6105CXCursor clang_getCursorDefinition(CXCursor C) {
6106 if (clang_isInvalid(C.kind))
6107 return clang_getNullCursor();
6108
6109 CXTranslationUnit TU = getCursorTU(C);
6110
6111 bool WasReference = false;
6112 if (clang_isReference(C.kind) || clang_isExpression(C.kind)) {
6113 C = clang_getCursorReferenced(C);
6114 WasReference = true;
6115 }
6116
6117 if (C.kind == CXCursor_MacroExpansion)
6118 return clang_getCursorReferenced(C);
6119
6120 if (!clang_isDeclaration(C.kind))
6121 return clang_getNullCursor();
6122
6123 const Decl *D = getCursorDecl(C);
6124 if (!D)
6125 return clang_getNullCursor();
6126
6127 switch (D->getKind()) {
6128 // Declaration kinds that don't really separate the notions of
6129 // declaration and definition.
6130 case Decl::Namespace:
6131 case Decl::Typedef:
6132 case Decl::TypeAlias:
6133 case Decl::TypeAliasTemplate:
6134 case Decl::TemplateTypeParm:
6135 case Decl::EnumConstant:
6136 case Decl::Field:
6137 case Decl::Binding:
6138 case Decl::MSProperty:
6139 case Decl::IndirectField:
6140 case Decl::ObjCIvar:
6141 case Decl::ObjCAtDefsField:
6142 case Decl::ImplicitParam:
6143 case Decl::ParmVar:
6144 case Decl::NonTypeTemplateParm:
6145 case Decl::TemplateTemplateParm:
6146 case Decl::ObjCCategoryImpl:
6147 case Decl::ObjCImplementation:
6148 case Decl::AccessSpec:
6149 case Decl::LinkageSpec:
6150 case Decl::Export:
6151 case Decl::ObjCPropertyImpl:
6152 case Decl::FileScopeAsm:
6153 case Decl::StaticAssert:
6154 case Decl::Block:
6155 case Decl::Captured:
6156 case Decl::OMPCapturedExpr:
6157 case Decl::Label: // FIXME: Is this right??
6158 case Decl::ClassScopeFunctionSpecialization:
6159 case Decl::CXXDeductionGuide:
6160 case Decl::Import:
6161 case Decl::OMPThreadPrivate:
6162 case Decl::OMPDeclareReduction:
6163 case Decl::ObjCTypeParam:
6164 case Decl::BuiltinTemplate:
6165 case Decl::PragmaComment:
6166 case Decl::PragmaDetectMismatch:
6167 case Decl::UsingPack:
6168 return C;
6169
6170 // Declaration kinds that don't make any sense here, but are
6171 // nonetheless harmless.
6172 case Decl::Empty:
6173 case Decl::TranslationUnit:
6174 case Decl::ExternCContext:
6175 break;
6176
6177 // Declaration kinds for which the definition is not resolvable.
6178 case Decl::UnresolvedUsingTypename:
6179 case Decl::UnresolvedUsingValue:
6180 break;
6181
6182 case Decl::UsingDirective:
6183 return MakeCXCursor(cast<UsingDirectiveDecl>(D)->getNominatedNamespace(),
6184 TU);
6185
6186 case Decl::NamespaceAlias:
6187 return MakeCXCursor(cast<NamespaceAliasDecl>(D)->getNamespace(), TU);
6188
6189 case Decl::Enum:
6190 case Decl::Record:
6191 case Decl::CXXRecord:
6192 case Decl::ClassTemplateSpecialization:
6193 case Decl::ClassTemplatePartialSpecialization:
6194 if (TagDecl *Def = cast<TagDecl>(D)->getDefinition())
6195 return MakeCXCursor(Def, TU);
6196 return clang_getNullCursor();
6197
6198 case Decl::Function:
6199 case Decl::CXXMethod:
6200 case Decl::CXXConstructor:
6201 case Decl::CXXDestructor:
6202 case Decl::CXXConversion: {
6203 const FunctionDecl *Def = nullptr;
6204 if (cast<FunctionDecl>(D)->getBody(Def))
6205 return MakeCXCursor(Def, TU);
6206 return clang_getNullCursor();
6207 }
6208
6209 case Decl::Var:
6210 case Decl::VarTemplateSpecialization:
6211 case Decl::VarTemplatePartialSpecialization:
6212 case Decl::Decomposition: {
6213 // Ask the variable if it has a definition.
6214 if (const VarDecl *Def = cast<VarDecl>(D)->getDefinition())
6215 return MakeCXCursor(Def, TU);
6216 return clang_getNullCursor();
6217 }
6218
6219 case Decl::FunctionTemplate: {
6220 const FunctionDecl *Def = nullptr;
6221 if (cast<FunctionTemplateDecl>(D)->getTemplatedDecl()->getBody(Def))
6222 return MakeCXCursor(Def->getDescribedFunctionTemplate(), TU);
6223 return clang_getNullCursor();
6224 }
6225
6226 case Decl::ClassTemplate: {
6227 if (RecordDecl *Def = cast<ClassTemplateDecl>(D)->getTemplatedDecl()
6228 ->getDefinition())
6229 return MakeCXCursor(cast<CXXRecordDecl>(Def)->getDescribedClassTemplate(),
6230 TU);
6231 return clang_getNullCursor();
6232 }
6233
6234 case Decl::VarTemplate: {
6235 if (VarDecl *Def =
6236 cast<VarTemplateDecl>(D)->getTemplatedDecl()->getDefinition())
6237 return MakeCXCursor(cast<VarDecl>(Def)->getDescribedVarTemplate(), TU);
6238 return clang_getNullCursor();
6239 }
6240
6241 case Decl::Using:
6242 return MakeCursorOverloadedDeclRef(cast<UsingDecl>(D),
6243 D->getLocation(), TU);
6244
6245 case Decl::UsingShadow:
6246 case Decl::ConstructorUsingShadow:
6247 return clang_getCursorDefinition(
6248 MakeCXCursor(cast<UsingShadowDecl>(D)->getTargetDecl(),
6249 TU));
6250
6251 case Decl::ObjCMethod: {
6252 const ObjCMethodDecl *Method = cast<ObjCMethodDecl>(D);
6253 if (Method->isThisDeclarationADefinition())
6254 return C;
6255
6256 // Dig out the method definition in the associated
6257 // @implementation, if we have it.
6258 // FIXME: The ASTs should make finding the definition easier.
6259 if (const ObjCInterfaceDecl *Class
6260 = dyn_cast<ObjCInterfaceDecl>(Method->getDeclContext()))
6261 if (ObjCImplementationDecl *ClassImpl = Class->getImplementation())
6262 if (ObjCMethodDecl *Def = ClassImpl->getMethod(Method->getSelector(),
6263 Method->isInstanceMethod()))
6264 if (Def->isThisDeclarationADefinition())
6265 return MakeCXCursor(Def, TU);
6266
6267 return clang_getNullCursor();
6268 }
6269
6270 case Decl::ObjCCategory:
6271 if (ObjCCategoryImplDecl *Impl
6272 = cast<ObjCCategoryDecl>(D)->getImplementation())
6273 return MakeCXCursor(Impl, TU);
6274 return clang_getNullCursor();
6275
6276 case Decl::ObjCProtocol:
6277 if (const ObjCProtocolDecl *Def = cast<ObjCProtocolDecl>(D)->getDefinition())
6278 return MakeCXCursor(Def, TU);
6279 return clang_getNullCursor();
6280
6281 case Decl::ObjCInterface: {
6282 // There are two notions of a "definition" for an Objective-C
6283 // class: the interface and its implementation. When we resolved a
6284 // reference to an Objective-C class, produce the @interface as
6285 // the definition; when we were provided with the interface,
6286 // produce the @implementation as the definition.
6287 const ObjCInterfaceDecl *IFace = cast<ObjCInterfaceDecl>(D);
6288 if (WasReference) {
6289 if (const ObjCInterfaceDecl *Def = IFace->getDefinition())
6290 return MakeCXCursor(Def, TU);
6291 } else if (ObjCImplementationDecl *Impl = IFace->getImplementation())
6292 return MakeCXCursor(Impl, TU);
6293 return clang_getNullCursor();
6294 }
6295
6296 case Decl::ObjCProperty:
6297 // FIXME: We don't really know where to find the
6298 // ObjCPropertyImplDecls that implement this property.
6299 return clang_getNullCursor();
6300
6301 case Decl::ObjCCompatibleAlias:
6302 if (const ObjCInterfaceDecl *Class
6303 = cast<ObjCCompatibleAliasDecl>(D)->getClassInterface())
6304 if (const ObjCInterfaceDecl *Def = Class->getDefinition())
6305 return MakeCXCursor(Def, TU);
6306
6307 return clang_getNullCursor();
6308
6309 case Decl::Friend:
6310 if (NamedDecl *Friend = cast<FriendDecl>(D)->getFriendDecl())
6311 return clang_getCursorDefinition(MakeCXCursor(Friend, TU));
6312 return clang_getNullCursor();
6313
6314 case Decl::FriendTemplate:
6315 if (NamedDecl *Friend = cast<FriendTemplateDecl>(D)->getFriendDecl())
6316 return clang_getCursorDefinition(MakeCXCursor(Friend, TU));
6317 return clang_getNullCursor();
6318 }
6319
6320 return clang_getNullCursor();
6321}
6322
6323unsigned clang_isCursorDefinition(CXCursor C) {
6324 if (!clang_isDeclaration(C.kind))
6325 return 0;
6326
6327 return clang_getCursorDefinition(C) == C;
6328}
6329
6330CXCursor clang_getCanonicalCursor(CXCursor C) {
6331 if (!clang_isDeclaration(C.kind))
6332 return C;
6333
6334 if (const Decl *D = getCursorDecl(C)) {
6335 if (const ObjCCategoryImplDecl *CatImplD = dyn_cast<ObjCCategoryImplDecl>(D))
6336 if (ObjCCategoryDecl *CatD = CatImplD->getCategoryDecl())
6337 return MakeCXCursor(CatD, getCursorTU(C));
6338
6339 if (const ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D))
6340 if (const ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
6341 return MakeCXCursor(IFD, getCursorTU(C));
6342
6343 return MakeCXCursor(D->getCanonicalDecl(), getCursorTU(C));
6344 }
6345
6346 return C;
6347}
6348
6349int clang_Cursor_getObjCSelectorIndex(CXCursor cursor) {
6350 return cxcursor::getSelectorIdentifierIndexAndLoc(cursor).first;
6351}
6352
6353unsigned clang_getNumOverloadedDecls(CXCursor C) {
6354 if (C.kind != CXCursor_OverloadedDeclRef)
6355 return 0;
6356
6357 OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(C).first;
6358 if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
6359 return E->getNumDecls();
6360
6361 if (OverloadedTemplateStorage *S
6362 = Storage.dyn_cast<OverloadedTemplateStorage*>())
6363 return S->size();
6364
6365 const Decl *D = Storage.get<const Decl *>();
6366 if (const UsingDecl *Using = dyn_cast<UsingDecl>(D))
6367 return Using->shadow_size();
6368
6369 return 0;
6370}
6371
6372CXCursor clang_getOverloadedDecl(CXCursor cursor, unsigned index) {
6373 if (cursor.kind != CXCursor_OverloadedDeclRef)
6374 return clang_getNullCursor();
6375
6376 if (index >= clang_getNumOverloadedDecls(cursor))
6377 return clang_getNullCursor();
6378
6379 CXTranslationUnit TU = getCursorTU(cursor);
6380 OverloadedDeclRefStorage Storage = getCursorOverloadedDeclRef(cursor).first;
6381 if (const OverloadExpr *E = Storage.dyn_cast<const OverloadExpr *>())
6382 return MakeCXCursor(E->decls_begin()[index], TU);
6383
6384 if (OverloadedTemplateStorage *S
6385 = Storage.dyn_cast<OverloadedTemplateStorage*>())
6386 return MakeCXCursor(S->begin()[index], TU);
6387
6388 const Decl *D = Storage.get<const Decl *>();
6389 if (const UsingDecl *Using = dyn_cast<UsingDecl>(D)) {
6390 // FIXME: This is, unfortunately, linear time.
6391 UsingDecl::shadow_iterator Pos = Using->shadow_begin();
6392 std::advance(Pos, index);
6393 return MakeCXCursor(cast<UsingShadowDecl>(*Pos)->getTargetDecl(), TU);
6394 }
6395
6396 return clang_getNullCursor();
6397}
6398
6399void clang_getDefinitionSpellingAndExtent(CXCursor C,
6400 const char **startBuf,
6401 const char **endBuf,
6402 unsigned *startLine,
6403 unsigned *startColumn,
6404 unsigned *endLine,
6405 unsigned *endColumn) {
6406 assert(getCursorDecl(C) && "CXCursor has null decl")(static_cast <bool> (getCursorDecl(C) && "CXCursor has null decl"
) ? void (0) : __assert_fail ("getCursorDecl(C) && \"CXCursor has null decl\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6406, __extension__ __PRETTY_FUNCTION__))
;
6407 const FunctionDecl *FD = dyn_cast<FunctionDecl>(getCursorDecl(C));
6408 CompoundStmt *Body = dyn_cast<CompoundStmt>(FD->getBody());
6409
6410 SourceManager &SM = FD->getASTContext().getSourceManager();
6411 *startBuf = SM.getCharacterData(Body->getLBracLoc());
6412 *endBuf = SM.getCharacterData(Body->getRBracLoc());
6413 *startLine = SM.getSpellingLineNumber(Body->getLBracLoc());
6414 *startColumn = SM.getSpellingColumnNumber(Body->getLBracLoc());
6415 *endLine = SM.getSpellingLineNumber(Body->getRBracLoc());
6416 *endColumn = SM.getSpellingColumnNumber(Body->getRBracLoc());
6417}
6418
6419
6420CXSourceRange clang_getCursorReferenceNameRange(CXCursor C, unsigned NameFlags,
6421 unsigned PieceIndex) {
6422 RefNamePieces Pieces;
6423
6424 switch (C.kind) {
6425 case CXCursor_MemberRefExpr:
6426 if (const MemberExpr *E = dyn_cast<MemberExpr>(getCursorExpr(C)))
6427 Pieces = buildPieces(NameFlags, true, E->getMemberNameInfo(),
6428 E->getQualifierLoc().getSourceRange());
6429 break;
6430
6431 case CXCursor_DeclRefExpr:
6432 if (const DeclRefExpr *E = dyn_cast<DeclRefExpr>(getCursorExpr(C))) {
6433 SourceRange TemplateArgLoc(E->getLAngleLoc(), E->getRAngleLoc());
6434 Pieces =
6435 buildPieces(NameFlags, false, E->getNameInfo(),
6436 E->getQualifierLoc().getSourceRange(), &TemplateArgLoc);
6437 }
6438 break;
6439
6440 case CXCursor_CallExpr:
6441 if (const CXXOperatorCallExpr *OCE =
6442 dyn_cast<CXXOperatorCallExpr>(getCursorExpr(C))) {
6443 const Expr *Callee = OCE->getCallee();
6444 if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
6445 Callee = ICE->getSubExpr();
6446
6447 if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee))
6448 Pieces = buildPieces(NameFlags, false, DRE->getNameInfo(),
6449 DRE->getQualifierLoc().getSourceRange());
6450 }
6451 break;
6452
6453 default:
6454 break;
6455 }
6456
6457 if (Pieces.empty()) {
6458 if (PieceIndex == 0)
6459 return clang_getCursorExtent(C);
6460 } else if (PieceIndex < Pieces.size()) {
6461 SourceRange R = Pieces[PieceIndex];
6462 if (R.isValid())
6463 return cxloc::translateSourceRange(getCursorContext(C), R);
6464 }
6465
6466 return clang_getNullRange();
6467}
6468
6469void clang_enableStackTraces(void) {
6470 // FIXME: Provide an argv0 here so we can find llvm-symbolizer.
6471 llvm::sys::PrintStackTraceOnErrorSignal(StringRef());
6472}
6473
6474void clang_executeOnThread(void (*fn)(void*), void *user_data,
6475 unsigned stack_size) {
6476 llvm::llvm_execute_on_thread(fn, user_data, stack_size);
6477}
6478
6479//===----------------------------------------------------------------------===//
6480// Token-based Operations.
6481//===----------------------------------------------------------------------===//
6482
6483/* CXToken layout:
6484 * int_data[0]: a CXTokenKind
6485 * int_data[1]: starting token location
6486 * int_data[2]: token length
6487 * int_data[3]: reserved
6488 * ptr_data: for identifiers and keywords, an IdentifierInfo*.
6489 * otherwise unused.
6490 */
6491CXTokenKind clang_getTokenKind(CXToken CXTok) {
6492 return static_cast<CXTokenKind>(CXTok.int_data[0]);
6493}
6494
6495CXString clang_getTokenSpelling(CXTranslationUnit TU, CXToken CXTok) {
6496 switch (clang_getTokenKind(CXTok)) {
6497 case CXToken_Identifier:
6498 case CXToken_Keyword:
6499 // We know we have an IdentifierInfo*, so use that.
6500 return cxstring::createRef(static_cast<IdentifierInfo *>(CXTok.ptr_data)
6501 ->getNameStart());
6502
6503 case CXToken_Literal: {
6504 // We have stashed the starting pointer in the ptr_data field. Use it.
6505 const char *Text = static_cast<const char *>(CXTok.ptr_data);
6506 return cxstring::createDup(StringRef(Text, CXTok.int_data[2]));
6507 }
6508
6509 case CXToken_Punctuation:
6510 case CXToken_Comment:
6511 break;
6512 }
6513
6514 if (isNotUsableTU(TU)) {
6515 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
6516 return cxstring::createEmpty();
6517 }
6518
6519 // We have to find the starting buffer pointer the hard way, by
6520 // deconstructing the source location.
6521 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
6522 if (!CXXUnit)
6523 return cxstring::createEmpty();
6524
6525 SourceLocation Loc = SourceLocation::getFromRawEncoding(CXTok.int_data[1]);
6526 std::pair<FileID, unsigned> LocInfo
6527 = CXXUnit->getSourceManager().getDecomposedSpellingLoc(Loc);
6528 bool Invalid = false;
6529 StringRef Buffer
6530 = CXXUnit->getSourceManager().getBufferData(LocInfo.first, &Invalid);
6531 if (Invalid)
6532 return cxstring::createEmpty();
6533
6534 return cxstring::createDup(Buffer.substr(LocInfo.second, CXTok.int_data[2]));
6535}
6536
6537CXSourceLocation clang_getTokenLocation(CXTranslationUnit TU, CXToken CXTok) {
6538 if (isNotUsableTU(TU)) {
6539 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
6540 return clang_getNullLocation();
6541 }
6542
6543 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
6544 if (!CXXUnit)
6545 return clang_getNullLocation();
6546
6547 return cxloc::translateSourceLocation(CXXUnit->getASTContext(),
6548 SourceLocation::getFromRawEncoding(CXTok.int_data[1]));
6549}
6550
6551CXSourceRange clang_getTokenExtent(CXTranslationUnit TU, CXToken CXTok) {
6552 if (isNotUsableTU(TU)) {
6553 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
6554 return clang_getNullRange();
6555 }
6556
6557 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
6558 if (!CXXUnit)
6559 return clang_getNullRange();
6560
6561 return cxloc::translateSourceRange(CXXUnit->getASTContext(),
6562 SourceLocation::getFromRawEncoding(CXTok.int_data[1]));
6563}
6564
6565static void getTokens(ASTUnit *CXXUnit, SourceRange Range,
6566 SmallVectorImpl<CXToken> &CXTokens) {
6567 SourceManager &SourceMgr = CXXUnit->getSourceManager();
6568 std::pair<FileID, unsigned> BeginLocInfo
6569 = SourceMgr.getDecomposedSpellingLoc(Range.getBegin());
6570 std::pair<FileID, unsigned> EndLocInfo
6571 = SourceMgr.getDecomposedSpellingLoc(Range.getEnd());
6572
6573 // Cannot tokenize across files.
6574 if (BeginLocInfo.first != EndLocInfo.first)
6575 return;
6576
6577 // Create a lexer
6578 bool Invalid = false;
6579 StringRef Buffer
6580 = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
6581 if (Invalid)
6582 return;
6583
6584 Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
6585 CXXUnit->getASTContext().getLangOpts(),
6586 Buffer.begin(), Buffer.data() + BeginLocInfo.second, Buffer.end());
6587 Lex.SetCommentRetentionState(true);
6588
6589 // Lex tokens until we hit the end of the range.
6590 const char *EffectiveBufferEnd = Buffer.data() + EndLocInfo.second;
6591 Token Tok;
6592 bool previousWasAt = false;
6593 do {
6594 // Lex the next token
6595 Lex.LexFromRawLexer(Tok);
6596 if (Tok.is(tok::eof))
6597 break;
6598
6599 // Initialize the CXToken.
6600 CXToken CXTok;
6601
6602 // - Common fields
6603 CXTok.int_data[1] = Tok.getLocation().getRawEncoding();
6604 CXTok.int_data[2] = Tok.getLength();
6605 CXTok.int_data[3] = 0;
6606
6607 // - Kind-specific fields
6608 if (Tok.isLiteral()) {
6609 CXTok.int_data[0] = CXToken_Literal;
6610 CXTok.ptr_data = const_cast<char *>(Tok.getLiteralData());
6611 } else if (Tok.is(tok::raw_identifier)) {
6612 // Lookup the identifier to determine whether we have a keyword.
6613 IdentifierInfo *II
6614 = CXXUnit->getPreprocessor().LookUpIdentifierInfo(Tok);
6615
6616 if ((II->getObjCKeywordID() != tok::objc_not_keyword) && previousWasAt) {
6617 CXTok.int_data[0] = CXToken_Keyword;
6618 }
6619 else {
6620 CXTok.int_data[0] = Tok.is(tok::identifier)
6621 ? CXToken_Identifier
6622 : CXToken_Keyword;
6623 }
6624 CXTok.ptr_data = II;
6625 } else if (Tok.is(tok::comment)) {
6626 CXTok.int_data[0] = CXToken_Comment;
6627 CXTok.ptr_data = nullptr;
6628 } else {
6629 CXTok.int_data[0] = CXToken_Punctuation;
6630 CXTok.ptr_data = nullptr;
6631 }
6632 CXTokens.push_back(CXTok);
6633 previousWasAt = Tok.is(tok::at);
6634 } while (Lex.getBufferLocation() < EffectiveBufferEnd);
6635}
6636
6637void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
6638 CXToken **Tokens, unsigned *NumTokens) {
6639 LOG_FUNC_SECTIONif (clang::cxindex::LogRef Log = clang::cxindex::Logger::make
(__func__))
{
6640 *Log << TU << ' ' << Range;
6641 }
6642
6643 if (Tokens)
6644 *Tokens = nullptr;
6645 if (NumTokens)
6646 *NumTokens = 0;
6647
6648 if (isNotUsableTU(TU)) {
6649 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
6650 return;
6651 }
6652
6653 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
6654 if (!CXXUnit || !Tokens || !NumTokens)
6655 return;
6656
6657 ASTUnit::ConcurrencyCheck Check(*CXXUnit);
6658
6659 SourceRange R = cxloc::translateCXSourceRange(Range);
6660 if (R.isInvalid())
6661 return;
6662
6663 SmallVector<CXToken, 32> CXTokens;
6664 getTokens(CXXUnit, R, CXTokens);
6665
6666 if (CXTokens.empty())
6667 return;
6668
6669 *Tokens = static_cast<CXToken *>(
6670 llvm::safe_malloc(sizeof(CXToken) * CXTokens.size()));
6671 memmove(*Tokens, CXTokens.data(), sizeof(CXToken) * CXTokens.size());
6672 *NumTokens = CXTokens.size();
6673}
6674
6675void clang_disposeTokens(CXTranslationUnit TU,
6676 CXToken *Tokens, unsigned NumTokens) {
6677 free(Tokens);
6678}
6679
6680//===----------------------------------------------------------------------===//
6681// Token annotation APIs.
6682//===----------------------------------------------------------------------===//
6683
6684static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor,
6685 CXCursor parent,
6686 CXClientData client_data);
6687static bool AnnotateTokensPostChildrenVisitor(CXCursor cursor,
6688 CXClientData client_data);
6689
6690namespace {
6691class AnnotateTokensWorker {
6692 CXToken *Tokens;
6693 CXCursor *Cursors;
6694 unsigned NumTokens;
6695 unsigned TokIdx;
6696 unsigned PreprocessingTokIdx;
6697 CursorVisitor AnnotateVis;
6698 SourceManager &SrcMgr;
6699 bool HasContextSensitiveKeywords;
6700
6701 struct PostChildrenInfo {
6702 CXCursor Cursor;
6703 SourceRange CursorRange;
6704 unsigned BeforeReachingCursorIdx;
6705 unsigned BeforeChildrenTokenIdx;
6706 };
6707 SmallVector<PostChildrenInfo, 8> PostChildrenInfos;
6708
6709 CXToken &getTok(unsigned Idx) {
6710 assert(Idx < NumTokens)(static_cast <bool> (Idx < NumTokens) ? void (0) : __assert_fail
("Idx < NumTokens", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6710, __extension__ __PRETTY_FUNCTION__))
;
6711 return Tokens[Idx];
6712 }
6713 const CXToken &getTok(unsigned Idx) const {
6714 assert(Idx < NumTokens)(static_cast <bool> (Idx < NumTokens) ? void (0) : __assert_fail
("Idx < NumTokens", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6714, __extension__ __PRETTY_FUNCTION__))
;
6715 return Tokens[Idx];
6716 }
6717 bool MoreTokens() const { return TokIdx < NumTokens; }
6718 unsigned NextToken() const { return TokIdx; }
6719 void AdvanceToken() { ++TokIdx; }
6720 SourceLocation GetTokenLoc(unsigned tokI) {
6721 return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]);
6722 }
6723 bool isFunctionMacroToken(unsigned tokI) const {
6724 return getTok(tokI).int_data[3] != 0;
6725 }
6726 SourceLocation getFunctionMacroTokenLoc(unsigned tokI) const {
6727 return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[3]);
6728 }
6729
6730 void annotateAndAdvanceTokens(CXCursor, RangeComparisonResult, SourceRange);
6731 bool annotateAndAdvanceFunctionMacroTokens(CXCursor, RangeComparisonResult,
6732 SourceRange);
6733
6734public:
6735 AnnotateTokensWorker(CXToken *tokens, CXCursor *cursors, unsigned numTokens,
6736 CXTranslationUnit TU, SourceRange RegionOfInterest)
6737 : Tokens(tokens), Cursors(cursors),
6738 NumTokens(numTokens), TokIdx(0), PreprocessingTokIdx(0),
6739 AnnotateVis(TU,
6740 AnnotateTokensVisitor, this,
6741 /*VisitPreprocessorLast=*/true,
6742 /*VisitIncludedEntities=*/false,
6743 RegionOfInterest,
6744 /*VisitDeclsOnly=*/false,
6745 AnnotateTokensPostChildrenVisitor),
6746 SrcMgr(cxtu::getASTUnit(TU)->getSourceManager()),
6747 HasContextSensitiveKeywords(false) { }
6748
6749 void VisitChildren(CXCursor C) { AnnotateVis.VisitChildren(C); }
6750 enum CXChildVisitResult Visit(CXCursor cursor, CXCursor parent);
6751 bool postVisitChildren(CXCursor cursor);
6752 void AnnotateTokens();
6753
6754 /// \brief Determine whether the annotator saw any cursors that have
6755 /// context-sensitive keywords.
6756 bool hasContextSensitiveKeywords() const {
6757 return HasContextSensitiveKeywords;
6758 }
6759
6760 ~AnnotateTokensWorker() {
6761 assert(PostChildrenInfos.empty())(static_cast <bool> (PostChildrenInfos.empty()) ? void (
0) : __assert_fail ("PostChildrenInfos.empty()", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6761, __extension__ __PRETTY_FUNCTION__))
;
6762 }
6763};
6764}
6765
6766void AnnotateTokensWorker::AnnotateTokens() {
6767 // Walk the AST within the region of interest, annotating tokens
6768 // along the way.
6769 AnnotateVis.visitFileRegion();
6770}
6771
6772static inline void updateCursorAnnotation(CXCursor &Cursor,
6773 const CXCursor &updateC) {
6774 if (clang_isInvalid(updateC.kind) || !clang_isInvalid(Cursor.kind))
6775 return;
6776 Cursor = updateC;
6777}
6778
6779/// \brief It annotates and advances tokens with a cursor until the comparison
6780//// between the cursor location and the source range is the same as
6781/// \arg compResult.
6782///
6783/// Pass RangeBefore to annotate tokens with a cursor until a range is reached.
6784/// Pass RangeOverlap to annotate tokens inside a range.
6785void AnnotateTokensWorker::annotateAndAdvanceTokens(CXCursor updateC,
6786 RangeComparisonResult compResult,
6787 SourceRange range) {
6788 while (MoreTokens()) {
6789 const unsigned I = NextToken();
6790 if (isFunctionMacroToken(I))
6791 if (!annotateAndAdvanceFunctionMacroTokens(updateC, compResult, range))
6792 return;
6793
6794 SourceLocation TokLoc = GetTokenLoc(I);
6795 if (LocationCompare(SrcMgr, TokLoc, range) == compResult) {
6796 updateCursorAnnotation(Cursors[I], updateC);
6797 AdvanceToken();
6798 continue;
6799 }
6800 break;
6801 }
6802}
6803
6804/// \brief Special annotation handling for macro argument tokens.
6805/// \returns true if it advanced beyond all macro tokens, false otherwise.
6806bool AnnotateTokensWorker::annotateAndAdvanceFunctionMacroTokens(
6807 CXCursor updateC,
6808 RangeComparisonResult compResult,
6809 SourceRange range) {
6810 assert(MoreTokens())(static_cast <bool> (MoreTokens()) ? void (0) : __assert_fail
("MoreTokens()", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6810, __extension__ __PRETTY_FUNCTION__))
;
6811 assert(isFunctionMacroToken(NextToken()) &&(static_cast <bool> (isFunctionMacroToken(NextToken()) &&
"Should be called only for macro arg tokens") ? void (0) : __assert_fail
("isFunctionMacroToken(NextToken()) && \"Should be called only for macro arg tokens\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6812, __extension__ __PRETTY_FUNCTION__))
6812 "Should be called only for macro arg tokens")(static_cast <bool> (isFunctionMacroToken(NextToken()) &&
"Should be called only for macro arg tokens") ? void (0) : __assert_fail
("isFunctionMacroToken(NextToken()) && \"Should be called only for macro arg tokens\""
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6812, __extension__ __PRETTY_FUNCTION__))
;
6813
6814 // This works differently than annotateAndAdvanceTokens; because expanded
6815 // macro arguments can have arbitrary translation-unit source order, we do not
6816 // advance the token index one by one until a token fails the range test.
6817 // We only advance once past all of the macro arg tokens if all of them
6818 // pass the range test. If one of them fails we keep the token index pointing
6819 // at the start of the macro arg tokens so that the failing token will be
6820 // annotated by a subsequent annotation try.
6821
6822 bool atLeastOneCompFail = false;
6823
6824 unsigned I = NextToken();
6825 for (; I < NumTokens && isFunctionMacroToken(I); ++I) {
6826 SourceLocation TokLoc = getFunctionMacroTokenLoc(I);
6827 if (TokLoc.isFileID())
6828 continue; // not macro arg token, it's parens or comma.
6829 if (LocationCompare(SrcMgr, TokLoc, range) == compResult) {
6830 if (clang_isInvalid(clang_getCursorKind(Cursors[I])))
6831 Cursors[I] = updateC;
6832 } else
6833 atLeastOneCompFail = true;
6834 }
6835
6836 if (atLeastOneCompFail)
6837 return false;
6838
6839 TokIdx = I; // All of the tokens were handled, advance beyond all of them.
6840 return true;
6841}
6842
6843enum CXChildVisitResult
6844AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) {
6845 SourceRange cursorRange = getRawCursorExtent(cursor);
6846 if (cursorRange.isInvalid())
6847 return CXChildVisit_Recurse;
6848
6849 if (!HasContextSensitiveKeywords) {
6850 // Objective-C properties can have context-sensitive keywords.
6851 if (cursor.kind == CXCursor_ObjCPropertyDecl) {
6852 if (const ObjCPropertyDecl *Property
6853 = dyn_cast_or_null<ObjCPropertyDecl>(getCursorDecl(cursor)))
6854 HasContextSensitiveKeywords = Property->getPropertyAttributesAsWritten() != 0;
6855 }
6856 // Objective-C methods can have context-sensitive keywords.
6857 else if (cursor.kind == CXCursor_ObjCInstanceMethodDecl ||
6858 cursor.kind == CXCursor_ObjCClassMethodDecl) {
6859 if (const ObjCMethodDecl *Method
6860 = dyn_cast_or_null<ObjCMethodDecl>(getCursorDecl(cursor))) {
6861 if (Method->getObjCDeclQualifier())
6862 HasContextSensitiveKeywords = true;
6863 else {
6864 for (const auto *P : Method->parameters()) {
6865 if (P->getObjCDeclQualifier()) {
6866 HasContextSensitiveKeywords = true;
6867 break;
6868 }
6869 }
6870 }
6871 }
6872 }
6873 // C++ methods can have context-sensitive keywords.
6874 else if (cursor.kind == CXCursor_CXXMethod) {
6875 if (const CXXMethodDecl *Method
6876 = dyn_cast_or_null<CXXMethodDecl>(getCursorDecl(cursor))) {
6877 if (Method->hasAttr<FinalAttr>() || Method->hasAttr<OverrideAttr>())
6878 HasContextSensitiveKeywords = true;
6879 }
6880 }
6881 // C++ classes can have context-sensitive keywords.
6882 else if (cursor.kind == CXCursor_StructDecl ||
6883 cursor.kind == CXCursor_ClassDecl ||
6884 cursor.kind == CXCursor_ClassTemplate ||
6885 cursor.kind == CXCursor_ClassTemplatePartialSpecialization) {
6886 if (const Decl *D = getCursorDecl(cursor))
6887 if (D->hasAttr<FinalAttr>())
6888 HasContextSensitiveKeywords = true;
6889 }
6890 }
6891
6892 // Don't override a property annotation with its getter/setter method.
6893 if (cursor.kind == CXCursor_ObjCInstanceMethodDecl &&
6894 parent.kind == CXCursor_ObjCPropertyDecl)
6895 return CXChildVisit_Continue;
6896
6897 if (clang_isPreprocessing(cursor.kind)) {
6898 // Items in the preprocessing record are kept separate from items in
6899 // declarations, so we keep a separate token index.
6900 unsigned SavedTokIdx = TokIdx;
6901 TokIdx = PreprocessingTokIdx;
6902
6903 // Skip tokens up until we catch up to the beginning of the preprocessing
6904 // entry.
6905 while (MoreTokens()) {
6906 const unsigned I = NextToken();
6907 SourceLocation TokLoc = GetTokenLoc(I);
6908 switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) {
6909 case RangeBefore:
6910 AdvanceToken();
6911 continue;
6912 case RangeAfter:
6913 case RangeOverlap:
6914 break;
6915 }
6916 break;
6917 }
6918
6919 // Look at all of the tokens within this range.
6920 while (MoreTokens()) {
6921 const unsigned I = NextToken();
6922 SourceLocation TokLoc = GetTokenLoc(I);
6923 switch (LocationCompare(SrcMgr, TokLoc, cursorRange)) {
6924 case RangeBefore:
6925 llvm_unreachable("Infeasible")::llvm::llvm_unreachable_internal("Infeasible", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 6925)
;
6926 case RangeAfter:
6927 break;
6928 case RangeOverlap:
6929 // For macro expansions, just note where the beginning of the macro
6930 // expansion occurs.
6931 if (cursor.kind == CXCursor_MacroExpansion) {
6932 if (TokLoc == cursorRange.getBegin())
6933 Cursors[I] = cursor;
6934 AdvanceToken();
6935 break;
6936 }
6937 // We may have already annotated macro names inside macro definitions.
6938 if (Cursors[I].kind != CXCursor_MacroExpansion)
6939 Cursors[I] = cursor;
6940 AdvanceToken();
6941 continue;
6942 }
6943 break;
6944 }
6945
6946 // Save the preprocessing token index; restore the non-preprocessing
6947 // token index.
6948 PreprocessingTokIdx = TokIdx;
6949 TokIdx = SavedTokIdx;
6950 return CXChildVisit_Recurse;
6951 }
6952
6953 if (cursorRange.isInvalid())
6954 return CXChildVisit_Continue;
6955
6956 unsigned BeforeReachingCursorIdx = NextToken();
6957 const enum CXCursorKind cursorK = clang_getCursorKind(cursor);
6958 const enum CXCursorKind K = clang_getCursorKind(parent);
6959 const CXCursor updateC =
6960 (clang_isInvalid(K) || K == CXCursor_TranslationUnit ||
6961 // Attributes are annotated out-of-order, skip tokens until we reach it.
6962 clang_isAttribute(cursor.kind))
6963 ? clang_getNullCursor() : parent;
6964
6965 annotateAndAdvanceTokens(updateC, RangeBefore, cursorRange);
6966
6967 // Avoid having the cursor of an expression "overwrite" the annotation of the
6968 // variable declaration that it belongs to.
6969 // This can happen for C++ constructor expressions whose range generally
6970 // include the variable declaration, e.g.:
6971 // MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr cursor.
6972 if (clang_isExpression(cursorK) && MoreTokens()) {
6973 const Expr *E = getCursorExpr(cursor);
6974 if (const Decl *D = getCursorParentDecl(cursor)) {
6975 const unsigned I = NextToken();
6976 if (E->getLocStart().isValid() && D->getLocation().isValid() &&
6977 E->getLocStart() == D->getLocation() &&
6978 E->getLocStart() == GetTokenLoc(I)) {
6979 updateCursorAnnotation(Cursors[I], updateC);
6980 AdvanceToken();
6981 }
6982 }
6983 }
6984
6985 // Before recursing into the children keep some state that we are going
6986 // to use in the AnnotateTokensWorker::postVisitChildren callback to do some
6987 // extra work after the child nodes are visited.
6988 // Note that we don't call VisitChildren here to avoid traversing statements
6989 // code-recursively which can blow the stack.
6990
6991 PostChildrenInfo Info;
6992 Info.Cursor = cursor;
6993 Info.CursorRange = cursorRange;
6994 Info.BeforeReachingCursorIdx = BeforeReachingCursorIdx;
6995 Info.BeforeChildrenTokenIdx = NextToken();
6996 PostChildrenInfos.push_back(Info);
6997
6998 return CXChildVisit_Recurse;
6999}
7000
7001bool AnnotateTokensWorker::postVisitChildren(CXCursor cursor) {
7002 if (PostChildrenInfos.empty())
7003 return false;
7004 const PostChildrenInfo &Info = PostChildrenInfos.back();
7005 if (!clang_equalCursors(Info.Cursor, cursor))
7006 return false;
7007
7008 const unsigned BeforeChildren = Info.BeforeChildrenTokenIdx;
7009 const unsigned AfterChildren = NextToken();
7010 SourceRange cursorRange = Info.CursorRange;
7011
7012 // Scan the tokens that are at the end of the cursor, but are not captured
7013 // but the child cursors.
7014 annotateAndAdvanceTokens(cursor, RangeOverlap, cursorRange);
7015
7016 // Scan the tokens that are at the beginning of the cursor, but are not
7017 // capture by the child cursors.
7018 for (unsigned I = BeforeChildren; I != AfterChildren; ++I) {
7019 if (!clang_isInvalid(clang_getCursorKind(Cursors[I])))
7020 break;
7021
7022 Cursors[I] = cursor;
7023 }
7024
7025 // Attributes are annotated out-of-order, rewind TokIdx to when we first
7026 // encountered the attribute cursor.
7027 if (clang_isAttribute(cursor.kind))
7028 TokIdx = Info.BeforeReachingCursorIdx;
7029
7030 PostChildrenInfos.pop_back();
7031 return false;
7032}
7033
7034static enum CXChildVisitResult AnnotateTokensVisitor(CXCursor cursor,
7035 CXCursor parent,
7036 CXClientData client_data) {
7037 return static_cast<AnnotateTokensWorker*>(client_data)->Visit(cursor, parent);
7038}
7039
7040static bool AnnotateTokensPostChildrenVisitor(CXCursor cursor,
7041 CXClientData client_data) {
7042 return static_cast<AnnotateTokensWorker*>(client_data)->
7043 postVisitChildren(cursor);
7044}
7045
7046namespace {
7047
7048/// \brief Uses the macro expansions in the preprocessing record to find
7049/// and mark tokens that are macro arguments. This info is used by the
7050/// AnnotateTokensWorker.
7051class MarkMacroArgTokensVisitor {
7052 SourceManager &SM;
7053 CXToken *Tokens;
7054 unsigned NumTokens;
7055 unsigned CurIdx;
7056
7057public:
7058 MarkMacroArgTokensVisitor(SourceManager &SM,
7059 CXToken *tokens, unsigned numTokens)
7060 : SM(SM), Tokens(tokens), NumTokens(numTokens), CurIdx(0) { }
7061
7062 CXChildVisitResult visit(CXCursor cursor, CXCursor parent) {
7063 if (cursor.kind != CXCursor_MacroExpansion)
7064 return CXChildVisit_Continue;
7065
7066 SourceRange macroRange = getCursorMacroExpansion(cursor).getSourceRange();
7067 if (macroRange.getBegin() == macroRange.getEnd())
7068 return CXChildVisit_Continue; // it's not a function macro.
7069
7070 for (; CurIdx < NumTokens; ++CurIdx) {
7071 if (!SM.isBeforeInTranslationUnit(getTokenLoc(CurIdx),
7072 macroRange.getBegin()))
7073 break;
7074 }
7075
7076 if (CurIdx == NumTokens)
7077 return CXChildVisit_Break;
7078
7079 for (; CurIdx < NumTokens; ++CurIdx) {
7080 SourceLocation tokLoc = getTokenLoc(CurIdx);
7081 if (!SM.isBeforeInTranslationUnit(tokLoc, macroRange.getEnd()))
7082 break;
7083
7084 setFunctionMacroTokenLoc(CurIdx, SM.getMacroArgExpandedLocation(tokLoc));
7085 }
7086
7087 if (CurIdx == NumTokens)
7088 return CXChildVisit_Break;
7089
7090 return CXChildVisit_Continue;
7091 }
7092
7093private:
7094 CXToken &getTok(unsigned Idx) {
7095 assert(Idx < NumTokens)(static_cast <bool> (Idx < NumTokens) ? void (0) : __assert_fail
("Idx < NumTokens", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 7095, __extension__ __PRETTY_FUNCTION__))
;
7096 return Tokens[Idx];
7097 }
7098 const CXToken &getTok(unsigned Idx) const {
7099 assert(Idx < NumTokens)(static_cast <bool> (Idx < NumTokens) ? void (0) : __assert_fail
("Idx < NumTokens", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 7099, __extension__ __PRETTY_FUNCTION__))
;
7100 return Tokens[Idx];
7101 }
7102
7103 SourceLocation getTokenLoc(unsigned tokI) {
7104 return SourceLocation::getFromRawEncoding(getTok(tokI).int_data[1]);
7105 }
7106
7107 void setFunctionMacroTokenLoc(unsigned tokI, SourceLocation loc) {
7108 // The third field is reserved and currently not used. Use it here
7109 // to mark macro arg expanded tokens with their expanded locations.
7110 getTok(tokI).int_data[3] = loc.getRawEncoding();
7111 }
7112};
7113
7114} // end anonymous namespace
7115
7116static CXChildVisitResult
7117MarkMacroArgTokensVisitorDelegate(CXCursor cursor, CXCursor parent,
7118 CXClientData client_data) {
7119 return static_cast<MarkMacroArgTokensVisitor*>(client_data)->visit(cursor,
7120 parent);
7121}
7122
7123/// \brief Used by \c annotatePreprocessorTokens.
7124/// \returns true if lexing was finished, false otherwise.
7125static bool lexNext(Lexer &Lex, Token &Tok,
7126 unsigned &NextIdx, unsigned NumTokens) {
7127 if (NextIdx >= NumTokens)
7128 return true;
7129
7130 ++NextIdx;
7131 Lex.LexFromRawLexer(Tok);
7132 return Tok.is(tok::eof);
7133}
7134
7135static void annotatePreprocessorTokens(CXTranslationUnit TU,
7136 SourceRange RegionOfInterest,
7137 CXCursor *Cursors,
7138 CXToken *Tokens,
7139 unsigned NumTokens) {
7140 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
7141
7142 Preprocessor &PP = CXXUnit->getPreprocessor();
7143 SourceManager &SourceMgr = CXXUnit->getSourceManager();
7144 std::pair<FileID, unsigned> BeginLocInfo
7145 = SourceMgr.getDecomposedSpellingLoc(RegionOfInterest.getBegin());
7146 std::pair<FileID, unsigned> EndLocInfo
7147 = SourceMgr.getDecomposedSpellingLoc(RegionOfInterest.getEnd());
7148
7149 if (BeginLocInfo.first != EndLocInfo.first)
7150 return;
7151
7152 StringRef Buffer;
7153 bool Invalid = false;
7154 Buffer = SourceMgr.getBufferData(BeginLocInfo.first, &Invalid);
7155 if (Buffer.empty() || Invalid)
7156 return;
7157
7158 Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
7159 CXXUnit->getASTContext().getLangOpts(),
7160 Buffer.begin(), Buffer.data() + BeginLocInfo.second,
7161 Buffer.end());
7162 Lex.SetCommentRetentionState(true);
7163
7164 unsigned NextIdx = 0;
7165 // Lex tokens in raw mode until we hit the end of the range, to avoid
7166 // entering #includes or expanding macros.
7167 while (true) {
7168 Token Tok;
7169 if (lexNext(Lex, Tok, NextIdx, NumTokens))
7170 break;
7171 unsigned TokIdx = NextIdx-1;
7172 assert(Tok.getLocation() ==(static_cast <bool> (Tok.getLocation() == SourceLocation
::getFromRawEncoding(Tokens[TokIdx].int_data[1])) ? void (0) :
__assert_fail ("Tok.getLocation() == SourceLocation::getFromRawEncoding(Tokens[TokIdx].int_data[1])"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 7173, __extension__ __PRETTY_FUNCTION__))
7173 SourceLocation::getFromRawEncoding(Tokens[TokIdx].int_data[1]))(static_cast <bool> (Tok.getLocation() == SourceLocation
::getFromRawEncoding(Tokens[TokIdx].int_data[1])) ? void (0) :
__assert_fail ("Tok.getLocation() == SourceLocation::getFromRawEncoding(Tokens[TokIdx].int_data[1])"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 7173, __extension__ __PRETTY_FUNCTION__))
;
7174
7175 reprocess:
7176 if (Tok.is(tok::hash) && Tok.isAtStartOfLine()) {
7177 // We have found a preprocessing directive. Annotate the tokens
7178 // appropriately.
7179 //
7180 // FIXME: Some simple tests here could identify macro definitions and
7181 // #undefs, to provide specific cursor kinds for those.
7182
7183 SourceLocation BeginLoc = Tok.getLocation();
7184 if (lexNext(Lex, Tok, NextIdx, NumTokens))
7185 break;
7186
7187 MacroInfo *MI = nullptr;
7188 if (Tok.is(tok::raw_identifier) && Tok.getRawIdentifier() == "define") {
7189 if (lexNext(Lex, Tok, NextIdx, NumTokens))
7190 break;
7191
7192 if (Tok.is(tok::raw_identifier)) {
7193 IdentifierInfo &II =
7194 PP.getIdentifierTable().get(Tok.getRawIdentifier());
7195 SourceLocation MappedTokLoc =
7196 CXXUnit->mapLocationToPreamble(Tok.getLocation());
7197 MI = getMacroInfo(II, MappedTokLoc, TU);
7198 }
7199 }
7200
7201 bool finished = false;
7202 do {
7203 if (lexNext(Lex, Tok, NextIdx, NumTokens)) {
7204 finished = true;
7205 break;
7206 }
7207 // If we are in a macro definition, check if the token was ever a
7208 // macro name and annotate it if that's the case.
7209 if (MI) {
7210 SourceLocation SaveLoc = Tok.getLocation();
7211 Tok.setLocation(CXXUnit->mapLocationToPreamble(SaveLoc));
7212 MacroDefinitionRecord *MacroDef =
7213 checkForMacroInMacroDefinition(MI, Tok, TU);
7214 Tok.setLocation(SaveLoc);
7215 if (MacroDef)
7216 Cursors[NextIdx - 1] =
7217 MakeMacroExpansionCursor(MacroDef, Tok.getLocation(), TU);
7218 }
7219 } while (!Tok.isAtStartOfLine());
7220
7221 unsigned LastIdx = finished ? NextIdx-1 : NextIdx-2;
7222 assert(TokIdx <= LastIdx)(static_cast <bool> (TokIdx <= LastIdx) ? void (0) :
__assert_fail ("TokIdx <= LastIdx", "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 7222, __extension__ __PRETTY_FUNCTION__))
;
7223 SourceLocation EndLoc =
7224 SourceLocation::getFromRawEncoding(Tokens[LastIdx].int_data[1]);
7225 CXCursor Cursor =
7226 MakePreprocessingDirectiveCursor(SourceRange(BeginLoc, EndLoc), TU);
7227
7228 for (; TokIdx <= LastIdx; ++TokIdx)
7229 updateCursorAnnotation(Cursors[TokIdx], Cursor);
7230
7231 if (finished)
7232 break;
7233 goto reprocess;
7234 }
7235 }
7236}
7237
7238// This gets run a separate thread to avoid stack blowout.
7239static void clang_annotateTokensImpl(CXTranslationUnit TU, ASTUnit *CXXUnit,
7240 CXToken *Tokens, unsigned NumTokens,
7241 CXCursor *Cursors) {
7242 CIndexer *CXXIdx = TU->CIdx;
7243 if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForEditing))
7244 setThreadBackgroundPriority();
7245
7246 // Determine the region of interest, which contains all of the tokens.
7247 SourceRange RegionOfInterest;
7248 RegionOfInterest.setBegin(
7249 cxloc::translateSourceLocation(clang_getTokenLocation(TU, Tokens[0])));
7250 RegionOfInterest.setEnd(
7251 cxloc::translateSourceLocation(clang_getTokenLocation(TU,
7252 Tokens[NumTokens-1])));
7253
7254 // Relex the tokens within the source range to look for preprocessing
7255 // directives.
7256 annotatePreprocessorTokens(TU, RegionOfInterest, Cursors, Tokens, NumTokens);
7257
7258 // If begin location points inside a macro argument, set it to the expansion
7259 // location so we can have the full context when annotating semantically.
7260 {
7261 SourceManager &SM = CXXUnit->getSourceManager();
7262 SourceLocation Loc =
7263 SM.getMacroArgExpandedLocation(RegionOfInterest.getBegin());
7264 if (Loc.isMacroID())
7265 RegionOfInterest.setBegin(SM.getExpansionLoc(Loc));
7266 }
7267
7268 if (CXXUnit->getPreprocessor().getPreprocessingRecord()) {
7269 // Search and mark tokens that are macro argument expansions.
7270 MarkMacroArgTokensVisitor Visitor(CXXUnit->getSourceManager(),
7271 Tokens, NumTokens);
7272 CursorVisitor MacroArgMarker(TU,
7273 MarkMacroArgTokensVisitorDelegate, &Visitor,
7274 /*VisitPreprocessorLast=*/true,
7275 /*VisitIncludedEntities=*/false,
7276 RegionOfInterest);
7277 MacroArgMarker.visitPreprocessedEntitiesInRegion();
7278 }
7279
7280 // Annotate all of the source locations in the region of interest that map to
7281 // a specific cursor.
7282 AnnotateTokensWorker W(Tokens, Cursors, NumTokens, TU, RegionOfInterest);
7283
7284 // FIXME: We use a ridiculous stack size here because the data-recursion
7285 // algorithm uses a large stack frame than the non-data recursive version,
7286 // and AnnotationTokensWorker currently transforms the data-recursion
7287 // algorithm back into a traditional recursion by explicitly calling
7288 // VisitChildren(). We will need to remove this explicit recursive call.
7289 W.AnnotateTokens();
7290
7291 // If we ran into any entities that involve context-sensitive keywords,
7292 // take another pass through the tokens to mark them as such.
7293 if (W.hasContextSensitiveKeywords()) {
7294 for (unsigned I = 0; I != NumTokens; ++I) {
7295 if (clang_getTokenKind(Tokens[I]) != CXToken_Identifier)
7296 continue;
7297
7298 if (Cursors[I].kind == CXCursor_ObjCPropertyDecl) {
7299 IdentifierInfo *II = static_cast<IdentifierInfo *>(Tokens[I].ptr_data);
7300 if (const ObjCPropertyDecl *Property
7301 = dyn_cast_or_null<ObjCPropertyDecl>(getCursorDecl(Cursors[I]))) {
7302 if (Property->getPropertyAttributesAsWritten() != 0 &&
7303 llvm::StringSwitch<bool>(II->getName())
7304 .Case("readonly", true)
7305 .Case("assign", true)
7306 .Case("unsafe_unretained", true)
7307 .Case("readwrite", true)
7308 .Case("retain", true)
7309 .Case("copy", true)
7310 .Case("nonatomic", true)
7311 .Case("atomic", true)
7312 .Case("getter", true)
7313 .Case("setter", true)
7314 .Case("strong", true)
7315 .Case("weak", true)
7316 .Case("class", true)
7317 .Default(false))
7318 Tokens[I].int_data[0] = CXToken_Keyword;
7319 }
7320 continue;
7321 }
7322
7323 if (Cursors[I].kind == CXCursor_ObjCInstanceMethodDecl ||
7324 Cursors[I].kind == CXCursor_ObjCClassMethodDecl) {
7325 IdentifierInfo *II = static_cast<IdentifierInfo *>(Tokens[I].ptr_data);
7326 if (llvm::StringSwitch<bool>(II->getName())
7327 .Case("in", true)
7328 .Case("out", true)
7329 .Case("inout", true)
7330 .Case("oneway", true)
7331 .Case("bycopy", true)
7332 .Case("byref", true)
7333 .Default(false))
7334 Tokens[I].int_data[0] = CXToken_Keyword;
7335 continue;
7336 }
7337
7338 if (Cursors[I].kind == CXCursor_CXXFinalAttr ||
7339 Cursors[I].kind == CXCursor_CXXOverrideAttr) {
7340 Tokens[I].int_data[0] = CXToken_Keyword;
7341 continue;
7342 }
7343 }
7344 }
7345}
7346
7347void clang_annotateTokens(CXTranslationUnit TU,
7348 CXToken *Tokens, unsigned NumTokens,
7349 CXCursor *Cursors) {
7350 if (isNotUsableTU(TU)) {
7351 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
7352 return;
7353 }
7354 if (NumTokens == 0 || !Tokens || !Cursors) {
7355 LOG_FUNC_SECTIONif (clang::cxindex::LogRef Log = clang::cxindex::Logger::make
(__func__))
{ *Log << "<null input>"; }
7356 return;
7357 }
7358
7359 LOG_FUNC_SECTIONif (clang::cxindex::LogRef Log = clang::cxindex::Logger::make
(__func__))
{
7360 *Log << TU << ' ';
7361 CXSourceLocation bloc = clang_getTokenLocation(TU, Tokens[0]);
7362 CXSourceLocation eloc = clang_getTokenLocation(TU, Tokens[NumTokens-1]);
7363 *Log << clang_getRange(bloc, eloc);
7364 }
7365
7366 // Any token we don't specifically annotate will have a NULL cursor.
7367 CXCursor C = clang_getNullCursor();
7368 for (unsigned I = 0; I != NumTokens; ++I)
7369 Cursors[I] = C;
7370
7371 ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
7372 if (!CXXUnit)
7373 return;
7374
7375 ASTUnit::ConcurrencyCheck Check(*CXXUnit);
7376
7377 auto AnnotateTokensImpl = [=]() {
7378 clang_annotateTokensImpl(TU, CXXUnit, Tokens, NumTokens, Cursors);
7379 };
7380 llvm::CrashRecoveryContext CRC;
7381 if (!RunSafely(CRC, AnnotateTokensImpl, GetSafetyThreadStackSize() * 2)) {
7382 fprintf(stderrstderr, "libclang: crash detected while annotating tokens\n");
7383 }
7384}
7385
7386//===----------------------------------------------------------------------===//
7387// Operations for querying linkage of a cursor.
7388//===----------------------------------------------------------------------===//
7389
7390CXLinkageKind clang_getCursorLinkage(CXCursor cursor) {
7391 if (!clang_isDeclaration(cursor.kind))
7392 return CXLinkage_Invalid;
7393
7394 const Decl *D = cxcursor::getCursorDecl(cursor);
7395 if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
7396 switch (ND->getLinkageInternal()) {
7397 case NoLinkage:
7398 case VisibleNoLinkage: return CXLinkage_NoLinkage;
7399 case ModuleInternalLinkage:
7400 case InternalLinkage: return CXLinkage_Internal;
7401 case UniqueExternalLinkage: return CXLinkage_UniqueExternal;
7402 case ModuleLinkage:
7403 case ExternalLinkage: return CXLinkage_External;
7404 };
7405
7406 return CXLinkage_Invalid;
7407}
7408
7409//===----------------------------------------------------------------------===//
7410// Operations for querying visibility of a cursor.
7411//===----------------------------------------------------------------------===//
7412
7413CXVisibilityKind clang_getCursorVisibility(CXCursor cursor) {
7414 if (!clang_isDeclaration(cursor.kind))
7415 return CXVisibility_Invalid;
7416
7417 const Decl *D = cxcursor::getCursorDecl(cursor);
7418 if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
7419 switch (ND->getVisibility()) {
7420 case HiddenVisibility: return CXVisibility_Hidden;
7421 case ProtectedVisibility: return CXVisibility_Protected;
7422 case DefaultVisibility: return CXVisibility_Default;
7423 };
7424
7425 return CXVisibility_Invalid;
7426}
7427
7428//===----------------------------------------------------------------------===//
7429// Operations for querying language of a cursor.
7430//===----------------------------------------------------------------------===//
7431
7432static CXLanguageKind getDeclLanguage(const Decl *D) {
7433 if (!D)
7434 return CXLanguage_C;
7435
7436 switch (D->getKind()) {
7437 default:
7438 break;
7439 case Decl::ImplicitParam:
7440 case Decl::ObjCAtDefsField:
7441 case Decl::ObjCCategory:
7442 case Decl::ObjCCategoryImpl:
7443 case Decl::ObjCCompatibleAlias:
7444 case Decl::ObjCImplementation:
7445 case Decl::ObjCInterface:
7446 case Decl::ObjCIvar:
7447 case Decl::ObjCMethod:
7448 case Decl::ObjCProperty:
7449 case Decl::ObjCPropertyImpl:
7450 case Decl::ObjCProtocol:
7451 case Decl::ObjCTypeParam:
7452 return CXLanguage_ObjC;
7453 case Decl::CXXConstructor:
7454 case Decl::CXXConversion:
7455 case Decl::CXXDestructor:
7456 case Decl::CXXMethod:
7457 case Decl::CXXRecord:
7458 case Decl::ClassTemplate:
7459 case Decl::ClassTemplatePartialSpecialization:
7460 case Decl::ClassTemplateSpecialization:
7461 case Decl::Friend:
7462 case Decl::FriendTemplate:
7463 case Decl::FunctionTemplate:
7464 case Decl::LinkageSpec:
7465 case Decl::Namespace:
7466 case Decl::NamespaceAlias:
7467 case Decl::NonTypeTemplateParm:
7468 case Decl::StaticAssert:
7469 case Decl::TemplateTemplateParm:
7470 case Decl::TemplateTypeParm:
7471 case Decl::UnresolvedUsingTypename:
7472 case Decl::UnresolvedUsingValue:
7473 case Decl::Using:
7474 case Decl::UsingDirective:
7475 case Decl::UsingShadow:
7476 return CXLanguage_CPlusPlus;
7477 }
7478
7479 return CXLanguage_C;
7480}
7481
7482static CXAvailabilityKind getCursorAvailabilityForDecl(const Decl *D) {
7483 if (isa<FunctionDecl>(D) && cast<FunctionDecl>(D)->isDeleted())
7484 return CXAvailability_NotAvailable;
7485
7486 switch (D->getAvailability()) {
7487 case AR_Available:
7488 case AR_NotYetIntroduced:
7489 if (const EnumConstantDecl *EnumConst = dyn_cast<EnumConstantDecl>(D))
7490 return getCursorAvailabilityForDecl(
7491 cast<Decl>(EnumConst->getDeclContext()));
7492 return CXAvailability_Available;
7493
7494 case AR_Deprecated:
7495 return CXAvailability_Deprecated;
7496
7497 case AR_Unavailable:
7498 return CXAvailability_NotAvailable;
7499 }
7500
7501 llvm_unreachable("Unknown availability kind!")::llvm::llvm_unreachable_internal("Unknown availability kind!"
, "/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 7501)
;
7502}
7503
7504enum CXAvailabilityKind clang_getCursorAvailability(CXCursor cursor) {
7505 if (clang_isDeclaration(cursor.kind))
7506 if (const Decl *D = cxcursor::getCursorDecl(cursor))
7507 return getCursorAvailabilityForDecl(D);
7508
7509 return CXAvailability_Available;
7510}
7511
7512static CXVersion convertVersion(VersionTuple In) {
7513 CXVersion Out = { -1, -1, -1 };
7514 if (In.empty())
7515 return Out;
7516
7517 Out.Major = In.getMajor();
7518
7519 Optional<unsigned> Minor = In.getMinor();
7520 if (Minor.hasValue())
7521 Out.Minor = *Minor;
7522 else
7523 return Out;
7524
7525 Optional<unsigned> Subminor = In.getSubminor();
7526 if (Subminor.hasValue())
7527 Out.Subminor = *Subminor;
7528
7529 return Out;
7530}
7531
7532static void getCursorPlatformAvailabilityForDecl(
7533 const Decl *D, int *always_deprecated, CXString *deprecated_message,
7534 int *always_unavailable, CXString *unavailable_message,
7535 SmallVectorImpl<AvailabilityAttr *> &AvailabilityAttrs) {
7536 bool HadAvailAttr = false;
7537 for (auto A : D->attrs()) {
7538 if (DeprecatedAttr *Deprecated = dyn_cast<DeprecatedAttr>(A)) {
7539 HadAvailAttr = true;
7540 if (always_deprecated)
7541 *always_deprecated = 1;
7542 if (deprecated_message) {
7543 clang_disposeString(*deprecated_message);
7544 *deprecated_message = cxstring::createDup(Deprecated->getMessage());
7545 }
7546 continue;
7547 }
7548
7549 if (UnavailableAttr *Unavailable = dyn_cast<UnavailableAttr>(A)) {
7550 HadAvailAttr = true;
7551 if (always_unavailable)
7552 *always_unavailable = 1;
7553 if (unavailable_message) {
7554 clang_disposeString(*unavailable_message);
7555 *unavailable_message = cxstring::createDup(Unavailable->getMessage());
7556 }
7557 continue;
7558 }
7559
7560 if (AvailabilityAttr *Avail = dyn_cast<AvailabilityAttr>(A)) {
7561 AvailabilityAttrs.push_back(Avail);
7562 HadAvailAttr = true;
7563 }
7564 }
7565
7566 if (!HadAvailAttr)
7567 if (const EnumConstantDecl *EnumConst = dyn_cast<EnumConstantDecl>(D))
7568 return getCursorPlatformAvailabilityForDecl(
7569 cast<Decl>(EnumConst->getDeclContext()), always_deprecated,
7570 deprecated_message, always_unavailable, unavailable_message,
7571 AvailabilityAttrs);
7572
7573 if (AvailabilityAttrs.empty())
7574 return;
7575
7576 std::sort(AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
7577 [](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
7578 return LHS->getPlatform()->getName() <
7579 RHS->getPlatform()->getName();
7580 });
7581 ASTContext &Ctx = D->getASTContext();
7582 auto It = std::unique(
7583 AvailabilityAttrs.begin(), AvailabilityAttrs.end(),
7584 [&Ctx](AvailabilityAttr *LHS, AvailabilityAttr *RHS) {
7585 if (LHS->getPlatform() != RHS->getPlatform())
1
Assuming the condition is false
2
Taking false branch
7586 return false;
7587
7588 if (LHS->getIntroduced() == RHS->getIntroduced() &&
3
Taking false branch
7589 LHS->getDeprecated() == RHS->getDeprecated() &&
7590 LHS->getObsoleted() == RHS->getObsoleted() &&
7591 LHS->getMessage() == RHS->getMessage() &&
7592 LHS->getReplacement() == RHS->getReplacement())
7593 return true;
7594
7595 if ((!LHS->getIntroduced().empty() && !RHS->getIntroduced().empty()) ||
4
Taking false branch
7596 (!LHS->getDeprecated().empty() && !RHS->getDeprecated().empty()) ||
7597 (!LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()))
7598 return false;
7599
7600 if (LHS->getIntroduced().empty() && !RHS->getIntroduced().empty())
5
Taking false branch
7601 LHS->setIntroduced(Ctx, RHS->getIntroduced());
7602
7603 if (LHS->getDeprecated().empty() && !RHS->getDeprecated().empty()) {
6
Taking false branch
7604 LHS->setDeprecated(Ctx, RHS->getDeprecated());
7605 if (LHS->getMessage().empty())
7606 LHS->setMessage(Ctx, RHS->getMessage());
7607 if (LHS->getReplacement().empty())
7608 LHS->setReplacement(Ctx, RHS->getReplacement());
7609 }
7610
7611 if (LHS->getObsoleted().empty() && !RHS->getObsoleted().empty()) {
7
Taking true branch
7612 LHS->setObsoleted(Ctx, RHS->getObsoleted());
7613 if (LHS->getMessage().empty())
8
Assuming the condition is true
9
Taking true branch
7614 LHS->setMessage(Ctx, RHS->getMessage());
10
Calling 'AvailabilityAttr::setMessage'
7615 if (LHS->getReplacement().empty())
7616 LHS->setReplacement(Ctx, RHS->getReplacement());
7617 }
7618
7619 return true;
7620 });
7621 AvailabilityAttrs.erase(It, AvailabilityAttrs.end());
7622}
7623
7624int clang_getCursorPlatformAvailability(CXCursor cursor, int *always_deprecated,
7625 CXString *deprecated_message,
7626 int *always_unavailable,
7627 CXString *unavailable_message,
7628 CXPlatformAvailability *availability,
7629 int availability_size) {
7630 if (always_deprecated)
7631 *always_deprecated = 0;
7632 if (deprecated_message)
7633 *deprecated_message = cxstring::createEmpty();
7634 if (always_unavailable)
7635 *always_unavailable = 0;
7636 if (unavailable_message)
7637 *unavailable_message = cxstring::createEmpty();
7638
7639 if (!clang_isDeclaration(cursor.kind))
7640 return 0;
7641
7642 const Decl *D = cxcursor::getCursorDecl(cursor);
7643 if (!D)
7644 return 0;
7645
7646 SmallVector<AvailabilityAttr *, 8> AvailabilityAttrs;
7647 getCursorPlatformAvailabilityForDecl(D, always_deprecated, deprecated_message,
7648 always_unavailable, unavailable_message,
7649 AvailabilityAttrs);
7650 for (const auto &Avail :
7651 llvm::enumerate(llvm::makeArrayRef(AvailabilityAttrs)
7652 .take_front(availability_size))) {
7653 availability[Avail.index()].Platform =
7654 cxstring::createDup(Avail.value()->getPlatform()->getName());
7655 availability[Avail.index()].Introduced =
7656 convertVersion(Avail.value()->getIntroduced());
7657 availability[Avail.index()].Deprecated =
7658 convertVersion(Avail.value()->getDeprecated());
7659 availability[Avail.index()].Obsoleted =
7660 convertVersion(Avail.value()->getObsoleted());
7661 availability[Avail.index()].Unavailable = Avail.value()->getUnavailable();
7662 availability[Avail.index()].Message =
7663 cxstring::createDup(Avail.value()->getMessage());
7664 }
7665
7666 return AvailabilityAttrs.size();
7667}
7668
7669void clang_disposeCXPlatformAvailability(CXPlatformAvailability *availability) {
7670 clang_disposeString(availability->Platform);
7671 clang_disposeString(availability->Message);
7672}
7673
7674CXLanguageKind clang_getCursorLanguage(CXCursor cursor) {
7675 if (clang_isDeclaration(cursor.kind))
7676 return getDeclLanguage(cxcursor::getCursorDecl(cursor));
7677
7678 return CXLanguage_Invalid;
7679}
7680
7681CXTLSKind clang_getCursorTLSKind(CXCursor cursor) {
7682 const Decl *D = cxcursor::getCursorDecl(cursor);
7683 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
7684 switch (VD->getTLSKind()) {
7685 case VarDecl::TLS_None:
7686 return CXTLS_None;
7687 case VarDecl::TLS_Dynamic:
7688 return CXTLS_Dynamic;
7689 case VarDecl::TLS_Static:
7690 return CXTLS_Static;
7691 }
7692 }
7693
7694 return CXTLS_None;
7695}
7696
7697 /// \brief If the given cursor is the "templated" declaration
7698 /// descibing a class or function template, return the class or
7699 /// function template.
7700static const Decl *maybeGetTemplateCursor(const Decl *D) {
7701 if (!D)
7702 return nullptr;
7703
7704 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
7705 if (FunctionTemplateDecl *FunTmpl = FD->getDescribedFunctionTemplate())
7706 return FunTmpl;
7707
7708 if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(D))
7709 if (ClassTemplateDecl *ClassTmpl = RD->getDescribedClassTemplate())
7710 return ClassTmpl;
7711
7712 return D;
7713}
7714
7715
7716enum CX_StorageClass clang_Cursor_getStorageClass(CXCursor C) {
7717 StorageClass sc = SC_None;
7718 const Decl *D = getCursorDecl(C);
7719 if (D) {
7720 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
7721 sc = FD->getStorageClass();
7722 } else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
7723 sc = VD->getStorageClass();
7724 } else {
7725 return CX_SC_Invalid;
7726 }
7727 } else {
7728 return CX_SC_Invalid;
7729 }
7730 switch (sc) {
7731 case SC_None:
7732 return CX_SC_None;
7733 case SC_Extern:
7734 return CX_SC_Extern;
7735 case SC_Static:
7736 return CX_SC_Static;
7737 case SC_PrivateExtern:
7738 return CX_SC_PrivateExtern;
7739 case SC_Auto:
7740 return CX_SC_Auto;
7741 case SC_Register:
7742 return CX_SC_Register;
7743 }
7744 llvm_unreachable("Unhandled storage class!")::llvm::llvm_unreachable_internal("Unhandled storage class!",
"/build/llvm-toolchain-snapshot-7~svn326246/tools/clang/tools/libclang/CIndex.cpp"
, 7744)
;
7745}
7746
7747CXCursor clang_getCursorSemanticParent(CXCursor cursor) {
7748 if (clang_isDeclaration(cursor.kind)) {
7749 if (const Decl *D = getCursorDecl(cursor)) {
7750 const DeclContext *DC = D->getDeclContext();
7751 if (!DC)
7752 return clang_getNullCursor();
7753
7754 return MakeCXCursor(maybeGetTemplateCursor(cast<Decl>(DC)),
7755 getCursorTU(cursor));
7756 }
7757 }
7758
7759 if (clang_isStatement(cursor.kind) || clang_isExpression(cursor.kind)) {
7760 if (const Decl *D = getCursorDecl(cursor))
7761 return MakeCXCursor(D, getCursorTU(cursor));
7762 }
7763
7764 return clang_getNullCursor();
7765}
7766
7767CXCursor clang_getCursorLexicalParent(CXCursor cursor) {
7768 if (clang_isDeclaration(cursor.kind)) {
7769 if (const Decl *D = getCursorDecl(cursor)) {
7770 const DeclContext *DC = D->getLexicalDeclContext();
7771 if (!DC)
7772 return clang_getNullCursor();
7773
7774 return MakeCXCursor(maybeGetTemplateCursor(cast<Decl>(DC)),
7775 getCursorTU(cursor));
7776 }
7777 }
7778
7779 // FIXME: Note that we can't easily compute the lexical context of a
7780 // statement or expression, so we return nothing.
7781 return clang_getNullCursor();
7782}
7783
7784CXFile clang_getIncludedFile(CXCursor cursor) {
7785 if (cursor.kind != CXCursor_InclusionDirective)
7786 return nullptr;
7787
7788 const InclusionDirective *ID = getCursorInclusionDirective(cursor);
7789 return const_cast<FileEntry *>(ID->getFile());
7790}
7791
7792unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C, unsigned reserved) {
7793 if (C.kind != CXCursor_ObjCPropertyDecl)
7794 return CXObjCPropertyAttr_noattr;
7795
7796 unsigned Result = CXObjCPropertyAttr_noattr;
7797 const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(getCursorDecl(C));
7798 ObjCPropertyDecl::PropertyAttributeKind Attr =
7799 PD->getPropertyAttributesAsWritten();
7800
7801#define SET_CXOBJCPROP_ATTR(A) \
7802 if (Attr & ObjCPropertyDecl::OBJC_PR_##A) \
7803 Result |= CXObjCPropertyAttr_##A
7804 SET_CXOBJCPROP_ATTR(readonly);
7805 SET_CXOBJCPROP_ATTR(getter);
7806 SET_CXOBJCPROP_ATTR(assign);
7807 SET_CXOBJCPROP_ATTR(readwrite);
7808 SET_CXOBJCPROP_ATTR(retain);
7809 SET_CXOBJCPROP_ATTR(copy);
7810 SET_CXOBJCPROP_ATTR(nonatomic);
7811 SET_CXOBJCPROP_ATTR(setter);
7812 SET_CXOBJCPROP_ATTR(atomic);
7813 SET_CXOBJCPROP_ATTR(weak);
7814 SET_CXOBJCPROP_ATTR(strong);
7815 SET_CXOBJCPROP_ATTR(unsafe_unretained);
7816 SET_CXOBJCPROP_ATTR(class);
7817#undef SET_CXOBJCPROP_ATTR
7818
7819 return Result;
7820}
7821
7822unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C) {
7823 if (!clang_isDeclaration(C.kind))
7824 return CXObjCDeclQualifier_None;
7825
7826 Decl::ObjCDeclQualifier QT = Decl::OBJC_TQ_None;
7827 const Decl *D = getCursorDecl(C);
7828 if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
7829 QT = MD->getObjCDeclQualifier();
7830 else if (const ParmVarDecl *PD = dyn_cast<ParmVarDecl>(D))
7831 QT = PD->getObjCDeclQualifier();
7832 if (QT == Decl::OBJC_TQ_None)
7833 return CXObjCDeclQualifier_None;
7834
7835 unsigned Result = CXObjCDeclQualifier_None;
7836 if (QT & Decl::OBJC_TQ_In) Result |= CXObjCDeclQualifier_In;
7837 if (QT & Decl::OBJC_TQ_Inout) Result |= CXObjCDeclQualifier_Inout;
7838 if (QT & Decl::OBJC_TQ_Out) Result |= CXObjCDeclQualifier_Out;
7839 if (QT & Decl::OBJC_TQ_Bycopy) Result |= CXObjCDeclQualifier_Bycopy;
7840 if (QT & Decl::OBJC_TQ_Byref) Result |= CXObjCDeclQualifier_Byref;
7841 if (QT & Decl::OBJC_TQ_Oneway) Result |= CXObjCDeclQualifier_Oneway;
7842
7843 return Result;
7844}
7845
7846unsigned clang_Cursor_isObjCOptional(CXCursor C) {
7847 if (!clang_isDeclaration(C.kind))
7848 return 0;
7849
7850 const Decl *D = getCursorDecl(C);
7851 if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
7852 return PD->getPropertyImplementation() == ObjCPropertyDecl::Optional;
7853 if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
7854 return MD->getImplementationControl() == ObjCMethodDecl::Optional;
7855
7856 return 0;
7857}
7858
7859unsigned clang_Cursor_isVariadic(CXCursor C) {
7860 if (!clang_isDeclaration(C.kind))
7861 return 0;
7862
7863 const Decl *D = getCursorDecl(C);
7864 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
7865 return FD->isVariadic();
7866 if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
7867 return MD->isVariadic();
7868
7869 return 0;
7870}
7871
7872unsigned clang_Cursor_isExternalSymbol(CXCursor C,
7873 CXString *language, CXString *definedIn,
7874 unsigned *isGenerated) {
7875 if (!clang_isDeclaration(C.kind))
7876 return 0;
7877
7878 const Decl *D = getCursorDecl(C);
7879
7880 if (auto *attr = D->getExternalSourceSymbolAttr()) {
7881 if (language)
7882 *language = cxstring::createDup(attr->getLanguage());
7883 if (definedIn)
7884 *definedIn = cxstring::createDup(attr->getDefinedIn());
7885 if (isGenerated)
7886 *isGenerated = attr->getGeneratedDeclaration();
7887 return 1;
7888 }
7889 return 0;
7890}
7891
7892CXSourceRange clang_Cursor_getCommentRange(CXCursor C) {
7893 if (!clang_isDeclaration(C.kind))
7894 return clang_getNullRange();
7895
7896 const Decl *D = getCursorDecl(C);
7897 ASTContext &Context = getCursorContext(C);
7898 const RawComment *RC = Context.getRawCommentForAnyRedecl(D);
7899 if (!RC)
7900 return clang_getNullRange();
7901
7902 return cxloc::translateSourceRange(Context, RC->getSourceRange());
7903}
7904
7905CXString clang_Cursor_getRawCommentText(CXCursor C) {
7906 if (!clang_isDeclaration(C.kind))
7907 return cxstring::createNull();
7908
7909 const Decl *D = getCursorDecl(C);
7910 ASTContext &Context = getCursorContext(C);
7911 const RawComment *RC = Context.getRawCommentForAnyRedecl(D);
7912 StringRef RawText = RC ? RC->getRawText(Context.getSourceManager()) :
7913 StringRef();
7914
7915 // Don't duplicate the string because RawText points directly into source
7916 // code.
7917 return cxstring::createRef(RawText);
7918}
7919
7920CXString clang_Cursor_getBriefCommentText(CXCursor C) {
7921 if (!clang_isDeclaration(C.kind))
7922 return cxstring::createNull();
7923
7924 const Decl *D = getCursorDecl(C);
7925 const ASTContext &Context = getCursorContext(C);
7926 const RawComment *RC = Context.getRawCommentForAnyRedecl(D);
7927
7928 if (RC) {
7929 StringRef BriefText = RC->getBriefText(Context);
7930
7931 // Don't duplicate the string because RawComment ensures that this memory
7932 // will not go away.
7933 return cxstring::createRef(BriefText);
7934 }
7935
7936 return cxstring::createNull();
7937}
7938
7939CXModule clang_Cursor_getModule(CXCursor C) {
7940 if (C.kind == CXCursor_ModuleImportDecl) {
7941 if (const ImportDecl *ImportD =
7942 dyn_cast_or_null<ImportDecl>(getCursorDecl(C)))
7943 return ImportD->getImportedModule();
7944 }
7945
7946 return nullptr;
7947}
7948
7949CXModule clang_getModuleForFile(CXTranslationUnit TU, CXFile File) {
7950 if (isNotUsableTU(TU)) {
7951 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
7952 return nullptr;
7953 }
7954 if (!File)
7955 return nullptr;
7956 FileEntry *FE = static_cast<FileEntry *>(File);
7957
7958 ASTUnit &Unit = *cxtu::getASTUnit(TU);
7959 HeaderSearch &HS = Unit.getPreprocessor().getHeaderSearchInfo();
7960 ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE);
7961
7962 return Header.getModule();
7963}
7964
7965CXFile clang_Module_getASTFile(CXModule CXMod) {
7966 if (!CXMod)
7967 return nullptr;
7968 Module *Mod = static_cast<Module*>(CXMod);
7969 return const_cast<FileEntry *>(Mod->getASTFile());
7970}
7971
7972CXModule clang_Module_getParent(CXModule CXMod) {
7973 if (!CXMod)
7974 return nullptr;
7975 Module *Mod = static_cast<Module*>(CXMod);
7976 return Mod->Parent;
7977}
7978
7979CXString clang_Module_getName(CXModule CXMod) {
7980 if (!CXMod)
7981 return cxstring::createEmpty();
7982 Module *Mod = static_cast<Module*>(CXMod);
7983 return cxstring::createDup(Mod->Name);
7984}
7985
7986CXString clang_Module_getFullName(CXModule CXMod) {
7987 if (!CXMod)
7988 return cxstring::createEmpty();
7989 Module *Mod = static_cast<Module*>(CXMod);
7990 return cxstring::createDup(Mod->getFullModuleName());
7991}
7992
7993int clang_Module_isSystem(CXModule CXMod) {
7994 if (!CXMod)
7995 return 0;
7996 Module *Mod = static_cast<Module*>(CXMod);
7997 return Mod->IsSystem;
7998}
7999
8000unsigned clang_Module_getNumTopLevelHeaders(CXTranslationUnit TU,
8001 CXModule CXMod) {
8002 if (isNotUsableTU(TU)) {
8003 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
8004 return 0;
8005 }
8006 if (!CXMod)
8007 return 0;
8008 Module *Mod = static_cast<Module*>(CXMod);
8009 FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager();
8010 ArrayRef<const FileEntry *> TopHeaders = Mod->getTopHeaders(FileMgr);
8011 return TopHeaders.size();
8012}
8013
8014CXFile clang_Module_getTopLevelHeader(CXTranslationUnit TU,
8015 CXModule CXMod, unsigned Index) {
8016 if (isNotUsableTU(TU)) {
8017 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
8018 return nullptr;
8019 }
8020 if (!CXMod)
8021 return nullptr;
8022 Module *Mod = static_cast<Module*>(CXMod);
8023 FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager();
8024
8025 ArrayRef<const FileEntry *> TopHeaders = Mod->getTopHeaders(FileMgr);
8026 if (Index < TopHeaders.size())
8027 return const_cast<FileEntry *>(TopHeaders[Index]);
8028
8029 return nullptr;
8030}
8031
8032//===----------------------------------------------------------------------===//
8033// C++ AST instrospection.
8034//===----------------------------------------------------------------------===//
8035
8036unsigned clang_CXXConstructor_isDefaultConstructor(CXCursor C) {
8037 if (!clang_isDeclaration(C.kind))
8038 return 0;
8039
8040 const Decl *D = cxcursor::getCursorDecl(C);
8041 const CXXConstructorDecl *Constructor =
8042 D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr;
8043 return (Constructor && Constructor->isDefaultConstructor()) ? 1 : 0;
8044}
8045
8046unsigned clang_CXXConstructor_isCopyConstructor(CXCursor C) {
8047 if (!clang_isDeclaration(C.kind))
8048 return 0;
8049
8050 const Decl *D = cxcursor::getCursorDecl(C);
8051 const CXXConstructorDecl *Constructor =
8052 D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr;
8053 return (Constructor && Constructor->isCopyConstructor()) ? 1 : 0;
8054}
8055
8056unsigned clang_CXXConstructor_isMoveConstructor(CXCursor C) {
8057 if (!clang_isDeclaration(C.kind))
8058 return 0;
8059
8060 const Decl *D = cxcursor::getCursorDecl(C);
8061 const CXXConstructorDecl *Constructor =
8062 D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr;
8063 return (Constructor && Constructor->isMoveConstructor()) ? 1 : 0;
8064}
8065
8066unsigned clang_CXXConstructor_isConvertingConstructor(CXCursor C) {
8067 if (!clang_isDeclaration(C.kind))
8068 return 0;
8069
8070 const Decl *D = cxcursor::getCursorDecl(C);
8071 const CXXConstructorDecl *Constructor =
8072 D ? dyn_cast_or_null<CXXConstructorDecl>(D->getAsFunction()) : nullptr;
8073 // Passing 'false' excludes constructors marked 'explicit'.
8074 return (Constructor && Constructor->isConvertingConstructor(false)) ? 1 : 0;
8075}
8076
8077unsigned clang_CXXField_isMutable(CXCursor C) {
8078 if (!clang_isDeclaration(C.kind))
8079 return 0;
8080
8081 if (const auto D = cxcursor::getCursorDecl(C))
8082 if (const auto FD = dyn_cast_or_null<FieldDecl>(D))
8083 return FD->isMutable() ? 1 : 0;
8084 return 0;
8085}
8086
8087unsigned clang_CXXMethod_isPureVirtual(CXCursor C) {
8088 if (!clang_isDeclaration(C.kind))
8089 return 0;
8090
8091 const Decl *D = cxcursor::getCursorDecl(C);
8092 const CXXMethodDecl *Method =
8093 D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
8094 return (Method && Method->isVirtual() && Method->isPure()) ? 1 : 0;
8095}
8096
8097unsigned clang_CXXMethod_isConst(CXCursor C) {
8098 if (!clang_isDeclaration(C.kind))
8099 return 0;
8100
8101 const Decl *D = cxcursor::getCursorDecl(C);
8102 const CXXMethodDecl *Method =
8103 D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
8104 return (Method && (Method->getTypeQualifiers() & Qualifiers::Const)) ? 1 : 0;
8105}
8106
8107unsigned clang_CXXMethod_isDefaulted(CXCursor C) {
8108 if (!clang_isDeclaration(C.kind))
8109 return 0;
8110
8111 const Decl *D = cxcursor::getCursorDecl(C);
8112 const CXXMethodDecl *Method =
8113 D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
8114 return (Method && Method->isDefaulted()) ? 1 : 0;
8115}
8116
8117unsigned clang_CXXMethod_isStatic(CXCursor C) {
8118 if (!clang_isDeclaration(C.kind))
8119 return 0;
8120
8121 const Decl *D = cxcursor::getCursorDecl(C);
8122 const CXXMethodDecl *Method =
8123 D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
8124 return (Method && Method->isStatic()) ? 1 : 0;
8125}
8126
8127unsigned clang_CXXMethod_isVirtual(CXCursor C) {
8128 if (!clang_isDeclaration(C.kind))
8129 return 0;
8130
8131 const Decl *D = cxcursor::getCursorDecl(C);
8132 const CXXMethodDecl *Method =
8133 D ? dyn_cast_or_null<CXXMethodDecl>(D->getAsFunction()) : nullptr;
8134 return (Method && Method->isVirtual()) ? 1 : 0;
8135}
8136
8137unsigned clang_CXXRecord_isAbstract(CXCursor C) {
8138 if (!clang_isDeclaration(C.kind))
8139 return 0;
8140
8141 const auto *D = cxcursor::getCursorDecl(C);
8142 const auto *RD = dyn_cast_or_null<CXXRecordDecl>(D);
8143 if (RD)
8144 RD = RD->getDefinition();
8145 return (RD && RD->isAbstract()) ? 1 : 0;
8146}
8147
8148unsigned clang_EnumDecl_isScoped(CXCursor C) {
8149 if (!clang_isDeclaration(C.kind))
8150 return 0;
8151
8152 const Decl *D = cxcursor::getCursorDecl(C);
8153 auto *Enum = dyn_cast_or_null<EnumDecl>(D);
8154 return (Enum && Enum->isScoped()) ? 1 : 0;
8155}
8156
8157//===----------------------------------------------------------------------===//
8158// Attribute introspection.
8159//===----------------------------------------------------------------------===//
8160
8161CXType clang_getIBOutletCollectionType(CXCursor C) {
8162 if (C.kind != CXCursor_IBOutletCollectionAttr)
8163 return cxtype::MakeCXType(QualType(), cxcursor::getCursorTU(C));
8164
8165 const IBOutletCollectionAttr *A =
8166 cast<IBOutletCollectionAttr>(cxcursor::getCursorAttr(C));
8167
8168 return cxtype::MakeCXType(A->getInterface(), cxcursor::getCursorTU(C));
8169}
8170
8171//===----------------------------------------------------------------------===//
8172// Inspecting memory usage.
8173//===----------------------------------------------------------------------===//
8174
8175typedef std::vector<CXTUResourceUsageEntry> MemUsageEntries;
8176
8177static inline void createCXTUResourceUsageEntry(MemUsageEntries &entries,
8178 enum CXTUResourceUsageKind k,
8179 unsigned long amount) {
8180 CXTUResourceUsageEntry entry = { k, amount };
8181 entries.push_back(entry);
8182}
8183
8184const char *clang_getTUResourceUsageName(CXTUResourceUsageKind kind) {
8185 const char *str = "";
8186 switch (kind) {
8187 case CXTUResourceUsage_AST:
8188 str = "ASTContext: expressions, declarations, and types";
8189 break;
8190 case CXTUResourceUsage_Identifiers:
8191 str = "ASTContext: identifiers";
8192 break;
8193 case CXTUResourceUsage_Selectors:
8194 str = "ASTContext: selectors";
8195 break;
8196 case CXTUResourceUsage_GlobalCompletionResults:
8197 str = "Code completion: cached global results";
8198 break;
8199 case CXTUResourceUsage_SourceManagerContentCache:
8200 str = "SourceManager: content cache allocator";
8201 break;
8202 case CXTUResourceUsage_AST_SideTables:
8203 str = "ASTContext: side tables";
8204 break;
8205 case CXTUResourceUsage_SourceManager_Membuffer_Malloc:
8206 str = "SourceManager: malloc'ed memory buffers";
8207 break;
8208 case CXTUResourceUsage_SourceManager_Membuffer_MMap:
8209 str = "SourceManager: mmap'ed memory buffers";
8210 break;
8211 case CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc:
8212 str = "ExternalASTSource: malloc'ed memory buffers";
8213 break;
8214 case CXTUResourceUsage_ExternalASTSource_Membuffer_MMap:
8215 str = "ExternalASTSource: mmap'ed memory buffers";
8216 break;
8217 case CXTUResourceUsage_Preprocessor:
8218 str = "Preprocessor: malloc'ed memory";
8219 break;
8220 case CXTUResourceUsage_PreprocessingRecord:
8221 str = "Preprocessor: PreprocessingRecord";
8222 break;
8223 case CXTUResourceUsage_SourceManager_DataStructures:
8224 str = "SourceManager: data structures and tables";
8225 break;
8226 case CXTUResourceUsage_Preprocessor_HeaderSearch:
8227 str = "Preprocessor: header search tables";
8228 break;
8229 }
8230 return str;
8231}
8232
8233CXTUResourceUsage clang_getCXTUResourceUsage(CXTranslationUnit TU) {
8234 if (isNotUsableTU(TU)) {
8235 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
8236 CXTUResourceUsage usage = { (void*) nullptr, 0, nullptr };
8237 return usage;
8238 }
8239
8240 ASTUnit *astUnit = cxtu::getASTUnit(TU);
8241 std::unique_ptr<MemUsageEntries> entries(new MemUsageEntries());
8242 ASTContext &astContext = astUnit->getASTContext();
8243
8244 // How much memory is used by AST nodes and types?
8245 createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_AST,
8246 (unsigned long) astContext.getASTAllocatedMemory());
8247
8248 // How much memory is used by identifiers?
8249 createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Identifiers,
8250 (unsigned long) astContext.Idents.getAllocator().getTotalMemory());
8251
8252 // How much memory is used for selectors?
8253 createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_Selectors,
8254 (unsigned long) astContext.Selectors.getTotalMemory());
8255
8256 // How much memory is used by ASTContext's side tables?
8257 createCXTUResourceUsageEntry(*entries, CXTUResourceUsage_AST_SideTables,
8258 (unsigned long) astContext.getSideTableAllocatedMemory());
8259
8260 // How much memory is used for caching global code completion results?
8261 unsigned long completionBytes = 0;
8262 if (GlobalCodeCompletionAllocator *completionAllocator =
8263 astUnit->getCachedCompletionAllocator().get()) {
8264 completionBytes = completionAllocator->getTotalMemory();
8265 }
8266 createCXTUResourceUsageEntry(*entries,
8267 CXTUResourceUsage_GlobalCompletionResults,
8268 completionBytes);
8269
8270 // How much memory is being used by SourceManager's content cache?
8271 createCXTUResourceUsageEntry(*entries,
8272 CXTUResourceUsage_SourceManagerContentCache,
8273 (unsigned long) astContext.getSourceManager().getContentCacheSize());
8274
8275 // How much memory is being used by the MemoryBuffer's in SourceManager?
8276 const SourceManager::MemoryBufferSizes &srcBufs =
8277 astUnit->getSourceManager().getMemoryBufferSizes();
8278
8279 createCXTUResourceUsageEntry(*entries,
8280 CXTUResourceUsage_SourceManager_Membuffer_Malloc,
8281 (unsigned long) srcBufs.malloc_bytes);
8282 createCXTUResourceUsageEntry(*entries,
8283 CXTUResourceUsage_SourceManager_Membuffer_MMap,
8284 (unsigned long) srcBufs.mmap_bytes);
8285 createCXTUResourceUsageEntry(*entries,
8286 CXTUResourceUsage_SourceManager_DataStructures,
8287 (unsigned long) astContext.getSourceManager()
8288 .getDataStructureSizes());
8289
8290 // How much memory is being used by the ExternalASTSource?
8291 if (ExternalASTSource *esrc = astContext.getExternalSource()) {
8292 const ExternalASTSource::MemoryBufferSizes &sizes =
8293 esrc->getMemoryBufferSizes();
8294
8295 createCXTUResourceUsageEntry(*entries,
8296 CXTUResourceUsage_ExternalASTSource_Membuffer_Malloc,
8297 (unsigned long) sizes.malloc_bytes);
8298 createCXTUResourceUsageEntry(*entries,
8299 CXTUResourceUsage_ExternalASTSource_Membuffer_MMap,
8300 (unsigned long) sizes.mmap_bytes);
8301 }
8302
8303 // How much memory is being used by the Preprocessor?
8304 Preprocessor &pp = astUnit->getPreprocessor();
8305 createCXTUResourceUsageEntry(*entries,
8306 CXTUResourceUsage_Preprocessor,
8307 pp.getTotalMemory());
8308
8309 if (PreprocessingRecord *pRec = pp.getPreprocessingRecord()) {
8310 createCXTUResourceUsageEntry(*entries,
8311 CXTUResourceUsage_PreprocessingRecord,
8312 pRec->getTotalMemory());
8313 }
8314
8315 createCXTUResourceUsageEntry(*entries,
8316 CXTUResourceUsage_Preprocessor_HeaderSearch,
8317 pp.getHeaderSearchInfo().getTotalMemory());
8318
8319 CXTUResourceUsage usage = { (void*) entries.get(),
8320 (unsigned) entries->size(),
8321 !entries->empty() ? &(*entries)[0] : nullptr };
8322 (void)entries.release();
8323 return usage;
8324}
8325
8326void clang_disposeCXTUResourceUsage(CXTUResourceUsage usage) {
8327 if (usage.data)
8328 delete (MemUsageEntries*) usage.data;
8329}
8330
8331CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit TU, CXFile file) {
8332 CXSourceRangeList *skipped = new CXSourceRangeList;
8333 skipped->count = 0;
8334 skipped->ranges = nullptr;
8335
8336 if (isNotUsableTU(TU)) {
8337 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
8338 return skipped;
8339 }
8340
8341 if (!file)
8342 return skipped;
8343
8344 ASTUnit *astUnit = cxtu::getASTUnit(TU);
8345 PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord();
8346 if (!ppRec)
8347 return skipped;
8348
8349 ASTContext &Ctx = astUnit->getASTContext();
8350 SourceManager &sm = Ctx.getSourceManager();
8351 FileEntry *fileEntry = static_cast<FileEntry *>(file);
8352 FileID wantedFileID = sm.translateFile(fileEntry);
8353 bool isMainFile = wantedFileID == sm.getMainFileID();
8354
8355 const std::vector<SourceRange> &SkippedRanges = ppRec->getSkippedRanges();
8356 std::vector<SourceRange> wantedRanges;
8357 for (std::vector<SourceRange>::const_iterator i = SkippedRanges.begin(), ei = SkippedRanges.end();
8358 i != ei; ++i) {
8359 if (sm.getFileID(i->getBegin()) == wantedFileID || sm.getFileID(i->getEnd()) == wantedFileID)
8360 wantedRanges.push_back(*i);
8361 else if (isMainFile && (astUnit->isInPreambleFileID(i->getBegin()) || astUnit->isInPreambleFileID(i->getEnd())))
8362 wantedRanges.push_back(*i);
8363 }
8364
8365 skipped->count = wantedRanges.size();
8366 skipped->ranges = new CXSourceRange[skipped->count];
8367 for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
8368 skipped->ranges[i] = cxloc::translateSourceRange(Ctx, wantedRanges[i]);
8369
8370 return skipped;
8371}
8372
8373CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
8374 CXSourceRangeList *skipped = new CXSourceRangeList;
8375 skipped->count = 0;
8376 skipped->ranges = nullptr;
8377
8378 if (isNotUsableTU(TU)) {
8379 LOG_BAD_TU(TU)do { if (clang::cxindex::LogRef Log = clang::cxindex::Logger::
make(__func__)) { *Log << "called with a bad TU: " <<
TU; } } while(false)
;
8380 return skipped;
8381 }
8382
8383 ASTUnit *astUnit = cxtu::getASTUnit(TU);
8384 PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord();
8385 if (!ppRec)
8386 return skipped;
8387
8388 ASTContext &Ctx = astUnit->getASTContext();
8389
8390 const std::vector<SourceRange> &SkippedRanges = ppRec->getSkippedRanges();
8391
8392 skipped->count = SkippedRanges.size();
8393 skipped->ranges = new CXSourceRange[skipped->count];
8394 for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
8395 skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]);
8396
8397 return skipped;
8398}
8399
8400void clang_disposeSourceRangeList(CXSourceRangeList *ranges) {
8401 if (ranges) {
8402 delete[] ranges->ranges;
8403 delete ranges;
8404 }
8405}
8406
8407void clang::PrintLibclangResourceUsage(CXTranslationUnit TU) {
8408 CXTUResourceUsage Usage = clang_getCXTUResourceUsage(TU);
8409 for (unsigned I = 0; I != Usage.numEntries; ++I)
8410 fprintf(stderrstderr, " %s: %lu\n",
8411 clang_getTUResourceUsageName(Usage.entries[I].kind),
8412 Usage.entries[I].amount);
8413
8414 clang_disposeCXTUResourceUsage(Usage);
8415}
8416
8417//===----------------------------------------------------------------------===//
8418// Misc. utility functions.
8419//===----------------------------------------------------------------------===//
8420
8421/// Default to using an 8 MB stack size on "safety" threads.
8422static unsigned SafetyStackThreadSize = 8 << 20;
8423
8424namespace clang {
8425
8426bool RunSafely(llvm::CrashRecoveryContext &CRC, llvm::function_ref<void()> Fn,
8427 unsigned Size) {
8428 if (!Size)
8429 Size = GetSafetyThreadStackSize();
8430 if (Size && !getenv("LIBCLANG_NOTHREADS"))
8431 return CRC.RunSafelyOnThread(Fn, Size);
8432 return CRC.RunSafely(Fn);
8433}
8434
8435unsigned GetSafetyThreadStackSize() {
8436 return SafetyStackThreadSize;
8437}
8438
8439void SetSafetyThreadStackSize(unsigned Value) {
8440 SafetyStackThreadSize = Value;
8441}
8442
8443}
8444
8445void clang::setThreadBackgroundPriority() {
8446 if (getenv("LIBCLANG_BGPRIO_DISABLE"))
8447 return;
8448
8449#ifdef USE_DARWIN_THREADS
8450 setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG);
8451#endif
8452}
8453
8454void cxindex::printDiagsToStderr(ASTUnit *Unit) {
8455 if (!Unit)
8456 return;
8457
8458 for (ASTUnit::stored_diag_iterator D = Unit->stored_diag_begin(),
8459 DEnd = Unit->stored_diag_end();
8460 D != DEnd; ++D) {
8461 CXStoredDiagnostic Diag(*D, Unit->getLangOpts());
8462 CXString Msg = clang_formatDiagnostic(&Diag,
8463 clang_defaultDiagnosticDisplayOptions());
8464 fprintf(stderrstderr, "%s\n", clang_getCString(Msg));
8465 clang_disposeString(Msg);
8466 }
8467#ifdef LLVM_ON_WIN32
8468 // On Windows, force a flush, since there may be multiple copies of
8469 // stderr and stdout in the file system, all with different buffers
8470 // but writing to the same device.
8471 fflush(stderrstderr);
8472#endif
8473}
8474
8475MacroInfo *cxindex::getMacroInfo(const IdentifierInfo &II,
8476 SourceLocation MacroDefLoc,
8477 CXTranslationUnit TU){
8478 if (MacroDefLoc.isInvalid() || !TU)
8479 return nullptr;
8480 if (!II.hadMacroDefinition())
8481 return nullptr;
8482
8483 ASTUnit *Unit = cxtu::getASTUnit(TU);
8484 Preprocessor &PP = Unit->getPreprocessor();
8485 MacroDirective *MD = PP.getLocalMacroDirectiveHistory(&II);
8486 if (MD) {
8487 for (MacroDirective::DefInfo
8488 Def = MD->getDefinition(); Def; Def = Def.getPreviousDefinition()) {
8489 if (MacroDefLoc == Def.getMacroInfo()->getDefinitionLoc())
8490 return Def.getMacroInfo();
8491 }
8492 }
8493
8494 return nullptr;
8495}
8496
8497const MacroInfo *cxindex::getMacroInfo(const MacroDefinitionRecord *MacroDef,
8498 CXTranslationUnit TU) {
8499 if (!MacroDef || !TU)
8500 return nullptr;
8501 const IdentifierInfo *II = MacroDef->getName();
8502 if (!II)
8503 return nullptr;
8504
8505 return getMacroInfo(*II, MacroDef->getLocation(), TU);
8506}
8507
8508MacroDefinitionRecord *
8509cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI, const Token &Tok,
8510 CXTranslationUnit TU) {
8511 if (!MI || !TU)
8512 return nullptr;
8513 if (Tok.isNot(tok::raw_identifier))
8514 return nullptr;
8515
8516 if (MI->getNumTokens() == 0)
8517 return nullptr;
8518 SourceRange DefRange(MI->getReplacementToken(0).getLocation(),
8519 MI->getDefinitionEndLoc());
8520 ASTUnit *Unit = cxtu::getASTUnit(TU);
8521
8522 // Check that the token is inside the definition and not its argument list.
8523 SourceManager &SM = Unit->getSourceManager();
8524 if (SM.isBeforeInTranslationUnit(Tok.getLocation(), DefRange.getBegin()))
8525 return nullptr;
8526 if (SM.isBeforeInTranslationUnit(DefRange.getEnd(), Tok.getLocation()))
8527 return nullptr;
8528
8529 Preprocessor &PP = Unit->getPreprocessor();
8530 PreprocessingRecord *PPRec = PP.getPreprocessingRecord();
8531 if (!PPRec)
8532 return nullptr;
8533
8534 IdentifierInfo &II = PP.getIdentifierTable().get(Tok.getRawIdentifier());
8535 if (!II.hadMacroDefinition())
8536 return nullptr;
8537
8538 // Check that the identifier is not one of the macro arguments.
8539 if (std::find(MI->param_begin(), MI->param_end(), &II) != MI->param_end())
8540 return nullptr;
8541
8542 MacroDirective *InnerMD = PP.getLocalMacroDirectiveHistory(&II);
8543 if (!InnerMD)
8544 return nullptr;
8545
8546 return PPRec->findMacroDefinition(InnerMD->getMacroInfo());
8547}
8548
8549MacroDefinitionRecord *
8550cxindex::checkForMacroInMacroDefinition(const MacroInfo *MI, SourceLocation Loc,
8551 CXTranslationUnit TU) {
8552 if (Loc.isInvalid() || !MI || !TU)
8553 return nullptr;
8554
8555 if (MI->getNumTokens() == 0)
8556 return nullptr;
8557 ASTUnit *Unit = cxtu::getASTUnit(TU);
8558 Preprocessor &PP = Unit->getPreprocessor();
8559 if (!PP.getPreprocessingRecord())
8560 return nullptr;
8561 Loc = Unit->getSourceManager().getSpellingLoc(Loc);
8562 Token Tok;
8563 if (PP.getRawToken(Loc, Tok))
8564 return nullptr;
8565
8566 return checkForMacroInMacroDefinition(MI, Tok, TU);
8567}
8568
8569CXString clang_getClangVersion() {
8570 return cxstring::createDup(getClangFullVersion());
8571}
8572
8573Logger &cxindex::Logger::operator<<(CXTranslationUnit TU) {
8574 if (TU) {
8575 if (ASTUnit *Unit = cxtu::getASTUnit(TU)) {
8576 LogOS << '<' << Unit->getMainFileName() << '>';
8577 if (Unit->isMainFileAST())
8578 LogOS << " (" << Unit->getASTFileName() << ')';
8579 return *this;
8580 }
8581 } else {
8582 LogOS << "<NULL TU>";
8583 }
8584 return *this;
8585}
8586
8587Logger &cxindex::Logger::operator<<(const FileEntry *FE) {
8588 *this << FE->getName();
8589 return *this;
8590}
8591
8592Logger &cxindex::Logger::operator<<(CXCursor cursor) {
8593 CXString cursorName = clang_getCursorDisplayName(cursor);
8594 *this << cursorName << "@" << clang_getCursorLocation(cursor);
8595 clang_disposeString(cursorName);
8596 return *this;
8597}
8598
8599Logger &cxindex::Logger::operator<<(CXSourceLocation Loc) {
8600 CXFile File;
8601 unsigned Line, Column;
8602 clang_getFileLocation(Loc, &File, &Line, &Column, nullptr);
8603 CXString FileName = clang_getFileName(File);
8604 *this << llvm::format("(%s:%d:%d)", clang_getCString(FileName), Line, Column);
8605 clang_disposeString(FileName);
8606 return *this;
8607}
8608
8609Logger &cxindex::Logger::operator<<(CXSourceRange range) {
8610 CXSourceLocation BLoc = clang_getRangeStart(range);
8611 CXSourceLocation ELoc = clang_getRangeEnd(range);
8612
8613 CXFile BFile;
8614 unsigned BLine, BColumn;
8615 clang_getFileLocation(BLoc, &BFile, &BLine, &BColumn, nullptr);
8616
8617 CXFile EFile;
8618 unsigned ELine, EColumn;
8619 clang_getFileLocation(ELoc, &EFile, &ELine, &EColumn, nullptr);
8620
8621 CXString BFileName = clang_getFileName(BFile);
8622 if (BFile == EFile) {
8623 *this << llvm::format("[%s %d:%d-%d:%d]", clang_getCString(BFileName),
8624 BLine, BColumn, ELine, EColumn);
8625 } else {
8626 CXString EFileName = clang_getFileName(EFile);
8627 *this << llvm::format("[%s:%d:%d - ", clang_getCString(BFileName),
8628 BLine, BColumn)
8629 << llvm::format("%s:%d:%d]", clang_getCString(EFileName),
8630 ELine, EColumn);
8631 clang_disposeString(EFileName);
8632 }
8633 clang_disposeString(BFileName);
8634 return *this;
8635}
8636
8637Logger &cxindex::Logger::operator<<(CXString Str) {
8638 *this << clang_getCString(Str);
8639 return *this;
8640}
8641
8642Logger &cxindex::Logger::operator<<(const llvm::format_object_base &Fmt) {
8643 LogOS << Fmt;
8644 return *this;
8645}
8646
8647static llvm::ManagedStatic<llvm::sys::Mutex> LoggingMutex;
8648
8649cxindex::Logger::~Logger() {
8650 llvm::sys::ScopedLock L(*LoggingMutex);
8651
8652 static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();
8653
8654 raw_ostream &OS = llvm::errs();
8655 OS << "[libclang:" << Name << ':';
8656
8657#ifdef USE_DARWIN_THREADS
8658 // TODO: Portability.
8659 mach_port_t tid = pthread_mach_thread_np(pthread_self());
8660 OS << tid << ':';
8661#endif
8662
8663 llvm::TimeRecord TR = llvm::TimeRecord::getCurrentTime();
8664 OS << llvm::format("%7.4f] ", TR.getWallTime() - sBeginTR.getWallTime());
8665 OS << Msg << '\n';
8666
8667 if (Trace) {
8668 llvm::sys::PrintStackTrace(OS);
8669 OS << "--------------------------------------------------\n";
8670 }
8671}
8672
8673#ifdef CLANG_TOOL_EXTRA_BUILD1
8674// This anchor is used to force the linker to link the clang-tidy plugin.
8675extern volatile int ClangTidyPluginAnchorSource;
8676static int LLVM_ATTRIBUTE_UNUSED__attribute__((__unused__)) ClangTidyPluginAnchorDestination =
8677 ClangTidyPluginAnchorSource;
8678
8679// This anchor is used to force the linker to link the clang-include-fixer
8680// plugin.
8681extern volatile int ClangIncludeFixerPluginAnchorSource;
8682static int LLVM_ATTRIBUTE_UNUSED__attribute__((__unused__)) ClangIncludeFixerPluginAnchorDestination =
8683 ClangIncludeFixerPluginAnchorSource;
8684#endif

/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc

1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* Attribute classes' definitions *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9#ifndef LLVM_CLANG_ATTR_CLASSES_INC
10#define LLVM_CLANG_ATTR_CLASSES_INC
11
12class AMDGPUFlatWorkGroupSizeAttr : public InheritableAttr {
13unsigned min;
14
15unsigned max;
16
17public:
18 static AMDGPUFlatWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned Min, unsigned Max, SourceRange Loc = SourceRange()) {
19 auto *A = new (Ctx) AMDGPUFlatWorkGroupSizeAttr(Loc, Ctx, Min, Max, 0);
20 A->setImplicit(true);
21 return A;
22 }
23
24 AMDGPUFlatWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx
25 , unsigned Min
26 , unsigned Max
27 , unsigned SI
28 )
29 : InheritableAttr(attr::AMDGPUFlatWorkGroupSize, R, SI, false, false)
30 , min(Min)
31 , max(Max)
32 {
33 }
34
35 AMDGPUFlatWorkGroupSizeAttr *clone(ASTContext &C) const;
36 void printPretty(raw_ostream &OS,
37 const PrintingPolicy &Policy) const;
38 const char *getSpelling() const;
39 unsigned getMin() const {
40 return min;
41 }
42
43 unsigned getMax() const {
44 return max;
45 }
46
47
48
49 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUFlatWorkGroupSize; }
50};
51
52class AMDGPUNumSGPRAttr : public InheritableAttr {
53unsigned numSGPR;
54
55public:
56 static AMDGPUNumSGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumSGPR, SourceRange Loc = SourceRange()) {
57 auto *A = new (Ctx) AMDGPUNumSGPRAttr(Loc, Ctx, NumSGPR, 0);
58 A->setImplicit(true);
59 return A;
60 }
61
62 AMDGPUNumSGPRAttr(SourceRange R, ASTContext &Ctx
63 , unsigned NumSGPR
64 , unsigned SI
65 )
66 : InheritableAttr(attr::AMDGPUNumSGPR, R, SI, false, false)
67 , numSGPR(NumSGPR)
68 {
69 }
70
71 AMDGPUNumSGPRAttr *clone(ASTContext &C) const;
72 void printPretty(raw_ostream &OS,
73 const PrintingPolicy &Policy) const;
74 const char *getSpelling() const;
75 unsigned getNumSGPR() const {
76 return numSGPR;
77 }
78
79
80
81 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumSGPR; }
82};
83
84class AMDGPUNumVGPRAttr : public InheritableAttr {
85unsigned numVGPR;
86
87public:
88 static AMDGPUNumVGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumVGPR, SourceRange Loc = SourceRange()) {
89 auto *A = new (Ctx) AMDGPUNumVGPRAttr(Loc, Ctx, NumVGPR, 0);
90 A->setImplicit(true);
91 return A;
92 }
93
94 AMDGPUNumVGPRAttr(SourceRange R, ASTContext &Ctx
95 , unsigned NumVGPR
96 , unsigned SI
97 )
98 : InheritableAttr(attr::AMDGPUNumVGPR, R, SI, false, false)
99 , numVGPR(NumVGPR)
100 {
101 }
102
103 AMDGPUNumVGPRAttr *clone(ASTContext &C) const;
104 void printPretty(raw_ostream &OS,
105 const PrintingPolicy &Policy) const;
106 const char *getSpelling() const;
107 unsigned getNumVGPR() const {
108 return numVGPR;
109 }
110
111
112
113 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumVGPR; }
114};
115
116class AMDGPUWavesPerEUAttr : public InheritableAttr {
117unsigned min;
118
119unsigned max;
120
121public:
122 static AMDGPUWavesPerEUAttr *CreateImplicit(ASTContext &Ctx, unsigned Min, unsigned Max, SourceRange Loc = SourceRange()) {
123 auto *A = new (Ctx) AMDGPUWavesPerEUAttr(Loc, Ctx, Min, Max, 0);
124 A->setImplicit(true);
125 return A;
126 }
127
128 AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx
129 , unsigned Min
130 , unsigned Max
131 , unsigned SI
132 )
133 : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false)
134 , min(Min)
135 , max(Max)
136 {
137 }
138
139 AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx
140 , unsigned Min
141 , unsigned SI
142 )
143 : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false)
144 , min(Min)
145 , max()
146 {
147 }
148
149 AMDGPUWavesPerEUAttr *clone(ASTContext &C) const;
150 void printPretty(raw_ostream &OS,
151 const PrintingPolicy &Policy) const;
152 const char *getSpelling() const;
153 unsigned getMin() const {
154 return min;
155 }
156
157 unsigned getMax() const {
158 return max;
159 }
160
161
162
163 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUWavesPerEU; }
164};
165
166class ARMInterruptAttr : public InheritableAttr {
167public:
168 enum InterruptType {
169 IRQ,
170 FIQ,
171 SWI,
172 ABORT,
173 UNDEF,
174 Generic
175 };
176private:
177 InterruptType interrupt;
178
179public:
180 static ARMInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) {
181 auto *A = new (Ctx) ARMInterruptAttr(Loc, Ctx, Interrupt, 0);
182 A->setImplicit(true);
183 return A;
184 }
185
186 ARMInterruptAttr(SourceRange R, ASTContext &Ctx
187 , InterruptType Interrupt
188 , unsigned SI
189 )
190 : InheritableAttr(attr::ARMInterrupt, R, SI, false, false)
191 , interrupt(Interrupt)
192 {
193 }
194
195 ARMInterruptAttr(SourceRange R, ASTContext &Ctx
196 , unsigned SI
197 )
198 : InheritableAttr(attr::ARMInterrupt, R, SI, false, false)
199 , interrupt(InterruptType(0))
200 {
201 }
202
203 ARMInterruptAttr *clone(ASTContext &C) const;
204 void printPretty(raw_ostream &OS,
205 const PrintingPolicy &Policy) const;
206 const char *getSpelling() const;
207 InterruptType getInterrupt() const {
208 return interrupt;
209 }
210
211 static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) {
212 Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val)
213 .Case("IRQ", ARMInterruptAttr::IRQ)
214 .Case("FIQ", ARMInterruptAttr::FIQ)
215 .Case("SWI", ARMInterruptAttr::SWI)
216 .Case("ABORT", ARMInterruptAttr::ABORT)
217 .Case("UNDEF", ARMInterruptAttr::UNDEF)
218 .Case("", ARMInterruptAttr::Generic)
219 .Default(Optional<InterruptType>());
220 if (R) {
221 Out = *R;
222 return true;
223 }
224 return false;
225 }
226
227 static const char *ConvertInterruptTypeToStr(InterruptType Val) {
228 switch(Val) {
229 case ARMInterruptAttr::IRQ: return "IRQ";
230 case ARMInterruptAttr::FIQ: return "FIQ";
231 case ARMInterruptAttr::SWI: return "SWI";
232 case ARMInterruptAttr::ABORT: return "ABORT";
233 case ARMInterruptAttr::UNDEF: return "UNDEF";
234 case ARMInterruptAttr::Generic: return "";
235 }
236 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 236)
;
237 }
238
239
240 static bool classof(const Attr *A) { return A->getKind() == attr::ARMInterrupt; }
241};
242
243class AVRInterruptAttr : public InheritableAttr {
244public:
245 static AVRInterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
246 auto *A = new (Ctx) AVRInterruptAttr(Loc, Ctx, 0);
247 A->setImplicit(true);
248 return A;
249 }
250
251 AVRInterruptAttr(SourceRange R, ASTContext &Ctx
252 , unsigned SI
253 )
254 : InheritableAttr(attr::AVRInterrupt, R, SI, false, false)
255 {
256 }
257
258 AVRInterruptAttr *clone(ASTContext &C) const;
259 void printPretty(raw_ostream &OS,
260 const PrintingPolicy &Policy) const;
261 const char *getSpelling() const;
262
263
264 static bool classof(const Attr *A) { return A->getKind() == attr::AVRInterrupt; }
265};
266
267class AVRSignalAttr : public InheritableAttr {
268public:
269 static AVRSignalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
270 auto *A = new (Ctx) AVRSignalAttr(Loc, Ctx, 0);
271 A->setImplicit(true);
272 return A;
273 }
274
275 AVRSignalAttr(SourceRange R, ASTContext &Ctx
276 , unsigned SI
277 )
278 : InheritableAttr(attr::AVRSignal, R, SI, false, false)
279 {
280 }
281
282 AVRSignalAttr *clone(ASTContext &C) const;
283 void printPretty(raw_ostream &OS,
284 const PrintingPolicy &Policy) const;
285 const char *getSpelling() const;
286
287
288 static bool classof(const Attr *A) { return A->getKind() == attr::AVRSignal; }
289};
290
291class AbiTagAttr : public Attr {
292 unsigned tags_Size;
293 StringRef *tags_;
294
295public:
296 static AbiTagAttr *CreateImplicit(ASTContext &Ctx, StringRef *Tags, unsigned TagsSize, SourceRange Loc = SourceRange()) {
297 auto *A = new (Ctx) AbiTagAttr(Loc, Ctx, Tags, TagsSize, 0);
298 A->setImplicit(true);
299 return A;
300 }
301
302 AbiTagAttr(SourceRange R, ASTContext &Ctx
303 , StringRef *Tags, unsigned TagsSize
304 , unsigned SI
305 )
306 : Attr(attr::AbiTag, R, SI, false)
307 , tags_Size(TagsSize), tags_(new (Ctx, 16) StringRef[tags_Size])
308 {
309 for (size_t I = 0, E = tags_Size; I != E;
310 ++I) {
311 StringRef Ref = Tags[I];
312 if (!Ref.empty()) {
313 char *Mem = new (Ctx, 1) char[Ref.size()];
314 std::memcpy(Mem, Ref.data(), Ref.size());
315 tags_[I] = StringRef(Mem, Ref.size());
316 }
317 }
318 }
319
320 AbiTagAttr(SourceRange R, ASTContext &Ctx
321 , unsigned SI
322 )
323 : Attr(attr::AbiTag, R, SI, false)
324 , tags_Size(0), tags_(nullptr)
325 {
326 }
327
328 AbiTagAttr *clone(ASTContext &C) const;
329 void printPretty(raw_ostream &OS,
330 const PrintingPolicy &Policy) const;
331 const char *getSpelling() const;
332 typedef StringRef* tags_iterator;
333 tags_iterator tags_begin() const { return tags_; }
334 tags_iterator tags_end() const { return tags_ + tags_Size; }
335 unsigned tags_size() const { return tags_Size; }
336 llvm::iterator_range<tags_iterator> tags() const { return llvm::make_range(tags_begin(), tags_end()); }
337
338
339
340
341 static bool classof(const Attr *A) { return A->getKind() == attr::AbiTag; }
342};
343
344class AcquireCapabilityAttr : public InheritableAttr {
345 unsigned args_Size;
346 Expr * *args_;
347
348public:
349 enum Spelling {
350 GNU_acquire_capability = 0,
351 CXX11_clang_acquire_capability = 1,
352 GNU_acquire_shared_capability = 2,
353 CXX11_clang_acquire_shared_capability = 3,
354 GNU_exclusive_lock_function = 4,
355 GNU_shared_lock_function = 5
356 };
357
358 static AcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
359 auto *A = new (Ctx) AcquireCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
360 A->setImplicit(true);
361 return A;
362 }
363
364 AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
365 , Expr * *Args, unsigned ArgsSize
366 , unsigned SI
367 )
368 : InheritableAttr(attr::AcquireCapability, R, SI, true, true)
369 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
370 {
371 std::copy(Args, Args + args_Size, args_);
372 }
373
374 AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
375 , unsigned SI
376 )
377 : InheritableAttr(attr::AcquireCapability, R, SI, true, true)
378 , args_Size(0), args_(nullptr)
379 {
380 }
381
382 AcquireCapabilityAttr *clone(ASTContext &C) const;
383 void printPretty(raw_ostream &OS,
384 const PrintingPolicy &Policy) const;
385 const char *getSpelling() const;
386 Spelling getSemanticSpelling() const {
387 switch (SpellingListIndex) {
388 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 388)
;
389 case 0: return GNU_acquire_capability;
390 case 1: return CXX11_clang_acquire_capability;
391 case 2: return GNU_acquire_shared_capability;
392 case 3: return CXX11_clang_acquire_shared_capability;
393 case 4: return GNU_exclusive_lock_function;
394 case 5: return GNU_shared_lock_function;
395 }
396 }
397 bool isShared() const { return SpellingListIndex == 2 ||
398 SpellingListIndex == 3 ||
399 SpellingListIndex == 5; }
400 typedef Expr ** args_iterator;
401 args_iterator args_begin() const { return args_; }
402 args_iterator args_end() const { return args_ + args_Size; }
403 unsigned args_size() const { return args_Size; }
404 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
405
406
407
408
409 static bool classof(const Attr *A) { return A->getKind() == attr::AcquireCapability; }
410};
411
412class AcquiredAfterAttr : public InheritableAttr {
413 unsigned args_Size;
414 Expr * *args_;
415
416public:
417 static AcquiredAfterAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
418 auto *A = new (Ctx) AcquiredAfterAttr(Loc, Ctx, Args, ArgsSize, 0);
419 A->setImplicit(true);
420 return A;
421 }
422
423 AcquiredAfterAttr(SourceRange R, ASTContext &Ctx
424 , Expr * *Args, unsigned ArgsSize
425 , unsigned SI
426 )
427 : InheritableAttr(attr::AcquiredAfter, R, SI, true, true)
428 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
429 {
430 std::copy(Args, Args + args_Size, args_);
431 }
432
433 AcquiredAfterAttr(SourceRange R, ASTContext &Ctx
434 , unsigned SI
435 )
436 : InheritableAttr(attr::AcquiredAfter, R, SI, true, true)
437 , args_Size(0), args_(nullptr)
438 {
439 }
440
441 AcquiredAfterAttr *clone(ASTContext &C) const;
442 void printPretty(raw_ostream &OS,
443 const PrintingPolicy &Policy) const;
444 const char *getSpelling() const;
445 typedef Expr ** args_iterator;
446 args_iterator args_begin() const { return args_; }
447 args_iterator args_end() const { return args_ + args_Size; }
448 unsigned args_size() const { return args_Size; }
449 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
450
451
452
453
454 static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredAfter; }
455};
456
457class AcquiredBeforeAttr : public InheritableAttr {
458 unsigned args_Size;
459 Expr * *args_;
460
461public:
462 static AcquiredBeforeAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
463 auto *A = new (Ctx) AcquiredBeforeAttr(Loc, Ctx, Args, ArgsSize, 0);
464 A->setImplicit(true);
465 return A;
466 }
467
468 AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx
469 , Expr * *Args, unsigned ArgsSize
470 , unsigned SI
471 )
472 : InheritableAttr(attr::AcquiredBefore, R, SI, true, true)
473 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
474 {
475 std::copy(Args, Args + args_Size, args_);
476 }
477
478 AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx
479 , unsigned SI
480 )
481 : InheritableAttr(attr::AcquiredBefore, R, SI, true, true)
482 , args_Size(0), args_(nullptr)
483 {
484 }
485
486 AcquiredBeforeAttr *clone(ASTContext &C) const;
487 void printPretty(raw_ostream &OS,
488 const PrintingPolicy &Policy) const;
489 const char *getSpelling() const;
490 typedef Expr ** args_iterator;
491 args_iterator args_begin() const { return args_; }
492 args_iterator args_end() const { return args_ + args_Size; }
493 unsigned args_size() const { return args_Size; }
494 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
495
496
497
498
499 static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredBefore; }
500};
501
502class AliasAttr : public Attr {
503unsigned aliaseeLength;
504char *aliasee;
505
506public:
507 static AliasAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) {
508 auto *A = new (Ctx) AliasAttr(Loc, Ctx, Aliasee, 0);
509 A->setImplicit(true);
510 return A;
511 }
512
513 AliasAttr(SourceRange R, ASTContext &Ctx
514 , llvm::StringRef Aliasee
515 , unsigned SI
516 )
517 : Attr(attr::Alias, R, SI, false)
518 , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength])
519 {
520 if (!Aliasee.empty())
521 std::memcpy(aliasee, Aliasee.data(), aliaseeLength);
522 }
523
524 AliasAttr *clone(ASTContext &C) const;
525 void printPretty(raw_ostream &OS,
526 const PrintingPolicy &Policy) const;
527 const char *getSpelling() const;
528 llvm::StringRef getAliasee() const {
529 return llvm::StringRef(aliasee, aliaseeLength);
530 }
531 unsigned getAliaseeLength() const {
532 return aliaseeLength;
533 }
534 void setAliasee(ASTContext &C, llvm::StringRef S) {
535 aliaseeLength = S.size();
536 this->aliasee = new (C, 1) char [aliaseeLength];
537 if (!S.empty())
538 std::memcpy(this->aliasee, S.data(), aliaseeLength);
539 }
540
541
542
543 static bool classof(const Attr *A) { return A->getKind() == attr::Alias; }
544};
545
546class AlignMac68kAttr : public InheritableAttr {
547public:
548 static AlignMac68kAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
549 auto *A = new (Ctx) AlignMac68kAttr(Loc, Ctx, 0);
550 A->setImplicit(true);
551 return A;
552 }
553
554 AlignMac68kAttr(SourceRange R, ASTContext &Ctx
555 , unsigned SI
556 )
557 : InheritableAttr(attr::AlignMac68k, R, SI, false, false)
558 {
559 }
560
561 AlignMac68kAttr *clone(ASTContext &C) const;
562 void printPretty(raw_ostream &OS,
563 const PrintingPolicy &Policy) const;
564 const char *getSpelling() const;
565
566
567 static bool classof(const Attr *A) { return A->getKind() == attr::AlignMac68k; }
568};
569
570class AlignValueAttr : public Attr {
571Expr * alignment;
572
573public:
574 static AlignValueAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, SourceRange Loc = SourceRange()) {
575 auto *A = new (Ctx) AlignValueAttr(Loc, Ctx, Alignment, 0);
576 A->setImplicit(true);
577 return A;
578 }
579
580 AlignValueAttr(SourceRange R, ASTContext &Ctx
581 , Expr * Alignment
582 , unsigned SI
583 )
584 : Attr(attr::AlignValue, R, SI, false)
585 , alignment(Alignment)
586 {
587 }
588
589 AlignValueAttr *clone(ASTContext &C) const;
590 void printPretty(raw_ostream &OS,
591 const PrintingPolicy &Policy) const;
592 const char *getSpelling() const;
593 Expr * getAlignment() const {
594 return alignment;
595 }
596
597
598
599 static bool classof(const Attr *A) { return A->getKind() == attr::AlignValue; }
600};
601
602class AlignedAttr : public InheritableAttr {
603bool isalignmentExpr;
604union {
605Expr *alignmentExpr;
606TypeSourceInfo *alignmentType;
607};
608
609public:
610 enum Spelling {
611 GNU_aligned = 0,
612 CXX11_gnu_aligned = 1,
613 Declspec_align = 2,
614 Keyword_alignas = 3,
615 Keyword_Alignas = 4
616 };
617
618 static AlignedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool IsAlignmentExpr, void *Alignment, SourceRange Loc = SourceRange()) {
619 auto *A = new (Ctx) AlignedAttr(Loc, Ctx, IsAlignmentExpr, Alignment, S);
620 A->setImplicit(true);
621 return A;
622 }
623
624 AlignedAttr(SourceRange R, ASTContext &Ctx
625 , bool IsAlignmentExpr, void *Alignment
626 , unsigned SI
627 )
628 : InheritableAttr(attr::Aligned, R, SI, false, false)
629 , isalignmentExpr(IsAlignmentExpr)
630 {
631 if (isalignmentExpr)
632 alignmentExpr = reinterpret_cast<Expr *>(Alignment);
633 else
634 alignmentType = reinterpret_cast<TypeSourceInfo *>(Alignment);
635 }
636
637 AlignedAttr(SourceRange R, ASTContext &Ctx
638 , unsigned SI
639 )
640 : InheritableAttr(attr::Aligned, R, SI, false, false)
641 , isalignmentExpr(false)
642 {
643 }
644
645 AlignedAttr *clone(ASTContext &C) const;
646 void printPretty(raw_ostream &OS,
647 const PrintingPolicy &Policy) const;
648 const char *getSpelling() const;
649 Spelling getSemanticSpelling() const {
650 switch (SpellingListIndex) {
651 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 651)
;
652 case 0: return GNU_aligned;
653 case 1: return CXX11_gnu_aligned;
654 case 2: return Declspec_align;
655 case 3: return Keyword_alignas;
656 case 4: return Keyword_Alignas;
657 }
658 }
659 bool isGNU() const { return SpellingListIndex == 0 ||
660 SpellingListIndex == 1; }
661 bool isC11() const { return SpellingListIndex == 4; }
662 bool isAlignas() const { return SpellingListIndex == 3 ||
663 SpellingListIndex == 4; }
664 bool isDeclspec() const { return SpellingListIndex == 2; }
665 bool isAlignmentDependent() const;
666 unsigned getAlignment(ASTContext &Ctx) const;
667 bool isAlignmentExpr() const {
668 return isalignmentExpr;
669 }
670 Expr *getAlignmentExpr() const {
671 assert(isalignmentExpr)(static_cast <bool> (isalignmentExpr) ? void (0) : __assert_fail
("isalignmentExpr", "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 671, __extension__ __PRETTY_FUNCTION__))
;
672 return alignmentExpr;
673 }
674 TypeSourceInfo *getAlignmentType() const {
675 assert(!isalignmentExpr)(static_cast <bool> (!isalignmentExpr) ? void (0) : __assert_fail
("!isalignmentExpr", "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 675, __extension__ __PRETTY_FUNCTION__))
;
676 return alignmentType;
677 }
678
679
680
681 static bool classof(const Attr *A) { return A->getKind() == attr::Aligned; }
682};
683
684class AllocAlignAttr : public InheritableAttr {
685int paramIndex;
686
687public:
688 static AllocAlignAttr *CreateImplicit(ASTContext &Ctx, int ParamIndex, SourceRange Loc = SourceRange()) {
689 auto *A = new (Ctx) AllocAlignAttr(Loc, Ctx, ParamIndex, 0);
690 A->setImplicit(true);
691 return A;
692 }
693
694 AllocAlignAttr(SourceRange R, ASTContext &Ctx
695 , int ParamIndex
696 , unsigned SI
697 )
698 : InheritableAttr(attr::AllocAlign, R, SI, false, false)
699 , paramIndex(ParamIndex)
700 {
701 }
702
703 AllocAlignAttr *clone(ASTContext &C) const;
704 void printPretty(raw_ostream &OS,
705 const PrintingPolicy &Policy) const;
706 const char *getSpelling() const;
707 int getParamIndex() const {
708 return paramIndex;
709 }
710
711
712
713 static bool classof(const Attr *A) { return A->getKind() == attr::AllocAlign; }
714};
715
716class AllocSizeAttr : public InheritableAttr {
717int elemSizeParam;
718
719int numElemsParam;
720
721public:
722 static AllocSizeAttr *CreateImplicit(ASTContext &Ctx, int ElemSizeParam, int NumElemsParam, SourceRange Loc = SourceRange()) {
723 auto *A = new (Ctx) AllocSizeAttr(Loc, Ctx, ElemSizeParam, NumElemsParam, 0);
724 A->setImplicit(true);
725 return A;
726 }
727
728 AllocSizeAttr(SourceRange R, ASTContext &Ctx
729 , int ElemSizeParam
730 , int NumElemsParam
731 , unsigned SI
732 )
733 : InheritableAttr(attr::AllocSize, R, SI, false, false)
734 , elemSizeParam(ElemSizeParam)
735 , numElemsParam(NumElemsParam)
736 {
737 }
738
739 AllocSizeAttr(SourceRange R, ASTContext &Ctx
740 , int ElemSizeParam
741 , unsigned SI
742 )
743 : InheritableAttr(attr::AllocSize, R, SI, false, false)
744 , elemSizeParam(ElemSizeParam)
745 , numElemsParam()
746 {
747 }
748
749 AllocSizeAttr *clone(ASTContext &C) const;
750 void printPretty(raw_ostream &OS,
751 const PrintingPolicy &Policy) const;
752 const char *getSpelling() const;
753 int getElemSizeParam() const {
754 return elemSizeParam;
755 }
756
757 int getNumElemsParam() const {
758 return numElemsParam;
759 }
760
761
762
763 static bool classof(const Attr *A) { return A->getKind() == attr::AllocSize; }
764};
765
766class AlwaysInlineAttr : public InheritableAttr {
767public:
768 enum Spelling {
769 GNU_always_inline = 0,
770 CXX11_gnu_always_inline = 1,
771 Keyword_forceinline = 2
772 };
773
774 static AlwaysInlineAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
775 auto *A = new (Ctx) AlwaysInlineAttr(Loc, Ctx, S);
776 A->setImplicit(true);
777 return A;
778 }
779
780 AlwaysInlineAttr(SourceRange R, ASTContext &Ctx
781 , unsigned SI
782 )
783 : InheritableAttr(attr::AlwaysInline, R, SI, false, false)
784 {
785 }
786
787 AlwaysInlineAttr *clone(ASTContext &C) const;
788 void printPretty(raw_ostream &OS,
789 const PrintingPolicy &Policy) const;
790 const char *getSpelling() const;
791 Spelling getSemanticSpelling() const {
792 switch (SpellingListIndex) {
793 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 793)
;
794 case 0: return GNU_always_inline;
795 case 1: return CXX11_gnu_always_inline;
796 case 2: return Keyword_forceinline;
797 }
798 }
799
800
801 static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysInline; }
802};
803
804class AnalyzerNoReturnAttr : public InheritableAttr {
805public:
806 static AnalyzerNoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
807 auto *A = new (Ctx) AnalyzerNoReturnAttr(Loc, Ctx, 0);
808 A->setImplicit(true);
809 return A;
810 }
811
812 AnalyzerNoReturnAttr(SourceRange R, ASTContext &Ctx
813 , unsigned SI
814 )
815 : InheritableAttr(attr::AnalyzerNoReturn, R, SI, false, false)
816 {
817 }
818
819 AnalyzerNoReturnAttr *clone(ASTContext &C) const;
820 void printPretty(raw_ostream &OS,
821 const PrintingPolicy &Policy) const;
822 const char *getSpelling() const;
823
824
825 static bool classof(const Attr *A) { return A->getKind() == attr::AnalyzerNoReturn; }
826};
827
828class AnnotateAttr : public InheritableParamAttr {
829unsigned annotationLength;
830char *annotation;
831
832public:
833 static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Annotation, SourceRange Loc = SourceRange()) {
834 auto *A = new (Ctx) AnnotateAttr(Loc, Ctx, Annotation, 0);
835 A->setImplicit(true);
836 return A;
837 }
838
839 AnnotateAttr(SourceRange R, ASTContext &Ctx
840 , llvm::StringRef Annotation
841 , unsigned SI
842 )
843 : InheritableParamAttr(attr::Annotate, R, SI, false, false)
844 , annotationLength(Annotation.size()),annotation(new (Ctx, 1) char[annotationLength])
845 {
846 if (!Annotation.empty())
847 std::memcpy(annotation, Annotation.data(), annotationLength);
848 }
849
850 AnnotateAttr *clone(ASTContext &C) const;
851 void printPretty(raw_ostream &OS,
852 const PrintingPolicy &Policy) const;
853 const char *getSpelling() const;
854 llvm::StringRef getAnnotation() const {
855 return llvm::StringRef(annotation, annotationLength);
856 }
857 unsigned getAnnotationLength() const {
858 return annotationLength;
859 }
860 void setAnnotation(ASTContext &C, llvm::StringRef S) {
861 annotationLength = S.size();
862 this->annotation = new (C, 1) char [annotationLength];
863 if (!S.empty())
864 std::memcpy(this->annotation, S.data(), annotationLength);
865 }
866
867
868
869 static bool classof(const Attr *A) { return A->getKind() == attr::Annotate; }
870};
871
872class AnyX86InterruptAttr : public InheritableAttr {
873public:
874 static AnyX86InterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
875 auto *A = new (Ctx) AnyX86InterruptAttr(Loc, Ctx, 0);
876 A->setImplicit(true);
877 return A;
878 }
879
880 AnyX86InterruptAttr(SourceRange R, ASTContext &Ctx
881 , unsigned SI
882 )
883 : InheritableAttr(attr::AnyX86Interrupt, R, SI, false, false)
884 {
885 }
886
887 AnyX86InterruptAttr *clone(ASTContext &C) const;
888 void printPretty(raw_ostream &OS,
889 const PrintingPolicy &Policy) const;
890 const char *getSpelling() const;
891
892
893 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86Interrupt; }
894};
895
896class AnyX86NoCallerSavedRegistersAttr : public InheritableAttr {
897public:
898 static AnyX86NoCallerSavedRegistersAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
899 auto *A = new (Ctx) AnyX86NoCallerSavedRegistersAttr(Loc, Ctx, 0);
900 A->setImplicit(true);
901 return A;
902 }
903
904 AnyX86NoCallerSavedRegistersAttr(SourceRange R, ASTContext &Ctx
905 , unsigned SI
906 )
907 : InheritableAttr(attr::AnyX86NoCallerSavedRegisters, R, SI, false, false)
908 {
909 }
910
911 AnyX86NoCallerSavedRegistersAttr *clone(ASTContext &C) const;
912 void printPretty(raw_ostream &OS,
913 const PrintingPolicy &Policy) const;
914 const char *getSpelling() const;
915
916
917 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCallerSavedRegisters; }
918};
919
920class ArcWeakrefUnavailableAttr : public InheritableAttr {
921public:
922 static ArcWeakrefUnavailableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
923 auto *A = new (Ctx) ArcWeakrefUnavailableAttr(Loc, Ctx, 0);
924 A->setImplicit(true);
925 return A;
926 }
927
928 ArcWeakrefUnavailableAttr(SourceRange R, ASTContext &Ctx
929 , unsigned SI
930 )
931 : InheritableAttr(attr::ArcWeakrefUnavailable, R, SI, false, false)
932 {
933 }
934
935 ArcWeakrefUnavailableAttr *clone(ASTContext &C) const;
936 void printPretty(raw_ostream &OS,
937 const PrintingPolicy &Policy) const;
938 const char *getSpelling() const;
939
940
941 static bool classof(const Attr *A) { return A->getKind() == attr::ArcWeakrefUnavailable; }
942};
943
944class ArgumentWithTypeTagAttr : public InheritableAttr {
945IdentifierInfo * argumentKind;
946
947unsigned argumentIdx;
948
949unsigned typeTagIdx;
950
951bool isPointer;
952
953public:
954 enum Spelling {
955 GNU_argument_with_type_tag = 0,
956 CXX11_clang_argument_with_type_tag = 1,
957 C2x_clang_argument_with_type_tag = 2,
958 GNU_pointer_with_type_tag = 3,
959 CXX11_clang_pointer_with_type_tag = 4,
960 C2x_clang_pointer_with_type_tag = 5
961 };
962
963 static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, unsigned ArgumentIdx, unsigned TypeTagIdx, bool IsPointer, SourceRange Loc = SourceRange()) {
964 auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, IsPointer, S);
965 A->setImplicit(true);
966 return A;
967 }
968
969 static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, unsigned ArgumentIdx, unsigned TypeTagIdx, SourceRange Loc = SourceRange()) {
970 auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, S);
971 A->setImplicit(true);
972 return A;
973 }
974
975 ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx
976 , IdentifierInfo * ArgumentKind
977 , unsigned ArgumentIdx
978 , unsigned TypeTagIdx
979 , bool IsPointer
980 , unsigned SI
981 )
982 : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false)
983 , argumentKind(ArgumentKind)
984 , argumentIdx(ArgumentIdx)
985 , typeTagIdx(TypeTagIdx)
986 , isPointer(IsPointer)
987 {
988 }
989
990 ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx
991 , IdentifierInfo * ArgumentKind
992 , unsigned ArgumentIdx
993 , unsigned TypeTagIdx
994 , unsigned SI
995 )
996 : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false)
997 , argumentKind(ArgumentKind)
998 , argumentIdx(ArgumentIdx)
999 , typeTagIdx(TypeTagIdx)
1000 , isPointer()
1001 {
1002 }
1003
1004 ArgumentWithTypeTagAttr *clone(ASTContext &C) const;
1005 void printPretty(raw_ostream &OS,
1006 const PrintingPolicy &Policy) const;
1007 const char *getSpelling() const;
1008 Spelling getSemanticSpelling() const {
1009 switch (SpellingListIndex) {
1010 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1010)
;
1011 case 0: return GNU_argument_with_type_tag;
1012 case 1: return CXX11_clang_argument_with_type_tag;
1013 case 2: return C2x_clang_argument_with_type_tag;
1014 case 3: return GNU_pointer_with_type_tag;
1015 case 4: return CXX11_clang_pointer_with_type_tag;
1016 case 5: return C2x_clang_pointer_with_type_tag;
1017 }
1018 }
1019 IdentifierInfo * getArgumentKind() const {
1020 return argumentKind;
1021 }
1022
1023 unsigned getArgumentIdx() const {
1024 return argumentIdx;
1025 }
1026
1027 unsigned getTypeTagIdx() const {
1028 return typeTagIdx;
1029 }
1030
1031 bool getIsPointer() const {
1032 return isPointer;
1033 }
1034
1035
1036
1037 static bool classof(const Attr *A) { return A->getKind() == attr::ArgumentWithTypeTag; }
1038};
1039
1040class ArtificialAttr : public InheritableAttr {
1041public:
1042 static ArtificialAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1043 auto *A = new (Ctx) ArtificialAttr(Loc, Ctx, 0);
1044 A->setImplicit(true);
1045 return A;
1046 }
1047
1048 ArtificialAttr(SourceRange R, ASTContext &Ctx
1049 , unsigned SI
1050 )
1051 : InheritableAttr(attr::Artificial, R, SI, false, false)
1052 {
1053 }
1054
1055 ArtificialAttr *clone(ASTContext &C) const;
1056 void printPretty(raw_ostream &OS,
1057 const PrintingPolicy &Policy) const;
1058 const char *getSpelling() const;
1059
1060
1061 static bool classof(const Attr *A) { return A->getKind() == attr::Artificial; }
1062};
1063
1064class AsmLabelAttr : public InheritableAttr {
1065unsigned labelLength;
1066char *label;
1067
1068public:
1069 static AsmLabelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Label, SourceRange Loc = SourceRange()) {
1070 auto *A = new (Ctx) AsmLabelAttr(Loc, Ctx, Label, 0);
1071 A->setImplicit(true);
1072 return A;
1073 }
1074
1075 AsmLabelAttr(SourceRange R, ASTContext &Ctx
1076 , llvm::StringRef Label
1077 , unsigned SI
1078 )
1079 : InheritableAttr(attr::AsmLabel, R, SI, false, false)
1080 , labelLength(Label.size()),label(new (Ctx, 1) char[labelLength])
1081 {
1082 if (!Label.empty())
1083 std::memcpy(label, Label.data(), labelLength);
1084 }
1085
1086 AsmLabelAttr *clone(ASTContext &C) const;
1087 void printPretty(raw_ostream &OS,
1088 const PrintingPolicy &Policy) const;
1089 const char *getSpelling() const;
1090 llvm::StringRef getLabel() const {
1091 return llvm::StringRef(label, labelLength);
1092 }
1093 unsigned getLabelLength() const {
1094 return labelLength;
1095 }
1096 void setLabel(ASTContext &C, llvm::StringRef S) {
1097 labelLength = S.size();
1098 this->label = new (C, 1) char [labelLength];
1099 if (!S.empty())
1100 std::memcpy(this->label, S.data(), labelLength);
1101 }
1102
1103
1104
1105 static bool classof(const Attr *A) { return A->getKind() == attr::AsmLabel; }
1106};
1107
1108class AssertCapabilityAttr : public InheritableAttr {
1109 unsigned args_Size;
1110 Expr * *args_;
1111
1112public:
1113 enum Spelling {
1114 GNU_assert_capability = 0,
1115 CXX11_clang_assert_capability = 1,
1116 GNU_assert_shared_capability = 2,
1117 CXX11_clang_assert_shared_capability = 3
1118 };
1119
1120 static AssertCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1121 auto *A = new (Ctx) AssertCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
1122 A->setImplicit(true);
1123 return A;
1124 }
1125
1126 AssertCapabilityAttr(SourceRange R, ASTContext &Ctx
1127 , Expr * *Args, unsigned ArgsSize
1128 , unsigned SI
1129 )
1130 : InheritableAttr(attr::AssertCapability, R, SI, true, true)
1131 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1132 {
1133 std::copy(Args, Args + args_Size, args_);
1134 }
1135
1136 AssertCapabilityAttr(SourceRange R, ASTContext &Ctx
1137 , unsigned SI
1138 )
1139 : InheritableAttr(attr::AssertCapability, R, SI, true, true)
1140 , args_Size(0), args_(nullptr)
1141 {
1142 }
1143
1144 AssertCapabilityAttr *clone(ASTContext &C) const;
1145 void printPretty(raw_ostream &OS,
1146 const PrintingPolicy &Policy) const;
1147 const char *getSpelling() const;
1148 Spelling getSemanticSpelling() const {
1149 switch (SpellingListIndex) {
1150 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1150)
;
1151 case 0: return GNU_assert_capability;
1152 case 1: return CXX11_clang_assert_capability;
1153 case 2: return GNU_assert_shared_capability;
1154 case 3: return CXX11_clang_assert_shared_capability;
1155 }
1156 }
1157 bool isShared() const { return SpellingListIndex == 2 ||
1158 SpellingListIndex == 3; }
1159 typedef Expr ** args_iterator;
1160 args_iterator args_begin() const { return args_; }
1161 args_iterator args_end() const { return args_ + args_Size; }
1162 unsigned args_size() const { return args_Size; }
1163 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1164
1165
1166
1167
1168 static bool classof(const Attr *A) { return A->getKind() == attr::AssertCapability; }
1169};
1170
1171class AssertExclusiveLockAttr : public InheritableAttr {
1172 unsigned args_Size;
1173 Expr * *args_;
1174
1175public:
1176 static AssertExclusiveLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1177 auto *A = new (Ctx) AssertExclusiveLockAttr(Loc, Ctx, Args, ArgsSize, 0);
1178 A->setImplicit(true);
1179 return A;
1180 }
1181
1182 AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx
1183 , Expr * *Args, unsigned ArgsSize
1184 , unsigned SI
1185 )
1186 : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true)
1187 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1188 {
1189 std::copy(Args, Args + args_Size, args_);
1190 }
1191
1192 AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx
1193 , unsigned SI
1194 )
1195 : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true)
1196 , args_Size(0), args_(nullptr)
1197 {
1198 }
1199
1200 AssertExclusiveLockAttr *clone(ASTContext &C) const;
1201 void printPretty(raw_ostream &OS,
1202 const PrintingPolicy &Policy) const;
1203 const char *getSpelling() const;
1204 typedef Expr ** args_iterator;
1205 args_iterator args_begin() const { return args_; }
1206 args_iterator args_end() const { return args_ + args_Size; }
1207 unsigned args_size() const { return args_Size; }
1208 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1209
1210
1211
1212
1213 static bool classof(const Attr *A) { return A->getKind() == attr::AssertExclusiveLock; }
1214};
1215
1216class AssertSharedLockAttr : public InheritableAttr {
1217 unsigned args_Size;
1218 Expr * *args_;
1219
1220public:
1221 static AssertSharedLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1222 auto *A = new (Ctx) AssertSharedLockAttr(Loc, Ctx, Args, ArgsSize, 0);
1223 A->setImplicit(true);
1224 return A;
1225 }
1226
1227 AssertSharedLockAttr(SourceRange R, ASTContext &Ctx
1228 , Expr * *Args, unsigned ArgsSize
1229 , unsigned SI
1230 )
1231 : InheritableAttr(attr::AssertSharedLock, R, SI, true, true)
1232 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1233 {
1234 std::copy(Args, Args + args_Size, args_);
1235 }
1236
1237 AssertSharedLockAttr(SourceRange R, ASTContext &Ctx
1238 , unsigned SI
1239 )
1240 : InheritableAttr(attr::AssertSharedLock, R, SI, true, true)
1241 , args_Size(0), args_(nullptr)
1242 {
1243 }
1244
1245 AssertSharedLockAttr *clone(ASTContext &C) const;
1246 void printPretty(raw_ostream &OS,
1247 const PrintingPolicy &Policy) const;
1248 const char *getSpelling() const;
1249 typedef Expr ** args_iterator;
1250 args_iterator args_begin() const { return args_; }
1251 args_iterator args_end() const { return args_ + args_Size; }
1252 unsigned args_size() const { return args_Size; }
1253 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1254
1255
1256
1257
1258 static bool classof(const Attr *A) { return A->getKind() == attr::AssertSharedLock; }
1259};
1260
1261class AssumeAlignedAttr : public InheritableAttr {
1262Expr * alignment;
1263
1264Expr * offset;
1265
1266public:
1267 static AssumeAlignedAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, Expr * Offset, SourceRange Loc = SourceRange()) {
1268 auto *A = new (Ctx) AssumeAlignedAttr(Loc, Ctx, Alignment, Offset, 0);
1269 A->setImplicit(true);
1270 return A;
1271 }
1272
1273 AssumeAlignedAttr(SourceRange R, ASTContext &Ctx
1274 , Expr * Alignment
1275 , Expr * Offset
1276 , unsigned SI
1277 )
1278 : InheritableAttr(attr::AssumeAligned, R, SI, false, false)
1279 , alignment(Alignment)
1280 , offset(Offset)
1281 {
1282 }
1283
1284 AssumeAlignedAttr(SourceRange R, ASTContext &Ctx
1285 , Expr * Alignment
1286 , unsigned SI
1287 )
1288 : InheritableAttr(attr::AssumeAligned, R, SI, false, false)
1289 , alignment(Alignment)
1290 , offset()
1291 {
1292 }
1293
1294 AssumeAlignedAttr *clone(ASTContext &C) const;
1295 void printPretty(raw_ostream &OS,
1296 const PrintingPolicy &Policy) const;
1297 const char *getSpelling() const;
1298 Expr * getAlignment() const {
1299 return alignment;
1300 }
1301
1302 Expr * getOffset() const {
1303 return offset;
1304 }
1305
1306
1307
1308 static bool classof(const Attr *A) { return A->getKind() == attr::AssumeAligned; }
1309};
1310
1311class AvailabilityAttr : public InheritableAttr {
1312IdentifierInfo * platform;
1313
1314VersionTuple introduced;
1315
1316
1317VersionTuple deprecated;
1318
1319
1320VersionTuple obsoleted;
1321
1322
1323bool unavailable;
1324
1325unsigned messageLength;
1326char *message;
1327
1328bool strict;
1329
1330unsigned replacementLength;
1331char *replacement;
1332
1333public:
1334 static AvailabilityAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool Unavailable, llvm::StringRef Message, bool Strict, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) {
1335 auto *A = new (Ctx) AvailabilityAttr(Loc, Ctx, Platform, Introduced, Deprecated, Obsoleted, Unavailable, Message, Strict, Replacement, 0);
1336 A->setImplicit(true);
1337 return A;
1338 }
1339
1340 AvailabilityAttr(SourceRange R, ASTContext &Ctx
1341 , IdentifierInfo * Platform
1342 , VersionTuple Introduced
1343 , VersionTuple Deprecated
1344 , VersionTuple Obsoleted
1345 , bool Unavailable
1346 , llvm::StringRef Message
1347 , bool Strict
1348 , llvm::StringRef Replacement
1349 , unsigned SI
1350 )
1351 : InheritableAttr(attr::Availability, R, SI, false, true)
1352 , platform(Platform)
1353 , introduced(Introduced)
1354 , deprecated(Deprecated)
1355 , obsoleted(Obsoleted)
1356 , unavailable(Unavailable)
1357 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
1358 , strict(Strict)
1359 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
1360 {
1361 if (!Message.empty())
1362 std::memcpy(message, Message.data(), messageLength);
1363 if (!Replacement.empty())
1364 std::memcpy(replacement, Replacement.data(), replacementLength);
1365 }
1366
1367 AvailabilityAttr *clone(ASTContext &C) const;
1368 void printPretty(raw_ostream &OS,
1369 const PrintingPolicy &Policy) const;
1370 const char *getSpelling() const;
1371 IdentifierInfo * getPlatform() const {
1372 return platform;
1373 }
1374
1375 VersionTuple getIntroduced() const {
1376 return introduced;
1377 }
1378 void setIntroduced(ASTContext &C, VersionTuple V) {
1379 introduced = V;
1380 }
1381
1382 VersionTuple getDeprecated() const {
1383 return deprecated;
1384 }
1385 void setDeprecated(ASTContext &C, VersionTuple V) {
1386 deprecated = V;
1387 }
1388
1389 VersionTuple getObsoleted() const {
1390 return obsoleted;
1391 }
1392 void setObsoleted(ASTContext &C, VersionTuple V) {
1393 obsoleted = V;
1394 }
1395
1396 bool getUnavailable() const {
1397 return unavailable;
1398 }
1399
1400 llvm::StringRef getMessage() const {
1401 return llvm::StringRef(message, messageLength);
1402 }
1403 unsigned getMessageLength() const {
1404 return messageLength;
1405 }
1406 void setMessage(ASTContext &C, llvm::StringRef S) {
1407 messageLength = S.size();
1408 this->message = new (C, 1) char [messageLength];
11
Null pointer value stored to field 'message'
1409 if (!S.empty())
12
Assuming the condition is true
13
Taking true branch
1410 std::memcpy(this->message, S.data(), messageLength);
14
Null pointer passed as an argument to a 'nonnull' parameter
1411 }
1412
1413 bool getStrict() const {
1414 return strict;
1415 }
1416
1417 llvm::StringRef getReplacement() const {
1418 return llvm::StringRef(replacement, replacementLength);
1419 }
1420 unsigned getReplacementLength() const {
1421 return replacementLength;
1422 }
1423 void setReplacement(ASTContext &C, llvm::StringRef S) {
1424 replacementLength = S.size();
1425 this->replacement = new (C, 1) char [replacementLength];
1426 if (!S.empty())
1427 std::memcpy(this->replacement, S.data(), replacementLength);
1428 }
1429
1430static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
1431 return llvm::StringSwitch<llvm::StringRef>(Platform)
1432 .Case("android", "Android")
1433 .Case("ios", "iOS")
1434 .Case("macos", "macOS")
1435 .Case("tvos", "tvOS")
1436 .Case("watchos", "watchOS")
1437 .Case("ios_app_extension", "iOS (App Extension)")
1438 .Case("macos_app_extension", "macOS (App Extension)")
1439 .Case("tvos_app_extension", "tvOS (App Extension)")
1440 .Case("watchos_app_extension", "watchOS (App Extension)")
1441 .Default(llvm::StringRef());
1442}
1443static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
1444 return llvm::StringSwitch<llvm::StringRef>(Platform)
1445 .Case("ios", "iOS")
1446 .Case("macos", "macOS")
1447 .Case("tvos", "tvOS")
1448 .Case("watchos", "watchOS")
1449 .Case("ios_app_extension", "iOSApplicationExtension")
1450 .Case("macos_app_extension", "macOSApplicationExtension")
1451 .Case("tvos_app_extension", "tvOSApplicationExtension")
1452 .Case("watchos_app_extension", "watchOSApplicationExtension")
1453 .Default(Platform);
1454}
1455static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
1456 return llvm::StringSwitch<llvm::StringRef>(Platform)
1457 .Case("iOS", "ios")
1458 .Case("macOS", "macos")
1459 .Case("tvOS", "tvos")
1460 .Case("watchOS", "watchos")
1461 .Case("iOSApplicationExtension", "ios_app_extension")
1462 .Case("macOSApplicationExtension", "macos_app_extension")
1463 .Case("tvOSApplicationExtension", "tvos_app_extension")
1464 .Case("watchOSApplicationExtension", "watchos_app_extension")
1465 .Default(Platform);
1466}
1467
1468 static bool classof(const Attr *A) { return A->getKind() == attr::Availability; }
1469};
1470
1471class BlocksAttr : public InheritableAttr {
1472public:
1473 enum BlockType {
1474 ByRef
1475 };
1476private:
1477 BlockType type;
1478
1479public:
1480 static BlocksAttr *CreateImplicit(ASTContext &Ctx, BlockType Type, SourceRange Loc = SourceRange()) {
1481 auto *A = new (Ctx) BlocksAttr(Loc, Ctx, Type, 0);
1482 A->setImplicit(true);
1483 return A;
1484 }
1485
1486 BlocksAttr(SourceRange R, ASTContext &Ctx
1487 , BlockType Type
1488 , unsigned SI
1489 )
1490 : InheritableAttr(attr::Blocks, R, SI, false, false)
1491 , type(Type)
1492 {
1493 }
1494
1495 BlocksAttr *clone(ASTContext &C) const;
1496 void printPretty(raw_ostream &OS,
1497 const PrintingPolicy &Policy) const;
1498 const char *getSpelling() const;
1499 BlockType getType() const {
1500 return type;
1501 }
1502
1503 static bool ConvertStrToBlockType(StringRef Val, BlockType &Out) {
1504 Optional<BlockType> R = llvm::StringSwitch<Optional<BlockType>>(Val)
1505 .Case("byref", BlocksAttr::ByRef)
1506 .Default(Optional<BlockType>());
1507 if (R) {
1508 Out = *R;
1509 return true;
1510 }
1511 return false;
1512 }
1513
1514 static const char *ConvertBlockTypeToStr(BlockType Val) {
1515 switch(Val) {
1516 case BlocksAttr::ByRef: return "byref";
1517 }
1518 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1518)
;
1519 }
1520
1521
1522 static bool classof(const Attr *A) { return A->getKind() == attr::Blocks; }
1523};
1524
1525class C11NoReturnAttr : public InheritableAttr {
1526public:
1527 static C11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1528 auto *A = new (Ctx) C11NoReturnAttr(Loc, Ctx, 0);
1529 A->setImplicit(true);
1530 return A;
1531 }
1532
1533 C11NoReturnAttr(SourceRange R, ASTContext &Ctx
1534 , unsigned SI
1535 )
1536 : InheritableAttr(attr::C11NoReturn, R, SI, false, false)
1537 {
1538 }
1539
1540 C11NoReturnAttr *clone(ASTContext &C) const;
1541 void printPretty(raw_ostream &OS,
1542 const PrintingPolicy &Policy) const;
1543 const char *getSpelling() const;
1544
1545
1546 static bool classof(const Attr *A) { return A->getKind() == attr::C11NoReturn; }
1547};
1548
1549class CDeclAttr : public InheritableAttr {
1550public:
1551 static CDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1552 auto *A = new (Ctx) CDeclAttr(Loc, Ctx, 0);
1553 A->setImplicit(true);
1554 return A;
1555 }
1556
1557 CDeclAttr(SourceRange R, ASTContext &Ctx
1558 , unsigned SI
1559 )
1560 : InheritableAttr(attr::CDecl, R, SI, false, false)
1561 {
1562 }
1563
1564 CDeclAttr *clone(ASTContext &C) const;
1565 void printPretty(raw_ostream &OS,
1566 const PrintingPolicy &Policy) const;
1567 const char *getSpelling() const;
1568
1569
1570 static bool classof(const Attr *A) { return A->getKind() == attr::CDecl; }
1571};
1572
1573class CFAuditedTransferAttr : public InheritableAttr {
1574public:
1575 static CFAuditedTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1576 auto *A = new (Ctx) CFAuditedTransferAttr(Loc, Ctx, 0);
1577 A->setImplicit(true);
1578 return A;
1579 }
1580
1581 CFAuditedTransferAttr(SourceRange R, ASTContext &Ctx
1582 , unsigned SI
1583 )
1584 : InheritableAttr(attr::CFAuditedTransfer, R, SI, false, false)
1585 {
1586 }
1587
1588 CFAuditedTransferAttr *clone(ASTContext &C) const;
1589 void printPretty(raw_ostream &OS,
1590 const PrintingPolicy &Policy) const;
1591 const char *getSpelling() const;
1592
1593
1594 static bool classof(const Attr *A) { return A->getKind() == attr::CFAuditedTransfer; }
1595};
1596
1597class CFConsumedAttr : public InheritableParamAttr {
1598public:
1599 static CFConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1600 auto *A = new (Ctx) CFConsumedAttr(Loc, Ctx, 0);
1601 A->setImplicit(true);
1602 return A;
1603 }
1604
1605 CFConsumedAttr(SourceRange R, ASTContext &Ctx
1606 , unsigned SI
1607 )
1608 : InheritableParamAttr(attr::CFConsumed, R, SI, false, false)
1609 {
1610 }
1611
1612 CFConsumedAttr *clone(ASTContext &C) const;
1613 void printPretty(raw_ostream &OS,
1614 const PrintingPolicy &Policy) const;
1615 const char *getSpelling() const;
1616
1617
1618 static bool classof(const Attr *A) { return A->getKind() == attr::CFConsumed; }
1619};
1620
1621class CFReturnsNotRetainedAttr : public InheritableAttr {
1622public:
1623 static CFReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1624 auto *A = new (Ctx) CFReturnsNotRetainedAttr(Loc, Ctx, 0);
1625 A->setImplicit(true);
1626 return A;
1627 }
1628
1629 CFReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx
1630 , unsigned SI
1631 )
1632 : InheritableAttr(attr::CFReturnsNotRetained, R, SI, false, false)
1633 {
1634 }
1635
1636 CFReturnsNotRetainedAttr *clone(ASTContext &C) const;
1637 void printPretty(raw_ostream &OS,
1638 const PrintingPolicy &Policy) const;
1639 const char *getSpelling() const;
1640
1641
1642 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsNotRetained; }
1643};
1644
1645class CFReturnsRetainedAttr : public InheritableAttr {
1646public:
1647 static CFReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1648 auto *A = new (Ctx) CFReturnsRetainedAttr(Loc, Ctx, 0);
1649 A->setImplicit(true);
1650 return A;
1651 }
1652
1653 CFReturnsRetainedAttr(SourceRange R, ASTContext &Ctx
1654 , unsigned SI
1655 )
1656 : InheritableAttr(attr::CFReturnsRetained, R, SI, false, false)
1657 {
1658 }
1659
1660 CFReturnsRetainedAttr *clone(ASTContext &C) const;
1661 void printPretty(raw_ostream &OS,
1662 const PrintingPolicy &Policy) const;
1663 const char *getSpelling() const;
1664
1665
1666 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsRetained; }
1667};
1668
1669class CFUnknownTransferAttr : public InheritableAttr {
1670public:
1671 static CFUnknownTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1672 auto *A = new (Ctx) CFUnknownTransferAttr(Loc, Ctx, 0);
1673 A->setImplicit(true);
1674 return A;
1675 }
1676
1677 CFUnknownTransferAttr(SourceRange R, ASTContext &Ctx
1678 , unsigned SI
1679 )
1680 : InheritableAttr(attr::CFUnknownTransfer, R, SI, false, false)
1681 {
1682 }
1683
1684 CFUnknownTransferAttr *clone(ASTContext &C) const;
1685 void printPretty(raw_ostream &OS,
1686 const PrintingPolicy &Policy) const;
1687 const char *getSpelling() const;
1688
1689
1690 static bool classof(const Attr *A) { return A->getKind() == attr::CFUnknownTransfer; }
1691};
1692
1693class CUDAConstantAttr : public InheritableAttr {
1694public:
1695 static CUDAConstantAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1696 auto *A = new (Ctx) CUDAConstantAttr(Loc, Ctx, 0);
1697 A->setImplicit(true);
1698 return A;
1699 }
1700
1701 CUDAConstantAttr(SourceRange R, ASTContext &Ctx
1702 , unsigned SI
1703 )
1704 : InheritableAttr(attr::CUDAConstant, R, SI, false, false)
1705 {
1706 }
1707
1708 CUDAConstantAttr *clone(ASTContext &C) const;
1709 void printPretty(raw_ostream &OS,
1710 const PrintingPolicy &Policy) const;
1711 const char *getSpelling() const;
1712
1713
1714 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAConstant; }
1715};
1716
1717class CUDADeviceAttr : public InheritableAttr {
1718public:
1719 static CUDADeviceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1720 auto *A = new (Ctx) CUDADeviceAttr(Loc, Ctx, 0);
1721 A->setImplicit(true);
1722 return A;
1723 }
1724
1725 CUDADeviceAttr(SourceRange R, ASTContext &Ctx
1726 , unsigned SI
1727 )
1728 : InheritableAttr(attr::CUDADevice, R, SI, false, false)
1729 {
1730 }
1731
1732 CUDADeviceAttr *clone(ASTContext &C) const;
1733 void printPretty(raw_ostream &OS,
1734 const PrintingPolicy &Policy) const;
1735 const char *getSpelling() const;
1736
1737
1738 static bool classof(const Attr *A) { return A->getKind() == attr::CUDADevice; }
1739};
1740
1741class CUDAGlobalAttr : public InheritableAttr {
1742public:
1743 static CUDAGlobalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1744 auto *A = new (Ctx) CUDAGlobalAttr(Loc, Ctx, 0);
1745 A->setImplicit(true);
1746 return A;
1747 }
1748
1749 CUDAGlobalAttr(SourceRange R, ASTContext &Ctx
1750 , unsigned SI
1751 )
1752 : InheritableAttr(attr::CUDAGlobal, R, SI, false, false)
1753 {
1754 }
1755
1756 CUDAGlobalAttr *clone(ASTContext &C) const;
1757 void printPretty(raw_ostream &OS,
1758 const PrintingPolicy &Policy) const;
1759 const char *getSpelling() const;
1760
1761
1762 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAGlobal; }
1763};
1764
1765class CUDAHostAttr : public InheritableAttr {
1766public:
1767 static CUDAHostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1768 auto *A = new (Ctx) CUDAHostAttr(Loc, Ctx, 0);
1769 A->setImplicit(true);
1770 return A;
1771 }
1772
1773 CUDAHostAttr(SourceRange R, ASTContext &Ctx
1774 , unsigned SI
1775 )
1776 : InheritableAttr(attr::CUDAHost, R, SI, false, false)
1777 {
1778 }
1779
1780 CUDAHostAttr *clone(ASTContext &C) const;
1781 void printPretty(raw_ostream &OS,
1782 const PrintingPolicy &Policy) const;
1783 const char *getSpelling() const;
1784
1785
1786 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAHost; }
1787};
1788
1789class CUDAInvalidTargetAttr : public InheritableAttr {
1790public:
1791 static CUDAInvalidTargetAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1792 auto *A = new (Ctx) CUDAInvalidTargetAttr(Loc, Ctx, 0);
1793 A->setImplicit(true);
1794 return A;
1795 }
1796
1797 CUDAInvalidTargetAttr(SourceRange R, ASTContext &Ctx
1798 , unsigned SI
1799 )
1800 : InheritableAttr(attr::CUDAInvalidTarget, R, SI, false, false)
1801 {
1802 }
1803
1804 CUDAInvalidTargetAttr *clone(ASTContext &C) const;
1805 void printPretty(raw_ostream &OS,
1806 const PrintingPolicy &Policy) const;
1807 const char *getSpelling() const;
1808
1809
1810 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAInvalidTarget; }
1811};
1812
1813class CUDALaunchBoundsAttr : public InheritableAttr {
1814Expr * maxThreads;
1815
1816Expr * minBlocks;
1817
1818public:
1819 static CUDALaunchBoundsAttr *CreateImplicit(ASTContext &Ctx, Expr * MaxThreads, Expr * MinBlocks, SourceRange Loc = SourceRange()) {
1820 auto *A = new (Ctx) CUDALaunchBoundsAttr(Loc, Ctx, MaxThreads, MinBlocks, 0);
1821 A->setImplicit(true);
1822 return A;
1823 }
1824
1825 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
1826 , Expr * MaxThreads
1827 , Expr * MinBlocks
1828 , unsigned SI
1829 )
1830 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
1831 , maxThreads(MaxThreads)
1832 , minBlocks(MinBlocks)
1833 {
1834 }
1835
1836 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
1837 , Expr * MaxThreads
1838 , unsigned SI
1839 )
1840 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
1841 , maxThreads(MaxThreads)
1842 , minBlocks()
1843 {
1844 }
1845
1846 CUDALaunchBoundsAttr *clone(ASTContext &C) const;
1847 void printPretty(raw_ostream &OS,
1848 const PrintingPolicy &Policy) const;
1849 const char *getSpelling() const;
1850 Expr * getMaxThreads() const {
1851 return maxThreads;
1852 }
1853
1854 Expr * getMinBlocks() const {
1855 return minBlocks;
1856 }
1857
1858
1859
1860 static bool classof(const Attr *A) { return A->getKind() == attr::CUDALaunchBounds; }
1861};
1862
1863class CUDASharedAttr : public InheritableAttr {
1864public:
1865 static CUDASharedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1866 auto *A = new (Ctx) CUDASharedAttr(Loc, Ctx, 0);
1867 A->setImplicit(true);
1868 return A;
1869 }
1870
1871 CUDASharedAttr(SourceRange R, ASTContext &Ctx
1872 , unsigned SI
1873 )
1874 : InheritableAttr(attr::CUDAShared, R, SI, false, false)
1875 {
1876 }
1877
1878 CUDASharedAttr *clone(ASTContext &C) const;
1879 void printPretty(raw_ostream &OS,
1880 const PrintingPolicy &Policy) const;
1881 const char *getSpelling() const;
1882
1883
1884 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAShared; }
1885};
1886
1887class CXX11NoReturnAttr : public InheritableAttr {
1888public:
1889 static CXX11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1890 auto *A = new (Ctx) CXX11NoReturnAttr(Loc, Ctx, 0);
1891 A->setImplicit(true);
1892 return A;
1893 }
1894
1895 CXX11NoReturnAttr(SourceRange R, ASTContext &Ctx
1896 , unsigned SI
1897 )
1898 : InheritableAttr(attr::CXX11NoReturn, R, SI, false, false)
1899 {
1900 }
1901
1902 CXX11NoReturnAttr *clone(ASTContext &C) const;
1903 void printPretty(raw_ostream &OS,
1904 const PrintingPolicy &Policy) const;
1905 const char *getSpelling() const;
1906
1907
1908 static bool classof(const Attr *A) { return A->getKind() == attr::CXX11NoReturn; }
1909};
1910
1911class CallableWhenAttr : public InheritableAttr {
1912public:
1913 enum ConsumedState {
1914 Unknown,
1915 Consumed,
1916 Unconsumed
1917 };
1918private:
1919 unsigned callableStates_Size;
1920 ConsumedState *callableStates_;
1921
1922public:
1923 static CallableWhenAttr *CreateImplicit(ASTContext &Ctx, ConsumedState *CallableStates, unsigned CallableStatesSize, SourceRange Loc = SourceRange()) {
1924 auto *A = new (Ctx) CallableWhenAttr(Loc, Ctx, CallableStates, CallableStatesSize, 0);
1925 A->setImplicit(true);
1926 return A;
1927 }
1928
1929 CallableWhenAttr(SourceRange R, ASTContext &Ctx
1930 , ConsumedState *CallableStates, unsigned CallableStatesSize
1931 , unsigned SI
1932 )
1933 : InheritableAttr(attr::CallableWhen, R, SI, false, false)
1934 , callableStates_Size(CallableStatesSize), callableStates_(new (Ctx, 16) ConsumedState[callableStates_Size])
1935 {
1936 std::copy(CallableStates, CallableStates + callableStates_Size, callableStates_);
1937 }
1938
1939 CallableWhenAttr(SourceRange R, ASTContext &Ctx
1940 , unsigned SI
1941 )
1942 : InheritableAttr(attr::CallableWhen, R, SI, false, false)
1943 , callableStates_Size(0), callableStates_(nullptr)
1944 {
1945 }
1946
1947 CallableWhenAttr *clone(ASTContext &C) const;
1948 void printPretty(raw_ostream &OS,
1949 const PrintingPolicy &Policy) const;
1950 const char *getSpelling() const;
1951 typedef ConsumedState* callableStates_iterator;
1952 callableStates_iterator callableStates_begin() const { return callableStates_; }
1953 callableStates_iterator callableStates_end() const { return callableStates_ + callableStates_Size; }
1954 unsigned callableStates_size() const { return callableStates_Size; }
1955 llvm::iterator_range<callableStates_iterator> callableStates() const { return llvm::make_range(callableStates_begin(), callableStates_end()); }
1956
1957
1958 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
1959 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
1960 .Case("unknown", CallableWhenAttr::Unknown)
1961 .Case("consumed", CallableWhenAttr::Consumed)
1962 .Case("unconsumed", CallableWhenAttr::Unconsumed)
1963 .Default(Optional<ConsumedState>());
1964 if (R) {
1965 Out = *R;
1966 return true;
1967 }
1968 return false;
1969 }
1970
1971 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
1972 switch(Val) {
1973 case CallableWhenAttr::Unknown: return "unknown";
1974 case CallableWhenAttr::Consumed: return "consumed";
1975 case CallableWhenAttr::Unconsumed: return "unconsumed";
1976 }
1977 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1977)
;
1978 }
1979
1980
1981 static bool classof(const Attr *A) { return A->getKind() == attr::CallableWhen; }
1982};
1983
1984class CapabilityAttr : public InheritableAttr {
1985unsigned nameLength;
1986char *name;
1987
1988public:
1989 enum Spelling {
1990 GNU_capability = 0,
1991 CXX11_clang_capability = 1,
1992 GNU_shared_capability = 2,
1993 CXX11_clang_shared_capability = 3
1994 };
1995
1996 static CapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
1997 auto *A = new (Ctx) CapabilityAttr(Loc, Ctx, Name, S);
1998 A->setImplicit(true);
1999 return A;
2000 }
2001
2002 CapabilityAttr(SourceRange R, ASTContext &Ctx
2003 , llvm::StringRef Name
2004 , unsigned SI
2005 )
2006 : InheritableAttr(attr::Capability, R, SI, false, false)
2007 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
2008 {
2009 if (!Name.empty())
2010 std::memcpy(name, Name.data(), nameLength);
2011 }
2012
2013 CapabilityAttr *clone(ASTContext &C) const;
2014 void printPretty(raw_ostream &OS,
2015 const PrintingPolicy &Policy) const;
2016 const char *getSpelling() const;
2017 Spelling getSemanticSpelling() const {
2018 switch (SpellingListIndex) {
2019 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2019)
;
2020 case 0: return GNU_capability;
2021 case 1: return CXX11_clang_capability;
2022 case 2: return GNU_shared_capability;
2023 case 3: return CXX11_clang_shared_capability;
2024 }
2025 }
2026 bool isShared() const { return SpellingListIndex == 2 ||
2027 SpellingListIndex == 3; }
2028 llvm::StringRef getName() const {
2029 return llvm::StringRef(name, nameLength);
2030 }
2031 unsigned getNameLength() const {
2032 return nameLength;
2033 }
2034 void setName(ASTContext &C, llvm::StringRef S) {
2035 nameLength = S.size();
2036 this->name = new (C, 1) char [nameLength];
2037 if (!S.empty())
2038 std::memcpy(this->name, S.data(), nameLength);
2039 }
2040
2041
2042 bool isMutex() const { return getName().equals_lower("mutex"); }
2043 bool isRole() const { return getName().equals_lower("role"); }
2044
2045
2046 static bool classof(const Attr *A) { return A->getKind() == attr::Capability; }
2047};
2048
2049class CapturedRecordAttr : public InheritableAttr {
2050public:
2051 static CapturedRecordAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2052 auto *A = new (Ctx) CapturedRecordAttr(Loc, Ctx, 0);
2053 A->setImplicit(true);
2054 return A;
2055 }
2056
2057 CapturedRecordAttr(SourceRange R, ASTContext &Ctx
2058 , unsigned SI
2059 )
2060 : InheritableAttr(attr::CapturedRecord, R, SI, false, false)
2061 {
2062 }
2063
2064 CapturedRecordAttr *clone(ASTContext &C) const;
2065 void printPretty(raw_ostream &OS,
2066 const PrintingPolicy &Policy) const;
2067 const char *getSpelling() const;
2068
2069
2070 static bool classof(const Attr *A) { return A->getKind() == attr::CapturedRecord; }
2071};
2072
2073class CarriesDependencyAttr : public InheritableParamAttr {
2074public:
2075 static CarriesDependencyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2076 auto *A = new (Ctx) CarriesDependencyAttr(Loc, Ctx, 0);
2077 A->setImplicit(true);
2078 return A;
2079 }
2080
2081 CarriesDependencyAttr(SourceRange R, ASTContext &Ctx
2082 , unsigned SI
2083 )
2084 : InheritableParamAttr(attr::CarriesDependency, R, SI, false, false)
2085 {
2086 }
2087
2088 CarriesDependencyAttr *clone(ASTContext &C) const;
2089 void printPretty(raw_ostream &OS,
2090 const PrintingPolicy &Policy) const;
2091 const char *getSpelling() const;
2092
2093
2094 static bool classof(const Attr *A) { return A->getKind() == attr::CarriesDependency; }
2095};
2096
2097class CleanupAttr : public InheritableAttr {
2098FunctionDecl * functionDecl;
2099
2100public:
2101 static CleanupAttr *CreateImplicit(ASTContext &Ctx, FunctionDecl * FunctionDecl, SourceRange Loc = SourceRange()) {
2102 auto *A = new (Ctx) CleanupAttr(Loc, Ctx, FunctionDecl, 0);
2103 A->setImplicit(true);
2104 return A;
2105 }
2106
2107 CleanupAttr(SourceRange R, ASTContext &Ctx
2108 , FunctionDecl * FunctionDecl
2109 , unsigned SI
2110 )
2111 : InheritableAttr(attr::Cleanup, R, SI, false, false)
2112 , functionDecl(FunctionDecl)
2113 {
2114 }
2115
2116 CleanupAttr *clone(ASTContext &C) const;
2117 void printPretty(raw_ostream &OS,
2118 const PrintingPolicy &Policy) const;
2119 const char *getSpelling() const;
2120 FunctionDecl * getFunctionDecl() const {
2121 return functionDecl;
2122 }
2123
2124
2125
2126 static bool classof(const Attr *A) { return A->getKind() == attr::Cleanup; }
2127};
2128
2129class ColdAttr : public InheritableAttr {
2130public:
2131 static ColdAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2132 auto *A = new (Ctx) ColdAttr(Loc, Ctx, 0);
2133 A->setImplicit(true);
2134 return A;
2135 }
2136
2137 ColdAttr(SourceRange R, ASTContext &Ctx
2138 , unsigned SI
2139 )
2140 : InheritableAttr(attr::Cold, R, SI, false, false)
2141 {
2142 }
2143
2144 ColdAttr *clone(ASTContext &C) const;
2145 void printPretty(raw_ostream &OS,
2146 const PrintingPolicy &Policy) const;
2147 const char *getSpelling() const;
2148
2149
2150 static bool classof(const Attr *A) { return A->getKind() == attr::Cold; }
2151};
2152
2153class CommonAttr : public InheritableAttr {
2154public:
2155 static CommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2156 auto *A = new (Ctx) CommonAttr(Loc, Ctx, 0);
2157 A->setImplicit(true);
2158 return A;
2159 }
2160
2161 CommonAttr(SourceRange R, ASTContext &Ctx
2162 , unsigned SI
2163 )
2164 : InheritableAttr(attr::Common, R, SI, false, false)
2165 {
2166 }
2167
2168 CommonAttr *clone(ASTContext &C) const;
2169 void printPretty(raw_ostream &OS,
2170 const PrintingPolicy &Policy) const;
2171 const char *getSpelling() const;
2172
2173
2174 static bool classof(const Attr *A) { return A->getKind() == attr::Common; }
2175};
2176
2177class ConstAttr : public InheritableAttr {
2178public:
2179 static ConstAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2180 auto *A = new (Ctx) ConstAttr(Loc, Ctx, 0);
2181 A->setImplicit(true);
2182 return A;
2183 }
2184
2185 ConstAttr(SourceRange R, ASTContext &Ctx
2186 , unsigned SI
2187 )
2188 : InheritableAttr(attr::Const, R, SI, false, false)
2189 {
2190 }
2191
2192 ConstAttr *clone(ASTContext &C) const;
2193 void printPretty(raw_ostream &OS,
2194 const PrintingPolicy &Policy) const;
2195 const char *getSpelling() const;
2196
2197
2198 static bool classof(const Attr *A) { return A->getKind() == attr::Const; }
2199};
2200
2201class ConstructorAttr : public InheritableAttr {
2202int priority;
2203
2204public:
2205 static ConstructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) {
2206 auto *A = new (Ctx) ConstructorAttr(Loc, Ctx, Priority, 0);
2207 A->setImplicit(true);
2208 return A;
2209 }
2210
2211 ConstructorAttr(SourceRange R, ASTContext &Ctx
2212 , int Priority
2213 , unsigned SI
2214 )
2215 : InheritableAttr(attr::Constructor, R, SI, false, false)
2216 , priority(Priority)
2217 {
2218 }
2219
2220 ConstructorAttr(SourceRange R, ASTContext &Ctx
2221 , unsigned SI
2222 )
2223 : InheritableAttr(attr::Constructor, R, SI, false, false)
2224 , priority()
2225 {
2226 }
2227
2228 ConstructorAttr *clone(ASTContext &C) const;
2229 void printPretty(raw_ostream &OS,
2230 const PrintingPolicy &Policy) const;
2231 const char *getSpelling() const;
2232 int getPriority() const {
2233 return priority;
2234 }
2235
2236 static const int DefaultPriority = 65535;
2237
2238
2239
2240 static bool classof(const Attr *A) { return A->getKind() == attr::Constructor; }
2241};
2242
2243class ConsumableAttr : public InheritableAttr {
2244public:
2245 enum ConsumedState {
2246 Unknown,
2247 Consumed,
2248 Unconsumed
2249 };
2250private:
2251 ConsumedState defaultState;
2252
2253public:
2254 static ConsumableAttr *CreateImplicit(ASTContext &Ctx, ConsumedState DefaultState, SourceRange Loc = SourceRange()) {
2255 auto *A = new (Ctx) ConsumableAttr(Loc, Ctx, DefaultState, 0);
2256 A->setImplicit(true);
2257 return A;
2258 }
2259
2260 ConsumableAttr(SourceRange R, ASTContext &Ctx
2261 , ConsumedState DefaultState
2262 , unsigned SI
2263 )
2264 : InheritableAttr(attr::Consumable, R, SI, false, false)
2265 , defaultState(DefaultState)
2266 {
2267 }
2268
2269 ConsumableAttr *clone(ASTContext &C) const;
2270 void printPretty(raw_ostream &OS,
2271 const PrintingPolicy &Policy) const;
2272 const char *getSpelling() const;
2273 ConsumedState getDefaultState() const {
2274 return defaultState;
2275 }
2276
2277 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
2278 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
2279 .Case("unknown", ConsumableAttr::Unknown)
2280 .Case("consumed", ConsumableAttr::Consumed)
2281 .Case("unconsumed", ConsumableAttr::Unconsumed)
2282 .Default(Optional<ConsumedState>());
2283 if (R) {
2284 Out = *R;
2285 return true;
2286 }
2287 return false;
2288 }
2289
2290 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
2291 switch(Val) {
2292 case ConsumableAttr::Unknown: return "unknown";
2293 case ConsumableAttr::Consumed: return "consumed";
2294 case ConsumableAttr::Unconsumed: return "unconsumed";
2295 }
2296 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2296)
;
2297 }
2298
2299
2300 static bool classof(const Attr *A) { return A->getKind() == attr::Consumable; }
2301};
2302
2303class ConsumableAutoCastAttr : public InheritableAttr {
2304public:
2305 static ConsumableAutoCastAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2306 auto *A = new (Ctx) ConsumableAutoCastAttr(Loc, Ctx, 0);
2307 A->setImplicit(true);
2308 return A;
2309 }
2310
2311 ConsumableAutoCastAttr(SourceRange R, ASTContext &Ctx
2312 , unsigned SI
2313 )
2314 : InheritableAttr(attr::ConsumableAutoCast, R, SI, false, false)
2315 {
2316 }
2317
2318 ConsumableAutoCastAttr *clone(ASTContext &C) const;
2319 void printPretty(raw_ostream &OS,
2320 const PrintingPolicy &Policy) const;
2321 const char *getSpelling() const;
2322
2323
2324 static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableAutoCast; }
2325};
2326
2327class ConsumableSetOnReadAttr : public InheritableAttr {
2328public:
2329 static ConsumableSetOnReadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2330 auto *A = new (Ctx) ConsumableSetOnReadAttr(Loc, Ctx, 0);
2331 A->setImplicit(true);
2332 return A;
2333 }
2334
2335 ConsumableSetOnReadAttr(SourceRange R, ASTContext &Ctx
2336 , unsigned SI
2337 )
2338 : InheritableAttr(attr::ConsumableSetOnRead, R, SI, false, false)
2339 {
2340 }
2341
2342 ConsumableSetOnReadAttr *clone(ASTContext &C) const;
2343 void printPretty(raw_ostream &OS,
2344 const PrintingPolicy &Policy) const;
2345 const char *getSpelling() const;
2346
2347
2348 static bool classof(const Attr *A) { return A->getKind() == attr::ConsumableSetOnRead; }
2349};
2350
2351class ConvergentAttr : public InheritableAttr {
2352public:
2353 static ConvergentAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2354 auto *A = new (Ctx) ConvergentAttr(Loc, Ctx, 0);
2355 A->setImplicit(true);
2356 return A;
2357 }
2358
2359 ConvergentAttr(SourceRange R, ASTContext &Ctx
2360 , unsigned SI
2361 )
2362 : InheritableAttr(attr::Convergent, R, SI, false, false)
2363 {
2364 }
2365
2366 ConvergentAttr *clone(ASTContext &C) const;
2367 void printPretty(raw_ostream &OS,
2368 const PrintingPolicy &Policy) const;
2369 const char *getSpelling() const;
2370
2371
2372 static bool classof(const Attr *A) { return A->getKind() == attr::Convergent; }
2373};
2374
2375class DLLExportAttr : public InheritableAttr {
2376public:
2377 static DLLExportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2378 auto *A = new (Ctx) DLLExportAttr(Loc, Ctx, 0);
2379 A->setImplicit(true);
2380 return A;
2381 }
2382
2383 DLLExportAttr(SourceRange R, ASTContext &Ctx
2384 , unsigned SI
2385 )
2386 : InheritableAttr(attr::DLLExport, R, SI, false, false)
2387 {
2388 }
2389
2390 DLLExportAttr *clone(ASTContext &C) const;
2391 void printPretty(raw_ostream &OS,
2392 const PrintingPolicy &Policy) const;
2393 const char *getSpelling() const;
2394
2395
2396 static bool classof(const Attr *A) { return A->getKind() == attr::DLLExport; }
2397};
2398
2399class DLLImportAttr : public InheritableAttr {
2400public:
2401 static DLLImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2402 auto *A = new (Ctx) DLLImportAttr(Loc, Ctx, 0);
2403 A->setImplicit(true);
2404 return A;
2405 }
2406
2407 DLLImportAttr(SourceRange R, ASTContext &Ctx
2408 , unsigned SI
2409 )
2410 : InheritableAttr(attr::DLLImport, R, SI, false, false)
2411 {
2412 }
2413
2414 DLLImportAttr *clone(ASTContext &C) const;
2415 void printPretty(raw_ostream &OS,
2416 const PrintingPolicy &Policy) const;
2417 const char *getSpelling() const;
2418
2419
2420 static bool classof(const Attr *A) { return A->getKind() == attr::DLLImport; }
2421};
2422
2423class DeprecatedAttr : public InheritableAttr {
2424unsigned messageLength;
2425char *message;
2426
2427unsigned replacementLength;
2428char *replacement;
2429
2430public:
2431 static DeprecatedAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) {
2432 auto *A = new (Ctx) DeprecatedAttr(Loc, Ctx, Message, Replacement, 0);
2433 A->setImplicit(true);
2434 return A;
2435 }
2436
2437 DeprecatedAttr(SourceRange R, ASTContext &Ctx
2438 , llvm::StringRef Message
2439 , llvm::StringRef Replacement
2440 , unsigned SI
2441 )
2442 : InheritableAttr(attr::Deprecated, R, SI, false, false)
2443 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2444 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
2445 {
2446 if (!Message.empty())
2447 std::memcpy(message, Message.data(), messageLength);
2448 if (!Replacement.empty())
2449 std::memcpy(replacement, Replacement.data(), replacementLength);
2450 }
2451
2452 DeprecatedAttr(SourceRange R, ASTContext &Ctx
2453 , unsigned SI
2454 )
2455 : InheritableAttr(attr::Deprecated, R, SI, false, false)
2456 , messageLength(0),message(nullptr)
2457 , replacementLength(0),replacement(nullptr)
2458 {
2459 }
2460
2461 DeprecatedAttr *clone(ASTContext &C) const;
2462 void printPretty(raw_ostream &OS,
2463 const PrintingPolicy &Policy) const;
2464 const char *getSpelling() const;
2465 llvm::StringRef getMessage() const {
2466 return llvm::StringRef(message, messageLength);
2467 }
2468 unsigned getMessageLength() const {
2469 return messageLength;
2470 }
2471 void setMessage(ASTContext &C, llvm::StringRef S) {
2472 messageLength = S.size();
2473 this->message = new (C, 1) char [messageLength];
2474 if (!S.empty())
2475 std::memcpy(this->message, S.data(), messageLength);
2476 }
2477
2478 llvm::StringRef getReplacement() const {
2479 return llvm::StringRef(replacement, replacementLength);
2480 }
2481 unsigned getReplacementLength() const {
2482 return replacementLength;
2483 }
2484 void setReplacement(ASTContext &C, llvm::StringRef S) {
2485 replacementLength = S.size();
2486 this->replacement = new (C, 1) char [replacementLength];
2487 if (!S.empty())
2488 std::memcpy(this->replacement, S.data(), replacementLength);
2489 }
2490
2491
2492
2493 static bool classof(const Attr *A) { return A->getKind() == attr::Deprecated; }
2494};
2495
2496class DestructorAttr : public InheritableAttr {
2497int priority;
2498
2499public:
2500 static DestructorAttr *CreateImplicit(ASTContext &Ctx, int Priority, SourceRange Loc = SourceRange()) {
2501 auto *A = new (Ctx) DestructorAttr(Loc, Ctx, Priority, 0);
2502 A->setImplicit(true);
2503 return A;
2504 }
2505
2506 DestructorAttr(SourceRange R, ASTContext &Ctx
2507 , int Priority
2508 , unsigned SI
2509 )
2510 : InheritableAttr(attr::Destructor, R, SI, false, false)
2511 , priority(Priority)
2512 {
2513 }
2514
2515 DestructorAttr(SourceRange R, ASTContext &Ctx
2516 , unsigned SI
2517 )
2518 : InheritableAttr(attr::Destructor, R, SI, false, false)
2519 , priority()
2520 {
2521 }
2522
2523 DestructorAttr *clone(ASTContext &C) const;
2524 void printPretty(raw_ostream &OS,
2525 const PrintingPolicy &Policy) const;
2526 const char *getSpelling() const;
2527 int getPriority() const {
2528 return priority;
2529 }
2530
2531 static const int DefaultPriority = 65535;
2532
2533
2534
2535 static bool classof(const Attr *A) { return A->getKind() == attr::Destructor; }
2536};
2537
2538class DiagnoseIfAttr : public InheritableAttr {
2539Expr * cond;
2540
2541unsigned messageLength;
2542char *message;
2543
2544public:
2545 enum DiagnosticType {
2546 DT_Error,
2547 DT_Warning
2548 };
2549private:
2550 DiagnosticType diagnosticType;
2551
2552bool argDependent;
2553
2554NamedDecl * parent;
2555
2556public:
2557 static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, bool ArgDependent, NamedDecl * Parent, SourceRange Loc = SourceRange()) {
2558 auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, ArgDependent, Parent, 0);
2559 A->setImplicit(true);
2560 return A;
2561 }
2562
2563 static DiagnoseIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, DiagnosticType DiagnosticType, SourceRange Loc = SourceRange()) {
2564 auto *A = new (Ctx) DiagnoseIfAttr(Loc, Ctx, Cond, Message, DiagnosticType, 0);
2565 A->setImplicit(true);
2566 return A;
2567 }
2568
2569 DiagnoseIfAttr(SourceRange R, ASTContext &Ctx
2570 , Expr * Cond
2571 , llvm::StringRef Message
2572 , DiagnosticType DiagnosticType
2573 , bool ArgDependent
2574 , NamedDecl * Parent
2575 , unsigned SI
2576 )
2577 : InheritableAttr(attr::DiagnoseIf, R, SI, true, true)
2578 , cond(Cond)
2579 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2580 , diagnosticType(DiagnosticType)
2581 , argDependent(ArgDependent)
2582 , parent(Parent)
2583 {
2584 if (!Message.empty())
2585 std::memcpy(message, Message.data(), messageLength);
2586 }
2587
2588 DiagnoseIfAttr(SourceRange R, ASTContext &Ctx
2589 , Expr * Cond
2590 , llvm::StringRef Message
2591 , DiagnosticType DiagnosticType
2592 , unsigned SI
2593 )
2594 : InheritableAttr(attr::DiagnoseIf, R, SI, true, true)
2595 , cond(Cond)
2596 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2597 , diagnosticType(DiagnosticType)
2598 , argDependent()
2599 , parent()
2600 {
2601 if (!Message.empty())
2602 std::memcpy(message, Message.data(), messageLength);
2603 }
2604
2605 DiagnoseIfAttr *clone(ASTContext &C) const;
2606 void printPretty(raw_ostream &OS,
2607 const PrintingPolicy &Policy) const;
2608 const char *getSpelling() const;
2609 Expr * getCond() const {
2610 return cond;
2611 }
2612
2613 llvm::StringRef getMessage() const {
2614 return llvm::StringRef(message, messageLength);
2615 }
2616 unsigned getMessageLength() const {
2617 return messageLength;
2618 }
2619 void setMessage(ASTContext &C, llvm::StringRef S) {
2620 messageLength = S.size();
2621 this->message = new (C, 1) char [messageLength];
2622 if (!S.empty())
2623 std::memcpy(this->message, S.data(), messageLength);
2624 }
2625
2626 DiagnosticType getDiagnosticType() const {
2627 return diagnosticType;
2628 }
2629
2630 static bool ConvertStrToDiagnosticType(StringRef Val, DiagnosticType &Out) {
2631 Optional<DiagnosticType> R = llvm::StringSwitch<Optional<DiagnosticType>>(Val)
2632 .Case("error", DiagnoseIfAttr::DT_Error)
2633 .Case("warning", DiagnoseIfAttr::DT_Warning)
2634 .Default(Optional<DiagnosticType>());
2635 if (R) {
2636 Out = *R;
2637 return true;
2638 }
2639 return false;
2640 }
2641
2642 static const char *ConvertDiagnosticTypeToStr(DiagnosticType Val) {
2643 switch(Val) {
2644 case DiagnoseIfAttr::DT_Error: return "error";
2645 case DiagnoseIfAttr::DT_Warning: return "warning";
2646 }
2647 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2647)
;
2648 }
2649 bool getArgDependent() const {
2650 return argDependent;
2651 }
2652
2653 NamedDecl * getParent() const {
2654 return parent;
2655 }
2656
2657
2658 bool isError() const { return diagnosticType == DT_Error; }
2659 bool isWarning() const { return diagnosticType == DT_Warning; }
2660
2661
2662 static bool classof(const Attr *A) { return A->getKind() == attr::DiagnoseIf; }
2663};
2664
2665class DisableTailCallsAttr : public InheritableAttr {
2666public:
2667 static DisableTailCallsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2668 auto *A = new (Ctx) DisableTailCallsAttr(Loc, Ctx, 0);
2669 A->setImplicit(true);
2670 return A;
2671 }
2672
2673 DisableTailCallsAttr(SourceRange R, ASTContext &Ctx
2674 , unsigned SI
2675 )
2676 : InheritableAttr(attr::DisableTailCalls, R, SI, false, false)
2677 {
2678 }
2679
2680 DisableTailCallsAttr *clone(ASTContext &C) const;
2681 void printPretty(raw_ostream &OS,
2682 const PrintingPolicy &Policy) const;
2683 const char *getSpelling() const;
2684
2685
2686 static bool classof(const Attr *A) { return A->getKind() == attr::DisableTailCalls; }
2687};
2688
2689class EmptyBasesAttr : public InheritableAttr {
2690public:
2691 static EmptyBasesAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2692 auto *A = new (Ctx) EmptyBasesAttr(Loc, Ctx, 0);
2693 A->setImplicit(true);
2694 return A;
2695 }
2696
2697 EmptyBasesAttr(SourceRange R, ASTContext &Ctx
2698 , unsigned SI
2699 )
2700 : InheritableAttr(attr::EmptyBases, R, SI, false, false)
2701 {
2702 }
2703
2704 EmptyBasesAttr *clone(ASTContext &C) const;
2705 void printPretty(raw_ostream &OS,
2706 const PrintingPolicy &Policy) const;
2707 const char *getSpelling() const;
2708
2709
2710 static bool classof(const Attr *A) { return A->getKind() == attr::EmptyBases; }
2711};
2712
2713class EnableIfAttr : public InheritableAttr {
2714Expr * cond;
2715
2716unsigned messageLength;
2717char *message;
2718
2719public:
2720 static EnableIfAttr *CreateImplicit(ASTContext &Ctx, Expr * Cond, llvm::StringRef Message, SourceRange Loc = SourceRange()) {
2721 auto *A = new (Ctx) EnableIfAttr(Loc, Ctx, Cond, Message, 0);
2722 A->setImplicit(true);
2723 return A;
2724 }
2725
2726 EnableIfAttr(SourceRange R, ASTContext &Ctx
2727 , Expr * Cond
2728 , llvm::StringRef Message
2729 , unsigned SI
2730 )
2731 : InheritableAttr(attr::EnableIf, R, SI, false, false)
2732 , cond(Cond)
2733 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
2734 {
2735 if (!Message.empty())
2736 std::memcpy(message, Message.data(), messageLength);
2737 }
2738
2739 EnableIfAttr *clone(ASTContext &C) const;
2740 void printPretty(raw_ostream &OS,
2741 const PrintingPolicy &Policy) const;
2742 const char *getSpelling() const;
2743 Expr * getCond() const {
2744 return cond;
2745 }
2746
2747 llvm::StringRef getMessage() const {
2748 return llvm::StringRef(message, messageLength);
2749 }
2750 unsigned getMessageLength() const {
2751 return messageLength;
2752 }
2753 void setMessage(ASTContext &C, llvm::StringRef S) {
2754 messageLength = S.size();
2755 this->message = new (C, 1) char [messageLength];
2756 if (!S.empty())
2757 std::memcpy(this->message, S.data(), messageLength);
2758 }
2759
2760
2761
2762 static bool classof(const Attr *A) { return A->getKind() == attr::EnableIf; }
2763};
2764
2765class EnumExtensibilityAttr : public InheritableAttr {
2766public:
2767 enum Kind {
2768 Closed,
2769 Open
2770 };
2771private:
2772 Kind extensibility;
2773
2774public:
2775 static EnumExtensibilityAttr *CreateImplicit(ASTContext &Ctx, Kind Extensibility, SourceRange Loc = SourceRange()) {
2776 auto *A = new (Ctx) EnumExtensibilityAttr(Loc, Ctx, Extensibility, 0);
2777 A->setImplicit(true);
2778 return A;
2779 }
2780
2781 EnumExtensibilityAttr(SourceRange R, ASTContext &Ctx
2782 , Kind Extensibility
2783 , unsigned SI
2784 )
2785 : InheritableAttr(attr::EnumExtensibility, R, SI, false, false)
2786 , extensibility(Extensibility)
2787 {
2788 }
2789
2790 EnumExtensibilityAttr *clone(ASTContext &C) const;
2791 void printPretty(raw_ostream &OS,
2792 const PrintingPolicy &Policy) const;
2793 const char *getSpelling() const;
2794 Kind getExtensibility() const {
2795 return extensibility;
2796 }
2797
2798 static bool ConvertStrToKind(StringRef Val, Kind &Out) {
2799 Optional<Kind> R = llvm::StringSwitch<Optional<Kind>>(Val)
2800 .Case("closed", EnumExtensibilityAttr::Closed)
2801 .Case("open", EnumExtensibilityAttr::Open)
2802 .Default(Optional<Kind>());
2803 if (R) {
2804 Out = *R;
2805 return true;
2806 }
2807 return false;
2808 }
2809
2810 static const char *ConvertKindToStr(Kind Val) {
2811 switch(Val) {
2812 case EnumExtensibilityAttr::Closed: return "closed";
2813 case EnumExtensibilityAttr::Open: return "open";
2814 }
2815 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 2815)
;
2816 }
2817
2818
2819 static bool classof(const Attr *A) { return A->getKind() == attr::EnumExtensibility; }
2820};
2821
2822class ExclusiveTrylockFunctionAttr : public InheritableAttr {
2823Expr * successValue;
2824
2825 unsigned args_Size;
2826 Expr * *args_;
2827
2828public:
2829 static ExclusiveTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
2830 auto *A = new (Ctx) ExclusiveTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0);
2831 A->setImplicit(true);
2832 return A;
2833 }
2834
2835 ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
2836 , Expr * SuccessValue
2837 , Expr * *Args, unsigned ArgsSize
2838 , unsigned SI
2839 )
2840 : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true)
2841 , successValue(SuccessValue)
2842 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
2843 {
2844 std::copy(Args, Args + args_Size, args_);
2845 }
2846
2847 ExclusiveTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
2848 , Expr * SuccessValue
2849 , unsigned SI
2850 )
2851 : InheritableAttr(attr::ExclusiveTrylockFunction, R, SI, true, true)
2852 , successValue(SuccessValue)
2853 , args_Size(0), args_(nullptr)
2854 {
2855 }
2856
2857 ExclusiveTrylockFunctionAttr *clone(ASTContext &C) const;
2858 void printPretty(raw_ostream &OS,
2859 const PrintingPolicy &Policy) const;
2860 const char *getSpelling() const;
2861 Expr * getSuccessValue() const {
2862 return successValue;
2863 }
2864
2865 typedef Expr ** args_iterator;
2866 args_iterator args_begin() const { return args_; }
2867 args_iterator args_end() const { return args_ + args_Size; }
2868 unsigned args_size() const { return args_Size; }
2869 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
2870
2871
2872
2873
2874 static bool classof(const Attr *A) { return A->getKind() == attr::ExclusiveTrylockFunction; }
2875};
2876
2877class ExternalSourceSymbolAttr : public InheritableAttr {
2878unsigned languageLength;
2879char *language;
2880
2881unsigned definedInLength;
2882char *definedIn;
2883
2884bool generatedDeclaration;
2885
2886public:
2887 static ExternalSourceSymbolAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Language, llvm::StringRef DefinedIn, bool GeneratedDeclaration, SourceRange Loc = SourceRange()) {
2888 auto *A = new (Ctx) ExternalSourceSymbolAttr(Loc, Ctx, Language, DefinedIn, GeneratedDeclaration, 0);
2889 A->setImplicit(true);
2890 return A;
2891 }
2892
2893 ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx
2894 , llvm::StringRef Language
2895 , llvm::StringRef DefinedIn
2896 , bool GeneratedDeclaration
2897 , unsigned SI
2898 )
2899 : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false)
2900 , languageLength(Language.size()),language(new (Ctx, 1) char[languageLength])
2901 , definedInLength(DefinedIn.size()),definedIn(new (Ctx, 1) char[definedInLength])
2902 , generatedDeclaration(GeneratedDeclaration)
2903 {
2904 if (!Language.empty())
2905 std::memcpy(language, Language.data(), languageLength);
2906 if (!DefinedIn.empty())
2907 std::memcpy(definedIn, DefinedIn.data(), definedInLength);
2908 }
2909
2910 ExternalSourceSymbolAttr(SourceRange R, ASTContext &Ctx
2911 , unsigned SI
2912 )
2913 : InheritableAttr(attr::ExternalSourceSymbol, R, SI, false, false)
2914 , languageLength(0),language(nullptr)
2915 , definedInLength(0),definedIn(nullptr)
2916 , generatedDeclaration()
2917 {
2918 }
2919
2920 ExternalSourceSymbolAttr *clone(ASTContext &C) const;
2921 void printPretty(raw_ostream &OS,
2922 const PrintingPolicy &Policy) const;
2923 const char *getSpelling() const;
2924 llvm::StringRef getLanguage() const {
2925 return llvm::StringRef(language, languageLength);
2926 }
2927 unsigned getLanguageLength() const {
2928 return languageLength;
2929 }
2930 void setLanguage(ASTContext &C, llvm::StringRef S) {
2931 languageLength = S.size();
2932 this->language = new (C, 1) char [languageLength];
2933 if (!S.empty())
2934 std::memcpy(this->language, S.data(), languageLength);
2935 }
2936
2937 llvm::StringRef getDefinedIn() const {
2938 return llvm::StringRef(definedIn, definedInLength);
2939 }
2940 unsigned getDefinedInLength() const {
2941 return definedInLength;
2942 }
2943 void setDefinedIn(ASTContext &C, llvm::StringRef S) {
2944 definedInLength = S.size();
2945 this->definedIn = new (C, 1) char [definedInLength];
2946 if (!S.empty())
2947 std::memcpy(this->definedIn, S.data(), definedInLength);
2948 }
2949
2950 bool getGeneratedDeclaration() const {
2951 return generatedDeclaration;
2952 }
2953
2954
2955
2956 static bool classof(const Attr *A) { return A->getKind() == attr::ExternalSourceSymbol; }
2957};
2958
2959class FallThroughAttr : public StmtAttr {
2960public:
2961 static FallThroughAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2962 auto *A = new (Ctx) FallThroughAttr(Loc, Ctx, 0);
2963 A->setImplicit(true);
2964 return A;
2965 }
2966
2967 FallThroughAttr(SourceRange R, ASTContext &Ctx
2968 , unsigned SI
2969 )
2970 : StmtAttr(attr::FallThrough, R, SI, false)
2971 {
2972 }
2973
2974 FallThroughAttr *clone(ASTContext &C) const;
2975 void printPretty(raw_ostream &OS,
2976 const PrintingPolicy &Policy) const;
2977 const char *getSpelling() const;
2978
2979
2980 static bool classof(const Attr *A) { return A->getKind() == attr::FallThrough; }
2981};
2982
2983class FastCallAttr : public InheritableAttr {
2984public:
2985 static FastCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
2986 auto *A = new (Ctx) FastCallAttr(Loc, Ctx, 0);
2987 A->setImplicit(true);
2988 return A;
2989 }
2990
2991 FastCallAttr(SourceRange R, ASTContext &Ctx
2992 , unsigned SI
2993 )
2994 : InheritableAttr(attr::FastCall, R, SI, false, false)
2995 {
2996 }
2997
2998 FastCallAttr *clone(ASTContext &C) const;
2999 void printPretty(raw_ostream &OS,
3000 const PrintingPolicy &Policy) const;
3001 const char *getSpelling() const;
3002
3003
3004 static bool classof(const Attr *A) { return A->getKind() == attr::FastCall; }
3005};
3006
3007class FinalAttr : public InheritableAttr {
3008public:
3009 enum Spelling {
3010 Keyword_final = 0,
3011 Keyword_sealed = 1
3012 };
3013
3014 static FinalAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
3015 auto *A = new (Ctx) FinalAttr(Loc, Ctx, S);
3016 A->setImplicit(true);
3017 return A;
3018 }
3019
3020 FinalAttr(SourceRange R, ASTContext &Ctx
3021 , unsigned SI
3022 )
3023 : InheritableAttr(attr::Final, R, SI, false, false)
3024 {
3025 }
3026
3027 FinalAttr *clone(ASTContext &C) const;
3028 void printPretty(raw_ostream &OS,
3029 const PrintingPolicy &Policy) const;
3030 const char *getSpelling() const;
3031 Spelling getSemanticSpelling() const {
3032 switch (SpellingListIndex) {
3033 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3033)
;
3034 case 0: return Keyword_final;
3035 case 1: return Keyword_sealed;
3036 }
3037 }
3038 bool isSpelledAsSealed() const { return SpellingListIndex == 1; }
3039
3040
3041 static bool classof(const Attr *A) { return A->getKind() == attr::Final; }
3042};
3043
3044class FlagEnumAttr : public InheritableAttr {
3045public:
3046 static FlagEnumAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3047 auto *A = new (Ctx) FlagEnumAttr(Loc, Ctx, 0);
3048 A->setImplicit(true);
3049 return A;
3050 }
3051
3052 FlagEnumAttr(SourceRange R, ASTContext &Ctx
3053 , unsigned SI
3054 )
3055 : InheritableAttr(attr::FlagEnum, R, SI, false, false)
3056 {
3057 }
3058
3059 FlagEnumAttr *clone(ASTContext &C) const;
3060 void printPretty(raw_ostream &OS,
3061 const PrintingPolicy &Policy) const;
3062 const char *getSpelling() const;
3063
3064
3065 static bool classof(const Attr *A) { return A->getKind() == attr::FlagEnum; }
3066};
3067
3068class FlattenAttr : public InheritableAttr {
3069public:
3070 static FlattenAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3071 auto *A = new (Ctx) FlattenAttr(Loc, Ctx, 0);
3072 A->setImplicit(true);
3073 return A;
3074 }
3075
3076 FlattenAttr(SourceRange R, ASTContext &Ctx
3077 , unsigned SI
3078 )
3079 : InheritableAttr(attr::Flatten, R, SI, false, false)
3080 {
3081 }
3082
3083 FlattenAttr *clone(ASTContext &C) const;
3084 void printPretty(raw_ostream &OS,
3085 const PrintingPolicy &Policy) const;
3086 const char *getSpelling() const;
3087
3088
3089 static bool classof(const Attr *A) { return A->getKind() == attr::Flatten; }
3090};
3091
3092class FormatAttr : public InheritableAttr {
3093IdentifierInfo * type;
3094
3095int formatIdx;
3096
3097int firstArg;
3098
3099public:
3100 static FormatAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Type, int FormatIdx, int FirstArg, SourceRange Loc = SourceRange()) {
3101 auto *A = new (Ctx) FormatAttr(Loc, Ctx, Type, FormatIdx, FirstArg, 0);
3102 A->setImplicit(true);
3103 return A;
3104 }
3105
3106 FormatAttr(SourceRange R, ASTContext &Ctx
3107 , IdentifierInfo * Type
3108 , int FormatIdx
3109 , int FirstArg
3110 , unsigned SI
3111 )
3112 : InheritableAttr(attr::Format, R, SI, false, false)
3113 , type(Type)
3114 , formatIdx(FormatIdx)
3115 , firstArg(FirstArg)
3116 {
3117 }
3118
3119 FormatAttr *clone(ASTContext &C) const;
3120 void printPretty(raw_ostream &OS,
3121 const PrintingPolicy &Policy) const;
3122 const char *getSpelling() const;
3123 IdentifierInfo * getType() const {
3124 return type;
3125 }
3126
3127 int getFormatIdx() const {
3128 return formatIdx;
3129 }
3130
3131 int getFirstArg() const {
3132 return firstArg;
3133 }
3134
3135
3136
3137 static bool classof(const Attr *A) { return A->getKind() == attr::Format; }
3138};
3139
3140class FormatArgAttr : public InheritableAttr {
3141int formatIdx;
3142
3143public:
3144 static FormatArgAttr *CreateImplicit(ASTContext &Ctx, int FormatIdx, SourceRange Loc = SourceRange()) {
3145 auto *A = new (Ctx) FormatArgAttr(Loc, Ctx, FormatIdx, 0);
3146 A->setImplicit(true);
3147 return A;
3148 }
3149
3150 FormatArgAttr(SourceRange R, ASTContext &Ctx
3151 , int FormatIdx
3152 , unsigned SI
3153 )
3154 : InheritableAttr(attr::FormatArg, R, SI, false, false)
3155 , formatIdx(FormatIdx)
3156 {
3157 }
3158
3159 FormatArgAttr *clone(ASTContext &C) const;
3160 void printPretty(raw_ostream &OS,
3161 const PrintingPolicy &Policy) const;
3162 const char *getSpelling() const;
3163 int getFormatIdx() const {
3164 return formatIdx;
3165 }
3166
3167
3168
3169 static bool classof(const Attr *A) { return A->getKind() == attr::FormatArg; }
3170};
3171
3172class GNUInlineAttr : public InheritableAttr {
3173public:
3174 static GNUInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3175 auto *A = new (Ctx) GNUInlineAttr(Loc, Ctx, 0);
3176 A->setImplicit(true);
3177 return A;
3178 }
3179
3180 GNUInlineAttr(SourceRange R, ASTContext &Ctx
3181 , unsigned SI
3182 )
3183 : InheritableAttr(attr::GNUInline, R, SI, false, false)
3184 {
3185 }
3186
3187 GNUInlineAttr *clone(ASTContext &C) const;
3188 void printPretty(raw_ostream &OS,
3189 const PrintingPolicy &Policy) const;
3190 const char *getSpelling() const;
3191
3192
3193 static bool classof(const Attr *A) { return A->getKind() == attr::GNUInline; }
3194};
3195
3196class GuardedByAttr : public InheritableAttr {
3197Expr * arg;
3198
3199public:
3200 static GuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) {
3201 auto *A = new (Ctx) GuardedByAttr(Loc, Ctx, Arg, 0);
3202 A->setImplicit(true);
3203 return A;
3204 }
3205
3206 GuardedByAttr(SourceRange R, ASTContext &Ctx
3207 , Expr * Arg
3208 , unsigned SI
3209 )
3210 : InheritableAttr(attr::GuardedBy, R, SI, true, true)
3211 , arg(Arg)
3212 {
3213 }
3214
3215 GuardedByAttr *clone(ASTContext &C) const;
3216 void printPretty(raw_ostream &OS,
3217 const PrintingPolicy &Policy) const;
3218 const char *getSpelling() const;
3219 Expr * getArg() const {
3220 return arg;
3221 }
3222
3223
3224
3225 static bool classof(const Attr *A) { return A->getKind() == attr::GuardedBy; }
3226};
3227
3228class GuardedVarAttr : public InheritableAttr {
3229public:
3230 static GuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3231 auto *A = new (Ctx) GuardedVarAttr(Loc, Ctx, 0);
3232 A->setImplicit(true);
3233 return A;
3234 }
3235
3236 GuardedVarAttr(SourceRange R, ASTContext &Ctx
3237 , unsigned SI
3238 )
3239 : InheritableAttr(attr::GuardedVar, R, SI, false, false)
3240 {
3241 }
3242
3243 GuardedVarAttr *clone(ASTContext &C) const;
3244 void printPretty(raw_ostream &OS,
3245 const PrintingPolicy &Policy) const;
3246 const char *getSpelling() const;
3247
3248
3249 static bool classof(const Attr *A) { return A->getKind() == attr::GuardedVar; }
3250};
3251
3252class HotAttr : public InheritableAttr {
3253public:
3254 static HotAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3255 auto *A = new (Ctx) HotAttr(Loc, Ctx, 0);
3256 A->setImplicit(true);
3257 return A;
3258 }
3259
3260 HotAttr(SourceRange R, ASTContext &Ctx
3261 , unsigned SI
3262 )
3263 : InheritableAttr(attr::Hot, R, SI, false, false)
3264 {
3265 }
3266
3267 HotAttr *clone(ASTContext &C) const;
3268 void printPretty(raw_ostream &OS,
3269 const PrintingPolicy &Policy) const;
3270 const char *getSpelling() const;
3271
3272
3273 static bool classof(const Attr *A) { return A->getKind() == attr::Hot; }
3274};
3275
3276class IBActionAttr : public InheritableAttr {
3277public:
3278 static IBActionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3279 auto *A = new (Ctx) IBActionAttr(Loc, Ctx, 0);
3280 A->setImplicit(true);
3281 return A;
3282 }
3283
3284 IBActionAttr(SourceRange R, ASTContext &Ctx
3285 , unsigned SI
3286 )
3287 : InheritableAttr(attr::IBAction, R, SI, false, false)
3288 {
3289 }
3290
3291 IBActionAttr *clone(ASTContext &C) const;
3292 void printPretty(raw_ostream &OS,
3293 const PrintingPolicy &Policy) const;
3294 const char *getSpelling() const;
3295
3296
3297 static bool classof(const Attr *A) { return A->getKind() == attr::IBAction; }
3298};
3299
3300class IBOutletAttr : public InheritableAttr {
3301public:
3302 static IBOutletAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3303 auto *A = new (Ctx) IBOutletAttr(Loc, Ctx, 0);
3304 A->setImplicit(true);
3305 return A;
3306 }
3307
3308 IBOutletAttr(SourceRange R, ASTContext &Ctx
3309 , unsigned SI
3310 )
3311 : InheritableAttr(attr::IBOutlet, R, SI, false, false)
3312 {
3313 }
3314
3315 IBOutletAttr *clone(ASTContext &C) const;
3316 void printPretty(raw_ostream &OS,
3317 const PrintingPolicy &Policy) const;
3318 const char *getSpelling() const;
3319
3320
3321 static bool classof(const Attr *A) { return A->getKind() == attr::IBOutlet; }
3322};
3323
3324class IBOutletCollectionAttr : public InheritableAttr {
3325TypeSourceInfo * interface_;
3326
3327public:
3328 static IBOutletCollectionAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * Interface, SourceRange Loc = SourceRange()) {
3329 auto *A = new (Ctx) IBOutletCollectionAttr(Loc, Ctx, Interface, 0);
3330 A->setImplicit(true);
3331 return A;
3332 }
3333
3334 IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx
3335 , TypeSourceInfo * Interface
3336 , unsigned SI
3337 )
3338 : InheritableAttr(attr::IBOutletCollection, R, SI, false, false)
3339 , interface_(Interface)
3340 {
3341 }
3342
3343 IBOutletCollectionAttr(SourceRange R, ASTContext &Ctx
3344 , unsigned SI
3345 )
3346 : InheritableAttr(attr::IBOutletCollection, R, SI, false, false)
3347 , interface_()
3348 {
3349 }
3350
3351 IBOutletCollectionAttr *clone(ASTContext &C) const;
3352 void printPretty(raw_ostream &OS,
3353 const PrintingPolicy &Policy) const;
3354 const char *getSpelling() const;
3355 QualType getInterface() const {
3356 return interface_->getType();
3357 } TypeSourceInfo * getInterfaceLoc() const {
3358 return interface_;
3359 }
3360
3361
3362
3363 static bool classof(const Attr *A) { return A->getKind() == attr::IBOutletCollection; }
3364};
3365
3366class IFuncAttr : public Attr {
3367unsigned resolverLength;
3368char *resolver;
3369
3370public:
3371 static IFuncAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Resolver, SourceRange Loc = SourceRange()) {
3372 auto *A = new (Ctx) IFuncAttr(Loc, Ctx, Resolver, 0);
3373 A->setImplicit(true);
3374 return A;
3375 }
3376
3377 IFuncAttr(SourceRange R, ASTContext &Ctx
3378 , llvm::StringRef Resolver
3379 , unsigned SI
3380 )
3381 : Attr(attr::IFunc, R, SI, false)
3382 , resolverLength(Resolver.size()),resolver(new (Ctx, 1) char[resolverLength])
3383 {
3384 if (!Resolver.empty())
3385 std::memcpy(resolver, Resolver.data(), resolverLength);
3386 }
3387
3388 IFuncAttr *clone(ASTContext &C) const;
3389 void printPretty(raw_ostream &OS,
3390 const PrintingPolicy &Policy) const;
3391 const char *getSpelling() const;
3392 llvm::StringRef getResolver() const {
3393 return llvm::StringRef(resolver, resolverLength);
3394 }
3395 unsigned getResolverLength() const {
3396 return resolverLength;
3397 }
3398 void setResolver(ASTContext &C, llvm::StringRef S) {
3399 resolverLength = S.size();
3400 this->resolver = new (C, 1) char [resolverLength];
3401 if (!S.empty())
3402 std::memcpy(this->resolver, S.data(), resolverLength);
3403 }
3404
3405
3406
3407 static bool classof(const Attr *A) { return A->getKind() == attr::IFunc; }
3408};
3409
3410class InitPriorityAttr : public InheritableAttr {
3411unsigned priority;
3412
3413public:
3414 static InitPriorityAttr *CreateImplicit(ASTContext &Ctx, unsigned Priority, SourceRange Loc = SourceRange()) {
3415 auto *A = new (Ctx) InitPriorityAttr(Loc, Ctx, Priority, 0);
3416 A->setImplicit(true);
3417 return A;
3418 }
3419
3420 InitPriorityAttr(SourceRange R, ASTContext &Ctx
3421 , unsigned Priority
3422 , unsigned SI
3423 )
3424 : InheritableAttr(attr::InitPriority, R, SI, false, false)
3425 , priority(Priority)
3426 {
3427 }
3428
3429 InitPriorityAttr *clone(ASTContext &C) const;
3430 void printPretty(raw_ostream &OS,
3431 const PrintingPolicy &Policy) const;
3432 const char *getSpelling() const;
3433 unsigned getPriority() const {
3434 return priority;
3435 }
3436
3437
3438
3439 static bool classof(const Attr *A) { return A->getKind() == attr::InitPriority; }
3440};
3441
3442class InitSegAttr : public Attr {
3443unsigned sectionLength;
3444char *section;
3445
3446public:
3447 static InitSegAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Section, SourceRange Loc = SourceRange()) {
3448 auto *A = new (Ctx) InitSegAttr(Loc, Ctx, Section, 0);
3449 A->setImplicit(true);
3450 return A;
3451 }
3452
3453 InitSegAttr(SourceRange R, ASTContext &Ctx
3454 , llvm::StringRef Section
3455 , unsigned SI
3456 )
3457 : Attr(attr::InitSeg, R, SI, false)
3458 , sectionLength(Section.size()),section(new (Ctx, 1) char[sectionLength])
3459 {
3460 if (!Section.empty())
3461 std::memcpy(section, Section.data(), sectionLength);
3462 }
3463
3464 InitSegAttr *clone(ASTContext &C) const;
3465 void printPretty(raw_ostream &OS,
3466 const PrintingPolicy &Policy) const;
3467 const char *getSpelling() const;
3468 llvm::StringRef getSection() const {
3469 return llvm::StringRef(section, sectionLength);
3470 }
3471 unsigned getSectionLength() const {
3472 return sectionLength;
3473 }
3474 void setSection(ASTContext &C, llvm::StringRef S) {
3475 sectionLength = S.size();
3476 this->section = new (C, 1) char [sectionLength];
3477 if (!S.empty())
3478 std::memcpy(this->section, S.data(), sectionLength);
3479 }
3480
3481
3482 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3483 OS << " (" << getSection() << ')';
3484 }
3485
3486
3487 static bool classof(const Attr *A) { return A->getKind() == attr::InitSeg; }
3488};
3489
3490class IntelOclBiccAttr : public InheritableAttr {
3491public:
3492 static IntelOclBiccAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3493 auto *A = new (Ctx) IntelOclBiccAttr(Loc, Ctx, 0);
3494 A->setImplicit(true);
3495 return A;
3496 }
3497
3498 IntelOclBiccAttr(SourceRange R, ASTContext &Ctx
3499 , unsigned SI
3500 )
3501 : InheritableAttr(attr::IntelOclBicc, R, SI, false, false)
3502 {
3503 }
3504
3505 IntelOclBiccAttr *clone(ASTContext &C) const;
3506 void printPretty(raw_ostream &OS,
3507 const PrintingPolicy &Policy) const;
3508 const char *getSpelling() const;
3509
3510
3511 static bool classof(const Attr *A) { return A->getKind() == attr::IntelOclBicc; }
3512};
3513
3514class InternalLinkageAttr : public InheritableAttr {
3515public:
3516 static InternalLinkageAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3517 auto *A = new (Ctx) InternalLinkageAttr(Loc, Ctx, 0);
3518 A->setImplicit(true);
3519 return A;
3520 }
3521
3522 InternalLinkageAttr(SourceRange R, ASTContext &Ctx
3523 , unsigned SI
3524 )
3525 : InheritableAttr(attr::InternalLinkage, R, SI, false, false)
3526 {
3527 }
3528
3529 InternalLinkageAttr *clone(ASTContext &C) const;
3530 void printPretty(raw_ostream &OS,
3531 const PrintingPolicy &Policy) const;
3532 const char *getSpelling() const;
3533
3534
3535 static bool classof(const Attr *A) { return A->getKind() == attr::InternalLinkage; }
3536};
3537
3538class LTOVisibilityPublicAttr : public InheritableAttr {
3539public:
3540 static LTOVisibilityPublicAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3541 auto *A = new (Ctx) LTOVisibilityPublicAttr(Loc, Ctx, 0);
3542 A->setImplicit(true);
3543 return A;
3544 }
3545
3546 LTOVisibilityPublicAttr(SourceRange R, ASTContext &Ctx
3547 , unsigned SI
3548 )
3549 : InheritableAttr(attr::LTOVisibilityPublic, R, SI, false, false)
3550 {
3551 }
3552
3553 LTOVisibilityPublicAttr *clone(ASTContext &C) const;
3554 void printPretty(raw_ostream &OS,
3555 const PrintingPolicy &Policy) const;
3556 const char *getSpelling() const;
3557
3558
3559 static bool classof(const Attr *A) { return A->getKind() == attr::LTOVisibilityPublic; }
3560};
3561
3562class LayoutVersionAttr : public InheritableAttr {
3563unsigned version;
3564
3565public:
3566 static LayoutVersionAttr *CreateImplicit(ASTContext &Ctx, unsigned Version, SourceRange Loc = SourceRange()) {
3567 auto *A = new (Ctx) LayoutVersionAttr(Loc, Ctx, Version, 0);
3568 A->setImplicit(true);
3569 return A;
3570 }
3571
3572 LayoutVersionAttr(SourceRange R, ASTContext &Ctx
3573 , unsigned Version
3574 , unsigned SI
3575 )
3576 : InheritableAttr(attr::LayoutVersion, R, SI, false, false)
3577 , version(Version)
3578 {
3579 }
3580
3581 LayoutVersionAttr *clone(ASTContext &C) const;
3582 void printPretty(raw_ostream &OS,
3583 const PrintingPolicy &Policy) const;
3584 const char *getSpelling() const;
3585 unsigned getVersion() const {
3586 return version;
3587 }
3588
3589
3590
3591 static bool classof(const Attr *A) { return A->getKind() == attr::LayoutVersion; }
3592};
3593
3594class LockReturnedAttr : public InheritableAttr {
3595Expr * arg;
3596
3597public:
3598 static LockReturnedAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) {
3599 auto *A = new (Ctx) LockReturnedAttr(Loc, Ctx, Arg, 0);
3600 A->setImplicit(true);
3601 return A;
3602 }
3603
3604 LockReturnedAttr(SourceRange R, ASTContext &Ctx
3605 , Expr * Arg
3606 , unsigned SI
3607 )
3608 : InheritableAttr(attr::LockReturned, R, SI, true, false)
3609 , arg(Arg)
3610 {
3611 }
3612
3613 LockReturnedAttr *clone(ASTContext &C) const;
3614 void printPretty(raw_ostream &OS,
3615 const PrintingPolicy &Policy) const;
3616 const char *getSpelling() const;
3617 Expr * getArg() const {
3618 return arg;
3619 }
3620
3621
3622
3623 static bool classof(const Attr *A) { return A->getKind() == attr::LockReturned; }
3624};
3625
3626class LocksExcludedAttr : public InheritableAttr {
3627 unsigned args_Size;
3628 Expr * *args_;
3629
3630public:
3631 static LocksExcludedAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
3632 auto *A = new (Ctx) LocksExcludedAttr(Loc, Ctx, Args, ArgsSize, 0);
3633 A->setImplicit(true);
3634 return A;
3635 }
3636
3637 LocksExcludedAttr(SourceRange R, ASTContext &Ctx
3638 , Expr * *Args, unsigned ArgsSize
3639 , unsigned SI
3640 )
3641 : InheritableAttr(attr::LocksExcluded, R, SI, true, true)
3642 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
3643 {
3644 std::copy(Args, Args + args_Size, args_);
3645 }
3646
3647 LocksExcludedAttr(SourceRange R, ASTContext &Ctx
3648 , unsigned SI
3649 )
3650 : InheritableAttr(attr::LocksExcluded, R, SI, true, true)
3651 , args_Size(0), args_(nullptr)
3652 {
3653 }
3654
3655 LocksExcludedAttr *clone(ASTContext &C) const;
3656 void printPretty(raw_ostream &OS,
3657 const PrintingPolicy &Policy) const;
3658 const char *getSpelling() const;
3659 typedef Expr ** args_iterator;
3660 args_iterator args_begin() const { return args_; }
3661 args_iterator args_end() const { return args_ + args_Size; }
3662 unsigned args_size() const { return args_Size; }
3663 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
3664
3665
3666
3667
3668 static bool classof(const Attr *A) { return A->getKind() == attr::LocksExcluded; }
3669};
3670
3671class LoopHintAttr : public Attr {
3672public:
3673 enum OptionType {
3674 Vectorize,
3675 VectorizeWidth,
3676 Interleave,
3677 InterleaveCount,
3678 Unroll,
3679 UnrollCount,
3680 Distribute
3681 };
3682private:
3683 OptionType option;
3684
3685public:
3686 enum LoopHintState {
3687 Enable,
3688 Disable,
3689 Numeric,
3690 AssumeSafety,
3691 Full
3692 };
3693private:
3694 LoopHintState state;
3695
3696Expr * value;
3697
3698public:
3699 enum Spelling {
3700 Pragma_clang_loop = 0,
3701 Pragma_unroll = 1,
3702 Pragma_nounroll = 2
3703 };
3704
3705 static LoopHintAttr *CreateImplicit(ASTContext &Ctx, Spelling S, OptionType Option, LoopHintState State, Expr * Value, SourceRange Loc = SourceRange()) {
3706 auto *A = new (Ctx) LoopHintAttr(Loc, Ctx, Option, State, Value, S);
3707 A->setImplicit(true);
3708 return A;
3709 }
3710
3711 LoopHintAttr(SourceRange R, ASTContext &Ctx
3712 , OptionType Option
3713 , LoopHintState State
3714 , Expr * Value
3715 , unsigned SI
3716 )
3717 : Attr(attr::LoopHint, R, SI, false)
3718 , option(Option)
3719 , state(State)
3720 , value(Value)
3721 {
3722 }
3723
3724 LoopHintAttr *clone(ASTContext &C) const;
3725 void printPretty(raw_ostream &OS,
3726 const PrintingPolicy &Policy) const;
3727 const char *getSpelling() const;
3728 Spelling getSemanticSpelling() const {
3729 switch (SpellingListIndex) {
3730 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3730)
;
3731 case 0: return Pragma_clang_loop;
3732 case 1: return Pragma_unroll;
3733 case 2: return Pragma_nounroll;
3734 }
3735 }
3736 OptionType getOption() const {
3737 return option;
3738 }
3739
3740 static bool ConvertStrToOptionType(StringRef Val, OptionType &Out) {
3741 Optional<OptionType> R = llvm::StringSwitch<Optional<OptionType>>(Val)
3742 .Case("vectorize", LoopHintAttr::Vectorize)
3743 .Case("vectorize_width", LoopHintAttr::VectorizeWidth)
3744 .Case("interleave", LoopHintAttr::Interleave)
3745 .Case("interleave_count", LoopHintAttr::InterleaveCount)
3746 .Case("unroll", LoopHintAttr::Unroll)
3747 .Case("unroll_count", LoopHintAttr::UnrollCount)
3748 .Case("distribute", LoopHintAttr::Distribute)
3749 .Default(Optional<OptionType>());
3750 if (R) {
3751 Out = *R;
3752 return true;
3753 }
3754 return false;
3755 }
3756
3757 static const char *ConvertOptionTypeToStr(OptionType Val) {
3758 switch(Val) {
3759 case LoopHintAttr::Vectorize: return "vectorize";
3760 case LoopHintAttr::VectorizeWidth: return "vectorize_width";
3761 case LoopHintAttr::Interleave: return "interleave";
3762 case LoopHintAttr::InterleaveCount: return "interleave_count";
3763 case LoopHintAttr::Unroll: return "unroll";
3764 case LoopHintAttr::UnrollCount: return "unroll_count";
3765 case LoopHintAttr::Distribute: return "distribute";
3766 }
3767 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3767)
;
3768 }
3769 LoopHintState getState() const {
3770 return state;
3771 }
3772
3773 static bool ConvertStrToLoopHintState(StringRef Val, LoopHintState &Out) {
3774 Optional<LoopHintState> R = llvm::StringSwitch<Optional<LoopHintState>>(Val)
3775 .Case("enable", LoopHintAttr::Enable)
3776 .Case("disable", LoopHintAttr::Disable)
3777 .Case("numeric", LoopHintAttr::Numeric)
3778 .Case("assume_safety", LoopHintAttr::AssumeSafety)
3779 .Case("full", LoopHintAttr::Full)
3780 .Default(Optional<LoopHintState>());
3781 if (R) {
3782 Out = *R;
3783 return true;
3784 }
3785 return false;
3786 }
3787
3788 static const char *ConvertLoopHintStateToStr(LoopHintState Val) {
3789 switch(Val) {
3790 case LoopHintAttr::Enable: return "enable";
3791 case LoopHintAttr::Disable: return "disable";
3792 case LoopHintAttr::Numeric: return "numeric";
3793 case LoopHintAttr::AssumeSafety: return "assume_safety";
3794 case LoopHintAttr::Full: return "full";
3795 }
3796 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3796)
;
3797 }
3798 Expr * getValue() const {
3799 return value;
3800 }
3801
3802
3803 static const char *getOptionName(int Option) {
3804 switch(Option) {
3805 case Vectorize: return "vectorize";
3806 case VectorizeWidth: return "vectorize_width";
3807 case Interleave: return "interleave";
3808 case InterleaveCount: return "interleave_count";
3809 case Unroll: return "unroll";
3810 case UnrollCount: return "unroll_count";
3811 case Distribute: return "distribute";
3812 }
3813 llvm_unreachable("Unhandled LoopHint option.")::llvm::llvm_unreachable_internal("Unhandled LoopHint option."
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3813)
;
3814 }
3815
3816 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
3817 unsigned SpellingIndex = getSpellingListIndex();
3818 // For "#pragma unroll" and "#pragma nounroll" the string "unroll" or
3819 // "nounroll" is already emitted as the pragma name.
3820 if (SpellingIndex == Pragma_nounroll)
3821 return;
3822 else if (SpellingIndex == Pragma_unroll) {
3823 OS << ' ' << getValueString(Policy);
3824 return;
3825 }
3826
3827 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling")(static_cast <bool> (SpellingIndex == Pragma_clang_loop
&& "Unexpected spelling") ? void (0) : __assert_fail
("SpellingIndex == Pragma_clang_loop && \"Unexpected spelling\""
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3827, __extension__ __PRETTY_FUNCTION__))
;
3828 OS << ' ' << getOptionName(option) << getValueString(Policy);
3829 }
3830
3831 // Return a string containing the loop hint argument including the
3832 // enclosing parentheses.
3833 std::string getValueString(const PrintingPolicy &Policy) const {
3834 std::string ValueName;
3835 llvm::raw_string_ostream OS(ValueName);
3836 OS << "(";
3837 if (state == Numeric)
3838 value->printPretty(OS, nullptr, Policy);
3839 else if (state == Enable)
3840 OS << "enable";
3841 else if (state == Full)
3842 OS << "full";
3843 else if (state == AssumeSafety)
3844 OS << "assume_safety";
3845 else
3846 OS << "disable";
3847 OS << ")";
3848 return OS.str();
3849 }
3850
3851 // Return a string suitable for identifying this attribute in diagnostics.
3852 std::string getDiagnosticName(const PrintingPolicy &Policy) const {
3853 unsigned SpellingIndex = getSpellingListIndex();
3854 if (SpellingIndex == Pragma_nounroll)
3855 return "#pragma nounroll";
3856 else if (SpellingIndex == Pragma_unroll)
3857 return "#pragma unroll" + (option == UnrollCount ? getValueString(Policy) : "");
3858
3859 assert(SpellingIndex == Pragma_clang_loop && "Unexpected spelling")(static_cast <bool> (SpellingIndex == Pragma_clang_loop
&& "Unexpected spelling") ? void (0) : __assert_fail
("SpellingIndex == Pragma_clang_loop && \"Unexpected spelling\""
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3859, __extension__ __PRETTY_FUNCTION__))
;
3860 return getOptionName(option) + getValueString(Policy);
3861 }
3862
3863
3864 static bool classof(const Attr *A) { return A->getKind() == attr::LoopHint; }
3865};
3866
3867class MSABIAttr : public InheritableAttr {
3868public:
3869 static MSABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3870 auto *A = new (Ctx) MSABIAttr(Loc, Ctx, 0);
3871 A->setImplicit(true);
3872 return A;
3873 }
3874
3875 MSABIAttr(SourceRange R, ASTContext &Ctx
3876 , unsigned SI
3877 )
3878 : InheritableAttr(attr::MSABI, R, SI, false, false)
3879 {
3880 }
3881
3882 MSABIAttr *clone(ASTContext &C) const;
3883 void printPretty(raw_ostream &OS,
3884 const PrintingPolicy &Policy) const;
3885 const char *getSpelling() const;
3886
3887
3888 static bool classof(const Attr *A) { return A->getKind() == attr::MSABI; }
3889};
3890
3891class MSInheritanceAttr : public InheritableAttr {
3892bool bestCase;
3893
3894public:
3895 enum Spelling {
3896 Keyword_single_inheritance = 0,
3897 Keyword_multiple_inheritance = 1,
3898 Keyword_virtual_inheritance = 2,
3899 Keyword_unspecified_inheritance = 3
3900 };
3901
3902 static MSInheritanceAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool BestCase, SourceRange Loc = SourceRange()) {
3903 auto *A = new (Ctx) MSInheritanceAttr(Loc, Ctx, BestCase, S);
3904 A->setImplicit(true);
3905 return A;
3906 }
3907
3908 MSInheritanceAttr(SourceRange R, ASTContext &Ctx
3909 , bool BestCase
3910 , unsigned SI
3911 )
3912 : InheritableAttr(attr::MSInheritance, R, SI, false, false)
3913 , bestCase(BestCase)
3914 {
3915 }
3916
3917 MSInheritanceAttr(SourceRange R, ASTContext &Ctx
3918 , unsigned SI
3919 )
3920 : InheritableAttr(attr::MSInheritance, R, SI, false, false)
3921 , bestCase()
3922 {
3923 }
3924
3925 MSInheritanceAttr *clone(ASTContext &C) const;
3926 void printPretty(raw_ostream &OS,
3927 const PrintingPolicy &Policy) const;
3928 const char *getSpelling() const;
3929 Spelling getSemanticSpelling() const {
3930 switch (SpellingListIndex) {
3931 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 3931)
;
3932 case 0: return Keyword_single_inheritance;
3933 case 1: return Keyword_multiple_inheritance;
3934 case 2: return Keyword_virtual_inheritance;
3935 case 3: return Keyword_unspecified_inheritance;
3936 }
3937 }
3938 bool getBestCase() const {
3939 return bestCase;
3940 }
3941
3942 static const bool DefaultBestCase = true;
3943
3944
3945 static bool hasVBPtrOffsetField(Spelling Inheritance) {
3946 return Inheritance == Keyword_unspecified_inheritance;
3947 }
3948
3949 // Only member pointers to functions need a this adjustment, since it can be
3950 // combined with the field offset for data pointers.
3951 static bool hasNVOffsetField(bool IsMemberFunction, Spelling Inheritance) {
3952 return IsMemberFunction && Inheritance >= Keyword_multiple_inheritance;
3953 }
3954
3955 static bool hasVBTableOffsetField(Spelling Inheritance) {
3956 return Inheritance >= Keyword_virtual_inheritance;
3957 }
3958
3959 static bool hasOnlyOneField(bool IsMemberFunction,
3960 Spelling Inheritance) {
3961 if (IsMemberFunction)
3962 return Inheritance <= Keyword_single_inheritance;
3963 return Inheritance <= Keyword_multiple_inheritance;
3964 }
3965
3966
3967 static bool classof(const Attr *A) { return A->getKind() == attr::MSInheritance; }
3968};
3969
3970class MSNoVTableAttr : public InheritableAttr {
3971public:
3972 static MSNoVTableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
3973 auto *A = new (Ctx) MSNoVTableAttr(Loc, Ctx, 0);
3974 A->setImplicit(true);
3975 return A;
3976 }
3977
3978 MSNoVTableAttr(SourceRange R, ASTContext &Ctx
3979 , unsigned SI
3980 )
3981 : InheritableAttr(attr::MSNoVTable, R, SI, false, false)
3982 {
3983 }
3984
3985 MSNoVTableAttr *clone(ASTContext &C) const;
3986 void printPretty(raw_ostream &OS,
3987 const PrintingPolicy &Policy) const;
3988 const char *getSpelling() const;
3989
3990
3991 static bool classof(const Attr *A) { return A->getKind() == attr::MSNoVTable; }
3992};
3993
3994class MSP430InterruptAttr : public InheritableAttr {
3995unsigned number;
3996
3997public:
3998 static MSP430InterruptAttr *CreateImplicit(ASTContext &Ctx, unsigned Number, SourceRange Loc = SourceRange()) {
3999 auto *A = new (Ctx) MSP430InterruptAttr(Loc, Ctx, Number, 0);
4000 A->setImplicit(true);
4001 return A;
4002 }
4003
4004 MSP430InterruptAttr(SourceRange R, ASTContext &Ctx
4005 , unsigned Number
4006 , unsigned SI
4007 )
4008 : InheritableAttr(attr::MSP430Interrupt, R, SI, false, false)
4009 , number(Number)
4010 {
4011 }
4012
4013 MSP430InterruptAttr *clone(ASTContext &C) const;
4014 void printPretty(raw_ostream &OS,
4015 const PrintingPolicy &Policy) const;
4016 const char *getSpelling() const;
4017 unsigned getNumber() const {
4018 return number;
4019 }
4020
4021
4022
4023 static bool classof(const Attr *A) { return A->getKind() == attr::MSP430Interrupt; }
4024};
4025
4026class MSStructAttr : public InheritableAttr {
4027public:
4028 static MSStructAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4029 auto *A = new (Ctx) MSStructAttr(Loc, Ctx, 0);
4030 A->setImplicit(true);
4031 return A;
4032 }
4033
4034 MSStructAttr(SourceRange R, ASTContext &Ctx
4035 , unsigned SI
4036 )
4037 : InheritableAttr(attr::MSStruct, R, SI, false, false)
4038 {
4039 }
4040
4041 MSStructAttr *clone(ASTContext &C) const;
4042 void printPretty(raw_ostream &OS,
4043 const PrintingPolicy &Policy) const;
4044 const char *getSpelling() const;
4045
4046
4047 static bool classof(const Attr *A) { return A->getKind() == attr::MSStruct; }
4048};
4049
4050class MSVtorDispAttr : public InheritableAttr {
4051unsigned vdm;
4052
4053public:
4054 static MSVtorDispAttr *CreateImplicit(ASTContext &Ctx, unsigned Vdm, SourceRange Loc = SourceRange()) {
4055 auto *A = new (Ctx) MSVtorDispAttr(Loc, Ctx, Vdm, 0);
4056 A->setImplicit(true);
4057 return A;
4058 }
4059
4060 MSVtorDispAttr(SourceRange R, ASTContext &Ctx
4061 , unsigned Vdm
4062 , unsigned SI
4063 )
4064 : InheritableAttr(attr::MSVtorDisp, R, SI, false, false)
4065 , vdm(Vdm)
4066 {
4067 }
4068
4069 MSVtorDispAttr *clone(ASTContext &C) const;
4070 void printPretty(raw_ostream &OS,
4071 const PrintingPolicy &Policy) const;
4072 const char *getSpelling() const;
4073 unsigned getVdm() const {
4074 return vdm;
4075 }
4076
4077
4078 enum Mode {
4079 Never,
4080 ForVBaseOverride,
4081 ForVFTable
4082 };
4083
4084 Mode getVtorDispMode() const { return Mode(vdm); }
4085
4086
4087 static bool classof(const Attr *A) { return A->getKind() == attr::MSVtorDisp; }
4088};
4089
4090class MaxFieldAlignmentAttr : public InheritableAttr {
4091unsigned alignment;
4092
4093public:
4094 static MaxFieldAlignmentAttr *CreateImplicit(ASTContext &Ctx, unsigned Alignment, SourceRange Loc = SourceRange()) {
4095 auto *A = new (Ctx) MaxFieldAlignmentAttr(Loc, Ctx, Alignment, 0);
4096 A->setImplicit(true);
4097 return A;
4098 }
4099
4100 MaxFieldAlignmentAttr(SourceRange R, ASTContext &Ctx
4101 , unsigned Alignment
4102 , unsigned SI
4103 )
4104 : InheritableAttr(attr::MaxFieldAlignment, R, SI, false, false)
4105 , alignment(Alignment)
4106 {
4107 }
4108
4109 MaxFieldAlignmentAttr *clone(ASTContext &C) const;
4110 void printPretty(raw_ostream &OS,
4111 const PrintingPolicy &Policy) const;
4112 const char *getSpelling() const;
4113 unsigned getAlignment() const {
4114 return alignment;
4115 }
4116
4117
4118
4119 static bool classof(const Attr *A) { return A->getKind() == attr::MaxFieldAlignment; }
4120};
4121
4122class MayAliasAttr : public InheritableAttr {
4123public:
4124 static MayAliasAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4125 auto *A = new (Ctx) MayAliasAttr(Loc, Ctx, 0);
4126 A->setImplicit(true);
4127 return A;
4128 }
4129
4130 MayAliasAttr(SourceRange R, ASTContext &Ctx
4131 , unsigned SI
4132 )
4133 : InheritableAttr(attr::MayAlias, R, SI, false, false)
4134 {
4135 }
4136
4137 MayAliasAttr *clone(ASTContext &C) const;
4138 void printPretty(raw_ostream &OS,
4139 const PrintingPolicy &Policy) const;
4140 const char *getSpelling() const;
4141
4142
4143 static bool classof(const Attr *A) { return A->getKind() == attr::MayAlias; }
4144};
4145
4146class MicroMipsAttr : public InheritableAttr {
4147public:
4148 static MicroMipsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4149 auto *A = new (Ctx) MicroMipsAttr(Loc, Ctx, 0);
4150 A->setImplicit(true);
4151 return A;
4152 }
4153
4154 MicroMipsAttr(SourceRange R, ASTContext &Ctx
4155 , unsigned SI
4156 )
4157 : InheritableAttr(attr::MicroMips, R, SI, false, false)
4158 {
4159 }
4160
4161 MicroMipsAttr *clone(ASTContext &C) const;
4162 void printPretty(raw_ostream &OS,
4163 const PrintingPolicy &Policy) const;
4164 const char *getSpelling() const;
4165
4166
4167 static bool classof(const Attr *A) { return A->getKind() == attr::MicroMips; }
4168};
4169
4170class MinSizeAttr : public InheritableAttr {
4171public:
4172 static MinSizeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4173 auto *A = new (Ctx) MinSizeAttr(Loc, Ctx, 0);
4174 A->setImplicit(true);
4175 return A;
4176 }
4177
4178 MinSizeAttr(SourceRange R, ASTContext &Ctx
4179 , unsigned SI
4180 )
4181 : InheritableAttr(attr::MinSize, R, SI, false, false)
4182 {
4183 }
4184
4185 MinSizeAttr *clone(ASTContext &C) const;
4186 void printPretty(raw_ostream &OS,
4187 const PrintingPolicy &Policy) const;
4188 const char *getSpelling() const;
4189
4190
4191 static bool classof(const Attr *A) { return A->getKind() == attr::MinSize; }
4192};
4193
4194class Mips16Attr : public InheritableAttr {
4195public:
4196 static Mips16Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4197 auto *A = new (Ctx) Mips16Attr(Loc, Ctx, 0);
4198 A->setImplicit(true);
4199 return A;
4200 }
4201
4202 Mips16Attr(SourceRange R, ASTContext &Ctx
4203 , unsigned SI
4204 )
4205 : InheritableAttr(attr::Mips16, R, SI, false, false)
4206 {
4207 }
4208
4209 Mips16Attr *clone(ASTContext &C) const;
4210 void printPretty(raw_ostream &OS,
4211 const PrintingPolicy &Policy) const;
4212 const char *getSpelling() const;
4213
4214
4215 static bool classof(const Attr *A) { return A->getKind() == attr::Mips16; }
4216};
4217
4218class MipsInterruptAttr : public InheritableAttr {
4219public:
4220 enum InterruptType {
4221 sw0,
4222 sw1,
4223 hw0,
4224 hw1,
4225 hw2,
4226 hw3,
4227 hw4,
4228 hw5,
4229 eic
4230 };
4231private:
4232 InterruptType interrupt;
4233
4234public:
4235 static MipsInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) {
4236 auto *A = new (Ctx) MipsInterruptAttr(Loc, Ctx, Interrupt, 0);
4237 A->setImplicit(true);
4238 return A;
4239 }
4240
4241 MipsInterruptAttr(SourceRange R, ASTContext &Ctx
4242 , InterruptType Interrupt
4243 , unsigned SI
4244 )
4245 : InheritableAttr(attr::MipsInterrupt, R, SI, false, false)
4246 , interrupt(Interrupt)
4247 {
4248 }
4249
4250 MipsInterruptAttr *clone(ASTContext &C) const;
4251 void printPretty(raw_ostream &OS,
4252 const PrintingPolicy &Policy) const;
4253 const char *getSpelling() const;
4254 InterruptType getInterrupt() const {
4255 return interrupt;
4256 }
4257
4258 static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) {
4259 Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val)
4260 .Case("vector=sw0", MipsInterruptAttr::sw0)
4261 .Case("vector=sw1", MipsInterruptAttr::sw1)
4262 .Case("vector=hw0", MipsInterruptAttr::hw0)
4263 .Case("vector=hw1", MipsInterruptAttr::hw1)
4264 .Case("vector=hw2", MipsInterruptAttr::hw2)
4265 .Case("vector=hw3", MipsInterruptAttr::hw3)
4266 .Case("vector=hw4", MipsInterruptAttr::hw4)
4267 .Case("vector=hw5", MipsInterruptAttr::hw5)
4268 .Case("eic", MipsInterruptAttr::eic)
4269 .Case("", MipsInterruptAttr::eic)
4270 .Default(Optional<InterruptType>());
4271 if (R) {
4272 Out = *R;
4273 return true;
4274 }
4275 return false;
4276 }
4277
4278 static const char *ConvertInterruptTypeToStr(InterruptType Val) {
4279 switch(Val) {
4280 case MipsInterruptAttr::sw0: return "vector=sw0";
4281 case MipsInterruptAttr::sw1: return "vector=sw1";
4282 case MipsInterruptAttr::hw0: return "vector=hw0";
4283 case MipsInterruptAttr::hw1: return "vector=hw1";
4284 case MipsInterruptAttr::hw2: return "vector=hw2";
4285 case MipsInterruptAttr::hw3: return "vector=hw3";
4286 case MipsInterruptAttr::hw4: return "vector=hw4";
4287 case MipsInterruptAttr::hw5: return "vector=hw5";
4288 case MipsInterruptAttr::eic: return "eic";
4289 }
4290 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4290)
;
4291 }
4292
4293
4294 static bool classof(const Attr *A) { return A->getKind() == attr::MipsInterrupt; }
4295};
4296
4297class MipsLongCallAttr : public InheritableAttr {
4298public:
4299 enum Spelling {
4300 GNU_long_call = 0,
4301 CXX11_gnu_long_call = 1,
4302 GNU_far = 2,
4303 CXX11_gnu_far = 3
4304 };
4305
4306 static MipsLongCallAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
4307 auto *A = new (Ctx) MipsLongCallAttr(Loc, Ctx, S);
4308 A->setImplicit(true);
4309 return A;
4310 }
4311
4312 MipsLongCallAttr(SourceRange R, ASTContext &Ctx
4313 , unsigned SI
4314 )
4315 : InheritableAttr(attr::MipsLongCall, R, SI, false, false)
4316 {
4317 }
4318
4319 MipsLongCallAttr *clone(ASTContext &C) const;
4320 void printPretty(raw_ostream &OS,
4321 const PrintingPolicy &Policy) const;
4322 const char *getSpelling() const;
4323 Spelling getSemanticSpelling() const {
4324 switch (SpellingListIndex) {
4325 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4325)
;
4326 case 0: return GNU_long_call;
4327 case 1: return CXX11_gnu_long_call;
4328 case 2: return GNU_far;
4329 case 3: return CXX11_gnu_far;
4330 }
4331 }
4332
4333
4334 static bool classof(const Attr *A) { return A->getKind() == attr::MipsLongCall; }
4335};
4336
4337class MipsShortCallAttr : public InheritableAttr {
4338public:
4339 enum Spelling {
4340 GNU_short_call = 0,
4341 CXX11_gnu_short_call = 1,
4342 GNU_near = 2,
4343 CXX11_gnu_near = 3
4344 };
4345
4346 static MipsShortCallAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
4347 auto *A = new (Ctx) MipsShortCallAttr(Loc, Ctx, S);
4348 A->setImplicit(true);
4349 return A;
4350 }
4351
4352 MipsShortCallAttr(SourceRange R, ASTContext &Ctx
4353 , unsigned SI
4354 )
4355 : InheritableAttr(attr::MipsShortCall, R, SI, false, false)
4356 {
4357 }
4358
4359 MipsShortCallAttr *clone(ASTContext &C) const;
4360 void printPretty(raw_ostream &OS,
4361 const PrintingPolicy &Policy) const;
4362 const char *getSpelling() const;
4363 Spelling getSemanticSpelling() const {
4364 switch (SpellingListIndex) {
4365 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 4365)
;
4366 case 0: return GNU_short_call;
4367 case 1: return CXX11_gnu_short_call;
4368 case 2: return GNU_near;
4369 case 3: return CXX11_gnu_near;
4370 }
4371 }
4372
4373
4374 static bool classof(const Attr *A) { return A->getKind() == attr::MipsShortCall; }
4375};
4376
4377class ModeAttr : public Attr {
4378IdentifierInfo * mode;
4379
4380public:
4381 static ModeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Mode, SourceRange Loc = SourceRange()) {
4382 auto *A = new (Ctx) ModeAttr(Loc, Ctx, Mode, 0);
4383 A->setImplicit(true);
4384 return A;
4385 }
4386
4387 ModeAttr(SourceRange R, ASTContext &Ctx
4388 , IdentifierInfo * Mode
4389 , unsigned SI
4390 )
4391 : Attr(attr::Mode, R, SI, false)
4392 , mode(Mode)
4393 {
4394 }
4395
4396 ModeAttr *clone(ASTContext &C) const;
4397 void printPretty(raw_ostream &OS,
4398 const PrintingPolicy &Policy) const;
4399 const char *getSpelling() const;
4400 IdentifierInfo * getMode() const {
4401 return mode;
4402 }
4403
4404
4405
4406 static bool classof(const Attr *A) { return A->getKind() == attr::Mode; }
4407};
4408
4409class NSConsumedAttr : public InheritableParamAttr {
4410public:
4411 static NSConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4412 auto *A = new (Ctx) NSConsumedAttr(Loc, Ctx, 0);
4413 A->setImplicit(true);
4414 return A;
4415 }
4416
4417 NSConsumedAttr(SourceRange R, ASTContext &Ctx
4418 , unsigned SI
4419 )
4420 : InheritableParamAttr(attr::NSConsumed, R, SI, false, false)
4421 {
4422 }
4423
4424 NSConsumedAttr *clone(ASTContext &C) const;
4425 void printPretty(raw_ostream &OS,
4426 const PrintingPolicy &Policy) const;
4427 const char *getSpelling() const;
4428
4429
4430 static bool classof(const Attr *A) { return A->getKind() == attr::NSConsumed; }
4431};
4432
4433class NSConsumesSelfAttr : public InheritableAttr {
4434public:
4435 static NSConsumesSelfAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4436 auto *A = new (Ctx) NSConsumesSelfAttr(Loc, Ctx, 0);
4437 A->setImplicit(true);
4438 return A;
4439 }
4440
4441 NSConsumesSelfAttr(SourceRange R, ASTContext &Ctx
4442 , unsigned SI
4443 )
4444 : InheritableAttr(attr::NSConsumesSelf, R, SI, false, false)
4445 {
4446 }
4447
4448 NSConsumesSelfAttr *clone(ASTContext &C) const;
4449 void printPretty(raw_ostream &OS,
4450 const PrintingPolicy &Policy) const;
4451 const char *getSpelling() const;
4452
4453
4454 static bool classof(const Attr *A) { return A->getKind() == attr::NSConsumesSelf; }
4455};
4456
4457class NSReturnsAutoreleasedAttr : public InheritableAttr {
4458public:
4459 static NSReturnsAutoreleasedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4460 auto *A = new (Ctx) NSReturnsAutoreleasedAttr(Loc, Ctx, 0);
4461 A->setImplicit(true);
4462 return A;
4463 }
4464
4465 NSReturnsAutoreleasedAttr(SourceRange R, ASTContext &Ctx
4466 , unsigned SI
4467 )
4468 : InheritableAttr(attr::NSReturnsAutoreleased, R, SI, false, false)
4469 {
4470 }
4471
4472 NSReturnsAutoreleasedAttr *clone(ASTContext &C) const;
4473 void printPretty(raw_ostream &OS,
4474 const PrintingPolicy &Policy) const;
4475 const char *getSpelling() const;
4476
4477
4478 static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsAutoreleased; }
4479};
4480
4481class NSReturnsNotRetainedAttr : public InheritableAttr {
4482public:
4483 static NSReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4484 auto *A = new (Ctx) NSReturnsNotRetainedAttr(Loc, Ctx, 0);
4485 A->setImplicit(true);
4486 return A;
4487 }
4488
4489 NSReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx
4490 , unsigned SI
4491 )
4492 : InheritableAttr(attr::NSReturnsNotRetained, R, SI, false, false)
4493 {
4494 }
4495
4496 NSReturnsNotRetainedAttr *clone(ASTContext &C) const;
4497 void printPretty(raw_ostream &OS,
4498 const PrintingPolicy &Policy) const;
4499 const char *getSpelling() const;
4500
4501
4502 static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsNotRetained; }
4503};
4504
4505class NSReturnsRetainedAttr : public InheritableAttr {
4506public:
4507 static NSReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4508 auto *A = new (Ctx) NSReturnsRetainedAttr(Loc, Ctx, 0);
4509 A->setImplicit(true);
4510 return A;
4511 }
4512
4513 NSReturnsRetainedAttr(SourceRange R, ASTContext &Ctx
4514 , unsigned SI
4515 )
4516 : InheritableAttr(attr::NSReturnsRetained, R, SI, false, false)
4517 {
4518 }
4519
4520 NSReturnsRetainedAttr *clone(ASTContext &C) const;
4521 void printPretty(raw_ostream &OS,
4522 const PrintingPolicy &Policy) const;
4523 const char *getSpelling() const;
4524
4525
4526 static bool classof(const Attr *A) { return A->getKind() == attr::NSReturnsRetained; }
4527};
4528
4529class NakedAttr : public InheritableAttr {
4530public:
4531 static NakedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4532 auto *A = new (Ctx) NakedAttr(Loc, Ctx, 0);
4533 A->setImplicit(true);
4534 return A;
4535 }
4536
4537 NakedAttr(SourceRange R, ASTContext &Ctx
4538 , unsigned SI
4539 )
4540 : InheritableAttr(attr::Naked, R, SI, false, false)
4541 {
4542 }
4543
4544 NakedAttr *clone(ASTContext &C) const;
4545 void printPretty(raw_ostream &OS,
4546 const PrintingPolicy &Policy) const;
4547 const char *getSpelling() const;
4548
4549
4550 static bool classof(const Attr *A) { return A->getKind() == attr::Naked; }
4551};
4552
4553class NoAliasAttr : public InheritableAttr {
4554public:
4555 static NoAliasAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4556 auto *A = new (Ctx) NoAliasAttr(Loc, Ctx, 0);
4557 A->setImplicit(true);
4558 return A;
4559 }
4560
4561 NoAliasAttr(SourceRange R, ASTContext &Ctx
4562 , unsigned SI
4563 )
4564 : InheritableAttr(attr::NoAlias, R, SI, false, false)
4565 {
4566 }
4567
4568 NoAliasAttr *clone(ASTContext &C) const;
4569 void printPretty(raw_ostream &OS,
4570 const PrintingPolicy &Policy) const;
4571 const char *getSpelling() const;
4572
4573
4574 static bool classof(const Attr *A) { return A->getKind() == attr::NoAlias; }
4575};
4576
4577class NoCommonAttr : public InheritableAttr {
4578public:
4579 static NoCommonAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4580 auto *A = new (Ctx) NoCommonAttr(Loc, Ctx, 0);
4581 A->setImplicit(true);
4582 return A;
4583 }
4584
4585 NoCommonAttr(SourceRange R, ASTContext &Ctx
4586 , unsigned SI
4587 )
4588 : InheritableAttr(attr::NoCommon, R, SI, false, false)
4589 {
4590 }
4591
4592 NoCommonAttr *clone(ASTContext &C) const;
4593 void printPretty(raw_ostream &OS,
4594 const PrintingPolicy &Policy) const;
4595 const char *getSpelling() const;
4596
4597
4598 static bool classof(const Attr *A) { return A->getKind() == attr::NoCommon; }
4599};
4600
4601class NoDebugAttr : public InheritableAttr {
4602public:
4603 static NoDebugAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4604 auto *A = new (Ctx) NoDebugAttr(Loc, Ctx, 0);
4605 A->setImplicit(true);
4606 return A;
4607 }
4608
4609 NoDebugAttr(SourceRange R, ASTContext &Ctx
4610 , unsigned SI
4611 )
4612 : InheritableAttr(attr::NoDebug, R, SI, false, false)
4613 {
4614 }
4615
4616 NoDebugAttr *clone(ASTContext &C) const;
4617 void printPretty(raw_ostream &OS,
4618 const PrintingPolicy &Policy) const;
4619 const char *getSpelling() const;
4620
4621
4622 static bool classof(const Attr *A) { return A->getKind() == attr::NoDebug; }
4623};
4624
4625class NoDuplicateAttr : public InheritableAttr {
4626public:
4627 static NoDuplicateAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4628 auto *A = new (Ctx) NoDuplicateAttr(Loc, Ctx, 0);
4629 A->setImplicit(true);
4630 return A;
4631 }
4632
4633 NoDuplicateAttr(SourceRange R, ASTContext &Ctx
4634 , unsigned SI
4635 )
4636 : InheritableAttr(attr::NoDuplicate, R, SI, false, false)
4637 {
4638 }
4639
4640 NoDuplicateAttr *clone(ASTContext &C) const;
4641 void printPretty(raw_ostream &OS,
4642 const PrintingPolicy &Policy) const;
4643 const char *getSpelling() const;
4644
4645
4646 static bool classof(const Attr *A) { return A->getKind() == attr::NoDuplicate; }
4647};
4648
4649class NoEscapeAttr : public Attr {
4650public:
4651 static NoEscapeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4652 auto *A = new (Ctx) NoEscapeAttr(Loc, Ctx, 0);
4653 A->setImplicit(true);
4654 return A;
4655 }
4656
4657 NoEscapeAttr(SourceRange R, ASTContext &Ctx
4658 , unsigned SI
4659 )
4660 : Attr(attr::NoEscape, R, SI, false)
4661 {
4662 }
4663
4664 NoEscapeAttr *clone(ASTContext &C) const;
4665 void printPretty(raw_ostream &OS,
4666 const PrintingPolicy &Policy) const;
4667 const char *getSpelling() const;
4668
4669
4670 static bool classof(const Attr *A) { return A->getKind() == attr::NoEscape; }
4671};
4672
4673class NoInlineAttr : public InheritableAttr {
4674public:
4675 static NoInlineAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4676 auto *A = new (Ctx) NoInlineAttr(Loc, Ctx, 0);
4677 A->setImplicit(true);
4678 return A;
4679 }
4680
4681 NoInlineAttr(SourceRange R, ASTContext &Ctx
4682 , unsigned SI
4683 )
4684 : InheritableAttr(attr::NoInline, R, SI, false, false)
4685 {
4686 }
4687
4688 NoInlineAttr *clone(ASTContext &C) const;
4689 void printPretty(raw_ostream &OS,
4690 const PrintingPolicy &Policy) const;
4691 const char *getSpelling() const;
4692
4693
4694 static bool classof(const Attr *A) { return A->getKind() == attr::NoInline; }
4695};
4696
4697class NoInstrumentFunctionAttr : public InheritableAttr {
4698public:
4699 static NoInstrumentFunctionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4700 auto *A = new (Ctx) NoInstrumentFunctionAttr(Loc, Ctx, 0);
4701 A->setImplicit(true);
4702 return A;
4703 }
4704
4705 NoInstrumentFunctionAttr(SourceRange R, ASTContext &Ctx
4706 , unsigned SI
4707 )
4708 : InheritableAttr(attr::NoInstrumentFunction, R, SI, false, false)
4709 {
4710 }
4711
4712 NoInstrumentFunctionAttr *clone(ASTContext &C) const;
4713 void printPretty(raw_ostream &OS,
4714 const PrintingPolicy &Policy) const;
4715 const char *getSpelling() const;
4716
4717
4718 static bool classof(const Attr *A) { return A->getKind() == attr::NoInstrumentFunction; }
4719};
4720
4721class NoMicroMipsAttr : public InheritableAttr {
4722public:
4723 static NoMicroMipsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4724 auto *A = new (Ctx) NoMicroMipsAttr(Loc, Ctx, 0);
4725 A->setImplicit(true);
4726 return A;
4727 }
4728
4729 NoMicroMipsAttr(SourceRange R, ASTContext &Ctx
4730 , unsigned SI
4731 )
4732 : InheritableAttr(attr::NoMicroMips, R, SI, false, false)
4733 {
4734 }
4735
4736 NoMicroMipsAttr *clone(ASTContext &C) const;
4737 void printPretty(raw_ostream &OS,
4738 const PrintingPolicy &Policy) const;
4739 const char *getSpelling() const;
4740
4741
4742 static bool classof(const Attr *A) { return A->getKind() == attr::NoMicroMips; }
4743};
4744
4745class NoMips16Attr : public InheritableAttr {
4746public:
4747 static NoMips16Attr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4748 auto *A = new (Ctx) NoMips16Attr(Loc, Ctx, 0);
4749 A->setImplicit(true);
4750 return A;
4751 }
4752
4753 NoMips16Attr(SourceRange R, ASTContext &Ctx
4754 , unsigned SI
4755 )
4756 : InheritableAttr(attr::NoMips16, R, SI, false, false)
4757 {
4758 }
4759
4760 NoMips16Attr *clone(ASTContext &C) const;
4761 void printPretty(raw_ostream &OS,
4762 const PrintingPolicy &Policy) const;
4763 const char *getSpelling() const;
4764
4765
4766 static bool classof(const Attr *A) { return A->getKind() == attr::NoMips16; }
4767};
4768
4769class NoReturnAttr : public InheritableAttr {
4770public:
4771 static NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4772 auto *A = new (Ctx) NoReturnAttr(Loc, Ctx, 0);
4773 A->setImplicit(true);
4774 return A;
4775 }
4776
4777 NoReturnAttr(SourceRange R, ASTContext &Ctx
4778 , unsigned SI
4779 )
4780 : InheritableAttr(attr::NoReturn, R, SI, false, false)
4781 {
4782 }
4783
4784 NoReturnAttr *clone(ASTContext &C) const;
4785 void printPretty(raw_ostream &OS,
4786 const PrintingPolicy &Policy) const;
4787 const char *getSpelling() const;
4788
4789
4790 static bool classof(const Attr *A) { return A->getKind() == attr::NoReturn; }
4791};
4792
4793class NoSanitizeAttr : public InheritableAttr {
4794 unsigned sanitizers_Size;
4795 StringRef *sanitizers_;
4796
4797public:
4798 static NoSanitizeAttr *CreateImplicit(ASTContext &Ctx, StringRef *Sanitizers, unsigned SanitizersSize, SourceRange Loc = SourceRange()) {
4799 auto *A = new (Ctx) NoSanitizeAttr(Loc, Ctx, Sanitizers, SanitizersSize, 0);
4800 A->setImplicit(true);
4801 return A;
4802 }
4803
4804 NoSanitizeAttr(SourceRange R, ASTContext &Ctx
4805 , StringRef *Sanitizers, unsigned SanitizersSize
4806 , unsigned SI
4807 )
4808 : InheritableAttr(attr::NoSanitize, R, SI, false, false)
4809 , sanitizers_Size(SanitizersSize), sanitizers_(new (Ctx, 16) StringRef[sanitizers_Size])
4810 {
4811 for (size_t I = 0, E = sanitizers_Size; I != E;
4812 ++I) {
4813 StringRef Ref = Sanitizers[I];
4814 if (!Ref.empty()) {
4815 char *Mem = new (Ctx, 1) char[Ref.size()];
4816 std::memcpy(Mem, Ref.data(), Ref.size());
4817 sanitizers_[I] = StringRef(Mem, Ref.size());
4818 }
4819 }
4820 }
4821
4822 NoSanitizeAttr(SourceRange R, ASTContext &Ctx
4823 , unsigned SI
4824 )
4825 : InheritableAttr(attr::NoSanitize, R, SI, false, false)
4826 , sanitizers_Size(0), sanitizers_(nullptr)
4827 {
4828 }
4829
4830 NoSanitizeAttr *clone(ASTContext &C) const;
4831 void printPretty(raw_ostream &OS,
4832 const PrintingPolicy &Policy) const;
4833 const char *getSpelling() const;
4834 typedef StringRef* sanitizers_iterator;
4835 sanitizers_iterator sanitizers_begin() const { return sanitizers_; }
4836 sanitizers_iterator sanitizers_end() const { return sanitizers_ + sanitizers_Size; }
4837 unsigned sanitizers_size() const { return sanitizers_Size; }
4838 llvm::iterator_range<sanitizers_iterator> sanitizers() const { return llvm::make_range(sanitizers_begin(), sanitizers_end()); }
4839
4840
4841
4842 SanitizerMask getMask() const {
4843 SanitizerMask Mask = 0;
4844 for (auto SanitizerName : sanitizers()) {
4845 SanitizerMask ParsedMask =
4846 parseSanitizerValue(SanitizerName, /*AllowGroups=*/true);
4847 Mask |= expandSanitizerGroups(ParsedMask);
4848 }
4849 return Mask;
4850 }
4851
4852
4853 static bool classof(const Attr *A) { return A->getKind() == attr::NoSanitize; }
4854};
4855
4856class NoSplitStackAttr : public InheritableAttr {
4857public:
4858 static NoSplitStackAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4859 auto *A = new (Ctx) NoSplitStackAttr(Loc, Ctx, 0);
4860 A->setImplicit(true);
4861 return A;
4862 }
4863
4864 NoSplitStackAttr(SourceRange R, ASTContext &Ctx
4865 , unsigned SI
4866 )
4867 : InheritableAttr(attr::NoSplitStack, R, SI, false, false)
4868 {
4869 }
4870
4871 NoSplitStackAttr *clone(ASTContext &C) const;
4872 void printPretty(raw_ostream &OS,
4873 const PrintingPolicy &Policy) const;
4874 const char *getSpelling() const;
4875
4876
4877 static bool classof(const Attr *A) { return A->getKind() == attr::NoSplitStack; }
4878};
4879
4880class NoThreadSafetyAnalysisAttr : public InheritableAttr {
4881public:
4882 static NoThreadSafetyAnalysisAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4883 auto *A = new (Ctx) NoThreadSafetyAnalysisAttr(Loc, Ctx, 0);
4884 A->setImplicit(true);
4885 return A;
4886 }
4887
4888 NoThreadSafetyAnalysisAttr(SourceRange R, ASTContext &Ctx
4889 , unsigned SI
4890 )
4891 : InheritableAttr(attr::NoThreadSafetyAnalysis, R, SI, false, false)
4892 {
4893 }
4894
4895 NoThreadSafetyAnalysisAttr *clone(ASTContext &C) const;
4896 void printPretty(raw_ostream &OS,
4897 const PrintingPolicy &Policy) const;
4898 const char *getSpelling() const;
4899
4900
4901 static bool classof(const Attr *A) { return A->getKind() == attr::NoThreadSafetyAnalysis; }
4902};
4903
4904class NoThrowAttr : public InheritableAttr {
4905public:
4906 static NoThrowAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4907 auto *A = new (Ctx) NoThrowAttr(Loc, Ctx, 0);
4908 A->setImplicit(true);
4909 return A;
4910 }
4911
4912 NoThrowAttr(SourceRange R, ASTContext &Ctx
4913 , unsigned SI
4914 )
4915 : InheritableAttr(attr::NoThrow, R, SI, false, false)
4916 {
4917 }
4918
4919 NoThrowAttr *clone(ASTContext &C) const;
4920 void printPretty(raw_ostream &OS,
4921 const PrintingPolicy &Policy) const;
4922 const char *getSpelling() const;
4923
4924
4925 static bool classof(const Attr *A) { return A->getKind() == attr::NoThrow; }
4926};
4927
4928class NonNullAttr : public InheritableParamAttr {
4929 unsigned args_Size;
4930 unsigned *args_;
4931
4932public:
4933 static NonNullAttr *CreateImplicit(ASTContext &Ctx, unsigned *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
4934 auto *A = new (Ctx) NonNullAttr(Loc, Ctx, Args, ArgsSize, 0);
4935 A->setImplicit(true);
4936 return A;
4937 }
4938
4939 NonNullAttr(SourceRange R, ASTContext &Ctx
4940 , unsigned *Args, unsigned ArgsSize
4941 , unsigned SI
4942 )
4943 : InheritableParamAttr(attr::NonNull, R, SI, false, true)
4944 , args_Size(ArgsSize), args_(new (Ctx, 16) unsigned[args_Size])
4945 {
4946 std::copy(Args, Args + args_Size, args_);
4947 }
4948
4949 NonNullAttr(SourceRange R, ASTContext &Ctx
4950 , unsigned SI
4951 )
4952 : InheritableParamAttr(attr::NonNull, R, SI, false, true)
4953 , args_Size(0), args_(nullptr)
4954 {
4955 }
4956
4957 NonNullAttr *clone(ASTContext &C) const;
4958 void printPretty(raw_ostream &OS,
4959 const PrintingPolicy &Policy) const;
4960 const char *getSpelling() const;
4961 typedef unsigned* args_iterator;
4962 args_iterator args_begin() const { return args_; }
4963 args_iterator args_end() const { return args_ + args_Size; }
4964 unsigned args_size() const { return args_Size; }
4965 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
4966
4967
4968bool isNonNull(unsigned idx) const {
4969 if (!args_size())
4970 return true;
4971 for (const auto &V : args())
4972 if (V == idx)
4973 return true;
4974 return false;
4975 }
4976
4977 static bool classof(const Attr *A) { return A->getKind() == attr::NonNull; }
4978};
4979
4980class NotTailCalledAttr : public InheritableAttr {
4981public:
4982 static NotTailCalledAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
4983 auto *A = new (Ctx) NotTailCalledAttr(Loc, Ctx, 0);
4984 A->setImplicit(true);
4985 return A;
4986 }
4987
4988 NotTailCalledAttr(SourceRange R, ASTContext &Ctx
4989 , unsigned SI
4990 )
4991 : InheritableAttr(attr::NotTailCalled, R, SI, false, false)
4992 {
4993 }
4994
4995 NotTailCalledAttr *clone(ASTContext &C) const;
4996 void printPretty(raw_ostream &OS,
4997 const PrintingPolicy &Policy) const;
4998 const char *getSpelling() const;
4999
5000
5001 static bool classof(const Attr *A) { return A->getKind() == attr::NotTailCalled; }
5002};
5003
5004class OMPCaptureKindAttr : public Attr {
5005unsigned captureKind;
5006
5007public:
5008 static OMPCaptureKindAttr *CreateImplicit(ASTContext &Ctx, unsigned CaptureKind, SourceRange Loc = SourceRange()) {
5009 auto *A = new (Ctx) OMPCaptureKindAttr(Loc, Ctx, CaptureKind, 0);
5010 A->setImplicit(true);
5011 return A;
5012 }
5013
5014 OMPCaptureKindAttr(SourceRange R, ASTContext &Ctx
5015 , unsigned CaptureKind
5016 , unsigned SI
5017 )
5018 : Attr(attr::OMPCaptureKind, R, SI, false)
5019 , captureKind(CaptureKind)
5020 {
5021 }
5022
5023 OMPCaptureKindAttr *clone(ASTContext &C) const;
5024 void printPretty(raw_ostream &OS,
5025 const PrintingPolicy &Policy) const;
5026 const char *getSpelling() const;
5027 unsigned getCaptureKind() const {
5028 return captureKind;
5029 }
5030
5031
5032
5033 static bool classof(const Attr *A) { return A->getKind() == attr::OMPCaptureKind; }
5034};
5035
5036class OMPCaptureNoInitAttr : public InheritableAttr {
5037public:
5038 static OMPCaptureNoInitAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5039 auto *A = new (Ctx) OMPCaptureNoInitAttr(Loc, Ctx, 0);
5040 A->setImplicit(true);
5041 return A;
5042 }
5043
5044 OMPCaptureNoInitAttr(SourceRange R, ASTContext &Ctx
5045 , unsigned SI
5046 )
5047 : InheritableAttr(attr::OMPCaptureNoInit, R, SI, false, false)
5048 {
5049 }
5050
5051 OMPCaptureNoInitAttr *clone(ASTContext &C) const;
5052 void printPretty(raw_ostream &OS,
5053 const PrintingPolicy &Policy) const;
5054 const char *getSpelling() const;
5055
5056
5057 static bool classof(const Attr *A) { return A->getKind() == attr::OMPCaptureNoInit; }
5058};
5059
5060class OMPDeclareSimdDeclAttr : public Attr {
5061public:
5062 enum BranchStateTy {
5063 BS_Undefined,
5064 BS_Inbranch,
5065 BS_Notinbranch
5066 };
5067private:
5068 BranchStateTy branchState;
5069
5070Expr * simdlen;
5071
5072 unsigned uniforms_Size;
5073 Expr * *uniforms_;
5074
5075 unsigned aligneds_Size;
5076 Expr * *aligneds_;
5077
5078 unsigned alignments_Size;
5079 Expr * *alignments_;
5080
5081 unsigned linears_Size;
5082 Expr * *linears_;
5083
5084 unsigned modifiers_Size;
5085 unsigned *modifiers_;
5086
5087 unsigned steps_Size;
5088 Expr * *steps_;
5089
5090public:
5091 static OMPDeclareSimdDeclAttr *CreateImplicit(ASTContext &Ctx, BranchStateTy BranchState, Expr * Simdlen, Expr * *Uniforms, unsigned UniformsSize, Expr * *Aligneds, unsigned AlignedsSize, Expr * *Alignments, unsigned AlignmentsSize, Expr * *Linears, unsigned LinearsSize, unsigned *Modifiers, unsigned ModifiersSize, Expr * *Steps, unsigned StepsSize, SourceRange Loc = SourceRange()) {
5092 auto *A = new (Ctx) OMPDeclareSimdDeclAttr(Loc, Ctx, BranchState, Simdlen, Uniforms, UniformsSize, Aligneds, AlignedsSize, Alignments, AlignmentsSize, Linears, LinearsSize, Modifiers, ModifiersSize, Steps, StepsSize, 0);
5093 A->setImplicit(true);
5094 return A;
5095 }
5096
5097 OMPDeclareSimdDeclAttr(SourceRange R, ASTContext &Ctx
5098 , BranchStateTy BranchState
5099 , Expr * Simdlen
5100 , Expr * *Uniforms, unsigned UniformsSize
5101 , Expr * *Aligneds, unsigned AlignedsSize
5102 , Expr * *Alignments, unsigned AlignmentsSize
5103 , Expr * *Linears, unsigned LinearsSize
5104 , unsigned *Modifiers, unsigned ModifiersSize
5105 , Expr * *Steps, unsigned StepsSize
5106 , unsigned SI
5107 )
5108 : Attr(attr::OMPDeclareSimdDecl, R, SI, false)
5109 , branchState(BranchState)
5110 , simdlen(Simdlen)
5111 , uniforms_Size(UniformsSize), uniforms_(new (Ctx, 16) Expr *[uniforms_Size])
5112 , aligneds_Size(AlignedsSize), aligneds_(new (Ctx, 16) Expr *[aligneds_Size])
5113 , alignments_Size(AlignmentsSize), alignments_(new (Ctx, 16) Expr *[alignments_Size])
5114 , linears_Size(LinearsSize), linears_(new (Ctx, 16) Expr *[linears_Size])
5115 , modifiers_Size(ModifiersSize), modifiers_(new (Ctx, 16) unsigned[modifiers_Size])
5116 , steps_Size(StepsSize), steps_(new (Ctx, 16) Expr *[steps_Size])
5117 {
5118 std::copy(Uniforms, Uniforms + uniforms_Size, uniforms_);
5119 std::copy(Aligneds, Aligneds + aligneds_Size, aligneds_);
5120 std::copy(Alignments, Alignments + alignments_Size, alignments_);
5121 std::copy(Linears, Linears + linears_Size, linears_);
5122 std::copy(Modifiers, Modifiers + modifiers_Size, modifiers_);
5123 std::copy(Steps, Steps + steps_Size, steps_);
5124 }
5125
5126 OMPDeclareSimdDeclAttr(SourceRange R, ASTContext &Ctx
5127 , BranchStateTy BranchState
5128 , Expr * Simdlen
5129 , unsigned SI
5130 )
5131 : Attr(attr::OMPDeclareSimdDecl, R, SI, false)
5132 , branchState(BranchState)
5133 , simdlen(Simdlen)
5134 , uniforms_Size(0), uniforms_(nullptr)
5135 , aligneds_Size(0), aligneds_(nullptr)
5136 , alignments_Size(0), alignments_(nullptr)
5137 , linears_Size(0), linears_(nullptr)
5138 , modifiers_Size(0), modifiers_(nullptr)
5139 , steps_Size(0), steps_(nullptr)
5140 {
5141 }
5142
5143 OMPDeclareSimdDeclAttr *clone(ASTContext &C) const;
5144 void printPretty(raw_ostream &OS,
5145 const PrintingPolicy &Policy) const;
5146 const char *getSpelling() const;
5147 BranchStateTy getBranchState() const {
5148 return branchState;
5149 }
5150
5151 static bool ConvertStrToBranchStateTy(StringRef Val, BranchStateTy &Out) {
5152 Optional<BranchStateTy> R = llvm::StringSwitch<Optional<BranchStateTy>>(Val)
5153 .Case("", OMPDeclareSimdDeclAttr::BS_Undefined)
5154 .Case("inbranch", OMPDeclareSimdDeclAttr::BS_Inbranch)
5155 .Case("notinbranch", OMPDeclareSimdDeclAttr::BS_Notinbranch)
5156 .Default(Optional<BranchStateTy>());
5157 if (R) {
5158 Out = *R;
5159 return true;
5160 }
5161 return false;
5162 }
5163
5164 static const char *ConvertBranchStateTyToStr(BranchStateTy Val) {
5165 switch(Val) {
5166 case OMPDeclareSimdDeclAttr::BS_Undefined: return "";
5167 case OMPDeclareSimdDeclAttr::BS_Inbranch: return "inbranch";
5168 case OMPDeclareSimdDeclAttr::BS_Notinbranch: return "notinbranch";
5169 }
5170 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 5170)
;
5171 }
5172 Expr * getSimdlen() const {
5173 return simdlen;
5174 }
5175
5176 typedef Expr ** uniforms_iterator;
5177 uniforms_iterator uniforms_begin() const { return uniforms_; }
5178 uniforms_iterator uniforms_end() const { return uniforms_ + uniforms_Size; }
5179 unsigned uniforms_size() const { return uniforms_Size; }
5180 llvm::iterator_range<uniforms_iterator> uniforms() const { return llvm::make_range(uniforms_begin(), uniforms_end()); }
5181
5182
5183 typedef Expr ** aligneds_iterator;
5184 aligneds_iterator aligneds_begin() const { return aligneds_; }
5185 aligneds_iterator aligneds_end() const { return aligneds_ + aligneds_Size; }
5186 unsigned aligneds_size() const { return aligneds_Size; }
5187 llvm::iterator_range<aligneds_iterator> aligneds() const { return llvm::make_range(aligneds_begin(), aligneds_end()); }
5188
5189
5190 typedef Expr ** alignments_iterator;
5191 alignments_iterator alignments_begin() const { return alignments_; }
5192 alignments_iterator alignments_end() const { return alignments_ + alignments_Size; }
5193 unsigned alignments_size() const { return alignments_Size; }
5194 llvm::iterator_range<alignments_iterator> alignments() const { return llvm::make_range(alignments_begin(), alignments_end()); }
5195
5196
5197 typedef Expr ** linears_iterator;
5198 linears_iterator linears_begin() const { return linears_; }
5199 linears_iterator linears_end() const { return linears_ + linears_Size; }
5200 unsigned linears_size() const { return linears_Size; }
5201 llvm::iterator_range<linears_iterator> linears() const { return llvm::make_range(linears_begin(), linears_end()); }
5202
5203
5204 typedef unsigned* modifiers_iterator;
5205 modifiers_iterator modifiers_begin() const { return modifiers_; }
5206 modifiers_iterator modifiers_end() const { return modifiers_ + modifiers_Size; }
5207 unsigned modifiers_size() const { return modifiers_Size; }
5208 llvm::iterator_range<modifiers_iterator> modifiers() const { return llvm::make_range(modifiers_begin(), modifiers_end()); }
5209
5210
5211 typedef Expr ** steps_iterator;
5212 steps_iterator steps_begin() const { return steps_; }
5213 steps_iterator steps_end() const { return steps_ + steps_Size; }
5214 unsigned steps_size() const { return steps_Size; }
5215 llvm::iterator_range<steps_iterator> steps() const { return llvm::make_range(steps_begin(), steps_end()); }
5216
5217
5218
5219 void printPrettyPragma(raw_ostream & OS, const PrintingPolicy &Policy)
5220 const {
5221 if (getBranchState() != BS_Undefined)
5222 OS << ' ' << ConvertBranchStateTyToStr(getBranchState());
5223 if (auto *E = getSimdlen()) {
5224 OS << " simdlen(";
5225 E->printPretty(OS, nullptr, Policy);
5226 OS << ")";
5227 }
5228 if (uniforms_size() > 0) {
5229 OS << " uniform";
5230 StringRef Sep = "(";
5231 for (auto *E : uniforms()) {
5232 OS << Sep;
5233 E->printPretty(OS, nullptr, Policy);
5234 Sep = ", ";
5235 }
5236 OS << ")";
5237 }
5238 alignments_iterator NI = alignments_begin();
5239 for (auto *E : aligneds()) {
5240 OS << " aligned(";
5241 E->printPretty(OS, nullptr, Policy);
5242 if (*NI) {
5243 OS << ": ";
5244 (*NI)->printPretty(OS, nullptr, Policy);
5245 }
5246 OS << ")";
5247 ++NI;
5248 }
5249 steps_iterator I = steps_begin();
5250 modifiers_iterator MI = modifiers_begin();
5251 for (auto *E : linears()) {
5252 OS << " linear(";
5253 if (*MI != OMPC_LINEAR_unknown)
5254 OS << getOpenMPSimpleClauseTypeName(OMPC_linear, *MI) << "(";
5255 E->printPretty(OS, nullptr, Policy);
5256 if (*MI != OMPC_LINEAR_unknown)
5257 OS << ")";
5258 if (*I) {
5259 OS << ": ";
5260 (*I)->printPretty(OS, nullptr, Policy);
5261 }
5262 OS << ")";
5263 ++I;
5264 ++MI;
5265 }
5266 }
5267
5268
5269 static bool classof(const Attr *A) { return A->getKind() == attr::OMPDeclareSimdDecl; }
5270};
5271
5272class OMPDeclareTargetDeclAttr : public Attr {
5273public:
5274 enum MapTypeTy {
5275 MT_To,
5276 MT_Link
5277 };
5278private:
5279 MapTypeTy mapType;
5280
5281public:
5282 static OMPDeclareTargetDeclAttr *CreateImplicit(ASTContext &Ctx, MapTypeTy MapType, SourceRange Loc = SourceRange()) {
5283 auto *A = new (Ctx) OMPDeclareTargetDeclAttr(Loc, Ctx, MapType, 0);
5284 A->setImplicit(true);
5285 return A;
5286 }
5287
5288 OMPDeclareTargetDeclAttr(SourceRange R, ASTContext &Ctx
5289 , MapTypeTy MapType
5290 , unsigned SI
5291 )
5292 : Attr(attr::OMPDeclareTargetDecl, R, SI, false)
5293 , mapType(MapType)
5294 {
5295 }
5296
5297 OMPDeclareTargetDeclAttr *clone(ASTContext &C) const;
5298 void printPretty(raw_ostream &OS,
5299 const PrintingPolicy &Policy) const;
5300 const char *getSpelling() const;
5301 MapTypeTy getMapType() const {
5302 return mapType;
5303 }
5304
5305 static bool ConvertStrToMapTypeTy(StringRef Val, MapTypeTy &Out) {
5306 Optional<MapTypeTy> R = llvm::StringSwitch<Optional<MapTypeTy>>(Val)
5307 .Case("to", OMPDeclareTargetDeclAttr::MT_To)
5308 .Case("link", OMPDeclareTargetDeclAttr::MT_Link)
5309 .Default(Optional<MapTypeTy>());
5310 if (R) {
5311 Out = *R;
5312 return true;
5313 }
5314 return false;
5315 }
5316
5317 static const char *ConvertMapTypeTyToStr(MapTypeTy Val) {
5318 switch(Val) {
5319 case OMPDeclareTargetDeclAttr::MT_To: return "to";
5320 case OMPDeclareTargetDeclAttr::MT_Link: return "link";
5321 }
5322 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 5322)
;
5323 }
5324
5325 void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) const {
5326 // Use fake syntax because it is for testing and debugging purpose only.
5327 if (getMapType() != MT_To)
5328 OS << ' ' << ConvertMapTypeTyToStr(getMapType());
5329 }
5330
5331
5332 static bool classof(const Attr *A) { return A->getKind() == attr::OMPDeclareTargetDecl; }
5333};
5334
5335class OMPThreadPrivateDeclAttr : public InheritableAttr {
5336public:
5337 static OMPThreadPrivateDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5338 auto *A = new (Ctx) OMPThreadPrivateDeclAttr(Loc, Ctx, 0);
5339 A->setImplicit(true);
5340 return A;
5341 }
5342
5343 OMPThreadPrivateDeclAttr(SourceRange R, ASTContext &Ctx
5344 , unsigned SI
5345 )
5346 : InheritableAttr(attr::OMPThreadPrivateDecl, R, SI, false, false)
5347 {
5348 }
5349
5350 OMPThreadPrivateDeclAttr *clone(ASTContext &C) const;
5351 void printPretty(raw_ostream &OS,
5352 const PrintingPolicy &Policy) const;
5353 const char *getSpelling() const;
5354
5355
5356 static bool classof(const Attr *A) { return A->getKind() == attr::OMPThreadPrivateDecl; }
5357};
5358
5359class ObjCBoxableAttr : public Attr {
5360public:
5361 static ObjCBoxableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5362 auto *A = new (Ctx) ObjCBoxableAttr(Loc, Ctx, 0);
5363 A->setImplicit(true);
5364 return A;
5365 }
5366
5367 ObjCBoxableAttr(SourceRange R, ASTContext &Ctx
5368 , unsigned SI
5369 )
5370 : Attr(attr::ObjCBoxable, R, SI, false)
5371 {
5372 }
5373
5374 ObjCBoxableAttr *clone(ASTContext &C) const;
5375 void printPretty(raw_ostream &OS,
5376 const PrintingPolicy &Policy) const;
5377 const char *getSpelling() const;
5378
5379
5380 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBoxable; }
5381};
5382
5383class ObjCBridgeAttr : public InheritableAttr {
5384IdentifierInfo * bridgedType;
5385
5386public:
5387 static ObjCBridgeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * BridgedType, SourceRange Loc = SourceRange()) {
5388 auto *A = new (Ctx) ObjCBridgeAttr(Loc, Ctx, BridgedType, 0);
5389 A->setImplicit(true);
5390 return A;
5391 }
5392
5393 ObjCBridgeAttr(SourceRange R, ASTContext &Ctx
5394 , IdentifierInfo * BridgedType
5395 , unsigned SI
5396 )
5397 : InheritableAttr(attr::ObjCBridge, R, SI, false, false)
5398 , bridgedType(BridgedType)
5399 {
5400 }
5401
5402 ObjCBridgeAttr *clone(ASTContext &C) const;
5403 void printPretty(raw_ostream &OS,
5404 const PrintingPolicy &Policy) const;
5405 const char *getSpelling() const;
5406 IdentifierInfo * getBridgedType() const {
5407 return bridgedType;
5408 }
5409
5410
5411
5412 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridge; }
5413};
5414
5415class ObjCBridgeMutableAttr : public InheritableAttr {
5416IdentifierInfo * bridgedType;
5417
5418public:
5419 static ObjCBridgeMutableAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * BridgedType, SourceRange Loc = SourceRange()) {
5420 auto *A = new (Ctx) ObjCBridgeMutableAttr(Loc, Ctx, BridgedType, 0);
5421 A->setImplicit(true);
5422 return A;
5423 }
5424
5425 ObjCBridgeMutableAttr(SourceRange R, ASTContext &Ctx
5426 , IdentifierInfo * BridgedType
5427 , unsigned SI
5428 )
5429 : InheritableAttr(attr::ObjCBridgeMutable, R, SI, false, false)
5430 , bridgedType(BridgedType)
5431 {
5432 }
5433
5434 ObjCBridgeMutableAttr *clone(ASTContext &C) const;
5435 void printPretty(raw_ostream &OS,
5436 const PrintingPolicy &Policy) const;
5437 const char *getSpelling() const;
5438 IdentifierInfo * getBridgedType() const {
5439 return bridgedType;
5440 }
5441
5442
5443
5444 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridgeMutable; }
5445};
5446
5447class ObjCBridgeRelatedAttr : public InheritableAttr {
5448IdentifierInfo * relatedClass;
5449
5450IdentifierInfo * classMethod;
5451
5452IdentifierInfo * instanceMethod;
5453
5454public:
5455 static ObjCBridgeRelatedAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * RelatedClass, IdentifierInfo * ClassMethod, IdentifierInfo * InstanceMethod, SourceRange Loc = SourceRange()) {
5456 auto *A = new (Ctx) ObjCBridgeRelatedAttr(Loc, Ctx, RelatedClass, ClassMethod, InstanceMethod, 0);
5457 A->setImplicit(true);
5458 return A;
5459 }
5460
5461 ObjCBridgeRelatedAttr(SourceRange R, ASTContext &Ctx
5462 , IdentifierInfo * RelatedClass
5463 , IdentifierInfo * ClassMethod
5464 , IdentifierInfo * InstanceMethod
5465 , unsigned SI
5466 )
5467 : InheritableAttr(attr::ObjCBridgeRelated, R, SI, false, false)
5468 , relatedClass(RelatedClass)
5469 , classMethod(ClassMethod)
5470 , instanceMethod(InstanceMethod)
5471 {
5472 }
5473
5474 ObjCBridgeRelatedAttr(SourceRange R, ASTContext &Ctx
5475 , IdentifierInfo * RelatedClass
5476 , unsigned SI
5477 )
5478 : InheritableAttr(attr::ObjCBridgeRelated, R, SI, false, false)
5479 , relatedClass(RelatedClass)
5480 , classMethod()
5481 , instanceMethod()
5482 {
5483 }
5484
5485 ObjCBridgeRelatedAttr *clone(ASTContext &C) const;
5486 void printPretty(raw_ostream &OS,
5487 const PrintingPolicy &Policy) const;
5488 const char *getSpelling() const;
5489 IdentifierInfo * getRelatedClass() const {
5490 return relatedClass;
5491 }
5492
5493 IdentifierInfo * getClassMethod() const {
5494 return classMethod;
5495 }
5496
5497 IdentifierInfo * getInstanceMethod() const {
5498 return instanceMethod;
5499 }
5500
5501
5502
5503 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCBridgeRelated; }
5504};
5505
5506class ObjCDesignatedInitializerAttr : public Attr {
5507public:
5508 static ObjCDesignatedInitializerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5509 auto *A = new (Ctx) ObjCDesignatedInitializerAttr(Loc, Ctx, 0);
5510 A->setImplicit(true);
5511 return A;
5512 }
5513
5514 ObjCDesignatedInitializerAttr(SourceRange R, ASTContext &Ctx
5515 , unsigned SI
5516 )
5517 : Attr(attr::ObjCDesignatedInitializer, R, SI, false)
5518 {
5519 }
5520
5521 ObjCDesignatedInitializerAttr *clone(ASTContext &C) const;
5522 void printPretty(raw_ostream &OS,
5523 const PrintingPolicy &Policy) const;
5524 const char *getSpelling() const;
5525
5526
5527 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCDesignatedInitializer; }
5528};
5529
5530class ObjCExceptionAttr : public InheritableAttr {
5531public:
5532 static ObjCExceptionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5533 auto *A = new (Ctx) ObjCExceptionAttr(Loc, Ctx, 0);
5534 A->setImplicit(true);
5535 return A;
5536 }
5537
5538 ObjCExceptionAttr(SourceRange R, ASTContext &Ctx
5539 , unsigned SI
5540 )
5541 : InheritableAttr(attr::ObjCException, R, SI, false, false)
5542 {
5543 }
5544
5545 ObjCExceptionAttr *clone(ASTContext &C) const;
5546 void printPretty(raw_ostream &OS,
5547 const PrintingPolicy &Policy) const;
5548 const char *getSpelling() const;
5549
5550
5551 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCException; }
5552};
5553
5554class ObjCExplicitProtocolImplAttr : public InheritableAttr {
5555public:
5556 static ObjCExplicitProtocolImplAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5557 auto *A = new (Ctx) ObjCExplicitProtocolImplAttr(Loc, Ctx, 0);
5558 A->setImplicit(true);
5559 return A;
5560 }
5561
5562 ObjCExplicitProtocolImplAttr(SourceRange R, ASTContext &Ctx
5563 , unsigned SI
5564 )
5565 : InheritableAttr(attr::ObjCExplicitProtocolImpl, R, SI, false, false)
5566 {
5567 }
5568
5569 ObjCExplicitProtocolImplAttr *clone(ASTContext &C) const;
5570 void printPretty(raw_ostream &OS,
5571 const PrintingPolicy &Policy) const;
5572 const char *getSpelling() const;
5573
5574
5575 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCExplicitProtocolImpl; }
5576};
5577
5578class ObjCIndependentClassAttr : public InheritableAttr {
5579public:
5580 static ObjCIndependentClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5581 auto *A = new (Ctx) ObjCIndependentClassAttr(Loc, Ctx, 0);
5582 A->setImplicit(true);
5583 return A;
5584 }
5585
5586 ObjCIndependentClassAttr(SourceRange R, ASTContext &Ctx
5587 , unsigned SI
5588 )
5589 : InheritableAttr(attr::ObjCIndependentClass, R, SI, false, false)
5590 {
5591 }
5592
5593 ObjCIndependentClassAttr *clone(ASTContext &C) const;
5594 void printPretty(raw_ostream &OS,
5595 const PrintingPolicy &Policy) const;
5596 const char *getSpelling() const;
5597
5598
5599 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCIndependentClass; }
5600};
5601
5602class ObjCMethodFamilyAttr : public InheritableAttr {
5603public:
5604 enum FamilyKind {
5605 OMF_None,
5606 OMF_alloc,
5607 OMF_copy,
5608 OMF_init,
5609 OMF_mutableCopy,
5610 OMF_new
5611 };
5612private:
5613 FamilyKind family;
5614
5615public:
5616 static ObjCMethodFamilyAttr *CreateImplicit(ASTContext &Ctx, FamilyKind Family, SourceRange Loc = SourceRange()) {
5617 auto *A = new (Ctx) ObjCMethodFamilyAttr(Loc, Ctx, Family, 0);
5618 A->setImplicit(true);
5619 return A;
5620 }
5621
5622 ObjCMethodFamilyAttr(SourceRange R, ASTContext &Ctx
5623 , FamilyKind Family
5624 , unsigned SI
5625 )
5626 : InheritableAttr(attr::ObjCMethodFamily, R, SI, false, false)
5627 , family(Family)
5628 {
5629 }
5630
5631 ObjCMethodFamilyAttr *clone(ASTContext &C) const;
5632 void printPretty(raw_ostream &OS,
5633 const PrintingPolicy &Policy) const;
5634 const char *getSpelling() const;
5635 FamilyKind getFamily() const {
5636 return family;
5637 }
5638
5639 static bool ConvertStrToFamilyKind(StringRef Val, FamilyKind &Out) {
5640 Optional<FamilyKind> R = llvm::StringSwitch<Optional<FamilyKind>>(Val)
5641 .Case("none", ObjCMethodFamilyAttr::OMF_None)
5642 .Case("alloc", ObjCMethodFamilyAttr::OMF_alloc)
5643 .Case("copy", ObjCMethodFamilyAttr::OMF_copy)
5644 .Case("init", ObjCMethodFamilyAttr::OMF_init)
5645 .Case("mutableCopy", ObjCMethodFamilyAttr::OMF_mutableCopy)
5646 .Case("new", ObjCMethodFamilyAttr::OMF_new)
5647 .Default(Optional<FamilyKind>());
5648 if (R) {
5649 Out = *R;
5650 return true;
5651 }
5652 return false;
5653 }
5654
5655 static const char *ConvertFamilyKindToStr(FamilyKind Val) {
5656 switch(Val) {
5657 case ObjCMethodFamilyAttr::OMF_None: return "none";
5658 case ObjCMethodFamilyAttr::OMF_alloc: return "alloc";
5659 case ObjCMethodFamilyAttr::OMF_copy: return "copy";
5660 case ObjCMethodFamilyAttr::OMF_init: return "init";
5661 case ObjCMethodFamilyAttr::OMF_mutableCopy: return "mutableCopy";
5662 case ObjCMethodFamilyAttr::OMF_new: return "new";
5663 }
5664 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 5664)
;
5665 }
5666
5667
5668 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCMethodFamily; }
5669};
5670
5671class ObjCNSObjectAttr : public InheritableAttr {
5672public:
5673 static ObjCNSObjectAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5674 auto *A = new (Ctx) ObjCNSObjectAttr(Loc, Ctx, 0);
5675 A->setImplicit(true);
5676 return A;
5677 }
5678
5679 ObjCNSObjectAttr(SourceRange R, ASTContext &Ctx
5680 , unsigned SI
5681 )
5682 : InheritableAttr(attr::ObjCNSObject, R, SI, false, false)
5683 {
5684 }
5685
5686 ObjCNSObjectAttr *clone(ASTContext &C) const;
5687 void printPretty(raw_ostream &OS,
5688 const PrintingPolicy &Policy) const;
5689 const char *getSpelling() const;
5690
5691
5692 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCNSObject; }
5693};
5694
5695class ObjCPreciseLifetimeAttr : public InheritableAttr {
5696public:
5697 static ObjCPreciseLifetimeAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5698 auto *A = new (Ctx) ObjCPreciseLifetimeAttr(Loc, Ctx, 0);
5699 A->setImplicit(true);
5700 return A;
5701 }
5702
5703 ObjCPreciseLifetimeAttr(SourceRange R, ASTContext &Ctx
5704 , unsigned SI
5705 )
5706 : InheritableAttr(attr::ObjCPreciseLifetime, R, SI, false, false)
5707 {
5708 }
5709
5710 ObjCPreciseLifetimeAttr *clone(ASTContext &C) const;
5711 void printPretty(raw_ostream &OS,
5712 const PrintingPolicy &Policy) const;
5713 const char *getSpelling() const;
5714
5715
5716 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCPreciseLifetime; }
5717};
5718
5719class ObjCRequiresPropertyDefsAttr : public InheritableAttr {
5720public:
5721 static ObjCRequiresPropertyDefsAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5722 auto *A = new (Ctx) ObjCRequiresPropertyDefsAttr(Loc, Ctx, 0);
5723 A->setImplicit(true);
5724 return A;
5725 }
5726
5727 ObjCRequiresPropertyDefsAttr(SourceRange R, ASTContext &Ctx
5728 , unsigned SI
5729 )
5730 : InheritableAttr(attr::ObjCRequiresPropertyDefs, R, SI, false, false)
5731 {
5732 }
5733
5734 ObjCRequiresPropertyDefsAttr *clone(ASTContext &C) const;
5735 void printPretty(raw_ostream &OS,
5736 const PrintingPolicy &Policy) const;
5737 const char *getSpelling() const;
5738
5739
5740 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRequiresPropertyDefs; }
5741};
5742
5743class ObjCRequiresSuperAttr : public InheritableAttr {
5744public:
5745 static ObjCRequiresSuperAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5746 auto *A = new (Ctx) ObjCRequiresSuperAttr(Loc, Ctx, 0);
5747 A->setImplicit(true);
5748 return A;
5749 }
5750
5751 ObjCRequiresSuperAttr(SourceRange R, ASTContext &Ctx
5752 , unsigned SI
5753 )
5754 : InheritableAttr(attr::ObjCRequiresSuper, R, SI, false, false)
5755 {
5756 }
5757
5758 ObjCRequiresSuperAttr *clone(ASTContext &C) const;
5759 void printPretty(raw_ostream &OS,
5760 const PrintingPolicy &Policy) const;
5761 const char *getSpelling() const;
5762
5763
5764 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRequiresSuper; }
5765};
5766
5767class ObjCReturnsInnerPointerAttr : public InheritableAttr {
5768public:
5769 static ObjCReturnsInnerPointerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5770 auto *A = new (Ctx) ObjCReturnsInnerPointerAttr(Loc, Ctx, 0);
5771 A->setImplicit(true);
5772 return A;
5773 }
5774
5775 ObjCReturnsInnerPointerAttr(SourceRange R, ASTContext &Ctx
5776 , unsigned SI
5777 )
5778 : InheritableAttr(attr::ObjCReturnsInnerPointer, R, SI, false, false)
5779 {
5780 }
5781
5782 ObjCReturnsInnerPointerAttr *clone(ASTContext &C) const;
5783 void printPretty(raw_ostream &OS,
5784 const PrintingPolicy &Policy) const;
5785 const char *getSpelling() const;
5786
5787
5788 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCReturnsInnerPointer; }
5789};
5790
5791class ObjCRootClassAttr : public InheritableAttr {
5792public:
5793 static ObjCRootClassAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5794 auto *A = new (Ctx) ObjCRootClassAttr(Loc, Ctx, 0);
5795 A->setImplicit(true);
5796 return A;
5797 }
5798
5799 ObjCRootClassAttr(SourceRange R, ASTContext &Ctx
5800 , unsigned SI
5801 )
5802 : InheritableAttr(attr::ObjCRootClass, R, SI, false, false)
5803 {
5804 }
5805
5806 ObjCRootClassAttr *clone(ASTContext &C) const;
5807 void printPretty(raw_ostream &OS,
5808 const PrintingPolicy &Policy) const;
5809 const char *getSpelling() const;
5810
5811
5812 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRootClass; }
5813};
5814
5815class ObjCRuntimeNameAttr : public Attr {
5816unsigned metadataNameLength;
5817char *metadataName;
5818
5819public:
5820 static ObjCRuntimeNameAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef MetadataName, SourceRange Loc = SourceRange()) {
5821 auto *A = new (Ctx) ObjCRuntimeNameAttr(Loc, Ctx, MetadataName, 0);
5822 A->setImplicit(true);
5823 return A;
5824 }
5825
5826 ObjCRuntimeNameAttr(SourceRange R, ASTContext &Ctx
5827 , llvm::StringRef MetadataName
5828 , unsigned SI
5829 )
5830 : Attr(attr::ObjCRuntimeName, R, SI, false)
5831 , metadataNameLength(MetadataName.size()),metadataName(new (Ctx, 1) char[metadataNameLength])
5832 {
5833 if (!MetadataName.empty())
5834 std::memcpy(metadataName, MetadataName.data(), metadataNameLength);
5835 }
5836
5837 ObjCRuntimeNameAttr *clone(ASTContext &C) const;
5838 void printPretty(raw_ostream &OS,
5839 const PrintingPolicy &Policy) const;
5840 const char *getSpelling() const;
5841 llvm::StringRef getMetadataName() const {
5842 return llvm::StringRef(metadataName, metadataNameLength);
5843 }
5844 unsigned getMetadataNameLength() const {
5845 return metadataNameLength;
5846 }
5847 void setMetadataName(ASTContext &C, llvm::StringRef S) {
5848 metadataNameLength = S.size();
5849 this->metadataName = new (C, 1) char [metadataNameLength];
5850 if (!S.empty())
5851 std::memcpy(this->metadataName, S.data(), metadataNameLength);
5852 }
5853
5854
5855
5856 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRuntimeName; }
5857};
5858
5859class ObjCRuntimeVisibleAttr : public Attr {
5860public:
5861 static ObjCRuntimeVisibleAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5862 auto *A = new (Ctx) ObjCRuntimeVisibleAttr(Loc, Ctx, 0);
5863 A->setImplicit(true);
5864 return A;
5865 }
5866
5867 ObjCRuntimeVisibleAttr(SourceRange R, ASTContext &Ctx
5868 , unsigned SI
5869 )
5870 : Attr(attr::ObjCRuntimeVisible, R, SI, false)
5871 {
5872 }
5873
5874 ObjCRuntimeVisibleAttr *clone(ASTContext &C) const;
5875 void printPretty(raw_ostream &OS,
5876 const PrintingPolicy &Policy) const;
5877 const char *getSpelling() const;
5878
5879
5880 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCRuntimeVisible; }
5881};
5882
5883class ObjCSubclassingRestrictedAttr : public InheritableAttr {
5884public:
5885 static ObjCSubclassingRestrictedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5886 auto *A = new (Ctx) ObjCSubclassingRestrictedAttr(Loc, Ctx, 0);
5887 A->setImplicit(true);
5888 return A;
5889 }
5890
5891 ObjCSubclassingRestrictedAttr(SourceRange R, ASTContext &Ctx
5892 , unsigned SI
5893 )
5894 : InheritableAttr(attr::ObjCSubclassingRestricted, R, SI, false, false)
5895 {
5896 }
5897
5898 ObjCSubclassingRestrictedAttr *clone(ASTContext &C) const;
5899 void printPretty(raw_ostream &OS,
5900 const PrintingPolicy &Policy) const;
5901 const char *getSpelling() const;
5902
5903
5904 static bool classof(const Attr *A) { return A->getKind() == attr::ObjCSubclassingRestricted; }
5905};
5906
5907class OpenCLAccessAttr : public Attr {
5908public:
5909 enum Spelling {
5910 Keyword_read_only = 0,
5911 Keyword_write_only = 2,
5912 Keyword_read_write = 4
5913 };
5914
5915 static OpenCLAccessAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
5916 auto *A = new (Ctx) OpenCLAccessAttr(Loc, Ctx, S);
5917 A->setImplicit(true);
5918 return A;
5919 }
5920
5921 OpenCLAccessAttr(SourceRange R, ASTContext &Ctx
5922 , unsigned SI
5923 )
5924 : Attr(attr::OpenCLAccess, R, SI, false)
5925 {
5926 }
5927
5928 OpenCLAccessAttr *clone(ASTContext &C) const;
5929 void printPretty(raw_ostream &OS,
5930 const PrintingPolicy &Policy) const;
5931 const char *getSpelling() const;
5932 Spelling getSemanticSpelling() const {
5933 switch (SpellingListIndex) {
5934 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 5934)
;
5935 case 0: return Keyword_read_only;
5936 case 1: return Keyword_read_only;
5937 case 2: return Keyword_write_only;
5938 case 3: return Keyword_write_only;
5939 case 4: return Keyword_read_write;
5940 case 5: return Keyword_read_write;
5941 }
5942 }
5943 bool isReadOnly() const { return SpellingListIndex == 0 ||
5944 SpellingListIndex == 1; }
5945 bool isReadWrite() const { return SpellingListIndex == 4 ||
5946 SpellingListIndex == 5; }
5947 bool isWriteOnly() const { return SpellingListIndex == 2 ||
5948 SpellingListIndex == 3; }
5949
5950
5951 static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLAccess; }
5952};
5953
5954class OpenCLIntelReqdSubGroupSizeAttr : public InheritableAttr {
5955unsigned subGroupSize;
5956
5957public:
5958 static OpenCLIntelReqdSubGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned SubGroupSize, SourceRange Loc = SourceRange()) {
5959 auto *A = new (Ctx) OpenCLIntelReqdSubGroupSizeAttr(Loc, Ctx, SubGroupSize, 0);
5960 A->setImplicit(true);
5961 return A;
5962 }
5963
5964 OpenCLIntelReqdSubGroupSizeAttr(SourceRange R, ASTContext &Ctx
5965 , unsigned SubGroupSize
5966 , unsigned SI
5967 )
5968 : InheritableAttr(attr::OpenCLIntelReqdSubGroupSize, R, SI, false, false)
5969 , subGroupSize(SubGroupSize)
5970 {
5971 }
5972
5973 OpenCLIntelReqdSubGroupSizeAttr *clone(ASTContext &C) const;
5974 void printPretty(raw_ostream &OS,
5975 const PrintingPolicy &Policy) const;
5976 const char *getSpelling() const;
5977 unsigned getSubGroupSize() const {
5978 return subGroupSize;
5979 }
5980
5981
5982
5983 static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLIntelReqdSubGroupSize; }
5984};
5985
5986class OpenCLKernelAttr : public InheritableAttr {
5987public:
5988 static OpenCLKernelAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
5989 auto *A = new (Ctx) OpenCLKernelAttr(Loc, Ctx, 0);
5990 A->setImplicit(true);
5991 return A;
5992 }
5993
5994 OpenCLKernelAttr(SourceRange R, ASTContext &Ctx
5995 , unsigned SI
5996 )
5997 : InheritableAttr(attr::OpenCLKernel, R, SI, false, false)
5998 {
5999 }
6000
6001 OpenCLKernelAttr *clone(ASTContext &C) const;
6002 void printPretty(raw_ostream &OS,
6003 const PrintingPolicy &Policy) const;
6004 const char *getSpelling() const;
6005
6006
6007 static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLKernel; }
6008};
6009
6010class OpenCLUnrollHintAttr : public InheritableAttr {
6011unsigned unrollHint;
6012
6013public:
6014 static OpenCLUnrollHintAttr *CreateImplicit(ASTContext &Ctx, unsigned UnrollHint, SourceRange Loc = SourceRange()) {
6015 auto *A = new (Ctx) OpenCLUnrollHintAttr(Loc, Ctx, UnrollHint, 0);
6016 A->setImplicit(true);
6017 return A;
6018 }
6019
6020 OpenCLUnrollHintAttr(SourceRange R, ASTContext &Ctx
6021 , unsigned UnrollHint
6022 , unsigned SI
6023 )
6024 : InheritableAttr(attr::OpenCLUnrollHint, R, SI, false, false)
6025 , unrollHint(UnrollHint)
6026 {
6027 }
6028
6029 OpenCLUnrollHintAttr *clone(ASTContext &C) const;
6030 void printPretty(raw_ostream &OS,
6031 const PrintingPolicy &Policy) const;
6032 const char *getSpelling() const;
6033 unsigned getUnrollHint() const {
6034 return unrollHint;
6035 }
6036
6037
6038
6039 static bool classof(const Attr *A) { return A->getKind() == attr::OpenCLUnrollHint; }
6040};
6041
6042class OptimizeNoneAttr : public InheritableAttr {
6043public:
6044 static OptimizeNoneAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6045 auto *A = new (Ctx) OptimizeNoneAttr(Loc, Ctx, 0);
6046 A->setImplicit(true);
6047 return A;
6048 }
6049
6050 OptimizeNoneAttr(SourceRange R, ASTContext &Ctx
6051 , unsigned SI
6052 )
6053 : InheritableAttr(attr::OptimizeNone, R, SI, false, false)
6054 {
6055 }
6056
6057 OptimizeNoneAttr *clone(ASTContext &C) const;
6058 void printPretty(raw_ostream &OS,
6059 const PrintingPolicy &Policy) const;
6060 const char *getSpelling() const;
6061
6062
6063 static bool classof(const Attr *A) { return A->getKind() == attr::OptimizeNone; }
6064};
6065
6066class OverloadableAttr : public Attr {
6067public:
6068 static OverloadableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6069 auto *A = new (Ctx) OverloadableAttr(Loc, Ctx, 0);
6070 A->setImplicit(true);
6071 return A;
6072 }
6073
6074 OverloadableAttr(SourceRange R, ASTContext &Ctx
6075 , unsigned SI
6076 )
6077 : Attr(attr::Overloadable, R, SI, false)
6078 {
6079 }
6080
6081 OverloadableAttr *clone(ASTContext &C) const;
6082 void printPretty(raw_ostream &OS,
6083 const PrintingPolicy &Policy) const;
6084 const char *getSpelling() const;
6085
6086
6087 static bool classof(const Attr *A) { return A->getKind() == attr::Overloadable; }
6088};
6089
6090class OverrideAttr : public InheritableAttr {
6091public:
6092 static OverrideAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6093 auto *A = new (Ctx) OverrideAttr(Loc, Ctx, 0);
6094 A->setImplicit(true);
6095 return A;
6096 }
6097
6098 OverrideAttr(SourceRange R, ASTContext &Ctx
6099 , unsigned SI
6100 )
6101 : InheritableAttr(attr::Override, R, SI, false, false)
6102 {
6103 }
6104
6105 OverrideAttr *clone(ASTContext &C) const;
6106 void printPretty(raw_ostream &OS,
6107 const PrintingPolicy &Policy) const;
6108 const char *getSpelling() const;
6109
6110
6111 static bool classof(const Attr *A) { return A->getKind() == attr::Override; }
6112};
6113
6114class OwnershipAttr : public InheritableAttr {
6115IdentifierInfo * module;
6116
6117 unsigned args_Size;
6118 unsigned *args_;
6119
6120public:
6121 enum Spelling {
6122 GNU_ownership_holds = 0,
6123 CXX11_clang_ownership_holds = 1,
6124 C2x_clang_ownership_holds = 2,
6125 GNU_ownership_returns = 3,
6126 CXX11_clang_ownership_returns = 4,
6127 C2x_clang_ownership_returns = 5,
6128 GNU_ownership_takes = 6,
6129 CXX11_clang_ownership_takes = 7,
6130 C2x_clang_ownership_takes = 8
6131 };
6132
6133 static OwnershipAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * Module, unsigned *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
6134 auto *A = new (Ctx) OwnershipAttr(Loc, Ctx, Module, Args, ArgsSize, S);
6135 A->setImplicit(true);
6136 return A;
6137 }
6138
6139 OwnershipAttr(SourceRange R, ASTContext &Ctx
6140 , IdentifierInfo * Module
6141 , unsigned *Args, unsigned ArgsSize
6142 , unsigned SI
6143 )
6144 : InheritableAttr(attr::Ownership, R, SI, false, false)
6145 , module(Module)
6146 , args_Size(ArgsSize), args_(new (Ctx, 16) unsigned[args_Size])
6147 {
6148 std::copy(Args, Args + args_Size, args_);
6149 }
6150
6151 OwnershipAttr(SourceRange R, ASTContext &Ctx
6152 , IdentifierInfo * Module
6153 , unsigned SI
6154 )
6155 : InheritableAttr(attr::Ownership, R, SI, false, false)
6156 , module(Module)
6157 , args_Size(0), args_(nullptr)
6158 {
6159 }
6160
6161 OwnershipAttr *clone(ASTContext &C) const;
6162 void printPretty(raw_ostream &OS,
6163 const PrintingPolicy &Policy) const;
6164 const char *getSpelling() const;
6165 Spelling getSemanticSpelling() const {
6166 switch (SpellingListIndex) {
6167 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6167)
;
6168 case 0: return GNU_ownership_holds;
6169 case 1: return CXX11_clang_ownership_holds;
6170 case 2: return C2x_clang_ownership_holds;
6171 case 3: return GNU_ownership_returns;
6172 case 4: return CXX11_clang_ownership_returns;
6173 case 5: return C2x_clang_ownership_returns;
6174 case 6: return GNU_ownership_takes;
6175 case 7: return CXX11_clang_ownership_takes;
6176 case 8: return C2x_clang_ownership_takes;
6177 }
6178 }
6179 bool isHolds() const { return SpellingListIndex == 0 ||
6180 SpellingListIndex == 1 ||
6181 SpellingListIndex == 2; }
6182 bool isReturns() const { return SpellingListIndex == 3 ||
6183 SpellingListIndex == 4 ||
6184 SpellingListIndex == 5; }
6185 bool isTakes() const { return SpellingListIndex == 6 ||
6186 SpellingListIndex == 7 ||
6187 SpellingListIndex == 8; }
6188 IdentifierInfo * getModule() const {
6189 return module;
6190 }
6191
6192 typedef unsigned* args_iterator;
6193 args_iterator args_begin() const { return args_; }
6194 args_iterator args_end() const { return args_ + args_Size; }
6195 unsigned args_size() const { return args_Size; }
6196 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
6197
6198
6199
6200 enum OwnershipKind { Holds, Returns, Takes };
6201 OwnershipKind getOwnKind() const {
6202 return isHolds() ? Holds :
6203 isTakes() ? Takes :
6204 Returns;
6205 }
6206
6207
6208 static bool classof(const Attr *A) { return A->getKind() == attr::Ownership; }
6209};
6210
6211class PackedAttr : public InheritableAttr {
6212public:
6213 static PackedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6214 auto *A = new (Ctx) PackedAttr(Loc, Ctx, 0);
6215 A->setImplicit(true);
6216 return A;
6217 }
6218
6219 PackedAttr(SourceRange R, ASTContext &Ctx
6220 , unsigned SI
6221 )
6222 : InheritableAttr(attr::Packed, R, SI, false, false)
6223 {
6224 }
6225
6226 PackedAttr *clone(ASTContext &C) const;
6227 void printPretty(raw_ostream &OS,
6228 const PrintingPolicy &Policy) const;
6229 const char *getSpelling() const;
6230
6231
6232 static bool classof(const Attr *A) { return A->getKind() == attr::Packed; }
6233};
6234
6235class ParamTypestateAttr : public InheritableAttr {
6236public:
6237 enum ConsumedState {
6238 Unknown,
6239 Consumed,
6240 Unconsumed
6241 };
6242private:
6243 ConsumedState paramState;
6244
6245public:
6246 static ParamTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState ParamState, SourceRange Loc = SourceRange()) {
6247 auto *A = new (Ctx) ParamTypestateAttr(Loc, Ctx, ParamState, 0);
6248 A->setImplicit(true);
6249 return A;
6250 }
6251
6252 ParamTypestateAttr(SourceRange R, ASTContext &Ctx
6253 , ConsumedState ParamState
6254 , unsigned SI
6255 )
6256 : InheritableAttr(attr::ParamTypestate, R, SI, false, false)
6257 , paramState(ParamState)
6258 {
6259 }
6260
6261 ParamTypestateAttr *clone(ASTContext &C) const;
6262 void printPretty(raw_ostream &OS,
6263 const PrintingPolicy &Policy) const;
6264 const char *getSpelling() const;
6265 ConsumedState getParamState() const {
6266 return paramState;
6267 }
6268
6269 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
6270 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
6271 .Case("unknown", ParamTypestateAttr::Unknown)
6272 .Case("consumed", ParamTypestateAttr::Consumed)
6273 .Case("unconsumed", ParamTypestateAttr::Unconsumed)
6274 .Default(Optional<ConsumedState>());
6275 if (R) {
6276 Out = *R;
6277 return true;
6278 }
6279 return false;
6280 }
6281
6282 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
6283 switch(Val) {
6284 case ParamTypestateAttr::Unknown: return "unknown";
6285 case ParamTypestateAttr::Consumed: return "consumed";
6286 case ParamTypestateAttr::Unconsumed: return "unconsumed";
6287 }
6288 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6288)
;
6289 }
6290
6291
6292 static bool classof(const Attr *A) { return A->getKind() == attr::ParamTypestate; }
6293};
6294
6295class PascalAttr : public InheritableAttr {
6296public:
6297 static PascalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6298 auto *A = new (Ctx) PascalAttr(Loc, Ctx, 0);
6299 A->setImplicit(true);
6300 return A;
6301 }
6302
6303 PascalAttr(SourceRange R, ASTContext &Ctx
6304 , unsigned SI
6305 )
6306 : InheritableAttr(attr::Pascal, R, SI, false, false)
6307 {
6308 }
6309
6310 PascalAttr *clone(ASTContext &C) const;
6311 void printPretty(raw_ostream &OS,
6312 const PrintingPolicy &Policy) const;
6313 const char *getSpelling() const;
6314
6315
6316 static bool classof(const Attr *A) { return A->getKind() == attr::Pascal; }
6317};
6318
6319class PassObjectSizeAttr : public InheritableParamAttr {
6320int type;
6321
6322public:
6323 static PassObjectSizeAttr *CreateImplicit(ASTContext &Ctx, int Type, SourceRange Loc = SourceRange()) {
6324 auto *A = new (Ctx) PassObjectSizeAttr(Loc, Ctx, Type, 0);
6325 A->setImplicit(true);
6326 return A;
6327 }
6328
6329 PassObjectSizeAttr(SourceRange R, ASTContext &Ctx
6330 , int Type
6331 , unsigned SI
6332 )
6333 : InheritableParamAttr(attr::PassObjectSize, R, SI, false, false)
6334 , type(Type)
6335 {
6336 }
6337
6338 PassObjectSizeAttr *clone(ASTContext &C) const;
6339 void printPretty(raw_ostream &OS,
6340 const PrintingPolicy &Policy) const;
6341 const char *getSpelling() const;
6342 int getType() const {
6343 return type;
6344 }
6345
6346
6347
6348 static bool classof(const Attr *A) { return A->getKind() == attr::PassObjectSize; }
6349};
6350
6351class PcsAttr : public InheritableAttr {
6352public:
6353 enum PCSType {
6354 AAPCS,
6355 AAPCS_VFP
6356 };
6357private:
6358 PCSType pCS;
6359
6360public:
6361 static PcsAttr *CreateImplicit(ASTContext &Ctx, PCSType PCS, SourceRange Loc = SourceRange()) {
6362 auto *A = new (Ctx) PcsAttr(Loc, Ctx, PCS, 0);
6363 A->setImplicit(true);
6364 return A;
6365 }
6366
6367 PcsAttr(SourceRange R, ASTContext &Ctx
6368 , PCSType PCS
6369 , unsigned SI
6370 )
6371 : InheritableAttr(attr::Pcs, R, SI, false, false)
6372 , pCS(PCS)
6373 {
6374 }
6375
6376 PcsAttr *clone(ASTContext &C) const;
6377 void printPretty(raw_ostream &OS,
6378 const PrintingPolicy &Policy) const;
6379 const char *getSpelling() const;
6380 PCSType getPCS() const {
6381 return pCS;
6382 }
6383
6384 static bool ConvertStrToPCSType(StringRef Val, PCSType &Out) {
6385 Optional<PCSType> R = llvm::StringSwitch<Optional<PCSType>>(Val)
6386 .Case("aapcs", PcsAttr::AAPCS)
6387 .Case("aapcs-vfp", PcsAttr::AAPCS_VFP)
6388 .Default(Optional<PCSType>());
6389 if (R) {
6390 Out = *R;
6391 return true;
6392 }
6393 return false;
6394 }
6395
6396 static const char *ConvertPCSTypeToStr(PCSType Val) {
6397 switch(Val) {
6398 case PcsAttr::AAPCS: return "aapcs";
6399 case PcsAttr::AAPCS_VFP: return "aapcs-vfp";
6400 }
6401 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6401)
;
6402 }
6403
6404
6405 static bool classof(const Attr *A) { return A->getKind() == attr::Pcs; }
6406};
6407
6408class PragmaClangBSSSectionAttr : public InheritableAttr {
6409unsigned nameLength;
6410char *name;
6411
6412public:
6413 static PragmaClangBSSSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
6414 auto *A = new (Ctx) PragmaClangBSSSectionAttr(Loc, Ctx, Name, 0);
6415 A->setImplicit(true);
6416 return A;
6417 }
6418
6419 PragmaClangBSSSectionAttr(SourceRange R, ASTContext &Ctx
6420 , llvm::StringRef Name
6421 , unsigned SI
6422 )
6423 : InheritableAttr(attr::PragmaClangBSSSection, R, SI, false, false)
6424 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
6425 {
6426 if (!Name.empty())
6427 std::memcpy(name, Name.data(), nameLength);
6428 }
6429
6430 PragmaClangBSSSectionAttr *clone(ASTContext &C) const;
6431 void printPretty(raw_ostream &OS,
6432 const PrintingPolicy &Policy) const;
6433 const char *getSpelling() const;
6434 llvm::StringRef getName() const {
6435 return llvm::StringRef(name, nameLength);
6436 }
6437 unsigned getNameLength() const {
6438 return nameLength;
6439 }
6440 void setName(ASTContext &C, llvm::StringRef S) {
6441 nameLength = S.size();
6442 this->name = new (C, 1) char [nameLength];
6443 if (!S.empty())
6444 std::memcpy(this->name, S.data(), nameLength);
6445 }
6446
6447
6448
6449 static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangBSSSection; }
6450};
6451
6452class PragmaClangDataSectionAttr : public InheritableAttr {
6453unsigned nameLength;
6454char *name;
6455
6456public:
6457 static PragmaClangDataSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
6458 auto *A = new (Ctx) PragmaClangDataSectionAttr(Loc, Ctx, Name, 0);
6459 A->setImplicit(true);
6460 return A;
6461 }
6462
6463 PragmaClangDataSectionAttr(SourceRange R, ASTContext &Ctx
6464 , llvm::StringRef Name
6465 , unsigned SI
6466 )
6467 : InheritableAttr(attr::PragmaClangDataSection, R, SI, false, false)
6468 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
6469 {
6470 if (!Name.empty())
6471 std::memcpy(name, Name.data(), nameLength);
6472 }
6473
6474 PragmaClangDataSectionAttr *clone(ASTContext &C) const;
6475 void printPretty(raw_ostream &OS,
6476 const PrintingPolicy &Policy) const;
6477 const char *getSpelling() const;
6478 llvm::StringRef getName() const {
6479 return llvm::StringRef(name, nameLength);
6480 }
6481 unsigned getNameLength() const {
6482 return nameLength;
6483 }
6484 void setName(ASTContext &C, llvm::StringRef S) {
6485 nameLength = S.size();
6486 this->name = new (C, 1) char [nameLength];
6487 if (!S.empty())
6488 std::memcpy(this->name, S.data(), nameLength);
6489 }
6490
6491
6492
6493 static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangDataSection; }
6494};
6495
6496class PragmaClangRodataSectionAttr : public InheritableAttr {
6497unsigned nameLength;
6498char *name;
6499
6500public:
6501 static PragmaClangRodataSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
6502 auto *A = new (Ctx) PragmaClangRodataSectionAttr(Loc, Ctx, Name, 0);
6503 A->setImplicit(true);
6504 return A;
6505 }
6506
6507 PragmaClangRodataSectionAttr(SourceRange R, ASTContext &Ctx
6508 , llvm::StringRef Name
6509 , unsigned SI
6510 )
6511 : InheritableAttr(attr::PragmaClangRodataSection, R, SI, false, false)
6512 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
6513 {
6514 if (!Name.empty())
6515 std::memcpy(name, Name.data(), nameLength);
6516 }
6517
6518 PragmaClangRodataSectionAttr *clone(ASTContext &C) const;
6519 void printPretty(raw_ostream &OS,
6520 const PrintingPolicy &Policy) const;
6521 const char *getSpelling() const;
6522 llvm::StringRef getName() const {
6523 return llvm::StringRef(name, nameLength);
6524 }
6525 unsigned getNameLength() const {
6526 return nameLength;
6527 }
6528 void setName(ASTContext &C, llvm::StringRef S) {
6529 nameLength = S.size();
6530 this->name = new (C, 1) char [nameLength];
6531 if (!S.empty())
6532 std::memcpy(this->name, S.data(), nameLength);
6533 }
6534
6535
6536
6537 static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangRodataSection; }
6538};
6539
6540class PragmaClangTextSectionAttr : public InheritableAttr {
6541unsigned nameLength;
6542char *name;
6543
6544public:
6545 static PragmaClangTextSectionAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
6546 auto *A = new (Ctx) PragmaClangTextSectionAttr(Loc, Ctx, Name, 0);
6547 A->setImplicit(true);
6548 return A;
6549 }
6550
6551 PragmaClangTextSectionAttr(SourceRange R, ASTContext &Ctx
6552 , llvm::StringRef Name
6553 , unsigned SI
6554 )
6555 : InheritableAttr(attr::PragmaClangTextSection, R, SI, false, false)
6556 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
6557 {
6558 if (!Name.empty())
6559 std::memcpy(name, Name.data(), nameLength);
6560 }
6561
6562 PragmaClangTextSectionAttr *clone(ASTContext &C) const;
6563 void printPretty(raw_ostream &OS,
6564 const PrintingPolicy &Policy) const;
6565 const char *getSpelling() const;
6566 llvm::StringRef getName() const {
6567 return llvm::StringRef(name, nameLength);
6568 }
6569 unsigned getNameLength() const {
6570 return nameLength;
6571 }
6572 void setName(ASTContext &C, llvm::StringRef S) {
6573 nameLength = S.size();
6574 this->name = new (C, 1) char [nameLength];
6575 if (!S.empty())
6576 std::memcpy(this->name, S.data(), nameLength);
6577 }
6578
6579
6580
6581 static bool classof(const Attr *A) { return A->getKind() == attr::PragmaClangTextSection; }
6582};
6583
6584class PreserveAllAttr : public InheritableAttr {
6585public:
6586 static PreserveAllAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6587 auto *A = new (Ctx) PreserveAllAttr(Loc, Ctx, 0);
6588 A->setImplicit(true);
6589 return A;
6590 }
6591
6592 PreserveAllAttr(SourceRange R, ASTContext &Ctx
6593 , unsigned SI
6594 )
6595 : InheritableAttr(attr::PreserveAll, R, SI, false, false)
6596 {
6597 }
6598
6599 PreserveAllAttr *clone(ASTContext &C) const;
6600 void printPretty(raw_ostream &OS,
6601 const PrintingPolicy &Policy) const;
6602 const char *getSpelling() const;
6603
6604
6605 static bool classof(const Attr *A) { return A->getKind() == attr::PreserveAll; }
6606};
6607
6608class PreserveMostAttr : public InheritableAttr {
6609public:
6610 static PreserveMostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6611 auto *A = new (Ctx) PreserveMostAttr(Loc, Ctx, 0);
6612 A->setImplicit(true);
6613 return A;
6614 }
6615
6616 PreserveMostAttr(SourceRange R, ASTContext &Ctx
6617 , unsigned SI
6618 )
6619 : InheritableAttr(attr::PreserveMost, R, SI, false, false)
6620 {
6621 }
6622
6623 PreserveMostAttr *clone(ASTContext &C) const;
6624 void printPretty(raw_ostream &OS,
6625 const PrintingPolicy &Policy) const;
6626 const char *getSpelling() const;
6627
6628
6629 static bool classof(const Attr *A) { return A->getKind() == attr::PreserveMost; }
6630};
6631
6632class PtGuardedByAttr : public InheritableAttr {
6633Expr * arg;
6634
6635public:
6636 static PtGuardedByAttr *CreateImplicit(ASTContext &Ctx, Expr * Arg, SourceRange Loc = SourceRange()) {
6637 auto *A = new (Ctx) PtGuardedByAttr(Loc, Ctx, Arg, 0);
6638 A->setImplicit(true);
6639 return A;
6640 }
6641
6642 PtGuardedByAttr(SourceRange R, ASTContext &Ctx
6643 , Expr * Arg
6644 , unsigned SI
6645 )
6646 : InheritableAttr(attr::PtGuardedBy, R, SI, true, true)
6647 , arg(Arg)
6648 {
6649 }
6650
6651 PtGuardedByAttr *clone(ASTContext &C) const;
6652 void printPretty(raw_ostream &OS,
6653 const PrintingPolicy &Policy) const;
6654 const char *getSpelling() const;
6655 Expr * getArg() const {
6656 return arg;
6657 }
6658
6659
6660
6661 static bool classof(const Attr *A) { return A->getKind() == attr::PtGuardedBy; }
6662};
6663
6664class PtGuardedVarAttr : public InheritableAttr {
6665public:
6666 static PtGuardedVarAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6667 auto *A = new (Ctx) PtGuardedVarAttr(Loc, Ctx, 0);
6668 A->setImplicit(true);
6669 return A;
6670 }
6671
6672 PtGuardedVarAttr(SourceRange R, ASTContext &Ctx
6673 , unsigned SI
6674 )
6675 : InheritableAttr(attr::PtGuardedVar, R, SI, false, false)
6676 {
6677 }
6678
6679 PtGuardedVarAttr *clone(ASTContext &C) const;
6680 void printPretty(raw_ostream &OS,
6681 const PrintingPolicy &Policy) const;
6682 const char *getSpelling() const;
6683
6684
6685 static bool classof(const Attr *A) { return A->getKind() == attr::PtGuardedVar; }
6686};
6687
6688class PureAttr : public InheritableAttr {
6689public:
6690 static PureAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6691 auto *A = new (Ctx) PureAttr(Loc, Ctx, 0);
6692 A->setImplicit(true);
6693 return A;
6694 }
6695
6696 PureAttr(SourceRange R, ASTContext &Ctx
6697 , unsigned SI
6698 )
6699 : InheritableAttr(attr::Pure, R, SI, false, false)
6700 {
6701 }
6702
6703 PureAttr *clone(ASTContext &C) const;
6704 void printPretty(raw_ostream &OS,
6705 const PrintingPolicy &Policy) const;
6706 const char *getSpelling() const;
6707
6708
6709 static bool classof(const Attr *A) { return A->getKind() == attr::Pure; }
6710};
6711
6712class RegCallAttr : public InheritableAttr {
6713public:
6714 static RegCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6715 auto *A = new (Ctx) RegCallAttr(Loc, Ctx, 0);
6716 A->setImplicit(true);
6717 return A;
6718 }
6719
6720 RegCallAttr(SourceRange R, ASTContext &Ctx
6721 , unsigned SI
6722 )
6723 : InheritableAttr(attr::RegCall, R, SI, false, false)
6724 {
6725 }
6726
6727 RegCallAttr *clone(ASTContext &C) const;
6728 void printPretty(raw_ostream &OS,
6729 const PrintingPolicy &Policy) const;
6730 const char *getSpelling() const;
6731
6732
6733 static bool classof(const Attr *A) { return A->getKind() == attr::RegCall; }
6734};
6735
6736class ReleaseCapabilityAttr : public InheritableAttr {
6737 unsigned args_Size;
6738 Expr * *args_;
6739
6740public:
6741 enum Spelling {
6742 GNU_release_capability = 0,
6743 CXX11_clang_release_capability = 1,
6744 GNU_release_shared_capability = 2,
6745 CXX11_clang_release_shared_capability = 3,
6746 GNU_release_generic_capability = 4,
6747 CXX11_clang_release_generic_capability = 5,
6748 GNU_unlock_function = 6,
6749 CXX11_clang_unlock_function = 7
6750 };
6751
6752 static ReleaseCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
6753 auto *A = new (Ctx) ReleaseCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
6754 A->setImplicit(true);
6755 return A;
6756 }
6757
6758 ReleaseCapabilityAttr(SourceRange R, ASTContext &Ctx
6759 , Expr * *Args, unsigned ArgsSize
6760 , unsigned SI
6761 )
6762 : InheritableAttr(attr::ReleaseCapability, R, SI, true, true)
6763 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
6764 {
6765 std::copy(Args, Args + args_Size, args_);
6766 }
6767
6768 ReleaseCapabilityAttr(SourceRange R, ASTContext &Ctx
6769 , unsigned SI
6770 )
6771 : InheritableAttr(attr::ReleaseCapability, R, SI, true, true)
6772 , args_Size(0), args_(nullptr)
6773 {
6774 }
6775
6776 ReleaseCapabilityAttr *clone(ASTContext &C) const;
6777 void printPretty(raw_ostream &OS,
6778 const PrintingPolicy &Policy) const;
6779 const char *getSpelling() const;
6780 Spelling getSemanticSpelling() const {
6781 switch (SpellingListIndex) {
6782 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6782)
;
6783 case 0: return GNU_release_capability;
6784 case 1: return CXX11_clang_release_capability;
6785 case 2: return GNU_release_shared_capability;
6786 case 3: return CXX11_clang_release_shared_capability;
6787 case 4: return GNU_release_generic_capability;
6788 case 5: return CXX11_clang_release_generic_capability;
6789 case 6: return GNU_unlock_function;
6790 case 7: return CXX11_clang_unlock_function;
6791 }
6792 }
6793 bool isShared() const { return SpellingListIndex == 2 ||
6794 SpellingListIndex == 3; }
6795 bool isGeneric() const { return SpellingListIndex == 4 ||
6796 SpellingListIndex == 5 ||
6797 SpellingListIndex == 6 ||
6798 SpellingListIndex == 7; }
6799 typedef Expr ** args_iterator;
6800 args_iterator args_begin() const { return args_; }
6801 args_iterator args_end() const { return args_ + args_Size; }
6802 unsigned args_size() const { return args_Size; }
6803 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
6804
6805
6806
6807
6808 static bool classof(const Attr *A) { return A->getKind() == attr::ReleaseCapability; }
6809};
6810
6811class RenderScriptKernelAttr : public Attr {
6812public:
6813 static RenderScriptKernelAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6814 auto *A = new (Ctx) RenderScriptKernelAttr(Loc, Ctx, 0);
6815 A->setImplicit(true);
6816 return A;
6817 }
6818
6819 RenderScriptKernelAttr(SourceRange R, ASTContext &Ctx
6820 , unsigned SI
6821 )
6822 : Attr(attr::RenderScriptKernel, R, SI, false)
6823 {
6824 }
6825
6826 RenderScriptKernelAttr *clone(ASTContext &C) const;
6827 void printPretty(raw_ostream &OS,
6828 const PrintingPolicy &Policy) const;
6829 const char *getSpelling() const;
6830
6831
6832 static bool classof(const Attr *A) { return A->getKind() == attr::RenderScriptKernel; }
6833};
6834
6835class ReqdWorkGroupSizeAttr : public InheritableAttr {
6836unsigned xDim;
6837
6838unsigned yDim;
6839
6840unsigned zDim;
6841
6842public:
6843 static ReqdWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned XDim, unsigned YDim, unsigned ZDim, SourceRange Loc = SourceRange()) {
6844 auto *A = new (Ctx) ReqdWorkGroupSizeAttr(Loc, Ctx, XDim, YDim, ZDim, 0);
6845 A->setImplicit(true);
6846 return A;
6847 }
6848
6849 ReqdWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx
6850 , unsigned XDim
6851 , unsigned YDim
6852 , unsigned ZDim
6853 , unsigned SI
6854 )
6855 : InheritableAttr(attr::ReqdWorkGroupSize, R, SI, false, false)
6856 , xDim(XDim)
6857 , yDim(YDim)
6858 , zDim(ZDim)
6859 {
6860 }
6861
6862 ReqdWorkGroupSizeAttr *clone(ASTContext &C) const;
6863 void printPretty(raw_ostream &OS,
6864 const PrintingPolicy &Policy) const;
6865 const char *getSpelling() const;
6866 unsigned getXDim() const {
6867 return xDim;
6868 }
6869
6870 unsigned getYDim() const {
6871 return yDim;
6872 }
6873
6874 unsigned getZDim() const {
6875 return zDim;
6876 }
6877
6878
6879
6880 static bool classof(const Attr *A) { return A->getKind() == attr::ReqdWorkGroupSize; }
6881};
6882
6883class RequireConstantInitAttr : public InheritableAttr {
6884public:
6885 static RequireConstantInitAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
6886 auto *A = new (Ctx) RequireConstantInitAttr(Loc, Ctx, 0);
6887 A->setImplicit(true);
6888 return A;
6889 }
6890
6891 RequireConstantInitAttr(SourceRange R, ASTContext &Ctx
6892 , unsigned SI
6893 )
6894 : InheritableAttr(attr::RequireConstantInit, R, SI, false, false)
6895 {
6896 }
6897
6898 RequireConstantInitAttr *clone(ASTContext &C) const;
6899 void printPretty(raw_ostream &OS,
6900 const PrintingPolicy &Policy) const;
6901 const char *getSpelling() const;
6902
6903
6904 static bool classof(const Attr *A) { return A->getKind() == attr::RequireConstantInit; }
6905};
6906
6907class RequiresCapabilityAttr : public InheritableAttr {
6908 unsigned args_Size;
6909 Expr * *args_;
6910
6911public:
6912 enum Spelling {
6913 GNU_requires_capability = 0,
6914 CXX11_clang_requires_capability = 1,
6915 GNU_exclusive_locks_required = 2,
6916 CXX11_clang_exclusive_locks_required = 3,
6917 GNU_requires_shared_capability = 4,
6918 CXX11_clang_requires_shared_capability = 5,
6919 GNU_shared_locks_required = 6,
6920 CXX11_clang_shared_locks_required = 7
6921 };
6922
6923 static RequiresCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
6924 auto *A = new (Ctx) RequiresCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
6925 A->setImplicit(true);
6926 return A;
6927 }
6928
6929 RequiresCapabilityAttr(SourceRange R, ASTContext &Ctx
6930 , Expr * *Args, unsigned ArgsSize
6931 , unsigned SI
6932 )
6933 : InheritableAttr(attr::RequiresCapability, R, SI, true, true)
6934 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
6935 {
6936 std::copy(Args, Args + args_Size, args_);
6937 }
6938
6939 RequiresCapabilityAttr(SourceRange R, ASTContext &Ctx
6940 , unsigned SI
6941 )
6942 : InheritableAttr(attr::RequiresCapability, R, SI, true, true)
6943 , args_Size(0), args_(nullptr)
6944 {
6945 }
6946
6947 RequiresCapabilityAttr *clone(ASTContext &C) const;
6948 void printPretty(raw_ostream &OS,
6949 const PrintingPolicy &Policy) const;
6950 const char *getSpelling() const;
6951 Spelling getSemanticSpelling() const {
6952 switch (SpellingListIndex) {
6953 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 6953)
;
6954 case 0: return GNU_requires_capability;
6955 case 1: return CXX11_clang_requires_capability;
6956 case 2: return GNU_exclusive_locks_required;
6957 case 3: return CXX11_clang_exclusive_locks_required;
6958 case 4: return GNU_requires_shared_capability;
6959 case 5: return CXX11_clang_requires_shared_capability;
6960 case 6: return GNU_shared_locks_required;
6961 case 7: return CXX11_clang_shared_locks_required;
6962 }
6963 }
6964 bool isShared() const { return SpellingListIndex == 4 ||
6965 SpellingListIndex == 5 ||
6966 SpellingListIndex == 6 ||
6967 SpellingListIndex == 7; }
6968 typedef Expr ** args_iterator;
6969 args_iterator args_begin() const { return args_; }
6970 args_iterator args_end() const { return args_ + args_Size; }
6971 unsigned args_size() const { return args_Size; }
6972 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
6973
6974
6975
6976
6977 static bool classof(const Attr *A) { return A->getKind() == attr::RequiresCapability; }
6978};
6979
6980class RestrictAttr : public InheritableAttr {
6981public:
6982 enum Spelling {
6983 Declspec_restrict = 0,
6984 GNU_malloc = 1,
6985 CXX11_gnu_malloc = 2
6986 };
6987
6988 static RestrictAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
6989 auto *A = new (Ctx) RestrictAttr(Loc, Ctx, S);
6990 A->setImplicit(true);
6991 return A;
6992 }
6993
6994 RestrictAttr(SourceRange R, ASTContext &Ctx
6995 , unsigned SI
6996 )
6997 : InheritableAttr(attr::Restrict, R, SI, false, false)
6998 {
6999 }
7000
7001 RestrictAttr *clone(ASTContext &C) const;
7002 void printPretty(raw_ostream &OS,
7003 const PrintingPolicy &Policy) const;
7004 const char *getSpelling() const;
7005 Spelling getSemanticSpelling() const {
7006 switch (SpellingListIndex) {
7007 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7007)
;
7008 case 0: return Declspec_restrict;
7009 case 1: return GNU_malloc;
7010 case 2: return CXX11_gnu_malloc;
7011 }
7012 }
7013
7014
7015 static bool classof(const Attr *A) { return A->getKind() == attr::Restrict; }
7016};
7017
7018class ReturnTypestateAttr : public InheritableAttr {
7019public:
7020 enum ConsumedState {
7021 Unknown,
7022 Consumed,
7023 Unconsumed
7024 };
7025private:
7026 ConsumedState state;
7027
7028public:
7029 static ReturnTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState State, SourceRange Loc = SourceRange()) {
7030 auto *A = new (Ctx) ReturnTypestateAttr(Loc, Ctx, State, 0);
7031 A->setImplicit(true);
7032 return A;
7033 }
7034
7035 ReturnTypestateAttr(SourceRange R, ASTContext &Ctx
7036 , ConsumedState State
7037 , unsigned SI
7038 )
7039 : InheritableAttr(attr::ReturnTypestate, R, SI, false, false)
7040 , state(State)
7041 {
7042 }
7043
7044 ReturnTypestateAttr *clone(ASTContext &C) const;
7045 void printPretty(raw_ostream &OS,
7046 const PrintingPolicy &Policy) const;
7047 const char *getSpelling() const;
7048 ConsumedState getState() const {
7049 return state;
7050 }
7051
7052 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
7053 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
7054 .Case("unknown", ReturnTypestateAttr::Unknown)
7055 .Case("consumed", ReturnTypestateAttr::Consumed)
7056 .Case("unconsumed", ReturnTypestateAttr::Unconsumed)
7057 .Default(Optional<ConsumedState>());
7058 if (R) {
7059 Out = *R;
7060 return true;
7061 }
7062 return false;
7063 }
7064
7065 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
7066 switch(Val) {
7067 case ReturnTypestateAttr::Unknown: return "unknown";
7068 case ReturnTypestateAttr::Consumed: return "consumed";
7069 case ReturnTypestateAttr::Unconsumed: return "unconsumed";
7070 }
7071 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7071)
;
7072 }
7073
7074
7075 static bool classof(const Attr *A) { return A->getKind() == attr::ReturnTypestate; }
7076};
7077
7078class ReturnsNonNullAttr : public InheritableAttr {
7079public:
7080 static ReturnsNonNullAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7081 auto *A = new (Ctx) ReturnsNonNullAttr(Loc, Ctx, 0);
7082 A->setImplicit(true);
7083 return A;
7084 }
7085
7086 ReturnsNonNullAttr(SourceRange R, ASTContext &Ctx
7087 , unsigned SI
7088 )
7089 : InheritableAttr(attr::ReturnsNonNull, R, SI, false, false)
7090 {
7091 }
7092
7093 ReturnsNonNullAttr *clone(ASTContext &C) const;
7094 void printPretty(raw_ostream &OS,
7095 const PrintingPolicy &Policy) const;
7096 const char *getSpelling() const;
7097
7098
7099 static bool classof(const Attr *A) { return A->getKind() == attr::ReturnsNonNull; }
7100};
7101
7102class ReturnsTwiceAttr : public InheritableAttr {
7103public:
7104 static ReturnsTwiceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7105 auto *A = new (Ctx) ReturnsTwiceAttr(Loc, Ctx, 0);
7106 A->setImplicit(true);
7107 return A;
7108 }
7109
7110 ReturnsTwiceAttr(SourceRange R, ASTContext &Ctx
7111 , unsigned SI
7112 )
7113 : InheritableAttr(attr::ReturnsTwice, R, SI, false, false)
7114 {
7115 }
7116
7117 ReturnsTwiceAttr *clone(ASTContext &C) const;
7118 void printPretty(raw_ostream &OS,
7119 const PrintingPolicy &Policy) const;
7120 const char *getSpelling() const;
7121
7122
7123 static bool classof(const Attr *A) { return A->getKind() == attr::ReturnsTwice; }
7124};
7125
7126class ScopedLockableAttr : public InheritableAttr {
7127public:
7128 static ScopedLockableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7129 auto *A = new (Ctx) ScopedLockableAttr(Loc, Ctx, 0);
7130 A->setImplicit(true);
7131 return A;
7132 }
7133
7134 ScopedLockableAttr(SourceRange R, ASTContext &Ctx
7135 , unsigned SI
7136 )
7137 : InheritableAttr(attr::ScopedLockable, R, SI, false, false)
7138 {
7139 }
7140
7141 ScopedLockableAttr *clone(ASTContext &C) const;
7142 void printPretty(raw_ostream &OS,
7143 const PrintingPolicy &Policy) const;
7144 const char *getSpelling() const;
7145
7146
7147 static bool classof(const Attr *A) { return A->getKind() == attr::ScopedLockable; }
7148};
7149
7150class SectionAttr : public InheritableAttr {
7151unsigned nameLength;
7152char *name;
7153
7154public:
7155 enum Spelling {
7156 GNU_section = 0,
7157 CXX11_gnu_section = 1,
7158 Declspec_allocate = 2
7159 };
7160
7161 static SectionAttr *CreateImplicit(ASTContext &Ctx, Spelling S, llvm::StringRef Name, SourceRange Loc = SourceRange()) {
7162 auto *A = new (Ctx) SectionAttr(Loc, Ctx, Name, S);
7163 A->setImplicit(true);
7164 return A;
7165 }
7166
7167 SectionAttr(SourceRange R, ASTContext &Ctx
7168 , llvm::StringRef Name
7169 , unsigned SI
7170 )
7171 : InheritableAttr(attr::Section, R, SI, false, false)
7172 , nameLength(Name.size()),name(new (Ctx, 1) char[nameLength])
7173 {
7174 if (!Name.empty())
7175 std::memcpy(name, Name.data(), nameLength);
7176 }
7177
7178 SectionAttr *clone(ASTContext &C) const;
7179 void printPretty(raw_ostream &OS,
7180 const PrintingPolicy &Policy) const;
7181 const char *getSpelling() const;
7182 Spelling getSemanticSpelling() const {
7183 switch (SpellingListIndex) {
7184 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7184)
;
7185 case 0: return GNU_section;
7186 case 1: return CXX11_gnu_section;
7187 case 2: return Declspec_allocate;
7188 }
7189 }
7190 llvm::StringRef getName() const {
7191 return llvm::StringRef(name, nameLength);
7192 }
7193 unsigned getNameLength() const {
7194 return nameLength;
7195 }
7196 void setName(ASTContext &C, llvm::StringRef S) {
7197 nameLength = S.size();
7198 this->name = new (C, 1) char [nameLength];
7199 if (!S.empty())
7200 std::memcpy(this->name, S.data(), nameLength);
7201 }
7202
7203
7204
7205 static bool classof(const Attr *A) { return A->getKind() == attr::Section; }
7206};
7207
7208class SelectAnyAttr : public InheritableAttr {
7209public:
7210 static SelectAnyAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7211 auto *A = new (Ctx) SelectAnyAttr(Loc, Ctx, 0);
7212 A->setImplicit(true);
7213 return A;
7214 }
7215
7216 SelectAnyAttr(SourceRange R, ASTContext &Ctx
7217 , unsigned SI
7218 )
7219 : InheritableAttr(attr::SelectAny, R, SI, false, false)
7220 {
7221 }
7222
7223 SelectAnyAttr *clone(ASTContext &C) const;
7224 void printPretty(raw_ostream &OS,
7225 const PrintingPolicy &Policy) const;
7226 const char *getSpelling() const;
7227
7228
7229 static bool classof(const Attr *A) { return A->getKind() == attr::SelectAny; }
7230};
7231
7232class SentinelAttr : public InheritableAttr {
7233int sentinel;
7234
7235int nullPos;
7236
7237public:
7238 static SentinelAttr *CreateImplicit(ASTContext &Ctx, int Sentinel, int NullPos, SourceRange Loc = SourceRange()) {
7239 auto *A = new (Ctx) SentinelAttr(Loc, Ctx, Sentinel, NullPos, 0);
7240 A->setImplicit(true);
7241 return A;
7242 }
7243
7244 SentinelAttr(SourceRange R, ASTContext &Ctx
7245 , int Sentinel
7246 , int NullPos
7247 , unsigned SI
7248 )
7249 : InheritableAttr(attr::Sentinel, R, SI, false, false)
7250 , sentinel(Sentinel)
7251 , nullPos(NullPos)
7252 {
7253 }
7254
7255 SentinelAttr(SourceRange R, ASTContext &Ctx
7256 , unsigned SI
7257 )
7258 : InheritableAttr(attr::Sentinel, R, SI, false, false)
7259 , sentinel()
7260 , nullPos()
7261 {
7262 }
7263
7264 SentinelAttr *clone(ASTContext &C) const;
7265 void printPretty(raw_ostream &OS,
7266 const PrintingPolicy &Policy) const;
7267 const char *getSpelling() const;
7268 int getSentinel() const {
7269 return sentinel;
7270 }
7271
7272 static const int DefaultSentinel = 0;
7273
7274 int getNullPos() const {
7275 return nullPos;
7276 }
7277
7278 static const int DefaultNullPos = 0;
7279
7280
7281
7282 static bool classof(const Attr *A) { return A->getKind() == attr::Sentinel; }
7283};
7284
7285class SetTypestateAttr : public InheritableAttr {
7286public:
7287 enum ConsumedState {
7288 Unknown,
7289 Consumed,
7290 Unconsumed
7291 };
7292private:
7293 ConsumedState newState;
7294
7295public:
7296 static SetTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState NewState, SourceRange Loc = SourceRange()) {
7297 auto *A = new (Ctx) SetTypestateAttr(Loc, Ctx, NewState, 0);
7298 A->setImplicit(true);
7299 return A;
7300 }
7301
7302 SetTypestateAttr(SourceRange R, ASTContext &Ctx
7303 , ConsumedState NewState
7304 , unsigned SI
7305 )
7306 : InheritableAttr(attr::SetTypestate, R, SI, false, false)
7307 , newState(NewState)
7308 {
7309 }
7310
7311 SetTypestateAttr *clone(ASTContext &C) const;
7312 void printPretty(raw_ostream &OS,
7313 const PrintingPolicy &Policy) const;
7314 const char *getSpelling() const;
7315 ConsumedState getNewState() const {
7316 return newState;
7317 }
7318
7319 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
7320 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
7321 .Case("unknown", SetTypestateAttr::Unknown)
7322 .Case("consumed", SetTypestateAttr::Consumed)
7323 .Case("unconsumed", SetTypestateAttr::Unconsumed)
7324 .Default(Optional<ConsumedState>());
7325 if (R) {
7326 Out = *R;
7327 return true;
7328 }
7329 return false;
7330 }
7331
7332 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
7333 switch(Val) {
7334 case SetTypestateAttr::Unknown: return "unknown";
7335 case SetTypestateAttr::Consumed: return "consumed";
7336 case SetTypestateAttr::Unconsumed: return "unconsumed";
7337 }
7338 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7338)
;
7339 }
7340
7341
7342 static bool classof(const Attr *A) { return A->getKind() == attr::SetTypestate; }
7343};
7344
7345class SharedTrylockFunctionAttr : public InheritableAttr {
7346Expr * successValue;
7347
7348 unsigned args_Size;
7349 Expr * *args_;
7350
7351public:
7352 static SharedTrylockFunctionAttr *CreateImplicit(ASTContext &Ctx, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
7353 auto *A = new (Ctx) SharedTrylockFunctionAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, 0);
7354 A->setImplicit(true);
7355 return A;
7356 }
7357
7358 SharedTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
7359 , Expr * SuccessValue
7360 , Expr * *Args, unsigned ArgsSize
7361 , unsigned SI
7362 )
7363 : InheritableAttr(attr::SharedTrylockFunction, R, SI, true, true)
7364 , successValue(SuccessValue)
7365 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
7366 {
7367 std::copy(Args, Args + args_Size, args_);
7368 }
7369
7370 SharedTrylockFunctionAttr(SourceRange R, ASTContext &Ctx
7371 , Expr * SuccessValue
7372 , unsigned SI
7373 )
7374 : InheritableAttr(attr::SharedTrylockFunction, R, SI, true, true)
7375 , successValue(SuccessValue)
7376 , args_Size(0), args_(nullptr)
7377 {
7378 }
7379
7380 SharedTrylockFunctionAttr *clone(ASTContext &C) const;
7381 void printPretty(raw_ostream &OS,
7382 const PrintingPolicy &Policy) const;
7383 const char *getSpelling() const;
7384 Expr * getSuccessValue() const {
7385 return successValue;
7386 }
7387
7388 typedef Expr ** args_iterator;
7389 args_iterator args_begin() const { return args_; }
7390 args_iterator args_end() const { return args_ + args_Size; }
7391 unsigned args_size() const { return args_Size; }
7392 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
7393
7394
7395
7396
7397 static bool classof(const Attr *A) { return A->getKind() == attr::SharedTrylockFunction; }
7398};
7399
7400class StdCallAttr : public InheritableAttr {
7401public:
7402 static StdCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7403 auto *A = new (Ctx) StdCallAttr(Loc, Ctx, 0);
7404 A->setImplicit(true);
7405 return A;
7406 }
7407
7408 StdCallAttr(SourceRange R, ASTContext &Ctx
7409 , unsigned SI
7410 )
7411 : InheritableAttr(attr::StdCall, R, SI, false, false)
7412 {
7413 }
7414
7415 StdCallAttr *clone(ASTContext &C) const;
7416 void printPretty(raw_ostream &OS,
7417 const PrintingPolicy &Policy) const;
7418 const char *getSpelling() const;
7419
7420
7421 static bool classof(const Attr *A) { return A->getKind() == attr::StdCall; }
7422};
7423
7424class SuppressAttr : public StmtAttr {
7425 unsigned diagnosticIdentifiers_Size;
7426 StringRef *diagnosticIdentifiers_;
7427
7428public:
7429 static SuppressAttr *CreateImplicit(ASTContext &Ctx, StringRef *DiagnosticIdentifiers, unsigned DiagnosticIdentifiersSize, SourceRange Loc = SourceRange()) {
7430 auto *A = new (Ctx) SuppressAttr(Loc, Ctx, DiagnosticIdentifiers, DiagnosticIdentifiersSize, 0);
7431 A->setImplicit(true);
7432 return A;
7433 }
7434
7435 SuppressAttr(SourceRange R, ASTContext &Ctx
7436 , StringRef *DiagnosticIdentifiers, unsigned DiagnosticIdentifiersSize
7437 , unsigned SI
7438 )
7439 : StmtAttr(attr::Suppress, R, SI, false)
7440 , diagnosticIdentifiers_Size(DiagnosticIdentifiersSize), diagnosticIdentifiers_(new (Ctx, 16) StringRef[diagnosticIdentifiers_Size])
7441 {
7442 for (size_t I = 0, E = diagnosticIdentifiers_Size; I != E;
7443 ++I) {
7444 StringRef Ref = DiagnosticIdentifiers[I];
7445 if (!Ref.empty()) {
7446 char *Mem = new (Ctx, 1) char[Ref.size()];
7447 std::memcpy(Mem, Ref.data(), Ref.size());
7448 diagnosticIdentifiers_[I] = StringRef(Mem, Ref.size());
7449 }
7450 }
7451 }
7452
7453 SuppressAttr(SourceRange R, ASTContext &Ctx
7454 , unsigned SI
7455 )
7456 : StmtAttr(attr::Suppress, R, SI, false)
7457 , diagnosticIdentifiers_Size(0), diagnosticIdentifiers_(nullptr)
7458 {
7459 }
7460
7461 SuppressAttr *clone(ASTContext &C) const;
7462 void printPretty(raw_ostream &OS,
7463 const PrintingPolicy &Policy) const;
7464 const char *getSpelling() const;
7465 typedef StringRef* diagnosticIdentifiers_iterator;
7466 diagnosticIdentifiers_iterator diagnosticIdentifiers_begin() const { return diagnosticIdentifiers_; }
7467 diagnosticIdentifiers_iterator diagnosticIdentifiers_end() const { return diagnosticIdentifiers_ + diagnosticIdentifiers_Size; }
7468 unsigned diagnosticIdentifiers_size() const { return diagnosticIdentifiers_Size; }
7469 llvm::iterator_range<diagnosticIdentifiers_iterator> diagnosticIdentifiers() const { return llvm::make_range(diagnosticIdentifiers_begin(), diagnosticIdentifiers_end()); }
7470
7471
7472
7473
7474 static bool classof(const Attr *A) { return A->getKind() == attr::Suppress; }
7475};
7476
7477class SwiftCallAttr : public InheritableAttr {
7478public:
7479 static SwiftCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7480 auto *A = new (Ctx) SwiftCallAttr(Loc, Ctx, 0);
7481 A->setImplicit(true);
7482 return A;
7483 }
7484
7485 SwiftCallAttr(SourceRange R, ASTContext &Ctx
7486 , unsigned SI
7487 )
7488 : InheritableAttr(attr::SwiftCall, R, SI, false, false)
7489 {
7490 }
7491
7492 SwiftCallAttr *clone(ASTContext &C) const;
7493 void printPretty(raw_ostream &OS,
7494 const PrintingPolicy &Policy) const;
7495 const char *getSpelling() const;
7496
7497
7498 static bool classof(const Attr *A) { return A->getKind() == attr::SwiftCall; }
7499};
7500
7501class SwiftContextAttr : public ParameterABIAttr {
7502public:
7503 static SwiftContextAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7504 auto *A = new (Ctx) SwiftContextAttr(Loc, Ctx, 0);
7505 A->setImplicit(true);
7506 return A;
7507 }
7508
7509 SwiftContextAttr(SourceRange R, ASTContext &Ctx
7510 , unsigned SI
7511 )
7512 : ParameterABIAttr(attr::SwiftContext, R, SI, false, false)
7513 {
7514 }
7515
7516 SwiftContextAttr *clone(ASTContext &C) const;
7517 void printPretty(raw_ostream &OS,
7518 const PrintingPolicy &Policy) const;
7519 const char *getSpelling() const;
7520
7521
7522 static bool classof(const Attr *A) { return A->getKind() == attr::SwiftContext; }
7523};
7524
7525class SwiftErrorResultAttr : public ParameterABIAttr {
7526public:
7527 static SwiftErrorResultAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7528 auto *A = new (Ctx) SwiftErrorResultAttr(Loc, Ctx, 0);
7529 A->setImplicit(true);
7530 return A;
7531 }
7532
7533 SwiftErrorResultAttr(SourceRange R, ASTContext &Ctx
7534 , unsigned SI
7535 )
7536 : ParameterABIAttr(attr::SwiftErrorResult, R, SI, false, false)
7537 {
7538 }
7539
7540 SwiftErrorResultAttr *clone(ASTContext &C) const;
7541 void printPretty(raw_ostream &OS,
7542 const PrintingPolicy &Policy) const;
7543 const char *getSpelling() const;
7544
7545
7546 static bool classof(const Attr *A) { return A->getKind() == attr::SwiftErrorResult; }
7547};
7548
7549class SwiftIndirectResultAttr : public ParameterABIAttr {
7550public:
7551 static SwiftIndirectResultAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7552 auto *A = new (Ctx) SwiftIndirectResultAttr(Loc, Ctx, 0);
7553 A->setImplicit(true);
7554 return A;
7555 }
7556
7557 SwiftIndirectResultAttr(SourceRange R, ASTContext &Ctx
7558 , unsigned SI
7559 )
7560 : ParameterABIAttr(attr::SwiftIndirectResult, R, SI, false, false)
7561 {
7562 }
7563
7564 SwiftIndirectResultAttr *clone(ASTContext &C) const;
7565 void printPretty(raw_ostream &OS,
7566 const PrintingPolicy &Policy) const;
7567 const char *getSpelling() const;
7568
7569
7570 static bool classof(const Attr *A) { return A->getKind() == attr::SwiftIndirectResult; }
7571};
7572
7573class SysVABIAttr : public InheritableAttr {
7574public:
7575 static SysVABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7576 auto *A = new (Ctx) SysVABIAttr(Loc, Ctx, 0);
7577 A->setImplicit(true);
7578 return A;
7579 }
7580
7581 SysVABIAttr(SourceRange R, ASTContext &Ctx
7582 , unsigned SI
7583 )
7584 : InheritableAttr(attr::SysVABI, R, SI, false, false)
7585 {
7586 }
7587
7588 SysVABIAttr *clone(ASTContext &C) const;
7589 void printPretty(raw_ostream &OS,
7590 const PrintingPolicy &Policy) const;
7591 const char *getSpelling() const;
7592
7593
7594 static bool classof(const Attr *A) { return A->getKind() == attr::SysVABI; }
7595};
7596
7597class TLSModelAttr : public InheritableAttr {
7598unsigned modelLength;
7599char *model;
7600
7601public:
7602 static TLSModelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Model, SourceRange Loc = SourceRange()) {
7603 auto *A = new (Ctx) TLSModelAttr(Loc, Ctx, Model, 0);
7604 A->setImplicit(true);
7605 return A;
7606 }
7607
7608 TLSModelAttr(SourceRange R, ASTContext &Ctx
7609 , llvm::StringRef Model
7610 , unsigned SI
7611 )
7612 : InheritableAttr(attr::TLSModel, R, SI, false, false)
7613 , modelLength(Model.size()),model(new (Ctx, 1) char[modelLength])
7614 {
7615 if (!Model.empty())
7616 std::memcpy(model, Model.data(), modelLength);
7617 }
7618
7619 TLSModelAttr *clone(ASTContext &C) const;
7620 void printPretty(raw_ostream &OS,
7621 const PrintingPolicy &Policy) const;
7622 const char *getSpelling() const;
7623 llvm::StringRef getModel() const {
7624 return llvm::StringRef(model, modelLength);
7625 }
7626 unsigned getModelLength() const {
7627 return modelLength;
7628 }
7629 void setModel(ASTContext &C, llvm::StringRef S) {
7630 modelLength = S.size();
7631 this->model = new (C, 1) char [modelLength];
7632 if (!S.empty())
7633 std::memcpy(this->model, S.data(), modelLength);
7634 }
7635
7636
7637
7638 static bool classof(const Attr *A) { return A->getKind() == attr::TLSModel; }
7639};
7640
7641class TargetAttr : public InheritableAttr {
7642unsigned featuresStrLength;
7643char *featuresStr;
7644
7645public:
7646 static TargetAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef FeaturesStr, SourceRange Loc = SourceRange()) {
7647 auto *A = new (Ctx) TargetAttr(Loc, Ctx, FeaturesStr, 0);
7648 A->setImplicit(true);
7649 return A;
7650 }
7651
7652 TargetAttr(SourceRange R, ASTContext &Ctx
7653 , llvm::StringRef FeaturesStr
7654 , unsigned SI
7655 )
7656 : InheritableAttr(attr::Target, R, SI, false, false)
7657 , featuresStrLength(FeaturesStr.size()),featuresStr(new (Ctx, 1) char[featuresStrLength])
7658 {
7659 if (!FeaturesStr.empty())
7660 std::memcpy(featuresStr, FeaturesStr.data(), featuresStrLength);
7661 }
7662
7663 TargetAttr *clone(ASTContext &C) const;
7664 void printPretty(raw_ostream &OS,
7665 const PrintingPolicy &Policy) const;
7666 const char *getSpelling() const;
7667 llvm::StringRef getFeaturesStr() const {
7668 return llvm::StringRef(featuresStr, featuresStrLength);
7669 }
7670 unsigned getFeaturesStrLength() const {
7671 return featuresStrLength;
7672 }
7673 void setFeaturesStr(ASTContext &C, llvm::StringRef S) {
7674 featuresStrLength = S.size();
7675 this->featuresStr = new (C, 1) char [featuresStrLength];
7676 if (!S.empty())
7677 std::memcpy(this->featuresStr, S.data(), featuresStrLength);
7678 }
7679
7680
7681 struct ParsedTargetAttr {
7682 std::vector<std::string> Features;
7683 StringRef Architecture;
7684 bool DuplicateArchitecture = false;
7685 bool operator ==(const ParsedTargetAttr &Other) const {
7686 return DuplicateArchitecture == Other.DuplicateArchitecture &&
7687 Architecture == Other.Architecture && Features == Other.Features;
7688 }
7689 };
7690 ParsedTargetAttr parse() const {
7691 return parse(getFeaturesStr());
7692 }
7693
7694 template<class Compare>
7695 ParsedTargetAttr parse(Compare cmp) const {
7696 ParsedTargetAttr Attrs = parse();
7697 std::sort(std::begin(Attrs.Features), std::end(Attrs.Features), cmp);
7698 return Attrs;
7699 }
7700
7701 bool isDefaultVersion() const { return getFeaturesStr() == "default"; }
7702
7703 static ParsedTargetAttr parse(StringRef Features) {
7704 ParsedTargetAttr Ret;
7705 if (Features == "default") return Ret;
7706 SmallVector<StringRef, 1> AttrFeatures;
7707 Features.split(AttrFeatures, ",");
7708
7709 // Grab the various features and prepend a "+" to turn on the feature to
7710 // the backend and add them to our existing set of features.
7711 for (auto &Feature : AttrFeatures) {
7712 // Go ahead and trim whitespace rather than either erroring or
7713 // accepting it weirdly.
7714 Feature = Feature.trim();
7715
7716 // We don't support cpu tuning this way currently.
7717 // TODO: Support the fpmath option. It will require checking
7718 // overall feature validity for the function with the rest of the
7719 // attributes on the function.
7720 if (Feature.startswith("fpmath=") || Feature.startswith("tune="))
7721 continue;
7722
7723 // While we're here iterating check for a different target cpu.
7724 if (Feature.startswith("arch=")) {
7725 if (!Ret.Architecture.empty())
7726 Ret.DuplicateArchitecture = true;
7727 else
7728 Ret.Architecture = Feature.split("=").second.trim();
7729 } else if (Feature.startswith("no-"))
7730 Ret.Features.push_back("-" + Feature.split("-").second.str());
7731 else
7732 Ret.Features.push_back("+" + Feature.str());
7733 }
7734 return Ret;
7735 }
7736
7737
7738 static bool classof(const Attr *A) { return A->getKind() == attr::Target; }
7739};
7740
7741class TestTypestateAttr : public InheritableAttr {
7742public:
7743 enum ConsumedState {
7744 Consumed,
7745 Unconsumed
7746 };
7747private:
7748 ConsumedState testState;
7749
7750public:
7751 static TestTypestateAttr *CreateImplicit(ASTContext &Ctx, ConsumedState TestState, SourceRange Loc = SourceRange()) {
7752 auto *A = new (Ctx) TestTypestateAttr(Loc, Ctx, TestState, 0);
7753 A->setImplicit(true);
7754 return A;
7755 }
7756
7757 TestTypestateAttr(SourceRange R, ASTContext &Ctx
7758 , ConsumedState TestState
7759 , unsigned SI
7760 )
7761 : InheritableAttr(attr::TestTypestate, R, SI, false, false)
7762 , testState(TestState)
7763 {
7764 }
7765
7766 TestTypestateAttr *clone(ASTContext &C) const;
7767 void printPretty(raw_ostream &OS,
7768 const PrintingPolicy &Policy) const;
7769 const char *getSpelling() const;
7770 ConsumedState getTestState() const {
7771 return testState;
7772 }
7773
7774 static bool ConvertStrToConsumedState(StringRef Val, ConsumedState &Out) {
7775 Optional<ConsumedState> R = llvm::StringSwitch<Optional<ConsumedState>>(Val)
7776 .Case("consumed", TestTypestateAttr::Consumed)
7777 .Case("unconsumed", TestTypestateAttr::Unconsumed)
7778 .Default(Optional<ConsumedState>());
7779 if (R) {
7780 Out = *R;
7781 return true;
7782 }
7783 return false;
7784 }
7785
7786 static const char *ConvertConsumedStateToStr(ConsumedState Val) {
7787 switch(Val) {
7788 case TestTypestateAttr::Consumed: return "consumed";
7789 case TestTypestateAttr::Unconsumed: return "unconsumed";
7790 }
7791 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7791)
;
7792 }
7793
7794
7795 static bool classof(const Attr *A) { return A->getKind() == attr::TestTypestate; }
7796};
7797
7798class ThisCallAttr : public InheritableAttr {
7799public:
7800 static ThisCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7801 auto *A = new (Ctx) ThisCallAttr(Loc, Ctx, 0);
7802 A->setImplicit(true);
7803 return A;
7804 }
7805
7806 ThisCallAttr(SourceRange R, ASTContext &Ctx
7807 , unsigned SI
7808 )
7809 : InheritableAttr(attr::ThisCall, R, SI, false, false)
7810 {
7811 }
7812
7813 ThisCallAttr *clone(ASTContext &C) const;
7814 void printPretty(raw_ostream &OS,
7815 const PrintingPolicy &Policy) const;
7816 const char *getSpelling() const;
7817
7818
7819 static bool classof(const Attr *A) { return A->getKind() == attr::ThisCall; }
7820};
7821
7822class ThreadAttr : public Attr {
7823public:
7824 static ThreadAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7825 auto *A = new (Ctx) ThreadAttr(Loc, Ctx, 0);
7826 A->setImplicit(true);
7827 return A;
7828 }
7829
7830 ThreadAttr(SourceRange R, ASTContext &Ctx
7831 , unsigned SI
7832 )
7833 : Attr(attr::Thread, R, SI, false)
7834 {
7835 }
7836
7837 ThreadAttr *clone(ASTContext &C) const;
7838 void printPretty(raw_ostream &OS,
7839 const PrintingPolicy &Policy) const;
7840 const char *getSpelling() const;
7841
7842
7843 static bool classof(const Attr *A) { return A->getKind() == attr::Thread; }
7844};
7845
7846class TransparentUnionAttr : public InheritableAttr {
7847public:
7848 static TransparentUnionAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7849 auto *A = new (Ctx) TransparentUnionAttr(Loc, Ctx, 0);
7850 A->setImplicit(true);
7851 return A;
7852 }
7853
7854 TransparentUnionAttr(SourceRange R, ASTContext &Ctx
7855 , unsigned SI
7856 )
7857 : InheritableAttr(attr::TransparentUnion, R, SI, false, false)
7858 {
7859 }
7860
7861 TransparentUnionAttr *clone(ASTContext &C) const;
7862 void printPretty(raw_ostream &OS,
7863 const PrintingPolicy &Policy) const;
7864 const char *getSpelling() const;
7865
7866
7867 static bool classof(const Attr *A) { return A->getKind() == attr::TransparentUnion; }
7868};
7869
7870class TrivialABIAttr : public InheritableAttr {
7871public:
7872 static TrivialABIAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
7873 auto *A = new (Ctx) TrivialABIAttr(Loc, Ctx, 0);
7874 A->setImplicit(true);
7875 return A;
7876 }
7877
7878 TrivialABIAttr(SourceRange R, ASTContext &Ctx
7879 , unsigned SI
7880 )
7881 : InheritableAttr(attr::TrivialABI, R, SI, false, false)
7882 {
7883 }
7884
7885 TrivialABIAttr *clone(ASTContext &C) const;
7886 void printPretty(raw_ostream &OS,
7887 const PrintingPolicy &Policy) const;
7888 const char *getSpelling() const;
7889
7890
7891 static bool classof(const Attr *A) { return A->getKind() == attr::TrivialABI; }
7892};
7893
7894class TryAcquireCapabilityAttr : public InheritableAttr {
7895Expr * successValue;
7896
7897 unsigned args_Size;
7898 Expr * *args_;
7899
7900public:
7901 enum Spelling {
7902 GNU_try_acquire_capability = 0,
7903 CXX11_clang_try_acquire_capability = 1,
7904 GNU_try_acquire_shared_capability = 2,
7905 CXX11_clang_try_acquire_shared_capability = 3
7906 };
7907
7908 static TryAcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * SuccessValue, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
7909 auto *A = new (Ctx) TryAcquireCapabilityAttr(Loc, Ctx, SuccessValue, Args, ArgsSize, S);
7910 A->setImplicit(true);
7911 return A;
7912 }
7913
7914 TryAcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
7915 , Expr * SuccessValue
7916 , Expr * *Args, unsigned ArgsSize
7917 , unsigned SI
7918 )
7919 : InheritableAttr(attr::TryAcquireCapability, R, SI, true, true)
7920 , successValue(SuccessValue)
7921 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
7922 {
7923 std::copy(Args, Args + args_Size, args_);
7924 }
7925
7926 TryAcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
7927 , Expr * SuccessValue
7928 , unsigned SI
7929 )
7930 : InheritableAttr(attr::TryAcquireCapability, R, SI, true, true)
7931 , successValue(SuccessValue)
7932 , args_Size(0), args_(nullptr)
7933 {
7934 }
7935
7936 TryAcquireCapabilityAttr *clone(ASTContext &C) const;
7937 void printPretty(raw_ostream &OS,
7938 const PrintingPolicy &Policy) const;
7939 const char *getSpelling() const;
7940 Spelling getSemanticSpelling() const {
7941 switch (SpellingListIndex) {
7942 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 7942)
;
7943 case 0: return GNU_try_acquire_capability;
7944 case 1: return CXX11_clang_try_acquire_capability;
7945 case 2: return GNU_try_acquire_shared_capability;
7946 case 3: return CXX11_clang_try_acquire_shared_capability;
7947 }
7948 }
7949 bool isShared() const { return SpellingListIndex == 2 ||
7950 SpellingListIndex == 3; }
7951 Expr * getSuccessValue() const {
7952 return successValue;
7953 }
7954
7955 typedef Expr ** args_iterator;
7956 args_iterator args_begin() const { return args_; }
7957 args_iterator args_end() const { return args_ + args_Size; }
7958 unsigned args_size() const { return args_Size; }
7959 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
7960
7961
7962
7963
7964 static bool classof(const Attr *A) { return A->getKind() == attr::TryAcquireCapability; }
7965};
7966
7967class TypeTagForDatatypeAttr : public InheritableAttr {
7968IdentifierInfo * argumentKind;
7969
7970TypeSourceInfo * matchingCType;
7971
7972bool layoutCompatible;
7973
7974bool mustBeNull;
7975
7976public:
7977 static TypeTagForDatatypeAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * ArgumentKind, TypeSourceInfo * MatchingCType, bool LayoutCompatible, bool MustBeNull, SourceRange Loc = SourceRange()) {
7978 auto *A = new (Ctx) TypeTagForDatatypeAttr(Loc, Ctx, ArgumentKind, MatchingCType, LayoutCompatible, MustBeNull, 0);
7979 A->setImplicit(true);
7980 return A;
7981 }
7982
7983 TypeTagForDatatypeAttr(SourceRange R, ASTContext &Ctx
7984 , IdentifierInfo * ArgumentKind
7985 , TypeSourceInfo * MatchingCType
7986 , bool LayoutCompatible
7987 , bool MustBeNull
7988 , unsigned SI
7989 )
7990 : InheritableAttr(attr::TypeTagForDatatype, R, SI, false, false)
7991 , argumentKind(ArgumentKind)
7992 , matchingCType(MatchingCType)
7993 , layoutCompatible(LayoutCompatible)
7994 , mustBeNull(MustBeNull)
7995 {
7996 }
7997
7998 TypeTagForDatatypeAttr *clone(ASTContext &C) const;
7999 void printPretty(raw_ostream &OS,
8000 const PrintingPolicy &Policy) const;
8001 const char *getSpelling() const;
8002 IdentifierInfo * getArgumentKind() const {
8003 return argumentKind;
8004 }
8005
8006 QualType getMatchingCType() const {
8007 return matchingCType->getType();
8008 } TypeSourceInfo * getMatchingCTypeLoc() const {
8009 return matchingCType;
8010 }
8011
8012 bool getLayoutCompatible() const {
8013 return layoutCompatible;
8014 }
8015
8016 bool getMustBeNull() const {
8017 return mustBeNull;
8018 }
8019
8020
8021
8022 static bool classof(const Attr *A) { return A->getKind() == attr::TypeTagForDatatype; }
8023};
8024
8025class TypeVisibilityAttr : public InheritableAttr {
8026public:
8027 enum VisibilityType {
8028 Default,
8029 Hidden,
8030 Protected
8031 };
8032private:
8033 VisibilityType visibility;
8034
8035public:
8036 static TypeVisibilityAttr *CreateImplicit(ASTContext &Ctx, VisibilityType Visibility, SourceRange Loc = SourceRange()) {
8037 auto *A = new (Ctx) TypeVisibilityAttr(Loc, Ctx, Visibility, 0);
8038 A->setImplicit(true);
8039 return A;
8040 }
8041
8042 TypeVisibilityAttr(SourceRange R, ASTContext &Ctx
8043 , VisibilityType Visibility
8044 , unsigned SI
8045 )
8046 : InheritableAttr(attr::TypeVisibility, R, SI, false, false)
8047 , visibility(Visibility)
8048 {
8049 }
8050
8051 TypeVisibilityAttr *clone(ASTContext &C) const;
8052 void printPretty(raw_ostream &OS,
8053 const PrintingPolicy &Policy) const;
8054 const char *getSpelling() const;
8055 VisibilityType getVisibility() const {
8056 return visibility;
8057 }
8058
8059 static bool ConvertStrToVisibilityType(StringRef Val, VisibilityType &Out) {
8060 Optional<VisibilityType> R = llvm::StringSwitch<Optional<VisibilityType>>(Val)
8061 .Case("default", TypeVisibilityAttr::Default)
8062 .Case("hidden", TypeVisibilityAttr::Hidden)
8063 .Case("internal", TypeVisibilityAttr::Hidden)
8064 .Case("protected", TypeVisibilityAttr::Protected)
8065 .Default(Optional<VisibilityType>());
8066 if (R) {
8067 Out = *R;
8068 return true;
8069 }
8070 return false;
8071 }
8072
8073 static const char *ConvertVisibilityTypeToStr(VisibilityType Val) {
8074 switch(Val) {
8075 case TypeVisibilityAttr::Default: return "default";
8076 case TypeVisibilityAttr::Hidden: return "hidden";
8077 case TypeVisibilityAttr::Protected: return "protected";
8078 }
8079 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8079)
;
8080 }
8081
8082
8083 static bool classof(const Attr *A) { return A->getKind() == attr::TypeVisibility; }
8084};
8085
8086class UnavailableAttr : public InheritableAttr {
8087unsigned messageLength;
8088char *message;
8089
8090public:
8091 enum ImplicitReason {
8092 IR_None,
8093 IR_ARCForbiddenType,
8094 IR_ForbiddenWeak,
8095 IR_ARCForbiddenConversion,
8096 IR_ARCInitReturnsUnrelated,
8097 IR_ARCFieldWithOwnership
8098 };
8099private:
8100 ImplicitReason implicitReason;
8101
8102public:
8103 static UnavailableAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, ImplicitReason ImplicitReason, SourceRange Loc = SourceRange()) {
8104 auto *A = new (Ctx) UnavailableAttr(Loc, Ctx, Message, ImplicitReason, 0);
8105 A->setImplicit(true);
8106 return A;
8107 }
8108
8109 static UnavailableAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Message, SourceRange Loc = SourceRange()) {
8110 auto *A = new (Ctx) UnavailableAttr(Loc, Ctx, Message, 0);
8111 A->setImplicit(true);
8112 return A;
8113 }
8114
8115 UnavailableAttr(SourceRange R, ASTContext &Ctx
8116 , llvm::StringRef Message
8117 , ImplicitReason ImplicitReason
8118 , unsigned SI
8119 )
8120 : InheritableAttr(attr::Unavailable, R, SI, false, false)
8121 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
8122 , implicitReason(ImplicitReason)
8123 {
8124 if (!Message.empty())
8125 std::memcpy(message, Message.data(), messageLength);
8126 }
8127
8128 UnavailableAttr(SourceRange R, ASTContext &Ctx
8129 , llvm::StringRef Message
8130 , unsigned SI
8131 )
8132 : InheritableAttr(attr::Unavailable, R, SI, false, false)
8133 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
8134 , implicitReason(ImplicitReason(0))
8135 {
8136 if (!Message.empty())
8137 std::memcpy(message, Message.data(), messageLength);
8138 }
8139
8140 UnavailableAttr(SourceRange R, ASTContext &Ctx
8141 , unsigned SI
8142 )
8143 : InheritableAttr(attr::Unavailable, R, SI, false, false)
8144 , messageLength(0),message(nullptr)
8145 , implicitReason(ImplicitReason(0))
8146 {
8147 }
8148
8149 UnavailableAttr *clone(ASTContext &C) const;
8150 void printPretty(raw_ostream &OS,
8151 const PrintingPolicy &Policy) const;
8152 const char *getSpelling() const;
8153 llvm::StringRef getMessage() const {
8154 return llvm::StringRef(message, messageLength);
8155 }
8156 unsigned getMessageLength() const {
8157 return messageLength;
8158 }
8159 void setMessage(ASTContext &C, llvm::StringRef S) {
8160 messageLength = S.size();
8161 this->message = new (C, 1) char [messageLength];
8162 if (!S.empty())
8163 std::memcpy(this->message, S.data(), messageLength);
8164 }
8165
8166 ImplicitReason getImplicitReason() const {
8167 return implicitReason;
8168 }
8169
8170
8171
8172 static bool classof(const Attr *A) { return A->getKind() == attr::Unavailable; }
8173};
8174
8175class UnusedAttr : public InheritableAttr {
8176public:
8177 enum Spelling {
8178 CXX11_maybe_unused = 0,
8179 GNU_unused = 1,
8180 CXX11_gnu_unused = 2,
8181 C2x_maybe_unused = 3
8182 };
8183
8184 static UnusedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
8185 auto *A = new (Ctx) UnusedAttr(Loc, Ctx, S);
8186 A->setImplicit(true);
8187 return A;
8188 }
8189
8190 UnusedAttr(SourceRange R, ASTContext &Ctx
8191 , unsigned SI
8192 )
8193 : InheritableAttr(attr::Unused, R, SI, false, false)
8194 {
8195 }
8196
8197 UnusedAttr *clone(ASTContext &C) const;
8198 void printPretty(raw_ostream &OS,
8199 const PrintingPolicy &Policy) const;
8200 const char *getSpelling() const;
8201 Spelling getSemanticSpelling() const {
8202 switch (SpellingListIndex) {
8203 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8203)
;
8204 case 0: return CXX11_maybe_unused;
8205 case 1: return GNU_unused;
8206 case 2: return CXX11_gnu_unused;
8207 case 3: return C2x_maybe_unused;
8208 }
8209 }
8210
8211
8212 static bool classof(const Attr *A) { return A->getKind() == attr::Unused; }
8213};
8214
8215class UsedAttr : public InheritableAttr {
8216public:
8217 static UsedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8218 auto *A = new (Ctx) UsedAttr(Loc, Ctx, 0);
8219 A->setImplicit(true);
8220 return A;
8221 }
8222
8223 UsedAttr(SourceRange R, ASTContext &Ctx
8224 , unsigned SI
8225 )
8226 : InheritableAttr(attr::Used, R, SI, false, false)
8227 {
8228 }
8229
8230 UsedAttr *clone(ASTContext &C) const;
8231 void printPretty(raw_ostream &OS,
8232 const PrintingPolicy &Policy) const;
8233 const char *getSpelling() const;
8234
8235
8236 static bool classof(const Attr *A) { return A->getKind() == attr::Used; }
8237};
8238
8239class UuidAttr : public InheritableAttr {
8240unsigned guidLength;
8241char *guid;
8242
8243public:
8244 static UuidAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Guid, SourceRange Loc = SourceRange()) {
8245 auto *A = new (Ctx) UuidAttr(Loc, Ctx, Guid, 0);
8246 A->setImplicit(true);
8247 return A;
8248 }
8249
8250 UuidAttr(SourceRange R, ASTContext &Ctx
8251 , llvm::StringRef Guid
8252 , unsigned SI
8253 )
8254 : InheritableAttr(attr::Uuid, R, SI, false, false)
8255 , guidLength(Guid.size()),guid(new (Ctx, 1) char[guidLength])
8256 {
8257 if (!Guid.empty())
8258 std::memcpy(guid, Guid.data(), guidLength);
8259 }
8260
8261 UuidAttr *clone(ASTContext &C) const;
8262 void printPretty(raw_ostream &OS,
8263 const PrintingPolicy &Policy) const;
8264 const char *getSpelling() const;
8265 llvm::StringRef getGuid() const {
8266 return llvm::StringRef(guid, guidLength);
8267 }
8268 unsigned getGuidLength() const {
8269 return guidLength;
8270 }
8271 void setGuid(ASTContext &C, llvm::StringRef S) {
8272 guidLength = S.size();
8273 this->guid = new (C, 1) char [guidLength];
8274 if (!S.empty())
8275 std::memcpy(this->guid, S.data(), guidLength);
8276 }
8277
8278
8279
8280 static bool classof(const Attr *A) { return A->getKind() == attr::Uuid; }
8281};
8282
8283class VecReturnAttr : public InheritableAttr {
8284public:
8285 static VecReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8286 auto *A = new (Ctx) VecReturnAttr(Loc, Ctx, 0);
8287 A->setImplicit(true);
8288 return A;
8289 }
8290
8291 VecReturnAttr(SourceRange R, ASTContext &Ctx
8292 , unsigned SI
8293 )
8294 : InheritableAttr(attr::VecReturn, R, SI, false, false)
8295 {
8296 }
8297
8298 VecReturnAttr *clone(ASTContext &C) const;
8299 void printPretty(raw_ostream &OS,
8300 const PrintingPolicy &Policy) const;
8301 const char *getSpelling() const;
8302
8303
8304 static bool classof(const Attr *A) { return A->getKind() == attr::VecReturn; }
8305};
8306
8307class VecTypeHintAttr : public InheritableAttr {
8308TypeSourceInfo * typeHint;
8309
8310public:
8311 static VecTypeHintAttr *CreateImplicit(ASTContext &Ctx, TypeSourceInfo * TypeHint, SourceRange Loc = SourceRange()) {
8312 auto *A = new (Ctx) VecTypeHintAttr(Loc, Ctx, TypeHint, 0);
8313 A->setImplicit(true);
8314 return A;
8315 }
8316
8317 VecTypeHintAttr(SourceRange R, ASTContext &Ctx
8318 , TypeSourceInfo * TypeHint
8319 , unsigned SI
8320 )
8321 : InheritableAttr(attr::VecTypeHint, R, SI, false, false)
8322 , typeHint(TypeHint)
8323 {
8324 }
8325
8326 VecTypeHintAttr *clone(ASTContext &C) const;
8327 void printPretty(raw_ostream &OS,
8328 const PrintingPolicy &Policy) const;
8329 const char *getSpelling() const;
8330 QualType getTypeHint() const {
8331 return typeHint->getType();
8332 } TypeSourceInfo * getTypeHintLoc() const {
8333 return typeHint;
8334 }
8335
8336
8337
8338 static bool classof(const Attr *A) { return A->getKind() == attr::VecTypeHint; }
8339};
8340
8341class VectorCallAttr : public InheritableAttr {
8342public:
8343 static VectorCallAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8344 auto *A = new (Ctx) VectorCallAttr(Loc, Ctx, 0);
8345 A->setImplicit(true);
8346 return A;
8347 }
8348
8349 VectorCallAttr(SourceRange R, ASTContext &Ctx
8350 , unsigned SI
8351 )
8352 : InheritableAttr(attr::VectorCall, R, SI, false, false)
8353 {
8354 }
8355
8356 VectorCallAttr *clone(ASTContext &C) const;
8357 void printPretty(raw_ostream &OS,
8358 const PrintingPolicy &Policy) const;
8359 const char *getSpelling() const;
8360
8361
8362 static bool classof(const Attr *A) { return A->getKind() == attr::VectorCall; }
8363};
8364
8365class VisibilityAttr : public InheritableAttr {
8366public:
8367 enum VisibilityType {
8368 Default,
8369 Hidden,
8370 Protected
8371 };
8372private:
8373 VisibilityType visibility;
8374
8375public:
8376 static VisibilityAttr *CreateImplicit(ASTContext &Ctx, VisibilityType Visibility, SourceRange Loc = SourceRange()) {
8377 auto *A = new (Ctx) VisibilityAttr(Loc, Ctx, Visibility, 0);
8378 A->setImplicit(true);
8379 return A;
8380 }
8381
8382 VisibilityAttr(SourceRange R, ASTContext &Ctx
8383 , VisibilityType Visibility
8384 , unsigned SI
8385 )
8386 : InheritableAttr(attr::Visibility, R, SI, false, false)
8387 , visibility(Visibility)
8388 {
8389 }
8390
8391 VisibilityAttr *clone(ASTContext &C) const;
8392 void printPretty(raw_ostream &OS,
8393 const PrintingPolicy &Policy) const;
8394 const char *getSpelling() const;
8395 VisibilityType getVisibility() const {
8396 return visibility;
8397 }
8398
8399 static bool ConvertStrToVisibilityType(StringRef Val, VisibilityType &Out) {
8400 Optional<VisibilityType> R = llvm::StringSwitch<Optional<VisibilityType>>(Val)
8401 .Case("default", VisibilityAttr::Default)
8402 .Case("hidden", VisibilityAttr::Hidden)
8403 .Case("internal", VisibilityAttr::Hidden)
8404 .Case("protected", VisibilityAttr::Protected)
8405 .Default(Optional<VisibilityType>());
8406 if (R) {
8407 Out = *R;
8408 return true;
8409 }
8410 return false;
8411 }
8412
8413 static const char *ConvertVisibilityTypeToStr(VisibilityType Val) {
8414 switch(Val) {
8415 case VisibilityAttr::Default: return "default";
8416 case VisibilityAttr::Hidden: return "hidden";
8417 case VisibilityAttr::Protected: return "protected";
8418 }
8419 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8419)
;
8420 }
8421
8422
8423 static bool classof(const Attr *A) { return A->getKind() == attr::Visibility; }
8424};
8425
8426class WarnUnusedAttr : public InheritableAttr {
8427public:
8428 static WarnUnusedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8429 auto *A = new (Ctx) WarnUnusedAttr(Loc, Ctx, 0);
8430 A->setImplicit(true);
8431 return A;
8432 }
8433
8434 WarnUnusedAttr(SourceRange R, ASTContext &Ctx
8435 , unsigned SI
8436 )
8437 : InheritableAttr(attr::WarnUnused, R, SI, false, false)
8438 {
8439 }
8440
8441 WarnUnusedAttr *clone(ASTContext &C) const;
8442 void printPretty(raw_ostream &OS,
8443 const PrintingPolicy &Policy) const;
8444 const char *getSpelling() const;
8445
8446
8447 static bool classof(const Attr *A) { return A->getKind() == attr::WarnUnused; }
8448};
8449
8450class WarnUnusedResultAttr : public InheritableAttr {
8451public:
8452 enum Spelling {
8453 CXX11_nodiscard = 0,
8454 C2x_nodiscard = 1,
8455 CXX11_clang_warn_unused_result = 2,
8456 GNU_warn_unused_result = 3,
8457 CXX11_gnu_warn_unused_result = 4
8458 };
8459
8460 static WarnUnusedResultAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
8461 auto *A = new (Ctx) WarnUnusedResultAttr(Loc, Ctx, S);
8462 A->setImplicit(true);
8463 return A;
8464 }
8465
8466 WarnUnusedResultAttr(SourceRange R, ASTContext &Ctx
8467 , unsigned SI
8468 )
8469 : InheritableAttr(attr::WarnUnusedResult, R, SI, false, false)
8470 {
8471 }
8472
8473 WarnUnusedResultAttr *clone(ASTContext &C) const;
8474 void printPretty(raw_ostream &OS,
8475 const PrintingPolicy &Policy) const;
8476 const char *getSpelling() const;
8477 Spelling getSemanticSpelling() const {
8478 switch (SpellingListIndex) {
8479 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8479)
;
8480 case 0: return CXX11_nodiscard;
8481 case 1: return C2x_nodiscard;
8482 case 2: return CXX11_clang_warn_unused_result;
8483 case 3: return GNU_warn_unused_result;
8484 case 4: return CXX11_gnu_warn_unused_result;
8485 }
8486 }
8487
8488
8489 static bool classof(const Attr *A) { return A->getKind() == attr::WarnUnusedResult; }
8490};
8491
8492class WeakAttr : public InheritableAttr {
8493public:
8494 static WeakAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8495 auto *A = new (Ctx) WeakAttr(Loc, Ctx, 0);
8496 A->setImplicit(true);
8497 return A;
8498 }
8499
8500 WeakAttr(SourceRange R, ASTContext &Ctx
8501 , unsigned SI
8502 )
8503 : InheritableAttr(attr::Weak, R, SI, false, false)
8504 {
8505 }
8506
8507 WeakAttr *clone(ASTContext &C) const;
8508 void printPretty(raw_ostream &OS,
8509 const PrintingPolicy &Policy) const;
8510 const char *getSpelling() const;
8511
8512
8513 static bool classof(const Attr *A) { return A->getKind() == attr::Weak; }
8514};
8515
8516class WeakImportAttr : public InheritableAttr {
8517public:
8518 static WeakImportAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8519 auto *A = new (Ctx) WeakImportAttr(Loc, Ctx, 0);
8520 A->setImplicit(true);
8521 return A;
8522 }
8523
8524 WeakImportAttr(SourceRange R, ASTContext &Ctx
8525 , unsigned SI
8526 )
8527 : InheritableAttr(attr::WeakImport, R, SI, false, false)
8528 {
8529 }
8530
8531 WeakImportAttr *clone(ASTContext &C) const;
8532 void printPretty(raw_ostream &OS,
8533 const PrintingPolicy &Policy) const;
8534 const char *getSpelling() const;
8535
8536
8537 static bool classof(const Attr *A) { return A->getKind() == attr::WeakImport; }
8538};
8539
8540class WeakRefAttr : public InheritableAttr {
8541unsigned aliaseeLength;
8542char *aliasee;
8543
8544public:
8545 static WeakRefAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) {
8546 auto *A = new (Ctx) WeakRefAttr(Loc, Ctx, Aliasee, 0);
8547 A->setImplicit(true);
8548 return A;
8549 }
8550
8551 WeakRefAttr(SourceRange R, ASTContext &Ctx
8552 , llvm::StringRef Aliasee
8553 , unsigned SI
8554 )
8555 : InheritableAttr(attr::WeakRef, R, SI, false, false)
8556 , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength])
8557 {
8558 if (!Aliasee.empty())
8559 std::memcpy(aliasee, Aliasee.data(), aliaseeLength);
8560 }
8561
8562 WeakRefAttr(SourceRange R, ASTContext &Ctx
8563 , unsigned SI
8564 )
8565 : InheritableAttr(attr::WeakRef, R, SI, false, false)
8566 , aliaseeLength(0),aliasee(nullptr)
8567 {
8568 }
8569
8570 WeakRefAttr *clone(ASTContext &C) const;
8571 void printPretty(raw_ostream &OS,
8572 const PrintingPolicy &Policy) const;
8573 const char *getSpelling() const;
8574 llvm::StringRef getAliasee() const {
8575 return llvm::StringRef(aliasee, aliaseeLength);
8576 }
8577 unsigned getAliaseeLength() const {
8578 return aliaseeLength;
8579 }
8580 void setAliasee(ASTContext &C, llvm::StringRef S) {
8581 aliaseeLength = S.size();
8582 this->aliasee = new (C, 1) char [aliaseeLength];
8583 if (!S.empty())
8584 std::memcpy(this->aliasee, S.data(), aliaseeLength);
8585 }
8586
8587
8588
8589 static bool classof(const Attr *A) { return A->getKind() == attr::WeakRef; }
8590};
8591
8592class WorkGroupSizeHintAttr : public InheritableAttr {
8593unsigned xDim;
8594
8595unsigned yDim;
8596
8597unsigned zDim;
8598
8599public:
8600 static WorkGroupSizeHintAttr *CreateImplicit(ASTContext &Ctx, unsigned XDim, unsigned YDim, unsigned ZDim, SourceRange Loc = SourceRange()) {
8601 auto *A = new (Ctx) WorkGroupSizeHintAttr(Loc, Ctx, XDim, YDim, ZDim, 0);
8602 A->setImplicit(true);
8603 return A;
8604 }
8605
8606 WorkGroupSizeHintAttr(SourceRange R, ASTContext &Ctx
8607 , unsigned XDim
8608 , unsigned YDim
8609 , unsigned ZDim
8610 , unsigned SI
8611 )
8612 : InheritableAttr(attr::WorkGroupSizeHint, R, SI, false, false)
8613 , xDim(XDim)
8614 , yDim(YDim)
8615 , zDim(ZDim)
8616 {
8617 }
8618
8619 WorkGroupSizeHintAttr *clone(ASTContext &C) const;
8620 void printPretty(raw_ostream &OS,
8621 const PrintingPolicy &Policy) const;
8622 const char *getSpelling() const;
8623 unsigned getXDim() const {
8624 return xDim;
8625 }
8626
8627 unsigned getYDim() const {
8628 return yDim;
8629 }
8630
8631 unsigned getZDim() const {
8632 return zDim;
8633 }
8634
8635
8636
8637 static bool classof(const Attr *A) { return A->getKind() == attr::WorkGroupSizeHint; }
8638};
8639
8640class X86ForceAlignArgPointerAttr : public InheritableAttr {
8641public:
8642 static X86ForceAlignArgPointerAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
8643 auto *A = new (Ctx) X86ForceAlignArgPointerAttr(Loc, Ctx, 0);
8644 A->setImplicit(true);
8645 return A;
8646 }
8647
8648 X86ForceAlignArgPointerAttr(SourceRange R, ASTContext &Ctx
8649 , unsigned SI
8650 )
8651 : InheritableAttr(attr::X86ForceAlignArgPointer, R, SI, false, false)
8652 {
8653 }
8654
8655 X86ForceAlignArgPointerAttr *clone(ASTContext &C) const;
8656 void printPretty(raw_ostream &OS,
8657 const PrintingPolicy &Policy) const;
8658 const char *getSpelling() const;
8659
8660
8661 static bool classof(const Attr *A) { return A->getKind() == attr::X86ForceAlignArgPointer; }
8662};
8663
8664class XRayInstrumentAttr : public InheritableAttr {
8665public:
8666 enum Spelling {
8667 GNU_xray_always_instrument = 0,
8668 CXX11_clang_xray_always_instrument = 1,
8669 C2x_clang_xray_always_instrument = 2,
8670 GNU_xray_never_instrument = 3,
8671 CXX11_clang_xray_never_instrument = 4,
8672 C2x_clang_xray_never_instrument = 5
8673 };
8674
8675 static XRayInstrumentAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
8676 auto *A = new (Ctx) XRayInstrumentAttr(Loc, Ctx, S);
8677 A->setImplicit(true);
8678 return A;
8679 }
8680
8681 XRayInstrumentAttr(SourceRange R, ASTContext &Ctx
8682 , unsigned SI
8683 )
8684 : InheritableAttr(attr::XRayInstrument, R, SI, false, false)
8685 {
8686 }
8687
8688 XRayInstrumentAttr *clone(ASTContext &C) const;
8689 void printPretty(raw_ostream &OS,
8690 const PrintingPolicy &Policy) const;
8691 const char *getSpelling() const;
8692 Spelling getSemanticSpelling() const {
8693 switch (SpellingListIndex) {
8694 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn326246/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 8694)
;
8695 case 0: return GNU_xray_always_instrument;
8696 case 1: return CXX11_clang_xray_always_instrument;
8697 case 2: return C2x_clang_xray_always_instrument;
8698 case 3: return GNU_xray_never_instrument;
8699 case 4: return CXX11_clang_xray_never_instrument;
8700 case 5: return C2x_clang_xray_never_instrument;
8701 }
8702 }
8703 bool alwaysXRayInstrument() const { return SpellingListIndex == 0 ||
8704 SpellingListIndex == 1 ||
8705 SpellingListIndex == 2; }
8706 bool neverXRayInstrument() const { return SpellingListIndex == 3 ||
8707 SpellingListIndex == 4 ||
8708 SpellingListIndex == 5; }
8709
8710
8711 static bool classof(const Attr *A) { return A->getKind() == attr::XRayInstrument; }
8712};
8713
8714class XRayLogArgsAttr : public InheritableAttr {
8715unsigned argumentCount;
8716
8717public:
8718 static XRayLogArgsAttr *CreateImplicit(ASTContext &Ctx, unsigned ArgumentCount, SourceRange Loc = SourceRange()) {
8719 auto *A = new (Ctx) XRayLogArgsAttr(Loc, Ctx, ArgumentCount, 0);
8720 A->setImplicit(true);
8721 return A;
8722 }
8723
8724 XRayLogArgsAttr(SourceRange R, ASTContext &Ctx
8725 , unsigned ArgumentCount
8726 , unsigned SI
8727 )
8728 : InheritableAttr(attr::XRayLogArgs, R, SI, false, false)
8729 , argumentCount(ArgumentCount)
8730 {
8731 }
8732
8733 XRayLogArgsAttr *clone(ASTContext &C) const;
8734 void printPretty(raw_ostream &OS,
8735 const PrintingPolicy &Policy) const;
8736 const char *getSpelling() const;
8737 unsigned getArgumentCount() const {
8738 return argumentCount;
8739 }
8740
8741
8742
8743 static bool classof(const Attr *A) { return A->getKind() == attr::XRayLogArgs; }
8744};
8745
8746#endif // LLVM_CLANG_ATTR_CLASSES_INC