Go to the documentation of this file.
24 #include "llvm/Support/raw_ostream.h"
25 using namespace clang;
28 class DeclPrinter :
public DeclVisitor<DeclPrinter> {
33 bool PrintInstantiation;
36 raw_ostream&
Indent(
unsigned Indentation);
54 const ASTContext &Context,
unsigned Indentation = 0,
55 bool PrintInstantiation =
false)
56 : Out(Out), Policy(Policy), Context(Context), Indentation(Indentation),
57 PrintInstantiation(PrintInstantiation) {}
85 void VisitClassTemplateSpecializationDecl(
87 void VisitClassTemplatePartialSpecializationDecl(
113 bool OmitTemplateKW =
false);
118 void prettyPrintAttributes(
Decl *D);
119 void prettyPrintPragmas(
Decl *D);
120 void printDeclType(
QualType T, StringRef DeclName,
bool Pack =
false);
125 bool PrintInstantiation)
const {
130 unsigned Indentation,
bool PrintInstantiation)
const {
131 DeclPrinter Printer(Out, Policy,
getASTContext(), Indentation,
133 Printer.Visit(
const_cast<Decl*
>(
this));
137 bool OmitTemplateKW)
const {
143 bool OmitTemplateKW)
const {
144 DeclPrinter Printer(Out, Policy, Context);
145 Printer.printTemplateParameters(
this, OmitTemplateKW);
159 else if (
const ArrayType *ATy = dyn_cast<ArrayType>(BaseType))
160 BaseType = ATy->getElementType();
162 BaseType = FTy->getReturnType();
164 BaseType = VTy->getElementType();
168 BaseType = ATy->getDeducedType();
170 BaseType = PTy->desugar();
180 return TDD->getUnderlyingType();
181 if (
ValueDecl* VD = dyn_cast<ValueDecl>(D))
182 return VD->getType();
188 unsigned Indentation) {
190 (*Begin)->print(Out, Policy, Indentation);
209 if (!isFirst) Out <<
", ";
214 (*Begin)->print(Out, SubPolicy, Indentation);
224 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
226 Printer.VisitDeclContext(
const_cast<DeclContext *
>(
this),
false);
229 raw_ostream& DeclPrinter::Indent(
unsigned Indentation) {
230 for (
unsigned i = 0; i != Indentation; ++i)
235 void DeclPrinter::prettyPrintAttributes(
Decl *D) {
236 if (Policy.PolishForDeclaration)
241 for (
auto *A : Attrs) {
242 if (A->isInherited() || A->isImplicit())
244 switch (A->getKind()) {
246 #define PRAGMA_SPELLING_ATTR(X) case attr::X:
247 #include "clang/Basic/AttrList.inc"
250 A->printPretty(Out, Policy);
257 void DeclPrinter::prettyPrintPragmas(
Decl *D) {
258 if (Policy.PolishForDeclaration)
263 for (
auto *A : Attrs) {
264 switch (A->getKind()) {
266 #define PRAGMA_SPELLING_ATTR(X) case attr::X:
267 #include "clang/Basic/AttrList.inc"
268 A->printPretty(Out, Policy);
278 void DeclPrinter::printDeclType(
QualType T, StringRef DeclName,
bool Pack) {
284 T = PET->getPattern();
286 T.
print(Out, Policy, (Pack ?
"..." :
"") + DeclName, Indentation);
299 if (AccessSpelling.empty())
300 llvm_unreachable(
"No access specifier!");
301 Out << AccessSpelling;
306 bool HasInitializerList =
false;
307 for (
const auto *BMInitializer : CDecl->
inits()) {
308 if (BMInitializer->isInClassMemberInitializer())
311 if (!HasInitializerList) {
315 HasInitializerList =
true;
319 if (BMInitializer->isAnyMemberInitializer()) {
320 FieldDecl *FD = BMInitializer->getAnyMember();
327 if (!BMInitializer->getInit()) {
330 Expr *Init = BMInitializer->getInit();
332 Init = Tmp->getSubExpr();
334 Init = Init->IgnoreParens();
336 Expr *SimpleInit =
nullptr;
337 Expr **Args =
nullptr;
338 unsigned NumArgs = 0;
339 if (
ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
340 Args = ParenList->getExprs();
341 NumArgs = ParenList->getNumExprs();
343 dyn_cast<CXXConstructExpr>(Init)) {
344 Args = Construct->getArgs();
345 NumArgs = Construct->getNumArgs();
350 SimpleInit->
printPretty(Out,
nullptr, Policy, Indentation,
"\n",
353 for (
unsigned I = 0; I != NumArgs; ++I) {
354 assert(Args[I] !=
nullptr &&
"Expected non-null Expr");
355 if (isa<CXXDefaultArgExpr>(Args[I]))
360 Args[I]->
printPretty(Out,
nullptr, Policy, Indentation,
"\n",
366 if (BMInitializer->isPackExpansion())
376 if (Policy.TerseOutput)
380 Indentation += Policy.Indentation;
388 if (isa<ObjCIvarDecl>(*D))
397 if (
auto FD = dyn_cast<FunctionDecl>(*D))
399 !isa<ClassTemplateSpecializationDecl>(DC))
415 if (!Decls.empty() && !CurDeclType.
isNull()) {
417 if (!BaseType.
isNull() && isa<ElaboratedType>(BaseType) &&
418 cast<ElaboratedType>(BaseType)->getOwnedTagDecl() == Decls[0]) {
426 ProcessDeclGroup(Decls);
430 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->isFreeStanding()) {
435 if (isa<AccessSpecDecl>(*D)) {
436 Indentation -= Policy.Indentation;
440 Indentation += Policy.Indentation;
448 const char *Terminator =
nullptr;
449 if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D) ||
450 isa<OMPDeclareMapperDecl>(*D) || isa<OMPRequiresDecl>(*D) ||
451 isa<OMPAllocateDecl>(*D))
452 Terminator =
nullptr;
453 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
454 Terminator =
nullptr;
455 else if (
auto FD = dyn_cast<FunctionDecl>(*D)) {
456 if (FD->isThisDeclarationADefinition())
457 Terminator =
nullptr;
460 }
else if (
auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
461 if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
462 Terminator =
nullptr;
465 }
else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
466 isa<ObjCImplementationDecl>(*D) ||
467 isa<ObjCInterfaceDecl>(*D) ||
468 isa<ObjCProtocolDecl>(*D) ||
469 isa<ObjCCategoryImplDecl>(*D) ||
470 isa<ObjCCategoryDecl>(*D))
471 Terminator =
nullptr;
472 else if (isa<EnumConstantDecl>(*D)) {
482 if (!Policy.TerseOutput &&
483 ((isa<FunctionDecl>(*D) &&
484 cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
485 (isa<FunctionTemplateDecl>(*D) &&
486 cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
493 if (D->
hasAttr<OMPDeclareTargetDeclAttr>())
494 Out <<
"#pragma omp end declare target\n";
498 ProcessDeclGroup(Decls);
501 Indentation -= Policy.Indentation;
505 VisitDeclContext(D,
false);
508 void DeclPrinter::VisitTypedefDecl(
TypedefDecl *D) {
509 if (!Policy.SuppressSpecifiers) {
513 Out <<
"__module_private__ ";
517 prettyPrintAttributes(D);
521 Out <<
"using " << *D;
522 prettyPrintAttributes(D);
523 Out <<
" = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
526 void DeclPrinter::VisitEnumDecl(
EnumDecl *D) {
528 Out <<
"__module_private__ ";
537 prettyPrintAttributes(D);
552 void DeclPrinter::VisitRecordDecl(
RecordDecl *D) {
554 Out <<
"__module_private__ ";
557 prettyPrintAttributes(D);
562 if (D->isCompleteDefinition()) {
571 prettyPrintAttributes(D);
572 if (
Expr *Init = D->getInitExpr()) {
574 Init->printPretty(Out,
nullptr, Policy, Indentation,
"\n", &Context);
582 llvm::raw_string_ostream EOut(Proto);
597 prettyPrintPragmas(D);
600 Out <<
"template<> ";
603 I < NumTemplateParams; ++I)
610 if (!Policy.SuppressSpecifiers) {
617 llvm_unreachable(
"invalid for functions");
632 SubPolicy.SuppressSpecifiers =
false;
635 if (Policy.FullyQualifiedName) {
638 llvm::raw_string_ostream
OS(Proto);
639 if (!Policy.SuppressScope) {
641 NS->print(OS, Policy);
650 llvm::raw_string_ostream POut(Proto);
651 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
653 if (TArgAsWritten && !Policy.PrintCanonicalTypes)
654 TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(),
nullptr);
657 TArgPrinter.printTemplateArguments(TArgs->asArray(),
nullptr);
661 while (
const ParenType *PT = dyn_cast<ParenType>(Ty)) {
662 Proto =
'(' + Proto +
')';
663 Ty = PT->getInnerType();
669 FT = dyn_cast<FunctionProtoType>(AFT);
673 llvm::raw_string_ostream POut(Proto);
674 DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
675 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
689 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
702 Proto +=
" volatile";
704 Proto +=
" restrict";
731 Proto +=
" noexcept";
734 llvm::raw_string_ostream EOut(Proto);
736 Indentation,
"\n", &Context);
743 if (!Policy.TerseOutput)
744 PrintConstructorInitializers(CDecl, Proto);
745 }
else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
749 Out << Proto <<
" -> ";
752 AFT->getReturnType().print(Out, Policy, Proto);
759 TrailingRequiresClause->printPretty(Out,
nullptr, SubPolicy, Indentation,
763 Ty.
print(Out, Policy, Proto);
766 prettyPrintAttributes(D);
775 if (!Policy.TerseOutput) {
780 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
781 Indentation += Policy.Indentation;
782 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
787 Indentation -= Policy.Indentation;
794 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
800 void DeclPrinter::VisitFriendDecl(
FriendDecl *D) {
803 for (
unsigned i = 0; i < NumTPLists; ++i)
806 Out <<
" " << TSI->getType().getAsString(Policy);
811 VisitFunctionDecl(FD);
816 VisitFunctionTemplateDecl(FTD);
821 VisitRedeclarableTemplateDecl(CTD);
825 void DeclPrinter::VisitFieldDecl(
FieldDecl *D) {
827 if (!Policy.SuppressSpecifiers && D->
isMutable())
830 Out <<
"__module_private__ ";
833 stream(Policy, D->
getName(), Indentation);
842 if (!Policy.SuppressInitializers && Init) {
847 Init->printPretty(Out,
nullptr, Policy, Indentation,
"\n", &Context);
849 prettyPrintAttributes(D);
852 void DeclPrinter::VisitLabelDecl(
LabelDecl *D) {
856 void DeclPrinter::VisitVarDecl(
VarDecl *D) {
857 prettyPrintPragmas(D);
863 if (!Policy.SuppressSpecifiers) {
875 Out <<
"_Thread_local ";
878 Out <<
"thread_local ";
883 Out <<
"__module_private__ ";
891 printDeclType(T, (isa<ParmVarDecl>(D) && Policy.CleanUglifiedParameters &&
896 if (!Policy.SuppressInitializers && Init) {
897 bool ImplicitInit =
false;
899 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
901 !Construct->isListInitialization()) {
902 ImplicitInit = Construct->getNumArgs() == 0 ||
913 SubPolicy.SuppressSpecifiers =
false;
914 SubPolicy.IncludeTagDefinition =
false;
915 Init->printPretty(Out,
nullptr, SubPolicy, Indentation,
"\n", &Context);
920 prettyPrintAttributes(D);
923 void DeclPrinter::VisitParmVarDecl(
ParmVarDecl *D) {
934 void DeclPrinter::VisitImportDecl(
ImportDecl *D) {
940 Out <<
"static_assert(";
945 SL->printPretty(Out,
nullptr, Policy, Indentation,
"\n", &Context);
967 Out <<
"using namespace ";
974 Out <<
"namespace " << *D <<
" = ";
975 if (D->getQualifier())
977 Out << *D->getAliasedNamespace();
980 void DeclPrinter::VisitEmptyDecl(
EmptyDecl *D) {
981 prettyPrintAttributes(D);
987 Out <<
"__module_private__ ";
990 prettyPrintAttributes(D);
995 if (
auto S = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
997 if (!Policy.PrintCanonicalTypes)
998 if (
const auto* TSI = S->getTypeAsWritten())
999 if (
const auto *TST =
1000 dyn_cast<TemplateSpecializationType>(TSI->getType()))
1001 Args = TST->template_arguments();
1002 printTemplateArguments(
1003 Args, S->getSpecializedTemplate()->getTemplateParameters());
1007 if (D->isCompleteDefinition()) {
1009 if (D->getNumBases()) {
1012 BaseEnd = D->bases_end();
Base != BaseEnd; ++
Base) {
1013 if (
Base != D->bases_begin())
1016 if (
Base->isVirtual())
1024 Out <<
Base->getType().getAsString(Policy);
1026 if (
Base->isPackExpansion())
1033 if (Policy.TerseOutput) {
1037 VisitDeclContext(D);
1049 "unknown language in linkage specification");
1053 Out <<
"extern \"" << l <<
"\" ";
1056 VisitDeclContext(D);
1063 bool OmitTemplateKW) {
1066 if (!OmitTemplateKW)
1070 bool NeedComma =
false;
1071 for (
const Decl *Param : *Params) {
1072 if (Param->isImplicit())
1080 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
1081 VisitTemplateTypeParmDecl(TTP);
1082 }
else if (
auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1083 VisitNonTypeTemplateParmDecl(NTTP);
1084 }
else if (
auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1085 VisitTemplateDecl(TTPD);
1091 if (!OmitTemplateKW)
1095 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args,
1096 const TemplateParameterList *Params) {
1098 for (size_t I = 0, E = Args.size(); I < E; ++I) {
1102 Args[I].print(Policy, Out, /*IncludeType*/ true);
1104 Args[I].print(Policy, Out,
1105 TemplateParameterList::shouldIncludeTypeForArgument(
1106 Policy, Params, I));
1111 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
1112 const TemplateParameterList *Params) {
1114 for (size_t I = 0, E = Args.size(); I < E; ++I) {
1118 Args[I].getArgument().print(Policy, Out, /*IncludeType*/ true);
1120 Args[I].getArgument().print(
1122 TemplateParameterList::shouldIncludeTypeForArgument(Policy, Params,
1128 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
1129 printTemplateParameters(D->getTemplateParameters());
1131 if (const TemplateTemplateParmDecl *TTP =
1132 dyn_cast<TemplateTemplateParmDecl>(D)) {
1135 if (TTP->isParameterPack())
1137 else if (TTP->getDeclName())
1140 if (TTP->getDeclName()) {
1141 if (Policy.CleanUglifiedParameters && TTP->getIdentifier())
1142 Out << TTP->getIdentifier()->deuglifiedName();
1144 Out << TTP->getDeclName();
1146 } else if (auto *TD = D->getTemplatedDecl())
1148 else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) {
1149 Out << "concept " << Concept->getName() << " = " ;
1150 Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, Indentation,
1155 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1156 prettyPrintPragmas(D->getTemplatedDecl());
1157 // Print any leading template parameter lists.
1158 if (const FunctionDecl *FD = D->getTemplatedDecl()) {
1159 for (unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists();
1160 I < NumTemplateParams; ++I)
1161 printTemplateParameters(FD->getTemplateParameterList(I));
1163 VisitRedeclarableTemplateDecl(D);
1164 // Declare target attribute is special one, natural spelling for the pragma
1165 // assumes "ending" construct so print it here.
1166 if (D->getTemplatedDecl()->hasAttr<OMPDeclareTargetDeclAttr>())
1167 Out << "#pragma omp end declare target\n";
1169 // Never print "instantiations" for deduction guides (they don't really
1171 if (PrintInstantiation &&
1172 !isa<CXXDeductionGuideDecl>(D->getTemplatedDecl())) {
1175 if (PrevDecl->
isDefined(Def) && Def != PrevDecl)
1177 for (
auto *I : D->specializations())
1182 prettyPrintPragmas(I);
1189 VisitRedeclarableTemplateDecl(D);
1191 if (PrintInstantiation) {
1203 void DeclPrinter::VisitClassTemplateSpecializationDecl(
1205 Out <<
"template<> ";
1206 VisitCXXRecordDecl(D);
1209 void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1212 VisitCXXRecordDecl(D);
1219 void DeclPrinter::PrintObjCMethodType(
ASTContext &Ctx,
1223 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1225 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1227 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1229 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1231 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1233 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1235 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
1246 unsigned First =
true;
1247 for (
auto *Param : *Params) {
1254 switch (Param->getVariance()) {
1259 Out <<
"__covariant ";
1263 Out <<
"__contravariant ";
1267 Out << Param->getDeclName();
1269 if (Param->hasExplicitBound()) {
1270 Out <<
" : " << Param->getUnderlyingType().getAsString(Policy);
1287 std::string::size_type pos, lastPos = 0;
1290 pos =
name.find_first_of(
':', lastPos);
1293 Out <<
name.substr(lastPos, pos - lastPos) <<
':';
1295 PI->getObjCDeclQualifier(),
1307 prettyPrintAttributes(OMD);
1309 if (OMD->
getBody() && !Policy.TerseOutput) {
1314 else if (Policy.PolishForDeclaration)
1322 bool eolnOut =
false;
1324 Out <<
"@implementation " << I <<
" : " << *SID;
1326 Out <<
"@implementation " << I;
1331 Indentation += Policy.Indentation;
1332 for (
const auto *I : OID->
ivars()) {
1333 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1336 Indentation -= Policy.Indentation;
1343 VisitDeclContext(OID,
false);
1354 Out <<
"@class " << I;
1357 PrintObjCTypeParams(TypeParams);
1363 bool eolnOut =
false;
1364 Out <<
"@interface " << I;
1367 PrintObjCTypeParams(TypeParams);
1375 if (!Protocols.
empty()) {
1377 E = Protocols.
end(); I != E; ++I)
1378 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1385 Indentation += Policy.Indentation;
1386 for (
const auto *I : OID->
ivars()) {
1387 Indent() << I->getASTContext()
1388 .getUnqualifiedObjCPointerType(I->getType())
1389 .getAsString(Policy) <<
' ' << *I <<
";\n";
1391 Indentation -= Policy.Indentation;
1399 VisitDeclContext(OID,
false);
1408 Out <<
"@protocol " << *PID <<
";\n";
1413 if (!Protocols.
empty()) {
1414 Out <<
"@protocol " << *PID;
1416 E = Protocols.
end(); I != E; ++I)
1417 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1420 Out <<
"@protocol " << *PID <<
'\n';
1421 VisitDeclContext(PID,
false);
1426 Out <<
"@implementation ";
1430 Out <<
"<<error-type>>";
1431 Out <<
'(' << *PID <<
")\n";
1433 VisitDeclContext(PID,
false);
1439 Out <<
"@interface ";
1443 Out <<
"<<error-type>>";
1445 PrintObjCTypeParams(TypeParams);
1447 Out <<
"(" << *PID <<
")\n";
1448 if (PID->ivar_size() > 0) {
1450 Indentation += Policy.Indentation;
1451 for (
const auto *I : PID->ivars())
1452 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1454 Indentation -= Policy.Indentation;
1458 VisitDeclContext(PID,
false);
1465 Out <<
"@compatibility_alias " << *AID
1480 Out <<
"@required\n";
1482 Out <<
"@optional\n";
1491 Out << (first ?
"" :
", ") <<
"class";
1496 Out << (first ?
"" :
", ") <<
"direct";
1502 Out << (first ?
"" :
", ") <<
"nonatomic";
1506 Out << (first ?
"" :
", ") <<
"atomic";
1511 Out << (first ?
"" :
", ") <<
"assign";
1515 Out << (first ?
"" :
", ") <<
"retain";
1520 Out << (first ?
"" :
", ") <<
"strong";
1524 Out << (first ?
"" :
", ") <<
"copy";
1528 Out << (first ?
"" :
", ") <<
"weak";
1533 Out << (first ?
"" :
", ") <<
"unsafe_unretained";
1539 Out << (first ?
"" :
", ") <<
"readwrite";
1543 Out << (first ?
"" :
", ") <<
"readonly";
1548 Out << (first ?
"" :
", ") <<
"getter = ";
1553 Out << (first ?
"" :
", ") <<
"setter = ";
1564 Out << (first ?
"" :
", ") <<
"null_resettable";
1566 Out << (first ?
"" :
", ")
1578 Out <<
' ' << TypeStr;
1579 if (!StringRef(TypeStr).endswith(
"*"))
1582 if (Policy.PolishForDeclaration)
1588 Out <<
"@synthesize ";
1596 void DeclPrinter::VisitUsingDecl(
UsingDecl *D) {
1605 for (
const auto *Shadow : D->
shadows()) {
1606 if (
const auto *ConstructorShadow =
1607 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1608 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1609 Out << *ConstructorShadow->getNominatedBaseClass();
1622 Out <<
"using typename ";
1639 Out <<
"#pragma omp threadprivate";
1645 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1653 Out <<
"#pragma omp allocate";
1659 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1674 Out <<
"#pragma omp requires ";
1684 Out <<
"#pragma omp declare reduction (";
1686 const char *OpName =
1688 assert(OpName &&
"not an overloaded operator");
1700 Out <<
" initializer(";
1706 Out <<
"omp_priv = ";
1711 Init->printPretty(Out,
nullptr, Policy, 0,
"\n", &Context);
1721 Out <<
"#pragma omp declare mapper (";
1744 TC->print(Out, Policy);
1768 void DeclPrinter::VisitNonTypeTemplateParmDecl(
1773 Policy.CleanUglifiedParameters ? II->deuglifiedName() : II->getName();
Store information needed for an explicit specifier.
StringRef getKindName() const
Represents an ObjC class declaration.
bool clauselist_empty() const
This represents '#pragma omp allocate ...' directive.
Represents an empty-declaration.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
ObjCIvarDecl * getPropertyIvarDecl() const
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
ObjCCompatibleAliasDecl - Represents alias of a class.
ASTContext & getASTContext() const LLVM_READONLY
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
void print(raw_ostream &Out, const ASTContext &Context, bool OmitTemplateKW=false) const
decl_iterator decls_end() const
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Represents a C++ constructor within a class.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
QualType getType() const
Return the type wrapped by this type source info.
NamedDecl * getNominatedNamespaceAsWritten()
Represents a linkage specification.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
QualType getDefaultArgument() const
Retrieve the default argument, if any.
Represents a C++ conversion function within a class.
Represents a C++ namespace alias.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
@ Invariant
The parameter is invariant: must match exactly.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Represents C++ using-directive.
clauselist_iterator clauselist_end()
This represents '#pragma omp threadprivate ...' directive.
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.
TemplateDecl * getDeducedTemplate() const
Get the template for which this guide performs deduction.
A (possibly-)qualified type.
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
const ParmVarDecl * getParamDecl(unsigned i) const
static QualType getDeclType(Decl *D)
TypeSourceInfo * getTypeSourceInfo() const
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Represents a member of a struct/union/class.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Represents a parameter to a function.
ObjCInterfaceDecl * getClassInterface()
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
@ Covariant
The parameter is covariant, e.g., X<T> is a subtype of X when the type parameter is covariant and T i...
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
void dumpDeclContext() const
clauselist_range clauselists()
param_const_iterator param_end() const
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
@ TSCS_thread_local
C++11 thread_local.
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
Describes how types, statements, expressions, and declarations should be printed.
PropertyControl getPropertyImplementation() const
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
FunctionType - C99 6.7.5.3 - Function Declarators.
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
bool clauselist_empty() const
const ObjCInterfaceDecl * getClassInterface() const
bool isVariadic() const
Whether this function prototype is variadic.
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
StringRef deuglifiedName() const
If the identifier is an "uglified" reserved name, return a cleaned form.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
DeclarationName getVarName()
Get the name of the variable declared in the mapper.
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
Represents a dependent using declaration which was marked with typename.
bool varlist_empty() const
Declaration of a template function.
llvm::StringRef getAsString(SyncScope S)
The top declaration context.
unsigned ivar_size() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ Contravariant
The parameter is contravariant, e.g., X<T> is a subtype of X when the type parameter is covariant and...
Represents a pack expansion of types.
This represents '#pragma omp declare reduction ...' directive.
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
TemplateParameterList * getTemplateParameterList(unsigned index) const
Describes a module import declaration, which makes the contents of the named module visible in the cu...
AccessSpecifier getAccess() const
MutableArrayRef< Expr * >::iterator varlist_iterator
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
This is a basic class for representing single OpenMP clause.
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
unsigned SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration.
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Represents a GCC generic vector type.
Expr * getBitWidth() const
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
std::string getAsString() const
Retrieve the human-readable string for this name.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
const T * getAs() const
Member-template getAs<specific type>'.
static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, PrintingPolicy &Policy, unsigned Indentation, const ASTContext &Context)
bool isInvalidDecl() const
const ObjCProtocolList & getReferencedProtocols() const
Selector getSetterName() const
Selector getSelector() const
StringLiteral * getMessage()
Represents the declaration of a label.
spec_range specializations() const
decl_iterator - Iterates through the declarations stored within this context.
bool isTranslationUnit() const
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
shadow_range shadows() const
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
@ ICIS_ListInit
Direct list-initialization.
Represents a variable declaration or definition.
QualType getReturnType() const
Represents the declaration of a struct/union/class/enum.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
This represents '#pragma omp declare mapper ...' directive.
Stores a list of template parameters for a TemplateDecl and its derived classes.
StringLiteral - This represents a string literal expression, e.g.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
@ RQ_None
No ref-qualifier was provided.
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
MutableArrayRef< Expr * >::iterator varlist_iterator
An instance of this object exists for each enum constant that is defined.
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
Represents a dependent using declaration which was not marked with typename.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Declaration of a template type parameter.
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
const ObjCInterfaceDecl * getSuperClass() const
bool isMutable() const
Determines whether this field is mutable (C++ only).
Represents a C++ using-declaration.
ObjCCategoryDecl - Represents a category declaration.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
unsigned IncludeTagDefinition
When true, include the body of a tag definition.
bool varlist_empty() const
clauselist_iterator clauselist_begin()
const Expr * getExpr() const
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
static QualType GetBaseType(QualType T)
std::string getNameAsString() const
Get the name of the class associated with this interface.
ObjCDeclQualifier getObjCDeclQualifier() const
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Represents a pointer to an Objective C object.
Represents a C++ using-enum-declaration.
Represents a C++ struct/union/class.
DeclarationNameInfo getNameInfo() const
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
bool isConstexprSpecified() const
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
void printName(raw_ostream &OS, PrintingPolicy Policy) const
printName - Print the human-readable name to a stream.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
bool isBitField() const
Determines whether this field is a bitfield.
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Expr * getDefaultArgument() const
Retrieve the default argument, if any.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
Represents a C++11 static_assert declaration.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
bool isSpecified() const
Determine if the declaration had an explicit specifier of any kind.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Declaration of a class template.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Represents a prototype with parameter type info, e.g.
Pseudo declaration for capturing expressions.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
const ObjCInterfaceDecl * getClassInterface() const
const clang::PrintingPolicy & getPrintingPolicy() const
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
The base class of all kinds of template declarations (e.g., class, function, etc.).
bool isIdentifier() const
Predicate functions for querying what type of name this is.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Decl - This represents one declaration (or definition), e.g.
bool isPure() const
Whether this virtual function is pure, i.e.
Represents one property declaration in an Objective-C interface.
bool isInstanceMethod() const
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
@ EST_MSAny
Microsoft throw(...) extension.
ObjCInterfaceDecl * getSuperClass() const
std::string getAsString() const
Derive the full selector name (e.g.
A template argument list.
std::string getQualifiedNameAsString() const
Kind getPropertyImplementation() const
const Expr * getInit() const
One of these records is kept for each identifier that is lexed.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
unsigned getFriendTypeNumTemplateParameterLists() const
ObjCPropertyDecl * getPropertyDecl() const
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
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...
bool isParameterPack() const
Returns whether this is a parameter pack.
ThreadStorageClassSpecifier getTSCSpec() const
varlist_iterator varlist_begin()
Selector getGetterName() const
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
bool clauselist_empty() const
unsigned ivar_size() const
ObjCMethodDecl - Represents an instance or class method declaration.
PointerType - C99 6.7.5.1 - Pointer Declarators.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
Represents a C++ deduction guide declaration.
param_const_iterator param_begin() const
InitKind getInitializerKind() const
Get initializer kind.
@ CInit
C-style initialization with assignment.
NameKind getNameKind() const
Determine what kind of name this is.
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
varlist_iterator varlist_end()
@ TSCS__Thread_local
C11 _Thread_local.
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
const StringLiteral * getAsmString() const
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool hasTypename() const
Return true if the using declaration has 'typename'.
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
A simple visitor class that helps create declaration visitors.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Represents an Objective-C protocol declaration.
Represents a base class of a C++ class.
varlist_iterator varlist_begin()
A container of type source information.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
This represents '#pragma omp requires...' directive.
virtual void printName(raw_ostream &os) const
Pretty-print the unqualified name of this declaration.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
@ TSCS___thread
GNU __thread.
Base class for declarations which introduce a typedef-name.
unsigned getNumTemplateParameterLists() const
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
ArrayRef< ParmVarDecl * > parameters() const
Base for LValueReferenceType and RValueReferenceType.
llvm::StringRef getAccessSpelling(AccessSpecifier AS)
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
This represents one expression.
void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
clauselist_range clauselists()
bool isDeletedAsWritten() const
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...
const ObjCProtocolList & getReferencedProtocols() const
Represents a class template specialization, which refers to a class template with a given set of temp...
ObjCPropertyAttribute::Kind getPropertyAttributes() const
varlist_iterator varlist_end()
TemplateParameterList * getFriendTypeTemplateParameterList(unsigned N) const
Represent a C++ namespace.
Represents a function declaration or definition.
Represents a struct/union/class.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isInline() const
Returns true if this is an inline namespace declaration.
Represents a call to a C++ constructor.
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
const LangOptions & getLangOpts() const
TypeSourceInfo * getTypeSourceInfo() const
Sugar for parentheses used when specifying types.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
EnumDecl * getEnumDecl() const
@ CallInit
Call-style initialization (C++98)
unsigned getNumExceptions() const
Return the number of types in the exception specification.
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
StorageClass
Storage classes.
decl_iterator decls_begin() const
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.