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