[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
This revision was automatically updated to reflect the committed changes. Closed by commit rC351172: [ASTDump] NFC: Move dump of type nodes to NodeDumper (authored by steveire, committed by ). Changed prior to commit: https://reviews.llvm.org/D56642?vs=181632=181738#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56642/new/ https://reviews.llvm.org/D56642 Files: include/clang/AST/TextNodeDumper.h lib/AST/ASTDumper.cpp lib/AST/TextNodeDumper.cpp Index: include/clang/AST/TextNodeDumper.h === --- include/clang/AST/TextNodeDumper.h +++ include/clang/AST/TextNodeDumper.h @@ -22,6 +22,7 @@ #include "clang/AST/ExprCXX.h" #include "clang/AST/StmtVisitor.h" #include "clang/AST/TemplateArgumentVisitor.h" +#include "clang/AST/TypeVisitor.h" namespace clang { @@ -127,7 +128,8 @@ const comments::FullComment *>, public ConstAttrVisitor, public ConstTemplateArgumentVisitor, - public ConstStmtVisitor { + public ConstStmtVisitor, + public TypeVisitor { raw_ostream const bool ShowColors; @@ -259,6 +261,26 @@ void VisitObjCIvarRefExpr(const ObjCIvarRefExpr *Node); void VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node); + void VisitRValueReferenceType(const ReferenceType *T); + void VisitArrayType(const ArrayType *T); + void VisitConstantArrayType(const ConstantArrayType *T); + void VisitVariableArrayType(const VariableArrayType *T); + void VisitDependentSizedArrayType(const DependentSizedArrayType *T); + void VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T); + void VisitVectorType(const VectorType *T); + void VisitFunctionType(const FunctionType *T); + void VisitFunctionProtoType(const FunctionProtoType *T); + void VisitUnresolvedUsingType(const UnresolvedUsingType *T); + void VisitTypedefType(const TypedefType *T); + void VisitUnaryTransformType(const UnaryTransformType *T); + void VisitTagType(const TagType *T); + void VisitTemplateTypeParmType(const TemplateTypeParmType *T); + void VisitAutoType(const AutoType *T); + void VisitTemplateSpecializationType(const TemplateSpecializationType *T); + void VisitInjectedClassNameType(const InjectedClassNameType *T); + void VisitObjCInterfaceType(const ObjCInterfaceType *T); + void VisitPackExpansionType(const PackExpansionType *T); + private: void dumpCXXTemporary(const CXXTemporary *Temporary); }; Index: lib/AST/ASTDumper.cpp === --- lib/AST/ASTDumper.cpp +++ lib/AST/ASTDumper.cpp @@ -134,99 +134,39 @@ void VisitReferenceType(const ReferenceType *T) { dumpTypeAsChild(T->getPointeeType()); } -void VisitRValueReferenceType(const ReferenceType *T) { - if (T->isSpelledAsLValue()) -OS << " written as lvalue reference"; - VisitReferenceType(T); -} void VisitMemberPointerType(const MemberPointerType *T) { dumpTypeAsChild(T->getClass()); dumpTypeAsChild(T->getPointeeType()); } void VisitArrayType(const ArrayType *T) { - switch (T->getSizeModifier()) { -case ArrayType::Normal: break; -case ArrayType::Static: OS << " static"; break; -case ArrayType::Star: OS << " *"; break; - } - OS << " " << T->getIndexTypeQualifiers().getAsString(); dumpTypeAsChild(T->getElementType()); } -void VisitConstantArrayType(const ConstantArrayType *T) { - OS << " " << T->getSize(); - VisitArrayType(T); -} void VisitVariableArrayType(const VariableArrayType *T) { - OS << " "; - NodeDumper.dumpSourceRange(T->getBracketsRange()); VisitArrayType(T); dumpStmt(T->getSizeExpr()); } void VisitDependentSizedArrayType(const DependentSizedArrayType *T) { - switch (T->getSizeModifier()) { -case ArrayType::Normal: break; -case ArrayType::Static: OS << " static"; break; -case ArrayType::Star: OS << " *"; break; - } - OS << " " << T->getIndexTypeQualifiers().getAsString(); - OS << " "; - NodeDumper.dumpSourceRange(T->getBracketsRange()); dumpTypeAsChild(T->getElementType()); dumpStmt(T->getSizeExpr()); } void VisitDependentSizedExtVectorType( const DependentSizedExtVectorType *T) { - OS << " "; - NodeDumper.dumpLocation(T->getAttributeLoc()); dumpTypeAsChild(T->getElementType()); dumpStmt(T->getSizeExpr()); } void VisitVectorType(const VectorType *T) { - switch (T->getVectorKind()) { -case VectorType::GenericVector: break; -case VectorType::AltiVecVector: OS << " altivec"; break; -case VectorType::AltiVecPixel: OS << " altivec pixel"; break; -case VectorType::AltiVecBool: OS << " altivec bool"; break; -case VectorType::NeonVector: OS << " neon"; break; -case
[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM aside from `auto` nits. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56642/new/ https://reviews.llvm.org/D56642 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
steveire updated this revision to Diff 181632. steveire added a comment. Nits Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56642/new/ https://reviews.llvm.org/D56642 Files: include/clang/AST/TextNodeDumper.h lib/AST/ASTDumper.cpp lib/AST/TextNodeDumper.cpp Index: lib/AST/TextNodeDumper.cpp === --- lib/AST/TextNodeDumper.cpp +++ lib/AST/TextNodeDumper.cpp @@ -12,6 +12,7 @@ //===--===// #include "clang/AST/TextNodeDumper.h" +#include "clang/AST/DeclTemplate.h" #include "clang/AST/LocInfoType.h" using namespace clang; @@ -170,6 +171,8 @@ OS << " contains_unexpanded_pack"; if (T->isFromAST()) OS << " imported"; + + TypeVisitor::Visit(T); } void TextNodeDumper::Visit(QualType T) { @@ -886,3 +889,161 @@ void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) { OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no"); } + +void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) { + if (T->isSpelledAsLValue()) +OS << " written as lvalue reference"; +} + +void TextNodeDumper::VisitArrayType(const ArrayType *T) { + switch (T->getSizeModifier()) { + case ArrayType::Normal: +break; + case ArrayType::Static: +OS << " static"; +break; + case ArrayType::Star: +OS << " *"; +break; + } + OS << " " << T->getIndexTypeQualifiers().getAsString(); +} + +void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) { + OS << " " << T->getSize(); + VisitArrayType(T); +} + +void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) { + OS << " "; + dumpSourceRange(T->getBracketsRange()); + VisitArrayType(T); +} + +void TextNodeDumper::VisitDependentSizedArrayType( +const DependentSizedArrayType *T) { + VisitArrayType(T); + OS << " "; + dumpSourceRange(T->getBracketsRange()); +} + +void TextNodeDumper::VisitDependentSizedExtVectorType( +const DependentSizedExtVectorType *T) { + OS << " "; + dumpLocation(T->getAttributeLoc()); +} + +void TextNodeDumper::VisitVectorType(const VectorType *T) { + switch (T->getVectorKind()) { + case VectorType::GenericVector: +break; + case VectorType::AltiVecVector: +OS << " altivec"; +break; + case VectorType::AltiVecPixel: +OS << " altivec pixel"; +break; + case VectorType::AltiVecBool: +OS << " altivec bool"; +break; + case VectorType::NeonVector: +OS << " neon"; +break; + case VectorType::NeonPolyVector: +OS << " neon poly"; +break; + } + OS << " " << T->getNumElements(); +} + +void TextNodeDumper::VisitFunctionType(const FunctionType *T) { + auto EI = T->getExtInfo(); + if (EI.getNoReturn()) +OS << " noreturn"; + if (EI.getProducesResult()) +OS << " produces_result"; + if (EI.getHasRegParm()) +OS << " regparm " << EI.getRegParm(); + OS << " " << FunctionType::getNameForCallConv(EI.getCC()); +} + +void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) { + auto EPI = T->getExtProtoInfo(); + if (EPI.HasTrailingReturn) +OS << " trailing_return"; + if (T->isConst()) +OS << " const"; + if (T->isVolatile()) +OS << " volatile"; + if (T->isRestrict()) +OS << " restrict"; + switch (EPI.RefQualifier) { + case RQ_None: +break; + case RQ_LValue: +OS << " &"; +break; + case RQ_RValue: +OS << " &&"; +break; + } + // FIXME: Exception specification. + // FIXME: Consumed parameters. + VisitFunctionType(T); +} + +void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitTypedefType(const TypedefType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) { + switch (T->getUTTKind()) { + case UnaryTransformType::EnumUnderlyingType: +OS << " underlying_type"; +break; + } +} + +void TextNodeDumper::VisitTagType(const TagType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { + OS << " depth " << T->getDepth() << " index " << T->getIndex(); + if (T->isParameterPack()) +OS << " pack"; + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitAutoType(const AutoType *T) { + if (T->isDecltypeAuto()) +OS << " decltype(auto)"; + if (!T->isDeduced()) +OS << " undeduced"; +} + +void TextNodeDumper::VisitTemplateSpecializationType( +const TemplateSpecializationType *T) { + if (T->isTypeAlias()) +OS << " alias"; + OS << " "; + T->getTemplateName().dump(OS); +} + +void TextNodeDumper::VisitInjectedClassNameType( +const InjectedClassNameType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) { + dumpDeclRef(T->getDecl()); +} + +void
[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
aaron.ballman added inline comments. Comment at: lib/AST/ASTDumper.cpp:145 void VisitVariableArrayType(const VariableArrayType *T) { - OS << " "; - NodeDumper.dumpSourceRange(T->getBracketsRange()); - VisitArrayType(T); + dumpTypeAsChild(T->getElementType()); dumpStmt(T->getSizeExpr()); steveire wrote: > aaron.ballman wrote: > > Why this approach instead of deferring to `VisitArrayType()` as before? I > > prefer calling the Visit function rather than reimplementing the > > functionality because we may decide to later improve the base class > > printing and expect subclasses to automatically pick that up. WDYT? > I think it's more clear to read what each visit method does, but I don't feel > strongly about it. I can change this if you do. Given that there's an established type hierarchy, I prefer calling the `Visit()` function for the superclass rather than reimplementing. The extra indirection wasn't too annoying with the old code, so it's unlikely to be too problematic with the new code (and if it is, then we'll have reason to change). Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56642/new/ https://reviews.llvm.org/D56642 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
steveire marked an inline comment as done. steveire added inline comments. Comment at: lib/AST/ASTDumper.cpp:145 void VisitVariableArrayType(const VariableArrayType *T) { - OS << " "; - NodeDumper.dumpSourceRange(T->getBracketsRange()); - VisitArrayType(T); + dumpTypeAsChild(T->getElementType()); dumpStmt(T->getSizeExpr()); aaron.ballman wrote: > Why this approach instead of deferring to `VisitArrayType()` as before? I > prefer calling the Visit function rather than reimplementing the > functionality because we may decide to later improve the base class printing > and expect subclasses to automatically pick that up. WDYT? I think it's more clear to read what each visit method does, but I don't feel strongly about it. I can change this if you do. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56642/new/ https://reviews.llvm.org/D56642 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
aaron.ballman added a comment. Mostly looks good (a few minor nits), but I did have a design question about whether we should prefer calling a `Visit` method for type hierarchies instead of reimplementing the functionality. Comment at: lib/AST/ASTDumper.cpp:145 void VisitVariableArrayType(const VariableArrayType *T) { - OS << " "; - NodeDumper.dumpSourceRange(T->getBracketsRange()); - VisitArrayType(T); + dumpTypeAsChild(T->getElementType()); dumpStmt(T->getSizeExpr()); Why this approach instead of deferring to `VisitArrayType()` as before? I prefer calling the Visit function rather than reimplementing the functionality because we may decide to later improve the base class printing and expect subclasses to automatically pick that up. WDYT? Comment at: lib/AST/ASTDumper.cpp:164 void VisitFunctionProtoType(const FunctionProtoType *T) { - auto EPI = T->getExtProtoInfo(); - if (EPI.HasTrailingReturn) OS << " trailing_return"; - - if (!T->getTypeQuals().empty()) -OS << " " << T->getTypeQuals().getAsString(); - - switch (EPI.RefQualifier) { -case RQ_None: break; -case RQ_LValue: OS << " &"; break; -case RQ_RValue: OS << " &&"; break; - } - // FIXME: Exception specification. - // FIXME: Consumed parameters. - VisitFunctionType(T); + dumpTypeAsChild(T->getReturnType()); for (QualType PT : T->getParamTypes()) Why this approach as opposed to deferring to `VisitFunctionType()` as before? Comment at: lib/AST/TextNodeDumper.cpp:15 #include "clang/AST/TextNodeDumper.h" +#include "clang/AST/DeclTemplate.h" Remove newline Comment at: lib/AST/TextNodeDumper.cpp:960 +void TextNodeDumper::VisitFunctionType(const FunctionType *T) { + auto EI = T->getExtInfo(); + if (EI.getNoReturn()) It'd be nice to remove this use of `auto`. Comment at: lib/AST/TextNodeDumper.cpp:971 +void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) { + auto EPI = T->getExtProtoInfo(); + if (EPI.HasTrailingReturn) It'd be nice to remove this use of `auto`. Comment at: lib/AST/TextNodeDumper.cpp:1047 +void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) { + if (auto N = T->getNumExpansions()) +OS << " expansions " << *N; It'd be nice to remove this use of `auto`. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56642/new/ https://reviews.llvm.org/D56642 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
steveire updated this revision to Diff 181475. steveire added a comment. Update Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56642/new/ https://reviews.llvm.org/D56642 Files: include/clang/AST/TextNodeDumper.h lib/AST/ASTDumper.cpp lib/AST/TextNodeDumper.cpp Index: lib/AST/TextNodeDumper.cpp === --- lib/AST/TextNodeDumper.cpp +++ lib/AST/TextNodeDumper.cpp @@ -13,6 +13,7 @@ #include "clang/AST/TextNodeDumper.h" +#include "clang/AST/DeclTemplate.h" #include "clang/AST/LocInfoType.h" using namespace clang; @@ -170,6 +171,8 @@ OS << " contains_unexpanded_pack"; if (T->isFromAST()) OS << " imported"; + + TypeVisitor::Visit(T); } void TextNodeDumper::Visit(QualType T) { @@ -886,3 +889,161 @@ void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) { OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no"); } + +void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) { + if (T->isSpelledAsLValue()) +OS << " written as lvalue reference"; +} + +void TextNodeDumper::VisitArrayType(const ArrayType *T) { + switch (T->getSizeModifier()) { + case ArrayType::Normal: +break; + case ArrayType::Static: +OS << " static"; +break; + case ArrayType::Star: +OS << " *"; +break; + } + OS << " " << T->getIndexTypeQualifiers().getAsString(); +} + +void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) { + OS << " " << T->getSize(); + VisitArrayType(T); +} + +void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) { + OS << " "; + dumpSourceRange(T->getBracketsRange()); + VisitArrayType(T); +} + +void TextNodeDumper::VisitDependentSizedArrayType( +const DependentSizedArrayType *T) { + VisitArrayType(T); + OS << " "; + dumpSourceRange(T->getBracketsRange()); +} + +void TextNodeDumper::VisitDependentSizedExtVectorType( +const DependentSizedExtVectorType *T) { + OS << " "; + dumpLocation(T->getAttributeLoc()); +} + +void TextNodeDumper::VisitVectorType(const VectorType *T) { + switch (T->getVectorKind()) { + case VectorType::GenericVector: +break; + case VectorType::AltiVecVector: +OS << " altivec"; +break; + case VectorType::AltiVecPixel: +OS << " altivec pixel"; +break; + case VectorType::AltiVecBool: +OS << " altivec bool"; +break; + case VectorType::NeonVector: +OS << " neon"; +break; + case VectorType::NeonPolyVector: +OS << " neon poly"; +break; + } + OS << " " << T->getNumElements(); +} + +void TextNodeDumper::VisitFunctionType(const FunctionType *T) { + auto EI = T->getExtInfo(); + if (EI.getNoReturn()) +OS << " noreturn"; + if (EI.getProducesResult()) +OS << " produces_result"; + if (EI.getHasRegParm()) +OS << " regparm " << EI.getRegParm(); + OS << " " << FunctionType::getNameForCallConv(EI.getCC()); +} + +void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) { + auto EPI = T->getExtProtoInfo(); + if (EPI.HasTrailingReturn) +OS << " trailing_return"; + if (T->isConst()) +OS << " const"; + if (T->isVolatile()) +OS << " volatile"; + if (T->isRestrict()) +OS << " restrict"; + switch (EPI.RefQualifier) { + case RQ_None: +break; + case RQ_LValue: +OS << " &"; +break; + case RQ_RValue: +OS << " &&"; +break; + } + // FIXME: Exception specification. + // FIXME: Consumed parameters. + VisitFunctionType(T); +} + +void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitTypedefType(const TypedefType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) { + switch (T->getUTTKind()) { + case UnaryTransformType::EnumUnderlyingType: +OS << " underlying_type"; +break; + } +} + +void TextNodeDumper::VisitTagType(const TagType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { + OS << " depth " << T->getDepth() << " index " << T->getIndex(); + if (T->isParameterPack()) +OS << " pack"; + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitAutoType(const AutoType *T) { + if (T->isDecltypeAuto()) +OS << " decltype(auto)"; + if (!T->isDeduced()) +OS << " undeduced"; +} + +void TextNodeDumper::VisitTemplateSpecializationType( +const TemplateSpecializationType *T) { + if (T->isTypeAlias()) +OS << " alias"; + OS << " "; + T->getTemplateName().dump(OS); +} + +void TextNodeDumper::VisitInjectedClassNameType( +const InjectedClassNameType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) { + if (auto N = T->getNumExpansions()) +
[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
steveire updated this revision to Diff 181452. steveire added a comment. Format Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D56642/new/ https://reviews.llvm.org/D56642 Files: include/clang/AST/TextNodeDumper.h lib/AST/ASTDumper.cpp lib/AST/TextNodeDumper.cpp Index: lib/AST/TextNodeDumper.cpp === --- lib/AST/TextNodeDumper.cpp +++ lib/AST/TextNodeDumper.cpp @@ -13,6 +13,7 @@ #include "clang/AST/TextNodeDumper.h" +#include "clang/AST/DeclTemplate.h" #include "clang/AST/LocInfoType.h" using namespace clang; @@ -170,6 +171,8 @@ OS << " contains_unexpanded_pack"; if (T->isFromAST()) OS << " imported"; + + TypeVisitor::Visit(T); } void TextNodeDumper::Visit(QualType T) { @@ -886,3 +889,161 @@ void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) { OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no"); } + +void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) { + if (T->isSpelledAsLValue()) +OS << " written as lvalue reference"; +} + +void TextNodeDumper::VisitArrayType(const ArrayType *T) { + switch (T->getSizeModifier()) { + case ArrayType::Normal: +break; + case ArrayType::Static: +OS << " static"; +break; + case ArrayType::Star: +OS << " *"; +break; + } + OS << " " << T->getIndexTypeQualifiers().getAsString(); +} + +void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) { + OS << " " << T->getSize(); + VisitArrayType(T); +} + +void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) { + OS << " "; + dumpSourceRange(T->getBracketsRange()); + VisitArrayType(T); +} + +void TextNodeDumper::VisitDependentSizedArrayType( +const DependentSizedArrayType *T) { + VisitArrayType(T); + OS << " "; + dumpSourceRange(T->getBracketsRange()); +} + +void TextNodeDumper::VisitDependentSizedExtVectorType( +const DependentSizedExtVectorType *T) { + OS << " "; + dumpLocation(T->getAttributeLoc()); +} + +void TextNodeDumper::VisitVectorType(const VectorType *T) { + switch (T->getVectorKind()) { + case VectorType::GenericVector: +break; + case VectorType::AltiVecVector: +OS << " altivec"; +break; + case VectorType::AltiVecPixel: +OS << " altivec pixel"; +break; + case VectorType::AltiVecBool: +OS << " altivec bool"; +break; + case VectorType::NeonVector: +OS << " neon"; +break; + case VectorType::NeonPolyVector: +OS << " neon poly"; +break; + } + OS << " " << T->getNumElements(); +} + +void TextNodeDumper::VisitFunctionType(const FunctionType *T) { + auto EI = T->getExtInfo(); + if (EI.getNoReturn()) +OS << " noreturn"; + if (EI.getProducesResult()) +OS << " produces_result"; + if (EI.getHasRegParm()) +OS << " regparm " << EI.getRegParm(); + OS << " " << FunctionType::getNameForCallConv(EI.getCC()); +} + +void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) { + auto EPI = T->getExtProtoInfo(); + if (EPI.HasTrailingReturn) +OS << " trailing_return"; + if (T->isConst()) +OS << " const"; + if (T->isVolatile()) +OS << " volatile"; + if (T->isRestrict()) +OS << " restrict"; + switch (EPI.RefQualifier) { + case RQ_None: +break; + case RQ_LValue: +OS << " &"; +break; + case RQ_RValue: +OS << " &&"; +break; + } + // FIXME: Exception specification. + // FIXME: Consumed parameters. + VisitFunctionType(T); +} + +void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitTypedefType(const TypedefType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) { + switch (T->getUTTKind()) { + case UnaryTransformType::EnumUnderlyingType: +OS << " underlying_type"; +break; + } +} + +void TextNodeDumper::VisitTagType(const TagType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { + OS << " depth " << T->getDepth() << " index " << T->getIndex(); + if (T->isParameterPack()) +OS << " pack"; + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitAutoType(const AutoType *T) { + if (T->isDecltypeAuto()) +OS << " decltype(auto)"; + if (!T->isDeduced()) +OS << " undeduced"; +} + +void TextNodeDumper::VisitTemplateSpecializationType( +const TemplateSpecializationType *T) { + if (T->isTypeAlias()) +OS << " alias"; + OS << " "; + T->getTemplateName().dump(OS); +} + +void TextNodeDumper::VisitInjectedClassNameType( +const InjectedClassNameType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) { + if (auto N = T->getNumExpansions()) +
[PATCH] D56642: NFC: Move dump of type nodes to NodeDumper
steveire created this revision. steveire added a reviewer: aaron.ballman. Herald added a subscriber: cfe-commits. Repository: rC Clang https://reviews.llvm.org/D56642 Files: include/clang/AST/TextNodeDumper.h lib/AST/ASTDumper.cpp lib/AST/TextNodeDumper.cpp Index: lib/AST/TextNodeDumper.cpp === --- lib/AST/TextNodeDumper.cpp +++ lib/AST/TextNodeDumper.cpp @@ -13,6 +13,7 @@ #include "clang/AST/TextNodeDumper.h" +#include "clang/AST/DeclTemplate.h" #include "clang/AST/LocInfoType.h" using namespace clang; @@ -170,6 +171,8 @@ OS << " contains_unexpanded_pack"; if (T->isFromAST()) OS << " imported"; + + TypeVisitor::Visit(T); } void TextNodeDumper::Visit(QualType T) { @@ -886,3 +889,161 @@ void TextNodeDumper::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *Node) { OS << " " << (Node->getValue() ? "__objc_yes" : "__objc_no"); } + +void TextNodeDumper::VisitRValueReferenceType(const ReferenceType *T) { + if (T->isSpelledAsLValue()) +OS << " written as lvalue reference"; +} + +void TextNodeDumper::VisitArrayType(const ArrayType *T) { + switch (T->getSizeModifier()) { + case ArrayType::Normal: +break; + case ArrayType::Static: +OS << " static"; +break; + case ArrayType::Star: +OS << " *"; +break; + } + OS << " " << T->getIndexTypeQualifiers().getAsString(); +} + +void TextNodeDumper::VisitConstantArrayType(const ConstantArrayType *T) { + OS << " " << T->getSize(); + VisitArrayType(T); +} + +void TextNodeDumper::VisitVariableArrayType(const VariableArrayType *T) { + OS << " "; + dumpSourceRange(T->getBracketsRange()); + VisitArrayType(T); +} + +void TextNodeDumper::VisitDependentSizedArrayType( +const DependentSizedArrayType *T) { + VisitArrayType(T); + OS << " "; + dumpSourceRange(T->getBracketsRange()); +} + +void TextNodeDumper::VisitDependentSizedExtVectorType( +const DependentSizedExtVectorType *T) { + OS << " "; + dumpLocation(T->getAttributeLoc()); +} + +void TextNodeDumper::VisitVectorType(const VectorType *T) { + switch (T->getVectorKind()) { + case VectorType::GenericVector: +break; + case VectorType::AltiVecVector: +OS << " altivec"; +break; + case VectorType::AltiVecPixel: +OS << " altivec pixel"; +break; + case VectorType::AltiVecBool: +OS << " altivec bool"; +break; + case VectorType::NeonVector: +OS << " neon"; +break; + case VectorType::NeonPolyVector: +OS << " neon poly"; +break; + } + OS << " " << T->getNumElements(); +} + +void TextNodeDumper::VisitFunctionType(const FunctionType *T) { + auto EI = T->getExtInfo(); + if (EI.getNoReturn()) +OS << " noreturn"; + if (EI.getProducesResult()) +OS << " produces_result"; + if (EI.getHasRegParm()) +OS << " regparm " << EI.getRegParm(); + OS << " " << FunctionType::getNameForCallConv(EI.getCC()); +} + +void TextNodeDumper::VisitFunctionProtoType(const FunctionProtoType *T) { + auto EPI = T->getExtProtoInfo(); + if (EPI.HasTrailingReturn) +OS << " trailing_return"; + if (T->isConst()) +OS << " const"; + if (T->isVolatile()) +OS << " volatile"; + if (T->isRestrict()) +OS << " restrict"; + switch (EPI.RefQualifier) { + case RQ_None: +break; + case RQ_LValue: +OS << " &"; +break; + case RQ_RValue: +OS << " &&"; +break; + } + // FIXME: Exception specification. + // FIXME: Consumed parameters. + VisitFunctionType(T); +} + +void TextNodeDumper::VisitUnresolvedUsingType(const UnresolvedUsingType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitTypedefType(const TypedefType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) { + switch (T->getUTTKind()) { + case UnaryTransformType::EnumUnderlyingType: +OS << " underlying_type"; +break; + } +} + +void TextNodeDumper::VisitTagType(const TagType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitTemplateTypeParmType(const TemplateTypeParmType *T) { + OS << " depth " << T->getDepth() << " index " << T->getIndex(); + if (T->isParameterPack()) +OS << " pack"; + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitAutoType(const AutoType *T) { + if (T->isDecltypeAuto()) +OS << " decltype(auto)"; + if (!T->isDeduced()) +OS << " undeduced"; +} + +void TextNodeDumper::VisitTemplateSpecializationType( +const TemplateSpecializationType *T) { + if (T->isTypeAlias()) +OS << " alias"; + OS << " "; + T->getTemplateName().dump(OS); +} + +void TextNodeDumper::VisitInjectedClassNameType( +const InjectedClassNameType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitObjCInterfaceType(const ObjCInterfaceType *T) { + dumpDeclRef(T->getDecl()); +} + +void TextNodeDumper::VisitPackExpansionType(const PackExpansionType *T) { + if (auto N = T->getNumExpansions()) +OS << " expansions " << *N; +}