diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/AST/DeclPrinter.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/AST/DeclPrinter.cpp | 390 |
1 files changed, 303 insertions, 87 deletions
diff --git a/contrib/llvm-project/clang/lib/AST/DeclPrinter.cpp b/contrib/llvm-project/clang/lib/AST/DeclPrinter.cpp index ca64f8f6cfbe..822ac12c4c7d 100644 --- a/contrib/llvm-project/clang/lib/AST/DeclPrinter.cpp +++ b/contrib/llvm-project/clang/lib/AST/DeclPrinter.cpp @@ -49,6 +49,18 @@ namespace { void PrintObjCTypeParams(ObjCTypeParamList *Params); + enum class AttrPrintLoc { + None = 0, + Left = 1, + Right = 2, + Any = Left | Right, + + LLVM_MARK_AS_BITMASK_ENUM(/*DefaultValue=*/Any) + }; + + void prettyPrintAttributes(Decl *D, raw_ostream &out, + AttrPrintLoc loc = AttrPrintLoc::Any); + public: DeclPrinter(raw_ostream &Out, const PrintingPolicy &Policy, const ASTContext &Context, unsigned Indentation = 0, @@ -72,6 +84,7 @@ namespace { void VisitLabelDecl(LabelDecl *D); void VisitParmVarDecl(ParmVarDecl *D); void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); + void VisitTopLevelStmtDecl(TopLevelStmtDecl *D); void VisitImportDecl(ImportDecl *D); void VisitStaticAssertDecl(StaticAssertDecl *D); void VisitNamespaceDecl(NamespaceDecl *D); @@ -98,6 +111,7 @@ namespace { void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); void VisitUsingDecl(UsingDecl *D); + void VisitUsingEnumDecl(UsingEnumDecl *D); void VisitUsingShadowDecl(UsingShadowDecl *D); void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); void VisitOMPAllocateDecl(OMPAllocateDecl *D); @@ -107,12 +121,19 @@ namespace { void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP); void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *NTTP); + void VisitHLSLBufferDecl(HLSLBufferDecl *D); void printTemplateParameters(const TemplateParameterList *Params, bool OmitTemplateKW = false); - void printTemplateArguments(llvm::ArrayRef<TemplateArgument> Args); - void printTemplateArguments(llvm::ArrayRef<TemplateArgumentLoc> Args); - void prettyPrintAttributes(Decl *D); + void printTemplateArguments(llvm::ArrayRef<TemplateArgument> Args, + const TemplateParameterList *Params); + void printTemplateArguments(llvm::ArrayRef<TemplateArgumentLoc> Args, + const TemplateParameterList *Params); + + inline void prettyPrintAttributes(Decl *D) { + prettyPrintAttributes(D, Out); + } + void prettyPrintPragmas(Decl *D); void printDeclType(QualType T, StringRef DeclName, bool Pack = false); }; @@ -148,11 +169,14 @@ static QualType GetBaseType(QualType T) { while (!BaseType->isSpecifierType()) { if (const PointerType *PTy = BaseType->getAs<PointerType>()) BaseType = PTy->getPointeeType(); + else if (const ObjCObjectPointerType *OPT = + BaseType->getAs<ObjCObjectPointerType>()) + BaseType = OPT->getPointeeType(); else if (const BlockPointerType *BPy = BaseType->getAs<BlockPointerType>()) BaseType = BPy->getPointeeType(); - else if (const ArrayType* ATy = dyn_cast<ArrayType>(BaseType)) + else if (const ArrayType *ATy = dyn_cast<ArrayType>(BaseType)) BaseType = ATy->getElementType(); - else if (const FunctionType* FTy = BaseType->getAs<FunctionType>()) + else if (const FunctionType *FTy = BaseType->getAs<FunctionType>()) BaseType = FTy->getReturnType(); else if (const VectorType *VTy = BaseType->getAs<VectorType>()) BaseType = VTy->getElementType(); @@ -226,7 +250,54 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) { return Out; } -void DeclPrinter::prettyPrintAttributes(Decl *D) { +// For CLANG_ATTR_LIST_CanPrintOnLeft macro. +#include "clang/Basic/AttrLeftSideCanPrintList.inc" + +// For CLANG_ATTR_LIST_PrintOnLeft macro. +#include "clang/Basic/AttrLeftSideMustPrintList.inc" + +static bool canPrintOnLeftSide(attr::Kind kind) { +#ifdef CLANG_ATTR_LIST_CanPrintOnLeft + switch (kind) { + CLANG_ATTR_LIST_CanPrintOnLeft + return true; + default: + return false; + } +#else + return false; +#endif +} + +static bool canPrintOnLeftSide(const Attr *A) { + if (A->isStandardAttributeSyntax()) + return false; + + return canPrintOnLeftSide(A->getKind()); +} + +static bool mustPrintOnLeftSide(attr::Kind kind) { +#ifdef CLANG_ATTR_LIST_PrintOnLeft + switch (kind) { + CLANG_ATTR_LIST_PrintOnLeft + return true; + default: + return false; + } +#else + return false; +#endif +} + +static bool mustPrintOnLeftSide(const Attr *A) { + if (A->isDeclspecAttribute()) + return true; + + return mustPrintOnLeftSide(A->getKind()); +} + +void DeclPrinter::prettyPrintAttributes(Decl *D, llvm::raw_ostream &Out, + AttrPrintLoc Loc) { if (Policy.PolishForDeclaration) return; @@ -235,15 +306,31 @@ void DeclPrinter::prettyPrintAttributes(Decl *D) { for (auto *A : Attrs) { if (A->isInherited() || A->isImplicit()) continue; - switch (A->getKind()) { -#define ATTR(X) -#define PRAGMA_SPELLING_ATTR(X) case attr::X: -#include "clang/Basic/AttrList.inc" - break; - default: - A->printPretty(Out, Policy); - break; + + AttrPrintLoc AttrLoc = AttrPrintLoc::Right; + if (mustPrintOnLeftSide(A)) { + // If we must always print on left side (e.g. declspec), then mark as + // so. + AttrLoc = AttrPrintLoc::Left; + } else if (canPrintOnLeftSide(A)) { + // For functions with body defined we print the attributes on the left + // side so that GCC accept our dumps as well. + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D); + FD && FD->isThisDeclarationADefinition()) + // In case Decl is a function with a body, then attrs should be print + // on the left side. + AttrLoc = AttrPrintLoc::Left; + + // In case it is a variable declaration with a ctor, then allow + // printing on the left side for readbility. + else if (const VarDecl *VD = dyn_cast<VarDecl>(D); + VD && VD->getInit() && + VD->getInitStyle() == VarDecl::CallInit) + AttrLoc = AttrPrintLoc::Left; } + // Only print the side matches the user requested. + if ((Loc & AttrLoc) != AttrPrintLoc::None) + A->printPretty(Out, Policy); } } } @@ -301,6 +388,8 @@ void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl, for (const auto *BMInitializer : CDecl->inits()) { if (BMInitializer->isInClassMemberInitializer()) continue; + if (!BMInitializer->isWritten()) + continue; if (!HasInitializerList) { Proto += " : "; @@ -313,15 +402,18 @@ void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl, if (BMInitializer->isAnyMemberInitializer()) { FieldDecl *FD = BMInitializer->getAnyMember(); Out << *FD; + } else if (BMInitializer->isDelegatingInitializer()) { + Out << CDecl->getNameAsString(); } else { Out << QualType(BMInitializer->getBaseClass(), 0).getAsString(Policy); } - Out << "("; - if (!BMInitializer->getInit()) { - // Nothing to print - } else { - Expr *Init = BMInitializer->getInit(); + if (Expr *Init = BMInitializer->getInit()) { + bool OutParens = !isa<InitListExpr>(Init); + + if (OutParens) + Out << "("; + if (ExprWithCleanups *Tmp = dyn_cast<ExprWithCleanups>(Init)) Init = Tmp->getSubExpr(); @@ -341,7 +433,8 @@ void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl, SimpleInit = Init; if (SimpleInit) - SimpleInit->printPretty(Out, nullptr, Policy, Indentation); + SimpleInit->printPretty(Out, nullptr, Policy, Indentation, "\n", + &Context); else { for (unsigned I = 0; I != NumArgs; ++I) { assert(Args[I] != nullptr && "Expected non-null Expr"); @@ -350,11 +443,17 @@ void DeclPrinter::PrintConstructorInitializers(CXXConstructorDecl *CDecl, if (I) Out << ", "; - Args[I]->printPretty(Out, nullptr, Policy, Indentation); + Args[I]->printPretty(Out, nullptr, Policy, Indentation, "\n", + &Context); } } + + if (OutParens) + Out << ")"; + } else { + Out << "()"; } - Out << ")"; + if (BMInitializer->isPackExpansion()) Out << "..."; } @@ -445,21 +544,18 @@ void DeclPrinter::VisitDeclContext(DeclContext *DC, bool Indent) { else if (isa<ObjCMethodDecl>(*D) && cast<ObjCMethodDecl>(*D)->hasBody()) Terminator = nullptr; else if (auto FD = dyn_cast<FunctionDecl>(*D)) { - if (FD->isThisDeclarationADefinition()) + if (FD->doesThisDeclarationHaveABody() && !FD->isDefaulted()) Terminator = nullptr; else Terminator = ";"; } else if (auto TD = dyn_cast<FunctionTemplateDecl>(*D)) { - if (TD->getTemplatedDecl()->isThisDeclarationADefinition()) + if (TD->getTemplatedDecl()->doesThisDeclarationHaveABody()) Terminator = nullptr; else Terminator = ";"; - } else if (isa<NamespaceDecl>(*D) || isa<LinkageSpecDecl>(*D) || - isa<ObjCImplementationDecl>(*D) || - isa<ObjCInterfaceDecl>(*D) || - isa<ObjCProtocolDecl>(*D) || - isa<ObjCCategoryImplDecl>(*D) || - isa<ObjCCategoryDecl>(*D)) + } else if (isa<NamespaceDecl, LinkageSpecDecl, ObjCImplementationDecl, + ObjCInterfaceDecl, ObjCProtocolDecl, ObjCCategoryImplDecl, + ObjCCategoryDecl, HLSLBufferDecl>(*D)) Terminator = nullptr; else if (isa<EnumConstantDecl>(*D)) { DeclContext::decl_iterator Next = D; @@ -568,18 +664,19 @@ void DeclPrinter::VisitEnumConstantDecl(EnumConstantDecl *D) { } static void printExplicitSpecifier(ExplicitSpecifier ES, llvm::raw_ostream &Out, - PrintingPolicy &Policy, - unsigned Indentation) { + PrintingPolicy &Policy, unsigned Indentation, + const ASTContext &Context) { std::string Proto = "explicit"; llvm::raw_string_ostream EOut(Proto); if (ES.getExpr()) { EOut << "("; - ES.getExpr()->printPretty(EOut, nullptr, Policy, Indentation); + ES.getExpr()->printPretty(EOut, nullptr, Policy, Indentation, "\n", + &Context); EOut << ")"; } EOut << " "; EOut.flush(); - Out << EOut.str(); + Out << Proto; } void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { @@ -595,6 +692,22 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { printTemplateParameters(D->getTemplateParameterList(I)); } + std::string LeftsideAttrs; + llvm::raw_string_ostream LSAS(LeftsideAttrs); + + prettyPrintAttributes(D, LSAS, AttrPrintLoc::Left); + + // prettyPrintAttributes print a space on left side of the attribute. + if (LeftsideAttrs[0] == ' ') { + // Skip the space prettyPrintAttributes generated. + LeftsideAttrs.erase(0, LeftsideAttrs.find_first_not_of(' ')); + + // Add a single space between the attribute and the Decl name. + LSAS << ' '; + } + + Out << LeftsideAttrs; + CXXConstructorDecl *CDecl = dyn_cast<CXXConstructorDecl>(D); CXXConversionDecl *ConversionDecl = dyn_cast<CXXConversionDecl>(D); CXXDeductionGuideDecl *GuideDecl = dyn_cast<CXXDeductionGuideDecl>(D); @@ -614,9 +727,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (D->isConstexprSpecified() && !D->isExplicitlyDefaulted()) Out << "constexpr "; if (D->isConsteval()) Out << "consteval "; + else if (D->isImmediateFunction()) + Out << "immediate "; ExplicitSpecifier ExplicitSpec = ExplicitSpecifier::getFromDecl(D); if (ExplicitSpec.isSpecified()) - printExplicitSpecifier(ExplicitSpec, Out, Policy, Indentation); + printExplicitSpecifier(ExplicitSpec, Out, Policy, Indentation, Context); } PrintingPolicy SubPolicy(Policy); @@ -642,10 +757,10 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { DeclPrinter TArgPrinter(POut, SubPolicy, Context, Indentation); const auto *TArgAsWritten = D->getTemplateSpecializationArgsAsWritten(); if (TArgAsWritten && !Policy.PrintCanonicalTypes) - TArgPrinter.printTemplateArguments(TArgAsWritten->arguments()); + TArgPrinter.printTemplateArguments(TArgAsWritten->arguments(), nullptr); else if (const TemplateArgumentList *TArgs = D->getTemplateSpecializationArgs()) - TArgPrinter.printTemplateArguments(TArgs->asArray()); + TArgPrinter.printTemplateArguments(TArgs->asArray(), nullptr); } QualType Ty = D->getType(); @@ -671,6 +786,10 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (FT->isVariadic()) { if (D->getNumParams()) POut << ", "; POut << "..."; + } else if (!D->getNumParams() && !Context.getLangOpts().CPlusPlus) { + // The function has a prototype, so it needs to retain the prototype + // in C. + POut << "void"; } } else if (D->doesThisDeclarationHaveABody() && !D->hasPrototype()) { for (unsigned i = 0, e = D->getNumParams(); i != e; ++i) { @@ -720,9 +839,8 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { Proto += "("; llvm::raw_string_ostream EOut(Proto); FT->getNoexceptExpr()->printPretty(EOut, nullptr, SubPolicy, - Indentation); + Indentation, "\n", &Context); EOut.flush(); - Proto += EOut.str(); Proto += ")"; } } @@ -744,15 +862,16 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { if (Expr *TrailingRequiresClause = D->getTrailingRequiresClause()) { Out << " requires "; - TrailingRequiresClause->printPretty(Out, nullptr, SubPolicy, Indentation); + TrailingRequiresClause->printPretty(Out, nullptr, SubPolicy, Indentation, + "\n", &Context); } } else { Ty.print(Out, Policy, Proto); } - prettyPrintAttributes(D); + prettyPrintAttributes(D, Out, AttrPrintLoc::Right); - if (D->isPure()) + if (D->isPureVirtual()) Out << " = 0"; else if (D->isDeletedAsWritten()) Out << " = delete"; @@ -772,11 +891,11 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) { Out << ";\n"; } Indentation -= Policy.Indentation; - } else - Out << ' '; + } if (D->getBody()) - D->getBody()->printPretty(Out, nullptr, SubPolicy, Indentation); + D->getBody()->printPrettyControlled(Out, nullptr, SubPolicy, Indentation, "\n", + &Context); } else { if (!Policy.TerseOutput && isa<CXXConstructorDecl>(*D)) Out << " {}"; @@ -821,7 +940,8 @@ void DeclPrinter::VisitFieldDecl(FieldDecl *D) { if (D->isBitField()) { Out << " : "; - D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation); + D->getBitWidth()->printPretty(Out, nullptr, Policy, Indentation, "\n", + &Context); } Expr *Init = D->getInClassInitializer(); @@ -830,7 +950,7 @@ void DeclPrinter::VisitFieldDecl(FieldDecl *D) { Out << " "; else Out << " = "; - Init->printPretty(Out, nullptr, Policy, Indentation); + Init->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); } prettyPrintAttributes(D); } @@ -842,6 +962,27 @@ void DeclPrinter::VisitLabelDecl(LabelDecl *D) { void DeclPrinter::VisitVarDecl(VarDecl *D) { prettyPrintPragmas(D); + if (const auto *Param = dyn_cast<ParmVarDecl>(D); + Param && Param->isExplicitObjectParameter()) + Out << "this "; + + std::string LeftSide; + llvm::raw_string_ostream LeftSideStream(LeftSide); + + // Print attributes that should be placed on the left, such as __declspec. + prettyPrintAttributes(D, LeftSideStream, AttrPrintLoc::Left); + + // prettyPrintAttributes print a space on left side of the attribute. + if (LeftSide[0] == ' ') { + // Skip the space prettyPrintAttributes generated. + LeftSide.erase(0, LeftSide.find_first_not_of(' ')); + + // Add a single space between the attribute and the Decl name. + LeftSideStream << ' '; + } + + Out << LeftSide; + QualType T = D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType() : D->getASTContext().getUnqualifiedObjCPointerType(D->getType()); @@ -874,16 +1015,31 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { } } - printDeclType(T, D->getName()); + StringRef Name; + + Name = (isa<ParmVarDecl>(D) && Policy.CleanUglifiedParameters && + D->getIdentifier()) + ? D->getIdentifier()->deuglifiedName() + : D->getName(); + + printDeclType(T, Name); + + // Print the attributes that should be placed right before the end of the + // decl. + prettyPrintAttributes(D, Out, AttrPrintLoc::Right); + Expr *Init = D->getInit(); if (!Policy.SuppressInitializers && Init) { bool ImplicitInit = false; - if (CXXConstructExpr *Construct = - dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) { + if (D->isCXXForRangeDecl()) { + // FIXME: We should print the range expression instead. + ImplicitInit = true; + } else if (CXXConstructExpr *Construct = + dyn_cast<CXXConstructExpr>(Init->IgnoreImplicit())) { if (D->getInitStyle() == VarDecl::CallInit && !Construct->isListInitialization()) { ImplicitInit = Construct->getNumArgs() == 0 || - Construct->getArg(0)->isDefaultArgument(); + Construct->getArg(0)->isDefaultArgument(); } } if (!ImplicitInit) { @@ -895,12 +1051,11 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { PrintingPolicy SubPolicy(Policy); SubPolicy.SuppressSpecifiers = false; SubPolicy.IncludeTagDefinition = false; - Init->printPretty(Out, nullptr, SubPolicy, Indentation); + Init->printPretty(Out, nullptr, SubPolicy, Indentation, "\n", &Context); if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init)) Out << ")"; } } - prettyPrintAttributes(D); } void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) { @@ -909,10 +1064,16 @@ void DeclPrinter::VisitParmVarDecl(ParmVarDecl *D) { void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { Out << "__asm ("; - D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation); + D->getAsmString()->printPretty(Out, nullptr, Policy, Indentation, "\n", + &Context); Out << ")"; } +void DeclPrinter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) { + assert(D->getStmt()); + D->getStmt()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); +} + void DeclPrinter::VisitImportDecl(ImportDecl *D) { Out << "@import " << D->getImportedModule()->getFullModuleName() << ";\n"; @@ -920,10 +1081,11 @@ void DeclPrinter::VisitImportDecl(ImportDecl *D) { void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) { Out << "static_assert("; - D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation); - if (StringLiteral *SL = D->getMessage()) { + D->getAssertExpr()->printPretty(Out, nullptr, Policy, Indentation, "\n", + &Context); + if (Expr *E = D->getMessage()) { Out << ", "; - SL->printPretty(Out, nullptr, Policy, Indentation); + E->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); } Out << ")"; } @@ -971,7 +1133,10 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { prettyPrintAttributes(D); if (D->getIdentifier()) { - Out << ' ' << *D; + Out << ' '; + if (auto *NNS = D->getQualifier()) + NNS->print(Out, Policy); + Out << *D; if (auto S = dyn_cast<ClassTemplateSpecializationDecl>(D)) { ArrayRef<TemplateArgument> Args = S->getTemplateArgs().asArray(); @@ -980,7 +1145,14 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { if (const auto *TST = dyn_cast<TemplateSpecializationType>(TSI->getType())) Args = TST->template_arguments(); - printTemplateArguments(Args); + printTemplateArguments( + Args, S->getSpecializedTemplate()->getTemplateParameters()); + } + } + + if (D->hasDefinition()) { + if (D->hasAttr<FinalAttr>()) { + Out << " final"; } } @@ -1022,10 +1194,10 @@ void DeclPrinter::VisitCXXRecordDecl(CXXRecordDecl *D) { void DeclPrinter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { const char *l; - if (D->getLanguage() == LinkageSpecDecl::lang_c) + if (D->getLanguage() == LinkageSpecLanguageIDs::C) l = "C"; else { - assert(D->getLanguage() == LinkageSpecDecl::lang_cxx && + assert(D->getLanguage() == LinkageSpecLanguageIDs::CXX && "unknown language in linkage specification"); l = "C++"; } @@ -1072,22 +1244,35 @@ void DeclPrinter::printTemplateParameters(const TemplateParameterList *Params, Out << ' '; } -void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args) { +void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgument> Args, + const TemplateParameterList *Params) { Out << "<"; for (size_t I = 0, E = Args.size(); I < E; ++I) { if (I) Out << ", "; - Args[I].print(Policy, Out); + if (!Params) + Args[I].print(Policy, Out, /*IncludeType*/ true); + else + Args[I].print(Policy, Out, + TemplateParameterList::shouldIncludeTypeForArgument( + Policy, Params, I)); } Out << ">"; } -void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args) { +void DeclPrinter::printTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, + const TemplateParameterList *Params) { Out << "<"; for (size_t I = 0, E = Args.size(); I < E; ++I) { if (I) Out << ", "; - Args[I].getArgument().print(Policy, Out); + if (!Params) + Args[I].getArgument().print(Policy, Out, /*IncludeType*/ true); + else + Args[I].getArgument().print( + Policy, Out, + TemplateParameterList::shouldIncludeTypeForArgument(Policy, Params, + I)); } Out << ">"; } @@ -1104,15 +1289,18 @@ void DeclPrinter::VisitTemplateDecl(const TemplateDecl *D) { else if (TTP->getDeclName()) Out << ' '; - if (TTP->getDeclName()) - Out << TTP->getDeclName(); + if (TTP->getDeclName()) { + if (Policy.CleanUglifiedParameters && TTP->getIdentifier()) + Out << TTP->getIdentifier()->deuglifiedName(); + else + Out << TTP->getDeclName(); + } } else if (auto *TD = D->getTemplatedDecl()) Visit(TD); else if (const auto *Concept = dyn_cast<ConceptDecl>(D)) { Out << "concept " << Concept->getName() << " = " ; - Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, - Indentation); - Out << ";"; + Concept->getConstraintExpr()->printPretty(Out, nullptr, Policy, Indentation, + "\n", &Context); } } @@ -1158,6 +1346,7 @@ void DeclPrinter::VisitClassTemplateDecl(ClassTemplateDecl *D) { if (D->isThisDeclarationADefinition()) Out << ";"; Out << "\n"; + Indent(); Visit(I); } } @@ -1271,7 +1460,8 @@ void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { if (OMD->getBody() && !Policy.TerseOutput) { Out << ' '; - OMD->getBody()->printPretty(Out, nullptr, Policy); + OMD->getBody()->printPretty(Out, nullptr, Policy, Indentation, "\n", + &Context); } else if (Policy.PolishForDeclaration) Out << ';'; @@ -1538,7 +1728,7 @@ void DeclPrinter::VisitObjCPropertyDecl(ObjCPropertyDecl *PDecl) { std::string TypeStr = PDecl->getASTContext().getUnqualifiedObjCPointerType(T). getAsString(Policy); Out << ' ' << TypeStr; - if (!StringRef(TypeStr).endswith("*")) + if (!StringRef(TypeStr).ends_with("*")) Out << ' '; Out << *PDecl; if (Policy.PolishForDeclaration) @@ -1575,6 +1765,10 @@ void DeclPrinter::VisitUsingDecl(UsingDecl *D) { Out << *D; } +void DeclPrinter::VisitUsingEnumDecl(UsingEnumDecl *D) { + Out << "using enum " << D->getEnumDecl(); +} + void DeclPrinter::VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) { Out << "using typename "; @@ -1607,6 +1801,21 @@ void DeclPrinter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { } } +void DeclPrinter::VisitHLSLBufferDecl(HLSLBufferDecl *D) { + if (D->isCBuffer()) + Out << "cbuffer "; + else + Out << "tbuffer "; + + Out << *D; + + prettyPrintAttributes(D); + + Out << " {\n"; + VisitDeclContext(D); + Indent() << "}"; +} + void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) { Out << "#pragma omp allocate"; if (!D->varlist_empty()) { @@ -1620,10 +1829,11 @@ void DeclPrinter::VisitOMPAllocateDecl(OMPAllocateDecl *D) { Out << ")"; } if (!D->clauselist_empty()) { - Out << " "; OMPClausePrinter Printer(Out, Policy); - for (OMPClause *C : D->clauselists()) + for (OMPClause *C : D->clauselists()) { + Out << " "; Printer.Visit(C); + } } } @@ -1646,27 +1856,27 @@ void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { Out << OpName; } else { assert(D->getDeclName().isIdentifier()); - D->printName(Out); + D->printName(Out, Policy); } Out << " : "; D->getType().print(Out, Policy); Out << " : "; - D->getCombiner()->printPretty(Out, nullptr, Policy, 0); + D->getCombiner()->printPretty(Out, nullptr, Policy, 0, "\n", &Context); Out << ")"; if (auto *Init = D->getInitializer()) { Out << " initializer("; switch (D->getInitializerKind()) { - case OMPDeclareReductionDecl::DirectInit: + case OMPDeclareReductionInitKind::Direct: Out << "omp_priv("; break; - case OMPDeclareReductionDecl::CopyInit: + case OMPDeclareReductionInitKind::Copy: Out << "omp_priv = "; break; - case OMPDeclareReductionDecl::CallInit: + case OMPDeclareReductionInitKind::Call: break; } - Init->printPretty(Out, nullptr, Policy, 0); - if (D->getInitializerKind() == OMPDeclareReductionDecl::DirectInit) + Init->printPretty(Out, nullptr, Policy, 0, "\n", &Context); + if (D->getInitializerKind() == OMPDeclareReductionInitKind::Direct) Out << ")"; Out << ")"; } @@ -1676,7 +1886,7 @@ void DeclPrinter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { void DeclPrinter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { if (!D->isInvalidDecl()) { Out << "#pragma omp declare mapper ("; - D->printName(Out); + D->printName(Out, Policy); Out << " : "; D->getType().print(Out, Policy); Out << " "; @@ -1693,7 +1903,7 @@ void DeclPrinter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { } void DeclPrinter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { - D->getInit()->printPretty(Out, nullptr, Policy, Indentation); + D->getInit()->printPretty(Out, nullptr, Policy, Indentation, "\n", &Context); } void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) { @@ -1709,8 +1919,12 @@ void DeclPrinter::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *TTP) { else if (TTP->getDeclName()) Out << ' '; - if (TTP->getDeclName()) - Out << TTP->getDeclName(); + if (TTP->getDeclName()) { + if (Policy.CleanUglifiedParameters && TTP->getIdentifier()) + Out << TTP->getIdentifier()->deuglifiedName(); + else + Out << TTP->getDeclName(); + } if (TTP->hasDefaultArgument()) { Out << " = "; @@ -1722,11 +1936,13 @@ void DeclPrinter::VisitNonTypeTemplateParmDecl( const NonTypeTemplateParmDecl *NTTP) { StringRef Name; if (IdentifierInfo *II = NTTP->getIdentifier()) - Name = II->getName(); + Name = + Policy.CleanUglifiedParameters ? II->deuglifiedName() : II->getName(); printDeclType(NTTP->getType(), Name, NTTP->isParameterPack()); if (NTTP->hasDefaultArgument()) { Out << " = "; - NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy, Indentation); + NTTP->getDefaultArgument()->printPretty(Out, nullptr, Policy, Indentation, + "\n", &Context); } } |