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(
110 bool OmitTemplateKW =
false);
113 void prettyPrintAttributes(
Decl *D);
114 void prettyPrintPragmas(
Decl *D);
115 void printDeclType(
QualType T, StringRef DeclName,
bool Pack =
false);
120 bool PrintInstantiation)
const {
121 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
125 unsigned Indentation,
bool PrintInstantiation)
const {
126 DeclPrinter Printer(Out, Policy, getASTContext(), Indentation,
128 Printer.Visit(const_cast<Decl*>(
this));
132 bool OmitTemplateKW)
const {
138 bool OmitTemplateKW)
const {
139 DeclPrinter Printer(Out, Policy, Context);
140 Printer.printTemplateParameters(
this, OmitTemplateKW);
151 else if (
const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
152 BaseType = ATy->getElementType();
154 BaseType = FTy->getReturnType();
156 BaseType = VTy->getElementType();
160 BaseType = ATy->getDeducedType();
162 BaseType = PTy->desugar();
172 return TDD->getUnderlyingType();
173 if (
ValueDecl* VD = dyn_cast<ValueDecl>(D))
174 return VD->getType();
180 unsigned Indentation) {
182 (*Begin)->print(Out, Policy, Indentation);
201 if (!isFirst) Out <<
", ";
206 (*Begin)->print(Out, SubPolicy, Indentation);
216 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
218 Printer.VisitDeclContext(const_cast<DeclContext *>(
this),
false);
221 raw_ostream& DeclPrinter::Indent(
unsigned Indentation) {
222 for (
unsigned i = 0; i != Indentation; ++i)
227 void DeclPrinter::prettyPrintAttributes(
Decl *D) {
228 if (Policy.PolishForDeclaration)
233 for (
auto *A : Attrs) {
234 if (A->isInherited() || A->isImplicit())
236 switch (A->getKind()) {
238 #define PRAGMA_SPELLING_ATTR(X) case attr::X: 239 #include "clang/Basic/AttrList.inc" 242 A->printPretty(Out, Policy);
249 void DeclPrinter::prettyPrintPragmas(
Decl *D) {
250 if (Policy.PolishForDeclaration)
255 for (
auto *A : Attrs) {
256 switch (A->getKind()) {
258 #define PRAGMA_SPELLING_ATTR(X) case attr::X: 259 #include "clang/Basic/AttrList.inc" 260 A->printPretty(Out, Policy);
270 void DeclPrinter::printDeclType(
QualType T, StringRef DeclName,
bool Pack) {
276 T = PET->getPattern();
278 T.
print(Out, Policy, (Pack ?
"..." :
"") + DeclName, Indentation);
291 case AS_none: llvm_unreachable(
"No access specifier!");
299 std::string &Proto) {
300 bool HasInitializerList =
false;
301 for (
const auto *BMInitializer : CDecl->
inits()) {
302 if (BMInitializer->isInClassMemberInitializer())
305 if (!HasInitializerList) {
309 HasInitializerList =
true;
313 if (BMInitializer->isAnyMemberInitializer()) {
314 FieldDecl *FD = BMInitializer->getAnyMember();
321 if (!BMInitializer->getInit()) {
324 Expr *Init = BMInitializer->getInit();
326 Init = Tmp->getSubExpr();
330 Expr *SimpleInit =
nullptr;
331 Expr **Args =
nullptr;
332 unsigned NumArgs = 0;
333 if (
ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
334 Args = ParenList->getExprs();
335 NumArgs = ParenList->getNumExprs();
337 dyn_cast<CXXConstructExpr>(Init)) {
338 Args = Construct->getArgs();
339 NumArgs = Construct->getNumArgs();
344 SimpleInit->
printPretty(Out,
nullptr, Policy, Indentation);
346 for (
unsigned I = 0; I != NumArgs; ++I) {
347 assert(Args[I] !=
nullptr &&
"Expected non-null Expr");
348 if (isa<CXXDefaultArgExpr>(Args[I]))
353 Args[I]->
printPretty(Out,
nullptr, Policy, Indentation);
358 if (BMInitializer->isPackExpansion())
368 if (Policy.TerseOutput)
372 Indentation += Policy.Indentation;
380 if (isa<ObjCIvarDecl>(*D))
389 if (
auto FD = dyn_cast<FunctionDecl>(*D))
391 !isa<ClassTemplateSpecializationDecl>(DC))
407 if (!Decls.empty() && !CurDeclType.
isNull()) {
409 if (!BaseType.
isNull() && isa<ElaboratedType>(BaseType) &&
410 cast<ElaboratedType>(BaseType)->getOwnedTagDecl() == Decls[0]) {
418 ProcessDeclGroup(Decls);
422 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->isFreeStanding()) {
427 if (isa<AccessSpecDecl>(*D)) {
428 Indentation -= Policy.Indentation;
432 Indentation += Policy.Indentation;
440 const char *Terminator =
nullptr;
441 if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D) ||
442 isa<OMPDeclareMapperDecl>(*D) || isa<OMPRequiresDecl>(*D) ||
443 isa<OMPAllocateDecl>(*D))
444 Terminator =
nullptr;
445 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
446 Terminator =
nullptr;
447 else if (
auto FD = dyn_cast<FunctionDecl>(*D)) {
448 if (FD->isThisDeclarationADefinition())
449 Terminator =
nullptr;
452 }
else if (
auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
453 if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
454 Terminator =
nullptr;
457 }
else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
458 isa<ObjCImplementationDecl>(*D) ||
459 isa<ObjCInterfaceDecl>(*D) ||
460 isa<ObjCProtocolDecl>(*D) ||
461 isa<ObjCCategoryImplDecl>(*D) ||
462 isa<ObjCCategoryDecl>(*D))
463 Terminator =
nullptr;
464 else if (isa<EnumConstantDecl>(*D)) {
474 if (!Policy.TerseOutput &&
475 ((isa<FunctionDecl>(*D) &&
476 cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
477 (isa<FunctionTemplateDecl>(*D) &&
478 cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
485 if (D->
hasAttr<OMPDeclareTargetDeclAttr>())
486 Out <<
"#pragma omp end declare target\n";
490 ProcessDeclGroup(Decls);
493 Indentation -= Policy.Indentation;
497 VisitDeclContext(D,
false);
500 void DeclPrinter::VisitTypedefDecl(
TypedefDecl *D) {
501 if (!Policy.SuppressSpecifiers) {
505 Out <<
"__module_private__ ";
509 prettyPrintAttributes(D);
513 Out <<
"using " << *D;
514 prettyPrintAttributes(D);
515 Out <<
" = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
518 void DeclPrinter::VisitEnumDecl(
EnumDecl *D) {
520 Out <<
"__module_private__ ";
529 prettyPrintAttributes(D);
533 if (D->isFixed() && D->getASTContext().getLangOpts().CPlusPlus11)
536 if (D->isCompleteDefinition()) {
543 void DeclPrinter::VisitRecordDecl(
RecordDecl *D) {
545 Out <<
"__module_private__ ";
548 prettyPrintAttributes(D);
562 prettyPrintAttributes(D);
563 if (
Expr *Init = D->getInitExpr()) {
565 Init->printPretty(Out,
nullptr, Policy, Indentation,
"\n", &Context);
571 unsigned Indentation) {
572 std::string Proto =
"explicit";
573 llvm::raw_string_ostream EOut(Proto);
587 prettyPrintPragmas(D);
590 Out <<
"template<> ";
593 I < NumTemplateParams; ++I)
600 if (!Policy.SuppressSpecifiers) {
607 llvm_unreachable(
"invalid for functions");
625 if (Policy.FullyQualifiedName) {
628 llvm::raw_string_ostream OS(Proto);
629 if (!Policy.SuppressScope) {
631 NS->print(OS, Policy);
638 Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString();
640 llvm::raw_string_ostream POut(Proto);
641 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
643 if (TArgAsWritten && !Policy.PrintCanonicalTypes)
644 TArgPrinter.printTemplateArguments(TArgAsWritten->arguments());
647 TArgPrinter.printTemplateArguments(TArgs->asArray());
651 while (
const ParenType *PT = dyn_cast<ParenType>(Ty)) {
652 Proto =
'(' + Proto +
')';
653 Ty = PT->getInnerType();
659 FT = dyn_cast<FunctionProtoType>(AFT);
663 llvm::raw_string_ostream POut(Proto);
664 DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
665 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
675 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
688 Proto +=
" volatile";
690 Proto +=
" restrict";
717 Proto +=
" noexcept";
720 llvm::raw_string_ostream EOut(Proto);
730 if (!Policy.TerseOutput)
731 PrintConstructorInitializers(CDecl, Proto);
732 }
else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
736 Out << Proto <<
" -> ";
739 AFT->getReturnType().print(Out, Policy, Proto);
746 TrailingRequiresClause->printPretty(Out,
nullptr, SubPolicy, Indentation);
749 Ty.
print(Out, Policy, Proto);
752 prettyPrintAttributes(D);
761 if (!Policy.TerseOutput) {
766 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
767 Indentation += Policy.Indentation;
768 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
773 Indentation -= Policy.Indentation;
780 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
786 void DeclPrinter::VisitFriendDecl(
FriendDecl *D) {
789 for (
unsigned i = 0; i < NumTPLists; ++i)
792 Out <<
" " << TSI->getType().getAsString(Policy);
797 VisitFunctionDecl(FD);
802 VisitFunctionTemplateDecl(FTD);
807 VisitRedeclarableTemplateDecl(CTD);
811 void DeclPrinter::VisitFieldDecl(
FieldDecl *D) {
813 if (!Policy.SuppressSpecifiers && D->
isMutable())
816 Out <<
"__module_private__ ";
819 stream(Policy, D->
getName(), Indentation);
827 if (!Policy.SuppressInitializers && Init) {
832 Init->
printPretty(Out,
nullptr, Policy, Indentation);
834 prettyPrintAttributes(D);
837 void DeclPrinter::VisitLabelDecl(
LabelDecl *D) {
841 void DeclPrinter::VisitVarDecl(
VarDecl *D) {
842 prettyPrintPragmas(D);
848 if (!Policy.SuppressSpecifiers) {
860 Out <<
"_Thread_local ";
863 Out <<
"thread_local ";
868 Out <<
"__module_private__ ";
876 printDeclType(T, D->
getName());
878 if (!Policy.SuppressInitializers && Init) {
879 bool ImplicitInit =
false;
881 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
883 !Construct->isListInitialization()) {
884 ImplicitInit = Construct->getNumArgs() == 0 ||
897 Init->printPretty(Out,
nullptr, SubPolicy, Indentation);
902 prettyPrintAttributes(D);
905 void DeclPrinter::VisitParmVarDecl(
ParmVarDecl *D) {
915 void DeclPrinter::VisitImportDecl(
ImportDecl *D) {
921 Out <<
"static_assert(";
925 SL->printPretty(Out,
nullptr, Policy, Indentation);
936 Out <<
"namespace " << *D <<
" {\n";
942 Out <<
"using namespace ";
949 Out <<
"namespace " << *D <<
" = ";
950 if (D->getQualifier())
952 Out << *D->getAliasedNamespace();
955 void DeclPrinter::VisitEmptyDecl(
EmptyDecl *D) {
956 prettyPrintAttributes(D);
962 Out <<
"__module_private__ ";
965 prettyPrintAttributes(D);
970 if (
auto S = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
972 if (!Policy.PrintCanonicalTypes)
973 if (
const auto* TSI = S->getTypeAsWritten())
974 if (
const auto *TST =
975 dyn_cast<TemplateSpecializationType>(TSI->getType()))
976 Args = TST->template_arguments();
977 printTemplateArguments(Args);
990 if (
Base->isVirtual())
998 Out <<
Base->getType().getAsString(Policy);
1000 if (
Base->isPackExpansion())
1007 if (Policy.TerseOutput) {
1011 VisitDeclContext(D);
1023 "unknown language in linkage specification");
1027 Out <<
"extern \"" << l <<
"\" ";
1030 VisitDeclContext(D);
1037 bool OmitTemplateKW) {
1040 if (!OmitTemplateKW)
1044 bool NeedComma =
false;
1045 for (
const Decl *Param : *Params) {
1046 if (Param->isImplicit())
1054 if (
auto TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
1057 TC->print(Out, Policy);
1058 else if (TTP->wasDeclaredWithTypename())
1063 if (TTP->isParameterPack())
1065 else if (!TTP->getName().empty())
1070 if (TTP->hasDefaultArgument()) {
1072 Out << TTP->getDefaultArgument().getAsString(Policy);
1074 }
else if (
auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1077 Name = II->getName();
1078 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
1080 if (NTTP->hasDefaultArgument()) {
1082 NTTP->getDefaultArgument()->printPretty(Out,
nullptr, Policy,
1085 }
else if (
auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1086 VisitTemplateDecl(TTPD);
1092 if (!OmitTemplateKW) 1096 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args) { 1098 for (size_t I = 0, E = Args.size(); I < E; ++I) { 1101 Args[I].print(Policy, Out); 1106 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args) { 1108 for (size_t I = 0, E = Args.size(); I < E; ++I) { 1111 Args[I].getArgument().print(Policy, Out); 1116 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { 1117 printTemplateParameters(D->getTemplateParameters()); 1119 if (const TemplateTemplateParmDecl *TTP = 1120 dyn_cast<TemplateTemplateParmDecl>(D)) { 1122 if (TTP->isParameterPack()) 1124 Out << D->getName(); 1125 } else if (auto *TD = D->getTemplatedDecl()) 1127 else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) { 1128 Out << "concept " << Concept->getName() << " = " ; 1129 Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, 1135 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { 1136 prettyPrintPragmas(D->getTemplatedDecl()); 1137 // Print any leading template parameter lists. 1138 if (const FunctionDecl *FD = D->getTemplatedDecl()) { 1139 for (unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists(); 1140 I < NumTemplateParams; ++I) 1141 printTemplateParameters(FD->getTemplateParameterList(I)); 1143 VisitRedeclarableTemplateDecl(D); 1144 // Declare target attribute is special one, natural spelling for the pragma 1145 // assumes "ending" construct so print it here. 1146 if (D->getTemplatedDecl()->hasAttr<OMPDeclareTargetDeclAttr>()) 1147 Out << "#pragma omp end declare target\n"; 1149 // Never print "instantiations" for deduction guides (they don't really
1151 if (PrintInstantiation &&
1152 !isa<CXXDeductionGuideDecl>(D->getTemplatedDecl())) {
1155 if (PrevDecl->
isDefined(Def) && Def != PrevDecl)
1157 for (
auto *I : D->specializations())
1162 prettyPrintPragmas(I);
1169 VisitRedeclarableTemplateDecl(D);
1171 if (PrintInstantiation) {
1182 void DeclPrinter::VisitClassTemplateSpecializationDecl(
1184 Out <<
"template<> ";
1185 VisitCXXRecordDecl(D);
1188 void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1191 VisitCXXRecordDecl(D);
1198 void DeclPrinter::PrintObjCMethodType(
ASTContext &Ctx,
1202 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1204 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1206 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1208 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1210 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1212 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1214 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
1225 unsigned First =
true;
1226 for (
auto *Param : *Params) {
1233 switch (Param->getVariance()) {
1238 Out <<
"__covariant ";
1242 Out <<
"__contravariant ";
1246 Out << Param->getDeclName().getAsString();
1248 if (Param->hasExplicitBound()) {
1249 Out <<
" : " << Param->getUnderlyingType().getAsString(Policy);
1266 std::string::size_type pos, lastPos = 0;
1269 pos = name.find_first_of(
':', lastPos);
1272 Out << name.substr(lastPos, pos - lastPos) <<
':';
1274 PI->getObjCDeclQualifier(),
1286 prettyPrintAttributes(OMD);
1288 if (OMD->
getBody() && !Policy.TerseOutput) {
1292 else if (Policy.PolishForDeclaration)
1300 bool eolnOut =
false;
1302 Out <<
"@implementation " << I <<
" : " << *SID;
1304 Out <<
"@implementation " << I;
1309 Indentation += Policy.Indentation;
1310 for (
const auto *I : OID->
ivars()) {
1311 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1314 Indentation -= Policy.Indentation;
1321 VisitDeclContext(OID,
false);
1332 Out <<
"@class " << I;
1335 PrintObjCTypeParams(TypeParams);
1341 bool eolnOut =
false;
1342 Out <<
"@interface " << I;
1345 PrintObjCTypeParams(TypeParams);
1353 if (!Protocols.
empty()) {
1355 E = Protocols.
end(); I != E; ++I)
1356 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1363 Indentation += Policy.Indentation;
1364 for (
const auto *I : OID->
ivars()) {
1365 Indent() << I->getASTContext()
1366 .getUnqualifiedObjCPointerType(I->getType())
1369 Indentation -= Policy.Indentation;
1377 VisitDeclContext(OID,
false);
1386 Out <<
"@protocol " << *PID <<
";\n";
1391 if (!Protocols.
empty()) {
1392 Out <<
"@protocol " << *PID;
1394 E = Protocols.
end(); I != E; ++I)
1395 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1398 Out <<
"@protocol " << *PID <<
'\n';
1399 VisitDeclContext(PID,
false);
1406 VisitDeclContext(PID,
false);
1414 PrintObjCTypeParams(TypeParams);
1416 Out <<
"(" << *PID <<
")\n";
1417 if (PID->ivar_size() > 0) {
1419 Indentation += Policy.Indentation;
1420 for (
const auto *I : PID->ivars())
1421 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1423 Indentation -= Policy.Indentation;
1427 VisitDeclContext(PID,
false);
1434 Out <<
"@compatibility_alias " << *AID
1449 Out <<
"@required\n";
1451 Out <<
"@optional\n";
1460 Out << (first ?
"" :
", ") <<
"class";
1465 Out << (first ?
"" :
", ") <<
"direct";
1471 Out << (first ?
"" :
", ") <<
"nonatomic";
1476 Out << (first ?
"" :
", ") <<
"atomic";
1481 Out << (first ?
"" :
", ") <<
"assign";
1485 Out << (first ?
"" :
", ") <<
"retain";
1490 Out << (first ?
"" :
", ") <<
"strong";
1494 Out << (first ?
"" :
", ") <<
"copy";
1498 Out << (first ?
"" :
", ") <<
"weak";
1503 Out << (first ?
"" :
", ") <<
"unsafe_unretained";
1509 Out << (first ?
"" :
", ") <<
"readwrite";
1514 Out << (first ?
"" :
", ") <<
"readonly";
1519 Out << (first ?
"" :
", ") <<
"getter = ";
1524 Out << (first ?
"" :
", ") <<
"setter = ";
1535 Out << (first ?
"" :
", ") <<
"null_resettable";
1537 Out << (first ?
"" :
", ")
1549 Out <<
' ' << TypeStr;
1550 if (!StringRef(TypeStr).endswith(
"*"))
1553 if (Policy.PolishForDeclaration)
1559 Out <<
"@synthesize ";
1567 void DeclPrinter::VisitUsingDecl(
UsingDecl *D) {
1576 for (
const auto *Shadow : D->
shadows()) {
1577 if (
const auto *ConstructorShadow =
1578 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1579 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1580 Out << *ConstructorShadow->getNominatedBaseClass();
1589 Out <<
"using typename ";
1606 Out <<
"#pragma omp threadprivate";
1612 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1620 Out <<
"#pragma omp allocate";
1626 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1640 Out <<
"#pragma omp requires ";
1650 Out <<
"#pragma omp declare reduction (";
1652 const char *OpName =
1654 assert(OpName &&
"not an overloaded operator");
1666 Out <<
" initializer(";
1672 Out <<
"omp_priv = ";
1677 Init->printPretty(Out,
nullptr, Policy, 0);
1687 Out <<
"#pragma omp declare mapper (";
clauselist_range clauselists()
Defines the clang::ASTContext interface.
Represents a function declaration or definition.
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
unsigned getFriendTypeNumTemplateParameterLists() const
varlist_iterator varlist_end()
ObjCInterfaceDecl * getClassInterface()
unsigned getNumBases() const
Retrieves the number of base classes of this class.
unsigned getNumExceptions() const
Return the number of types in the exception specification.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
ObjCIvarDecl * getPropertyIvarDecl() const
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Expr * getBitWidth() const
FunctionType - C99 6.7.5.3 - Function Declarators.
This represents '#pragma omp allocate ...' directive.
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
An instance of this object exists for each enum constant that is defined.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
spec_range specializations() const
Decl - This represents one declaration (or definition), e.g.
bool isVariadic() const
Whether this function prototype is variadic.
ThreadStorageClassSpecifier getTSCSpec() const
Defines the C++ template declaration subclasses.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
bool hasWrittenPrototype() const
Whether this function has a written prototype.
Represents an empty-declaration.
The parameter is covariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant and ...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Represent a C++ namespace.
Represents a call to a C++ constructor.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
bool clauselist_empty() const
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
A container of type source information.
Store information needed for an explicit specifier.
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
bool isDefined(const FunctionDecl *&Definition) const
Returns true if the function has a definition that does not need to be instantiated.
param_const_iterator param_end() const
Represents a C++ constructor within a class.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
Represents a variable declaration or definition.
const T * getAs() const
Member-template getAs<specific type>'.
ObjCMethodDecl - Represents an instance or class method declaration.
bool clauselist_empty() const
bool isInvalidDecl() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
Describes how types, statements, expressions, and declarations should be printed. ...
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
Represents an expression – generally a full-expression – that introduces cleanups to be run at the ...
Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
const ObjCInterfaceDecl * getSuperClass() const
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Represents a struct/union/class.
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
One of these records is kept for each identifier that is lexed.
Represents a class template specialization, which refers to a class template with a given set of temp...
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
StringLiteral * getMessage()
const ObjCProtocolList & getReferencedProtocols() const
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isInline() const
Returns true if this is an inline namespace declaration.
The parameter is contravariant, e.g., X<T> is a subtype of X<U> when the type parameter is covariant ...
NameKind getNameKind() const
Determine what kind of name this is.
Represents a member of a struct/union/class.
RetTy Visit(PTR(OMPClause) S)
InitKind getInitializerKind() const
Get initializer kind.
std::string getNameAsString() const
Get the name of the class associated with this interface.
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class. ...
Represents a C++ using-declaration.
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
bool isBitField() const
Determines whether this field is a bitfield.
An lvalue ref-qualifier was provided (&).
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
static QualType getDeclType(Decl *D)
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Microsoft throw(...) extension.
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
unsigned ivar_size() const
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool clauselist_empty() const
Whether values of this type can be null is (explicitly) unspecified.
PropertyAttributeKind getPropertyAttributes() const
NamedDecl * getNominatedNamespaceAsWritten()
const clang::PrintingPolicy & getPrintingPolicy() const
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
TemplateParameterList * getFriendTypeTemplateParameterList(unsigned N) const
base_class_iterator bases_begin()
Represents an Objective-C protocol declaration.
PropertyControl getPropertyImplementation() const
Represents an ObjC class declaration.
Represents a linkage specification.
QualType getReturnType() const
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false) const
Print this nested name specifier to the given output stream.
bool isConstexprSpecified() const
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
unsigned IncludeTagDefinition
When true, include the body of a tag definition.
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Represents a prototype with parameter type info, e.g.
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
DeclarationName getVarName()
Get the name of the variable declared in the mapper.
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
MutableArrayRef< Expr * >::iterator varlist_iterator
unsigned ivar_size() const
TypeSourceInfo * getTypeSourceInfo() const
This represents '#pragma omp requires...' directive.
varlist_iterator varlist_begin()
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
StringRef getKindName() const
Selector getSetterName() const
llvm::StringRef getAsString(SyncScope S)
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
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
ObjCInterfaceDecl * getSuperClass() const
StorageClass getStorageClass() const
Returns the storage class as written in the source.
const Expr * getExpr() const
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
static QualType GetBaseType(QualType T)
static Optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
StorageClass
Storage classes.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
bool isSpecifierType() const
Returns true if this type can be represented by some set of type specifiers.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isInstanceMethod() const
clauselist_range clauselists()
Represents a GCC generic vector type.
unsigned SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
Represents a C++ deduction guide declaration.
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...
Selector getSelector() const
Represents a C++ conversion function within a class.
This template specialization was implicitly instantiated from a template.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
virtual void printName(raw_ostream &os) const
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
std::string getAsString() const
Derive the full selector name (e.g.
Sugar for parentheses used when specifying types.
bool isPure() const
Whether this virtual function is pure, i.e.
This represents '#pragma omp declare reduction ...' directive.
decl_iterator decls_begin() const
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Pseudo declaration for capturing expressions.
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
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...
Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
Represents the declaration of a label.
Represents a dependent using declaration which was not marked with typename.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
varlist_iterator varlist_begin()
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
No ref-qualifier was provided.
C-style initialization with assignment.
const ParmVarDecl * getParamDecl(unsigned i) const
ObjCCategoryDecl - Represents a category declaration.
This is a basic class for representing single OpenMP clause.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
Defines the clang::Module class, which describes a module in the source code.
Direct list-initialization.
Represents one property declaration in an Objective-C interface.
A simple visitor class that helps create declaration visitors.
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
ObjCDeclQualifier getObjCDeclQualifier() const
static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, PrintingPolicy &Policy, unsigned Indentation)
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted per C++0x.
DeclarationNameInfo getNameInfo() const
Represents a C++11 static_assert declaration.
An rvalue ref-qualifier was provided (&&).
clauselist_iterator clauselist_begin()
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Represents a pack expansion of types.
bool varlist_empty() const
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
decl_iterator - Iterates through the declarations stored within this context.
Base class for declarations which introduce a typedef-name.
const ObjCInterfaceDecl * getClassInterface() const
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
The base class of all kinds of template declarations (e.g., class, function, etc.).
Kind getPropertyImplementation() const
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
const ObjCProtocolList & getReferencedProtocols() const
const Expr * getInit() const
AccessSpecifier getAccess() const
void print(raw_ostream &Out, const ASTContext &Context, bool OmitTemplateKW=false) const
Represents a dependent using declaration which was marked with typename.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
unsigned getNumTemplateParameterLists() const
void printName(raw_ostream &OS, PrintingPolicy Policy) const
printName - Print the human-readable name to a stream.
const ObjCInterfaceDecl * getClassInterface() const
MutableArrayRef< Expr * >::iterator varlist_iterator
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword...
TypeSourceInfo * getTypeSourceInfo() const
param_const_iterator param_begin() const
Base for LValueReferenceType and RValueReferenceType.
clauselist_iterator clauselist_end()
Represents a base class of a C++ class.
bool hasTypename() const
Return true if the using declaration has 'typename'.
A template argument list.
shadow_range shadows() const
varlist_iterator varlist_end()
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
Call-style initialization (C++98)
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\, const ASTContext *Context=nullptr) const
bool isMutable() const
Determines whether this field is mutable (C++ only).
Represents a C++ struct/union/class.
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
base_class_iterator bases_end()
bool varlist_empty() const
Declaration of a class template.
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
bool isSpecified() const
Determine if the declaration had an explicit specifier of any kind.
This represents '#pragma omp declare mapper ...' directive.
StringLiteral - This represents a string literal expression, e.g.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
std::string getQualifiedNameAsString() const
The top declaration context.
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
ObjCPropertyDecl * getPropertyDecl() const
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined...
This represents a decl that may have a name.
bool isTranslationUnit() const
Represents a C++ namespace alias.
Selector getGetterName() const
Represents C++ using-directive.
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
This represents '#pragma omp threadprivate ...' directive.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
The parameter is invariant: must match exactly.
void dumpDeclContext() const
Declaration of a template function.
bool isDeletedAsWritten() const
const StringLiteral * getAsmString() const
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
QualType getType() const
Return the type wrapped by this type source info.
ArrayRef< ParmVarDecl * > parameters() const
ObjCCompatibleAliasDecl - Represents alias of a class.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point...
decl_iterator decls_end() const