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(
109 void prettyPrintAttributes(
Decl *D);
110 void prettyPrintPragmas(
Decl *D);
111 void printDeclType(
QualType T, StringRef DeclName,
bool Pack =
false);
116 bool PrintInstantiation)
const {
117 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
121 unsigned Indentation,
bool PrintInstantiation)
const {
122 DeclPrinter Printer(Out, Policy, getASTContext(), Indentation,
124 Printer.Visit(const_cast<Decl*>(
this));
131 if (isa<TypedefType>(BaseType))
137 else if (
const ArrayType* ATy = dyn_cast<ArrayType>(BaseType))
138 BaseType = ATy->getElementType();
140 BaseType = FTy->getReturnType();
142 BaseType = VTy->getElementType();
146 BaseType = ATy->getDeducedType();
148 llvm_unreachable(
"Unknown declarator!");
155 return TDD->getUnderlyingType();
156 if (
ValueDecl* VD = dyn_cast<ValueDecl>(D))
157 return VD->getType();
163 unsigned Indentation) {
165 (*Begin)->print(Out, Policy, Indentation);
184 if (!isFirst) Out <<
", ";
189 (*Begin)->print(Out, SubPolicy, Indentation);
199 ASTContext &Ctx = cast<TranslationUnitDecl>(DC)->getASTContext();
201 Printer.VisitDeclContext(const_cast<DeclContext *>(
this),
false);
204 raw_ostream& DeclPrinter::Indent(
unsigned Indentation) {
205 for (
unsigned i = 0; i != Indentation; ++i)
210 void DeclPrinter::prettyPrintAttributes(
Decl *D) {
211 if (Policy.PolishForDeclaration)
216 for (
auto *A : Attrs) {
217 switch (A->getKind()) {
219 #define PRAGMA_SPELLING_ATTR(X) case attr::X: 220 #include "clang/Basic/AttrList.inc" 223 A->printPretty(Out, Policy);
230 void DeclPrinter::prettyPrintPragmas(
Decl *D) {
231 if (Policy.PolishForDeclaration)
236 for (
auto *A : Attrs) {
237 switch (A->getKind()) {
239 #define PRAGMA_SPELLING_ATTR(X) case attr::X: 240 #include "clang/Basic/AttrList.inc" 241 A->printPretty(Out, Policy);
251 void DeclPrinter::printDeclType(
QualType T, StringRef DeclName,
bool Pack) {
257 T = PET->getPattern();
259 T.
print(Out, Policy, (Pack ?
"..." :
"") + DeclName, Indentation);
272 case AS_none: llvm_unreachable(
"No access specifier!");
280 std::string &Proto) {
281 bool HasInitializerList =
false;
282 for (
const auto *BMInitializer : CDecl->
inits()) {
283 if (BMInitializer->isInClassMemberInitializer())
286 if (!HasInitializerList) {
290 HasInitializerList =
true;
294 if (BMInitializer->isAnyMemberInitializer()) {
295 FieldDecl *FD = BMInitializer->getAnyMember();
302 if (!BMInitializer->getInit()) {
305 Expr *Init = BMInitializer->getInit();
307 Init = Tmp->getSubExpr();
311 Expr *SimpleInit =
nullptr;
312 Expr **Args =
nullptr;
313 unsigned NumArgs = 0;
314 if (
ParenListExpr *ParenList = dyn_cast<ParenListExpr>(Init)) {
315 Args = ParenList->getExprs();
316 NumArgs = ParenList->getNumExprs();
318 dyn_cast<CXXConstructExpr>(Init)) {
319 Args = Construct->getArgs();
320 NumArgs = Construct->getNumArgs();
325 SimpleInit->
printPretty(Out,
nullptr, Policy, Indentation);
327 for (
unsigned I = 0; I != NumArgs; ++I) {
328 assert(Args[I] !=
nullptr &&
"Expected non-null Expr");
329 if (isa<CXXDefaultArgExpr>(Args[I]))
334 Args[I]->
printPretty(Out,
nullptr, Policy, Indentation);
339 if (BMInitializer->isPackExpansion())
348 void DeclPrinter::VisitDeclContext(
DeclContext *DC,
bool Indent) {
349 if (Policy.TerseOutput)
353 Indentation += Policy.Indentation;
361 if (isa<ObjCIvarDecl>(*D))
370 if (
auto FD = dyn_cast<FunctionDecl>(*D))
372 !isa<ClassTemplateSpecializationDecl>(DC))
384 if (!Decls.empty() && !CurDeclType.
isNull()) {
386 if (!BaseType.
isNull() && isa<ElaboratedType>(BaseType))
387 BaseType = cast<ElaboratedType>(BaseType)->getNamedType();
388 if (!BaseType.
isNull() && isa<TagType>(BaseType) &&
389 cast<TagType>(BaseType)->getDecl() == Decls[0]) {
397 ProcessDeclGroup(Decls);
401 if (isa<TagDecl>(*D) && !cast<TagDecl>(*D)->getIdentifier()) {
406 if (isa<AccessSpecDecl>(*D)) {
407 Indentation -= Policy.Indentation;
411 Indentation += Policy.Indentation;
419 const char *Terminator =
nullptr;
420 if (isa<OMPThreadPrivateDecl>(*D) || isa<OMPDeclareReductionDecl>(*D))
421 Terminator =
nullptr;
422 else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody())
423 Terminator =
nullptr;
424 else if (
auto FD = dyn_cast<FunctionDecl>(*D)) {
425 if (FD->isThisDeclarationADefinition())
426 Terminator =
nullptr;
429 }
else if (
auto TD = dyn_cast<FunctionTemplateDecl>(*D)) {
430 if (TD->getTemplatedDecl()->isThisDeclarationADefinition())
431 Terminator =
nullptr;
434 }
else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) ||
435 isa<ObjCImplementationDecl>(*D) ||
436 isa<ObjCInterfaceDecl>(*D) ||
437 isa<ObjCProtocolDecl>(*D) ||
438 isa<ObjCCategoryImplDecl>(*D) ||
439 isa<ObjCCategoryDecl>(*D))
440 Terminator =
nullptr;
441 else if (isa<EnumConstantDecl>(*D)) {
451 if (!Policy.TerseOutput &&
452 ((isa<FunctionDecl>(*D) &&
453 cast<FunctionDecl>(*D)->doesThisDeclarationHaveABody()) ||
454 (isa<FunctionTemplateDecl>(*D) &&
455 cast<FunctionTemplateDecl>(*D)->getTemplatedDecl()->doesThisDeclarationHaveABody())))
462 if (D->
hasAttr<OMPDeclareTargetDeclAttr>())
463 Out <<
"#pragma omp end declare target\n";
467 ProcessDeclGroup(Decls);
470 Indentation -= Policy.Indentation;
474 VisitDeclContext(D,
false);
477 void DeclPrinter::VisitTypedefDecl(
TypedefDecl *D) {
478 if (!Policy.SuppressSpecifiers) {
482 Out <<
"__module_private__ ";
486 prettyPrintAttributes(D);
490 Out <<
"using " << *D;
491 prettyPrintAttributes(D);
492 Out <<
" = " << D->getTypeSourceInfo()->getType().getAsString(Policy);
495 void DeclPrinter::VisitEnumDecl(
EnumDecl *D) {
497 Out <<
"__module_private__ ";
507 if (D->isFixed() && D->getASTContext().getLangOpts().CPlusPlus11)
510 if (D->isCompleteDefinition()) {
515 prettyPrintAttributes(D);
518 void DeclPrinter::VisitRecordDecl(
RecordDecl *D) {
520 Out <<
"__module_private__ ";
523 prettyPrintAttributes(D);
537 prettyPrintAttributes(D);
538 if (
Expr *Init = D->getInitExpr()) {
540 Init->printPretty(Out,
nullptr, Policy, Indentation, &Context);
547 prettyPrintPragmas(D);
550 Out <<
"template<> ";
553 I < NumTemplateParams; ++I)
560 if (!Policy.SuppressSpecifiers) {
567 llvm_unreachable(
"invalid for functions");
575 (ConversionDecl && ConversionDecl->isExplicitSpecified()) ||
576 (GuideDecl && GuideDecl->isExplicitSpecified()))
584 if (Policy.FullyQualifiedName) {
587 if (!Policy.SuppressScope) {
589 llvm::raw_string_ostream OS(Proto);
590 NS->print(OS, Policy);
597 Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString();
599 llvm::raw_string_ostream POut(Proto);
600 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
601 TArgPrinter.printTemplateArguments(*TArgs);
605 while (
const ParenType *PT = dyn_cast<ParenType>(Ty)) {
606 Proto =
'(' + Proto +
')';
607 Ty = PT->getInnerType();
613 FT = dyn_cast<FunctionProtoType>(AFT);
617 llvm::raw_string_ostream POut(Proto);
618 DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
619 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
629 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
642 Proto +=
" volatile";
644 Proto +=
" restrict";
671 Proto +=
" noexcept";
674 llvm::raw_string_ostream EOut(Proto);
684 if (!Policy.TerseOutput)
685 PrintConstructorInitializers(CDecl, Proto);
686 }
else if (!ConversionDecl && !isa<CXXDestructorDecl>(D)) {
690 Out << Proto <<
" -> ";
693 AFT->getReturnType().print(Out, Policy, Proto);
698 Ty.
print(Out, Policy, Proto);
701 prettyPrintAttributes(D);
710 if (!Policy.TerseOutput) {
715 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
716 Indentation += Policy.Indentation;
717 for (
unsigned i = 0, e = D->
getNumParams(); i != e; ++i) {
722 Indentation -= Policy.Indentation;
729 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D))
735 void DeclPrinter::VisitFriendDecl(
FriendDecl *D) {
738 for (
unsigned i = 0; i < NumTPLists; ++i)
741 Out <<
" " << TSI->getType().getAsString(Policy);
746 VisitFunctionDecl(FD);
751 VisitFunctionTemplateDecl(FTD);
756 VisitRedeclarableTemplateDecl(CTD);
760 void DeclPrinter::VisitFieldDecl(
FieldDecl *D) {
762 if (!Policy.SuppressSpecifiers && D->
isMutable())
765 Out <<
"__module_private__ ";
768 stream(Policy, D->
getName(), Indentation);
776 if (!Policy.SuppressInitializers && Init) {
781 Init->
printPretty(Out,
nullptr, Policy, Indentation);
783 prettyPrintAttributes(D);
786 void DeclPrinter::VisitLabelDecl(
LabelDecl *D) {
790 void DeclPrinter::VisitVarDecl(
VarDecl *D) {
791 prettyPrintPragmas(D);
797 if (!Policy.SuppressSpecifiers) {
809 Out <<
"_Thread_local ";
812 Out <<
"thread_local ";
817 Out <<
"__module_private__ ";
825 printDeclType(T, D->
getName());
827 if (!Policy.SuppressInitializers && Init) {
828 bool ImplicitInit =
false;
830 dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) {
832 !Construct->isListInitialization()) {
833 ImplicitInit = Construct->getNumArgs() == 0 ||
846 Init->printPretty(Out,
nullptr, SubPolicy, Indentation);
851 prettyPrintAttributes(D);
854 void DeclPrinter::VisitParmVarDecl(
ParmVarDecl *D) {
864 void DeclPrinter::VisitImportDecl(
ImportDecl *D) {
870 Out <<
"static_assert(";
874 SL->printPretty(Out,
nullptr, Policy, Indentation);
885 Out <<
"namespace " << *D <<
" {\n";
891 Out <<
"using namespace ";
898 Out <<
"namespace " << *D <<
" = ";
899 if (D->getQualifier())
901 Out << *D->getAliasedNamespace();
904 void DeclPrinter::VisitEmptyDecl(
EmptyDecl *D) {
905 prettyPrintAttributes(D);
911 Out <<
"__module_private__ ";
914 prettyPrintAttributes(D);
919 if (
auto S = dyn_cast<ClassTemplatePartialSpecializationDecl>(D))
920 printTemplateArguments(S->getTemplateArgs(), S->getTemplateParameters());
921 else if (
auto S = dyn_cast<ClassTemplateSpecializationDecl>(D))
922 printTemplateArguments(S->getTemplateArgs());
934 if (
Base->isVirtual())
942 Out <<
Base->getType().getAsString(Policy);
944 if (
Base->isPackExpansion())
951 if (Policy.TerseOutput) {
967 "unknown language in linkage specification");
971 Out <<
"extern \"" << l <<
"\" ";
985 for (
unsigned i = 0, e = Params->
size(); i != e; ++i) {
990 if (
auto TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
992 if (TTP->wasDeclaredWithTypename())
997 if (TTP->isParameterPack())
1002 if (TTP->hasDefaultArgument()) {
1004 Out << TTP->getDefaultArgument().getAsString(Policy);
1006 }
else if (
auto NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1009 Name = II->getName();
1010 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack());
1012 if (NTTP->hasDefaultArgument()) {
1014 NTTP->getDefaultArgument()->printPretty(Out,
nullptr, Policy,
1017 }
else if (
auto TTPD = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1018 VisitTemplateDecl(TTPD);
1029 for (
size_t I = 0, E = Args.
size(); I < E; ++I) {
1036 auto P = cast<TemplateTypeParmDecl>(Params->
getParam(T->getIndex()));
1042 if (
auto TD = dyn_cast<TemplateTemplateParmDecl>(T)) {
1043 auto P = cast<TemplateTemplateParmDecl>(
1050 if (
auto E = dyn_cast<DeclRefExpr>(A.
getAsExpr()))
1051 if (
auto N = dyn_cast<NonTypeTemplateParmDecl>(E->getDecl())) {
1052 auto P = cast<NonTypeTemplateParmDecl>(
1059 A.
print(Policy, Out);
1064 void DeclPrinter::VisitTemplateDecl(
const TemplateDecl *D) {
1068 dyn_cast<TemplateTemplateParmDecl>(D)) {
1070 if (TTP->isParameterPack())
1082 for (
unsigned I = 0, NumTemplateParams = FD->getNumTemplateParameterLists();
1083 I < NumTemplateParams; ++I)
1084 printTemplateParameters(FD->getTemplateParameterList(I));
1086 VisitRedeclarableTemplateDecl(D);
1090 if (PrintInstantiation &&
1094 if (PrevDecl->
isDefined(Def) && Def != PrevDecl)
1101 prettyPrintPragmas(I);
1108 VisitRedeclarableTemplateDecl(D);
1110 if (PrintInstantiation) {
1121 void DeclPrinter::VisitClassTemplateSpecializationDecl(
1123 Out <<
"template<> ";
1124 VisitCXXRecordDecl(D);
1127 void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1130 VisitCXXRecordDecl(D);
1137 void DeclPrinter::PrintObjCMethodType(
ASTContext &Ctx,
1141 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_In)
1143 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Inout)
1145 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Out)
1147 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Bycopy)
1149 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Byref)
1151 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_Oneway)
1153 if (Quals & Decl::ObjCDeclQualifier::OBJC_TQ_CSNullability) {
1164 unsigned First =
true;
1165 for (
auto *Param : *Params) {
1172 switch (Param->getVariance()) {
1177 Out <<
"__covariant ";
1181 Out <<
"__contravariant ";
1185 Out << Param->getDeclName().getAsString();
1187 if (Param->hasExplicitBound()) {
1188 Out <<
" : " << Param->getUnderlyingType().getAsString(Policy);
1205 std::string::size_type pos, lastPos = 0;
1208 pos = name.find_first_of(
':', lastPos);
1211 Out << name.substr(lastPos, pos - lastPos) <<
':';
1213 PI->getObjCDeclQualifier(),
1225 prettyPrintAttributes(OMD);
1227 if (OMD->
getBody() && !Policy.TerseOutput) {
1231 else if (Policy.PolishForDeclaration)
1239 bool eolnOut =
false;
1241 Out <<
"@implementation " << I <<
" : " << *SID;
1243 Out <<
"@implementation " << I;
1248 Indentation += Policy.Indentation;
1249 for (
const auto *I : OID->
ivars()) {
1250 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1253 Indentation -= Policy.Indentation;
1260 VisitDeclContext(OID,
false);
1271 Out <<
"@class " << I;
1274 PrintObjCTypeParams(TypeParams);
1280 bool eolnOut =
false;
1281 Out <<
"@interface " << I;
1284 PrintObjCTypeParams(TypeParams);
1292 if (!Protocols.
empty()) {
1294 E = Protocols.
end(); I != E; ++I)
1295 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1302 Indentation += Policy.Indentation;
1303 for (
const auto *I : OID->
ivars()) {
1304 Indent() << I->getASTContext()
1305 .getUnqualifiedObjCPointerType(I->getType())
1308 Indentation -= Policy.Indentation;
1316 VisitDeclContext(OID,
false);
1325 Out <<
"@protocol " << *PID <<
";\n";
1330 if (!Protocols.
empty()) {
1331 Out <<
"@protocol " << *PID;
1333 E = Protocols.
end(); I != E; ++I)
1334 Out << (I == Protocols.
begin() ?
'<' :
',') << **I;
1337 Out <<
"@protocol " << *PID <<
'\n';
1338 VisitDeclContext(PID,
false);
1345 VisitDeclContext(PID,
false);
1353 PrintObjCTypeParams(TypeParams);
1355 Out <<
"(" << *PID <<
")\n";
1356 if (PID->ivar_size() > 0) {
1358 Indentation += Policy.Indentation;
1359 for (
const auto *I : PID->ivars())
1360 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1362 Indentation -= Policy.Indentation;
1366 VisitDeclContext(PID,
false);
1373 Out <<
"@compatibility_alias " << *AID
1381 Out <<
"@required\n";
1383 Out <<
"@optional\n";
1393 Out << (first ?
' ' :
',') <<
"readonly";
1398 Out << (first ?
' ' :
',') <<
"getter = ";
1403 Out << (first ?
' ' :
',') <<
"setter = ";
1409 Out << (first ?
' ' :
',') <<
"assign";
1415 Out << (first ?
' ' :
',') <<
"readwrite";
1420 Out << (first ?
' ' :
',') <<
"retain";
1425 Out << (first ?
' ' :
',') <<
"strong";
1430 Out << (first ?
' ' :
',') <<
"copy";
1436 Out << (first ?
' ' :
',') <<
"nonatomic";
1441 Out << (first ?
' ' :
',') <<
"atomic";
1451 Out << (first ?
' ' :
',') <<
"null_resettable";
1453 Out << (first ?
' ' :
',')
1461 Out << (first ?
' ' :
',') <<
"class";
1470 if (Policy.PolishForDeclaration)
1476 Out <<
"@synthesize ";
1484 void DeclPrinter::VisitUsingDecl(
UsingDecl *D) {
1493 for (
const auto *Shadow : D->
shadows()) {
1494 if (
const auto *ConstructorShadow =
1495 dyn_cast<ConstructorUsingShadowDecl>(Shadow)) {
1496 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1497 Out << *ConstructorShadow->getNominatedBaseClass();
1506 Out <<
"using typename ";
1523 Out <<
"#pragma omp threadprivate";
1529 NamedDecl *ND = cast<NamedDecl>(cast<DeclRefExpr>(*I)->getDecl());
1538 Out <<
"#pragma omp declare reduction (";
1542 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \ 1544 #include "clang/Basic/OperatorKinds.def" 1546 const char *OpName =
1548 assert(OpName &&
"not an overloaded operator");
1560 Out <<
" initializer(";
1566 Out <<
"omp_priv = ";
1571 Init->printPretty(Out,
nullptr, Policy, 0);
Defines the clang::ASTContext interface.
An instance of this class is created to represent 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
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
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...
EnumConstantDecl - 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.
TypedefDecl - 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.
ThreadStorageClassSpecifier getTSCSpec() const
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
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.
NamespaceDecl - 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 is defined at all, including a deleted definition.
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
isCompleteDefinition - 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.
VarDecl - An instance of this class is created to represent 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 ...
ParmVarDecl - Represents a parameter to a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isExplicitSpecified() const
Whether this function is marked as explicit explicitly.
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
const ObjCInterfaceDecl * getSuperClass() const
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
RecordDecl - Represents a struct/union/class.
LanguageIDs getLanguage() const
Return the language specified by this linkage specification.
DeclarationName getDeclName() const
getDeclName - 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 ...
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
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
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.
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.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, const ASTContext *Context=nullptr) const
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
NameKind getNameKind() const
getNameKind - Determine what kind of name this is.
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
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.
TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x alias-declaration.
Represents a prototype with parameter type info, e.g.
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
OverloadedOperatorKind getCXXOverloadedOperator() const
getCXXOverloadedOperator - If this name is the name of an overloadable operator in C++ (e...
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
MutableArrayRef< Expr * >::iterator varlist_iterator
void print(raw_ostream &OS, const PrintingPolicy &Policy) const
Print this nested name specifier to the given output stream.
unsigned ivar_size() const
TypeSourceInfo * getTypeSourceInfo() const
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - 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.
const FunctionProtoType * T
bool IncludeTagDefinition
When true, include the body of a tag definition.
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.
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.
Represents a C++ deduction guide declaration.
void printQualifiedName(raw_ostream &OS) const
printQualifiedName - Returns human-readable qualified name for declaration, like A::B::i, for i being member of namespace A::B.
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
virtual void printName(raw_ostream &os) const
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
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
bool SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration...
TagDecl - Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
LabelDecl - 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
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 (&&).
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)
getStorageClassSpecifierString - 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
EnumDecl - Represents an enum.
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.
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)
bool isMutable() const
isMutable - 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
getIntegerType - Return the integer type this enum decl corresponds to.
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body - that is, if it is a non-delete...
StringRef getName() const
getName - 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
TranslationUnitDecl - 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...
NamedDecl - This represents a decl with 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