24 #include "llvm/Support/raw_ostream.h" 25 using namespace clang;
28 class DeclPrinter :
public DeclVisitor<DeclPrinter> {
33 bool PrintInstantiation;
35 raw_ostream& Indent() {
return Indent(Indentation); }
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) {}
59 void VisitDeclContext(
DeclContext *DC,
bool Indent =
true);
85 void VisitClassTemplateSpecializationDecl(
87 void VisitClassTemplatePartialSpecializationDecl(
110 void prettyPrintAttributes(
Decl *D);
111 void prettyPrintPragmas(
Decl *D);
112 void printDeclType(
QualType T, StringRef DeclName,
bool Pack =
false);
117 bool PrintInstantiation)
const {
118 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
122 unsigned Indentation,
bool PrintInstantiation)
const {
123 DeclPrinter Printer(Out, Policy, getASTContext(), Indentation,
125 Printer.Visit(const_cast<Decl*>(
this));
136 else if (
const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
137 BaseType = ATy->getElementType();
139 BaseType = FTy->getReturnType();
141 BaseType = VTy->getElementType();
145 BaseType = ATy->getDeducedType();
147 BaseType = PTy->desugar();
157 return TDD->getUnderlyingType();
158 if (
ValueDecl* VD = dyn_cast<ValueDecl>(D))
159 return VD->getType();
165 unsigned Indentation) {
167 (*Begin)->print(Out, Policy, Indentation);
186 if (!isFirst) Out <<
", ";
191 (*Begin)->print(Out, SubPolicy, Indentation);
201 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
203 Printer.VisitDeclContext(const_cast<DeclContext *>(
this),
false);
206 raw_ostream& DeclPrinter::Indent(
unsigned Indentation) {
207 for (
unsigned i = 0; i != Indentation; ++i)
212 void DeclPrinter::prettyPrintAttributes(
Decl *D) {
213 if (Policy.PolishForDeclaration)
218 for (
auto *A : Attrs) {
219 if (A->isInherited() || A->isImplicit())
221 switch (A->getKind()) {
223 #define PRAGMA_SPELLING_ATTR(X) case attr::X: 224 #include "clang/Basic/AttrList.inc" 227 A->printPretty(Out, Policy);
234 void DeclPrinter::prettyPrintPragmas(
Decl *D) {
235 if (Policy.PolishForDeclaration)
240 for (
auto *A : Attrs) {
241 switch (A->getKind()) {
243 #define PRAGMA_SPELLING_ATTR(X) case attr::X: 244 #include "clang/Basic/AttrList.inc" 245 A->printPretty(Out, Policy);
255 void DeclPrinter::printDeclType(
QualType T, StringRef DeclName,
bool Pack) {
261 T = PET->getPattern();
263 T.
print(Out, Policy, (Pack ?
"..." :
"") + DeclName, Indentation);
276 case AS_none: llvm_unreachable(
"No access specifier!");
284 std::string &Proto) {
285 bool HasInitializerList =
false;
286 for (
const auto *BMInitializer : CDecl->
inits()) {
287 if (BMInitializer->isInClassMemberInitializer())
290 if (!HasInitializerList) {
294 HasInitializerList =
true;
298 if (BMInitializer->isAnyMemberInitializer()) {
299 FieldDecl *FD = BMInitializer->getAnyMember();
306 if (!BMInitializer->getInit()) {
309 Expr *Init = BMInitializer->getInit();
311 Init = Tmp->getSubExpr();
315 Expr *SimpleInit =
nullptr;
316 Expr **Args =
nullptr;
317 unsigned NumArgs = 0;
318 if (
ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
319 Args = ParenList->getExprs();
320 NumArgs = ParenList->getNumExprs();
322 dyn_cast<CXXConstructExpr>(Init)) {
323 Args = Construct->getArgs();
324 NumArgs = Construct->getNumArgs();
329 SimpleInit->
printPretty(Out,
nullptr, Policy, Indentation);
331 for (
unsigned I = 0; I != NumArgs; ++I) {
332 assert(Args[I] !=
nullptr &&
"Expected non-null Expr");
333 if (isa<CXXDefaultArgExpr>(Args[I]))
338 Args[I]->
printPretty(Out,
nullptr, Policy, Indentation);
343 if (BMInitializer->isPackExpansion())
352 void DeclPrinter::VisitDeclContext(
DeclContext *DC,
bool Indent) {
353 if (Policy.TerseOutput)
357 Indentation += Policy.Indentation;
365 if (isa<ObjCIvarDecl>(*D))
374 if (
auto FD = dyn_cast<FunctionDecl>(*D))
376 !isa<ClassTemplateSpecializationDecl>(DC))
392 if (!Decls.empty() && !CurDeclType.
isNull()) {
394 if (!BaseType.
isNull() && isa<ElaboratedType>(BaseType) &&
395 cast<ElaboratedType>(BaseType)->getOwnedTagDecl() == Decls[0]) {
403 ProcessDeclGroup(Decls);
407 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->isFreeStanding()) {
412 if (isa<AccessSpecDecl>(*D)) {
413 Indentation -= Policy.Indentation;
417 Indentation += Policy.Indentation;
425 const char *Terminator =
nullptr;
426 if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D) ||
427 isa<OMPRequiresDecl>(*D))
428 Terminator =
nullptr;
429 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
430 Terminator =
nullptr;
431 else if (
auto FD = dyn_cast<FunctionDecl>(*D)) {
432 if (FD->isThisDeclarationADefinition())
433 Terminator =
nullptr;
436 }
else if (
auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
437 if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
438 Terminator =
nullptr;
441 }
else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
442 isa<ObjCImplementationDecl>(*D) ||
443 isa<ObjCInterfaceDecl>(*D) ||
444 isa<ObjCProtocolDecl>(*D) ||
445 isa<ObjCCategoryImplDecl>(*D) ||
446 isa<ObjCCategoryDecl>(*D))
447 Terminator =
nullptr;
448 else if (isa<EnumConstantDecl>(*D)) {
458 if (!Policy.TerseOutput &&
459 ((isa<FunctionDecl>(*D) &&
460 cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
461 (isa<FunctionTemplateDecl>(*D) &&
462 cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
469 if (D->
hasAttr<OMPDeclareTargetDeclAttr>())
470 Out <<
"#pragma omp end declare target\n";
474 ProcessDeclGroup(Decls);
477 Indentation -= Policy.Indentation;
481 VisitDeclContext(D,
false);
484 void DeclPrinter::VisitTypedefDecl(
TypedefDecl *D) {
485 if (!Policy.SuppressSpecifiers) {
489 Out <<
"__module_private__ ";
493 prettyPrintAttributes(D);
497 Out <<
"using " << *D;
498 prettyPrintAttributes(D);
499 Out <<
" = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
502 void DeclPrinter::VisitEnumDecl(
EnumDecl *D) {
504 Out <<
"__module_private__ ";
513 prettyPrintAttributes(D);
517 if (D->isFixed() && D->getASTContext().getLangOpts().CPlusPlus11)
520 if (D->isCompleteDefinition()) {
527 void DeclPrinter::VisitRecordDecl(
RecordDecl *D) {
529 Out <<
"__module_private__ ";
532 prettyPrintAttributes(D);
546 prettyPrintAttributes(D);
547 if (
Expr *Init = D->getInitExpr()) {
549 Init->printPretty(Out,
nullptr, Policy, Indentation,
"\n", &Context);
556 prettyPrintPragmas(D);
559 Out <<
"template<> ";
562 I < NumTemplateParams; ++I)
569 if (!Policy.SuppressSpecifiers) {
576 llvm_unreachable(
"invalid for functions");
584 (ConversionDecl && ConversionDecl->isExplicitSpecified()) ||
585 (GuideDecl && GuideDecl->isExplicitSpecified()))
593 if (Policy.FullyQualifiedName) {
596 if (!Policy.SuppressScope) {
598 llvm::raw_string_ostream OS(Proto);
599 NS->print(OS, Policy);
606 Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString();
608 llvm::raw_string_ostream POut(Proto);
609 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
610 TArgPrinter.printTemplateArguments(*TArgs);
614 while (
const ParenType *PT = dyn_cast<ParenType>(Ty)) {
615 Proto =
'(' + Proto +
')';
616 Ty = PT->getInnerType();
622 FT = dyn_cast<FunctionProtoType>(AFT);
626 llvm::raw_string_ostream POut(Proto);
627 DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
628 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
638 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
651 Proto +=
" volatile";
653 Proto +=
" restrict";
680 Proto +=
" noexcept";
683 llvm::raw_string_ostream EOut(Proto);
693 if (!Policy.TerseOutput)
694 PrintConstructorInitializers(CDecl, Proto);
695 }
else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
699 Out << Proto <<
" -> ";
702 AFT->getReturnType().print(Out, Policy, Proto);
707 Ty.
print(Out, Policy, Proto);
710 prettyPrintAttributes(D);
719 if (!Policy.TerseOutput) {
724 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
725 Indentation += Policy.Indentation;
726 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
731 Indentation -= Policy.Indentation;
738 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
744 void DeclPrinter::VisitFriendDecl(
FriendDecl *D) {
747 for (
unsigned i = 0; i < NumTPLists; ++i)
750 Out <<
" " << TSI->getType().getAsString(Policy);
755 VisitFunctionDecl(FD);
760 VisitFunctionTemplateDecl(FTD);
765 VisitRedeclarableTemplateDecl(CTD);
769 void DeclPrinter::VisitFieldDecl(
FieldDecl *D) {
771 if (!Policy.SuppressSpecifiers && D->
isMutable())
774 Out <<
"__module_private__ ";
777 stream(Policy, D->
getName(), Indentation);
785 if (!Policy.SuppressInitializers && Init) {
790 Init->
printPretty(Out,
nullptr, Policy, Indentation);
792 prettyPrintAttributes(D);
795 void DeclPrinter::VisitLabelDecl(
LabelDecl *D) {
799 void DeclPrinter::VisitVarDecl(
VarDecl *D) {
800 prettyPrintPragmas(D);
806 if (!Policy.SuppressSpecifiers) {
818 Out <<
"_Thread_local ";
821 Out <<
"thread_local ";
826 Out <<
"__module_private__ ";
834 printDeclType(T, D->
getName());
836 if (!Policy.SuppressInitializers && Init) {
837 bool ImplicitInit =
false;
839 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
841 !Construct->isListInitialization()) {
842 ImplicitInit = Construct->getNumArgs() == 0 ||
855 Init->printPretty(Out,
nullptr, SubPolicy, Indentation);
860 prettyPrintAttributes(D);
863 void DeclPrinter::VisitParmVarDecl(
ParmVarDecl *D) {
873 void DeclPrinter::VisitImportDecl(
ImportDecl *D) {
879 Out <<
"static_assert(";
883 SL->printPretty(Out,
nullptr, Policy, Indentation);
894 Out <<
"namespace " << *D <<
" {\n";
900 Out <<
"using namespace ";
907 Out <<
"namespace " << *D <<
" = ";
908 if (D->getQualifier())
910 Out << *D->getAliasedNamespace();
913 void DeclPrinter::VisitEmptyDecl(
EmptyDecl *D) {
914 prettyPrintAttributes(D);
920 Out <<
"__module_private__ ";
923 prettyPrintAttributes(D);
928 if (
auto S = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
929 printTemplateArguments(S->getTemplateArgs(), S->getTemplateParameters());
930 else if (
auto S = dyn_cast<ClassTemplateSpecializationDecl>(D))
931 printTemplateArguments(S->getTemplateArgs());
943 if (
Base->isVirtual())
951 Out <<
Base->getType().getAsString(Policy);
953 if (
Base->isPackExpansion())
960 if (Policy.TerseOutput) {
976 "unknown language in linkage specification");
980 Out <<
"extern \"" << l <<
"\" ";
994 for (
unsigned i = 0, e = Params->
size(); i != e; ++i) {
999 if (
auto TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
1001 if (TTP->wasDeclaredWithTypename())
1006 if (TTP->isParameterPack())
1011 if (TTP->hasDefaultArgument()) {
1013 Out << TTP->getDefaultArgument().getAsString(Policy);
1015 }
else if (
auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1018 Name = II->getName();
1019 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
1021 if (NTTP->hasDefaultArgument()) {
1023 NTTP->getDefaultArgument()->printPretty(Out,
nullptr, Policy,
1026 }
else if (
auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1027 VisitTemplateDecl(TTPD);
1038 for (
size_t I = 0, E = Args.
size(); I < E; ++I) {
1045 auto P = cast<TemplateTypeParmDecl>(Params->
getParam(T->getIndex()));
1051 if (
auto TD = dyn_cast<TemplateTemplateParmDecl>(T)) {
1052 auto P = cast<TemplateTemplateParmDecl>(
1059 if (
auto E = dyn_cast<DeclRefExpr>(A.
getAsExpr()))
1060 if (
auto N = dyn_cast<NonTypeTemplateParmDecl>(E->getDecl())) {
1061 auto P = cast<NonTypeTemplateParmDecl>(
1068 A.
print(Policy, Out);
1073 void DeclPrinter::VisitTemplateDecl(
const TemplateDecl *D) {
1077 dyn_cast<TemplateTemplateParmDecl>(D)) {
1079 if (TTP->isParameterPack())
1091 for (
unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists();
1092 I < NumTemplateParams; ++I)
1093 printTemplateParameters(FD->getTemplateParameterList(I));
1095 VisitRedeclarableTemplateDecl(D);
1099 Out <<
"#pragma omp end declare target\n";
1103 if (PrintInstantiation &&
1107 if (PrevDecl->
isDefined(Def) && Def != PrevDecl)
1114 prettyPrintPragmas(I);
1121 VisitRedeclarableTemplateDecl(D);
1123 if (PrintInstantiation) {
1134 void DeclPrinter::VisitClassTemplateSpecializationDecl(
1136 Out <<
"template<> ";
1137 VisitCXXRecordDecl(D);
1140 void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1143 VisitCXXRecordDecl(D);
1150 void DeclPrinter::PrintObjCMethodType(
ASTContext &Ctx,
1154 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1156 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1158 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1160 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1162 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1164 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1166 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
1177 unsigned First =
true;
1178 for (
auto *Param : *Params) {
1185 switch (Param->getVariance()) {
1190 Out <<
"__covariant ";
1194 Out <<
"__contravariant ";
1198 Out << Param->getDeclName().getAsString();
1200 if (Param->hasExplicitBound()) {
1201 Out <<
" : " << Param->getUnderlyingType().getAsString(Policy);
1218 std::string::size_type pos, lastPos = 0;
1221 pos = name.find_first_of(
':', lastPos);
1224 Out << name.substr(lastPos, pos - lastPos) <<
':';
1226 PI->getObjCDeclQualifier(),
1238 prettyPrintAttributes(OMD);
1240 if (OMD->
getBody() && !Policy.TerseOutput) {
1244 else if (Policy.PolishForDeclaration)
1252 bool eolnOut =
false;
1254 Out <<
"@implementation " << I <<
" : " << *SID;
1256 Out <<
"@implementation " << I;
1261 Indentation += Policy.Indentation;
1262 for (
const auto *I : OID->
ivars()) {
1263 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1266 Indentation -= Policy.Indentation;
1273 VisitDeclContext(OID,
false);
1284 Out <<
"@class " << I;
1287 PrintObjCTypeParams(TypeParams);
1293 bool eolnOut =
false;
1294 Out <<
"@interface " << I;
1297 PrintObjCTypeParams(TypeParams);
1305 if (!Protocols.
empty()) {
1307 E = Protocols.
end(); I != E; ++I)
1308 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1315 Indentation += Policy.Indentation;
1316 for (
const auto *I : OID->
ivars()) {
1317 Indent() << I->getASTContext()
1318 .getUnqualifiedObjCPointerType(I->getType())
1321 Indentation -= Policy.Indentation;
1329 VisitDeclContext(OID,
false);
1338 Out <<
"@protocol " << *PID <<
";\n";
1343 if (!Protocols.
empty()) {
1344 Out <<
"@protocol " << *PID;
1346 E = Protocols.
end(); I != E; ++I)
1347 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1350 Out <<
"@protocol " << *PID <<
'\n';
1351 VisitDeclContext(PID,
false);
1358 VisitDeclContext(PID,
false);
1366 PrintObjCTypeParams(TypeParams);
1368 Out <<
"(" << *PID <<
")\n";
1369 if (PID->ivar_size() > 0) {
1371 Indentation += Policy.Indentation;
1372 for (
const auto *I : PID->ivars())
1373 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1375 Indentation -= Policy.Indentation;
1379 VisitDeclContext(PID,
false);
1386 Out <<
"@compatibility_alias " << *AID
1394 Out <<
"@required\n";
1396 Out <<
"@optional\n";
1406 Out << (first ?
' ' :
',') <<
"readonly";
1411 Out << (first ?
' ' :
',') <<
"getter = ";
1416 Out << (first ?
' ' :
',') <<
"setter = ";
1422 Out << (first ?
' ' :
',') <<
"assign";
1428 Out << (first ?
' ' :
',') <<
"readwrite";
1433 Out << (first ?
' ' :
',') <<
"retain";
1438 Out << (first ?
' ' :
',') <<
"strong";
1443 Out << (first ?
' ' :
',') <<
"copy";
1449 Out << (first ?
' ' :
',') <<
"nonatomic";
1454 Out << (first ?
' ' :
',') <<
"atomic";
1464 Out << (first ?
' ' :
',') <<
"null_resettable";
1466 Out << (first ?
' ' :
',')
1474 Out << (first ?
' ' :
',') <<
"class";
1483 if (Policy.PolishForDeclaration)
1489 Out <<
"@synthesize ";
1497 void DeclPrinter::VisitUsingDecl(
UsingDecl *D) {
1506 for (
const auto *Shadow : D->
shadows()) {
1507 if (
const auto *ConstructorShadow =
1508 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1509 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1510 Out << *ConstructorShadow->getNominatedBaseClass();
1519 Out <<
"using typename ";
1536 Out <<
"#pragma omp threadprivate";
1542 NamedDecl *ND = cast<DeclRefExpr>(*I)->getDecl();
1550 Out <<
"#pragma omp requires ";
1560 Out <<
"#pragma omp declare reduction (";
1564 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \ 1566 #include "clang/Basic/OperatorKinds.def" 1568 const char *OpName =
1570 assert(OpName &&
"not an overloaded operator");
1582 Out <<
" initializer(";
1588 Out <<
"omp_priv = ";
1593 Init->printPretty(Out,
nullptr, Policy, 0);
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
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.
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.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
spec_range specializations() const
The template argument is an expression, and we've not resolved it to one of the other forms yet...
unsigned size() const
Retrieve the number of template arguments in this template argument list.
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
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
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.
NamedDecl * getParam(unsigned Idx)
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
A container of type source information.
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 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
Expr * getAsExpr() const
Retrieve the template argument as an expression.
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.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
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.
spec_range specializations() const
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.
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.
void print(const PrintingPolicy &Policy, raw_ostream &Out) const
Print this template argument to the given output stream.
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.
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.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
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.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
bool isExplicitSpecified() const
Whether this function is marked as explicit explicitly.
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
Represents a GCC generic vector type.
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
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.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
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.
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.
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
ObjCDeclQualifier getObjCDeclQualifier() const
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.
Represents a template argument.
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
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
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
TypeSourceInfo * getTypeSourceInfo() const
param_const_iterator param_begin() const
Base for LValueReferenceType and RValueReferenceType.
clauselist_iterator clauselist_end()
The template argument is a type.
Represents a base class of a C++ class.
bool hasTypename() const
Return true if the using declaration has 'typename'.
A template argument list.
ArgKind getKind() const
Return the kind of stored template argument.
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.
The template argument is a template name that was provided for a template template parameter...
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
base_class_iterator bases_end()
Declaration of a class template.
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
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.
QualType getAsType() const
Retrieve the type for a type template argument.
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.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
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
IgnoreParens - Ignore parentheses.
decl_iterator decls_end() const