24#include "llvm/Support/raw_ostream.h"
28 class DeclPrinter :
public DeclVisitor<DeclPrinter> {
33 bool PrintInstantiation;
35 raw_ostream& Indent() {
return Indent(Indentation); }
36 raw_ostream& Indent(
unsigned Indentation);
52 enum class AttrPrintLoc {
61 void prettyPrintAttributes(
Decl *D, raw_ostream &out,
62 AttrPrintLoc loc = AttrPrintLoc::Any);
66 const ASTContext &Context,
unsigned Indentation = 0,
67 bool PrintInstantiation =
false)
68 : Out(Out), Policy(Policy), Context(Context), Indentation(Indentation),
69 PrintInstantiation(PrintInstantiation) {}
71 void VisitDeclContext(
DeclContext *DC,
bool Indent =
true);
98 void VisitClassTemplateSpecializationDecl(
100 void VisitClassTemplatePartialSpecializationDecl(
127 bool OmitTemplateKW =
false);
133 inline void prettyPrintAttributes(
Decl *D) {
134 prettyPrintAttributes(D, Out);
137 void prettyPrintPragmas(
Decl *D);
138 void printDeclType(
QualType T, StringRef DeclName,
bool Pack =
false);
143 bool PrintInstantiation)
const {
148 unsigned Indentation,
bool PrintInstantiation)
const {
149 DeclPrinter Printer(Out, Policy,
getASTContext(), Indentation,
151 Printer.Visit(
const_cast<Decl*
>(
this));
155 bool OmitTemplateKW)
const {
161 bool OmitTemplateKW)
const {
162 DeclPrinter Printer(Out, Policy, Context);
163 Printer.printTemplateParameters(
this, OmitTemplateKW);
177 else if (
const ArrayType *ATy = dyn_cast<ArrayType>(BaseType))
178 BaseType = ATy->getElementType();
180 BaseType = FTy->getReturnType();
182 BaseType = VTy->getElementType();
186 BaseType = ATy->getDeducedType();
188 BaseType = PTy->desugar();
198 return TDD->getUnderlyingType();
199 if (
ValueDecl* VD = dyn_cast<ValueDecl>(D))
200 return VD->getType();
206 unsigned Indentation) {
208 (*Begin)->print(Out, Policy, Indentation);
227 if (!isFirst) Out <<
", ";
232 (*Begin)->print(Out, SubPolicy, Indentation);
242 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
244 Printer.VisitDeclContext(
const_cast<DeclContext *
>(
this),
false);
247raw_ostream& DeclPrinter::Indent(
unsigned Indentation) {
248 for (
unsigned i = 0; i != Indentation; ++i)
254#include "clang/Basic/AttrLeftSideCanPrintList.inc"
257#include "clang/Basic/AttrLeftSideMustPrintList.inc"
260#ifdef CLANG_ATTR_LIST_CanPrintOnLeft
262 CLANG_ATTR_LIST_CanPrintOnLeft
280#ifdef CLANG_ATTR_LIST_PrintOnLeft
282 CLANG_ATTR_LIST_PrintOnLeft
299void DeclPrinter::prettyPrintAttributes(
Decl *D, llvm::raw_ostream &Out,
306 for (
auto *A : Attrs) {
307 if (A->isInherited() || A->isImplicit())
310 AttrPrintLoc AttrLoc = AttrPrintLoc::Right;
314 AttrLoc = AttrPrintLoc::Left;
322 AttrLoc = AttrPrintLoc::Left;
326 else if (
const VarDecl *VD = dyn_cast<VarDecl>(D);
329 AttrLoc = AttrPrintLoc::Left;
332 if ((Loc & AttrLoc) != AttrPrintLoc::None)
333 A->printPretty(Out, Policy);
338void DeclPrinter::prettyPrintPragmas(
Decl *D) {
344 for (
auto *A : Attrs) {
345 switch (A->getKind()) {
347#define PRAGMA_SPELLING_ATTR(X) case attr::X:
348#include "clang/Basic/AttrList.inc"
349 A->printPretty(Out, Policy);
359void DeclPrinter::printDeclType(
QualType T, StringRef DeclName,
bool Pack) {
365 T = PET->getPattern();
367 T.
print(Out, Policy, (Pack ?
"..." :
"") + DeclName, Indentation);
380 if (AccessSpelling.empty())
381 llvm_unreachable(
"No access specifier!");
382 Out << AccessSpelling;
386 std::string &Proto) {
387 bool HasInitializerList =
false;
388 for (
const auto *BMInitializer : CDecl->
inits()) {
389 if (BMInitializer->isInClassMemberInitializer())
391 if (!BMInitializer->isWritten())
394 if (!HasInitializerList) {
398 HasInitializerList =
true;
402 if (BMInitializer->isAnyMemberInitializer()) {
403 FieldDecl *FD = BMInitializer->getAnyMember();
405 }
else if (BMInitializer->isDelegatingInitializer()) {
411 if (
Expr *
Init = BMInitializer->getInit()) {
412 bool OutParens = !isa<InitListExpr>(
Init);
418 Init = Tmp->getSubExpr();
422 Expr *SimpleInit =
nullptr;
423 Expr **Args =
nullptr;
424 unsigned NumArgs = 0;
426 Args = ParenList->getExprs();
427 NumArgs = ParenList->getNumExprs();
429 dyn_cast<CXXConstructExpr>(
Init)) {
430 Args = Construct->getArgs();
431 NumArgs = Construct->getNumArgs();
436 SimpleInit->
printPretty(Out,
nullptr, Policy, Indentation,
"\n",
439 for (
unsigned I = 0; I != NumArgs; ++I) {
440 assert(Args[I] !=
nullptr &&
"Expected non-null Expr");
441 if (isa<CXXDefaultArgExpr>(Args[I]))
446 Args[I]->
printPretty(Out,
nullptr, Policy, Indentation,
"\n",
457 if (BMInitializer->isPackExpansion())
466void DeclPrinter::VisitDeclContext(
DeclContext *DC,
bool Indent) {
479 if (isa<ObjCIvarDecl>(*D))
488 if (
auto FD = dyn_cast<FunctionDecl>(*D))
490 !isa<ClassTemplateSpecializationDecl>(DC))
506 if (!Decls.empty() && !CurDeclType.
isNull()) {
508 if (!BaseType.
isNull() && isa<ElaboratedType>(BaseType) &&
509 cast<ElaboratedType>(BaseType)->getOwnedTagDecl() == Decls[0]) {
517 ProcessDeclGroup(Decls);
521 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->isFreeStanding()) {
526 if (isa<AccessSpecDecl>(*D)) {
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;
551 }
else if (
auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
552 if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
553 Terminator =
nullptr;
559 Terminator =
nullptr;
560 else if (isa<EnumConstantDecl>(*D)) {
571 ((isa<FunctionDecl>(*D) &&
572 cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
573 (isa<FunctionTemplateDecl>(*D) &&
574 cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
581 if (D->
hasAttr<OMPDeclareTargetDeclAttr>())
582 Out <<
"#pragma omp end declare target\n";
586 ProcessDeclGroup(Decls);
593 VisitDeclContext(D,
false);
596void DeclPrinter::VisitTypedefDecl(
TypedefDecl *D) {
601 Out <<
"__module_private__ ";
605 prettyPrintAttributes(D);
609 Out <<
"using " << *D;
610 prettyPrintAttributes(D);
614void DeclPrinter::VisitEnumDecl(
EnumDecl *D) {
616 Out <<
"__module_private__ ";
625 prettyPrintAttributes(D);
640void DeclPrinter::VisitRecordDecl(
RecordDecl *D) {
642 Out <<
"__module_private__ ";
645 prettyPrintAttributes(D);
650 if (D->isCompleteDefinition()) {
659 prettyPrintAttributes(D);
662 Init->printPretty(Out,
nullptr, Policy, Indentation,
"\n", &Context);
669 std::string Proto =
"explicit";
670 llvm::raw_string_ostream EOut(Proto);
684 llvm::raw_ostream &Out) {
695 prettyPrintPragmas(D);
698 Out <<
"template<> ";
701 I < NumTemplateParams; ++I)
705 std::string LeftsideAttrs;
706 llvm::raw_string_ostream LSAS(LeftsideAttrs);
708 prettyPrintAttributes(D, LSAS, AttrPrintLoc::Left);
711 if (LeftsideAttrs[0] ==
' ') {
713 LeftsideAttrs.erase(0, LeftsideAttrs.find_first_not_of(
' '));
719 Out << LeftsideAttrs;
731 llvm_unreachable(
"invalid for functions");
748 SubPolicy.SuppressSpecifiers =
false;
754 llvm::raw_string_ostream OS(Proto);
757 NS->print(OS, Policy);
766 llvm::raw_string_ostream POut(Proto);
767 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
770 TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(),
nullptr);
773 TArgPrinter.printTemplateArguments(TArgs->asArray(),
nullptr);
777 while (
const ParenType *PT = dyn_cast<ParenType>(Ty)) {
778 Proto =
'(' + Proto +
')';
779 Ty = PT->getInnerType();
785 FT = dyn_cast<FunctionProtoType>(AFT);
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) {
805 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
818 Proto +=
" volatile";
820 Proto +=
" restrict";
847 Proto +=
" noexcept";
850 llvm::raw_string_ostream EOut(Proto);
852 Indentation,
"\n", &Context);
860 PrintConstructorInitializers(CDecl, Proto);
861 }
else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
865 Out << Proto <<
" -> ";
872 AFT->getReturnType().print(Out, Policy, Proto);
879 TrailingRequiresClause->printPretty(Out,
nullptr, SubPolicy, Indentation,
883 Ty.
print(Out, Policy, Proto);
886 prettyPrintAttributes(D, Out, AttrPrintLoc::Right);
900 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
902 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
914 if (!Policy.
TerseOutput && isa<CXXConstructorDecl>(*D))
920void DeclPrinter::VisitFriendDecl(
FriendDecl *D) {
923 for (
unsigned i = 0; i < NumTPLists; ++i)
926 Out <<
" " << TSI->getType().getAsString(Policy);
931 VisitFunctionDecl(FD);
936 VisitFunctionTemplateDecl(FTD);
941 VisitRedeclarableTemplateDecl(CTD);
945void DeclPrinter::VisitFieldDecl(
FieldDecl *D) {
950 Out <<
"__module_private__ ";
953 stream(Policy, D->
getName(), Indentation);
967 Init->printPretty(Out,
nullptr, Policy, Indentation,
"\n", &Context);
969 prettyPrintAttributes(D);
972void DeclPrinter::VisitLabelDecl(
LabelDecl *D) {
976void DeclPrinter::VisitVarDecl(
VarDecl *D) {
977 prettyPrintPragmas(D);
979 if (
const auto *Param = dyn_cast<ParmVarDecl>(D);
980 Param && Param->isExplicitObjectParameter())
983 std::string LeftSide;
984 llvm::raw_string_ostream LeftSideStream(LeftSide);
987 prettyPrintAttributes(D, LeftSideStream, AttrPrintLoc::Left);
990 if (LeftSide[0] ==
' ') {
992 LeftSide.erase(0, LeftSide.find_first_not_of(
' '));
995 LeftSideStream <<
' ';
1016 Out <<
"_Thread_local ";
1019 Out <<
"thread_local ";
1024 Out <<
"__module_private__ ";
1027 Out <<
"constexpr ";
1042 printDeclType(T, Name);
1046 prettyPrintAttributes(D, Out, AttrPrintLoc::Right);
1050 bool ImplicitInit =
false;
1053 ImplicitInit =
true;
1055 dyn_cast<CXXConstructExpr>(
Init->IgnoreImplicit())) {
1057 !Construct->isListInitialization()) {
1058 ImplicitInit = Construct->getNumArgs() == 0 ||
1062 if (!ImplicitInit) {
1069 SubPolicy.SuppressSpecifiers =
false;
1070 SubPolicy.IncludeTagDefinition =
false;
1071 Init->printPretty(Out,
nullptr, SubPolicy, Indentation,
"\n", &Context);
1078void DeclPrinter::VisitParmVarDecl(
ParmVarDecl *D) {
1094void DeclPrinter::VisitImportDecl(
ImportDecl *D) {
1100 Out <<
"static_assert(";
1105 E->printPretty(Out,
nullptr, Policy, Indentation,
"\n", &Context);
1117 Out <<
"namespace ";
1122 VisitDeclContext(D);
1127 Out <<
"using namespace ";
1134 Out <<
"namespace " << *D <<
" = ";
1140void DeclPrinter::VisitEmptyDecl(
EmptyDecl *D) {
1141 prettyPrintAttributes(D);
1147 Out <<
"__module_private__ ";
1150 prettyPrintAttributes(D);
1155 NNS->print(Out, Policy);
1158 if (
auto S = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
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());
1170 if (D->hasDefinition()) {
1171 if (D->hasAttr<FinalAttr>()) {
1176 if (D->isCompleteDefinition()) {
1178 if (D->getNumBases()) {
1181 BaseEnd = D->bases_end();
Base != BaseEnd; ++
Base) {
1182 if (
Base != D->bases_begin())
1185 if (
Base->isVirtual())
1193 Out <<
Base->getType().getAsString(Policy);
1195 if (
Base->isPackExpansion())
1206 VisitDeclContext(D);
1218 "unknown language in linkage specification");
1222 Out <<
"extern \"" << l <<
"\" ";
1225 VisitDeclContext(D);
1232 bool OmitTemplateKW) {
1239 if (!OmitTemplateKW)
1243 bool NeedComma =
false;
1244 for (
const Decl *Param : *Params) {
1245 if (Param->isImplicit())
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);
1264 if (!OmitTemplateKW)
1271 for (
size_t I = 0, E = Args.size(); I < E; ++I) {
1275 Args[I].print(Policy, Out,
true);
1277 Args[I].print(Policy, Out,
1279 Policy, Params, I));
1287 for (
size_t I = 0, E = Args.size(); I < E; ++I) {
1291 Args[I].getArgument().print(Policy, Out,
true);
1293 Args[I].getArgument().print(
1301void DeclPrinter::VisitTemplateDecl(
const TemplateDecl *D) {
1305 dyn_cast<TemplateTemplateParmDecl>(D)) {
1308 if (TTP->isParameterPack())
1310 else if (TTP->getDeclName())
1313 if (TTP->getDeclName()) {
1315 Out << TTP->getIdentifier()->deuglifiedName();
1317 Out << TTP->getDeclName();
1321 else if (
const auto *Concept = dyn_cast<ConceptDecl>(D)) {
1322 Out <<
"concept " <<
Concept->getName() <<
" = " ;
1323 Concept->getConstraintExpr()->printPretty(Out,
nullptr, Policy, Indentation,
1333 I < NumTemplateParams; ++I)
1336 VisitRedeclarableTemplateDecl(D);
1340 Out <<
"#pragma omp end declare target\n";
1344 if (PrintInstantiation &&
1348 if (PrevDecl->
isDefined(Def) && Def != PrevDecl)
1355 prettyPrintPragmas(I);
1362 VisitRedeclarableTemplateDecl(D);
1364 if (PrintInstantiation) {
1376void DeclPrinter::VisitClassTemplateSpecializationDecl(
1378 Out <<
"template<> ";
1379 VisitCXXRecordDecl(D);
1382void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1385 VisitCXXRecordDecl(D);
1392void DeclPrinter::PrintObjCMethodType(
ASTContext &Ctx,
1419 unsigned First =
true;
1420 for (
auto *Param : *Params) {
1427 switch (Param->getVariance()) {
1432 Out <<
"__covariant ";
1436 Out <<
"__contravariant ";
1440 Out << Param->getDeclName();
1442 if (Param->hasExplicitBound()) {
1443 Out <<
" : " << Param->getUnderlyingType().getAsString(Policy);
1460 std::string::size_type pos, lastPos = 0;
1463 pos =
name.find_first_of(
':', lastPos);
1466 Out <<
name.substr(lastPos, pos - lastPos) <<
':';
1468 PI->getObjCDeclQualifier(),
1480 prettyPrintAttributes(OMD);
1495 bool eolnOut =
false;
1497 Out <<
"@implementation " << I <<
" : " << *SID;
1499 Out <<
"@implementation " << I;
1505 for (
const auto *I : OID->
ivars()) {
1506 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1516 VisitDeclContext(OID,
false);
1527 Out <<
"@class " << I;
1530 PrintObjCTypeParams(TypeParams);
1536 bool eolnOut =
false;
1538 prettyPrintAttributes(OID);
1542 Out <<
"@interface " << I;
1545 PrintObjCTypeParams(TypeParams);
1553 if (!Protocols.
empty()) {
1555 E = Protocols.
end(); I != E; ++I)
1556 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1564 for (
const auto *I : OID->
ivars()) {
1565 Indent() << I->getASTContext()
1566 .getUnqualifiedObjCPointerType(I->getType())
1567 .getAsString(Policy) <<
' ' << *I <<
";\n";
1577 VisitDeclContext(OID,
false);
1586 Out <<
"@protocol " << *PID <<
";\n";
1591 if (!Protocols.
empty()) {
1592 Out <<
"@protocol " << *PID;
1594 E = Protocols.
end(); I != E; ++I)
1595 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1598 Out <<
"@protocol " << *PID <<
'\n';
1599 VisitDeclContext(PID,
false);
1604 Out <<
"@implementation ";
1608 Out <<
"<<error-type>>";
1609 Out <<
'(' << *PID <<
")\n";
1611 VisitDeclContext(PID,
false);
1617 Out <<
"@interface ";
1621 Out <<
"<<error-type>>";
1623 PrintObjCTypeParams(TypeParams);
1625 Out <<
"(" << *PID <<
")\n";
1626 if (PID->ivar_size() > 0) {
1629 for (
const auto *I : PID->ivars())
1630 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1636 VisitDeclContext(PID,
false);
1643 Out <<
"@compatibility_alias " << *AID
1658 Out <<
"@required\n";
1660 Out <<
"@optional\n";
1669 Out << (first ?
"" :
", ") <<
"class";
1674 Out << (first ?
"" :
", ") <<
"direct";
1680 Out << (first ?
"" :
", ") <<
"nonatomic";
1684 Out << (first ?
"" :
", ") <<
"atomic";
1689 Out << (first ?
"" :
", ") <<
"assign";
1693 Out << (first ?
"" :
", ") <<
"retain";
1698 Out << (first ?
"" :
", ") <<
"strong";
1702 Out << (first ?
"" :
", ") <<
"copy";
1706 Out << (first ?
"" :
", ") <<
"weak";
1711 Out << (first ?
"" :
", ") <<
"unsafe_unretained";
1717 Out << (first ?
"" :
", ") <<
"readwrite";
1721 Out << (first ?
"" :
", ") <<
"readonly";
1726 Out << (first ?
"" :
", ") <<
"getter = ";
1731 Out << (first ?
"" :
", ") <<
"setter = ";
1742 Out << (first ?
"" :
", ") <<
"null_resettable";
1744 Out << (first ?
"" :
", ")
1756 Out <<
' ' << TypeStr;
1757 if (!StringRef(TypeStr).ends_with(
"*"))
1766 Out <<
"@synthesize ";
1774void DeclPrinter::VisitUsingDecl(
UsingDecl *D) {
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();
1800 Out <<
"using typename ";
1817 Out <<
"#pragma omp threadprivate";
1823 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1838 prettyPrintAttributes(D);
1841 VisitDeclContext(D);
1846 Out <<
"#pragma omp allocate";
1852 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1867 Out <<
"#pragma omp requires ";
1877 Out <<
"#pragma omp declare reduction (";
1879 const char *OpName =
1881 assert(OpName &&
"not an overloaded operator");
1893 Out <<
" initializer(";
1899 Out <<
"omp_priv = ";
1904 Init->printPretty(Out,
nullptr, Policy, 0,
"\n", &Context);
1914 Out <<
"#pragma omp declare mapper (";
1937 TC->print(Out, Policy);
1961void DeclPrinter::VisitNonTypeTemplateParmDecl(
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.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
const clang::PrintingPolicy & getPrintingPolicy() const
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.
Attr - This represents one attribute.
attr::Kind getKind() const
bool isDeclspecAttribute() const
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.
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
shadow_range shadows() const
Represents a base class of a C++ class.
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
Represents a C++ conversion function within a class.
Represents a C++ deduction guide declaration.
TemplateDecl * getDeducedTemplate() const
Get the template for which this guide performs deduction.
Represents a C++ struct/union/class.
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.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isTranslationUnit() const
void dumpDeclContext() const
decl_iterator decls_end() const
decl_iterator decls_begin() const
A simple visitor class that helps create declaration visitors.
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
@ OBJC_TQ_CSNullability
The nullability qualifier is set when the nullability of the result or parameter was expressed via a ...
bool isInvalidDecl() const
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
AccessSpecifier getAccess() const
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
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 ...
TemplateParameterList * getTemplateParameterList(unsigned index) const
unsigned getNumTemplateParameterLists() const
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
TypeSourceInfo * getTypeSourceInfo() const
Represents an empty-declaration.
An instance of this object exists for each enum constant that is defined.
const Expr * getInitExpr() const
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Store information needed for an explicit specifier.
const Expr * getExpr() const
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
bool isSpecified() const
Determine if the declaration had an explicit specifier of any kind.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Represents a member of a struct/union/class.
bool isMutable() const
Determines whether this field is mutable (C++ only).
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
bool isBitField() const
Determines whether this field is a bitfield.
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
const StringLiteral * getAsmString() const
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
unsigned getFriendTypeNumTemplateParameterLists() const
TemplateParameterList * getFriendTypeTemplateParameterList(unsigned N) const
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
bool isImmediateFunction() const
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
bool hasWrittenPrototype() const
Whether this function has a written prototype.
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
bool isConstexprSpecified() const
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isDeletedAsWritten() const
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
DeclarationNameInfo getNameInfo() const
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Represents a prototype with parameter type info, e.g.
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
unsigned getNumExceptions() const
Return the number of types in the exception specification.
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
bool isVariadic() const
Whether this function prototype is variadic.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
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.
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
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...
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Represents the declaration of a label.
Represents a linkage specification.
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
This represents a decl that may have a name.
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
std::string getQualifiedNameAsString() const
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...
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...
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Represents a C++ namespace alias.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
NamedDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
Represent a C++ namespace.
bool isInline() const
Returns true if this is an inline namespace declaration.
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.
bool varlist_empty() const
bool clauselist_empty() const
varlist_iterator varlist_begin()
MutableArrayRef< Expr * >::iterator varlist_iterator
clauselist_range clauselists()
varlist_iterator varlist_end()
Pseudo declaration for capturing expressions.
This is a basic class for representing single OpenMP clause.
This represents '#pragma omp declare mapper ...' directive.
clauselist_range clauselists()
DeclarationName getVarName()
Get the name of the variable declared in the mapper.
bool clauselist_empty() const
This represents '#pragma omp declare reduction ...' directive.
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
OMPDeclareReductionInitKind getInitializerKind() const
Get initializer kind.
This represents '#pragma omp requires...' directive.
clauselist_iterator clauselist_begin()
bool clauselist_empty() const
clauselist_iterator clauselist_end()
This represents '#pragma omp threadprivate ...' directive.
MutableArrayRef< Expr * >::iterator varlist_iterator
bool varlist_empty() const
varlist_iterator varlist_end()
varlist_iterator varlist_begin()
ObjCCategoryDecl - Represents a category declaration.
ObjCInterfaceDecl * getClassInterface()
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
ObjCCompatibleAliasDecl - Represents alias of a class.
const ObjCInterfaceDecl * getClassInterface() const
const ObjCInterfaceDecl * getClassInterface() const
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
std::string getNameAsString() const
Get the name of the class associated with this interface.
unsigned ivar_size() const
const ObjCInterfaceDecl * getSuperClass() const
Represents an ObjC class declaration.
unsigned ivar_size() const
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
const ObjCProtocolList & getReferencedProtocols() const
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
ObjCInterfaceDecl * getSuperClass() const
ObjCList - This is a simple template class used to hold various lists of decls etc,...
ObjCMethodDecl - Represents an instance or class method declaration.
ObjCDeclQualifier getObjCDeclQualifier() const
ArrayRef< ParmVarDecl * > parameters() const
param_const_iterator param_end() const
param_const_iterator param_begin() const
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Selector getSelector() const
bool isInstanceMethod() const
QualType getReturnType() const
Represents a pointer to an Objective C object.
Represents one property declaration in an Objective-C interface.
Selector getSetterName() const
Selector getGetterName() const
ObjCPropertyAttribute::Kind getPropertyAttributes() const
PropertyControl getPropertyImplementation() const
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
ObjCIvarDecl * getPropertyIvarDecl() const
Kind getPropertyImplementation() const
ObjCPropertyDecl * getPropertyDecl() const
Represents an Objective-C protocol declaration.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
const ObjCProtocolList & getReferencedProtocols() const
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Represents a pack expansion of types.
Sugar for parentheses used when specifying types.
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
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
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Represents a struct/union/class.
Base for LValueReferenceType and RValueReferenceType.
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.
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.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
StringRef getKindName() const
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
A template argument list.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
void print(raw_ostream &Out, const ASTContext &Context, bool OmitTemplateKW=false) const
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
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.
The top declaration context.
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
A container of type source information.
QualType getType() const
Return the type wrapped by this type source info.
bool isStructureType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
const T * getAs() const
Member-template getAs<specific type>'.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Base class for declarations which introduce a typedef-name.
TypeSourceInfo * getTypeSourceInfo() const
Represents a dependent using declaration which was marked with typename.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Represents a dependent using declaration which was not marked with typename.
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Represents a C++ using-declaration.
bool hasTypename() const
Return true if the using declaration has 'typename'.
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Represents C++ using-directive.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
NamedDecl * getNominatedNamespaceAsWritten()
Represents a C++ using-enum-declaration.
EnumDecl * getEnumDecl() const
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
@ CInit
C-style initialization with assignment.
@ CallInit
Call-style initialization (C++98)
bool isCXXForRangeDecl() const
Determine whether this variable is the for-range-declaration in a C++0x for-range statement.
ThreadStorageClassSpecifier getTSCSpec() const
const Expr * getInit() const
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Represents a GCC generic vector type.
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
@ LLVM_MARK_AS_BITMASK_ENUM
The JSON file list parser is used to communicate input to InstallAPI.
llvm::StringRef getAccessSpelling(AccessSpecifier AS)
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
@ ICIS_ListInit
Direct list-initialization.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
StorageClass
Storage classes.
@ TSCS_thread_local
C++11 thread_local.
@ TSCS__Thread_local
C11 _Thread_local.
@ TSCS___thread
GNU __thread.
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)
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ 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...
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 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.
unsigned SuppressInitializers
Suppress printing of variable initializers.
unsigned IncludeTagDefinition
When true, include the body of a tag definition.
unsigned TerseOutput
Provide a 'terse' output.