Mercurial > hg > CbC > CbC_llvm
comparison clang/lib/AST/DeclPrinter.cpp @ 207:2e18cbf3894f
LLVM12
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 08 Jun 2021 06:07:14 +0900 |
parents | 0572611fdcc8 |
children | 5f17cb93ff66 |
comparison
equal
deleted
inserted
replaced
173:0572611fdcc8 | 207:2e18cbf3894f |
---|---|
108 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP); | 108 void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP); |
109 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP); | 109 void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP); |
110 | 110 |
111 void printTemplateParameters(const TemplateParameterList *Params, | 111 void printTemplateParameters(const TemplateParameterList *Params, |
112 bool OmitTemplateKW = false); | 112 bool OmitTemplateKW = false); |
113 void printTemplateArguments(llvm::ArrayRef<TemplateArgument> Args); | 113 void printTemplateArguments(llvm::ArrayRef<TemplateArgument> Args, |
114 void printTemplateArguments(llvm::ArrayRef<TemplateArgumentLoc> Args); | 114 const TemplateParameterList *Params, |
115 bool TemplOverloaded); | |
116 void printTemplateArguments(llvm::ArrayRef<TemplateArgumentLoc> Args, | |
117 const TemplateParameterList *Params, | |
118 bool TemplOverloaded); | |
115 void prettyPrintAttributes(Decl *D); | 119 void prettyPrintAttributes(Decl *D); |
116 void prettyPrintPragmas(Decl *D); | 120 void prettyPrintPragmas(Decl *D); |
117 void printDeclType(QualType T, StringRef DeclName, bool Pack = false); | 121 void printDeclType(QualType T, StringRef DeclName, bool Pack = false); |
118 }; | 122 }; |
119 } | 123 } |
287 Decls.clear(); | 291 Decls.clear(); |
288 | 292 |
289 } | 293 } |
290 | 294 |
291 void DeclPrinter::Print(AccessSpecifier AS) { | 295 void DeclPrinter::Print(AccessSpecifier AS) { |
292 switch(AS) { | 296 const auto AccessSpelling = getAccessSpelling(AS); |
293 case AS_none: llvm_unreachable("No access specifier!"); | 297 if (AccessSpelling.empty()) |
294 case AS_public: Out << "public"; break; | 298 llvm_unreachable("No access specifier!"); |
295 case AS_protected: Out << "protected"; break; | 299 Out << AccessSpelling; |
296 case AS_private: Out << "private"; break; | |
297 } | |
298 } | 300 } |
299 | 301 |
300 void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl, | 302 void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl, |
301 std::string &Proto) { | 303 std::string &Proto) { |
302 bool HasInitializerList = false; | 304 bool HasInitializerList = false; |
341 NumArgs = Construct->getNumArgs(); | 343 NumArgs = Construct->getNumArgs(); |
342 } else | 344 } else |
343 SimpleInit = Init; | 345 SimpleInit = Init; |
344 | 346 |
345 if (SimpleInit) | 347 if (SimpleInit) |
346 SimpleInit->printPretty(Out, nullptr, Policy, Indentation); | 348 SimpleInit->printPretty(Out, nullptr, Policy, Indentation, "\n", |
349 &Context); | |
347 else { | 350 else { |
348 for (unsigned I = 0; I != NumArgs; ++I) { | 351 for (unsigned I = 0; I != NumArgs; ++I) { |
349 assert(Args[I] != nullptr && "Expected non-null Expr"); | 352 assert(Args[I] != nullptr && "Expected non-null Expr"); |
350 if (isa<CXXDefaultArgExpr>(Args[I])) | 353 if (isa<CXXDefaultArgExpr>(Args[I])) |
351 break; | 354 break; |
352 | 355 |
353 if (I) | 356 if (I) |
354 Out << ", "; | 357 Out << ", "; |
355 Args[I]->printPretty(Out, nullptr, Policy, Indentation); | 358 Args[I]->printPretty(Out, nullptr, Policy, Indentation, "\n", |
359 &Context); | |
356 } | 360 } |
357 } | 361 } |
358 } | 362 } |
359 Out << ")"; | 363 Out << ")"; |
360 if (BMInitializer->isPackExpansion()) | 364 if (BMInitializer->isPackExpansion()) |
528 Out << " struct"; | 532 Out << " struct"; |
529 } | 533 } |
530 | 534 |
531 prettyPrintAttributes(D); | 535 prettyPrintAttributes(D); |
532 | 536 |
533 Out << ' ' << *D; | 537 if (D->getDeclName()) |
538 Out << ' ' << D->getDeclName(); | |
534 | 539 |
535 if (D->isFixed()) | 540 if (D->isFixed()) |
536 Out << " : " << D->getIntegerType().stream(Policy); | 541 Out << " : " << D->getIntegerType().stream(Policy); |
537 | 542 |
538 if (D->isCompleteDefinition()) { | 543 if (D->isCompleteDefinition()) { |
567 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); | 572 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); |
568 } | 573 } |
569 } | 574 } |
570 | 575 |
571 static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, | 576 static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, |
572 PrintingPolicy &Policy, | 577 PrintingPolicy &Policy, unsigned Indentation, |
573 unsigned Indentation) { | 578 const ASTContext &Context) { |
574 std::string Proto = "explicit"; | 579 std::string Proto = "explicit"; |
575 llvm::raw_string_ostream EOut(Proto); | 580 llvm::raw_string_ostream EOut(Proto); |
576 if (ES.getExpr()) { | 581 if (ES.getExpr()) { |
577 EOut << "("; | 582 EOut << "("; |
578 ES.getExpr()->printPretty(EOut, nullptr, Policy, Indentation); | 583 ES.getExpr()->printPretty(EOut, nullptr, Policy, Indentation, "\n", |
584 &Context); | |
579 EOut << ")"; | 585 EOut << ")"; |
580 } | 586 } |
581 EOut << " "; | 587 EOut << " "; |
582 EOut.flush(); | 588 EOut.flush(); |
583 Out << EOut.str(); | 589 Out << EOut.str(); |
615 if (D->isConstexprSpecified() && !D->isExplicitlyDefaulted()) | 621 if (D->isConstexprSpecified() && !D->isExplicitlyDefaulted()) |
616 Out << "constexpr "; | 622 Out << "constexpr "; |
617 if (D->isConsteval()) Out << "consteval "; | 623 if (D->isConsteval()) Out << "consteval "; |
618 ExplicitSpecifier ExplicitSpec = ExplicitSpecifier::getFromDecl(D); | 624 ExplicitSpecifier ExplicitSpec = ExplicitSpecifier::getFromDecl(D); |
619 if (ExplicitSpec.isSpecified()) | 625 if (ExplicitSpec.isSpecified()) |
620 printExplicitSpecifier(ExplicitSpec, Out, Policy, Indentation); | 626 printExplicitSpecifier(ExplicitSpec, Out, Policy, Indentation, Context); |
621 } | 627 } |
622 | 628 |
623 PrintingPolicy SubPolicy(Policy); | 629 PrintingPolicy SubPolicy(Policy); |
624 SubPolicy.SuppressSpecifiers = false; | 630 SubPolicy.SuppressSpecifiers = false; |
625 std::string Proto; | 631 std::string Proto; |
640 Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString(); | 646 Proto = GuideDecl->getDeducedTemplate()->getDeclName().getAsString(); |
641 if (D->isFunctionTemplateSpecialization()) { | 647 if (D->isFunctionTemplateSpecialization()) { |
642 llvm::raw_string_ostream POut(Proto); | 648 llvm::raw_string_ostream POut(Proto); |
643 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation); | 649 DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation); |
644 const auto *TArgAsWritten = D->getTemplateSpecializationArgsAsWritten(); | 650 const auto *TArgAsWritten = D->getTemplateSpecializationArgsAsWritten(); |
651 const TemplateParameterList *TPL = D->getTemplateSpecializationInfo() | |
652 ->getTemplate() | |
653 ->getTemplateParameters(); | |
645 if (TArgAsWritten && !Policy.PrintCanonicalTypes) | 654 if (TArgAsWritten && !Policy.PrintCanonicalTypes) |
646 TArgPrinter.printTemplateArguments(TArgAsWritten->arguments()); | 655 TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(), TPL, |
656 /*TemplOverloaded*/ true); | |
647 else if (const TemplateArgumentList *TArgs = | 657 else if (const TemplateArgumentList *TArgs = |
648 D->getTemplateSpecializationArgs()) | 658 D->getTemplateSpecializationArgs()) |
649 TArgPrinter.printTemplateArguments(TArgs->asArray()); | 659 TArgPrinter.printTemplateArguments(TArgs->asArray(), TPL, |
660 /*TemplOverloaded*/ true); | |
650 } | 661 } |
651 | 662 |
652 QualType Ty = D->getType(); | 663 QualType Ty = D->getType(); |
653 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) { | 664 while (const ParenType *PT = dyn_cast<ParenType>(Ty)) { |
654 Proto = '(' + Proto + ')'; | 665 Proto = '(' + Proto + ')'; |
719 Proto += " noexcept"; | 730 Proto += " noexcept"; |
720 if (isComputedNoexcept(FT->getExceptionSpecType())) { | 731 if (isComputedNoexcept(FT->getExceptionSpecType())) { |
721 Proto += "("; | 732 Proto += "("; |
722 llvm::raw_string_ostream EOut(Proto); | 733 llvm::raw_string_ostream EOut(Proto); |
723 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy, | 734 FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy, |
724 Indentation); | 735 Indentation, "\n", &Context); |
725 EOut.flush(); | 736 EOut.flush(); |
726 Proto += EOut.str(); | 737 Proto += EOut.str(); |
727 Proto += ")"; | 738 Proto += ")"; |
728 } | 739 } |
729 } | 740 } |
743 } | 754 } |
744 Out << Proto; | 755 Out << Proto; |
745 | 756 |
746 if (Expr *TrailingRequiresClause = D->getTrailingRequiresClause()) { | 757 if (Expr *TrailingRequiresClause = D->getTrailingRequiresClause()) { |
747 Out << " requires "; | 758 Out << " requires "; |
748 TrailingRequiresClause->printPretty(Out, nullptr, SubPolicy, Indentation); | 759 TrailingRequiresClause->printPretty(Out, nullptr, SubPolicy, Indentation, |
760 "\n", &Context); | |
749 } | 761 } |
750 } else { | 762 } else { |
751 Ty.print(Out, Policy, Proto); | 763 Ty.print(Out, Policy, Proto); |
752 } | 764 } |
753 | 765 |
775 Indentation -= Policy.Indentation; | 787 Indentation -= Policy.Indentation; |
776 } else | 788 } else |
777 Out << ' '; | 789 Out << ' '; |
778 | 790 |
779 if (D->getBody()) | 791 if (D->getBody()) |
780 D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation); | 792 D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation, "\n", |
793 &Context); | |
781 } else { | 794 } else { |
782 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D)) | 795 if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D)) |
783 Out << " {}"; | 796 Out << " {}"; |
784 } | 797 } |
785 } | 798 } |
820 Out << D->getASTContext().getUnqualifiedObjCPointerType(D->getType()). | 833 Out << D->getASTContext().getUnqualifiedObjCPointerType(D->getType()). |
821 stream(Policy, D->getName(), Indentation); | 834 stream(Policy, D->getName(), Indentation); |
822 | 835 |
823 if (D->isBitField()) { | 836 if (D->isBitField()) { |
824 Out << " : "; | 837 Out << " : "; |
825 D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation); | 838 D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation, "\n", |
839 &Context); | |
826 } | 840 } |
827 | 841 |
828 Expr *Init = D->getInClassInitializer(); | 842 Expr *Init = D->getInClassInitializer(); |
829 if (!Policy.SuppressInitializers && Init) { | 843 if (!Policy.SuppressInitializers && Init) { |
830 if (D->getInClassInitStyle() == ICIS_ListInit) | 844 if (D->getInClassInitStyle() == ICIS_ListInit) |
831 Out << " "; | 845 Out << " "; |
832 else | 846 else |
833 Out << " = "; | 847 Out << " = "; |
834 Init->printPretty(Out, nullptr, Policy, Indentation); | 848 Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); |
835 } | 849 } |
836 prettyPrintAttributes(D); | 850 prettyPrintAttributes(D); |
837 } | 851 } |
838 | 852 |
839 void DeclPrinter::VisitLabelDecl(LabelDecl *D) { | 853 void DeclPrinter::VisitLabelDecl(LabelDecl *D) { |
894 Out << " = "; | 908 Out << " = "; |
895 } | 909 } |
896 PrintingPolicy SubPolicy(Policy); | 910 PrintingPolicy SubPolicy(Policy); |
897 SubPolicy.SuppressSpecifiers = false; | 911 SubPolicy.SuppressSpecifiers = false; |
898 SubPolicy.IncludeTagDefinition = false; | 912 SubPolicy.IncludeTagDefinition = false; |
899 Init->printPretty(Out, nullptr, SubPolicy, Indentation); | 913 Init->printPretty(Out, nullptr, SubPolicy, Indentation, "\n", &Context); |
900 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init)) | 914 if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init)) |
901 Out << ")"; | 915 Out << ")"; |
902 } | 916 } |
903 } | 917 } |
904 prettyPrintAttributes(D); | 918 prettyPrintAttributes(D); |
908 VisitVarDecl(D); | 922 VisitVarDecl(D); |
909 } | 923 } |
910 | 924 |
911 void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { | 925 void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
912 Out << "__asm ("; | 926 Out << "__asm ("; |
913 D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation); | 927 D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation, "\n", |
928 &Context); | |
914 Out << ")"; | 929 Out << ")"; |
915 } | 930 } |
916 | 931 |
917 void DeclPrinter::VisitImportDecl(ImportDecl *D) { | 932 void DeclPrinter::VisitImportDecl(ImportDecl *D) { |
918 Out << "@import " << D->getImportedModule()->getFullModuleName() | 933 Out << "@import " << D->getImportedModule()->getFullModuleName() |
919 << ";\n"; | 934 << ";\n"; |
920 } | 935 } |
921 | 936 |
922 void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) { | 937 void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
923 Out << "static_assert("; | 938 Out << "static_assert("; |
924 D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation); | 939 D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation, "\n", |
940 &Context); | |
925 if (StringLiteral *SL = D->getMessage()) { | 941 if (StringLiteral *SL = D->getMessage()) { |
926 Out << ", "; | 942 Out << ", "; |
927 SL->printPretty(Out, nullptr, Policy, Indentation); | 943 SL->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); |
928 } | 944 } |
929 Out << ")"; | 945 Out << ")"; |
930 } | 946 } |
931 | 947 |
932 //---------------------------------------------------------------------------- | 948 //---------------------------------------------------------------------------- |
933 // C++ declarations | 949 // C++ declarations |
934 //---------------------------------------------------------------------------- | 950 //---------------------------------------------------------------------------- |
935 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) { | 951 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) { |
936 if (D->isInline()) | 952 if (D->isInline()) |
937 Out << "inline "; | 953 Out << "inline "; |
938 Out << "namespace " << *D << " {\n"; | 954 |
955 Out << "namespace "; | |
956 if (D->getDeclName()) | |
957 Out << D->getDeclName() << ' '; | |
958 Out << "{\n"; | |
959 | |
939 VisitDeclContext(D); | 960 VisitDeclContext(D); |
940 Indent() << "}"; | 961 Indent() << "}"; |
941 } | 962 } |
942 | 963 |
943 void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | 964 void DeclPrinter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
974 if (!Policy.PrintCanonicalTypes) | 995 if (!Policy.PrintCanonicalTypes) |
975 if (const auto* TSI = S->getTypeAsWritten()) | 996 if (const auto* TSI = S->getTypeAsWritten()) |
976 if (const auto *TST = | 997 if (const auto *TST = |
977 dyn_cast<TemplateSpecializationType>(TSI->getType())) | 998 dyn_cast<TemplateSpecializationType>(TSI->getType())) |
978 Args = TST->template_arguments(); | 999 Args = TST->template_arguments(); |
979 printTemplateArguments(Args); | 1000 printTemplateArguments( |
1001 Args, S->getSpecializedTemplate()->getTemplateParameters(), | |
1002 /*TemplOverloaded*/ false); | |
980 } | 1003 } |
981 } | 1004 } |
982 | 1005 |
983 if (D->isCompleteDefinition()) { | 1006 if (D->isCompleteDefinition()) { |
984 // Print the base classes | 1007 // Print the base classes |
1066 Out << '>'; | 1089 Out << '>'; |
1067 if (!OmitTemplateKW) | 1090 if (!OmitTemplateKW) |
1068 Out << ' '; | 1091 Out << ' '; |
1069 } | 1092 } |
1070 | 1093 |
1071 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args) { | 1094 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args, |
1095 const TemplateParameterList *Params, | |
1096 bool TemplOverloaded) { | |
1072 Out << "<"; | 1097 Out << "<"; |
1073 for (size_t I = 0, E = Args.size(); I < E; ++I) { | 1098 for (size_t I = 0, E = Args.size(); I < E; ++I) { |
1074 if (I) | 1099 if (I) |
1075 Out << ", "; | 1100 Out << ", "; |
1076 Args[I].print(Policy, Out); | 1101 if (TemplOverloaded || !Params) |
1102 Args[I].print(Policy, Out, /*IncludeType*/ true); | |
1103 else | |
1104 Args[I].print( | |
1105 Policy, Out, | |
1106 TemplateParameterList::shouldIncludeTypeForArgument(Params, I)); | |
1077 } | 1107 } |
1078 Out << ">"; | 1108 Out << ">"; |
1079 } | 1109 } |
1080 | 1110 |
1081 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args) { | 1111 void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
1112 const TemplateParameterList *Params, | |
1113 bool TemplOverloaded) { | |
1082 Out << "<"; | 1114 Out << "<"; |
1083 for (size_t I = 0, E = Args.size(); I < E; ++I) { | 1115 for (size_t I = 0, E = Args.size(); I < E; ++I) { |
1084 if (I) | 1116 if (I) |
1085 Out << ", "; | 1117 Out << ", "; |
1086 Args[I].getArgument().print(Policy, Out); | 1118 if (TemplOverloaded) |
1119 Args[I].getArgument().print(Policy, Out, /*IncludeType*/ true); | |
1120 else | |
1121 Args[I].getArgument().print( | |
1122 Policy, Out, | |
1123 TemplateParameterList::shouldIncludeTypeForArgument(Params, I)); | |
1087 } | 1124 } |
1088 Out << ">"; | 1125 Out << ">"; |
1089 } | 1126 } |
1090 | 1127 |
1091 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { | 1128 void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { |
1092 printTemplateParameters(D->getTemplateParameters()); | 1129 printTemplateParameters(D->getTemplateParameters()); |
1093 | 1130 |
1094 if (const TemplateTemplateParmDecl *TTP = | 1131 if (const TemplateTemplateParmDecl *TTP = |
1095 dyn_cast<TemplateTemplateParmDecl>(D)) { | 1132 dyn_cast<TemplateTemplateParmDecl>(D)) { |
1096 Out << "class "; | 1133 Out << "class"; |
1134 | |
1097 if (TTP->isParameterPack()) | 1135 if (TTP->isParameterPack()) |
1098 Out << "..."; | 1136 Out << " ..."; |
1099 Out << D->getName(); | 1137 else if (TTP->getDeclName()) |
1138 Out << ' '; | |
1139 | |
1140 if (TTP->getDeclName()) | |
1141 Out << TTP->getDeclName(); | |
1100 } else if (auto *TD = D->getTemplatedDecl()) | 1142 } else if (auto *TD = D->getTemplatedDecl()) |
1101 Visit(TD); | 1143 Visit(TD); |
1102 else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) { | 1144 else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) { |
1103 Out << "concept " << Concept->getName() << " = " ; | 1145 Out << "concept " << Concept->getName() << " = " ; |
1104 Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, | 1146 Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, Indentation, |
1105 Indentation); | 1147 "\n", &Context); |
1106 Out << ";"; | 1148 Out << ";"; |
1107 } | 1149 } |
1108 } | 1150 } |
1109 | 1151 |
1110 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | 1152 void DeclPrinter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
1216 case ObjCTypeParamVariance::Contravariant: | 1258 case ObjCTypeParamVariance::Contravariant: |
1217 Out << "__contravariant "; | 1259 Out << "__contravariant "; |
1218 break; | 1260 break; |
1219 } | 1261 } |
1220 | 1262 |
1221 Out << Param->getDeclName().getAsString(); | 1263 Out << Param->getDeclName(); |
1222 | 1264 |
1223 if (Param->hasExplicitBound()) { | 1265 if (Param->hasExplicitBound()) { |
1224 Out << " : " << Param->getUnderlyingType().getAsString(Policy); | 1266 Out << " : " << Param->getUnderlyingType().getAsString(Policy); |
1225 } | 1267 } |
1226 } | 1268 } |
1260 | 1302 |
1261 prettyPrintAttributes(OMD); | 1303 prettyPrintAttributes(OMD); |
1262 | 1304 |
1263 if (OMD->getBody() && !Policy.TerseOutput) { | 1305 if (OMD->getBody() && !Policy.TerseOutput) { |
1264 Out << ' '; | 1306 Out << ' '; |
1265 OMD->getBody()->printPretty(Out, nullptr, Policy); | 1307 OMD->getBody()->printPretty(Out, nullptr, Policy, Indentation, "\n", |
1308 &Context); | |
1266 } | 1309 } |
1267 else if (Policy.PolishForDeclaration) | 1310 else if (Policy.PolishForDeclaration) |
1268 Out << ';'; | 1311 Out << ';'; |
1269 } | 1312 } |
1270 | 1313 |
1374 VisitDeclContext(PID, false); | 1417 VisitDeclContext(PID, false); |
1375 Out << "@end"; | 1418 Out << "@end"; |
1376 } | 1419 } |
1377 | 1420 |
1378 void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { | 1421 void DeclPrinter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) { |
1379 Out << "@implementation " << *PID->getClassInterface() << '(' << *PID <<")\n"; | 1422 Out << "@implementation "; |
1423 if (const auto *CID = PID->getClassInterface()) | |
1424 Out << *CID; | |
1425 else | |
1426 Out << "<<error-type>>"; | |
1427 Out << '(' << *PID << ")\n"; | |
1380 | 1428 |
1381 VisitDeclContext(PID, false); | 1429 VisitDeclContext(PID, false); |
1382 Out << "@end"; | 1430 Out << "@end"; |
1383 // FIXME: implement the rest... | 1431 // FIXME: implement the rest... |
1384 } | 1432 } |
1385 | 1433 |
1386 void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) { | 1434 void DeclPrinter::VisitObjCCategoryDecl(ObjCCategoryDecl *PID) { |
1387 Out << "@interface " << *PID->getClassInterface(); | 1435 Out << "@interface "; |
1436 if (const auto *CID = PID->getClassInterface()) | |
1437 Out << *CID; | |
1438 else | |
1439 Out << "<<error-type>>"; | |
1388 if (auto TypeParams = PID->getTypeParamList()) { | 1440 if (auto TypeParams = PID->getTypeParamList()) { |
1389 PrintObjCTypeParams(TypeParams); | 1441 PrintObjCTypeParams(TypeParams); |
1390 } | 1442 } |
1391 Out << "(" << *PID << ")\n"; | 1443 Out << "(" << *PID << ")\n"; |
1392 if (PID->ivar_size() > 0) { | 1444 if (PID->ivar_size() > 0) { |
1631 D->printName(Out); | 1683 D->printName(Out); |
1632 } | 1684 } |
1633 Out << " : "; | 1685 Out << " : "; |
1634 D->getType().print(Out, Policy); | 1686 D->getType().print(Out, Policy); |
1635 Out << " : "; | 1687 Out << " : "; |
1636 D->getCombiner()->printPretty(Out, nullptr, Policy, 0); | 1688 D->getCombiner()->printPretty(Out, nullptr, Policy, 0, "\n", &Context); |
1637 Out << ")"; | 1689 Out << ")"; |
1638 if (auto *Init = D->getInitializer()) { | 1690 if (auto *Init = D->getInitializer()) { |
1639 Out << " initializer("; | 1691 Out << " initializer("; |
1640 switch (D->getInitializerKind()) { | 1692 switch (D->getInitializerKind()) { |
1641 case OMPDeclareReductionDecl::DirectInit: | 1693 case OMPDeclareReductionDecl::DirectInit: |
1645 Out << "omp_priv = "; | 1697 Out << "omp_priv = "; |
1646 break; | 1698 break; |
1647 case OMPDeclareReductionDecl::CallInit: | 1699 case OMPDeclareReductionDecl::CallInit: |
1648 break; | 1700 break; |
1649 } | 1701 } |
1650 Init->printPretty(Out, nullptr, Policy, 0); | 1702 Init->printPretty(Out, nullptr, Policy, 0, "\n", &Context); |
1651 if (D->getInitializerKind() == OMPDeclareReductionDecl::DirectInit) | 1703 if (D->getInitializerKind() == OMPDeclareReductionDecl::DirectInit) |
1652 Out << ")"; | 1704 Out << ")"; |
1653 Out << ")"; | 1705 Out << ")"; |
1654 } | 1706 } |
1655 } | 1707 } |
1673 } | 1725 } |
1674 } | 1726 } |
1675 } | 1727 } |
1676 | 1728 |
1677 void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { | 1729 void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { |
1678 D->getInit()->printPretty(Out, nullptr, Policy, Indentation); | 1730 D->getInit()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); |
1679 } | 1731 } |
1680 | 1732 |
1681 void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) { | 1733 void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) { |
1682 if (const TypeConstraint *TC = TTP->getTypeConstraint()) | 1734 if (const TypeConstraint *TC = TTP->getTypeConstraint()) |
1683 TC->print(Out, Policy); | 1735 TC->print(Out, Policy); |
1686 else | 1738 else |
1687 Out << "class"; | 1739 Out << "class"; |
1688 | 1740 |
1689 if (TTP->isParameterPack()) | 1741 if (TTP->isParameterPack()) |
1690 Out << " ..."; | 1742 Out << " ..."; |
1691 else if (!TTP->getName().empty()) | 1743 else if (TTP->getDeclName()) |
1692 Out << ' '; | 1744 Out << ' '; |
1693 | 1745 |
1694 Out << *TTP; | 1746 if (TTP->getDeclName()) |
1747 Out << TTP->getDeclName(); | |
1695 | 1748 |
1696 if (TTP->hasDefaultArgument()) { | 1749 if (TTP->hasDefaultArgument()) { |
1697 Out << " = "; | 1750 Out << " = "; |
1698 Out << TTP->getDefaultArgument().getAsString(Policy); | 1751 Out << TTP->getDefaultArgument().getAsString(Policy); |
1699 } | 1752 } |
1706 Name = II->getName(); | 1759 Name = II->getName(); |
1707 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack()); | 1760 printDeclType(NTTP->getType(), Name, NTTP->isParameterPack()); |
1708 | 1761 |
1709 if (NTTP->hasDefaultArgument()) { | 1762 if (NTTP->hasDefaultArgument()) { |
1710 Out << " = "; | 1763 Out << " = "; |
1711 NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy, Indentation); | 1764 NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy, Indentation, |
1712 } | 1765 "\n", &Context); |
1713 } | 1766 } |
1767 } |