From 372df097866f776c2f1e232733f9db39bdabcfaf Mon Sep 17 00:00:00 2001 From: Eugene Zelenko Date: Tue, 10 Apr 2018 22:54:42 +0000 Subject: [PATCH] [AST] Fix some Clang-tidy modernize-use-auto and Include What You Use warnings; other minor fixes (NFC). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329766 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprCXX.h | 12 +-- lib/AST/ExprCXX.cpp | 69 ++++++++------- lib/AST/ExprClassification.cpp | 25 +++--- lib/AST/StmtPrinter.cpp | 128 ++++++++++++++++++---------- lib/AST/TypePrinter.cpp | 148 +++++++++++++++++++++++---------- 5 files changed, 239 insertions(+), 143 deletions(-) diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index e51ffb6d5b..cb93b8b9e6 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -715,7 +715,7 @@ public: child_range children() { if (isTypeOperand()) return child_range(child_iterator(), child_iterator()); - Stmt **begin = reinterpret_cast(&Operand); + auto **begin = reinterpret_cast(&Operand); return child_range(begin, begin + 1); } }; @@ -925,7 +925,7 @@ public: child_range children() { if (isTypeOperand()) return child_range(child_iterator(), child_iterator()); - Stmt **begin = reinterpret_cast(&Operand); + auto **begin = reinterpret_cast(&Operand); return child_range(begin, begin + 1); } }; @@ -2621,7 +2621,7 @@ public: if (isa(E)) { assert(cast(E)->getOpcode() == UO_AddrOf); E = cast(E)->getSubExpr(); - OverloadExpr *Ovl = cast(E->IgnoreParens()); + auto *Ovl = cast(E->IgnoreParens()); Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); Result.IsAddressOfOperand = true; @@ -3190,7 +3190,7 @@ public: // Iterators child_range children() { - Stmt **begin = reinterpret_cast(arg_begin()); + auto **begin = reinterpret_cast(arg_begin()); return child_range(begin, begin + NumArgs); } }; @@ -3768,7 +3768,7 @@ class SizeOfPackExpr final Length(Length ? *Length : PartialArgs.size()), Pack(Pack) { assert((!Length || PartialArgs.empty()) && "have partial args for non-dependent sizeof... expression"); - TemplateArgument *Args = getTrailingObjects(); + auto *Args = getTrailingObjects(); std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args); } @@ -3819,7 +3819,7 @@ public: /// \brief Get ArrayRef getPartialArguments() const { assert(isPartiallySubstituted()); - const TemplateArgument *Args = getTrailingObjects(); + const auto *Args = getTrailingObjects(); return llvm::makeArrayRef(Args, Args + Length); } diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index b8a837fe47..eb2e8c50f7 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -181,7 +181,7 @@ QualType CXXDeleteExpr::getDestroyedType() const { // For a destroying operator delete, we may have implicitly converted the // pointer type to the type of the parameter of the 'operator delete' // function. - while (auto *ICE = dyn_cast(Arg)) { + while (const auto *ICE = dyn_cast(Arg)) { if (ICE->getCastKind() == CK_DerivedToBase || ICE->getCastKind() == CK_UncheckedDerivedToBase || ICE->getCastKind() == CK_NoOp) { @@ -290,7 +290,7 @@ UnresolvedLookupExpr::CreateEmpty(const ASTContext &C, totalSizeToAlloc( HasTemplateKWAndArgsInfo, NumTemplateArgs); void *Mem = C.Allocate(Size, alignof(UnresolvedLookupExpr)); - UnresolvedLookupExpr *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); + auto *E = new (Mem) UnresolvedLookupExpr(EmptyShell()); E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; return E; } @@ -442,8 +442,8 @@ DependentScopeDeclRefExpr::CreateEmpty(const ASTContext &C, totalSizeToAlloc( HasTemplateKWAndArgsInfo, NumTemplateArgs); void *Mem = C.Allocate(Size); - DependentScopeDeclRefExpr *E - = new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(), + auto *E = + new (Mem) DependentScopeDeclRefExpr(QualType(), NestedNameSpecifierLoc(), SourceLocation(), DeclarationNameInfo(), nullptr); E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; @@ -504,9 +504,9 @@ SourceRange CXXOperatorCallExpr::getSourceRangeImpl() const { Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { const Expr *Callee = getCallee()->IgnoreParens(); - if (const MemberExpr *MemExpr = dyn_cast(Callee)) + if (const auto *MemExpr = dyn_cast(Callee)) return MemExpr->getBase(); - if (const BinaryOperator *BO = dyn_cast(Callee)) + if (const auto *BO = dyn_cast(Callee)) if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI) return BO->getLHS(); @@ -515,8 +515,7 @@ Expr *CXXMemberCallExpr::getImplicitObjectArgument() const { } CXXMethodDecl *CXXMemberCallExpr::getMethodDecl() const { - if (const MemberExpr *MemExpr = - dyn_cast(getCallee()->IgnoreParens())) + if (const auto *MemExpr = dyn_cast(getCallee()->IgnoreParens())) return cast(MemExpr->getMemberDecl()); // FIXME: Will eventually need to cope with member pointers. @@ -561,9 +560,9 @@ CXXStaticCastExpr *CXXStaticCastExpr::Create(const ASTContext &C, QualType T, SourceRange AngleBrackets) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CXXStaticCastExpr *E = - new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, - RParenLoc, AngleBrackets); + auto *E = + new (Buffer) CXXStaticCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, + RParenLoc, AngleBrackets); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -586,9 +585,9 @@ CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T, SourceRange AngleBrackets) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CXXDynamicCastExpr *E = - new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, - RParenLoc, AngleBrackets); + auto *E = + new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, + RParenLoc, AngleBrackets); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -614,7 +613,7 @@ bool CXXDynamicCastExpr::isAlwaysNull() const QualType SrcType = getSubExpr()->getType(); QualType DestType = getType(); - if (const PointerType *SrcPTy = SrcType->getAs()) { + if (const auto *SrcPTy = SrcType->getAs()) { SrcType = SrcPTy->getPointeeType(); DestType = DestType->castAs()->getPointeeType(); } @@ -622,14 +621,14 @@ bool CXXDynamicCastExpr::isAlwaysNull() const if (DestType->isVoidType()) return false; - const CXXRecordDecl *SrcRD = - cast(SrcType->castAs()->getDecl()); + const auto *SrcRD = + cast(SrcType->castAs()->getDecl()); if (!SrcRD->hasAttr()) return false; - const CXXRecordDecl *DestRD = - cast(DestType->castAs()->getDecl()); + const auto *DestRD = + cast(DestType->castAs()->getDecl()); return !DestRD->isDerivedFrom(SrcRD); } @@ -643,9 +642,9 @@ CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T, SourceRange AngleBrackets) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CXXReinterpretCastExpr *E = - new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, - RParenLoc, AngleBrackets); + auto *E = + new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L, + RParenLoc, AngleBrackets); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -678,8 +677,8 @@ CXXFunctionalCastExpr::Create(const ASTContext &C, QualType T, ExprValueKind VK, SourceLocation L, SourceLocation R) { unsigned PathSize = (BasePath ? BasePath->size() : 0); void *Buffer = C.Allocate(totalSizeToAlloc(PathSize)); - CXXFunctionalCastExpr *E = - new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R); + auto *E = + new (Buffer) CXXFunctionalCastExpr(T, VK, Written, K, Op, PathSize, L, R); if (PathSize) std::uninitialized_copy_n(BasePath->data(), BasePath->size(), E->getTrailingObjects()); @@ -1079,7 +1078,7 @@ CXXUnresolvedConstructExpr::CXXUnresolvedConstructExpr(TypeSourceInfo *Type, true, true, Type->getType()->containsUnexpandedParameterPack()), Type(Type), LParenLoc(LParenLoc), RParenLoc(RParenLoc), NumArgs(Args.size()) { - Expr **StoredArgs = getTrailingObjects(); + auto **StoredArgs = getTrailingObjects(); for (unsigned I = 0; I != Args.size(); ++I) { if (Args[I]->containsUnexpandedParameterPack()) ExprBits.ContainsUnexpandedParameterPack = true; @@ -1176,12 +1175,12 @@ CXXDependentScopeMemberExpr::CreateEmpty(const ASTContext &C, totalSizeToAlloc( HasTemplateKWAndArgsInfo, NumTemplateArgs); void *Mem = C.Allocate(Size, alignof(CXXDependentScopeMemberExpr)); - CXXDependentScopeMemberExpr *E - = new (Mem) CXXDependentScopeMemberExpr(C, nullptr, QualType(), - false, SourceLocation(), - NestedNameSpecifierLoc(), - SourceLocation(), nullptr, - DeclarationNameInfo(), nullptr); + auto *E = + new (Mem) CXXDependentScopeMemberExpr(C, nullptr, QualType(), + false, SourceLocation(), + NestedNameSpecifierLoc(), + SourceLocation(), nullptr, + DeclarationNameInfo(), nullptr); E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; return E; } @@ -1274,7 +1273,7 @@ UnresolvedMemberExpr::CreateEmpty(const ASTContext &C, HasTemplateKWAndArgsInfo, NumTemplateArgs); void *Mem = C.Allocate(Size, alignof(UnresolvedMemberExpr)); - UnresolvedMemberExpr *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); + auto *E = new (Mem) UnresolvedMemberExpr(EmptyShell()); E->HasTemplateKWAndArgsInfo = HasTemplateKWAndArgsInfo; return E; } @@ -1297,7 +1296,7 @@ CXXRecordDecl *UnresolvedMemberExpr::getNamingClass() const { else { QualType BaseType = getBaseType().getNonReferenceType(); if (isArrow()) { - const PointerType *PT = BaseType->getAs(); + const auto *PT = BaseType->getAs(); assert(PT && "base of arrow member access is not pointer"); BaseType = PT->getPointeeType(); } @@ -1379,7 +1378,7 @@ void MaterializeTemporaryExpr::setExtendingDecl(const ValueDecl *ExtendedBy, // We may need to allocate extra storage for the mangling number and the // extended-by ValueDecl. if (!State.is()) { - auto ES = new (ExtendedBy->getASTContext()) ExtraState; + auto *ES = new (ExtendedBy->getASTContext()) ExtraState; ES->Temporary = State.get(); State = ES; } @@ -1403,7 +1402,7 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, TypeTraitExprBits.Value = Value; TypeTraitExprBits.NumArgs = Args.size(); - TypeSourceInfo **ToArgs = getTrailingObjects(); + auto **ToArgs = getTrailingObjects(); for (unsigned I = 0, N = Args.size(); I != N; ++I) { if (Args[I]->getType()->isDependentType()) diff --git a/lib/AST/ExprClassification.cpp b/lib/AST/ExprClassification.cpp index 3bb2b4eb5f..297267b521 100644 --- a/lib/AST/ExprClassification.cpp +++ b/lib/AST/ExprClassification.cpp @@ -1,4 +1,4 @@ -//===--- ExprClassification.cpp - Expression AST Node Implementation ------===// +//===- ExprClassification.cpp - Expression AST Node Implementation --------===// // // The LLVM Compiler Infrastructure // @@ -19,9 +19,10 @@ #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" #include "llvm/Support/ErrorHandling.h" + using namespace clang; -typedef Expr::Classification Cl; +using Cl = Expr::Classification; static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E); static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D); @@ -348,14 +349,14 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) { case Expr::BinaryConditionalOperatorClass: { if (!Lang.CPlusPlus) return Cl::CL_PRValue; - const BinaryConditionalOperator *co = cast(E); + const auto *co = cast(E); return ClassifyConditional(Ctx, co->getTrueExpr(), co->getFalseExpr()); } case Expr::ConditionalOperatorClass: { // Once again, only C++ is interesting. if (!Lang.CPlusPlus) return Cl::CL_PRValue; - const ConditionalOperator *co = cast(E); + const auto *co = cast(E); return ClassifyConditional(Ctx, co->getTrueExpr(), co->getFalseExpr()); } @@ -385,7 +386,7 @@ static Cl::Kinds ClassifyInternal(ASTContext &Ctx, const Expr *E) { case Expr::StmtExprClass: { const CompoundStmt *S = cast(E)->getSubStmt(); - if (const Expr *LastExpr = dyn_cast_or_null(S->body_back())) + if (const auto *LastExpr = dyn_cast_or_null(S->body_back())) return ClassifyUnnamed(Ctx, LastExpr->getType()); return Cl::CL_PRValue; } @@ -434,8 +435,7 @@ static Cl::Kinds ClassifyDecl(ASTContext &Ctx, const Decl *D) { return Cl::CL_MemberFunction; bool islvalue; - if (const NonTypeTemplateParmDecl *NTTParm = - dyn_cast(D)) + if (const auto *NTTParm = dyn_cast(D)) islvalue = NTTParm->getType()->isReferenceType(); else islvalue = isa(D) || isa(D) || @@ -461,7 +461,7 @@ static Cl::Kinds ClassifyUnnamed(ASTContext &Ctx, QualType T) { // otherwise. if (T->isLValueReferenceType()) return Cl::CL_LValue; - const RValueReferenceType *RV = T->getAs(); + const auto *RV = T->getAs(); if (!RV) // Could still be a class temporary, though. return ClassifyTemporary(T); @@ -491,7 +491,7 @@ static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E) { // C++ [expr.ref]p3: E1->E2 is converted to the equivalent form (*(E1)).E2. // C++ [expr.ref]p4: If E2 is declared to have type "reference to T", then // E1.E2 is an lvalue. - if (ValueDecl *Value = dyn_cast(Member)) + if (const auto *Value = dyn_cast(Member)) if (Value->getType()->isReferenceType()) return Cl::CL_LValue; @@ -517,7 +517,7 @@ static Cl::Kinds ClassifyMemberExpr(ASTContext &Ctx, const MemberExpr *E) { // -- If it refers to a static member function [...], then E1.E2 is an // lvalue; [...] // -- Otherwise [...] E1.E2 is a prvalue. - if (CXXMethodDecl *Method = dyn_cast(Member)) + if (const auto *Method = dyn_cast(Member)) return Method->isStatic() ? Cl::CL_LValue : Cl::CL_MemberFunction; // -- If E2 is a member enumerator [...], the expression E1.E2 is a prvalue. @@ -599,8 +599,7 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, if (Kind == Cl::CL_PRValue) { // For the sake of better diagnostics, we want to specifically recognize // use of the GCC cast-as-lvalue extension. - if (const ExplicitCastExpr *CE = - dyn_cast(E->IgnoreParens())) { + if (const auto *CE = dyn_cast(E->IgnoreParens())) { if (CE->getSubExpr()->IgnoreParenImpCasts()->isLValue()) { Loc = CE->getExprLoc(); return Cl::CM_LValueCast; @@ -617,7 +616,7 @@ static Cl::ModifiableType IsModifiable(ASTContext &Ctx, const Expr *E, // Assignment to a property in ObjC is an implicit setter access. But a // setter might not exist. - if (const ObjCPropertyRefExpr *Expr = dyn_cast(E)) { + if (const auto *Expr = dyn_cast(E)) { if (Expr->isImplicitProperty() && Expr->getImplicitPropertySetter() == nullptr) return Cl::CM_NoSetterProperty; diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 3022483046..e782d3d144 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -1,4 +1,4 @@ -//===--- StmtPrinter.cpp - Printing implementation for Stmt ASTs ----------===// +//===- StmtPrinter.cpp - Printing implementation for Stmt ASTs ------------===// // // The LLVM Compiler Infrastructure // @@ -14,30 +14,60 @@ #include "clang/AST/ASTContext.h" #include "clang/AST/Attr.h" +#include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclOpenMP.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" +#include "clang/AST/ExprObjC.h" #include "clang/AST/ExprOpenMP.h" +#include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/OpenMPClause.h" #include "clang/AST/PrettyPrinter.h" +#include "clang/AST/Stmt.h" +#include "clang/AST/StmtCXX.h" +#include "clang/AST/StmtObjC.h" +#include "clang/AST/StmtOpenMP.h" #include "clang/AST/StmtVisitor.h" +#include "clang/AST/TemplateBase.h" +#include "clang/AST/Type.h" #include "clang/Basic/CharInfo.h" +#include "clang/Basic/ExpressionTraits.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" +#include "clang/Basic/Lambda.h" +#include "clang/Basic/OpenMPKinds.h" +#include "clang/Basic/OperatorKinds.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/TypeTraits.h" #include "clang/Lex/Lexer.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + using namespace clang; //===----------------------------------------------------------------------===// // StmtPrinter Visitor //===----------------------------------------------------------------------===// -namespace { +namespace { + class StmtPrinter : public StmtVisitor { raw_ostream &OS; unsigned IndentLevel; - clang::PrinterHelper* Helper; + PrinterHelper* Helper; PrintingPolicy Policy; const ASTContext *Context; @@ -100,9 +130,11 @@ namespace { void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED { Indent() << "<>\n"; } + void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED { OS << "<>"; } + void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node); #define ABSTRACT_STMT(CLASS) @@ -110,7 +142,8 @@ namespace { void Visit##CLASS(CLASS *Node); #include "clang/AST/StmtNodes.inc" }; -} + +} // namespace //===----------------------------------------------------------------------===// // Stmt printing methods. @@ -131,7 +164,7 @@ void StmtPrinter::PrintRawDecl(Decl *D) { } void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) { - SmallVector Decls(S->decls()); + SmallVector Decls(S->decls()); Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel); } @@ -189,7 +222,7 @@ void StmtPrinter::PrintRawIfStmt(IfStmt *If) { PrintExpr(If->getCond()); OS << ')'; - if (CompoundStmt *CS = dyn_cast(If->getThen())) { + if (auto *CS = dyn_cast(If->getThen())) { OS << ' '; PrintRawCompoundStmt(CS); OS << (If->getElse() ? ' ' : '\n'); @@ -202,11 +235,11 @@ void StmtPrinter::PrintRawIfStmt(IfStmt *If) { if (Stmt *Else = If->getElse()) { OS << "else"; - if (CompoundStmt *CS = dyn_cast(Else)) { + if (auto *CS = dyn_cast(Else)) { OS << ' '; PrintRawCompoundStmt(CS); OS << '\n'; - } else if (IfStmt *ElseIf = dyn_cast(Else)) { + } else if (auto *ElseIf = dyn_cast(Else)) { OS << ' '; PrintRawIfStmt(ElseIf); } else { @@ -230,7 +263,7 @@ void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) { OS << ")"; // Pretty print compoundstmt bodies (very common). - if (CompoundStmt *CS = dyn_cast(Node->getBody())) { + if (auto *CS = dyn_cast(Node->getBody())) { OS << " "; PrintRawCompoundStmt(CS); OS << "\n"; @@ -252,7 +285,7 @@ void StmtPrinter::VisitWhileStmt(WhileStmt *Node) { void StmtPrinter::VisitDoStmt(DoStmt *Node) { Indent() << "do "; - if (CompoundStmt *CS = dyn_cast(Node->getBody())) { + if (auto *CS = dyn_cast(Node->getBody())) { PrintRawCompoundStmt(CS); OS << " "; } else { @@ -269,7 +302,7 @@ void StmtPrinter::VisitDoStmt(DoStmt *Node) { void StmtPrinter::VisitForStmt(ForStmt *Node) { Indent() << "for ("; if (Node->getInit()) { - if (DeclStmt *DS = dyn_cast(Node->getInit())) + if (auto *DS = dyn_cast(Node->getInit())) PrintRawDeclStmt(DS); else PrintExpr(cast(Node->getInit())); @@ -286,7 +319,7 @@ void StmtPrinter::VisitForStmt(ForStmt *Node) { } OS << ") "; - if (CompoundStmt *CS = dyn_cast(Node->getBody())) { + if (auto *CS = dyn_cast(Node->getBody())) { PrintRawCompoundStmt(CS); OS << "\n"; } else { @@ -297,7 +330,7 @@ void StmtPrinter::VisitForStmt(ForStmt *Node) { void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) { Indent() << "for ("; - if (DeclStmt *DS = dyn_cast(Node->getElement())) + if (auto *DS = dyn_cast(Node->getElement())) PrintRawDeclStmt(DS); else PrintExpr(cast(Node->getElement())); @@ -305,7 +338,7 @@ void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) { PrintExpr(Node->getCollection()); OS << ") "; - if (CompoundStmt *CS = dyn_cast(Node->getBody())) { + if (auto *CS = dyn_cast(Node->getBody())) { PrintRawCompoundStmt(CS); OS << "\n"; } else { @@ -365,7 +398,6 @@ void StmtPrinter::VisitBreakStmt(BreakStmt *Node) { if (Policy.IncludeNewlines) OS << "\n"; } - void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) { Indent() << "return"; if (Node->getRetValue()) { @@ -376,7 +408,6 @@ void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) { if (Policy.IncludeNewlines) OS << "\n"; } - void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) { Indent() << "asm "; @@ -458,7 +489,7 @@ void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) { void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { Indent() << "@try"; - if (CompoundStmt *TS = dyn_cast(Node->getTryBody())) { + if (auto *TS = dyn_cast(Node->getTryBody())) { PrintRawCompoundStmt(TS); OS << "\n"; } @@ -471,14 +502,13 @@ void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { PrintRawDecl(DS); } OS << ")"; - if (CompoundStmt *CS = dyn_cast(catchStmt->getCatchBody())) { + if (auto *CS = dyn_cast(catchStmt->getCatchBody())) { PrintRawCompoundStmt(CS); OS << "\n"; } } - if (ObjCAtFinallyStmt *FS = static_cast( - Node->getFinallyStmt())) { + if (auto *FS = static_cast(Node->getFinallyStmt())) { Indent() << "@finally"; PrintRawCompoundStmt(dyn_cast(FS->getFinallyBody())); OS << "\n"; @@ -596,20 +626,26 @@ void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) { //===----------------------------------------------------------------------===// namespace { + class OMPClausePrinter : public OMPClauseVisitor { raw_ostream &OS; const PrintingPolicy &Policy; + /// \brief Process clauses with list of variables. template void VisitOMPClauseList(T *Node, char StartSym); + public: OMPClausePrinter(raw_ostream &OS, const PrintingPolicy &Policy) - : OS(OS), Policy(Policy) { } + : OS(OS), Policy(Policy) {} + #define OPENMP_CLAUSE(Name, Class) \ void Visit##Class(Class *S); #include "clang/Basic/OpenMPKinds.def" }; +} // namespace + void OMPClausePrinter::VisitOMPIfClause(OMPIfClause *Node) { OS << "if("; if (Node->getNameModifier() != OMPD_unknown) @@ -776,7 +812,7 @@ void OMPClausePrinter::VisitOMPClauseList(T *Node, char StartSym) { I != E; ++I) { assert(*I && "Expected non-null Stmt"); OS << (I == Node->varlist_begin() ? StartSym : ','); - if (DeclRefExpr *DRE = dyn_cast(*I)) { + if (auto *DRE = dyn_cast(*I)) { if (isa(DRE->getDecl())) DRE->printPretty(OS, nullptr, Policy, 0); else @@ -1017,7 +1053,6 @@ void OMPClausePrinter::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *Node) { OS << ")"; } } -} //===----------------------------------------------------------------------===// // OpenMP directives printing methods @@ -1027,11 +1062,10 @@ void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S, bool ForceNoStmt) { OMPClausePrinter Printer(OS, Policy); ArrayRef Clauses = S->clauses(); - for (ArrayRef::iterator I = Clauses.begin(), E = Clauses.end(); - I != E; ++I) - if (*I && !(*I)->isImplicit()) { + for (auto *Clause : Clauses) + if (Clause && !Clause->isImplicit()) { OS << ' '; - Printer.Visit(*I); + Printer.Visit(Clause); } OS << "\n"; if (!ForceNoStmt && S->hasAssociatedStmt()) @@ -1306,7 +1340,7 @@ void StmtPrinter::VisitOMPTargetTeamsDistributeSimdDirective( //===----------------------------------------------------------------------===// void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { - if (auto *OCED = dyn_cast(Node->getDecl())) { + if (const auto *OCED = dyn_cast(Node->getDecl())) { OCED->getInit()->IgnoreImpCasts()->printPretty(OS, nullptr, Policy); return; } @@ -1342,8 +1376,7 @@ void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) { static bool isImplicitSelf(const Expr *E) { if (const auto *DRE = dyn_cast(E)) { - if (const ImplicitParamDecl *PD = - dyn_cast(DRE->getDecl())) { + if (const auto *PD = dyn_cast(DRE->getDecl())) { if (PD->getParameterKind() == ImplicitParamDecl::ObjCSelf && DRE->getLocStart().isInvalid()) return true; @@ -1380,7 +1413,6 @@ void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) { } void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) { - PrintExpr(Node->getBaseExpr()); OS << "["; PrintExpr(Node->getKeyExpr()); @@ -1530,11 +1562,13 @@ void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) { void StmtPrinter::VisitStringLiteral(StringLiteral *Str) { Str->outputString(OS); } + void StmtPrinter::VisitParenExpr(ParenExpr *Node) { OS << "("; PrintExpr(Node->getSubExpr()); OS << ")"; } + void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) { if (!Node->isPostfix()) { OS << UnaryOperator::getOpcodeStr(Node->getOpcode()); @@ -1690,7 +1724,7 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { if (!Policy.SuppressImplicitBase || !isImplicitThis(Node->getBase())) { PrintExpr(Node->getBase()); - MemberExpr *ParentMember = dyn_cast(Node->getBase()); + auto *ParentMember = dyn_cast(Node->getBase()); FieldDecl *ParentDecl = ParentMember ? dyn_cast(ParentMember->getMemberDecl()) : nullptr; @@ -1699,7 +1733,7 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { OS << (Node->isArrow() ? "->" : "."); } - if (FieldDecl *FD = dyn_cast(Node->getMemberDecl())) + if (auto *FD = dyn_cast(Node->getMemberDecl())) if (FD->isAnonymousStructOrUnion()) return; @@ -1711,6 +1745,7 @@ void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { if (Node->hasExplicitTemplateArgs()) printTemplateArgumentList(OS, Node->template_arguments(), Policy); } + void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) { PrintExpr(Node->getBase()); OS << (Node->isArrow() ? "->isa" : ".isa"); @@ -1721,32 +1756,38 @@ void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { OS << "."; OS << Node->getAccessor().getName(); } + void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) { OS << '('; Node->getTypeAsWritten().print(OS, Policy); OS << ')'; PrintExpr(Node->getSubExpr()); } + void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) { OS << '('; Node->getType().print(OS, Policy); OS << ')'; PrintExpr(Node->getInitializer()); } + void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) { // No need to print anything, simply forward to the subexpression. PrintExpr(Node->getSubExpr()); } + void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) { PrintExpr(Node->getLHS()); OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " "; PrintExpr(Node->getRHS()); } + void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) { PrintExpr(Node->getLHS()); OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " "; PrintExpr(Node->getRHS()); } + void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) { PrintExpr(Node->getCond()); OS << " ? "; @@ -1763,6 +1804,7 @@ StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) { OS << " ?: "; PrintExpr(Node->getFalseExpr()); } + void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) { OS << "&&" << Node->getLabel()->getName(); } @@ -2095,7 +2137,7 @@ void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) { OS << cast(Node->getArg(0)->IgnoreImpCasts())->getString(); break; case UserDefinedLiteral::LOK_Template: { - DeclRefExpr *DRE = cast(Node->getCallee()->IgnoreImpCasts()); + const auto *DRE = cast(Node->getCallee()->IgnoreImpCasts()); const TemplateArgumentList *Args = cast(DRE->getDecl())->getTemplateSpecializationArgs(); assert(Args); @@ -2116,13 +2158,13 @@ void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) { } case UserDefinedLiteral::LOK_Integer: { // Print integer literal without suffix. - IntegerLiteral *Int = cast(Node->getCookedLiteral()); + const auto *Int = cast(Node->getCookedLiteral()); OS << Int->getValue().toString(10, /*isSigned*/false); break; } case UserDefinedLiteral::LOK_Floating: { // Print floating literal without suffix. - FloatingLiteral *Float = cast(Node->getCookedLiteral()); + auto *Float = cast(Node->getCookedLiteral()); PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false); break; } @@ -2235,9 +2277,11 @@ void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) { case LCK_This: OS << "this"; break; + case LCK_StarThis: OS << "*this"; break; + case LCK_ByRef: if (Node->getCaptureDefault() != LCD_ByRef || Node->isInitCapture(C)) OS << '&'; @@ -2247,6 +2291,7 @@ void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) { case LCK_ByCopy: OS << C->getCapturedVar()->getName(); break; + case LCK_VLAType: llvm_unreachable("VLA type in explicit captures."); } @@ -2260,7 +2305,7 @@ void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) { OS << " ("; CXXMethodDecl *Method = Node->getCallOperator(); NeedComma = false; - for (auto P : Method->parameters()) { + for (const auto *P : Method->parameters()) { if (NeedComma) { OS << ", "; } else { @@ -2279,8 +2324,7 @@ void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) { if (Node->isMutable()) OS << " mutable"; - const FunctionProtoType *Proto - = Method->getType()->getAs(); + auto *Proto = Method->getType()->getAs(); Proto->printExceptionSpecification(OS, Policy); // FIXME: Attributes @@ -2564,13 +2608,11 @@ void StmtPrinter::VisitCoawaitExpr(CoawaitExpr *S) { PrintExpr(S->getOperand()); } - void StmtPrinter::VisitDependentCoawaitExpr(DependentCoawaitExpr *S) { OS << "co_await "; PrintExpr(S->getOperand()); } - void StmtPrinter::VisitCoyieldExpr(CoyieldExpr *S) { OS << "co_yield "; PrintExpr(S->getOperand()); @@ -2703,7 +2745,7 @@ void StmtPrinter::VisitBlockExpr(BlockExpr *Node) { (*AI)->getType().print(OS, Policy, ParamStr); } - const FunctionProtoType *FT = cast(AFT); + const auto *FT = cast(AFT); if (FT->isVariadic()) { if (!BD->param_empty()) OS << ", "; OS << "..."; @@ -2750,4 +2792,4 @@ void Stmt::printPretty(raw_ostream &OS, PrinterHelper *Helper, //===----------------------------------------------------------------------===// // Implement virtual destructor. -PrinterHelper::~PrinterHelper() {} +PrinterHelper::~PrinterHelper() = default; diff --git a/lib/AST/TypePrinter.cpp b/lib/AST/TypePrinter.cpp index d46f8d3348..743e35e2dc 100644 --- a/lib/AST/TypePrinter.cpp +++ b/lib/AST/TypePrinter.cpp @@ -1,4 +1,4 @@ -//===--- TypePrinter.cpp - Pretty-Print Clang Types -----------------------===// +//===- TypePrinter.cpp - Pretty-Print Clang Types -------------------------===// // // The LLVM Compiler Infrastructure // @@ -14,19 +14,39 @@ #include "clang/AST/PrettyPrinter.h" #include "clang/AST/ASTContext.h" #include "clang/AST/Decl.h" +#include "clang/AST/DeclBase.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" +#include "clang/AST/NestedNameSpecifier.h" +#include "clang/AST/TemplateBase.h" +#include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" +#include "clang/Basic/AddressSpaces.h" +#include "clang/Basic/ExceptionSpecificationType.h" +#include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" +#include "clang/Basic/Specifiers.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" -#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/SaveAndRestore.h" #include "llvm/Support/raw_ostream.h" +#include +#include + using namespace clang; namespace { + /// \brief RAII object that enables printing of the ARC __strong lifetime /// qualifier. class IncludeStrongLifetimeRAII { @@ -35,7 +55,7 @@ namespace { public: explicit IncludeStrongLifetimeRAII(PrintingPolicy &Policy) - : Policy(Policy), Old(Policy.SuppressStrongLifetime) { + : Policy(Policy), Old(Policy.SuppressStrongLifetime) { if (!Policy.SuppressLifetimeQualifiers) Policy.SuppressStrongLifetime = false; } @@ -51,7 +71,7 @@ namespace { public: explicit ParamPolicyRAII(PrintingPolicy &Policy) - : Policy(Policy), Old(Policy.SuppressSpecifiers) { + : Policy(Policy), Old(Policy.SuppressSpecifiers) { Policy.SuppressSpecifiers = false; } @@ -82,13 +102,12 @@ namespace { class TypePrinter { PrintingPolicy Policy; unsigned Indentation; - bool HasEmptyPlaceHolder; - bool InsideCCAttribute; + bool HasEmptyPlaceHolder = false; + bool InsideCCAttribute = false; public: explicit TypePrinter(const PrintingPolicy &Policy, unsigned Indentation = 0) - : Policy(Policy), Indentation(Indentation), - HasEmptyPlaceHolder(false), InsideCCAttribute(false) { } + : Policy(Policy), Indentation(Indentation) {} void print(const Type *ty, Qualifiers qs, raw_ostream &OS, StringRef PlaceHolder); @@ -111,7 +130,8 @@ namespace { void print##CLASS##After(const CLASS##Type *T, raw_ostream &OS); #include "clang/AST/TypeNodes.def" }; -} + +} // namespace static void AppendTypeQualList(raw_ostream &OS, unsigned TypeQuals, bool HasRestrictKeyword) { @@ -169,10 +189,9 @@ bool TypePrinter::canPrefixQualifiers(const Type *T, bool CanPrefixQualifiers = false; NeedARCStrongQualifier = false; Type::TypeClass TC = T->getTypeClass(); - if (const AutoType *AT = dyn_cast(T)) + if (const auto *AT = dyn_cast(T)) TC = AT->desugar()->getTypeClass(); - if (const SubstTemplateTypeParmType *Subst - = dyn_cast(T)) + if (const auto *Subst = dyn_cast(T)) TC = Subst->getReplacementType()->getTypeClass(); switch (TC) { @@ -245,8 +264,7 @@ void TypePrinter::printBefore(QualType T, raw_ostream &OS) { // If we have cv1 T, where T is substituted for cv2 U, only print cv1 - cv2 // at this level. Qualifiers Quals = Split.Quals; - if (const SubstTemplateTypeParmType *Subst = - dyn_cast(Split.Ty)) + if (const auto *Subst = dyn_cast(Split.Ty)) Quals -= QualType(Subst, 0).getQualifiers(); printBefore(Split.Ty, Quals, OS); @@ -321,12 +339,14 @@ void TypePrinter::printBuiltinBefore(const BuiltinType *T, raw_ostream &OS) { OS << T->getName(Policy); spaceBeforePlaceHolder(OS); } -void TypePrinter::printBuiltinAfter(const BuiltinType *T, raw_ostream &OS) { } + +void TypePrinter::printBuiltinAfter(const BuiltinType *T, raw_ostream &OS) {} void TypePrinter::printComplexBefore(const ComplexType *T, raw_ostream &OS) { OS << "_Complex "; printBefore(T->getElementType(), OS); } + void TypePrinter::printComplexAfter(const ComplexType *T, raw_ostream &OS) { printAfter(T->getElementType(), OS); } @@ -341,6 +361,7 @@ void TypePrinter::printPointerBefore(const PointerType *T, raw_ostream &OS) { OS << '('; OS << '*'; } + void TypePrinter::printPointerAfter(const PointerType *T, raw_ostream &OS) { IncludeStrongLifetimeRAII Strong(Policy); SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false); @@ -357,6 +378,7 @@ void TypePrinter::printBlockPointerBefore(const BlockPointerType *T, printBefore(T->getPointeeType(), OS); OS << '^'; } + void TypePrinter::printBlockPointerAfter(const BlockPointerType *T, raw_ostream &OS) { SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false); @@ -374,6 +396,7 @@ void TypePrinter::printLValueReferenceBefore(const LValueReferenceType *T, OS << '('; OS << '&'; } + void TypePrinter::printLValueReferenceAfter(const LValueReferenceType *T, raw_ostream &OS) { IncludeStrongLifetimeRAII Strong(Policy); @@ -396,6 +419,7 @@ void TypePrinter::printRValueReferenceBefore(const RValueReferenceType *T, OS << '('; OS << "&&"; } + void TypePrinter::printRValueReferenceAfter(const RValueReferenceType *T, raw_ostream &OS) { IncludeStrongLifetimeRAII Strong(Policy); @@ -423,6 +447,7 @@ void TypePrinter::printMemberPointerBefore(const MemberPointerType *T, OS << "::*"; } + void TypePrinter::printMemberPointerAfter(const MemberPointerType *T, raw_ostream &OS) { IncludeStrongLifetimeRAII Strong(Policy); @@ -440,6 +465,7 @@ void TypePrinter::printConstantArrayBefore(const ConstantArrayType *T, SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false); printBefore(T->getElementType(), OS); } + void TypePrinter::printConstantArrayAfter(const ConstantArrayType *T, raw_ostream &OS) { OS << '['; @@ -462,6 +488,7 @@ void TypePrinter::printIncompleteArrayBefore(const IncompleteArrayType *T, SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false); printBefore(T->getElementType(), OS); } + void TypePrinter::printIncompleteArrayAfter(const IncompleteArrayType *T, raw_ostream &OS) { OS << "[]"; @@ -474,6 +501,7 @@ void TypePrinter::printVariableArrayBefore(const VariableArrayType *T, SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false); printBefore(T->getElementType(), OS); } + void TypePrinter::printVariableArrayAfter(const VariableArrayType *T, raw_ostream &OS) { OS << '['; @@ -499,6 +527,7 @@ void TypePrinter::printAdjustedBefore(const AdjustedType *T, raw_ostream &OS) { // invisible. printBefore(T->getAdjustedType(), OS); } + void TypePrinter::printAdjustedAfter(const AdjustedType *T, raw_ostream &OS) { printAfter(T->getAdjustedType(), OS); } @@ -507,6 +536,7 @@ void TypePrinter::printDecayedBefore(const DecayedType *T, raw_ostream &OS) { // Print as though it's a pointer. printAdjustedBefore(T, OS); } + void TypePrinter::printDecayedAfter(const DecayedType *T, raw_ostream &OS) { printAdjustedAfter(T, OS); } @@ -518,6 +548,7 @@ void TypePrinter::printDependentSizedArrayBefore( SaveAndRestore NonEmptyPH(HasEmptyPlaceHolder, false); printBefore(T->getElementType(), OS); } + void TypePrinter::printDependentSizedArrayAfter( const DependentSizedArrayType *T, raw_ostream &OS) { @@ -532,6 +563,7 @@ void TypePrinter::printDependentAddressSpaceBefore( const DependentAddressSpaceType *T, raw_ostream &OS) { printBefore(T->getPointeeType(), OS); } + void TypePrinter::printDependentAddressSpaceAfter( const DependentAddressSpaceType *T, raw_ostream &OS) { OS << " __attribute__((address_space("; @@ -546,6 +578,7 @@ void TypePrinter::printDependentSizedExtVectorBefore( raw_ostream &OS) { printBefore(T->getElementType(), OS); } + void TypePrinter::printDependentSizedExtVectorAfter( const DependentSizedExtVectorType *T, raw_ostream &OS) { @@ -592,6 +625,7 @@ void TypePrinter::printVectorBefore(const VectorType *T, raw_ostream &OS) { } } } + void TypePrinter::printVectorAfter(const VectorType *T, raw_ostream &OS) { printAfter(T->getElementType(), OS); } @@ -600,6 +634,7 @@ void TypePrinter::printExtVectorBefore(const ExtVectorType *T, raw_ostream &OS) { printBefore(T->getElementType(), OS); } + void TypePrinter::printExtVectorAfter(const ExtVectorType *T, raw_ostream &OS) { printAfter(T->getElementType(), OS); OS << " __attribute__((ext_vector_type("; @@ -611,7 +646,6 @@ void FunctionProtoType::printExceptionSpecification(raw_ostream &OS, const PrintingPolicy &Policy) const { - if (hasDynamicExceptionSpec()) { OS << " throw("; if (getExceptionSpecType() == EST_MSAny) @@ -650,7 +684,7 @@ void TypePrinter::printFunctionProtoBefore(const FunctionProtoType *T, } } -llvm::StringRef clang::getParameterABISpelling(ParameterABI ABI) { +StringRef clang::getParameterABISpelling(ParameterABI ABI) { switch (ABI) { case ParameterABI::Ordinary: llvm_unreachable("asking for spelling of ordinary parameter ABI"); @@ -813,6 +847,7 @@ void TypePrinter::printFunctionNoProtoBefore(const FunctionNoProtoType *T, if (!PrevPHIsEmpty.get()) OS << '('; } + void TypePrinter::printFunctionNoProtoAfter(const FunctionNoProtoType *T, raw_ostream &OS) { // If needed for precedence reasons, wrap the inner part in grouping parens. @@ -842,13 +877,15 @@ void TypePrinter::printUnresolvedUsingBefore(const UnresolvedUsingType *T, raw_ostream &OS) { printTypeSpec(T->getDecl(), OS); } + void TypePrinter::printUnresolvedUsingAfter(const UnresolvedUsingType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} void TypePrinter::printTypedefBefore(const TypedefType *T, raw_ostream &OS) { printTypeSpec(T->getDecl(), OS); } -void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) { } + +void TypePrinter::printTypedefAfter(const TypedefType *T, raw_ostream &OS) {} void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T, raw_ostream &OS) { @@ -857,8 +894,9 @@ void TypePrinter::printTypeOfExprBefore(const TypeOfExprType *T, T->getUnderlyingExpr()->printPretty(OS, nullptr, Policy); spaceBeforePlaceHolder(OS); } + void TypePrinter::printTypeOfExprAfter(const TypeOfExprType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) { OS << "typeof("; @@ -866,7 +904,8 @@ void TypePrinter::printTypeOfBefore(const TypeOfType *T, raw_ostream &OS) { OS << ')'; spaceBeforePlaceHolder(OS); } -void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) { } + +void TypePrinter::printTypeOfAfter(const TypeOfType *T, raw_ostream &OS) {} void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) { OS << "decltype("; @@ -875,7 +914,8 @@ void TypePrinter::printDecltypeBefore(const DecltypeType *T, raw_ostream &OS) { OS << ')'; spaceBeforePlaceHolder(OS); } -void TypePrinter::printDecltypeAfter(const DecltypeType *T, raw_ostream &OS) { } + +void TypePrinter::printDecltypeAfter(const DecltypeType *T, raw_ostream &OS) {} void TypePrinter::printUnaryTransformBefore(const UnaryTransformType *T, raw_ostream &OS) { @@ -892,6 +932,7 @@ void TypePrinter::printUnaryTransformBefore(const UnaryTransformType *T, printBefore(T->getBaseType(), OS); } + void TypePrinter::printUnaryTransformAfter(const UnaryTransformType *T, raw_ostream &OS) { IncludeStrongLifetimeRAII Strong(Policy); @@ -917,6 +958,7 @@ void TypePrinter::printAutoBefore(const AutoType *T, raw_ostream &OS) { spaceBeforePlaceHolder(OS); } } + void TypePrinter::printAutoAfter(const AutoType *T, raw_ostream &OS) { // If the type has been deduced, do not print 'auto'. if (!T->getDeducedType().isNull()) @@ -934,6 +976,7 @@ void TypePrinter::printDeducedTemplateSpecializationBefore( spaceBeforePlaceHolder(OS); } } + void TypePrinter::printDeducedTemplateSpecializationAfter( const DeducedTemplateSpecializationType *T, raw_ostream &OS) { // If the type has been deduced, print the deduced type. @@ -949,7 +992,8 @@ void TypePrinter::printAtomicBefore(const AtomicType *T, raw_ostream &OS) { OS << ')'; spaceBeforePlaceHolder(OS); } -void TypePrinter::printAtomicAfter(const AtomicType *T, raw_ostream &OS) { } + +void TypePrinter::printAtomicAfter(const AtomicType *T, raw_ostream &OS) {} void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) { IncludeStrongLifetimeRAII Strong(Policy); @@ -963,15 +1007,15 @@ void TypePrinter::printPipeBefore(const PipeType *T, raw_ostream &OS) { spaceBeforePlaceHolder(OS); } -void TypePrinter::printPipeAfter(const PipeType *T, raw_ostream &OS) { -} +void TypePrinter::printPipeAfter(const PipeType *T, raw_ostream &OS) {} + /// Appends the given scope to the end of a string. void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) { if (DC->isTranslationUnit()) return; if (DC->isFunctionOrMethod()) return; AppendScope(DC->getParent(), OS); - if (NamespaceDecl *NS = dyn_cast(DC)) { + if (const auto *NS = dyn_cast(DC)) { if (Policy.SuppressUnwrittenScope && (NS->isAnonymousNamespace() || NS->isInline())) return; @@ -979,14 +1023,13 @@ void TypePrinter::AppendScope(DeclContext *DC, raw_ostream &OS) { OS << NS->getName() << "::"; else OS << "(anonymous namespace)::"; - } else if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(DC)) { + } else if (const auto *Spec = dyn_cast(DC)) { IncludeStrongLifetimeRAII Strong(Policy); OS << Spec->getIdentifier()->getName(); const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); printTemplateArgumentList(OS, TemplateArgs.asArray(), Policy); OS << "::"; - } else if (TagDecl *Tag = dyn_cast(DC)) { + } else if (const auto *Tag = dyn_cast(DC)) { if (TypedefNameDecl *Typedef = Tag->getTypedefNameForAnonDecl()) OS << Typedef->getIdentifier()->getName() << "::"; else if (Tag->getIdentifier()) @@ -1059,8 +1102,7 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) { // If this is a class template specialization, print the template // arguments. - if (ClassTemplateSpecializationDecl *Spec - = dyn_cast(D)) { + if (const auto *Spec = dyn_cast(D)) { ArrayRef Args; if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) { const TemplateSpecializationType *TST = @@ -1080,12 +1122,14 @@ void TypePrinter::printTag(TagDecl *D, raw_ostream &OS) { void TypePrinter::printRecordBefore(const RecordType *T, raw_ostream &OS) { printTag(T->getDecl(), OS); } -void TypePrinter::printRecordAfter(const RecordType *T, raw_ostream &OS) { } + +void TypePrinter::printRecordAfter(const RecordType *T, raw_ostream &OS) {} void TypePrinter::printEnumBefore(const EnumType *T, raw_ostream &OS) { printTag(T->getDecl(), OS); } -void TypePrinter::printEnumAfter(const EnumType *T, raw_ostream &OS) { } + +void TypePrinter::printEnumAfter(const EnumType *T, raw_ostream &OS) {} void TypePrinter::printTemplateTypeParmBefore(const TemplateTypeParmType *T, raw_ostream &OS) { @@ -1095,8 +1139,9 @@ void TypePrinter::printTemplateTypeParmBefore(const TemplateTypeParmType *T, OS << "type-parameter-" << T->getDepth() << '-' << T->getIndex(); spaceBeforePlaceHolder(OS); } + void TypePrinter::printTemplateTypeParmAfter(const TemplateTypeParmType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} void TypePrinter::printSubstTemplateTypeParmBefore( const SubstTemplateTypeParmType *T, @@ -1104,6 +1149,7 @@ void TypePrinter::printSubstTemplateTypeParmBefore( IncludeStrongLifetimeRAII Strong(Policy); printBefore(T->getReplacementType(), OS); } + void TypePrinter::printSubstTemplateTypeParmAfter( const SubstTemplateTypeParmType *T, raw_ostream &OS) { @@ -1117,6 +1163,7 @@ void TypePrinter::printSubstTemplateTypeParmPackBefore( IncludeStrongLifetimeRAII Strong(Policy); printTemplateTypeParmBefore(T->getReplacedParameter(), OS); } + void TypePrinter::printSubstTemplateTypeParmPackAfter( const SubstTemplateTypeParmPackType *T, raw_ostream &OS) { @@ -1133,16 +1180,18 @@ void TypePrinter::printTemplateSpecializationBefore( printTemplateArgumentList(OS, T->template_arguments(), Policy); spaceBeforePlaceHolder(OS); } + void TypePrinter::printTemplateSpecializationAfter( const TemplateSpecializationType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} void TypePrinter::printInjectedClassNameBefore(const InjectedClassNameType *T, raw_ostream &OS) { printTemplateSpecializationBefore(T->getInjectedTST(), OS); } + void TypePrinter::printInjectedClassNameAfter(const InjectedClassNameType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} void TypePrinter::printElaboratedBefore(const ElaboratedType *T, raw_ostream &OS) { @@ -1152,7 +1201,7 @@ void TypePrinter::printElaboratedBefore(const ElaboratedType *T, OS << TypeWithKeyword::getKeywordName(T->getKeyword()); if (T->getKeyword() != ETK_None) OS << " "; - NestedNameSpecifier* Qualifier = T->getQualifier(); + NestedNameSpecifier *Qualifier = T->getQualifier(); if (Qualifier) Qualifier->print(OS, Policy); } @@ -1160,6 +1209,7 @@ void TypePrinter::printElaboratedBefore(const ElaboratedType *T, ElaboratedTypePolicyRAII PolicyRAII(Policy); printBefore(T->getNamedType(), OS); } + void TypePrinter::printElaboratedAfter(const ElaboratedType *T, raw_ostream &OS) { ElaboratedTypePolicyRAII PolicyRAII(Policy); @@ -1173,6 +1223,7 @@ void TypePrinter::printParenBefore(const ParenType *T, raw_ostream &OS) { } else printBefore(T->getInnerType(), OS); } + void TypePrinter::printParenAfter(const ParenType *T, raw_ostream &OS) { if (!HasEmptyPlaceHolder && !isa(T->getInnerType())) { OS << ')'; @@ -1192,8 +1243,9 @@ void TypePrinter::printDependentNameBefore(const DependentNameType *T, OS << T->getIdentifier()->getName(); spaceBeforePlaceHolder(OS); } + void TypePrinter::printDependentNameAfter(const DependentNameType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} void TypePrinter::printDependentTemplateSpecializationBefore( const DependentTemplateSpecializationType *T, raw_ostream &OS) { @@ -1211,12 +1263,13 @@ void TypePrinter::printDependentTemplateSpecializationBefore( } void TypePrinter::printDependentTemplateSpecializationAfter( - const DependentTemplateSpecializationType *T, raw_ostream &OS) { } + const DependentTemplateSpecializationType *T, raw_ostream &OS) {} void TypePrinter::printPackExpansionBefore(const PackExpansionType *T, raw_ostream &OS) { printBefore(T->getPattern(), OS); } + void TypePrinter::printPackExpansionAfter(const PackExpansionType *T, raw_ostream &OS) { printAfter(T->getPattern(), OS); @@ -1325,9 +1378,9 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, OS << ')'; break; - case AttributedType::attr_vector_size: { + case AttributedType::attr_vector_size: OS << "__vector_size__("; - if (const VectorType *vector =T->getEquivalentType()->getAs()) { + if (const auto *vector = T->getEquivalentType()->getAs()) { OS << vector->getNumElements(); OS << " * sizeof("; print(vector->getElementType(), OS, StringRef()); @@ -1335,7 +1388,6 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, } OS << ')'; break; - } case AttributedType::attr_neon_vector_type: case AttributedType::attr_neon_polyvector_type: { @@ -1343,7 +1395,7 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, OS << "neon_vector_type("; else OS << "neon_polyvector_type("; - const VectorType *vector = T->getEquivalentType()->getAs(); + const auto *vector = T->getEquivalentType()->getAs(); OS << vector->getNumElements(); OS << ')'; break; @@ -1420,10 +1472,12 @@ void TypePrinter::printAttributedAfter(const AttributedType *T, OS << ')'; break; } + case AttributedType::attr_inteloclbicc: OS << "inteloclbicc"; break; case AttributedType::attr_preserve_most: OS << "preserve_most"; break; + case AttributedType::attr_preserve_all: OS << "preserve_all"; break; @@ -1436,8 +1490,9 @@ void TypePrinter::printObjCInterfaceBefore(const ObjCInterfaceType *T, OS << T->getDecl()->getName(); spaceBeforePlaceHolder(OS); } + void TypePrinter::printObjCInterfaceAfter(const ObjCInterfaceType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} void TypePrinter::printObjCTypeParamBefore(const ObjCTypeParamType *T, raw_ostream &OS) { @@ -1459,7 +1514,7 @@ void TypePrinter::printObjCTypeParamBefore(const ObjCTypeParamType *T, } void TypePrinter::printObjCTypeParamAfter(const ObjCTypeParamType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T, raw_ostream &OS) { @@ -1501,6 +1556,7 @@ void TypePrinter::printObjCObjectBefore(const ObjCObjectType *T, spaceBeforePlaceHolder(OS); } + void TypePrinter::printObjCObjectAfter(const ObjCObjectType *T, raw_ostream &OS) { if (T->qual_empty() && T->isUnspecializedAsWritten() && @@ -1522,7 +1578,7 @@ void TypePrinter::printObjCObjectPointerBefore(const ObjCObjectPointerType *T, } void TypePrinter::printObjCObjectPointerAfter(const ObjCObjectPointerType *T, - raw_ostream &OS) { } + raw_ostream &OS) {} static const TemplateArgument &getArgument(const TemplateArgument &A) { return A; } -- 2.40.0