clang 23.0.0git
DeclPrinter.cpp
Go to the documentation of this file.
1//===--- DeclPrinter.cpp - Printing implementation for Decl ASTs ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Decl::print method, which pretty prints the
10// AST back out to C/Objective-C/C++/Objective-C++ code.
11//
12//===----------------------------------------------------------------------===//
14#include "clang/AST/Attr.h"
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclCXX.h"
17#include "clang/AST/DeclObjC.h"
20#include "clang/AST/Expr.h"
21#include "clang/AST/ExprCXX.h"
23#include "clang/Basic/Module.h"
25#include "llvm/ADT/StringExtras.h"
26#include "llvm/Support/raw_ostream.h"
27using namespace clang;
28
29namespace {
30 class DeclPrinter : public DeclVisitor<DeclPrinter> {
31 raw_ostream &Out;
32 PrintingPolicy Policy;
33 const ASTContext &Context;
34 unsigned Indentation;
35 bool PrintInstantiation;
36
37 raw_ostream& Indent() { return Indent(Indentation); }
38 raw_ostream& Indent(unsigned Indentation);
39 void ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls);
40
41 void Print(AccessSpecifier AS);
42 void PrintConstructorInitializers(CXXConstructorDecl *CDecl,
43 std::string &Proto);
44
45 /// Print an Objective-C method type in parentheses.
46 ///
47 /// \param Quals The Objective-C declaration qualifiers.
48 /// \param T The type to print.
49 void PrintObjCMethodType(ASTContext &Ctx, Decl::ObjCDeclQualifier Quals,
50 QualType T);
51
52 void PrintObjCTypeParams(ObjCTypeParamList *Params);
53 void PrintOpenACCRoutineOnLambda(Decl *D);
54
55 public:
56 DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy,
57 const ASTContext &Context, unsigned Indentation = 0,
58 bool PrintInstantiation = false)
59 : Out(Out), Policy(Policy), Context(Context), Indentation(Indentation),
60 PrintInstantiation(PrintInstantiation) {}
61
62 void VisitDeclContext(DeclContext *DC, bool Indent = true);
63
64 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
65 void VisitTypedefDecl(TypedefDecl *D);
66 void VisitTypeAliasDecl(TypeAliasDecl *D);
67 void VisitEnumDecl(EnumDecl *D);
68 void VisitRecordDecl(RecordDecl *D);
69 void VisitEnumConstantDecl(EnumConstantDecl *D);
70 void VisitEmptyDecl(EmptyDecl *D);
71 void VisitFunctionDecl(FunctionDecl *D);
72 void VisitFriendDecl(FriendDecl *D);
73 void VisitFieldDecl(FieldDecl *D);
74 void VisitVarDecl(VarDecl *D);
75 void VisitLabelDecl(LabelDecl *D);
76 void VisitParmVarDecl(ParmVarDecl *D);
77 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
78 void VisitTopLevelStmtDecl(TopLevelStmtDecl *D);
79 void VisitImportDecl(ImportDecl *D);
80 void VisitStaticAssertDecl(StaticAssertDecl *D);
81 void VisitNamespaceDecl(NamespaceDecl *D);
82 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
83 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
84 void VisitCXXRecordDecl(CXXRecordDecl *D);
85 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
86 void VisitTemplateDecl(const TemplateDecl *D);
87 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
88 void VisitClassTemplateDecl(ClassTemplateDecl *D);
89 void VisitClassTemplateSpecializationDecl(
90 ClassTemplateSpecializationDecl *D);
91 void VisitClassTemplatePartialSpecializationDecl(
92 ClassTemplatePartialSpecializationDecl *D);
93 void VisitObjCMethodDecl(ObjCMethodDecl *D);
94 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
95 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
96 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
97 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
98 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
99 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
100 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
101 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
102 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
103 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
104 void VisitUsingDecl(UsingDecl *D);
105 void VisitUsingEnumDecl(UsingEnumDecl *D);
106 void VisitUsingShadowDecl(UsingShadowDecl *D);
107 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
108 void VisitOMPAllocateDecl(OMPAllocateDecl *D);
109 void VisitOMPRequiresDecl(OMPRequiresDecl *D);
110 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
111 void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
112 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
113 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP);
114 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP);
115 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *);
116 void VisitHLSLBufferDecl(HLSLBufferDecl *D);
117
118 void VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D);
119 void VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D);
120
121 void printTemplateParameters(const TemplateParameterList *Params,
122 bool OmitTemplateKW = false);
123 void printTemplateArguments(ArrayRef<TemplateArgument> Args,
124 const TemplateParameterList *Params);
125 void printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
126 const TemplateParameterList *Params);
127 enum class AttrPosAsWritten { Default = 0, Left, Right };
128 std::optional<std::string>
129 prettyPrintAttributes(const Decl *D,
130 AttrPosAsWritten Pos = AttrPosAsWritten::Default);
131
132 void prettyPrintPragmas(Decl *D);
133 void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
134 };
135}
136
137void Decl::print(raw_ostream &Out, unsigned Indentation,
138 bool PrintInstantiation) const {
139 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
140}
141
142void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
143 unsigned Indentation, bool PrintInstantiation) const {
144 DeclPrinter Printer(Out, Policy, getASTContext(), Indentation,
145 PrintInstantiation);
146 Printer.Visit(const_cast<Decl*>(this));
147}
148
149void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context,
150 bool OmitTemplateKW) const {
151 print(Out, Context, Context.getPrintingPolicy(), OmitTemplateKW);
152}
153
154void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context,
155 const PrintingPolicy &Policy,
156 bool OmitTemplateKW) const {
157 DeclPrinter Printer(Out, Policy, Context);
158 Printer.printTemplateParameters(this, OmitTemplateKW);
159}
160
162 // FIXME: This should be on the Type class!
163 QualType BaseType = T;
164 while (!BaseType->isSpecifierType()) {
165 if (const PointerType *PTy = BaseType->getAs<PointerType>())
166 BaseType = PTy->getPointeeType();
167 else if (const ObjCObjectPointerType *OPT =
168 BaseType->getAs<ObjCObjectPointerType>())
169 BaseType = OPT->getPointeeType();
170 else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
171 BaseType = BPy->getPointeeType();
172 else if (const ArrayType *ATy = dyn_cast<ArrayType>(BaseType))
173 BaseType = ATy->getElementType();
174 else if (const FunctionType *FTy = BaseType->getAs<FunctionType>())
175 BaseType = FTy->getReturnType();
176 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
177 BaseType = VTy->getElementType();
178 else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
179 BaseType = RTy->getPointeeType();
180 else if (const AutoType *ATy = BaseType->getAs<AutoType>())
181 BaseType = ATy->getDeducedType();
182 else if (const ParenType *PTy = BaseType->getAs<ParenType>())
183 BaseType = PTy->desugar();
184 else
185 // This must be a syntax error.
186 break;
187 }
188 return BaseType;
189}
190
192 if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
193 return TDD->getUnderlyingType();
194 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
195 return VD->getType();
196 return QualType();
197}
198
199void Decl::printGroup(Decl** Begin, unsigned NumDecls,
200 raw_ostream &Out, const PrintingPolicy &Policy,
201 unsigned Indentation) {
202 if (NumDecls == 1) {
203 (*Begin)->print(Out, Policy, Indentation);
204 return;
205 }
206
207 Decl** End = Begin + NumDecls;
208 if (isa<TagDecl>(*Begin))
209 ++Begin;
210
211 PrintingPolicy SubPolicy(Policy);
212
213 bool isFirst = true;
214 for ( ; Begin != End; ++Begin) {
215 if (isFirst) {
216 isFirst = false;
217 } else {
218 Out << ", ";
219 SubPolicy.SuppressSpecifiers = true;
220 }
221
222 (*Begin)->print(Out, SubPolicy, Indentation);
223 }
224}
225
226LLVM_DUMP_METHOD void DeclContext::dumpDeclContext() const {
227 // Get the translation unit
228 const DeclContext *DC = this;
229 while (!DC->isTranslationUnit())
230 DC = DC->getParent();
231
232 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
233 DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), Ctx, 0);
234 Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
235}
236
237raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
238 for (unsigned i = 0; i != Indentation; ++i)
239 Out << " ";
240 return Out;
241}
242
243static DeclPrinter::AttrPosAsWritten getPosAsWritten(const Attr *A,
244 const Decl *D) {
245 SourceLocation ALoc = A->getLoc();
246 SourceLocation DLoc = D->getLocation();
247 const ASTContext &C = D->getASTContext();
248 if (ALoc.isInvalid() || DLoc.isInvalid())
249 return DeclPrinter::AttrPosAsWritten::Left;
250
251 if (C.getSourceManager().isBeforeInTranslationUnit(ALoc, DLoc))
252 return DeclPrinter::AttrPosAsWritten::Left;
253
254 return DeclPrinter::AttrPosAsWritten::Right;
255}
256
257std::optional<std::string>
258DeclPrinter::prettyPrintAttributes(const Decl *D,
259 AttrPosAsWritten Pos /*=Default*/) {
260 if (Policy.SuppressDeclAttributes || !D->hasAttrs())
261 return std::nullopt;
262
263 std::string AttrStr;
264 llvm::raw_string_ostream AOut(AttrStr);
265 llvm::ListSeparator LS(" ");
266 for (auto *A : D->getAttrs()) {
267 if (A->isInherited() || A->isImplicit())
268 continue;
269 // Print out the keyword attributes, they aren't regular attributes.
270 if (Policy.PolishForDeclaration && !A->isKeywordAttribute())
271 continue;
272 switch (A->getKind()) {
273#define ATTR(X)
274#define PRAGMA_SPELLING_ATTR(X) case attr::X:
275#include "clang/Basic/AttrList.inc"
276 break;
277 default:
278 AttrPosAsWritten APos = getPosAsWritten(A, D);
279 assert(APos != AttrPosAsWritten::Default &&
280 "Default not a valid for an attribute location");
281 if (Pos == AttrPosAsWritten::Default || Pos == APos) {
282 AOut << LS;
283 A->printPretty(AOut, Policy);
284 }
285 break;
286 }
287 }
288 if (AttrStr.empty())
289 return std::nullopt;
290 return AttrStr;
291}
292
293void DeclPrinter::PrintOpenACCRoutineOnLambda(Decl *D) {
294 CXXRecordDecl *CXXRD = nullptr;
295 if (const auto *VD = dyn_cast<VarDecl>(D)) {
296 if (const auto *Init = VD->getInit())
297 CXXRD = Init->getType().isNull() ? nullptr
298 : Init->getType()->getAsCXXRecordDecl();
299 } else if (const auto *FD = dyn_cast<FieldDecl>(D)) {
300 CXXRD =
301 FD->getType().isNull() ? nullptr : FD->getType()->getAsCXXRecordDecl();
302 }
303
304 if (!CXXRD || !CXXRD->isLambda())
305 return;
306
307 if (const auto *Call = CXXRD->getLambdaCallOperator()) {
308 for (auto *A : Call->specific_attrs<OpenACCRoutineDeclAttr>()) {
309 A->printPretty(Out, Policy);
310 Indent();
311 }
312 }
313}
314
315void DeclPrinter::prettyPrintPragmas(Decl *D) {
316 if (Policy.PolishForDeclaration)
317 return;
318
319 PrintOpenACCRoutineOnLambda(D);
320
321 if (D->hasAttrs()) {
322 AttrVec &Attrs = D->getAttrs();
323 for (auto *A : Attrs) {
324 switch (A->getKind()) {
325#define ATTR(X)
326#define PRAGMA_SPELLING_ATTR(X) case attr::X:
327#include "clang/Basic/AttrList.inc"
328 A->printPretty(Out, Policy);
329 Indent();
330 break;
331 default:
332 break;
333 }
334 }
335 }
336}
337
338void DeclPrinter::printDeclType(QualType T, StringRef DeclName, bool Pack) {
339 // Normally, a PackExpansionType is written as T[3]... (for instance, as a
340 // template argument), but if it is the type of a declaration, the ellipsis
341 // is placed before the name being declared.
342 if (auto *PET = T->getAs<PackExpansionType>()) {
343 Pack = true;
344 T = PET->getPattern();
345 }
346 T.print(Out, Policy, (Pack ? "..." : "") + DeclName, Indentation);
347}
348
349void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
350 this->Indent();
351 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
352 Out << ";\n";
353 Decls.clear();
354
355}
356
357void DeclPrinter::Print(AccessSpecifier AS) {
358 const auto AccessSpelling = getAccessSpelling(AS);
359 if (AccessSpelling.empty())
360 llvm_unreachable("No access specifier!");
361 Out << AccessSpelling;
362}
363
364void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl,
365 std::string &Proto) {
366 bool HasInitializerList = false;
367 for (const auto *BMInitializer : CDecl->inits()) {
368 if (BMInitializer->isInClassMemberInitializer())
369 continue;
370 if (!BMInitializer->isWritten())
371 continue;
372
373 if (!HasInitializerList) {
374 Proto += " : ";
375 Out << Proto;
376 Proto.clear();
377 HasInitializerList = true;
378 } else
379 Out << ", ";
380
381 if (BMInitializer->isAnyMemberInitializer()) {
382 FieldDecl *FD = BMInitializer->getAnyMember();
383 Out << *FD;
384 } else if (BMInitializer->isDelegatingInitializer()) {
385 Out << CDecl->getNameAsString();
386 } else {
387 Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
388 }
389
390 if (Expr *Init = BMInitializer->getInit()) {
391 bool OutParens = !isa<InitListExpr>(Init);
392
393 if (OutParens)
394 Out << "(";
395
396 if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
397 Init = Tmp->getSubExpr();
398
399 Init = Init->IgnoreParens();
400
401 Expr *SimpleInit = nullptr;
402 Expr **Args = nullptr;
403 unsigned NumArgs = 0;
404 if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
405 Args = ParenList->getExprs();
406 NumArgs = ParenList->getNumExprs();
407 } else if (CXXConstructExpr *Construct =
408 dyn_cast<CXXConstructExpr>(Init)) {
409 Args = Construct->getArgs();
410 NumArgs = Construct->getNumArgs();
411 } else
412 SimpleInit = Init;
413
414 if (SimpleInit)
415 SimpleInit->printPretty(Out, nullptr, Policy, Indentation, "\n",
416 &Context);
417 else {
418 for (unsigned I = 0; I != NumArgs; ++I) {
419 assert(Args[I] != nullptr && "Expected non-null Expr");
420 if (isa<CXXDefaultArgExpr>(Args[I]))
421 break;
422
423 if (I)
424 Out << ", ";
425 Args[I]->printPretty(Out, nullptr, Policy, Indentation, "\n",
426 &Context);
427 }
428 }
429
430 if (OutParens)
431 Out << ")";
432 } else {
433 Out << "()";
434 }
435
436 if (BMInitializer->isPackExpansion())
437 Out << "...";
438 }
439}
440
441//----------------------------------------------------------------------------
442// Common C declarations
443//----------------------------------------------------------------------------
444
445void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
446 if (Policy.TerseOutput)
447 return;
448
449 if (Indent)
450 Indentation += Policy.Indentation;
451
453 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
454 D != DEnd; ++D) {
455
456 // Don't print ObjCIvarDecls, as they are printed when visiting the
457 // containing ObjCInterfaceDecl.
458 if (isa<ObjCIvarDecl>(*D))
459 continue;
460
461 // Skip over implicit declarations in pretty-printing mode.
462 if (D->isImplicit())
463 continue;
464
465 // Don't print implicit specializations, as they are printed when visiting
466 // corresponding templates.
467 if (auto FD = dyn_cast<FunctionDecl>(*D))
468 if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation &&
470 continue;
471
472 // The next bits of code handle stuff like "struct {int x;} a,b"; we're
473 // forced to merge the declarations because there's no other way to
474 // refer to the struct in question. When that struct is named instead, we
475 // also need to merge to avoid splitting off a stand-alone struct
476 // declaration that produces the warning ext_no_declarators in some
477 // contexts.
478 //
479 // This limited merging is safe without a bunch of other checks because it
480 // only merges declarations directly referring to the tag, not typedefs.
481 //
482 // Check whether the current declaration should be grouped with a previous
483 // non-free-standing tag declaration.
484 QualType CurDeclType = getDeclType(*D);
485 if (!Decls.empty() && !CurDeclType.isNull()) {
486 QualType BaseType = GetBaseType(CurDeclType);
487 if (const auto *TT = dyn_cast_or_null<TagType>(BaseType);
488 TT && TT->isTagOwned()) {
489 if (TT->getDecl() == Decls[0]) {
490 Decls.push_back(*D);
491 continue;
492 }
493 }
494 }
495
496 // If we have a merged group waiting to be handled, handle it now.
497 if (!Decls.empty())
498 ProcessDeclGroup(Decls);
499
500 // If the current declaration is not a free standing declaration, save it
501 // so we can merge it with the subsequent declaration(s) using it.
502 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->isFreeStanding()) {
503 Decls.push_back(*D);
504 continue;
505 }
506
507 if (isa<AccessSpecDecl>(*D)) {
508 Indentation -= Policy.Indentation;
509 this->Indent();
510 Print(D->getAccess());
511 Out << ":\n";
512 Indentation += Policy.Indentation;
513 continue;
514 }
515
516 this->Indent();
517 Visit(*D);
518
519 // FIXME: Need to be able to tell the DeclPrinter when
520 const char *Terminator = nullptr;
524 Terminator = nullptr;
526 Terminator = nullptr;
527 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
528 Terminator = nullptr;
529 else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
530 if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
531 Terminator = nullptr;
532 else
533 Terminator = ";";
534 } else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
535 if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
536 Terminator = nullptr;
537 else
538 Terminator = ";";
542 Terminator = nullptr;
543 else if (isa<EnumConstantDecl>(*D)) {
545 ++Next;
546 if (Next != DEnd)
547 Terminator = ",";
548 } else
549 Terminator = ";";
550
551 if (Terminator)
552 Out << Terminator;
553 if (!Policy.TerseOutput &&
554 ((isa<FunctionDecl>(*D) &&
555 cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
557 cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
558 ; // StmtPrinter already added '\n' after CompoundStmt.
559 else
560 Out << "\n";
561
562 // Declare target attribute is special one, natural spelling for the pragma
563 // assumes "ending" construct so print it here.
564 if (D->hasAttr<OMPDeclareTargetDeclAttr>())
565 Out << "#pragma omp end declare target\n";
566 }
567
568 if (!Decls.empty())
569 ProcessDeclGroup(Decls);
570
571 if (Indent)
572 Indentation -= Policy.Indentation;
573}
574
575void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
576 VisitDeclContext(D, false);
577}
578
579void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
580 if (!Policy.SuppressSpecifiers) {
581 Out << "typedef ";
582
583 if (D->isModulePrivate())
584 Out << "__module_private__ ";
585 }
587 Ty.print(Out, Policy, D->getName(), Indentation);
588
589 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
590 Out << ' ' << *Attrs;
591}
592
593void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
594 Out << "using " << *D;
595 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
596 Out << ' ' << *Attrs;
597 Out << " = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
598}
599
600void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
601 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
602 Out << "__module_private__ ";
603 Out << "enum";
604 if (D->isScoped()) {
605 if (D->isScopedUsingClassTag())
606 Out << " class";
607 else
608 Out << " struct";
609 }
610
611 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
612 Out << ' ' << *Attrs;
613
614 if (D->getDeclName())
615 Out << ' ' << D->getDeclName();
616
617 if (D->isFixed())
618 Out << " : " << D->getIntegerType().stream(Policy);
619
620 if (D->isCompleteDefinition()) {
621 Out << " {\n";
622 VisitDeclContext(D);
623 Indent() << "}";
624 }
625}
626
627void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
628 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
629 Out << "__module_private__ ";
630 Out << D->getKindName();
631
632 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
633 Out << ' ' << *Attrs;
634
635 if (D->getIdentifier())
636 Out << ' ' << *D;
637
638 if (D->isCompleteDefinition()) {
639 Out << " {\n";
640 VisitDeclContext(D);
641 Indent() << "}";
642 }
643}
644
645void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
646 Out << *D;
647 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
648 Out << ' ' << *Attrs;
649 if (Expr *Init = D->getInitExpr()) {
650 Out << " = ";
651 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
652 }
653}
654
655static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out,
656 PrintingPolicy &Policy, unsigned Indentation,
657 const ASTContext &Context) {
658 std::string Proto = "explicit";
659 llvm::raw_string_ostream EOut(Proto);
660 if (ES.getExpr()) {
661 EOut << "(";
662 ES.getExpr()->printPretty(EOut, nullptr, Policy, Indentation, "\n",
663 &Context);
664 EOut << ")";
665 }
666 EOut << " ";
667 Out << Proto;
668}
669
670void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
673 prettyPrintPragmas(D);
674 if (std::optional<std::string> Attrs =
675 prettyPrintAttributes(D, AttrPosAsWritten::Left))
676 Out << *Attrs << ' ';
677 }
678
680 Out << "template<> ";
681 else if (!D->getDescribedFunctionTemplate()) {
682 for (unsigned I = 0, NumTemplateParams = D->getNumTemplateParameterLists();
683 I < NumTemplateParams; ++I)
684 printTemplateParameters(D->getTemplateParameterList(I));
685 }
686
687 CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
688 CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
689 CXXDeductionGuideDecl *GuideDecl = dyn_cast<CXXDeductionGuideDecl>(D);
690 if (!Policy.SuppressSpecifiers) {
691 switch (D->getStorageClass()) {
692 case SC_None: break;
693 case SC_Extern: Out << "extern "; break;
694 case SC_Static: Out << "static "; break;
695 case SC_PrivateExtern: Out << "__private_extern__ "; break;
696 case SC_Auto: case SC_Register:
697 llvm_unreachable("invalid for functions");
698 }
699
700 if (D->isInlineSpecified()) Out << "inline ";
701 if (D->isVirtualAsWritten()) Out << "virtual ";
702 if (D->isModulePrivate()) Out << "__module_private__ ";
704 Out << "constexpr ";
705 if (D->isConsteval()) Out << "consteval ";
706 else if (D->isImmediateFunction())
707 Out << "immediate ";
709 if (ExplicitSpec.isSpecified())
710 printExplicitSpecifier(ExplicitSpec, Out, Policy, Indentation, Context);
711 }
712
713 PrintingPolicy SubPolicy(Policy);
714 SubPolicy.SuppressSpecifiers = false;
715 std::string Proto;
716
717 if (Policy.FullyQualifiedName) {
718 Proto += D->getQualifiedNameAsString();
719 } else {
720 llvm::raw_string_ostream OS(Proto);
721 if (!Policy.SuppressScope)
722 D->getQualifier().print(OS, Policy);
723 D->getNameInfo().printName(OS, Policy);
724 }
725
726 if (GuideDecl)
727 Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString();
729 llvm::raw_string_ostream POut(Proto);
730 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
731 const auto *TArgAsWritten = D->getTemplateSpecializationArgsAsWritten();
732 if (TArgAsWritten && !Policy.PrintAsCanonical)
733 TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(), nullptr);
734 else if (const TemplateArgumentList *TArgs =
736 TArgPrinter.printTemplateArguments(TArgs->asArray(), nullptr);
737 }
738
739 QualType Ty = D->getType();
740 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
741 Proto = '(' + Proto + ')';
742 Ty = PT->getInnerType();
743 }
744
745 if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
746 const FunctionProtoType *FT = nullptr;
747 if (D->hasWrittenPrototype())
748 FT = dyn_cast<FunctionProtoType>(AFT);
749
750 Proto += "(";
751 if (FT) {
752 llvm::raw_string_ostream POut(Proto);
753 DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
754 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
755 if (i) POut << ", ";
756 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
757 }
758
759 if (FT->isVariadic()) {
760 if (D->getNumParams()) POut << ", ";
761 POut << "...";
762 } else if (!D->getNumParams() && !Context.getLangOpts().CPlusPlus) {
763 // The function has a prototype, so it needs to retain the prototype
764 // in C.
765 POut << "void";
766 }
767 } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
768 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
769 if (i)
770 Proto += ", ";
771 Proto += D->getParamDecl(i)->getNameAsString();
772 }
773 }
774
775 Proto += ")";
776
777 if (FT) {
778 if (FT->isConst())
779 Proto += " const";
780 if (FT->isVolatile())
781 Proto += " volatile";
782 if (FT->isRestrict())
783 Proto += " restrict";
784
785 switch (FT->getRefQualifier()) {
786 case RQ_None:
787 break;
788 case RQ_LValue:
789 Proto += " &";
790 break;
791 case RQ_RValue:
792 Proto += " &&";
793 break;
794 }
795 }
796
797 if (FT && FT->hasDynamicExceptionSpec()) {
798 Proto += " throw(";
799 if (FT->getExceptionSpecType() == EST_MSAny)
800 Proto += "...";
801 else
802 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
803 if (I)
804 Proto += ", ";
805
806 Proto += FT->getExceptionType(I).getAsString(SubPolicy);
807 }
808 Proto += ")";
809 } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
810 Proto += " noexcept";
812 Proto += "(";
813 llvm::raw_string_ostream EOut(Proto);
814 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
815 Indentation, "\n", &Context);
816 Proto += ")";
817 }
818 }
819
820 if (CDecl) {
821 if (!Policy.TerseOutput)
822 PrintConstructorInitializers(CDecl, Proto);
823 } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
824 if (FT && FT->hasTrailingReturn()) {
825 if (!GuideDecl)
826 Out << "auto ";
827 Out << Proto << " -> ";
828 Proto.clear();
829 }
830 AFT->getReturnType().print(Out, Policy, Proto);
831 Proto.clear();
832 }
833 Out << Proto;
834
835 if (const AssociatedConstraint &TrailingRequiresClause =
837 Out << " requires ";
838 // FIXME: The printer could support printing expressions and types as if
839 // expanded by an index. Pass in the ArgumentPackSubstitutionIndex when
840 // that's supported.
841 TrailingRequiresClause.ConstraintExpr->printPretty(
842 Out, nullptr, SubPolicy, Indentation, "\n", &Context);
843 }
844 } else {
845 Ty.print(Out, Policy, Proto);
846 }
847
848 if (std::optional<std::string> Attrs =
849 prettyPrintAttributes(D, AttrPosAsWritten::Right))
850 Out << ' ' << *Attrs;
851
852 if (D->isPureVirtual())
853 Out << " = 0";
854 else if (D->isDeletedAsWritten()) {
855 Out << " = delete";
856 if (const StringLiteral *M = D->getDeletedMessage()) {
857 Out << "(";
858 M->outputString(Out);
859 Out << ")";
860 }
861 } else if (D->isExplicitlyDefaulted())
862 Out << " = default";
863 else if (D->doesThisDeclarationHaveABody()) {
864 if (!Policy.TerseOutput) {
865 if (!D->hasPrototype() && D->getNumParams()) {
866 // This is a K&R function definition, so we need to print the
867 // parameters.
868 Out << '\n';
869 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
870 Indentation += Policy.Indentation;
871 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
872 Indent();
873 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
874 Out << ";\n";
875 }
876 Indentation -= Policy.Indentation;
877 }
878
879 if (D->getBody())
880 D->getBody()->printPrettyControlled(Out, nullptr, SubPolicy, Indentation, "\n",
881 &Context);
882 } else {
883 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
884 Out << " {}";
885 }
886 }
887}
888
889void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
890 if (TypeSourceInfo *TSI = D->getFriendType()) {
891 unsigned NumTPLists = D->getFriendTypeNumTemplateParameterLists();
892 for (unsigned i = 0; i < NumTPLists; ++i)
893 printTemplateParameters(D->getFriendTypeTemplateParameterList(i));
894 Out << "friend ";
895 Out << TSI->getType().getAsString(Policy);
896 }
897 else if (FunctionDecl *FD =
898 dyn_cast<FunctionDecl>(D->getFriendDecl())) {
899 Out << "friend ";
900 VisitFunctionDecl(FD);
901 }
902 else if (FunctionTemplateDecl *FTD =
903 dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
904 Out << "friend ";
905 VisitFunctionTemplateDecl(FTD);
906 }
907 else if (ClassTemplateDecl *CTD =
908 dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
909 Out << "friend ";
910 VisitRedeclarableTemplateDecl(CTD);
911 }
912
913 if (D->isPackExpansion())
914 Out << "...";
915}
916
917void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
918 prettyPrintPragmas(D);
919 // FIXME: add printing of pragma attributes if required.
920 if (!Policy.SuppressSpecifiers && D->isMutable())
921 Out << "mutable ";
922 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
923 Out << "__module_private__ ";
924
926 stream(Policy, D->getName(), Indentation);
927
928 if (D->isBitField()) {
929 Out << " : ";
930 D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation, "\n",
931 &Context);
932 }
933
935 if (!Policy.SuppressInitializers && Init) {
937 Out << " ";
938 else
939 Out << " = ";
940 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
941 }
942 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
943 Out << ' ' << *Attrs;
944}
945
946void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
947 Out << *D << ":";
948}
949
950void DeclPrinter::VisitVarDecl(VarDecl *D) {
951 prettyPrintPragmas(D);
952
953 if (std::optional<std::string> Attrs =
954 prettyPrintAttributes(D, AttrPosAsWritten::Left))
955 Out << *Attrs << ' ';
956
957 if (const auto *Param = dyn_cast<ParmVarDecl>(D);
958 Param && Param->isExplicitObjectParameter())
959 Out << "this ";
960
962 ? D->getTypeSourceInfo()->getType()
964
965 if (!Policy.SuppressSpecifiers) {
967 if (SC != SC_None)
969
970 switch (D->getTSCSpec()) {
971 case TSCS_unspecified:
972 break;
973 case TSCS___thread:
974 Out << "__thread ";
975 break;
977 Out << "_Thread_local ";
978 break;
980 Out << "thread_local ";
981 break;
982 }
983
984 if (D->isModulePrivate())
985 Out << "__module_private__ ";
986
987 if (D->isConstexpr()) {
988 Out << "constexpr ";
989 T.removeLocalConst();
990 }
991 }
992
993 printDeclType(T, (isa<ParmVarDecl>(D) && Policy.CleanUglifiedParameters &&
994 D->getIdentifier())
996 : D->getName());
997
998 if (std::optional<std::string> Attrs =
999 prettyPrintAttributes(D, AttrPosAsWritten::Right))
1000 Out << ' ' << *Attrs;
1001
1002 Expr *Init = D->getInit();
1003 if (!Policy.SuppressInitializers && Init) {
1004 bool ImplicitInit = false;
1005 if (D->isCXXForRangeDecl()) {
1006 // FIXME: We should print the range expression instead.
1007 ImplicitInit = true;
1008 } else if (CXXConstructExpr *Construct =
1009 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
1010 if (D->getInitStyle() == VarDecl::CallInit &&
1011 !Construct->isListInitialization()) {
1012 ImplicitInit = Construct->getNumArgs() == 0 ||
1013 Construct->getArg(0)->isDefaultArgument();
1014 }
1015 }
1016 if (!ImplicitInit) {
1018 Out << "(";
1019 else if (D->getInitStyle() == VarDecl::CInit) {
1020 Out << " = ";
1021 }
1022 PrintingPolicy SubPolicy(Policy);
1023 SubPolicy.SuppressSpecifiers = false;
1024 Init->printPretty(Out, nullptr, SubPolicy, Indentation, "\n", &Context);
1026 Out << ")";
1027 }
1028 }
1029}
1030
1031void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
1032 VisitVarDecl(D);
1033}
1034
1035void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
1036 Out << "__asm (";
1037 D->getAsmStringExpr()->printPretty(Out, nullptr, Policy, Indentation, "\n",
1038 &Context);
1039 Out << ")";
1040}
1041
1042void DeclPrinter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) {
1043 assert(D->getStmt());
1044 D->getStmt()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1045}
1046
1047void DeclPrinter::VisitImportDecl(ImportDecl *D) {
1048 Out << "@import " << D->getImportedModule()->getFullModuleName()
1049 << ";\n";
1050}
1051
1052void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
1053 Out << "static_assert(";
1054 D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation, "\n",
1055 &Context);
1056 if (Expr *E = D->getMessage()) {
1057 Out << ", ";
1058 E->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1059 }
1060 Out << ")";
1061}
1062
1063//----------------------------------------------------------------------------
1064// C++ declarations
1065//----------------------------------------------------------------------------
1066void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
1067 if (D->isInline())
1068 Out << "inline ";
1069
1070 Out << "namespace ";
1071 if (D->getDeclName())
1072 Out << D->getDeclName() << ' ';
1073 Out << "{\n";
1074
1075 VisitDeclContext(D);
1076 Indent() << "}";
1077}
1078
1079void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
1080 Out << "using namespace ";
1081 D->getQualifier().print(Out, Policy);
1083}
1084
1085void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
1086 Out << "namespace " << *D << " = ";
1087 D->getQualifier().print(Out, Policy);
1088 Out << *D->getAliasedNamespace();
1089}
1090
1091void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
1092 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
1093 Out << *Attrs;
1094}
1095
1096void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
1097 // FIXME: add printing of pragma attributes if required.
1098 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
1099 Out << "__module_private__ ";
1100
1101 Out << D->getKindName() << ' ';
1102
1103 if (std::optional<std::string> Attrs =
1104 prettyPrintAttributes(D, AttrPosAsWritten::Left))
1105 Out << *Attrs << ' ';
1106
1107 if (D->getIdentifier()) {
1108 D->getQualifier().print(Out, Policy);
1109 Out << *D;
1110
1111 if (auto *S = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1112 const TemplateParameterList *TParams =
1113 S->getSpecializedTemplate()->getTemplateParameters();
1114 const ASTTemplateArgumentListInfo *TArgAsWritten =
1115 S->getTemplateArgsAsWritten();
1116 if (TArgAsWritten && !Policy.PrintAsCanonical)
1117 printTemplateArguments(TArgAsWritten->arguments(), TParams);
1118 else
1119 printTemplateArguments(S->getTemplateArgs().asArray(), TParams);
1120 }
1121 }
1122
1123 if (std::optional<std::string> Attrs =
1124 prettyPrintAttributes(D, AttrPosAsWritten::Right))
1125 Out << ' ' << *Attrs;
1126
1127 if (D->isCompleteDefinition()) {
1128 Out << ' ';
1129 // Print the base classes
1130 if (D->getNumBases()) {
1131 Out << ": ";
1132 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
1133 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
1134 if (Base != D->bases_begin())
1135 Out << ", ";
1136
1137 if (Base->isVirtual())
1138 Out << "virtual ";
1139
1140 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
1141 if (AS != AS_none) {
1142 Print(AS);
1143 Out << " ";
1144 }
1145 Out << Base->getType().getAsString(Policy);
1146
1147 if (Base->isPackExpansion())
1148 Out << "...";
1149 }
1150 Out << ' ';
1151 }
1152
1153 // Print the class definition
1154 // FIXME: Doesn't print access specifiers, e.g., "public:"
1155 if (Policy.TerseOutput) {
1156 Out << "{}";
1157 } else {
1158 Out << "{\n";
1159 VisitDeclContext(D);
1160 Indent() << "}";
1161 }
1162 }
1163}
1164
1165void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1166 const char *l;
1168 l = "C";
1169 else {
1171 "unknown language in linkage specification");
1172 l = "C++";
1173 }
1174
1175 Out << "extern \"" << l << "\" ";
1176 if (D->hasBraces()) {
1177 Out << "{\n";
1178 VisitDeclContext(D);
1179 Indent() << "}";
1180 } else
1181 Visit(*D->decls_begin());
1182}
1183
1184void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params,
1185 bool OmitTemplateKW) {
1186 assert(Params);
1187
1188 // Don't print invented template parameter lists.
1189 if (!Params->empty() && Params->getParam(0)->isImplicit())
1190 return;
1191
1192 if (!OmitTemplateKW)
1193 Out << "template ";
1194 Out << '<';
1195
1196 bool NeedComma = false;
1197 for (const Decl *Param : *Params) {
1198 if (Param->isImplicit())
1199 continue;
1200
1201 if (NeedComma)
1202 Out << ", ";
1203 else
1204 NeedComma = true;
1205
1206 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
1207 VisitTemplateTypeParmDecl(TTP);
1208 } else if (auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1209 VisitNonTypeTemplateParmDecl(NTTP);
1210 } else if (auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1211 VisitTemplateTemplateParmDecl(TTPD);
1212 }
1213 }
1214
1215 Out << '>';
1216
1217 if (const Expr *RequiresClause = Params->getRequiresClause()) {
1218 Out << " requires ";
1219 RequiresClause->printPretty(Out, nullptr, Policy, Indentation, "\n",
1220 &Context);
1221 }
1222
1223 if (!OmitTemplateKW)
1224 Out << ' ';
1225}
1226
1227void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args,
1228 const TemplateParameterList *Params) {
1229 Out << "<";
1230 for (size_t I = 0, E = Args.size(); I < E; ++I) {
1231 if (I)
1232 Out << ", ";
1233 if (!Params)
1234 Args[I].print(Policy, Out, /*IncludeType*/ true);
1235 else
1236 Args[I].print(Policy, Out,
1238 Policy, Params, I));
1239 }
1240 Out << ">";
1241}
1242
1243void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
1244 const TemplateParameterList *Params) {
1245 Out << "<";
1246 for (size_t I = 0, E = Args.size(); I < E; ++I) {
1247 if (I)
1248 Out << ", ";
1249 if (!Params)
1250 Args[I].getArgument().print(Policy, Out, /*IncludeType*/ true);
1251 else
1252 Args[I].getArgument().print(
1253 Policy, Out,
1255 I));
1256 }
1257 Out << ">";
1258}
1259
1260void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
1261 printTemplateParameters(D->getTemplateParameters());
1262
1263 if (const TemplateTemplateParmDecl *TTP =
1264 dyn_cast<TemplateTemplateParmDecl>(D)) {
1265 if (TTP->wasDeclaredWithTypename())
1266 Out << "typename";
1267 else
1268 Out << "class";
1269
1270 if (TTP->isParameterPack())
1271 Out << " ...";
1272 else if (TTP->getDeclName())
1273 Out << ' ';
1274
1275 if (TTP->getDeclName()) {
1276 if (Policy.CleanUglifiedParameters && TTP->getIdentifier())
1277 Out << TTP->getIdentifier()->deuglifiedName();
1278 else
1279 Out << TTP->getDeclName();
1280 }
1281 } else if (auto *TD = D->getTemplatedDecl())
1282 Visit(TD);
1283 else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) {
1284 Out << "concept " << Concept->getName() << " = " ;
1285 Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, Indentation,
1286 "\n", &Context);
1287 }
1288}
1289
1290void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1291 prettyPrintPragmas(D->getTemplatedDecl());
1292 // Print any leading template parameter lists.
1293 if (const FunctionDecl *FD = D->getTemplatedDecl()) {
1294 for (unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists();
1295 I < NumTemplateParams; ++I)
1296 printTemplateParameters(FD->getTemplateParameterList(I));
1297 }
1298 VisitRedeclarableTemplateDecl(D);
1299 // Declare target attribute is special one, natural spelling for the pragma
1300 // assumes "ending" construct so print it here.
1301 if (D->getTemplatedDecl()->hasAttr<OMPDeclareTargetDeclAttr>())
1302 Out << "#pragma omp end declare target\n";
1303
1304 // Never print "instantiations" for deduction guides (they don't really
1305 // have them).
1306 if (PrintInstantiation &&
1308 FunctionDecl *PrevDecl = D->getTemplatedDecl();
1309 const FunctionDecl *Def;
1310 if (PrevDecl->isDefined(Def) && Def != PrevDecl)
1311 return;
1312 for (auto *I : D->specializations())
1313 if (I->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) {
1314 if (!PrevDecl->isThisDeclarationADefinition())
1315 Out << ";\n";
1316 Indent();
1317 prettyPrintPragmas(I);
1318 Visit(I);
1319 }
1320 }
1321}
1322
1323void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1324 VisitRedeclarableTemplateDecl(D);
1325
1326 if (PrintInstantiation) {
1327 for (auto *I : D->specializations())
1328 if (I->getSpecializationKind() == TSK_ImplicitInstantiation) {
1330 Out << ";";
1331 Out << "\n";
1332 Indent();
1333 Visit(I);
1334 }
1335 }
1336}
1337
1338void DeclPrinter::VisitClassTemplateSpecializationDecl(
1340 Out << "template<> ";
1341 VisitCXXRecordDecl(D);
1342}
1343
1344void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1346 printTemplateParameters(D->getTemplateParameters());
1347 VisitCXXRecordDecl(D);
1348}
1349
1350//----------------------------------------------------------------------------
1351// Objective-C declarations
1352//----------------------------------------------------------------------------
1353
1354void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx,
1356 QualType T) {
1357 Out << '(';
1359 Out << "in ";
1361 Out << "inout ";
1363 Out << "out ";
1365 Out << "bycopy ";
1367 Out << "byref ";
1369 Out << "oneway ";
1371 if (auto nullability = AttributedType::stripOuterNullability(T))
1372 Out << getNullabilitySpelling(*nullability, true) << ' ';
1373 }
1374
1376 Out << ')';
1377}
1378
1379void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) {
1380 Out << "<";
1381 unsigned First = true;
1382 for (auto *Param : *Params) {
1383 if (First) {
1384 First = false;
1385 } else {
1386 Out << ", ";
1387 }
1388
1389 switch (Param->getVariance()) {
1391 break;
1392
1394 Out << "__covariant ";
1395 break;
1396
1398 Out << "__contravariant ";
1399 break;
1400 }
1401
1402 Out << Param->getDeclName();
1403
1404 if (Param->hasExplicitBound()) {
1405 Out << " : " << Param->getUnderlyingType().getAsString(Policy);
1406 }
1407 }
1408 Out << ">";
1409}
1410
1411void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
1412 if (OMD->isInstanceMethod())
1413 Out << "- ";
1414 else
1415 Out << "+ ";
1416 if (!OMD->getReturnType().isNull()) {
1417 PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(),
1418 OMD->getReturnType());
1419 }
1420
1421 std::string name = OMD->getSelector().getAsString();
1422 std::string::size_type pos, lastPos = 0;
1423 for (const auto *PI : OMD->parameters()) {
1424 // FIXME: selector is missing here!
1425 pos = name.find_first_of(':', lastPos);
1426 if (lastPos != 0)
1427 Out << " ";
1428 Out << name.substr(lastPos, pos - lastPos) << ':';
1429 PrintObjCMethodType(OMD->getASTContext(),
1430 PI->getObjCDeclQualifier(),
1431 PI->getType());
1432 Out << *PI;
1433 lastPos = pos + 1;
1434 }
1435
1436 if (OMD->parameters().empty())
1437 Out << name;
1438
1439 if (OMD->isVariadic())
1440 Out << ", ...";
1441
1442 if (std::optional<std::string> Attrs = prettyPrintAttributes(OMD))
1443 Out << ' ' << *Attrs;
1444
1445 if (OMD->getBody() && !Policy.TerseOutput) {
1446 Out << ' ';
1447 OMD->getBody()->printPretty(Out, nullptr, Policy, Indentation, "\n",
1448 &Context);
1449 }
1450 else if (Policy.PolishForDeclaration)
1451 Out << ';';
1452}
1453
1454void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
1455 std::string I = OID->getNameAsString();
1456 ObjCInterfaceDecl *SID = OID->getSuperClass();
1457
1458 bool eolnOut = false;
1459 if (SID)
1460 Out << "@implementation " << I << " : " << *SID;
1461 else
1462 Out << "@implementation " << I;
1463
1464 if (OID->ivar_size() > 0) {
1465 Out << "{\n";
1466 eolnOut = true;
1467 Indentation += Policy.Indentation;
1468 for (const auto *I : OID->ivars()) {
1469 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1470 getAsString(Policy) << ' ' << *I << ";\n";
1471 }
1472 Indentation -= Policy.Indentation;
1473 Out << "}\n";
1474 } else if (SID || !OID->decls().empty()) {
1475 Out << "\n";
1476 eolnOut = true;
1477 }
1478 VisitDeclContext(OID, false);
1479 if (!eolnOut)
1480 Out << "\n";
1481 Out << "@end";
1482}
1483
1484void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
1485 std::string I = OID->getNameAsString();
1486 ObjCInterfaceDecl *SID = OID->getSuperClass();
1487
1488 if (!OID->isThisDeclarationADefinition()) {
1489 Out << "@class " << I;
1490
1491 if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1492 PrintObjCTypeParams(TypeParams);
1493 }
1494
1495 Out << ";";
1496 return;
1497 }
1498 bool eolnOut = false;
1499 if (std::optional<std::string> Attrs = prettyPrintAttributes(OID))
1500 Out << *Attrs << "\n";
1501
1502 Out << "@interface " << I;
1503
1504 if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1505 PrintObjCTypeParams(TypeParams);
1506 }
1507
1508 if (SID)
1509 Out << " : " << QualType(OID->getSuperClassType(), 0).getAsString(Policy);
1510
1511 // Protocols?
1512 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
1513 if (!Protocols.empty()) {
1514 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1515 E = Protocols.end(); I != E; ++I)
1516 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1517 Out << "> ";
1518 }
1519
1520 if (OID->ivar_size() > 0) {
1521 Out << "{\n";
1522 eolnOut = true;
1523 Indentation += Policy.Indentation;
1524 for (const auto *I : OID->ivars()) {
1525 Indent() << I->getASTContext()
1526 .getUnqualifiedObjCPointerType(I->getType())
1527 .getAsString(Policy) << ' ' << *I << ";\n";
1528 }
1529 Indentation -= Policy.Indentation;
1530 Out << "}\n";
1531 } else if (SID || !OID->decls().empty()) {
1532 Out << "\n";
1533 eolnOut = true;
1534 }
1535
1536 VisitDeclContext(OID, false);
1537 if (!eolnOut)
1538 Out << "\n";
1539 Out << "@end";
1540 // FIXME: implement the rest...
1541}
1542
1543void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
1544 if (!PID->isThisDeclarationADefinition()) {
1545 Out << "@protocol " << *PID << ";\n";
1546 return;
1547 }
1548 // Protocols?
1549 const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
1550 if (!Protocols.empty()) {
1551 Out << "@protocol " << *PID;
1552 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1553 E = Protocols.end(); I != E; ++I)
1554 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1555 Out << ">\n";
1556 } else
1557 Out << "@protocol " << *PID << '\n';
1558 VisitDeclContext(PID, false);
1559 Out << "@end";
1560}
1561
1562void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
1563 Out << "@implementation ";
1564 if (const auto *CID = PID->getClassInterface())
1565 Out << *CID;
1566 else
1567 Out << "<<error-type>>";
1568 Out << '(' << *PID << ")\n";
1569
1570 VisitDeclContext(PID, false);
1571 Out << "@end";
1572 // FIXME: implement the rest...
1573}
1574
1575void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
1576 Out << "@interface ";
1577 if (const auto *CID = PID->getClassInterface())
1578 Out << *CID;
1579 else
1580 Out << "<<error-type>>";
1581 if (auto TypeParams = PID->getTypeParamList()) {
1582 PrintObjCTypeParams(TypeParams);
1583 }
1584 Out << "(" << *PID << ")\n";
1585 if (PID->ivar_size() > 0) {
1586 Out << "{\n";
1587 Indentation += Policy.Indentation;
1588 for (const auto *I : PID->ivars())
1589 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1590 getAsString(Policy) << ' ' << *I << ";\n";
1591 Indentation -= Policy.Indentation;
1592 Out << "}\n";
1593 }
1594
1595 VisitDeclContext(PID, false);
1596 Out << "@end";
1597
1598 // FIXME: implement the rest...
1599}
1600
1601void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
1602 Out << "@compatibility_alias " << *AID
1603 << ' ' << *AID->getClassInterface() << ";\n";
1604}
1605
1606/// PrintObjCPropertyDecl - print a property declaration.
1607///
1608/// Print attributes in the following order:
1609/// - class
1610/// - nonatomic | atomic
1611/// - assign | retain | strong | copy | weak | unsafe_unretained
1612/// - readwrite | readonly
1613/// - getter & setter
1614/// - nullability
1615void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1617 Out << "@required\n";
1619 Out << "@optional\n";
1620
1621 QualType T = PDecl->getType();
1622
1623 Out << "@property";
1625 bool first = true;
1626 Out << "(";
1628 Out << (first ? "" : ", ") << "class";
1629 first = false;
1630 }
1631
1633 Out << (first ? "" : ", ") << "direct";
1634 first = false;
1635 }
1636
1637 if (PDecl->getPropertyAttributes() &
1639 Out << (first ? "" : ", ") << "nonatomic";
1640 first = false;
1641 }
1643 Out << (first ? "" : ", ") << "atomic";
1644 first = false;
1645 }
1646
1648 Out << (first ? "" : ", ") << "assign";
1649 first = false;
1650 }
1652 Out << (first ? "" : ", ") << "retain";
1653 first = false;
1654 }
1655
1657 Out << (first ? "" : ", ") << "strong";
1658 first = false;
1659 }
1661 Out << (first ? "" : ", ") << "copy";
1662 first = false;
1663 }
1665 Out << (first ? "" : ", ") << "weak";
1666 first = false;
1667 }
1668 if (PDecl->getPropertyAttributes() &
1670 Out << (first ? "" : ", ") << "unsafe_unretained";
1671 first = false;
1672 }
1673
1674 if (PDecl->getPropertyAttributes() &
1676 Out << (first ? "" : ", ") << "readwrite";
1677 first = false;
1678 }
1680 Out << (first ? "" : ", ") << "readonly";
1681 first = false;
1682 }
1683
1685 Out << (first ? "" : ", ") << "getter = ";
1686 PDecl->getGetterName().print(Out);
1687 first = false;
1688 }
1690 Out << (first ? "" : ", ") << "setter = ";
1691 PDecl->getSetterName().print(Out);
1692 first = false;
1693 }
1694
1695 if (PDecl->getPropertyAttributes() &
1697 if (auto nullability = AttributedType::stripOuterNullability(T)) {
1698 if (*nullability == NullabilityKind::Unspecified &&
1699 (PDecl->getPropertyAttributes() &
1701 Out << (first ? "" : ", ") << "null_resettable";
1702 } else {
1703 Out << (first ? "" : ", ")
1704 << getNullabilitySpelling(*nullability, true);
1705 }
1706 first = false;
1707 }
1708 }
1709
1710 (void) first; // Silence dead store warning due to idiomatic code.
1711 Out << ")";
1712 }
1713 std::string TypeStr = PDecl->getASTContext().getUnqualifiedObjCPointerType(T).
1714 getAsString(Policy);
1715 Out << ' ' << TypeStr;
1716 if (!StringRef(TypeStr).ends_with("*"))
1717 Out << ' ';
1718 Out << *PDecl;
1719 if (Policy.PolishForDeclaration)
1720 Out << ';';
1721}
1722
1723void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1725 Out << "@synthesize ";
1726 else
1727 Out << "@dynamic ";
1728 Out << *PID->getPropertyDecl();
1729 if (PID->getPropertyIvarDecl())
1730 Out << '=' << *PID->getPropertyIvarDecl();
1731}
1732
1733void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1734 if (!D->isAccessDeclaration())
1735 Out << "using ";
1736 if (D->hasTypename())
1737 Out << "typename ";
1738 D->getQualifier().print(Out, Policy);
1739
1740 // Use the correct record name when the using declaration is used for
1741 // inheriting constructors.
1742 for (const auto *Shadow : D->shadows()) {
1743 if (const auto *ConstructorShadow =
1744 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1745 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1746 Out << *ConstructorShadow->getNominatedBaseClass();
1747 return;
1748 }
1749 }
1750 Out << *D;
1751}
1752
1753void DeclPrinter::VisitUsingEnumDecl(UsingEnumDecl *D) {
1754 Out << "using enum " << D->getEnumDecl();
1755}
1756
1757void
1758DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1759 Out << "using typename ";
1760 D->getQualifier().print(Out, Policy);
1761 Out << D->getDeclName();
1762}
1763
1764void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1765 if (!D->isAccessDeclaration())
1766 Out << "using ";
1767 D->getQualifier().print(Out, Policy);
1768 Out << D->getDeclName();
1769}
1770
1771void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1772 // ignore
1773}
1774
1775void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1776 Out << "#pragma omp threadprivate";
1777 if (!D->varlist_empty()) {
1779 E = D->varlist_end();
1780 I != E; ++I) {
1781 Out << (I == D->varlist_begin() ? '(' : ',');
1782 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1783 ND->printQualifiedName(Out);
1784 }
1785 Out << ")";
1786 }
1787}
1788
1789void DeclPrinter::VisitHLSLBufferDecl(HLSLBufferDecl *D) {
1790 if (D->isCBuffer())
1791 Out << "cbuffer ";
1792 else
1793 Out << "tbuffer ";
1794
1795 Out << *D;
1796
1797 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
1798 Out << ' ' << *Attrs;
1799
1800 Out << " {\n";
1801 VisitDeclContext(D);
1802 Indent() << "}";
1803}
1804
1805void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
1806 Out << "#pragma omp allocate";
1807 if (!D->varlist_empty()) {
1809 E = D->varlist_end();
1810 I != E; ++I) {
1811 Out << (I == D->varlist_begin() ? '(' : ',');
1812 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1813 ND->printQualifiedName(Out);
1814 }
1815 Out << ")";
1816 }
1817 if (!D->clauselist_empty()) {
1818 OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
1819 for (OMPClause *C : D->clauselists()) {
1820 Out << " ";
1821 Printer.Visit(C);
1822 }
1823 }
1824}
1825
1826void DeclPrinter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
1827 Out << "#pragma omp requires ";
1828 if (!D->clauselist_empty()) {
1829 OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
1830 for (auto I = D->clauselist_begin(), E = D->clauselist_end(); I != E; ++I)
1831 Printer.Visit(*I);
1832 }
1833}
1834
1835void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1836 if (!D->isInvalidDecl()) {
1837 Out << "#pragma omp declare reduction (";
1839 const char *OpName =
1841 assert(OpName && "not an overloaded operator");
1842 Out << OpName;
1843 } else {
1844 assert(D->getDeclName().isIdentifier());
1845 D->printName(Out, Policy);
1846 }
1847 Out << " : ";
1848 D->getType().print(Out, Policy);
1849 Out << " : ";
1850 D->getCombiner()->printPretty(Out, nullptr, Policy, 0, "\n", &Context);
1851 Out << ")";
1852 if (auto *Init = D->getInitializer()) {
1853 Out << " initializer(";
1854 switch (D->getInitializerKind()) {
1856 Out << "omp_priv(";
1857 break;
1859 Out << "omp_priv = ";
1860 break;
1862 break;
1863 }
1864 Init->printPretty(Out, nullptr, Policy, 0, "\n", &Context);
1866 Out << ")";
1867 Out << ")";
1868 }
1869 }
1870}
1871
1872void DeclPrinter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
1873 if (!D->isInvalidDecl()) {
1874 Out << "#pragma omp declare mapper (";
1875 D->printName(Out, Policy);
1876 Out << " : ";
1877 D->getType().print(Out, Policy);
1878 Out << " ";
1879 Out << D->getVarName();
1880 Out << ")";
1881 if (!D->clauselist_empty()) {
1882 OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
1883 for (auto *C : D->clauselists()) {
1884 Out << " ";
1885 Printer.Visit(C);
1886 }
1887 }
1888 }
1889}
1890
1891void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
1892 D->getInit()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1893}
1894
1895void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) {
1896 if (const TypeConstraint *TC = TTP->getTypeConstraint())
1897 TC->print(Out, Policy);
1898 else if (TTP->wasDeclaredWithTypename())
1899 Out << "typename";
1900 else
1901 Out << "class";
1902
1903 if (TTP->isParameterPack())
1904 Out << " ...";
1905 else if (TTP->getDeclName())
1906 Out << ' ';
1907
1908 if (TTP->getDeclName()) {
1909 if (Policy.CleanUglifiedParameters && TTP->getIdentifier())
1910 Out << TTP->getIdentifier()->deuglifiedName();
1911 else
1912 Out << TTP->getDeclName();
1913 }
1914
1915 if (TTP->hasDefaultArgument() && !TTP->defaultArgumentWasInherited()) {
1916 Out << " = ";
1917 TTP->getDefaultArgument().getArgument().print(Policy, Out,
1918 /*IncludeType=*/false);
1919 }
1920}
1921
1922void DeclPrinter::VisitNonTypeTemplateParmDecl(
1923 const NonTypeTemplateParmDecl *NTTP) {
1924 StringRef Name;
1925 if (IdentifierInfo *II = NTTP->getIdentifier())
1926 Name =
1927 Policy.CleanUglifiedParameters ? II->deuglifiedName() : II->getName();
1928 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
1929
1930 if (NTTP->hasDefaultArgument() && !NTTP->defaultArgumentWasInherited()) {
1931 Out << " = ";
1932 NTTP->getDefaultArgument().getArgument().print(Policy, Out,
1933 /*IncludeType=*/false);
1934 }
1935}
1936
1937void DeclPrinter::VisitTemplateTemplateParmDecl(
1938 const TemplateTemplateParmDecl *TTPD) {
1939 VisitTemplateDecl(TTPD);
1940 if (TTPD->hasDefaultArgument() && !TTPD->defaultArgumentWasInherited()) {
1941 Out << " = ";
1942 TTPD->getDefaultArgument().getArgument().print(Policy, Out,
1943 /*IncludeType=*/false);
1944 }
1945}
1946
1947void DeclPrinter::VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D) {
1948 if (!D->isInvalidDecl()) {
1949 Out << "#pragma acc declare";
1950 if (!D->clauses().empty()) {
1951 Out << ' ';
1952 OpenACCClausePrinter Printer(Out, Policy);
1953 Printer.VisitClauseList(D->clauses());
1954 }
1955 }
1956}
1957void DeclPrinter::VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D) {
1958 if (!D->isInvalidDecl()) {
1959 Out << "#pragma acc routine";
1960
1961 Out << "(";
1962
1963 // The referenced function was named here, but this makes us tolerant of
1964 // errors.
1965 if (D->getFunctionReference())
1966 D->getFunctionReference()->printPretty(Out, nullptr, Policy, Indentation,
1967 "\n", &Context);
1968 else
1969 Out << "<error>";
1970
1971 Out << ")";
1972
1973 if (!D->clauses().empty()) {
1974 Out << ' ';
1975 OpenACCClausePrinter Printer(Out, Policy);
1976 Printer.VisitClauseList(D->clauses());
1977 }
1978 }
1979}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static DeclPrinter::AttrPosAsWritten getPosAsWritten(const Attr *A, const Decl *D)
static QualType getDeclType(Decl *D)
static QualType GetBaseType(QualType T)
static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, PrintingPolicy &Policy, unsigned Indentation, const ASTContext &Context)
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
FormatToken * Next
The next token in the unwrapped line.
Defines the clang::Module class, which describes a module in the source code.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:220
const LangOptions & getLangOpts() const
Definition ASTContext.h:944
const clang::PrintingPolicy & getPrintingPolicy() const
Definition ASTContext.h:843
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3723
Attr - This represents one attribute.
Definition Attr.h:46
SourceLocation getLoc() const
shadow_range shadows() const
Definition DeclCXX.h:3558
Pointer to a block type.
Definition TypeBase.h:3543
Represents a call to a C++ constructor.
Definition ExprCXX.h:1548
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2939
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1979
TemplateDecl * getDeducedTemplate() const
Get the template for which this guide performs deduction.
Definition DeclCXX.h:2044
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
CXXBaseSpecifier * base_class_iterator
Iterator that traverses the base classes of a class.
Definition DeclCXX.h:517
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition DeclCXX.h:1018
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition DeclCXX.cpp:1736
Declaration of a class template.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
spec_range specializations() const
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
decl_iterator - Iterates through the declarations stored within this context.
Definition DeclBase.h:2330
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1449
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2109
bool isTranslationUnit() const
Definition DeclBase.h:2185
DeclContext(Decl::Kind K)
void dumpDeclContext() const
decl_iterator decls_end() const
Definition DeclBase.h:2375
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition DeclBase.h:2373
decl_iterator decls_begin() const
A simple visitor class that helps create declaration visitors.
Definition DeclVisitor.h:68
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Decl()=delete
bool hasAttrs() const
Definition DeclBase.h:518
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:593
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
Definition DeclBase.h:198
@ OBJC_TQ_CSNullability
The nullability qualifier is set when the nullability of the result or parameter was expressed via a ...
Definition DeclBase.h:210
bool isInvalidDecl() const
Definition DeclBase.h:588
SourceLocation getLocation() const
Definition DeclBase.h:439
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
AccessSpecifier getAccess() const
Definition DeclBase.h:507
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
AttrVec & getAttrs()
Definition DeclBase.h:524
bool hasAttr() const
Definition DeclBase.h:577
std::string getAsString() const
Retrieve the human-readable string for this name.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
NameKind getNameKind() const
Determine what kind of name this is.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
TemplateParameterList * getTemplateParameterList(unsigned index) const
Definition Decl.h:866
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:855
unsigned getNumTemplateParameterLists() const
Definition Decl.h:862
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:837
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
Represents an empty-declaration.
Definition Decl.h:5178
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3423
const Expr * getInitExpr() const
Definition Decl.h:3441
Represents an enum.
Definition Decl.h:4010
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4228
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4231
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4237
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4183
Store information needed for an explicit specifier.
Definition DeclCXX.h:1924
const Expr * getExpr() const
Definition DeclCXX.h:1933
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
Definition DeclCXX.cpp:2354
bool isSpecified() const
Determine if the declaration had an explicit specifier of any kind.
Definition DeclCXX.h:1937
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3661
This represents one expression.
Definition Expr.h:112
Represents a member of a struct/union/class.
Definition Decl.h:3160
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3260
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4725
bool isBitField() const
Determines whether this field is a bitfield.
Definition Decl.h:3263
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3334
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3276
const Expr * getAsmStringExpr() const
Definition Decl.h:4619
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:54
unsigned getFriendTypeNumTemplateParameterLists() const
Definition DeclFriend.h:129
TemplateParameterList * getFriendTypeTemplateParameterList(unsigned N) const
Definition DeclFriend.h:133
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:139
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:125
bool isPackExpansion() const
Definition DeclFriend.h:190
Represents a function declaration or definition.
Definition Decl.h:2000
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:2797
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3279
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition Decl.cpp:4205
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4193
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition Decl.h:2314
bool isImmediateFunction() const
Definition Decl.cpp:3340
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2758
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2389
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2448
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
Definition Decl.h:2443
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2326
bool isConstexprSpecified() const
Definition Decl.h:2479
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition Decl.cpp:4329
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:2888
bool isDeletedAsWritten() const
Definition Decl.h:2544
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2353
bool isConsteval() const
Definition Decl.h:2482
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2344
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3826
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2211
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
Definition Decl.cpp:3246
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition Decl.h:2899
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition Decl.cpp:4339
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5269
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition TypeBase.h:5576
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition TypeBase.h:5689
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition TypeBase.h:5627
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition TypeBase.h:5619
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition TypeBase.h:5585
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5673
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition TypeBase.h:5634
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition TypeBase.h:5703
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
spec_range specializations() const
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4465
bool isConst() const
Definition TypeBase.h:4827
bool isRestrict() const
Definition TypeBase.h:4829
bool isVolatile() const
Definition TypeBase.h:4828
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
Definition Decl.h:5193
bool isCBuffer() const
Definition Decl.h:5237
One of these records is kept for each identifier that is lexed.
StringRef deuglifiedName() const
If the identifier is an "uglified" reserved name, return a cleaned form.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition Decl.h:5052
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition Decl.h:5110
Represents the declaration of a label.
Definition Decl.h:524
Represents a linkage specification.
Definition DeclCXX.h:3011
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3034
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3045
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition Module.cpp:239
This represents a decl that may have a name.
Definition Decl.h:274
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
Definition DeclBase.h:648
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
std::string getQualifiedNameAsString() const
Definition Decl.cpp:1680
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Definition Decl.h:317
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
Definition Decl.cpp:1687
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:1672
Represents a C++ namespace alias.
Definition DeclCXX.h:3197
NamespaceBaseDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
Definition DeclCXX.h:3290
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition DeclCXX.h:3262
Represent a C++ namespace.
Definition Decl.h:592
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:648
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false, bool PrintFinalScopeResOp=true) const
Print this nested name specifier to the given output stream.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
This represents 'pragma omp allocate ...' directive.
Definition DeclOpenMP.h:536
bool varlist_empty() const
Definition DeclOpenMP.h:574
bool clauselist_empty() const
Definition DeclOpenMP.h:576
varlist_iterator varlist_begin()
Definition DeclOpenMP.h:584
MutableArrayRef< Expr * >::iterator varlist_iterator
Definition DeclOpenMP.h:564
clauselist_range clauselists()
Definition DeclOpenMP.h:589
varlist_iterator varlist_end()
Definition DeclOpenMP.h:585
Pseudo declaration for capturing expressions.
Definition DeclOpenMP.h:445
This is a basic class for representing single OpenMP clause.
This represents 'pragma omp declare mapper ...' directive.
Definition DeclOpenMP.h:349
clauselist_range clauselists()
Definition DeclOpenMP.h:395
DeclarationName getVarName()
Get the name of the variable declared in the mapper.
Definition DeclOpenMP.h:421
This represents 'pragma omp declare reduction ...' directive.
Definition DeclOpenMP.h:239
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
Definition DeclOpenMP.h:300
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
Definition DeclOpenMP.h:282
OMPDeclareReductionInitKind getInitializerKind() const
Get initializer kind.
Definition DeclOpenMP.h:303
This represents 'pragma omp requires...' directive.
Definition DeclOpenMP.h:479
clauselist_iterator clauselist_begin()
Definition DeclOpenMP.h:510
bool clauselist_empty() const
Definition DeclOpenMP.h:502
clauselist_iterator clauselist_end()
Definition DeclOpenMP.h:511
This represents 'pragma omp threadprivate ...' directive.
Definition DeclOpenMP.h:110
MutableArrayRef< Expr * >::iterator varlist_iterator
Definition DeclOpenMP.h:138
varlist_iterator varlist_end()
Definition DeclOpenMP.h:153
varlist_iterator varlist_begin()
Definition DeclOpenMP.h:152
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2329
ObjCInterfaceDecl * getClassInterface()
Definition DeclObjC.h:2372
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition DeclObjC.h:2377
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition DeclObjC.h:2545
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition DeclObjC.h:2775
const ObjCInterfaceDecl * getClassInterface() const
Definition DeclObjC.h:2793
const ObjCInterfaceDecl * getClassInterface() const
Definition DeclObjC.h:2486
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2597
std::string getNameAsString() const
Get the name of the class associated with this interface.
Definition DeclObjC.h:2729
ivar_range ivars() const
Definition DeclObjC.h:2749
unsigned ivar_size() const
Definition DeclObjC.h:2759
const ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.h:2735
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
unsigned ivar_size() const
Definition DeclObjC.h:1469
ivar_range ivars() const
Definition DeclObjC.h:1451
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition DeclObjC.h:1303
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition DeclObjC.h:1523
const ObjCProtocolList & getReferencedProtocols() const
Definition DeclObjC.h:1333
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition DeclObjC.h:1565
ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.cpp:349
bool empty() const
Definition DeclObjC.h:71
ObjCList - This is a simple template class used to hold various lists of decls etc,...
Definition DeclObjC.h:82
iterator end() const
Definition DeclObjC.h:91
iterator begin() const
Definition DeclObjC.h:90
T *const * iterator
Definition DeclObjC.h:88
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
ObjCDeclQualifier getObjCDeclQualifier() const
Definition DeclObjC.h:246
ArrayRef< ParmVarDecl * > parameters() const
Definition DeclObjC.h:373
bool isVariadic() const
Definition DeclObjC.h:431
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition DeclObjC.cpp:906
Selector getSelector() const
Definition DeclObjC.h:327
bool isInstanceMethod() const
Definition DeclObjC.h:426
QualType getReturnType() const
Definition DeclObjC.h:329
Represents a pointer to an Objective C object.
Definition TypeBase.h:7910
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
Selector getSetterName() const
Definition DeclObjC.h:893
QualType getType() const
Definition DeclObjC.h:804
Selector getGetterName() const
Definition DeclObjC.h:885
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition DeclObjC.h:815
PropertyControl getPropertyImplementation() const
Definition DeclObjC.h:912
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition DeclObjC.h:2805
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:2879
Kind getPropertyImplementation() const
Definition DeclObjC.h:2875
ObjCPropertyDecl * getPropertyDecl() const
Definition DeclObjC.h:2870
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2084
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition DeclObjC.h:2261
const ObjCProtocolList & getReferencedProtocols() const
Definition DeclObjC.h:2153
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:662
ArrayRef< const OpenACCClause * > clauses() const
Definition DeclOpenACC.h:62
const Expr * getFunctionReference() const
Sugar for parentheses used when specifying types.
Definition TypeBase.h:3303
Represents a parameter to a function.
Definition Decl.h:1790
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3329
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition TypeBase.h:1388
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition TypeBase.h:1332
Represents a struct/union/class.
Definition Decl.h:4324
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3574
std::string getAsString() const
Derive the full selector name (e.g.
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
Encodes a location in the source.
Represents a C++11 static_assert declaration.
Definition DeclCXX.h:4132
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1799
StringRef getKindName() const
Definition Decl.h:3910
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3815
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:3960
A template argument list.
const TemplateArgument & getArgument() const
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
void print(raw_ostream &Out, const ASTContext &Context, bool OmitTemplateKW=false) const
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool isParameterPack() const
Returns whether this is a parameter pack.
A declaration that models statements at global scope.
Definition Decl.h:4634
The top declaration context.
Definition Decl.h:105
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3688
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition ASTConcept.h:227
A container of type source information.
Definition TypeBase.h:8263
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8274
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9111
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3667
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3562
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3612
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4033
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition DeclCXX.h:4070
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3936
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition DeclCXX.h:3973
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition DeclCXX.h:3980
Represents a C++ using-declaration.
Definition DeclCXX.h:3587
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3636
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition DeclCXX.h:3633
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition DeclCXX.h:3624
Represents C++ using-directive.
Definition DeclCXX.h:3092
NamedDecl * getNominatedNamespaceAsWritten()
Definition DeclCXX.h:3145
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition DeclCXX.h:3141
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3788
EnumDecl * getEnumDecl() const
Definition DeclCXX.h:3830
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3395
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:926
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1569
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition Decl.h:1466
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition Decl.cpp:2132
@ CInit
C-style initialization with assignment.
Definition Decl.h:931
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:934
bool isCXXForRangeDecl() const
Determine whether this variable is the for-range-declaration in a C++0x for-range statement.
Definition Decl.h:1522
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1177
const Expr * getInit() const
Definition Decl.h:1368
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1168
Represents a GCC generic vector type.
Definition TypeBase.h:4176
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition Address.h:330
llvm::StringRef getAccessSpelling(AccessSpecifier AS)
Definition Specifiers.h:419
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
Definition Specifiers.h:357
@ ICIS_ListInit
Direct list-initialization.
Definition Specifiers.h:274
@ RQ_None
No ref-qualifier was provided.
Definition TypeBase.h:1782
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
Definition TypeBase.h:1785
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
Definition TypeBase.h:1788
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition Specifiers.h:123
@ AS_none
Definition Specifiers.h:127
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
StorageClass
Storage classes.
Definition Specifiers.h:248
@ SC_Auto
Definition Specifiers.h:256
@ SC_PrivateExtern
Definition Specifiers.h:253
@ SC_Extern
Definition Specifiers.h:251
@ SC_Register
Definition Specifiers.h:257
@ SC_Static
Definition Specifiers.h:252
@ SC_None
Definition Specifiers.h:250
@ TSCS_thread_local
C++11 thread_local.
Definition Specifiers.h:241
@ TSCS_unspecified
Definition Specifiers.h:236
@ TSCS__Thread_local
C11 _Thread_local.
Definition Specifiers.h:244
@ TSCS___thread
GNU __thread.
Definition Specifiers.h:238
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition JsonSupport.h:21
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
@ Concept
The name was classified as a concept name.
Definition Sema.h:590
llvm::StringRef getAsString(SyncScope S)
Definition SyncScope.h:62
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition Specifiers.h:194
@ Invariant
The parameter is invariant: must match exactly.
Definition DeclObjC.h:555
@ Contravariant
The parameter is contravariant, e.g., X<T> is a subtype of X when the type parameter is covariant and...
Definition DeclObjC.h:563
@ Covariant
The parameter is covariant, e.g., X<T> is a subtype of X when the type parameter is covariant and T i...
Definition DeclObjC.h:559
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
U cast(CodeGen::Address addr)
Definition Address.h:327
@ EST_MSAny
Microsoft throw(...) extension.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
ArrayRef< TemplateArgumentLoc > arguments() const
void printName(raw_ostream &OS, PrintingPolicy Policy) const
printName - Print the human-readable name to a stream.
Describes how types, statements, expressions, and declarations should be printed.
unsigned SuppressDeclAttributes
Whether to suppress attributes in decl printing.
unsigned FullyQualifiedName
When true, print the fully qualified name of function declarations.
unsigned PolishForDeclaration
When true, do certain refinement needed for producing proper declaration tag; such as,...
unsigned CleanUglifiedParameters
Whether to strip underscores when printing reserved parameter names.
unsigned SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration.
unsigned SuppressScope
Suppresses printing of scope specifiers.
unsigned Indentation
The number of spaces to use to indent each line.
unsigned SuppressInitializers
Suppress printing of variable initializers.
unsigned TerseOutput
Provide a 'terse' output.
unsigned PrintAsCanonical
Whether to print entities as written or canonically.