r351172 - [ASTDump] NFC: Move dump of type nodes to NodeDumper

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 15 04:58:03 PST 2019


On Tue, Jan 15, 2019 at 4:33 AM Stephen Kelly via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
>
> Author: steveire
> Date: Tue Jan 15 01:30:00 2019
> New Revision: 351172
>
> URL: http://llvm.org/viewvc/llvm-project?rev=351172&view=rev
> Log:
> [ASTDump] NFC: Move dump of type nodes to NodeDumper
>
> Reviewers: aaron.ballman
>
> Subscribers: cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D56642
>
> Modified:
>     cfe/trunk/include/clang/AST/TextNodeDumper.h
>     cfe/trunk/lib/AST/ASTDumper.cpp
>     cfe/trunk/lib/AST/TextNodeDumper.cpp
>
> Modified: cfe/trunk/include/clang/AST/TextNodeDumper.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TextNodeDumper.h?rev=351172&r1=351171&r2=351172&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/TextNodeDumper.h (original)
> +++ cfe/trunk/include/clang/AST/TextNodeDumper.h Tue Jan 15 01:30:00 2019
> @@ -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 @@ class TextNodeDumper
>                                             const comments::FullComment *>,
>        public ConstAttrVisitor<TextNodeDumper>,
>        public ConstTemplateArgumentVisitor<TextNodeDumper>,
> -      public ConstStmtVisitor<TextNodeDumper> {
> +      public ConstStmtVisitor<TextNodeDumper>,
> +      public TypeVisitor<TextNodeDumper> {
>    raw_ostream &OS;
>    const bool ShowColors;
>
> @@ -259,6 +261,26 @@ public:
>    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);
>  };
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=351172&r1=351171&r2=351172&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jan 15 01:30:00 2019
> @@ -134,99 +134,39 @@ namespace  {
>      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 VectorType::NeonPolyVector: OS << " neon poly"; break;
> -      }
> -      OS << " " << T->getNumElements();
>        dumpTypeAsChild(T->getElementType());
>      }
>      void 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());
>        dumpTypeAsChild(T->getReturnType());
>      }
>      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);
>        for (QualType PT : T->getParamTypes())
>          dumpTypeAsChild(PT);
> -      if (EPI.Variadic)
> +      if (T->getExtProtoInfo().Variadic)
>          dumpChild([=] { OS << "..."; });
>      }
> -    void VisitUnresolvedUsingType(const UnresolvedUsingType *T) {
> -      NodeDumper.dumpDeclRef(T->getDecl());
> -    }
> -    void VisitTypedefType(const TypedefType *T) {
> -      NodeDumper.dumpDeclRef(T->getDecl());
> -    }
>      void VisitTypeOfExprType(const TypeOfExprType *T) {
>        dumpStmt(T->getUnderlyingExpr());
>      }
> @@ -234,25 +174,12 @@ namespace  {
>        dumpStmt(T->getUnderlyingExpr());
>      }
>      void VisitUnaryTransformType(const UnaryTransformType *T) {
> -      switch (T->getUTTKind()) {
> -      case UnaryTransformType::EnumUnderlyingType:
> -        OS << " underlying_type";
> -        break;
> -      }
>        dumpTypeAsChild(T->getBaseType());
>      }
> -    void VisitTagType(const TagType *T) {
> -      NodeDumper.dumpDeclRef(T->getDecl());
> -    }
>      void VisitAttributedType(const AttributedType *T) {
>        // FIXME: AttrKind
>        dumpTypeAsChild(T->getModifiedType());
>      }
> -    void VisitTemplateTypeParmType(const TemplateTypeParmType *T) {
> -      OS << " depth " << T->getDepth() << " index " << T->getIndex();
> -      if (T->isParameterPack()) OS << " pack";
> -      NodeDumper.dumpDeclRef(T->getDecl());
> -    }
>      void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
>        dumpTypeAsChild(T->getReplacedParameter());
>      }
> @@ -261,25 +188,12 @@ namespace  {
>        dumpTypeAsChild(T->getReplacedParameter());
>        dumpTemplateArgument(T->getArgumentPack());
>      }
> -    void VisitAutoType(const AutoType *T) {
> -      if (T->isDecltypeAuto()) OS << " decltype(auto)";
> -      if (!T->isDeduced())
> -        OS << " undeduced";
> -    }
>      void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
> -      if (T->isTypeAlias()) OS << " alias";
> -      OS << " "; T->getTemplateName().dump(OS);
>        for (auto &Arg : *T)
>          dumpTemplateArgument(Arg);
>        if (T->isTypeAlias())
>          dumpTypeAsChild(T->getAliasedType());
>      }
> -    void VisitInjectedClassNameType(const InjectedClassNameType *T) {
> -      NodeDumper.dumpDeclRef(T->getDecl());
> -    }
> -    void VisitObjCInterfaceType(const ObjCInterfaceType *T) {
> -      NodeDumper.dumpDeclRef(T->getDecl());
> -    }
>      void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
>        dumpTypeAsChild(T->getPointeeType());
>      }
> @@ -293,7 +207,6 @@ namespace  {
>        dumpTypeAsChild(T->getOriginalType());
>      }
>      void VisitPackExpansionType(const PackExpansionType *T) {
> -      if (auto N = T->getNumExpansions()) OS << " expansions " << *N;
>        if (!T->isSugared())
>          dumpTypeAsChild(T->getPattern());
>      }
>
> Modified: cfe/trunk/lib/AST/TextNodeDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TextNodeDumper.cpp?rev=351172&r1=351171&r2=351172&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/TextNodeDumper.cpp (original)
> +++ cfe/trunk/lib/AST/TextNodeDumper.cpp Tue Jan 15 01:30:00 2019
> @@ -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 @@ void TextNodeDumper::Visit(const Type *T
>      OS << " contains_unexpanded_pack";
>    if (T->isFromAST())
>      OS << " imported";
> +
> +  TypeVisitor<TextNodeDumper>::Visit(T);
>  }
>
>  void TextNodeDumper::Visit(QualType T) {
> @@ -886,3 +889,161 @@ void TextNodeDumper::VisitObjCSubscriptR
>  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())

It looks like the auto nits didn't get cleaned up. Can you handle those?

~Aaron

> +    OS << " expansions " << *N;
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list