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 if (!Policy.SuppressScope) {
630 llvm::raw_string_ostream OS(Proto);
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);
642 TArgPrinter.printTemplateArguments(*TArgs);
646 while (
const ParenType *PT = dyn_cast<ParenType>(Ty)) {
647 Proto =
'(' + Proto +
')';
648 Ty = PT->getInnerType();
654 FT = dyn_cast<FunctionProtoType>(AFT);
658 llvm::raw_string_ostream POut(Proto);
659 DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
683 Proto +=
" volatile";
685 Proto +=
" restrict";
712 Proto +=
" noexcept";
715 llvm::raw_string_ostream EOut(Proto);
725 if (!Policy.TerseOutput)
726 PrintConstructorInitializers(CDecl, Proto);
727 }
else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
731 Out << Proto <<
" -> ";
734 AFT->getReturnType().print(Out, Policy, Proto);
739 Ty.
print(Out, Policy, Proto);
742 prettyPrintAttributes(D);
751 if (!Policy.TerseOutput) {
756 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
757 Indentation += Policy.Indentation;
763 Indentation -= Policy.Indentation;
770 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
776 void DeclPrinter::VisitFriendDecl(
FriendDecl *D) {
779 for (
unsigned i = 0;
i < NumTPLists; ++
i)
782 Out <<
" " << TSI->getType().getAsString(Policy);
787 VisitFunctionDecl(FD);
792 VisitFunctionTemplateDecl(FTD);
797 VisitRedeclarableTemplateDecl(CTD);
801 void DeclPrinter::VisitFieldDecl(
FieldDecl *D) {
803 if (!Policy.SuppressSpecifiers && D->
isMutable())
806 Out <<
"__module_private__ ";
809 stream(Policy, D->
getName(), Indentation);
817 if (!Policy.SuppressInitializers && Init) {
822 Init->
printPretty(Out,
nullptr, Policy, Indentation);
824 prettyPrintAttributes(D);
827 void DeclPrinter::VisitLabelDecl(
LabelDecl *D) {
831 void DeclPrinter::VisitVarDecl(
VarDecl *D) {
832 prettyPrintPragmas(D);
838 if (!Policy.SuppressSpecifiers) {
850 Out <<
"_Thread_local ";
853 Out <<
"thread_local ";
858 Out <<
"__module_private__ ";
866 printDeclType(T, D->
getName());
868 if (!Policy.SuppressInitializers && Init) {
869 bool ImplicitInit =
false;
871 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
873 !Construct->isListInitialization()) {
874 ImplicitInit = Construct->getNumArgs() == 0 ||
887 Init->printPretty(Out,
nullptr, SubPolicy, Indentation);
892 prettyPrintAttributes(D);
895 void DeclPrinter::VisitParmVarDecl(
ParmVarDecl *D) {
905 void DeclPrinter::VisitImportDecl(
ImportDecl *D) {
911 Out <<
"static_assert(";
915 SL->printPretty(Out,
nullptr, Policy, Indentation);
926 Out <<
"namespace " << *D <<
" {\n";
932 Out <<
"using namespace ";
939 Out <<
"namespace " << *D <<
" = ";
940 if (D->getQualifier())
942 Out << *D->getAliasedNamespace();
945 void DeclPrinter::VisitEmptyDecl(
EmptyDecl *D) {
946 prettyPrintAttributes(D);
952 Out <<
"__module_private__ ";
955 prettyPrintAttributes(D);
960 if (
auto S = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
961 printTemplateArguments(S->getTemplateArgs(), S->getTemplateParameters());
962 else if (
auto S = dyn_cast<ClassTemplateSpecializationDecl>(D))
963 printTemplateArguments(S->getTemplateArgs());
975 if (
Base->isVirtual())
983 Out <<
Base->getType().getAsString(Policy);
985 if (
Base->isPackExpansion())
992 if (Policy.TerseOutput) {
1008 "unknown language in linkage specification");
1012 Out <<
"extern \"" << l <<
"\" ";
1015 VisitDeclContext(D);
1022 bool OmitTemplateKW) {
1025 if (!OmitTemplateKW)
1029 bool NeedComma =
false;
1030 for (
const Decl *Param : *Params) {
1031 if (Param->isImplicit())
1039 if (
auto TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
1041 if (TTP->wasDeclaredWithTypename())
1046 if (TTP->isParameterPack())
1048 else if (!TTP->getName().empty())
1053 if (TTP->hasDefaultArgument()) {
1055 Out << TTP->getDefaultArgument().getAsString(Policy);
1057 }
else if (
auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1060 Name = II->getName();
1061 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
1063 if (NTTP->hasDefaultArgument()) {
1065 NTTP->getDefaultArgument()->printPretty(Out,
nullptr, Policy,
1068 }
else if (
auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1069 VisitTemplateDecl(TTPD);
1075 if (!OmitTemplateKW) 1079 void DeclPrinter::printTemplateArguments(const TemplateArgumentList &Args, 1080 const TemplateParameterList *Params) { 1082 for (size_t I = 0, E = Args.size(); I < E; ++I) { 1083 const TemplateArgument &A = Args[I]; 1087 if (A.getKind() == TemplateArgument::Type) 1088 if (auto T = A.getAsType()->getAs<TemplateTypeParmType>()) { 1089 auto P = cast<TemplateTypeParmDecl>(Params->getParam(T->getIndex())); 1093 if (A.getKind() == TemplateArgument::Template) { 1094 if (auto T = A.getAsTemplate().getAsTemplateDecl()) 1095 if (auto TD = dyn_cast<TemplateTemplateParmDecl>(T)) { 1096 auto P = cast<TemplateTemplateParmDecl>( 1097 Params->getParam(TD->getIndex())); 1102 if (A.getKind() == TemplateArgument::Expression) { 1103 if (auto E = dyn_cast<DeclRefExpr>(A.getAsExpr())) 1104 if (auto N = dyn_cast<NonTypeTemplateParmDecl>(E->getDecl())) { 1105 auto P = cast<NonTypeTemplateParmDecl>( 1106 Params->getParam(N->getIndex())); 1112 A.print(Policy, Out); 1117 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { 1118 printTemplateParameters(D->getTemplateParameters()); 1120 if (const TemplateTemplateParmDecl *TTP = 1121 dyn_cast<TemplateTemplateParmDecl>(D)) { 1123 if (TTP->isParameterPack()) 1125 Out << D->getName(); 1126 } else if (auto *TD = D->getTemplatedDecl()) 1128 else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) { 1129 Out << "concept " << Concept->getName() << " = " ; 1130 Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, 1136 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { 1137 prettyPrintPragmas(D->getTemplatedDecl()); 1138 // Print any leading template parameter lists. 1139 if (const FunctionDecl *FD = D->getTemplatedDecl()) { 1140 for (unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists(); 1141 I < NumTemplateParams; ++I) 1142 printTemplateParameters(FD->getTemplateParameterList(I)); 1144 VisitRedeclarableTemplateDecl(D); 1145 // Declare target attribute is special one, natural spelling for the pragma 1146 // assumes "ending" construct so print it here. 1147 if (D->getTemplatedDecl()->hasAttr<OMPDeclareTargetDeclAttr>()) 1148 Out << "#pragma omp end declare target\n"; 1150 // Never print "instantiations" for deduction guides (they don't really
1152 if (PrintInstantiation &&
1153 !isa<CXXDeductionGuideDecl>(D->getTemplatedDecl())) {
1156 if (PrevDecl->
isDefined(Def) && Def != PrevDecl)
1158 for (
auto *I : D->specializations())
1163 prettyPrintPragmas(I);
1170 VisitRedeclarableTemplateDecl(D);
1172 if (PrintInstantiation) {
1183 void DeclPrinter::VisitClassTemplateSpecializationDecl(
1185 Out <<
"template<> ";
1186 VisitCXXRecordDecl(D);
1189 void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1192 VisitCXXRecordDecl(D);
1199 void DeclPrinter::PrintObjCMethodType(
ASTContext &Ctx,
1203 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1205 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1207 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1209 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1211 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1213 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1215 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
1226 unsigned First =
true;
1227 for (
auto *Param : *Params) {
1234 switch (Param->getVariance()) {
1239 Out <<
"__covariant ";
1243 Out <<
"__contravariant ";
1247 Out << Param->getDeclName().getAsString();
1249 if (Param->hasExplicitBound()) {
1250 Out <<
" : " << Param->getUnderlyingType().getAsString(Policy);
1267 std::string::size_type pos, lastPos = 0;
1270 pos = name.find_first_of(
':', lastPos);
1273 Out << name.substr(lastPos, pos - lastPos) <<
':';
1275 PI->getObjCDeclQualifier(),
1287 prettyPrintAttributes(OMD);
1289 if (OMD->
getBody() && !Policy.TerseOutput) {
1293 else if (Policy.PolishForDeclaration)
1301 bool eolnOut =
false;
1303 Out <<
"@implementation " << I <<
" : " << *SID;
1305 Out <<
"@implementation " << I;
1310 Indentation += Policy.Indentation;
1311 for (
const auto *I : OID->
ivars()) {
1312 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1315 Indentation -= Policy.Indentation;
1322 VisitDeclContext(OID,
false);
1333 Out <<
"@class " << I;
1336 PrintObjCTypeParams(TypeParams);
1342 bool eolnOut =
false;
1343 Out <<
"@interface " << I;
1346 PrintObjCTypeParams(TypeParams);
1354 if (!Protocols.
empty()) {
1356 E = Protocols.
end(); I != E; ++I)
1357 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1364 Indentation += Policy.Indentation;
1365 for (
const auto *I : OID->
ivars()) {
1366 Indent() << I->getASTContext()
1367 .getUnqualifiedObjCPointerType(I->getType())
1370 Indentation -= Policy.Indentation;
1378 VisitDeclContext(OID,
false);
1387 Out <<
"@protocol " << *PID <<
";\n";
1392 if (!Protocols.
empty()) {
1393 Out <<
"@protocol " << *PID;
1395 E = Protocols.
end(); I != E; ++I)
1396 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1399 Out <<
"@protocol " << *PID <<
'\n';
1400 VisitDeclContext(PID,
false);
1407 VisitDeclContext(PID,
false);
1415 PrintObjCTypeParams(TypeParams);
1417 Out <<
"(" << *PID <<
")\n";
1418 if (PID->ivar_size() > 0) {
1420 Indentation += Policy.Indentation;
1421 for (
const auto *I : PID->ivars())
1422 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1424 Indentation -= Policy.Indentation;
1428 VisitDeclContext(PID,
false);
1435 Out <<
"@compatibility_alias " << *AID
1450 Out <<
"@required\n";
1452 Out <<
"@optional\n";
1461 Out << (first ?
"" :
", ") <<
"class";
1467 Out << (first ?
"" :
", ") <<
"nonatomic";
1472 Out << (first ?
"" :
", ") <<
"atomic";
1477 Out << (first ?
"" :
", ") <<
"assign";
1481 Out << (first ?
"" :
", ") <<
"retain";
1486 Out << (first ?
"" :
", ") <<
"strong";
1490 Out << (first ?
"" :
", ") <<
"copy";
1494 Out << (first ?
"" :
", ") <<
"weak";
1499 Out << (first ?
"" :
", ") <<
"unsafe_unretained";
1505 Out << (first ?
"" :
", ") <<
"readwrite";
1510 Out << (first ?
"" :
", ") <<
"readonly";
1515 Out << (first ?
"" :
", ") <<
"getter = ";
1520 Out << (first ?
"" :
", ") <<
"setter = ";
1531 Out << (first ?
"" :
", ") <<
"null_resettable";
1533 Out << (first ?
"" :
", ")
1545 Out <<
' ' << TypeStr;
1546 if (!StringRef(TypeStr).endswith(
"*"))
1549 if (Policy.PolishForDeclaration)
1555 Out <<
"@synthesize ";
1563 void DeclPrinter::VisitUsingDecl(
UsingDecl *D) {
1572 for (
const auto *Shadow : D->
shadows()) {
1573 if (
const auto *ConstructorShadow =
1574 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1575 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1576 Out << *ConstructorShadow->getNominatedBaseClass();
1585 Out <<
"using typename ";
1602 Out <<
"#pragma omp threadprivate";
1608 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1616 Out <<
"#pragma omp allocate";
1622 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1636 Out <<
"#pragma omp requires ";
1646 Out <<
"#pragma omp declare reduction (";
1648 const char *OpName =
1650 assert(OpName &&
"not an overloaded operator");
1662 Out <<
" initializer(";
1668 Out <<
"omp_priv = ";
1673 Init->printPretty(Out,
nullptr, Policy, 0);
1683 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.
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
Defines the clang::Module class, which describes a module in the source code.
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.
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. ...
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
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.
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.
std::string getAsString() const
getAsString - Retrieve the human-readable string for this name.
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
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
Return true if the ExplicitSpecifier isn't defaulted.
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