clang 24.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 VisitFriendTemplateDecl(FriendTemplateDecl *D);
74 void VisitFieldDecl(FieldDecl *D);
75 void VisitVarDecl(VarDecl *D);
76 void VisitLabelDecl(LabelDecl *D);
77 void VisitParmVarDecl(ParmVarDecl *D);
78 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
79 void VisitTopLevelStmtDecl(TopLevelStmtDecl *D);
80 void VisitImportDecl(ImportDecl *D);
81 void VisitStaticAssertDecl(StaticAssertDecl *D);
82 void VisitNamespaceDecl(NamespaceDecl *D);
83 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
84 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
85 void VisitCXXRecordDecl(CXXRecordDecl *D);
86 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
87 void VisitTemplateDecl(const TemplateDecl *D);
88 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
89 void VisitClassTemplateDecl(ClassTemplateDecl *D);
90 void VisitExplicitInstantiationDecl(ExplicitInstantiationDecl *D);
91 void VisitClassTemplateSpecializationDecl(
92 ClassTemplateSpecializationDecl *D);
93 void VisitClassTemplatePartialSpecializationDecl(
94 ClassTemplatePartialSpecializationDecl *D);
95 void VisitObjCMethodDecl(ObjCMethodDecl *D);
96 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
97 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
98 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
99 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
100 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
101 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
102 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
103 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
104 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
105 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
106 void VisitUsingDecl(UsingDecl *D);
107 void VisitUsingEnumDecl(UsingEnumDecl *D);
108 void VisitUsingShadowDecl(UsingShadowDecl *D);
109 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
110 void VisitOMPAllocateDecl(OMPAllocateDecl *D);
111 void VisitOMPRequiresDecl(OMPRequiresDecl *D);
112 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
113 void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
114 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
115 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP);
116 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP);
117 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *);
118 void VisitHLSLBufferDecl(HLSLBufferDecl *D);
119 void VisitCXXExpansionStmtDecl(const CXXExpansionStmtDecl *D);
120
121 void VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D);
122 void VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D);
123
124 void printTemplateParameters(const TemplateParameterList *Params,
125 bool OmitTemplateKW = false);
126 void printTemplateArguments(ArrayRef<TemplateArgument> Args,
127 const TemplateParameterList *Params);
128 void printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
129 const TemplateParameterList *Params);
130 enum class AttrPosAsWritten { Default = 0, Left, Right };
131 std::optional<std::string>
132 prettyPrintAttributes(const Decl *D,
133 AttrPosAsWritten Pos = AttrPosAsWritten::Default);
134
135 void prettyPrintPragmas(Decl *D);
136 void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
137 };
138}
139
140void Decl::print(raw_ostream &Out, unsigned Indentation,
141 bool PrintInstantiation) const {
142 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
143}
144
145void Decl::print(raw_ostream &Out, const PrintingPolicy &Policy,
146 unsigned Indentation, bool PrintInstantiation) const {
147 DeclPrinter Printer(Out, Policy, getASTContext(), Indentation,
148 PrintInstantiation);
149 Printer.Visit(const_cast<Decl*>(this));
150}
151
152void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context,
153 bool OmitTemplateKW) const {
154 print(Out, Context, Context.getPrintingPolicy(), OmitTemplateKW);
155}
156
157void TemplateParameterList::print(raw_ostream &Out, const ASTContext &Context,
158 const PrintingPolicy &Policy,
159 bool OmitTemplateKW) const {
160 DeclPrinter Printer(Out, Policy, Context);
161 Printer.printTemplateParameters(this, OmitTemplateKW);
162}
163
165 // FIXME: This should be on the Type class!
166 QualType BaseType = T;
167 while (!BaseType->isSpecifierType()) {
168 if (const PointerType *PTy = BaseType->getAs<PointerType>())
169 BaseType = PTy->getPointeeType();
170 else if (const ObjCObjectPointerType *OPT =
171 BaseType->getAs<ObjCObjectPointerType>())
172 BaseType = OPT->getPointeeType();
173 else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>())
174 BaseType = BPy->getPointeeType();
175 else if (const ArrayType *ATy = dyn_cast<ArrayType>(BaseType))
176 BaseType = ATy->getElementType();
177 else if (const FunctionType *FTy = BaseType->getAs<FunctionType>())
178 BaseType = FTy->getReturnType();
179 else if (const VectorType *VTy = BaseType->getAs<VectorType>())
180 BaseType = VTy->getElementType();
181 else if (const ReferenceType *RTy = BaseType->getAs<ReferenceType>())
182 BaseType = RTy->getPointeeType();
183 else if (const AutoType *ATy = BaseType->getAs<AutoType>())
184 BaseType = ATy->getDeducedType();
185 else if (const ParenType *PTy = BaseType->getAs<ParenType>())
186 BaseType = PTy->desugar();
187 else
188 // This must be a syntax error.
189 break;
190 }
191 return BaseType;
192}
193
195 if (TypedefNameDecl* TDD = dyn_cast<TypedefNameDecl>(D))
196 return TDD->getUnderlyingType();
197 if (ValueDecl* VD = dyn_cast<ValueDecl>(D))
198 return VD->getType();
199 return QualType();
200}
201
202void Decl::printGroup(Decl** Begin, unsigned NumDecls,
203 raw_ostream &Out, const PrintingPolicy &Policy,
204 unsigned Indentation) {
205 if (NumDecls == 1) {
206 (*Begin)->print(Out, Policy, Indentation);
207 return;
208 }
209
210 Decl** End = Begin + NumDecls;
211 if (isa<TagDecl>(*Begin))
212 ++Begin;
213
214 PrintingPolicy SubPolicy(Policy);
215
216 bool isFirst = true;
217 for ( ; Begin != End; ++Begin) {
218 if (isFirst) {
219 isFirst = false;
220 } else {
221 Out << ", ";
222 SubPolicy.SuppressSpecifiers = true;
223 }
224
225 (*Begin)->print(Out, SubPolicy, Indentation);
226 }
227}
228
229LLVM_DUMP_METHOD void DeclContext::dumpDeclContext() const {
230 // Get the translation unit
231 const DeclContext *DC = this;
232 while (!DC->isTranslationUnit())
233 DC = DC->getParent();
234
235 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
236 DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), Ctx, 0);
237 Printer.VisitDeclContext(const_cast<DeclContext *>(this), /*Indent=*/false);
238}
239
240raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
241 for (unsigned i = 0; i != Indentation; ++i)
242 Out << " ";
243 return Out;
244}
245
246static DeclPrinter::AttrPosAsWritten getPosAsWritten(const Attr *A,
247 const Decl *D) {
248 SourceLocation ALoc = A->getLoc();
249 SourceLocation DLoc = D->getLocation();
250 const ASTContext &C = D->getASTContext();
251 if (ALoc.isInvalid() || DLoc.isInvalid())
252 return DeclPrinter::AttrPosAsWritten::Left;
253
254 if (C.getSourceManager().isBeforeInTranslationUnit(ALoc, DLoc))
255 return DeclPrinter::AttrPosAsWritten::Left;
256
257 return DeclPrinter::AttrPosAsWritten::Right;
258}
259
260std::optional<std::string>
261DeclPrinter::prettyPrintAttributes(const Decl *D,
262 AttrPosAsWritten Pos /*=Default*/) {
263 if (Policy.SuppressDeclAttributes || !D->hasAttrs())
264 return std::nullopt;
265
266 std::string AttrStr;
267 llvm::raw_string_ostream AOut(AttrStr);
268 llvm::ListSeparator LS(" ");
269 for (auto *A : D->getAttrs()) {
270 if (A->isInherited() || A->isImplicit())
271 continue;
272 // Print out the keyword attributes, they aren't regular attributes.
273 if (Policy.PolishForDeclaration && !A->isKeywordAttribute())
274 continue;
275 switch (A->getKind()) {
276#define ATTR(X)
277#define PRAGMA_SPELLING_ATTR(X) case attr::X:
278#include "clang/Basic/AttrList.inc"
279 break;
280 default:
281 AttrPosAsWritten APos = getPosAsWritten(A, D);
282 assert(APos != AttrPosAsWritten::Default &&
283 "Default not a valid for an attribute location");
284 if (Pos == AttrPosAsWritten::Default || Pos == APos) {
285 AOut << LS;
286 A->printPretty(AOut, Policy);
287 }
288 break;
289 }
290 }
291 if (AttrStr.empty())
292 return std::nullopt;
293 return AttrStr;
294}
295
296void DeclPrinter::PrintOpenACCRoutineOnLambda(Decl *D) {
297 CXXRecordDecl *CXXRD = nullptr;
298 if (const auto *VD = dyn_cast<VarDecl>(D)) {
299 if (const auto *Init = VD->getInit())
300 CXXRD = Init->getType().isNull() ? nullptr
301 : Init->getType()->getAsCXXRecordDecl();
302 } else if (const auto *FD = dyn_cast<FieldDecl>(D)) {
303 CXXRD =
304 FD->getType().isNull() ? nullptr : FD->getType()->getAsCXXRecordDecl();
305 }
306
307 if (!CXXRD || !CXXRD->isLambda())
308 return;
309
310 if (const auto *Call = CXXRD->getLambdaCallOperator()) {
311 for (auto *A : Call->specific_attrs<OpenACCRoutineDeclAttr>()) {
312 A->printPretty(Out, Policy);
313 Indent();
314 }
315 }
316}
317
318void DeclPrinter::prettyPrintPragmas(Decl *D) {
319 if (Policy.PolishForDeclaration)
320 return;
321
322 PrintOpenACCRoutineOnLambda(D);
323
324 if (D->hasAttrs()) {
325 AttrVec &Attrs = D->getAttrs();
326 for (auto *A : Attrs) {
327 switch (A->getKind()) {
328#define ATTR(X)
329#define PRAGMA_SPELLING_ATTR(X) case attr::X:
330#include "clang/Basic/AttrList.inc"
331 A->printPretty(Out, Policy);
332 Indent();
333 break;
334 default:
335 break;
336 }
337 }
338 }
339}
340
341void DeclPrinter::printDeclType(QualType T, StringRef DeclName, bool Pack) {
342 // Normally, a PackExpansionType is written as T[3]... (for instance, as a
343 // template argument), but if it is the type of a declaration, the ellipsis
344 // is placed before the name being declared.
345 if (auto *PET = T->getAs<PackExpansionType>()) {
346 Pack = true;
347 T = PET->getPattern();
348 }
349 T.print(Out, Policy, (Pack ? "..." : "") + DeclName, Indentation);
350}
351
352void DeclPrinter::ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls) {
353 this->Indent();
354 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
355 Out << ";\n";
356 Decls.clear();
357
358}
359
360void DeclPrinter::Print(AccessSpecifier AS) {
361 const auto AccessSpelling = getAccessSpelling(AS);
362 if (AccessSpelling.empty())
363 llvm_unreachable("No access specifier!");
364 Out << AccessSpelling;
365}
366
367void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl,
368 std::string &Proto) {
369 bool HasInitializerList = false;
370 for (const auto *BMInitializer : CDecl->inits()) {
371 if (BMInitializer->isInClassMemberInitializer())
372 continue;
373 if (!BMInitializer->isWritten())
374 continue;
375
376 if (!HasInitializerList) {
377 Proto += " : ";
378 Out << Proto;
379 Proto.clear();
380 HasInitializerList = true;
381 } else
382 Out << ", ";
383
384 if (BMInitializer->isAnyMemberInitializer()) {
385 FieldDecl *FD = BMInitializer->getAnyMember();
386 Out << *FD;
387 } else if (BMInitializer->isDelegatingInitializer()) {
388 Out << CDecl->getNameAsString();
389 } else {
390 Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy);
391 }
392
393 if (Expr *Init = BMInitializer->getInit()) {
394 bool OutParens = !isa<InitListExpr>(Init);
395
396 if (OutParens)
397 Out << "(";
398
399 if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init))
400 Init = Tmp->getSubExpr();
401
402 Init = Init->IgnoreParens();
403
404 Expr *SimpleInit = nullptr;
405 Expr **Args = nullptr;
406 unsigned NumArgs = 0;
407 if (ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
408 Args = ParenList->getExprs();
409 NumArgs = ParenList->getNumExprs();
410 } else if (CXXConstructExpr *Construct =
411 dyn_cast<CXXConstructExpr>(Init)) {
412 Args = Construct->getArgs();
413 NumArgs = Construct->getNumArgs();
414 } else
415 SimpleInit = Init;
416
417 if (SimpleInit)
418 SimpleInit->printPretty(Out, nullptr, Policy, Indentation, "\n",
419 &Context);
420 else {
421 for (unsigned I = 0; I != NumArgs; ++I) {
422 assert(Args[I] != nullptr && "Expected non-null Expr");
423 if (isa<CXXDefaultArgExpr>(Args[I]))
424 break;
425
426 if (I)
427 Out << ", ";
428 Args[I]->printPretty(Out, nullptr, Policy, Indentation, "\n",
429 &Context);
430 }
431 }
432
433 if (OutParens)
434 Out << ")";
435 } else {
436 Out << "()";
437 }
438
439 if (BMInitializer->isPackExpansion())
440 Out << "...";
441 }
442}
443
444//----------------------------------------------------------------------------
445// Common C declarations
446//----------------------------------------------------------------------------
447
448void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
449 if (Policy.TerseOutput)
450 return;
451
452 if (Indent)
453 Indentation += Policy.Indentation;
454
456 for (DeclContext::decl_iterator D = DC->decls_begin(), DEnd = DC->decls_end();
457 D != DEnd; ++D) {
458
459 // Don't print ObjCIvarDecls, as they are printed when visiting the
460 // containing ObjCInterfaceDecl.
461 if (isa<ObjCIvarDecl>(*D))
462 continue;
463
464 // Skip over implicit declarations in pretty-printing mode.
465 if (D->isImplicit())
466 continue;
467
468 // Don't print implicit specializations, as they are printed when visiting
469 // corresponding templates.
470 if (auto FD = dyn_cast<FunctionDecl>(*D))
471 if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation &&
473 continue;
474
475 // The next bits of code handle stuff like "struct {int x;} a,b"; we're
476 // forced to merge the declarations because there's no other way to
477 // refer to the struct in question. When that struct is named instead, we
478 // also need to merge to avoid splitting off a stand-alone struct
479 // declaration that produces the warning ext_no_declarators in some
480 // contexts.
481 //
482 // This limited merging is safe without a bunch of other checks because it
483 // only merges declarations directly referring to the tag, not typedefs.
484 //
485 // Check whether the current declaration should be grouped with a previous
486 // non-free-standing tag declaration.
487 QualType CurDeclType = getDeclType(*D);
488 if (!Decls.empty() && !CurDeclType.isNull()) {
489 QualType BaseType = GetBaseType(CurDeclType);
490 if (const auto *TT = dyn_cast_or_null<TagType>(BaseType);
491 TT && TT->isTagOwned()) {
492 if (TT->getDecl() == Decls[0]) {
493 Decls.push_back(*D);
494 continue;
495 }
496 }
497 }
498
499 // If we have a merged group waiting to be handled, handle it now.
500 if (!Decls.empty())
501 ProcessDeclGroup(Decls);
502
503 // If the current declaration is not a free standing declaration, save it
504 // so we can merge it with the subsequent declaration(s) using it.
505 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->isFreeStanding()) {
506 Decls.push_back(*D);
507 continue;
508 }
509
510 if (isa<AccessSpecDecl>(*D)) {
511 Indentation -= Policy.Indentation;
512 this->Indent();
513 Print(D->getAccess());
514 Out << ":\n";
515 Indentation += Policy.Indentation;
516 continue;
517 }
518
519 this->Indent();
520 Visit(*D);
521
522 // FIXME: Need to be able to tell the DeclPrinter when
523 const char *Terminator = nullptr;
527 Terminator = nullptr;
529 Terminator = nullptr;
530 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
531 Terminator = nullptr;
532 else if (auto FD = dyn_cast<FunctionDecl>(*D)) {
533 if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
534 Terminator = nullptr;
535 else
536 Terminator = ";";
537 } else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
538 if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
539 Terminator = nullptr;
540 else
541 Terminator = ";";
545 Terminator = nullptr;
546 else if (isa<EnumConstantDecl>(*D)) {
548 ++Next;
549 if (Next != DEnd)
550 Terminator = ",";
551 } else
552 Terminator = ";";
553
554 if (Terminator)
555 Out << Terminator;
556 if (!Policy.TerseOutput &&
557 ((isa<FunctionDecl>(*D) &&
558 cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
560 cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
561 ; // StmtPrinter already added '\n' after CompoundStmt.
562 else
563 Out << "\n";
564
565 // Declare target attribute is special one, natural spelling for the pragma
566 // assumes "ending" construct so print it here.
567 if (D->hasAttr<OMPDeclareTargetDeclAttr>())
568 Out << "#pragma omp end declare target\n";
569 }
570
571 if (!Decls.empty())
572 ProcessDeclGroup(Decls);
573
574 if (Indent)
575 Indentation -= Policy.Indentation;
576}
577
578void DeclPrinter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
579 VisitDeclContext(D, false);
580}
581
582void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
583 if (!Policy.SuppressSpecifiers) {
584 Out << "typedef ";
585
586 if (D->isModulePrivate())
587 Out << "__module_private__ ";
588 }
590 Ty.print(Out, Policy, D->getName(), Indentation);
591
592 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
593 Out << ' ' << *Attrs;
594}
595
596void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
597 Out << "using " << *D;
598 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
599 Out << ' ' << *Attrs;
600 Out << " = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
601}
602
603void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
604 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
605 Out << "__module_private__ ";
606 Out << "enum";
607 if (D->isScoped()) {
608 if (D->isScopedUsingClassTag())
609 Out << " class";
610 else
611 Out << " struct";
612 }
613
614 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
615 Out << ' ' << *Attrs;
616
617 if (D->getDeclName())
618 Out << ' ' << D->getDeclName();
619
620 if (D->isFixed())
621 Out << " : " << D->getIntegerType().stream(Policy);
622
623 if (D->isCompleteDefinition()) {
624 Out << " {\n";
625 VisitDeclContext(D);
626 Indent() << "}";
627 }
628}
629
630void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
631 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
632 Out << "__module_private__ ";
633 Out << D->getKindName();
634
635 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
636 Out << ' ' << *Attrs;
637
638 if (D->getIdentifier())
639 Out << ' ' << *D;
640
641 if (D->isCompleteDefinition()) {
642 Out << " {\n";
643 VisitDeclContext(D);
644 Indent() << "}";
645 }
646}
647
648void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
649 Out << *D;
650 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
651 Out << ' ' << *Attrs;
652 if (Expr *Init = D->getInitExpr()) {
653 Out << " = ";
654 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
655 }
656}
657
658static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out,
659 PrintingPolicy &Policy, unsigned Indentation,
660 const ASTContext &Context) {
661 std::string Proto = "explicit";
662 llvm::raw_string_ostream EOut(Proto);
663 if (ES.getExpr()) {
664 EOut << "(";
665 ES.getExpr()->printPretty(EOut, nullptr, Policy, Indentation, "\n",
666 &Context);
667 EOut << ")";
668 }
669 EOut << " ";
670 Out << Proto;
671}
672
673void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
676 prettyPrintPragmas(D);
677 if (std::optional<std::string> Attrs =
678 prettyPrintAttributes(D, AttrPosAsWritten::Left))
679 Out << *Attrs << ' ';
680 }
681
683 Out << "template<> ";
684 else if (!D->getDescribedFunctionTemplate()) {
686 printTemplateParameters(TPL);
687 }
688
689 CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D);
690 CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D);
691 CXXDeductionGuideDecl *GuideDecl = dyn_cast<CXXDeductionGuideDecl>(D);
692 if (!Policy.SuppressSpecifiers) {
693 switch (D->getStorageClass()) {
694 case SC_None: break;
695 case SC_Extern: Out << "extern "; break;
696 case SC_Static: Out << "static "; break;
697 case SC_PrivateExtern: Out << "__private_extern__ "; break;
698 case SC_Auto: case SC_Register:
699 llvm_unreachable("invalid for functions");
700 }
701
702 if (D->isInlineSpecified()) Out << "inline ";
703 if (D->isVirtualAsWritten()) Out << "virtual ";
704 if (D->isModulePrivate()) Out << "__module_private__ ";
706 Out << "constexpr ";
707 if (D->isConsteval()) Out << "consteval ";
708 else if (D->isImmediateFunction())
709 Out << "immediate ";
711 if (ExplicitSpec.isSpecified())
712 printExplicitSpecifier(ExplicitSpec, Out, Policy, Indentation, Context);
713 }
714
715 PrintingPolicy SubPolicy(Policy);
716 SubPolicy.SuppressSpecifiers = false;
717 std::string Proto;
718
719 if (Policy.FullyQualifiedName) {
720 Proto += D->getQualifiedNameAsString();
721 } else {
722 llvm::raw_string_ostream OS(Proto);
723 if (!Policy.SuppressScope)
724 D->getQualifier().print(OS, Policy);
725 D->getNameInfo().printName(OS, Policy);
726 }
727
728 if (GuideDecl)
729 Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString();
731 llvm::raw_string_ostream POut(Proto);
732 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
733 const auto *TArgAsWritten = D->getTemplateSpecializationArgsAsWritten();
734 if (TArgAsWritten && !Policy.PrintAsCanonical)
735 TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(), nullptr);
736 else if (const TemplateArgumentList *TArgs =
738 TArgPrinter.printTemplateArguments(TArgs->asArray(), nullptr);
739 }
740
741 QualType Ty = D->getType();
742 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) {
743 Proto = '(' + Proto + ')';
744 Ty = PT->getInnerType();
745 }
746
747 if (const FunctionType *AFT = Ty->getAs<FunctionType>()) {
748 const FunctionProtoType *FT = nullptr;
749 if (D->hasWrittenPrototype())
750 FT = dyn_cast<FunctionProtoType>(AFT);
751
752 Proto += "(";
753 if (FT) {
754 llvm::raw_string_ostream POut(Proto);
755 DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
756 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
757 if (i) POut << ", ";
758 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
759 }
760
761 if (FT->isVariadic()) {
762 if (D->getNumParams()) POut << ", ";
763 POut << "...";
764 } else if (!D->getNumParams() && !Context.getLangOpts().CPlusPlus) {
765 // The function has a prototype, so it needs to retain the prototype
766 // in C.
767 POut << "void";
768 }
769 } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) {
770 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
771 if (i)
772 Proto += ", ";
773 Proto += D->getParamDecl(i)->getNameAsString();
774 }
775 }
776
777 Proto += ")";
778
779 if (FT) {
780 if (FT->isConst())
781 Proto += " const";
782 if (FT->isVolatile())
783 Proto += " volatile";
784 if (FT->isRestrict())
785 Proto += " restrict";
786
787 switch (FT->getRefQualifier()) {
788 case RQ_None:
789 break;
790 case RQ_LValue:
791 Proto += " &";
792 break;
793 case RQ_RValue:
794 Proto += " &&";
795 break;
796 }
797 }
798
799 if (FT && FT->hasDynamicExceptionSpec()) {
800 Proto += " throw(";
801 if (FT->getExceptionSpecType() == EST_MSAny)
802 Proto += "...";
803 else
804 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
805 if (I)
806 Proto += ", ";
807
808 Proto += FT->getExceptionType(I).getAsString(SubPolicy);
809 }
810 Proto += ")";
811 } else if (FT && isNoexceptExceptionSpec(FT->getExceptionSpecType())) {
812 Proto += " noexcept";
814 Proto += "(";
815 llvm::raw_string_ostream EOut(Proto);
816 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy,
817 Indentation, "\n", &Context);
818 Proto += ")";
819 }
820 }
821
822 if (CDecl) {
823 if (!Policy.TerseOutput)
824 PrintConstructorInitializers(CDecl, Proto);
825 } else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
826 if (FT && FT->hasTrailingReturn()) {
827 if (!GuideDecl)
828 Out << "auto ";
829 Out << Proto << " -> ";
830 Proto.clear();
831 }
832 AFT->getReturnType().print(Out, Policy, Proto);
833 Proto.clear();
834 }
835 Out << Proto;
836
837 if (const AssociatedConstraint &TrailingRequiresClause =
839 Out << " requires ";
840 // FIXME: The printer could support printing expressions and types as if
841 // expanded by an index. Pass in the ArgumentPackSubstitutionIndex when
842 // that's supported.
843 TrailingRequiresClause.ConstraintExpr->printPretty(
844 Out, nullptr, SubPolicy, Indentation, "\n", &Context);
845 }
846 } else {
847 Ty.print(Out, Policy, Proto);
848 }
849
850 if (std::optional<std::string> Attrs =
851 prettyPrintAttributes(D, AttrPosAsWritten::Right))
852 Out << ' ' << *Attrs;
853
854 if (D->isPureVirtual())
855 Out << " = 0";
856 else if (D->isDeletedAsWritten()) {
857 Out << " = delete";
858 if (const StringLiteral *M = D->getDeletedMessage()) {
859 Out << "(";
860 M->outputString(Out);
861 Out << ")";
862 }
863 } else if (D->isExplicitlyDefaulted())
864 Out << " = default";
865 else if (D->doesThisDeclarationHaveABody()) {
866 if (!Policy.TerseOutput) {
867 if (!D->hasPrototype() && D->getNumParams()) {
868 // This is a K&R function definition, so we need to print the
869 // parameters.
870 Out << '\n';
871 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
872 Indentation += Policy.Indentation;
873 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
874 Indent();
875 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
876 Out << ";\n";
877 }
878 Indentation -= Policy.Indentation;
879 }
880
881 if (D->getBody())
882 D->getBody()->printPrettyControlled(Out, nullptr, SubPolicy, Indentation, "\n",
883 &Context);
884 } else {
885 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
886 Out << " {}";
887 }
888 }
889}
890
891void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
892 if (TypeSourceInfo *TSI = D->getFriendType()) {
893 Out << "friend ";
894 Out << TSI->getType().getAsString(Policy);
895 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D->getFriendDecl())) {
896 Out << "friend ";
897 VisitFunctionDecl(FD);
898 } else if (FunctionTemplateDecl *FTD =
899 dyn_cast<FunctionTemplateDecl>(D->getFriendDecl())) {
900 Out << "friend ";
901 VisitFunctionTemplateDecl(FTD);
902 } else if (ClassTemplateDecl *CTD =
903 dyn_cast<ClassTemplateDecl>(D->getFriendDecl())) {
904 Out << "friend ";
905 VisitRedeclarableTemplateDecl(CTD);
906 }
907
908 if (D->isPackExpansion())
909 Out << "...";
910}
911
912void DeclPrinter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
914 printTemplateParameters(TPL);
915
917 if (D->getFriendType() || TN.isNull()) {
918 VisitFriendDecl(D);
919 } else {
920 Out << "friend ";
921 if (auto *CTD =
922 dyn_cast_if_present<ClassTemplateDecl>(TN.getAsTemplateDecl()))
923 Out << CTD->getTemplatedDecl()->getKindName() << ' ';
924 TN.print(Out, Policy,
927
928 if (D->isPackExpansion())
929 Out << "...";
930 }
931}
932
933void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
934 prettyPrintPragmas(D);
935 // FIXME: add printing of pragma attributes if required.
936 if (!Policy.SuppressSpecifiers && D->isMutable())
937 Out << "mutable ";
938 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
939 Out << "__module_private__ ";
940
942 stream(Policy, D->getName(), Indentation);
943
944 if (D->isBitField()) {
945 Out << " : ";
946 D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation, "\n",
947 &Context);
948 }
949
951 if (!Policy.SuppressInitializers && Init) {
953 Out << " ";
954 else
955 Out << " = ";
956 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
957 }
958 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
959 Out << ' ' << *Attrs;
960}
961
962void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
963 Out << *D << ":";
964}
965
966void DeclPrinter::VisitVarDecl(VarDecl *D) {
967 prettyPrintPragmas(D);
968
969 if (std::optional<std::string> Attrs =
970 prettyPrintAttributes(D, AttrPosAsWritten::Left))
971 Out << *Attrs << ' ';
972
973 if (const auto *Param = dyn_cast<ParmVarDecl>(D);
974 Param && Param->isExplicitObjectParameter())
975 Out << "this ";
976
978 ? D->getTypeSourceInfo()->getType()
980
981 if (!Policy.SuppressSpecifiers) {
983 if (SC != SC_None)
985
986 switch (D->getTSCSpec()) {
987 case TSCS_unspecified:
988 break;
989 case TSCS___thread:
990 Out << "__thread ";
991 break;
993 Out << "_Thread_local ";
994 break;
996 Out << "thread_local ";
997 break;
998 }
999
1000 if (D->isModulePrivate())
1001 Out << "__module_private__ ";
1002
1003 if (D->isConstexpr()) {
1004 Out << "constexpr ";
1005 T.removeLocalConst();
1006 }
1007 }
1008
1009 printDeclType(T, (isa<ParmVarDecl>(D) && Policy.CleanUglifiedParameters &&
1010 D->getIdentifier())
1012 : D->getName());
1013
1014 if (std::optional<std::string> Attrs =
1015 prettyPrintAttributes(D, AttrPosAsWritten::Right))
1016 Out << ' ' << *Attrs;
1017
1018 Expr *Init = D->getInit();
1019 if (!Policy.SuppressInitializers && Init) {
1020 bool ImplicitInit = false;
1021 if (D->isCXXForRangeDecl()) {
1022 // FIXME: We should print the range expression instead.
1023 ImplicitInit = true;
1024 } else if (CXXConstructExpr *Construct =
1025 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
1026 if (D->getInitStyle() == VarDecl::CallInit &&
1027 !Construct->isListInitialization()) {
1028 ImplicitInit = Construct->getNumArgs() == 0 ||
1029 Construct->getArg(0)->isDefaultArgument();
1030 }
1031 }
1032 if (!ImplicitInit) {
1034 Out << "(";
1035 else if (D->getInitStyle() == VarDecl::CInit) {
1036 Out << " = ";
1037 }
1038 PrintingPolicy SubPolicy(Policy);
1039 SubPolicy.SuppressSpecifiers = false;
1040 Init->printPretty(Out, nullptr, SubPolicy, Indentation, "\n", &Context);
1042 Out << ")";
1043 }
1044 }
1045}
1046
1047void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
1048 VisitVarDecl(D);
1049}
1050
1051void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
1052 Out << "__asm (";
1053 D->getAsmStringExpr()->printPretty(Out, nullptr, Policy, Indentation, "\n",
1054 &Context);
1055 Out << ")";
1056}
1057
1058void DeclPrinter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) {
1059 assert(D->getStmt());
1060 D->getStmt()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1061}
1062
1063void DeclPrinter::VisitImportDecl(ImportDecl *D) {
1064 Out << "@import " << D->getImportedModule()->getFullModuleName()
1065 << ";\n";
1066}
1067
1068void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
1069 Out << "static_assert(";
1070 D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation, "\n",
1071 &Context);
1072 if (Expr *E = D->getMessage()) {
1073 Out << ", ";
1074 E->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1075 }
1076 Out << ")";
1077}
1078
1079//----------------------------------------------------------------------------
1080// C++ declarations
1081//----------------------------------------------------------------------------
1082void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
1083 if (D->isInline())
1084 Out << "inline ";
1085
1086 Out << "namespace ";
1087 if (D->getDeclName())
1088 Out << D->getDeclName() << ' ';
1089 Out << "{\n";
1090
1091 VisitDeclContext(D);
1092 Indent() << "}";
1093}
1094
1095void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
1096 Out << "using namespace ";
1097 D->getQualifier().print(Out, Policy);
1099}
1100
1101void DeclPrinter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
1102 Out << "namespace " << *D << " = ";
1103 D->getQualifier().print(Out, Policy);
1104 Out << *D->getAliasedNamespace();
1105}
1106
1107void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
1108 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
1109 Out << *Attrs;
1110}
1111
1112void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
1113 // FIXME: add printing of pragma attributes if required.
1114 if (!Policy.SuppressSpecifiers && D->isModulePrivate())
1115 Out << "__module_private__ ";
1116
1117 Out << D->getKindName() << ' ';
1118
1119 if (std::optional<std::string> Attrs =
1120 prettyPrintAttributes(D, AttrPosAsWritten::Left))
1121 Out << *Attrs << ' ';
1122
1123 if (D->getIdentifier()) {
1124 D->getQualifier().print(Out, Policy);
1125 Out << *D;
1126
1127 if (auto *S = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
1128 const TemplateParameterList *TParams =
1129 S->getSpecializedTemplate()->getTemplateParameters();
1130 const ASTTemplateArgumentListInfo *TArgAsWritten =
1131 S->getTemplateArgsAsWritten();
1132 if (TArgAsWritten && !Policy.PrintAsCanonical)
1133 printTemplateArguments(TArgAsWritten->arguments(), TParams);
1134 else
1135 printTemplateArguments(S->getTemplateArgs().asArray(), TParams);
1136 }
1137 }
1138
1139 if (std::optional<std::string> Attrs =
1140 prettyPrintAttributes(D, AttrPosAsWritten::Right))
1141 Out << ' ' << *Attrs;
1142
1143 if (D->isCompleteDefinition()) {
1144 Out << ' ';
1145 // Print the base classes
1146 if (D->getNumBases()) {
1147 Out << ": ";
1148 for (CXXRecordDecl::base_class_iterator Base = D->bases_begin(),
1149 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
1150 if (Base != D->bases_begin())
1151 Out << ", ";
1152
1153 if (Base->isVirtual())
1154 Out << "virtual ";
1155
1156 AccessSpecifier AS = Base->getAccessSpecifierAsWritten();
1157 if (AS != AS_none) {
1158 Print(AS);
1159 Out << " ";
1160 }
1161 Out << Base->getType().getAsString(Policy);
1162
1163 if (Base->isPackExpansion())
1164 Out << "...";
1165 }
1166 Out << ' ';
1167 }
1168
1169 // Print the class definition
1170 // FIXME: Doesn't print access specifiers, e.g., "public:"
1171 if (Policy.TerseOutput) {
1172 Out << "{}";
1173 } else {
1174 Out << "{\n";
1175 VisitDeclContext(D);
1176 Indent() << "}";
1177 }
1178 }
1179}
1180
1181void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1182 const char *l;
1184 l = "C";
1185 else {
1187 "unknown language in linkage specification");
1188 l = "C++";
1189 }
1190
1191 Out << "extern \"" << l << "\" ";
1192 if (D->hasBraces()) {
1193 Out << "{\n";
1194 VisitDeclContext(D);
1195 Indent() << "}";
1196 } else
1197 Visit(*D->decls_begin());
1198}
1199
1200void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params,
1201 bool OmitTemplateKW) {
1202 assert(Params);
1203
1204 // Don't print invented template parameter lists.
1205 if (!Params->empty() && Params->getParam(0)->isImplicit())
1206 return;
1207
1208 if (!OmitTemplateKW)
1209 Out << "template ";
1210 Out << '<';
1211
1212 bool NeedComma = false;
1213 for (const Decl *Param : *Params) {
1214 if (Param->isImplicit())
1215 continue;
1216
1217 if (NeedComma)
1218 Out << ", ";
1219 else
1220 NeedComma = true;
1221
1222 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
1223 VisitTemplateTypeParmDecl(TTP);
1224 } else if (auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1225 VisitNonTypeTemplateParmDecl(NTTP);
1226 } else if (auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1227 VisitTemplateTemplateParmDecl(TTPD);
1228 }
1229 }
1230
1231 Out << '>';
1232
1233 if (const Expr *RequiresClause = Params->getRequiresClause()) {
1234 Out << " requires ";
1235 RequiresClause->printPretty(Out, nullptr, Policy, Indentation, "\n",
1236 &Context);
1237 }
1238
1239 if (!OmitTemplateKW)
1240 Out << ' ';
1241}
1242
1243void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> 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].print(Policy, Out, /*IncludeType*/ true);
1251 else
1252 Args[I].print(Policy, Out,
1254 Policy, Params, I));
1255 }
1256 Out << ">";
1257}
1258
1259void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
1260 const TemplateParameterList *Params) {
1261 Out << "<";
1262 for (size_t I = 0, E = Args.size(); I < E; ++I) {
1263 if (I)
1264 Out << ", ";
1265 if (!Params)
1266 Args[I].getArgument().print(Policy, Out, /*IncludeType*/ true);
1267 else
1268 Args[I].getArgument().print(
1269 Policy, Out,
1271 I));
1272 }
1273 Out << ">";
1274}
1275
1276void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
1277 printTemplateParameters(D->getTemplateParameters());
1278
1279 if (const TemplateTemplateParmDecl *TTP =
1280 dyn_cast<TemplateTemplateParmDecl>(D)) {
1281 if (TTP->wasDeclaredWithTypename())
1282 Out << "typename";
1283 else
1284 Out << "class";
1285
1286 if (TTP->isParameterPack())
1287 Out << " ...";
1288 else if (TTP->getDeclName())
1289 Out << ' ';
1290
1291 if (TTP->getDeclName()) {
1292 if (Policy.CleanUglifiedParameters && TTP->getIdentifier())
1293 Out << TTP->getIdentifier()->deuglifiedName();
1294 else
1295 Out << TTP->getDeclName();
1296 }
1297 } else if (auto *TD = D->getTemplatedDecl())
1298 Visit(TD);
1299 else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) {
1300 Out << "concept " << Concept->getName() << " = " ;
1301 Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, Indentation,
1302 "\n", &Context);
1303 }
1304}
1305
1306void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1307 prettyPrintPragmas(D->getTemplatedDecl());
1308 // Print any leading template parameter lists.
1309 if (const FunctionDecl *FD = D->getTemplatedDecl())
1311 printTemplateParameters(TPL);
1312 VisitRedeclarableTemplateDecl(D);
1313 // Declare target attribute is special one, natural spelling for the pragma
1314 // assumes "ending" construct so print it here.
1315 if (D->getTemplatedDecl()->hasAttr<OMPDeclareTargetDeclAttr>())
1316 Out << "#pragma omp end declare target\n";
1317
1318 // Never print "instantiations" for deduction guides (they don't really
1319 // have them).
1320 if (PrintInstantiation &&
1322 FunctionDecl *PrevDecl = D->getTemplatedDecl();
1323 const FunctionDecl *Def;
1324 if (PrevDecl->isDefined(Def) && Def != PrevDecl)
1325 return;
1326 for (auto *I : D->specializations())
1327 if (I->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) {
1328 if (!PrevDecl->isThisDeclarationADefinition())
1329 Out << ";\n";
1330 Indent();
1331 prettyPrintPragmas(I);
1332 Visit(I);
1333 }
1334 }
1335}
1336
1337void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1338 VisitRedeclarableTemplateDecl(D);
1339
1340 if (PrintInstantiation) {
1341 for (auto *I : D->specializations())
1342 if (I->getSpecializationKind() == TSK_ImplicitInstantiation) {
1344 Out << ";";
1345 Out << "\n";
1346 Indent();
1347 Visit(I);
1348 }
1349 }
1350}
1351
1352void DeclPrinter::VisitExplicitInstantiationDecl(ExplicitInstantiationDecl *D) {
1353 if (D->isExternTemplate())
1354 Out << "extern ";
1355 Out << "template ";
1356
1357 NamedDecl *Spec = D->getSpecialization();
1358
1359 // Build the qualified name with template arguments.
1360 std::string Name;
1361 llvm::raw_string_ostream NameOS(Name);
1362 if (D->getQualifierLoc())
1363 D->getQualifierLoc().getNestedNameSpecifier().print(NameOS, Policy);
1364 Spec->printName(NameOS, Policy);
1365 if (auto NumArgs = D->getNumTemplateArgs(); NumArgs && *NumArgs > 0) {
1367 for (unsigned I = 0; I < *NumArgs; ++I)
1368 Args.push_back(D->getTemplateArg(I));
1369 printTemplateArgumentList(NameOS, Args, Policy);
1370 }
1371
1372 if (auto *RD = dyn_cast<RecordDecl>(Spec)) {
1373 Out << RD->getKindName() << " " << Name;
1374 } else if (auto *FD = dyn_cast<FunctionDecl>(Spec)) {
1375 FD->getReturnType().print(Out, Policy);
1376 Out << " " << Name << "(";
1377 llvm::ListSeparator LS;
1378 for (const ParmVarDecl *P : FD->parameters()) {
1379 Out << LS;
1380 P->print(Out, Policy);
1381 }
1382 if (FD->isVariadic()) {
1383 Out << LS;
1384 Out << "...";
1385 }
1386 Out << ")";
1387 } else if (auto *TSI = D->getTypeAsWritten()) {
1388 TSI->getType().print(Out, Policy, Name);
1389 } else {
1390 llvm_unreachable("unexpected specialization kind");
1391 }
1392}
1393
1394void DeclPrinter::VisitClassTemplateSpecializationDecl(
1396 Out << "template<> ";
1397 VisitCXXRecordDecl(D);
1398}
1399
1400void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1402 printTemplateParameters(D->getTemplateParameters());
1403 VisitCXXRecordDecl(D);
1404}
1405
1406void DeclPrinter::VisitCXXExpansionStmtDecl(const CXXExpansionStmtDecl *D) {
1407 D->getExpansionPattern()->printPretty(Out, /*PrinterHelper=*/nullptr, Policy,
1408 Indentation, "\n", &Context);
1409}
1410
1411//----------------------------------------------------------------------------
1412// Objective-C declarations
1413//----------------------------------------------------------------------------
1414
1415void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx,
1417 QualType T) {
1418 Out << '(';
1420 Out << "in ";
1422 Out << "inout ";
1424 Out << "out ";
1426 Out << "bycopy ";
1428 Out << "byref ";
1430 Out << "oneway ";
1432 if (auto nullability = AttributedType::stripOuterNullability(T))
1433 Out << getNullabilitySpelling(*nullability, true) << ' ';
1434 }
1435
1437 Out << ')';
1438}
1439
1440void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) {
1441 Out << "<";
1442 unsigned First = true;
1443 for (auto *Param : *Params) {
1444 if (First) {
1445 First = false;
1446 } else {
1447 Out << ", ";
1448 }
1449
1450 switch (Param->getVariance()) {
1452 break;
1453
1455 Out << "__covariant ";
1456 break;
1457
1459 Out << "__contravariant ";
1460 break;
1461 }
1462
1463 Out << Param->getDeclName();
1464
1465 if (Param->hasExplicitBound()) {
1466 Out << " : " << Param->getUnderlyingType().getAsString(Policy);
1467 }
1468 }
1469 Out << ">";
1470}
1471
1472void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
1473 if (OMD->isInstanceMethod())
1474 Out << "- ";
1475 else
1476 Out << "+ ";
1477 if (!OMD->getReturnType().isNull()) {
1478 PrintObjCMethodType(OMD->getASTContext(), OMD->getObjCDeclQualifier(),
1479 OMD->getReturnType());
1480 }
1481
1482 std::string name = OMD->getSelector().getAsString();
1483 std::string::size_type pos, lastPos = 0;
1484 for (const auto *PI : OMD->parameters()) {
1485 // FIXME: selector is missing here!
1486 pos = name.find_first_of(':', lastPos);
1487 if (lastPos != 0)
1488 Out << " ";
1489 Out << name.substr(lastPos, pos - lastPos) << ':';
1490 PrintObjCMethodType(OMD->getASTContext(),
1491 PI->getObjCDeclQualifier(),
1492 PI->getType());
1493 Out << *PI;
1494 lastPos = pos + 1;
1495 }
1496
1497 if (OMD->parameters().empty())
1498 Out << name;
1499
1500 if (OMD->isVariadic())
1501 Out << ", ...";
1502
1503 if (std::optional<std::string> Attrs = prettyPrintAttributes(OMD))
1504 Out << ' ' << *Attrs;
1505
1506 if (OMD->getBody() && !Policy.TerseOutput) {
1507 Out << ' ';
1508 OMD->getBody()->printPretty(Out, nullptr, Policy, Indentation, "\n",
1509 &Context);
1510 }
1511 else if (Policy.PolishForDeclaration)
1512 Out << ';';
1513}
1514
1515void DeclPrinter::VisitObjCImplementationDecl(ObjCImplementationDecl *OID) {
1516 std::string I = OID->getNameAsString();
1517 ObjCInterfaceDecl *SID = OID->getSuperClass();
1518
1519 bool eolnOut = false;
1520 if (SID)
1521 Out << "@implementation " << I << " : " << *SID;
1522 else
1523 Out << "@implementation " << I;
1524
1525 if (OID->ivar_size() > 0) {
1526 Out << "{\n";
1527 eolnOut = true;
1528 Indentation += Policy.Indentation;
1529 for (const auto *I : OID->ivars()) {
1530 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1531 getAsString(Policy) << ' ' << *I << ";\n";
1532 }
1533 Indentation -= Policy.Indentation;
1534 Out << "}\n";
1535 } else if (SID || !OID->decls().empty()) {
1536 Out << "\n";
1537 eolnOut = true;
1538 }
1539 VisitDeclContext(OID, false);
1540 if (!eolnOut)
1541 Out << "\n";
1542 Out << "@end";
1543}
1544
1545void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
1546 std::string I = OID->getNameAsString();
1547 ObjCInterfaceDecl *SID = OID->getSuperClass();
1548
1549 if (!OID->isThisDeclarationADefinition()) {
1550 Out << "@class " << I;
1551
1552 if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1553 PrintObjCTypeParams(TypeParams);
1554 }
1555
1556 Out << ";";
1557 return;
1558 }
1559 bool eolnOut = false;
1560 if (std::optional<std::string> Attrs = prettyPrintAttributes(OID))
1561 Out << *Attrs << "\n";
1562
1563 Out << "@interface " << I;
1564
1565 if (auto TypeParams = OID->getTypeParamListAsWritten()) {
1566 PrintObjCTypeParams(TypeParams);
1567 }
1568
1569 if (SID)
1570 Out << " : " << QualType(OID->getSuperClassType(), 0).getAsString(Policy);
1571
1572 // Protocols?
1573 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
1574 if (!Protocols.empty()) {
1575 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1576 E = Protocols.end(); I != E; ++I)
1577 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1578 Out << "> ";
1579 }
1580
1581 if (OID->ivar_size() > 0) {
1582 Out << "{\n";
1583 eolnOut = true;
1584 Indentation += Policy.Indentation;
1585 for (const auto *I : OID->ivars()) {
1586 Indent() << I->getASTContext()
1587 .getUnqualifiedObjCPointerType(I->getType())
1588 .getAsString(Policy) << ' ' << *I << ";\n";
1589 }
1590 Indentation -= Policy.Indentation;
1591 Out << "}\n";
1592 } else if (SID || !OID->decls().empty()) {
1593 Out << "\n";
1594 eolnOut = true;
1595 }
1596
1597 VisitDeclContext(OID, false);
1598 if (!eolnOut)
1599 Out << "\n";
1600 Out << "@end";
1601 // FIXME: implement the rest...
1602}
1603
1604void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
1605 if (!PID->isThisDeclarationADefinition()) {
1606 Out << "@protocol " << *PID << ";\n";
1607 return;
1608 }
1609 // Protocols?
1610 const ObjCList<ObjCProtocolDecl> &Protocols = PID->getReferencedProtocols();
1611 if (!Protocols.empty()) {
1612 Out << "@protocol " << *PID;
1613 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
1614 E = Protocols.end(); I != E; ++I)
1615 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1616 Out << ">\n";
1617 } else
1618 Out << "@protocol " << *PID << '\n';
1619 VisitDeclContext(PID, false);
1620 Out << "@end";
1621}
1622
1623void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
1624 Out << "@implementation ";
1625 if (const auto *CID = PID->getClassInterface())
1626 Out << *CID;
1627 else
1628 Out << "<<error-type>>";
1629 Out << '(' << *PID << ")\n";
1630
1631 VisitDeclContext(PID, false);
1632 Out << "@end";
1633 // FIXME: implement the rest...
1634}
1635
1636void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
1637 Out << "@interface ";
1638 if (const auto *CID = PID->getClassInterface())
1639 Out << *CID;
1640 else
1641 Out << "<<error-type>>";
1642 if (auto TypeParams = PID->getTypeParamList()) {
1643 PrintObjCTypeParams(TypeParams);
1644 }
1645 Out << "(" << *PID << ")\n";
1646 if (PID->ivar_size() > 0) {
1647 Out << "{\n";
1648 Indentation += Policy.Indentation;
1649 for (const auto *I : PID->ivars())
1650 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1651 getAsString(Policy) << ' ' << *I << ";\n";
1652 Indentation -= Policy.Indentation;
1653 Out << "}\n";
1654 }
1655
1656 VisitDeclContext(PID, false);
1657 Out << "@end";
1658
1659 // FIXME: implement the rest...
1660}
1661
1662void DeclPrinter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
1663 Out << "@compatibility_alias " << *AID
1664 << ' ' << *AID->getClassInterface() << ";\n";
1665}
1666
1667/// PrintObjCPropertyDecl - print a property declaration.
1668///
1669/// Print attributes in the following order:
1670/// - class
1671/// - nonatomic | atomic
1672/// - assign | retain | strong | copy | weak | unsafe_unretained
1673/// - readwrite | readonly
1674/// - getter & setter
1675/// - nullability
1676void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1678 Out << "@required\n";
1680 Out << "@optional\n";
1681
1682 QualType T = PDecl->getType();
1683
1684 Out << "@property";
1686 bool first = true;
1687 Out << "(";
1689 Out << (first ? "" : ", ") << "class";
1690 first = false;
1691 }
1692
1694 Out << (first ? "" : ", ") << "direct";
1695 first = false;
1696 }
1697
1698 if (PDecl->getPropertyAttributes() &
1700 Out << (first ? "" : ", ") << "nonatomic";
1701 first = false;
1702 }
1704 Out << (first ? "" : ", ") << "atomic";
1705 first = false;
1706 }
1707
1709 Out << (first ? "" : ", ") << "assign";
1710 first = false;
1711 }
1713 Out << (first ? "" : ", ") << "retain";
1714 first = false;
1715 }
1716
1718 Out << (first ? "" : ", ") << "strong";
1719 first = false;
1720 }
1722 Out << (first ? "" : ", ") << "copy";
1723 first = false;
1724 }
1726 Out << (first ? "" : ", ") << "weak";
1727 first = false;
1728 }
1729 if (PDecl->getPropertyAttributes() &
1731 Out << (first ? "" : ", ") << "unsafe_unretained";
1732 first = false;
1733 }
1734
1735 if (PDecl->getPropertyAttributes() &
1737 Out << (first ? "" : ", ") << "readwrite";
1738 first = false;
1739 }
1741 Out << (first ? "" : ", ") << "readonly";
1742 first = false;
1743 }
1744
1746 Out << (first ? "" : ", ") << "getter = ";
1747 PDecl->getGetterName().print(Out);
1748 first = false;
1749 }
1751 Out << (first ? "" : ", ") << "setter = ";
1752 PDecl->getSetterName().print(Out);
1753 first = false;
1754 }
1755
1756 if (PDecl->getPropertyAttributes() &
1758 if (auto nullability = AttributedType::stripOuterNullability(T)) {
1759 if (*nullability == NullabilityKind::Unspecified &&
1760 (PDecl->getPropertyAttributes() &
1762 Out << (first ? "" : ", ") << "null_resettable";
1763 } else {
1764 Out << (first ? "" : ", ")
1765 << getNullabilitySpelling(*nullability, true);
1766 }
1767 first = false;
1768 }
1769 }
1770
1771 (void) first; // Silence dead store warning due to idiomatic code.
1772 Out << ")";
1773 }
1774 std::string TypeStr = PDecl->getASTContext().getUnqualifiedObjCPointerType(T).
1775 getAsString(Policy);
1776 Out << ' ' << TypeStr;
1777 if (!StringRef(TypeStr).ends_with("*"))
1778 Out << ' ';
1779 Out << *PDecl;
1780 if (Policy.PolishForDeclaration)
1781 Out << ';';
1782}
1783
1784void DeclPrinter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
1786 Out << "@synthesize ";
1787 else
1788 Out << "@dynamic ";
1789 Out << *PID->getPropertyDecl();
1790 if (PID->getPropertyIvarDecl())
1791 Out << '=' << *PID->getPropertyIvarDecl();
1792}
1793
1794void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1795 if (!D->isAccessDeclaration())
1796 Out << "using ";
1797 if (D->hasTypename())
1798 Out << "typename ";
1799 D->getQualifier().print(Out, Policy);
1800
1801 // Use the correct record name when the using declaration is used for
1802 // inheriting constructors.
1803 for (const auto *Shadow : D->shadows()) {
1804 if (const auto *ConstructorShadow =
1805 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1806 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1807 Out << *ConstructorShadow->getNominatedBaseClass();
1808 return;
1809 }
1810 }
1811 Out << *D;
1812}
1813
1814void DeclPrinter::VisitUsingEnumDecl(UsingEnumDecl *D) {
1815 Out << "using enum " << D->getEnumDecl();
1816}
1817
1818void
1819DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
1820 Out << "using typename ";
1821 D->getQualifier().print(Out, Policy);
1822 Out << D->getDeclName();
1823}
1824
1825void DeclPrinter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1826 if (!D->isAccessDeclaration())
1827 Out << "using ";
1828 D->getQualifier().print(Out, Policy);
1829 Out << D->getDeclName();
1830}
1831
1832void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1833 // ignore
1834}
1835
1836void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1837 Out << "#pragma omp threadprivate";
1838 if (!D->varlist_empty()) {
1840 E = D->varlist_end();
1841 I != E; ++I) {
1842 Out << (I == D->varlist_begin() ? '(' : ',');
1843 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1844 ND->printQualifiedName(Out);
1845 }
1846 Out << ")";
1847 }
1848}
1849
1850void DeclPrinter::VisitHLSLBufferDecl(HLSLBufferDecl *D) {
1851 if (D->isCBuffer())
1852 Out << "cbuffer ";
1853 else
1854 Out << "tbuffer ";
1855
1856 Out << *D;
1857
1858 if (std::optional<std::string> Attrs = prettyPrintAttributes(D))
1859 Out << ' ' << *Attrs;
1860
1861 Out << " {\n";
1862 VisitDeclContext(D);
1863 Indent() << "}";
1864}
1865
1866void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
1867 Out << "#pragma omp allocate";
1868 if (!D->varlist_empty()) {
1870 E = D->varlist_end();
1871 I != E; ++I) {
1872 Out << (I == D->varlist_begin() ? '(' : ',');
1873 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1874 ND->printQualifiedName(Out);
1875 }
1876 Out << ")";
1877 }
1878 if (!D->clauselist_empty()) {
1879 OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
1880 for (OMPClause *C : D->clauselists()) {
1881 Out << " ";
1882 Printer.Visit(C);
1883 }
1884 }
1885}
1886
1887void DeclPrinter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
1888 Out << "#pragma omp requires ";
1889 if (!D->clauselist_empty()) {
1890 OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
1891 for (auto I = D->clauselist_begin(), E = D->clauselist_end(); I != E; ++I)
1892 Printer.Visit(*I);
1893 }
1894}
1895
1896void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1897 if (!D->isInvalidDecl()) {
1898 Out << "#pragma omp declare reduction (";
1900 const char *OpName =
1902 assert(OpName && "not an overloaded operator");
1903 Out << OpName;
1904 } else {
1905 assert(D->getDeclName().isIdentifier());
1906 D->printName(Out, Policy);
1907 }
1908 Out << " : ";
1909 D->getType().print(Out, Policy);
1910 Out << " : ";
1911 D->getCombiner()->printPretty(Out, nullptr, Policy, 0, "\n", &Context);
1912 Out << ")";
1913 if (auto *Init = D->getInitializer()) {
1914 Out << " initializer(";
1915 switch (D->getInitializerKind()) {
1917 Out << "omp_priv(";
1918 break;
1920 Out << "omp_priv = ";
1921 break;
1923 break;
1924 }
1925 Init->printPretty(Out, nullptr, Policy, 0, "\n", &Context);
1927 Out << ")";
1928 Out << ")";
1929 }
1930 }
1931}
1932
1933void DeclPrinter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
1934 if (!D->isInvalidDecl()) {
1935 Out << "#pragma omp declare mapper (";
1936 D->printName(Out, Policy);
1937 Out << " : ";
1938 D->getType().print(Out, Policy);
1939 Out << " ";
1940 Out << D->getVarName();
1941 Out << ")";
1942 if (!D->clauselist_empty()) {
1943 OMPClausePrinter Printer(Out, Policy, Context.getLangOpts().OpenMP);
1944 for (auto *C : D->clauselists()) {
1945 Out << " ";
1946 Printer.Visit(C);
1947 }
1948 }
1949 }
1950}
1951
1952void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
1953 D->getInit()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1954}
1955
1956void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) {
1957 if (const TypeConstraint *TC = TTP->getTypeConstraint())
1958 TC->print(Out, Policy);
1959 else if (TTP->wasDeclaredWithTypename())
1960 Out << "typename";
1961 else
1962 Out << "class";
1963
1964 if (TTP->isParameterPack())
1965 Out << " ...";
1966 else if (TTP->getDeclName())
1967 Out << ' ';
1968
1969 if (TTP->getDeclName()) {
1970 if (Policy.CleanUglifiedParameters && TTP->getIdentifier())
1971 Out << TTP->getIdentifier()->deuglifiedName();
1972 else
1973 Out << TTP->getDeclName();
1974 }
1975
1976 if (TTP->hasDefaultArgument() && !TTP->defaultArgumentWasInherited()) {
1977 Out << " = ";
1978 TTP->getDefaultArgument().getArgument().print(Policy, Out,
1979 /*IncludeType=*/false);
1980 }
1981}
1982
1983void DeclPrinter::VisitNonTypeTemplateParmDecl(
1984 const NonTypeTemplateParmDecl *NTTP) {
1985 StringRef Name;
1986 if (IdentifierInfo *II = NTTP->getIdentifier())
1987 Name =
1988 Policy.CleanUglifiedParameters ? II->deuglifiedName() : II->getName();
1989 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
1990
1991 if (NTTP->hasDefaultArgument() && !NTTP->defaultArgumentWasInherited()) {
1992 Out << " = ";
1993 NTTP->getDefaultArgument().getArgument().print(Policy, Out,
1994 /*IncludeType=*/false);
1995 }
1996}
1997
1998void DeclPrinter::VisitTemplateTemplateParmDecl(
1999 const TemplateTemplateParmDecl *TTPD) {
2000 VisitTemplateDecl(TTPD);
2001 if (TTPD->hasDefaultArgument() && !TTPD->defaultArgumentWasInherited()) {
2002 Out << " = ";
2003 TTPD->getDefaultArgument().getArgument().print(Policy, Out,
2004 /*IncludeType=*/false);
2005 }
2006}
2007
2008void DeclPrinter::VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D) {
2009 if (!D->isInvalidDecl()) {
2010 Out << "#pragma acc declare";
2011 if (!D->clauses().empty()) {
2012 Out << ' ';
2013 OpenACCClausePrinter Printer(Out, Policy);
2014 Printer.VisitClauseList(D->clauses());
2015 }
2016 }
2017}
2018void DeclPrinter::VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D) {
2019 if (!D->isInvalidDecl()) {
2020 Out << "#pragma acc routine";
2021
2022 Out << "(";
2023
2024 // The referenced function was named here, but this makes us tolerant of
2025 // errors.
2026 if (D->getFunctionReference())
2027 D->getFunctionReference()->printPretty(Out, nullptr, Policy, Indentation,
2028 "\n", &Context);
2029 else
2030 Out << "<error>";
2031
2032 Out << ")";
2033
2034 if (!D->clauses().empty()) {
2035 Out << ' ';
2036 OpenACCClausePrinter Printer(Out, Policy);
2037 Printer.VisitClauseList(D->clauses());
2038 }
2039 }
2040}
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:223
const LangOptions & getLangOpts() const
Definition ASTContext.h:980
const clang::PrintingPolicy & getPrintingPolicy() const
Definition ASTContext.h:876
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:3836
Attr - This represents one attribute.
Definition Attr.h:46
SourceLocation getLoc() const
shadow_range shadows() const
Definition DeclCXX.h:3587
Pointer to a block type.
Definition TypeBase.h:3656
Represents a call to a C++ constructor.
Definition ExprCXX.h:1551
Represents a C++ constructor within a class.
Definition DeclCXX.h:2637
Represents a C++ conversion function within a class.
Definition DeclCXX.h:2972
Represents a C++ deduction guide declaration.
Definition DeclCXX.h:1996
TemplateDecl * getDeducedTemplate() const
Get the template for which this guide performs deduction.
Definition DeclCXX.h:2060
Represents a C++26 expansion statement declaration.
CXXExpansionStmtPattern * getExpansionPattern()
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:1023
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Definition DeclCXX.cpp:1744
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:2360
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2126
bool isTranslationUnit() const
Definition DeclBase.h:2202
DeclContext(Decl::Kind K)
void dumpDeclContext() const
decl_iterator decls_end() const
Definition DeclBase.h:2405
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition DeclBase.h:2403
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:526
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:550
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition DeclBase.h:601
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:596
SourceLocation getLocation() const
Definition DeclBase.h:447
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
AccessSpecifier getAccess() const
Definition DeclBase.h:515
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
AttrVec & getAttrs()
Definition DeclBase.h:532
bool hasAttr() const
Definition DeclBase.h:585
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.
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
Definition Decl.h:855
ArrayRef< TemplateParameterList * > getTemplateParameterLists() 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:5313
An instance of this object exists for each enum constant that is defined.
Definition Decl.h:3557
const Expr * getInitExpr() const
Definition Decl.h:3575
Represents an enum.
Definition Decl.h:4145
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4363
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Definition Decl.h:4366
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
Definition Decl.h:4372
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Definition Decl.h:4318
Represents an explicit instantiation of a template entity in source code.
TypeSourceInfo * getTypeAsWritten() const
The declared type (return type or variable type) for function / variable templates.
std::optional< unsigned > getNumTemplateArgs() const
Returns the number of explicit template arguments, or std::nullopt if this entity has no template arg...
TemplateArgumentLoc getTemplateArg(unsigned I) const
NamedDecl * getSpecialization() const
NestedNameSpecifierLoc getQualifierLoc() const
Returns the qualifier regardless of where it is stored.
Store information needed for an explicit specifier.
Definition DeclCXX.h:1944
const Expr * getExpr() const
Definition DeclCXX.h:1953
static ExplicitSpecifier getFromDecl(const FunctionDecl *Function)
Definition DeclCXX.cpp:2370
bool isSpecified() const
Determine if the declaration had an explicit specifier of any kind.
Definition DeclCXX.h:1957
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3660
This represents one expression.
Definition Expr.h:112
Represents a member of a struct/union/class.
Definition Decl.h:3294
bool isMutable() const
Determines whether this field is mutable (C++ only).
Definition Decl.h:3394
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition Decl.cpp:4788
bool isBitField() const
Determines whether this field is a bitfield.
Definition Decl.h:3397
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Definition Decl.h:3468
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
Definition Decl.h:3410
const Expr * getAsmStringExpr() const
Definition Decl.h:4754
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition DeclFriend.h:46
virtual NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Definition DeclFriend.h:102
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition DeclFriend.h:96
bool isPackExpansion() const
Definition DeclFriend.h:113
Declaration of a friend template.
TemplateName getFriendTemplateName() const
ArrayRef< TemplateParameterList * > getTemplateParameterLists() const
Represents a function declaration or definition.
Definition Decl.h:2058
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:2927
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition Decl.cpp:3267
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
Definition Decl.cpp:4248
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition Decl.cpp:4236
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Definition Decl.h:2427
bool isImmediateFunction() const
Definition Decl.cpp:3383
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
Definition Decl.h:2888
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
Definition Decl.h:2515
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Definition Decl.h:2574
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
Definition Decl.h:2569
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
Definition Decl.h:2439
bool isConstexprSpecified() const
Definition Decl.h:2605
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Definition Decl.cpp:4372
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:3018
bool isDeletedAsWritten() const
Definition Decl.h:2670
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
Definition Decl.h:2479
bool isConsteval() const
Definition Decl.h:2608
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
Definition Decl.h:2470
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Definition Decl.cpp:3869
DeclarationNameInfo getNameInfo() const
Definition Decl.h:2324
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:3234
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Definition Decl.h:3029
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Definition Decl.cpp:4382
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5421
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition TypeBase.h:5728
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition TypeBase.h:5841
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition TypeBase.h:5779
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition TypeBase.h:5771
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition TypeBase.h:5737
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5825
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition TypeBase.h:5786
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition TypeBase.h:5855
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:4617
bool isConst() const
Definition TypeBase.h:4979
bool isRestrict() const
Definition TypeBase.h:4981
bool isVolatile() const
Definition TypeBase.h:4980
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
Definition Decl.h:5328
bool isCBuffer() const
Definition Decl.h:5372
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:5187
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Definition Decl.h:5245
Represents the declaration of a label.
Definition Decl.h:524
Represents a linkage specification.
Definition DeclCXX.h:3040
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
Definition DeclCXX.h:3063
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Definition DeclCXX.h:3074
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:240
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:656
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:1683
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:1690
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Definition Decl.cpp:1675
Represents a C++ namespace alias.
Definition DeclCXX.h:3226
NamespaceBaseDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
Definition DeclCXX.h:3319
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition DeclCXX.h:3291
Represent a C++ namespace.
Definition Decl.h:592
bool isInline() const
Returns true if this is an inline namespace declaration.
Definition Decl.h:648
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
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:2335
ObjCInterfaceDecl * getClassInterface()
Definition DeclObjC.h:2378
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
Definition DeclObjC.h:2383
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition DeclObjC.h:2551
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition DeclObjC.h:2781
const ObjCInterfaceDecl * getClassInterface() const
Definition DeclObjC.h:2799
const ObjCInterfaceDecl * getClassInterface() const
Definition DeclObjC.h:2492
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition DeclObjC.h:2603
std::string getNameAsString() const
Get the name of the class associated with this interface.
Definition DeclObjC.h:2735
ivar_range ivars() const
Definition DeclObjC.h:2755
unsigned ivar_size() const
Definition DeclObjC.h:2765
const ObjCInterfaceDecl * getSuperClass() const
Definition DeclObjC.h:2741
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
unsigned ivar_size() const
Definition DeclObjC.h:1475
ivar_range ivars() const
Definition DeclObjC.h:1457
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
Definition DeclObjC.h:1309
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
Definition DeclObjC.h:1529
const ObjCProtocolList & getReferencedProtocols() const
Definition DeclObjC.h:1339
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
Definition DeclObjC.h:1571
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:376
bool isVariadic() const
Definition DeclObjC.h:434
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Definition DeclObjC.cpp:927
Selector getSelector() const
Definition DeclObjC.h:330
bool isInstanceMethod() const
Definition DeclObjC.h:429
QualType getReturnType() const
Definition DeclObjC.h:332
Represents a pointer to an Objective C object.
Definition TypeBase.h:8122
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:734
Selector getSetterName() const
Definition DeclObjC.h:899
QualType getType() const
Definition DeclObjC.h:810
Selector getGetterName() const
Definition DeclObjC.h:891
ObjCPropertyAttribute::Kind getPropertyAttributes() const
Definition DeclObjC.h:821
PropertyControl getPropertyImplementation() const
Definition DeclObjC.h:918
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition DeclObjC.h:2811
ObjCIvarDecl * getPropertyIvarDecl() const
Definition DeclObjC.h:2885
Kind getPropertyImplementation() const
Definition DeclObjC.h:2881
ObjCPropertyDecl * getPropertyDecl() const
Definition DeclObjC.h:2876
Represents an Objective-C protocol declaration.
Definition DeclObjC.h:2090
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
Definition DeclObjC.h:2267
const ObjCProtocolList & getReferencedProtocols() const
Definition DeclObjC.h:2159
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition DeclObjC.h:665
ArrayRef< const OpenACCClause * > clauses() const
Definition DeclOpenACC.h:62
const Expr * getFunctionReference() const
Sugar for parentheses used when specifying types.
Definition TypeBase.h:3382
Represents a parameter to a function.
Definition Decl.h:1819
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3408
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
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:1404
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition TypeBase.h:1348
Represents a struct/union/class.
Definition Decl.h:4459
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3687
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:4161
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:1810
StringRef getKindName() const
Definition Decl.h:4047
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3952
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Definition Decl.h:4097
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.
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
bool isNull() const
Determine whether this template name is NULL.
void print(raw_ostream &OS, const PrintingPolicy &Policy, Qualified Qual=Qualified::AsWritten) const
Print the template name.
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:4769
The top declaration context.
Definition Decl.h:105
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition Decl.h:3822
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:8475
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8486
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9340
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition Decl.h:3801
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3696
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:3746
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4062
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition DeclCXX.h:4099
Represents a dependent using declaration which was not marked with typename.
Definition DeclCXX.h:3965
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition DeclCXX.h:4002
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition DeclCXX.h:4009
Represents a C++ using-declaration.
Definition DeclCXX.h:3616
bool hasTypename() const
Return true if the using declaration has 'typename'.
Definition DeclCXX.h:3665
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Definition DeclCXX.h:3662
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Definition DeclCXX.h:3653
Represents C++ using-directive.
Definition DeclCXX.h:3121
NamedDecl * getNominatedNamespaceAsWritten()
Definition DeclCXX.h:3174
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Definition DeclCXX.h:3170
Represents a C++ using-enum-declaration.
Definition DeclCXX.h:3817
EnumDecl * getEnumDecl() const
Definition DeclCXX.h:3859
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3424
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:932
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
Definition Decl.h:1593
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Definition Decl.h:1490
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
Definition Decl.cpp:2102
@ CInit
C-style initialization with assignment.
Definition Decl.h:937
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:940
bool isCXXForRangeDecl() const
Determine whether this variable is the for-range-declaration in a C++0x for-range statement.
Definition Decl.h:1546
ThreadStorageClassSpecifier getTSCSpec() const
Definition Decl.h:1183
const Expr * getInit() const
Definition Decl.h:1391
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1174
Represents a GCC generic vector type.
Definition TypeBase.h:4289
@ 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...
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
llvm::StringRef getAccessSpelling(AccessSpecifier AS)
Definition Specifiers.h:420
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
Definition Specifiers.h:356
@ ICIS_ListInit
Direct list-initialization.
Definition Specifiers.h:275
@ RQ_None
No ref-qualifier was provided.
Definition TypeBase.h:1801
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
Definition TypeBase.h:1804
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
Definition TypeBase.h:1807
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition Specifiers.h:124
@ AS_none
Definition Specifiers.h:128
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:249
@ SC_Auto
Definition Specifiers.h:257
@ SC_PrivateExtern
Definition Specifiers.h:254
@ SC_Extern
Definition Specifiers.h:252
@ SC_Register
Definition Specifiers.h:258
@ SC_Static
Definition Specifiers.h:253
@ SC_None
Definition Specifiers.h:251
@ TSCS_thread_local
C++11 thread_local.
Definition Specifiers.h:242
@ TSCS_unspecified
Definition Specifiers.h:237
@ TSCS__Thread_local
C11 _Thread_local.
Definition Specifiers.h:245
@ TSCS___thread
GNU __thread.
Definition Specifiers.h:239
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition JsonSupport.h:21
@ Default
Set to the current date and time.
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:586
llvm::StringRef getAsString(SyncScope S)
Definition SyncScope.h:63
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition Specifiers.h:195
@ Invariant
The parameter is invariant: must match exactly.
Definition DeclObjC.h:558
@ Contravariant
The parameter is contravariant, e.g., X<T> is a subtype of X when the type parameter is covariant and...
Definition DeclObjC.h:566
@ 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:562
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.