clang: lib/AST/DeclPrinter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
25#include "llvm/Support/raw_ostream.h"
26using namespace clang;
27
28namespace {
29 class DeclPrinter : public DeclVisitor {
30 raw_ostream &Out;
31 PrintingPolicy Policy;
32 const ASTContext &Context;
33 unsigned Indentation;
34 bool PrintInstantiation;
35
36 raw_ostream& Indent() { return Indent(Indentation); }
37 raw_ostream& Indent(unsigned Indentation);
38 void ProcessDeclGroup(SmallVectorImpl<Decl*>& Decls);
39
41 void PrintConstructorInitializers(CXXConstructorDecl *CDecl,
42 std::string &Proto);
43
44
45
46
47
49 QualType T);
50
51 void PrintObjCTypeParams(ObjCTypeParamList *Params);
52 void PrintOpenACCRoutineOnLambda(Decl *D);
53
54 public:
55 DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy,
56 const ASTContext &Context, unsigned Indentation = 0,
57 bool PrintInstantiation = false)
58 : Out(Out), Policy(Policy), Context(Context), Indentation(Indentation),
59 PrintInstantiation(PrintInstantiation) {}
60
61 void VisitDeclContext(DeclContext *DC, bool Indent = true);
62
63 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
64 void VisitTypedefDecl(TypedefDecl *D);
65 void VisitTypeAliasDecl(TypeAliasDecl *D);
66 void VisitEnumDecl(EnumDecl *D);
67 void VisitRecordDecl(RecordDecl *D);
68 void VisitEnumConstantDecl(EnumConstantDecl *D);
69 void VisitEmptyDecl(EmptyDecl *D);
70 void VisitFunctionDecl(FunctionDecl *D);
71 void VisitFriendDecl(FriendDecl *D);
72 void VisitFieldDecl(FieldDecl *D);
73 void VisitVarDecl(VarDecl *D);
74 void VisitLabelDecl(LabelDecl *D);
75 void VisitParmVarDecl(ParmVarDecl *D);
76 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
77 void VisitTopLevelStmtDecl(TopLevelStmtDecl *D);
78 void VisitImportDecl(ImportDecl *D);
79 void VisitStaticAssertDecl(StaticAssertDecl *D);
80 void VisitNamespaceDecl(NamespaceDecl *D);
81 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
82 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
83 void VisitCXXRecordDecl(CXXRecordDecl *D);
84 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
85 void VisitTemplateDecl(const TemplateDecl *D);
86 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
87 void VisitClassTemplateDecl(ClassTemplateDecl *D);
88 void VisitClassTemplateSpecializationDecl(
89 ClassTemplateSpecializationDecl *D);
90 void VisitClassTemplatePartialSpecializationDecl(
91 ClassTemplatePartialSpecializationDecl *D);
92 void VisitObjCMethodDecl(ObjCMethodDecl *D);
93 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
94 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
95 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
96 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
97 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
98 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
99 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
100 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
101 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
102 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
103 void VisitUsingDecl(UsingDecl *D);
104 void VisitUsingEnumDecl(UsingEnumDecl *D);
105 void VisitUsingShadowDecl(UsingShadowDecl *D);
106 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
107 void VisitOMPAllocateDecl(OMPAllocateDecl *D);
108 void VisitOMPRequiresDecl(OMPRequiresDecl *D);
109 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
110 void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
111 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
112 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP);
113 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP);
114 void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *);
115 void VisitHLSLBufferDecl(HLSLBufferDecl *D);
116
117 void VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D);
118 void VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D);
119
120 void printTemplateParameters(const TemplateParameterList *Params,
121 bool OmitTemplateKW = false);
122 void printTemplateArguments(ArrayRef Args,
123 const TemplateParameterList *Params);
124 void printTemplateArguments(ArrayRef Args,
125 const TemplateParameterList *Params);
127 bool
128 prettyPrintAttributes(const Decl *D,
129 AttrPosAsWritten Pos = AttrPosAsWritten::Default);
130 void prettyPrintPragmas(Decl *D);
131 void printDeclType(QualType T, StringRef DeclName, bool Pack = false);
132 };
133}
134
135void Decl::print(raw_ostream &Out, unsigned Indentation,
136 bool PrintInstantiation) const {
137 print(Out, getASTContext().getPrintingPolicy(), Indentation, PrintInstantiation);
138}
139
141 unsigned Indentation, bool PrintInstantiation) const {
142 DeclPrinter Printer(Out, Policy, getASTContext(), Indentation,
143 PrintInstantiation);
144 Printer.Visit(const_cast<Decl*>(this));
145}
146
148 bool OmitTemplateKW) const {
149 print(Out, Context, Context.getPrintingPolicy(), OmitTemplateKW);
150}
151
154 bool OmitTemplateKW) const {
155 DeclPrinter Printer(Out, Policy, Context);
156 Printer.printTemplateParameters(this, OmitTemplateKW);
157}
158
160
162 while (!BaseType->isSpecifierType()) {
164 BaseType = PTy->getPointeeType();
167 BaseType = OPT->getPointeeType();
169 BaseType = BPy->getPointeeType();
170 else if (const ArrayType *ATy = dyn_cast(BaseType))
171 BaseType = ATy->getElementType();
173 BaseType = FTy->getReturnType();
175 BaseType = VTy->getElementType();
177 BaseType = RTy->getPointeeType();
178 else if (const AutoType *ATy = BaseType->getAs())
179 BaseType = ATy->getDeducedType();
181 BaseType = PTy->desugar();
182 else
183
184 break;
185 }
186 return BaseType;
187}
188
191 return TDD->getUnderlyingType();
192 if (ValueDecl* VD = dyn_cast(D))
193 return VD->getType();
195}
196
199 unsigned Indentation) {
200 if (NumDecls == 1) {
201 (*Begin)->print(Out, Policy, Indentation);
202 return;
203 }
204
205 Decl** End = Begin + NumDecls;
207 ++Begin;
208
210
211 bool isFirst = true;
212 for ( ; Begin != End; ++Begin) {
213 if (isFirst) {
214 isFirst = false;
215 } else {
216 Out << ", ";
218 }
219
220 (*Begin)->print(Out, SubPolicy, Indentation);
221 }
222}
223
225
229
231 DeclPrinter Printer(llvm::errs(), Ctx.getPrintingPolicy(), Ctx, 0);
232 Printer.VisitDeclContext(const_cast<DeclContext *>(this), false);
233}
234
235raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
236 for (unsigned i = 0; i != Indentation; ++i)
237 Out << " ";
238 return Out;
239}
240
242 const Decl *D) {
247 return DeclPrinter::AttrPosAsWritten::Left;
248
249 if (C.getSourceManager().isBeforeInTranslationUnit(ALoc, DLoc))
250 return DeclPrinter::AttrPosAsWritten::Left;
251
252 return DeclPrinter::AttrPosAsWritten::Right;
253}
254
255
256bool DeclPrinter::prettyPrintAttributes(const Decl *D,
257 AttrPosAsWritten Pos ) {
258 bool hasPrinted = false;
259
262 for (auto *A : Attrs) {
263 if (A->isInherited() || A->isImplicit())
264 continue;
265
267 continue;
268 switch (A->getKind()) {
269#define ATTR(X)
270#define PRAGMA_SPELLING_ATTR(X) case attr::X:
271#include "clang/Basic/AttrList.inc"
272 break;
273 default:
275 assert(APos != AttrPosAsWritten::Default &&
276 "Default not a valid for an attribute location");
277 if (Pos == AttrPosAsWritten::Default || Pos == APos) {
278 if (Pos != AttrPosAsWritten::Left)
279 Out << ' ';
280 A->printPretty(Out, Policy);
281 hasPrinted = true;
282 if (Pos == AttrPosAsWritten::Left)
283 Out << ' ';
284 }
285 break;
286 }
287 }
288 }
289 return hasPrinted;
290}
291
292void DeclPrinter::PrintOpenACCRoutineOnLambda(Decl *D) {
294 if (const auto *VD = dyn_cast(D)) {
295 if (const auto *Init = VD->getInit())
296 CXXRD = Init->getType().isNull() ? nullptr
297 : Init->getType()->getAsCXXRecordDecl();
298 } else if (const auto *FD = dyn_cast(D)) {
299 CXXRD =
300 FD->getType().isNull() ? nullptr : FD->getType()->getAsCXXRecordDecl();
301 }
302
303 if (!CXXRD || !CXXRD->isLambda())
304 return;
305
307 for (auto *A : Call->specific_attrs()) {
308 A->printPretty(Out, Policy);
310 }
311 }
312}
313
314void DeclPrinter::prettyPrintPragmas(Decl *D) {
316 return;
317
318 PrintOpenACCRoutineOnLambda(D);
319
322 for (auto *A : Attrs) {
323 switch (A->getKind()) {
324#define ATTR(X)
325#define PRAGMA_SPELLING_ATTR(X) case attr::X:
326#include "clang/Basic/AttrList.inc"
327 A->printPretty(Out, Policy);
329 break;
330 default:
331 break;
332 }
333 }
334 }
335}
336
337void DeclPrinter::printDeclType(QualType T, StringRef DeclName, bool Pack) {
338
339
340
341 if (auto *PET = T->getAs()) {
342 Pack = true;
343 T = PET->getPattern();
344 }
345 T.print(Out, Policy, (Pack ? "..." : "") + DeclName, Indentation);
346}
347
350 Decl::printGroup(Decls.data(), Decls.size(), Out, Policy, Indentation);
351 Out << ";\n";
352 Decls.clear();
353
354}
355
358 if (AccessSpelling.empty())
359 llvm_unreachable("No access specifier!");
360 Out << AccessSpelling;
361}
362
363void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl,
364 std::string &Proto) {
365 bool HasInitializerList = false;
366 for (const auto *BMInitializer : CDecl->inits()) {
367 if (BMInitializer->isInClassMemberInitializer())
368 continue;
369 if (!BMInitializer->isWritten())
370 continue;
371
372 if (!HasInitializerList) {
373 Proto += " : ";
374 Out << Proto;
375 Proto.clear();
376 HasInitializerList = true;
377 } else
378 Out << ", ";
379
380 if (BMInitializer->isAnyMemberInitializer()) {
381 FieldDecl *FD = BMInitializer->getAnyMember();
382 Out << *FD;
383 } else if (BMInitializer->isDelegatingInitializer()) {
385 } else {
387 }
388
389 if (Expr *Init = BMInitializer->getInit()) {
391
392 if (OutParens)
393 Out << "(";
394
396 Init = Tmp->getSubExpr();
397
399
400 Expr *SimpleInit = nullptr;
401 Expr **Args = nullptr;
402 unsigned NumArgs = 0;
404 Args = ParenList->getExprs();
405 NumArgs = ParenList->getNumExprs();
407 dyn_cast(Init)) {
408 Args = Construct->getArgs();
409 NumArgs = Construct->getNumArgs();
410 } else
411 SimpleInit = Init;
412
413 if (SimpleInit)
414 SimpleInit->printPretty(Out, nullptr, Policy, Indentation, "\n",
415 &Context);
416 else {
417 for (unsigned I = 0; I != NumArgs; ++I) {
418 assert(Args[I] != nullptr && "Expected non-null Expr");
420 break;
421
422 if (I)
423 Out << ", ";
424 Args[I]->printPretty(Out, nullptr, Policy, Indentation, "\n",
425 &Context);
426 }
427 }
428
429 if (OutParens)
430 Out << ")";
431 } else {
432 Out << "()";
433 }
434
435 if (BMInitializer->isPackExpansion())
436 Out << "...";
437 }
438}
439
440
441
442
443
444void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) {
446 return;
447
450
453 D != DEnd; ++D) {
454
455
456
458 continue;
459
460
462 continue;
463
464
465
466 if (auto FD = dyn_cast(*D))
469 continue;
470
471
472
473
474
475
476
477
478
479
480
481
482
484 if (!Decls.empty() && !CurDeclType.isNull()) {
486 if (const auto *TT = dyn_cast_or_null(BaseType);
487 TT && TT->isTagOwned()) {
488 if (TT->getDecl() == Decls[0]) {
489 Decls.push_back(*D);
490 continue;
491 }
492 }
493 }
494
495
496 if (!Decls.empty())
497 ProcessDeclGroup(Decls);
498
499
500
502 Decls.push_back(*D);
503 continue;
504 }
505
510 Out << ":\n";
512 continue;
513 }
514
516 Visit(*D);
517
518
519 const char *Terminator = nullptr;
523 Terminator = nullptr;
525 Terminator = nullptr;
527 Terminator = nullptr;
528 else if (auto FD = dyn_cast(*D)) {
529 if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted())
530 Terminator = nullptr;
531 else
532 Terminator = ";";
533 } else if (auto TD = dyn_cast(*D)) {
534 if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody())
535 Terminator = nullptr;
536 else
537 Terminator = ";";
541 Terminator = nullptr;
545 if (Next != DEnd)
546 Terminator = ",";
547 } else
548 Terminator = ";";
549
550 if (Terminator)
551 Out << Terminator;
557 ;
558 else
559 Out << "\n";
560
561
562
563 if (D->hasAttr())
564 Out << "#pragma omp end declare target\n";
565 }
566
567 if (!Decls.empty())
568 ProcessDeclGroup(Decls);
569
572}
573
575 VisitDeclContext(D, false);
576}
577
578void DeclPrinter::VisitTypedefDecl(TypedefDecl *D) {
580 Out << "typedef ";
581
583 Out << "__module_private__ ";
584 }
586 Ty.print(Out, Policy, D->getName(), Indentation);
587 prettyPrintAttributes(D);
588}
589
590void DeclPrinter::VisitTypeAliasDecl(TypeAliasDecl *D) {
591 Out << "using " << *D;
592 prettyPrintAttributes(D);
594}
595
596void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
598 Out << "__module_private__ ";
599 Out << "enum";
602 Out << " class";
603 else
604 Out << " struct";
605 }
606
607 prettyPrintAttributes(D);
608
611
614
616 Out << " {\n";
617 VisitDeclContext(D);
619 }
620}
621
622void DeclPrinter::VisitRecordDecl(RecordDecl *D) {
624 Out << "__module_private__ ";
626
627 prettyPrintAttributes(D);
628
630 Out << ' ' << *D;
631
632 if (D->isCompleteDefinition()) {
633 Out << " {\n";
634 VisitDeclContext(D);
636 }
637}
638
639void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) {
640 Out << *D;
641 prettyPrintAttributes(D);
643 Out << " = ";
644 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
645 }
646}
647
651 std::string Proto = "explicit";
652 llvm::raw_string_ostream EOut(Proto);
654 EOut << "(";
656 &Context);
657 EOut << ")";
658 }
659 EOut << " ";
660 Out << Proto;
661}
662
663void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {
666 prettyPrintPragmas(D);
667 prettyPrintAttributes(D, AttrPosAsWritten::Left);
668 }
669
671 Out << "template<> ";
674 I < NumTemplateParams; ++I)
676 }
677
679 CXXConversionDecl *ConversionDecl = dyn_cast(D);
688 llvm_unreachable("invalid for functions");
689 }
690
695 Out << "constexpr ";
698 Out << "immediate ";
702 }
703
705 SubPolicy.SuppressSpecifiers = false;
706 std::string Proto;
707
710 } else {
711 llvm::raw_string_ostream OS(Proto);
715 }
716
717 if (GuideDecl)
720 llvm::raw_string_ostream POut(Proto);
721 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation);
724 TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(), nullptr);
727 TArgPrinter.printTemplateArguments(TArgs->asArray(), nullptr);
728 }
729
731 while (const ParenType *PT = dyn_cast(Ty)) {
732 Proto = '(' + Proto + ')';
733 Ty = PT->getInnerType();
734 }
735
739 FT = dyn_cast(AFT);
740
741 Proto += "(";
742 if (FT) {
743 llvm::raw_string_ostream POut(Proto);
744 DeclPrinter ParamPrinter(POut, SubPolicy, Context, Indentation);
745 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
746 if (i) POut << ", ";
747 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
748 }
749
752 POut << "...";
754
755
756 POut << "void";
757 }
759 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
760 if (i)
761 Proto += ", ";
763 }
764 }
765
766 Proto += ")";
767
768 if (FT) {
770 Proto += " const";
772 Proto += " volatile";
774 Proto += " restrict";
775
778 break;
780 Proto += " &";
781 break;
783 Proto += " &&";
784 break;
785 }
786 }
787
789 Proto += " throw(";
791 Proto += "...";
792 else
793 for (unsigned I = 0, N = FT->getNumExceptions(); I != N; ++I) {
794 if (I)
795 Proto += ", ";
796
798 }
799 Proto += ")";
801 Proto += " noexcept";
803 Proto += "(";
804 llvm::raw_string_ostream EOut(Proto);
806 Indentation, "\n", &Context);
807 Proto += ")";
808 }
809 }
810
811 if (CDecl) {
813 PrintConstructorInitializers(CDecl, Proto);
816 if (!GuideDecl)
817 Out << "auto ";
818 Out << Proto << " -> ";
819 Proto.clear();
820 }
821 AFT->getReturnType().print(Out, Policy, Proto);
822 Proto.clear();
823 }
824 Out << Proto;
825
828 Out << " requires ";
829
830
831
832 TrailingRequiresClause.ConstraintExpr->printPretty(
833 Out, nullptr, SubPolicy, Indentation, "\n", &Context);
834 }
835 } else {
836 Ty.print(Out, Policy, Proto);
837 }
838
839 prettyPrintAttributes(D, AttrPosAsWritten::Right);
840
842 Out << " = 0";
844 Out << " = delete";
846 Out << "(";
847 M->outputString(Out);
848 Out << ")";
849 }
851 Out << " = default";
855
856
857 Out << '\n';
858 DeclPrinter ParamPrinter(Out, SubPolicy, Context, Indentation);
860 for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) {
862 ParamPrinter.VisitParmVarDecl(D->getParamDecl(i));
863 Out << ";\n";
864 }
866 }
867
870 &Context);
871 } else {
873 Out << " {}";
874 }
875 }
876}
877
878void DeclPrinter::VisitFriendDecl(FriendDecl *D) {
881 for (unsigned i = 0; i < NumTPLists; ++i)
883 Out << "friend ";
884 Out << TSI->getType().getAsString(Policy);
885 }
888 Out << "friend ";
889 VisitFunctionDecl(FD);
890 }
892 dyn_cast(D->getFriendDecl())) {
893 Out << "friend ";
894 VisitFunctionTemplateDecl(FTD);
895 }
897 dyn_cast(D->getFriendDecl())) {
898 Out << "friend ";
899 VisitRedeclarableTemplateDecl(CTD);
900 }
901
903 Out << "...";
904}
905
906void DeclPrinter::VisitFieldDecl(FieldDecl *D) {
907 prettyPrintPragmas(D);
908
910 Out << "mutable ";
912 Out << "__module_private__ ";
913
915 stream(Policy, D->getName(), Indentation);
916
918 Out << " : ";
920 &Context);
921 }
922
926 Out << " ";
927 else
928 Out << " = ";
929 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
930 }
931 prettyPrintAttributes(D);
932}
933
934void DeclPrinter::VisitLabelDecl(LabelDecl *D) {
935 Out << *D << ":";
936}
937
938void DeclPrinter::VisitVarDecl(VarDecl *D) {
939 prettyPrintPragmas(D);
940
941 prettyPrintAttributes(D, AttrPosAsWritten::Left);
942
943 if (const auto *Param = dyn_cast(D);
944 Param && Param->isExplicitObjectParameter())
945 Out << "this ";
946
950
955
958 break;
960 Out << "__thread ";
961 break;
963 Out << "_Thread_local ";
964 break;
966 Out << "thread_local ";
967 break;
968 }
969
971 Out << "__module_private__ ";
972
974 Out << "constexpr ";
975 T.removeLocalConst();
976 }
977 }
978
983
984 prettyPrintAttributes(D, AttrPosAsWritten::Right);
985
988 bool ImplicitInit = false;
990
991 ImplicitInit = true;
993 dyn_cast(Init->IgnoreImplicit())) {
995 !Construct->isListInitialization()) {
996 ImplicitInit = Construct->getNumArgs() == 0 ||
997 Construct->getArg(0)->isDefaultArgument();
998 }
999 }
1000 if (!ImplicitInit) {
1002 Out << "(";
1004 Out << " = ";
1005 }
1007 SubPolicy.SuppressSpecifiers = false;
1008 Init->printPretty(Out, nullptr, SubPolicy, Indentation, "\n", &Context);
1010 Out << ")";
1011 }
1012 }
1013}
1014
1015void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) {
1016 VisitVarDecl(D);
1017}
1018
1019void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
1020 Out << "__asm (";
1022 &Context);
1023 Out << ")";
1024}
1025
1026void DeclPrinter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) {
1028 D->getStmt()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1029}
1030
1031void DeclPrinter::VisitImportDecl(ImportDecl *D) {
1033 << ";\n";
1034}
1035
1036void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
1037 Out << "static_assert(";
1039 &Context);
1041 Out << ", ";
1042 E->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1043 }
1044 Out << ")";
1045}
1046
1047
1048
1049
1050void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
1052 Out << "inline ";
1053
1054 Out << "namespace ";
1057 Out << "{\n";
1058
1059 VisitDeclContext(D);
1061}
1062
1064 Out << "using namespace ";
1067}
1068
1070 Out << "namespace " << *D << " = ";
1073}
1074
1075void DeclPrinter::VisitEmptyDecl(EmptyDecl *D) {
1076 prettyPrintAttributes(D);
1077}
1078
1079void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) {
1080
1082 Out << "__module_private__ ";
1083
1085
1086
1087
1088 if (prettyPrintAttributes(D, AttrPosAsWritten::Left))
1089 Out << ' ';
1090
1093 Out << *D;
1094
1095 if (auto *S = dyn_cast(D)) {
1097 S->getSpecializedTemplate()->getTemplateParameters();
1099 S->getTemplateArgsAsWritten();
1101 printTemplateArguments(TArgAsWritten->arguments(), TParams);
1102 else
1103 printTemplateArguments(S->getTemplateArgs().asArray(), TParams);
1104 }
1105 }
1106
1107 prettyPrintAttributes(D, AttrPosAsWritten::Right);
1108
1109 if (D->isCompleteDefinition()) {
1110 Out << ' ';
1111
1112 if (D->getNumBases()) {
1113 Out << ": ";
1115 BaseEnd = D->bases_end(); Base != BaseEnd; ++Base) {
1116 if (Base != D->bases_begin())
1117 Out << ", ";
1118
1119 if (Base->isVirtual())
1120 Out << "virtual ";
1121
1124 Print(AS);
1125 Out << " ";
1126 }
1127 Out << Base->getType().getAsString(Policy);
1128
1129 if (Base->isPackExpansion())
1130 Out << "...";
1131 }
1132 Out << ' ';
1133 }
1134
1135
1136
1138 Out << "{}";
1139 } else {
1140 Out << "{\n";
1141 VisitDeclContext(D);
1143 }
1144 }
1145}
1146
1147void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1148 const char *l;
1150 l = "C";
1151 else {
1153 "unknown language in linkage specification");
1154 l = "C++";
1155 }
1156
1157 Out << "extern \"" << l << "\" ";
1159 Out << "{\n";
1160 VisitDeclContext(D);
1162 } else
1164}
1165
1167 bool OmitTemplateKW) {
1168 assert(Params);
1169
1170
1172 return;
1173
1174 if (!OmitTemplateKW)
1175 Out << "template ";
1176 Out << '<';
1177
1178 bool NeedComma = false;
1179 for (const Decl *Param : *Params) {
1180 if (Param->isImplicit())
1181 continue;
1182
1183 if (NeedComma)
1184 Out << ", ";
1185 else
1186 NeedComma = true;
1187
1188 if (const auto *TTP = dyn_cast(Param)) {
1189 VisitTemplateTypeParmDecl(TTP);
1190 } else if (auto NTTP = dyn_cast(Param)) {
1191 VisitNonTypeTemplateParmDecl(NTTP);
1192 } else if (auto TTPD = dyn_cast(Param)) {
1193 VisitTemplateTemplateParmDecl(TTPD);
1194 }
1195 }
1196
1197 Out << '>';
1198
1199 if (const Expr *RequiresClause = Params->getRequiresClause()) {
1200 Out << " requires ";
1201 RequiresClause->printPretty(Out, nullptr, Policy, Indentation, "\n",
1202 &Context);
1203 }
1204
1205 if (!OmitTemplateKW)
1206 Out << ' ';
1207}
1208
1211 Out << "<";
1212 for (size_t I = 0, E = Args.size(); I < E; ++I) {
1213 if (I)
1214 Out << ", ";
1215 if (!Params)
1216 Args[I].print(Policy, Out, true);
1217 else
1218 Args[I].print(Policy, Out,
1220 Policy, Params, I));
1221 }
1222 Out << ">";
1223}
1224
1227 Out << "<";
1228 for (size_t I = 0, E = Args.size(); I < E; ++I) {
1229 if (I)
1230 Out << ", ";
1231 if (!Params)
1232 Args[I].getArgument().print(Policy, Out, true);
1233 else
1234 Args[I].getArgument().print(
1235 Policy, Out,
1237 I));
1238 }
1239 Out << ">";
1240}
1241
1242void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
1244
1246 dyn_cast(D)) {
1247 if (TTP->wasDeclaredWithTypename())
1248 Out << "typename";
1249 else
1250 Out << "class";
1251
1252 if (TTP->isParameterPack())
1253 Out << " ...";
1254 else if (TTP->getDeclName())
1255 Out << ' ';
1256
1257 if (TTP->getDeclName()) {
1259 Out << TTP->getIdentifier()->deuglifiedName();
1260 else
1261 Out << TTP->getDeclName();
1262 }
1264 Visit(TD);
1265 else if (const auto *Concept = dyn_cast(D)) {
1266 Out << "concept " << Concept->getName() << " = " ;
1267 Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, Indentation,
1268 "\n", &Context);
1269 }
1270}
1271
1274
1277 I < NumTemplateParams; ++I)
1279 }
1280 VisitRedeclarableTemplateDecl(D);
1281
1282
1284 Out << "#pragma omp end declare target\n";
1285
1286
1287
1288 if (PrintInstantiation &&
1292 if (PrevDecl->isDefined(Def) && Def != PrevDecl)
1293 return;
1297 Out << ";\n";
1299 prettyPrintPragmas(I);
1300 Visit(I);
1301 }
1302 }
1303}
1304
1306 VisitRedeclarableTemplateDecl(D);
1307
1308 if (PrintInstantiation) {
1312 Out << ";";
1313 Out << "\n";
1315 Visit(I);
1316 }
1317 }
1318}
1319
1320void DeclPrinter::VisitClassTemplateSpecializationDecl(
1322 Out << "template<> ";
1323 VisitCXXRecordDecl(D);
1324}
1325
1326void DeclPrinter::VisitClassTemplatePartialSpecializationDecl(
1329 VisitCXXRecordDecl(D);
1330}
1331
1332
1333
1334
1335
1336void DeclPrinter::PrintObjCMethodType(ASTContext &Ctx,
1339 Out << '(';
1341 Out << "in ";
1343 Out << "inout ";
1345 Out << "out ";
1347 Out << "bycopy ";
1349 Out << "byref ";
1351 Out << "oneway ";
1353 if (auto nullability = AttributedType::stripOuterNullability(T))
1355 }
1356
1358 Out << ')';
1359}
1360
1361void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList *Params) {
1362 Out << "<";
1363 unsigned First = true;
1364 for (auto *Param : *Params) {
1367 } else {
1368 Out << ", ";
1369 }
1370
1371 switch (Param->getVariance()) {
1373 break;
1374
1376 Out << "__covariant ";
1377 break;
1378
1380 Out << "__contravariant ";
1381 break;
1382 }
1383
1384 Out << Param->getDeclName();
1385
1386 if (Param->hasExplicitBound()) {
1387 Out << " : " << Param->getUnderlyingType().getAsString(Policy);
1388 }
1389 }
1390 Out << ">";
1391}
1392
1393void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) {
1395 Out << "- ";
1396 else
1397 Out << "+ ";
1401 }
1402
1404 std:🧵:size_type pos, lastPos = 0;
1405 for (const auto *PI : OMD->parameters()) {
1406
1407 pos = name.find_first_of(':', lastPos);
1408 if (lastPos != 0)
1409 Out << " ";
1410 Out << name.substr(lastPos, pos - lastPos) << ':';
1412 PI->getObjCDeclQualifier(),
1413 PI->getType());
1414 Out << *PI;
1415 lastPos = pos + 1;
1416 }
1417
1420
1422 Out << ", ...";
1423
1424 prettyPrintAttributes(OMD);
1425
1427 Out << ' ';
1428 OMD->getBody()->printPretty(Out, nullptr, Policy, Indentation, "\n",
1429 &Context);
1430 }
1432 Out << ';';
1433}
1434
1438
1439 bool eolnOut = false;
1440 if (SID)
1441 Out << "@implementation " << I << " : " << *SID;
1442 else
1443 Out << "@implementation " << I;
1444
1446 Out << "{\n";
1447 eolnOut = true;
1449 for (const auto *I : OID->ivars()) {
1450 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1451 getAsString(Policy) << ' ' << *I << ";\n";
1452 }
1454 Out << "}\n";
1455 } else if (SID || !OID->decls().empty()) {
1456 Out << "\n";
1457 eolnOut = true;
1458 }
1459 VisitDeclContext(OID, false);
1460 if (!eolnOut)
1461 Out << "\n";
1462 Out << "@end";
1463}
1464
1465void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
1468
1470 Out << "@class " << I;
1471
1473 PrintObjCTypeParams(TypeParams);
1474 }
1475
1476 Out << ";";
1477 return;
1478 }
1479 bool eolnOut = false;
1481 prettyPrintAttributes(OID);
1482 Out << "\n";
1483 }
1484
1485 Out << "@interface " << I;
1486
1488 PrintObjCTypeParams(TypeParams);
1489 }
1490
1491 if (SID)
1493
1494
1496 if (!Protocols.empty()) {
1498 E = Protocols.end(); I != E; ++I)
1499 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1500 Out << "> ";
1501 }
1502
1504 Out << "{\n";
1505 eolnOut = true;
1507 for (const auto *I : OID->ivars()) {
1508 Indent() << I->getASTContext()
1509 .getUnqualifiedObjCPointerType(I->getType())
1510 .getAsString(Policy) << ' ' << *I << ";\n";
1511 }
1513 Out << "}\n";
1514 } else if (SID || !OID->decls().empty()) {
1515 Out << "\n";
1516 eolnOut = true;
1517 }
1518
1519 VisitDeclContext(OID, false);
1520 if (!eolnOut)
1521 Out << "\n";
1522 Out << "@end";
1523
1524}
1525
1526void DeclPrinter::VisitObjCProtocolDecl(ObjCProtocolDecl *PID) {
1528 Out << "@protocol " << *PID << ";\n";
1529 return;
1530 }
1531
1533 if (!Protocols.empty()) {
1534 Out << "@protocol " << *PID;
1536 E = Protocols.end(); I != E; ++I)
1537 Out << (I == Protocols.begin() ? '<' : ',') << **I;
1538 Out << ">\n";
1539 } else
1540 Out << "@protocol " << *PID << '\n';
1541 VisitDeclContext(PID, false);
1542 Out << "@end";
1543}
1544
1546 Out << "@implementation ";
1548 Out << *CID;
1549 else
1550 Out << "<>";
1551 Out << '(' << *PID << ")\n";
1552
1553 VisitDeclContext(PID, false);
1554 Out << "@end";
1555
1556}
1557
1558void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) {
1559 Out << "@interface ";
1561 Out << *CID;
1562 else
1563 Out << "<>";
1565 PrintObjCTypeParams(TypeParams);
1566 }
1567 Out << "(" << *PID << ")\n";
1568 if (PID->ivar_size() > 0) {
1569 Out << "{\n";
1571 for (const auto *I : PID->ivars())
1572 Indent() << I->getASTContext().getUnqualifiedObjCPointerType(I->getType()).
1573 getAsString(Policy) << ' ' << *I << ";\n";
1575 Out << "}\n";
1576 }
1577
1578 VisitDeclContext(PID, false);
1579 Out << "@end";
1580
1581
1582}
1583
1585 Out << "@compatibility_alias " << *AID
1587}
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
1600 Out << "@required\n";
1602 Out << "@optional\n";
1603
1605
1606 Out << "@property";
1608 bool first = true;
1609 Out << "(";
1611 Out << (first ? "" : ", ") << "class";
1612 first = false;
1613 }
1614
1616 Out << (first ? "" : ", ") << "direct";
1617 first = false;
1618 }
1619
1622 Out << (first ? "" : ", ") << "nonatomic";
1623 first = false;
1624 }
1626 Out << (first ? "" : ", ") << "atomic";
1627 first = false;
1628 }
1629
1631 Out << (first ? "" : ", ") << "assign";
1632 first = false;
1633 }
1635 Out << (first ? "" : ", ") << "retain";
1636 first = false;
1637 }
1638
1640 Out << (first ? "" : ", ") << "strong";
1641 first = false;
1642 }
1644 Out << (first ? "" : ", ") << "copy";
1645 first = false;
1646 }
1648 Out << (first ? "" : ", ") << "weak";
1649 first = false;
1650 }
1653 Out << (first ? "" : ", ") << "unsafe_unretained";
1654 first = false;
1655 }
1656
1659 Out << (first ? "" : ", ") << "readwrite";
1660 first = false;
1661 }
1663 Out << (first ? "" : ", ") << "readonly";
1664 first = false;
1665 }
1666
1668 Out << (first ? "" : ", ") << "getter = ";
1670 first = false;
1671 }
1673 Out << (first ? "" : ", ") << "setter = ";
1675 first = false;
1676 }
1677
1680 if (auto nullability = AttributedType::stripOuterNullability(T)) {
1684 Out << (first ? "" : ", ") << "null_resettable";
1685 } else {
1686 Out << (first ? "" : ", ")
1688 }
1689 first = false;
1690 }
1691 }
1692
1693 (void) first;
1694 Out << ")";
1695 }
1698 Out << ' ' << TypeStr;
1699 if (!StringRef(TypeStr).ends_with("*"))
1700 Out << ' ';
1701 Out << *PDecl;
1703 Out << ';';
1704}
1705
1708 Out << "@synthesize ";
1709 else
1710 Out << "@dynamic ";
1714}
1715
1716void DeclPrinter::VisitUsingDecl(UsingDecl *D) {
1718 Out << "using ";
1720 Out << "typename ";
1722
1723
1724
1725 for (const auto *Shadow : D->shadows()) {
1726 if (const auto *ConstructorShadow =
1727 dyn_cast(Shadow)) {
1728 assert(Shadow->getDeclContext() == ConstructorShadow->getDeclContext());
1729 Out << *ConstructorShadow->getNominatedBaseClass();
1730 return;
1731 }
1732 }
1733 Out << *D;
1734}
1735
1736void DeclPrinter::VisitUsingEnumDecl(UsingEnumDecl *D) {
1738}
1739
1740void
1742 Out << "using typename ";
1745}
1746
1749 Out << "using ";
1752}
1753
1754void DeclPrinter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1755
1756}
1757
1759 Out << "#pragma omp threadprivate";
1763 I != E; ++I) {
1767 }
1768 Out << ")";
1769 }
1770}
1771
1772void DeclPrinter::VisitHLSLBufferDecl(HLSLBufferDecl *D) {
1774 Out << "cbuffer ";
1775 else
1776 Out << "tbuffer ";
1777
1778 Out << *D;
1779
1780 prettyPrintAttributes(D);
1781
1782 Out << " {\n";
1783 VisitDeclContext(D);
1785}
1786
1787void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
1788 Out << "#pragma omp allocate";
1792 I != E; ++I) {
1796 }
1797 Out << ")";
1798 }
1802 Out << " ";
1803 Printer.Visit(C);
1804 }
1805 }
1806}
1807
1808void DeclPrinter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
1809 Out << "#pragma omp requires ";
1813 Printer.Visit(*I);
1814 }
1815}
1816
1819 Out << "#pragma omp declare reduction (";
1821 const char *OpName =
1823 assert(OpName && "not an overloaded operator");
1824 Out << OpName;
1825 } else {
1828 }
1829 Out << " : ";
1831 Out << " : ";
1833 Out << ")";
1835 Out << " initializer(";
1838 Out << "omp_priv(";
1839 break;
1841 Out << "omp_priv = ";
1842 break;
1844 break;
1845 }
1846 Init->printPretty(Out, nullptr, Policy, 0, "\n", &Context);
1848 Out << ")";
1849 Out << ")";
1850 }
1851 }
1852}
1853
1856 Out << "#pragma omp declare mapper (";
1858 Out << " : ";
1860 Out << " ";
1862 Out << ")";
1866 Out << " ";
1867 Printer.Visit(C);
1868 }
1869 }
1870 }
1871}
1872
1874 D->getInit()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context);
1875}
1876
1877void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) {
1879 TC->print(Out, Policy);
1881 Out << "typename";
1882 else
1883 Out << "class";
1884
1886 Out << " ...";
1888 Out << ' ';
1889
1893 else
1895 }
1896
1898 Out << " = ";
1900 false);
1901 }
1902}
1903
1904void DeclPrinter::VisitNonTypeTemplateParmDecl(
1906 StringRef Name;
1908 Name =
1911
1913 Out << " = ";
1915 false);
1916 }
1917}
1918
1919void DeclPrinter::VisitTemplateTemplateParmDecl(
1921 VisitTemplateDecl(TTPD);
1923 Out << " = ";
1925 false);
1926 }
1927}
1928
1931 Out << "#pragma acc declare";
1932 if (!D->clauses().empty()) {
1933 Out << ' ';
1935 Printer.VisitClauseList(D->clauses());
1936 }
1937 }
1938}
1941 Out << "#pragma acc routine";
1942
1943 Out << "(";
1944
1945
1946
1949 "\n", &Context);
1950 else
1951 Out << "";
1952
1953 Out << ")";
1954
1955 if (!D->clauses().empty()) {
1956 Out << ' ';
1958 Printer.VisitClauseList(D->clauses());
1959 }
1960 }
1961}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
static DeclPrinter::AttrPosAsWritten getPosAsWritten(const Attr *A, const Decl *D)
Definition DeclPrinter.cpp:241
static QualType getDeclType(Decl *D)
Definition DeclPrinter.cpp:189
static QualType GetBaseType(QualType T)
Definition DeclPrinter.cpp:159
static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, PrintingPolicy &Policy, unsigned Indentation, const ASTContext &Context)
Definition DeclPrinter.cpp:648
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
FormatToken * Next
The next token in the unwrapped line.
Defines the clang::Module class, which describes a module in the source code.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
const clang::PrintingPolicy & getPrintingPolicy() const
QualType getUnqualifiedObjCPointerType(QualType type) const
getUnqualifiedObjCPointerType - Returns version of Objective-C pointer type with lifetime qualifier r...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Attr - This represents one attribute.
SourceLocation getLoc() const
shadow_range shadows() const
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
Represents a C++ conversion function within a class.
Represents a C++ deduction guide declaration.
TemplateDecl * getDeducedTemplate() const
Get the template for which this guide performs deduction.
Represents a C++ struct/union/class.
CXXBaseSpecifier * base_class_iterator
Iterator that traverses the base classes of a class.
bool isLambda() const
Determine whether this class describes a lambda function object.
CXXMethodDecl * getLambdaCallOperator() const
Retrieve the lambda call operator of the closure type if this is a closure type.
Declaration of a class template.
bool isThisDeclarationADefinition() const
Returns whether this template declaration defines the primary class pattern.
spec_range specializations() const
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
decl_iterator - Iterates through the declarations stored within this context.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isTranslationUnit() const
DeclContext(Decl::Kind K)
void dumpDeclContext() const
Definition DeclPrinter.cpp:224
decl_iterator decls_end() const
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
decl_iterator decls_begin() const
A simple visitor class that helps create declaration visitors.
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
ObjCDeclQualifier
ObjCDeclQualifier - 'Qualifiers' written next to the return and parameter types in method declaration...
@ OBJC_TQ_CSNullability
The nullability qualifier is set when the nullability of the result or parameter was expressed via a ...
bool isInvalidDecl() const
SourceLocation getLocation() const
static void printGroup(Decl **Begin, unsigned NumDecls, raw_ostream &Out, const PrintingPolicy &Policy, unsigned Indentation=0)
Definition DeclPrinter.cpp:197
AccessSpecifier getAccess() const
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
Definition DeclPrinter.cpp:135
std::string getAsString() const
Retrieve the human-readable string for this name.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
NameKind getNameKind() const
Determine what kind of name this is.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
TemplateParameterList * getTemplateParameterList(unsigned index) const
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
unsigned getNumTemplateParameterLists() const
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
TypeSourceInfo * getTypeSourceInfo() const
Represents an empty-declaration.
An instance of this object exists for each enum constant that is defined.
const Expr * getInitExpr() const
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
bool isScopedUsingClassTag() const
Returns true if this is a C++11 scoped enumeration.
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
Store information needed for an explicit specifier.
const Expr * getExpr() const
static ExplicitSpecifier getFromDecl(FunctionDecl *Function)
bool isSpecified() const
Determine if the declaration had an explicit specifier of any kind.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
This represents one expression.
Represents a member of a struct/union/class.
bool isMutable() const
Determines whether this field is mutable (C++ only).
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
bool isBitField() const
Determines whether this field is a bitfield.
InClassInitStyle getInClassInitStyle() const
Get the kind of (C++11) default member initializer that this field has.
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
const Expr * getAsmStringExpr() const
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
unsigned getFriendTypeNumTemplateParameterLists() const
TemplateParameterList * getFriendTypeTemplateParameterList(unsigned N) const
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
bool isPackExpansion() const
Represents a function declaration or definition.
const ParmVarDecl * getParamDecl(unsigned i) const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
bool isImmediateFunction() const
StringLiteral * getDeletedMessage() const
Get the message that indicates why this function was deleted.
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
bool hasWrittenPrototype() const
Whether this function has a written prototype.
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
bool isConstexprSpecified() const
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isDeletedAsWritten() const
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
bool isVirtualAsWritten() const
Whether this function is marked as virtual explicitly.
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
DeclarationNameInfo getNameInfo() const
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Represents a prototype with parameter type info, e.g.
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
unsigned getNumExceptions() const
Return the number of types in the exception specification.
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
bool isVariadic() const
Whether this function prototype is variadic.
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Declaration of a template function.
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
spec_range specializations() const
FunctionType - C99 6.7.5.3 - Function Declarators.
HLSLBufferDecl - Represent a cbuffer or tbuffer declaration.
One of these records is kept for each identifier that is lexed.
StringRef deuglifiedName() const
If the identifier is an "uglified" reserved name, return a cleaned form.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Represents the declaration of a label.
Represents a linkage specification.
LinkageSpecLanguageIDs getLanguage() const
Return the language specified by this linkage specification.
bool hasBraces() const
Determines whether this linkage specification had braces in its syntactic form.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
This represents a decl that may have a name.
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
std::string getQualifiedNameAsString() const
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...
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...
virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const
Pretty-print the unqualified name of this declaration.
Represents a C++ namespace alias.
NamespaceBaseDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Represent a C++ namespace.
bool isInline() const
Returns true if this is an inline namespace declaration.
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool ResolveTemplateArguments=false, bool PrintFinalScopeResOp=true) const
Print this nested name specifier to the given output stream.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool isParameterPack() const
Whether this parameter is a non-type template parameter pack.
This represents 'pragma omp allocate ...' directive.
bool varlist_empty() const
bool clauselist_empty() const
varlist_iterator varlist_begin()
MutableArrayRef< Expr * >::iterator varlist_iterator
clauselist_range clauselists()
varlist_iterator varlist_end()
Pseudo declaration for capturing expressions.
This is a basic class for representing single OpenMP clause.
This represents 'pragma omp declare mapper ...' directive.
clauselist_range clauselists()
DeclarationName getVarName()
Get the name of the variable declared in the mapper.
bool clauselist_empty() const
This represents 'pragma omp declare reduction ...' directive.
Expr * getInitializer()
Get initializer expression (if specified) of the declare reduction construct.
Expr * getCombiner()
Get combiner expression of the declare reduction construct.
OMPDeclareReductionInitKind getInitializerKind() const
Get initializer kind.
This represents 'pragma omp requires...' directive.
clauselist_iterator clauselist_begin()
bool clauselist_empty() const
clauselist_iterator clauselist_end()
This represents 'pragma omp threadprivate ...' directive.
MutableArrayRef< Expr * >::iterator varlist_iterator
bool varlist_empty() const
varlist_iterator varlist_end()
varlist_iterator varlist_begin()
ObjCCategoryDecl - Represents a category declaration.
ObjCInterfaceDecl * getClassInterface()
ObjCTypeParamList * getTypeParamList() const
Retrieve the type parameter list associated with this category or extension.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
ObjCCompatibleAliasDecl - Represents alias of a class.
const ObjCInterfaceDecl * getClassInterface() const
const ObjCInterfaceDecl * getClassInterface() const
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
std::string getNameAsString() const
Get the name of the class associated with this interface.
unsigned ivar_size() const
const ObjCInterfaceDecl * getSuperClass() const
Represents an ObjC class declaration.
unsigned ivar_size() const
ObjCTypeParamList * getTypeParamListAsWritten() const
Retrieve the type parameters written on this particular declaration of the class.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
const ObjCProtocolList & getReferencedProtocols() const
const ObjCObjectType * getSuperClassType() const
Retrieve the superclass type.
ObjCInterfaceDecl * getSuperClass() const
ObjCList - This is a simple template class used to hold various lists of decls etc,...
ObjCMethodDecl - Represents an instance or class method declaration.
ObjCDeclQualifier getObjCDeclQualifier() const
ArrayRef< ParmVarDecl * > parameters() const
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Selector getSelector() const
bool isInstanceMethod() const
QualType getReturnType() const
Represents a pointer to an Objective C object.
Represents one property declaration in an Objective-C interface.
Selector getSetterName() const
Selector getGetterName() const
ObjCPropertyAttribute::Kind getPropertyAttributes() const
PropertyControl getPropertyImplementation() const
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
ObjCIvarDecl * getPropertyIvarDecl() const
Kind getPropertyImplementation() const
ObjCPropertyDecl * getPropertyDecl() const
Represents an Objective-C protocol declaration.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
const ObjCProtocolList & getReferencedProtocols() const
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
ArrayRef< const OpenACCClause * > clauses() const
const Expr * getFunctionReference() const
Sugar for parentheses used when specifying types.
Represents a parameter to a function.
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Represents a struct/union/class.
Base for LValueReferenceType and RValueReferenceType.
std::string getAsString() const
Derive the full selector name (e.g.
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
Encodes a location in the source.
Represents a C++11 static_assert declaration.
void printPretty(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
void printPrettyControlled(raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const
StringLiteral - This represents a string literal expression, e.g.
StringRef getKindName() const
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
A template argument list.
const TemplateArgument & getArgument() const
void print(const PrintingPolicy &Policy, raw_ostream &Out, bool IncludeType) const
Print this template argument to the given output stream.
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Stores a list of template parameters for a TemplateDecl and its derived classes.
NamedDecl * getParam(unsigned Idx)
void print(raw_ostream &Out, const ASTContext &Context, bool OmitTemplateKW=false) const
static bool shouldIncludeTypeForArgument(const PrintingPolicy &Policy, const TemplateParameterList *TPL, unsigned Idx)
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
Declaration of a template type parameter.
bool wasDeclaredWithTypename() const
Whether this template type parameter was declared with the 'typename' keyword.
const TemplateArgumentLoc & getDefaultArgument() const
Retrieve the default argument, if any.
const TypeConstraint * getTypeConstraint() const
Returns the type constraint associated with this template parameter (if any).
bool hasDefaultArgument() const
Determine whether this template parameter has a default argument.
bool defaultArgumentWasInherited() const
Determines whether the default argument was inherited from a previous declaration of this template.
bool isParameterPack() const
Returns whether this is a parameter pack.
A declaration that models statements at global scope.
The top declaration context.
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
A container of type source information.
QualType getType() const
Return the type wrapped by this type source info.
const T * getAs() const
Member-template getAs'.
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Base class for declarations which introduce a typedef-name.
TypeSourceInfo * getTypeSourceInfo() const
Represents a dependent using declaration which was marked with typename.
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Represents a dependent using declaration which was not marked with typename.
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Represents a C++ using-declaration.
bool hasTypename() const
Return true if the using declaration has 'typename'.
bool isAccessDeclaration() const
Return true if it is a C++03 access declaration (no 'using').
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name.
Represents C++ using-directive.
NamedDecl * getNominatedNamespaceAsWritten()
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of the namespace.
Represents a C++ using-enum-declaration.
EnumDecl * getEnumDecl() const
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
InitializationStyle getInitStyle() const
The style of initialization for this declaration.
static const char * getStorageClassSpecifierString(StorageClass SC)
Return the string used to specify the storage class SC.
@ CInit
C-style initialization with assignment.
@ CallInit
Call-style initialization (C++98)
bool isCXXForRangeDecl() const
Determine whether this variable is the for-range-declaration in a C++0x for-range statement.
ThreadStorageClassSpecifier getTSCSpec() const
const Expr * getInit() const
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Represents a GCC generic vector type.
@ kind_nullability
Indicates that the nullability of the type was spelled with a property attribute rather than a type q...
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr, CxxCtorInitializer, and TypeLoc) selects th...
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
llvm::StringRef getAccessSpelling(AccessSpecifier AS)
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
@ ICIS_ListInit
Direct list-initialization.
@ RQ_None
No ref-qualifier was provided.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
SmallVector< Attr *, 4 > AttrVec
AttrVec - A vector of Attr, which is how they are stored on the AST.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
StorageClass
Storage classes.
@ TSCS_thread_local
C++11 thread_local.
@ TSCS__Thread_local
C11 _Thread_local.
@ TSCS___thread
GNU __thread.
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
llvm::StringRef getNullabilitySpelling(NullabilityKind kind, bool isContextSensitive=false)
Retrieve the spelling of the given nullability kind.
const FunctionProtoType * T
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
@ Concept
The name was classified as a concept name.
llvm::StringRef getAsString(SyncScope S)
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
@ Invariant
The parameter is invariant: must match exactly.
@ Contravariant
The parameter is contravariant, e.g., X is a subtype of X when the type parameter is covariant and...
@ Covariant
The parameter is covariant, e.g., X is a subtype of X when the type parameter is covariant and T i...
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
U cast(CodeGen::Address addr)
@ EST_MSAny
Microsoft throw(...) extension.
Represents an explicit template argument list in C++, e.g., the "" in "sort".
ArrayRef< TemplateArgumentLoc > arguments() const
void printName(raw_ostream &OS, PrintingPolicy Policy) const
printName - Print the human-readable name to a stream.
Describes how types, statements, expressions, and declarations should be printed.
unsigned FullyQualifiedName
When true, print the fully qualified name of function declarations.
unsigned PolishForDeclaration
When true, do certain refinement needed for producing proper declaration tag; such as,...
unsigned CleanUglifiedParameters
Whether to strip underscores when printing reserved parameter names.
unsigned SuppressSpecifiers
Whether we should suppress printing of the actual specifiers for the given type or declaration.
unsigned SuppressScope
Suppresses printing of scope specifiers.
unsigned Indentation
The number of spaces to use to indent each line.
unsigned SuppressInitializers
Suppress printing of variable initializers.
unsigned TerseOutput
Provide a 'terse' output.
unsigned PrintAsCanonical
Whether to print entities as written or canonically.