From fb3023497a11e4dc7d1c032dfc13dabd28791781 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 30 Jan 2019 21:48:32 +0000 Subject: [PATCH] [ASTDump] Inline traverse methods into class This API will be extracted into a new template class. This change will make the follow-up commit easier to review. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352676 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTDumper.cpp | 931 ++++++++++++++++++------------------------ 1 file changed, 388 insertions(+), 543 deletions(-) diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index a098fc83fb..7cb61c8aff 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -74,42 +74,175 @@ namespace { void setDeserialize(bool D) { Deserialize = D; } - void Visit(const Decl *D); - void Visit(const Stmt *S, StringRef Label = {}); - void Visit(QualType T); - void Visit(const Type *T); - void Visit(const Attr *A); - void Visit(const CXXCtorInitializer *Init); - void Visit(const TemplateArgument &A, SourceRange R = SourceRange(), - const Decl *From = nullptr, const char *Label = nullptr); - void Visit(const BlockDecl::Capture &C); - void Visit(const OMPClause *C); - void Visit(const GenericSelectionExpr::ConstAssociation &A); - void Visit(const Comment *C, const FullComment *FC); - - // C++ Utilities + void Visit(const Decl *D) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(D); + if (!D) + return; + + ConstDeclVisitor::Visit(D); + + for (const auto &A : D->attrs()) + Visit(A); + + if (const FullComment *Comment = + D->getASTContext().getLocalCommentForDeclUncached(D)) + Visit(Comment, Comment); + + // Decls within functions are visited by the body. + if (!isa(*D) && !isa(*D)) { + if (const auto *DC = dyn_cast(D)) + dumpDeclContext(DC); + } + }); + } + + void Visit(const Stmt *S, StringRef Label = {}) { + NodeDumper.AddChild(Label, [=] { + NodeDumper.Visit(S); + + if (!S) { + return; + } + + ConstStmtVisitor::Visit(S); + + // Some statements have custom mechanisms for dumping their children. + if (isa(S) || isa(S)) { + return; + } + + for (const Stmt *SubStmt : S->children()) + Visit(SubStmt); + }); + } + + void Visit(QualType T) { + SplitQualType SQT = T.split(); + if (!SQT.Quals.hasQualifiers()) + return Visit(SQT.Ty); + + NodeDumper.AddChild([=] { + NodeDumper.Visit(T); + Visit(T.split().Ty); + }); + } + + void Visit(const Type *T) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(T); + if (!T) + return; + TypeVisitor::Visit(T); + + QualType SingleStepDesugar = + T->getLocallyUnqualifiedSingleStepDesugaredType(); + if (SingleStepDesugar != QualType(T, 0)) + Visit(SingleStepDesugar); + }); + } + + void Visit(const Attr *A) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(A); + ConstAttrVisitor::Visit(A); + }); + } + + void Visit(const CXXCtorInitializer *Init) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(Init); + Visit(Init->getInit()); + }); + } + + void Visit(const TemplateArgument &A, SourceRange R = {}, + const Decl *From = nullptr, const char *Label = nullptr) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(A, R, From, Label); + ConstTemplateArgumentVisitor::Visit(A); + }); + } + + void Visit(const BlockDecl::Capture &C) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(C); + if (C.hasCopyExpr()) + Visit(C.getCopyExpr()); + }); + } + + void Visit(const OMPClause *C) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(C); + for (const auto *S : C->children()) + Visit(S); + }); + } + + void Visit(const GenericSelectionExpr::ConstAssociation &A) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(A); + if (const TypeSourceInfo *TSI = A.getTypeSourceInfo()) + Visit(TSI->getType()); + Visit(A.getAssociationExpr()); + }); + } + + void Visit(const Comment *C, const FullComment *FC) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(C, FC); + if (!C) { + return; + } + ConstCommentVisitor::visit(C, FC); + for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); + I != E; ++I) + Visit(*I, FC); + }); + } + void dumpDeclContext(const DeclContext *DC); void dumpLookups(const DeclContext *DC, bool DumpDecls); - void dumpTemplateParameters(const TemplateParameterList *TPL); - void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI); + + void dumpTemplateParameters(const TemplateParameterList *TPL) { + if (!TPL) + return; + + for (const auto &TP : *TPL) + Visit(TP); + } + + void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI) { + for (const auto &TA : TALI.arguments()) + dumpTemplateArgumentLoc(TA); + } + void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, const Decl *From = nullptr, - const char *Label = nullptr); - void dumpTemplateArgumentList(const TemplateArgumentList &TAL); + const char *Label = nullptr) { + Visit(A.getArgument(), A.getSourceRange(), From, Label); + } + + void dumpTemplateArgumentList(const TemplateArgumentList &TAL) { + for (unsigned i = 0, e = TAL.size(); i < e; ++i) + Visit(TAL[i]); + } - // Objective-C utilities. - void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams); + void dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) { + if (!typeParams) + return; - // Types - void VisitComplexType(const ComplexType *T) { - Visit(T->getElementType()); + for (const auto &typeParam : *typeParams) { + Visit(typeParam); + } } + + void VisitComplexType(const ComplexType *T) { Visit(T->getElementType()); } void VisitLocInfoType(const LocInfoType *T) { Visit(T->getTypeSourceInfo()->getType()); } - void VisitPointerType(const PointerType *T) { - Visit(T->getPointeeType()); - } + void VisitPointerType(const PointerType *T) { Visit(T->getPointeeType()); } void VisitBlockPointerType(const BlockPointerType *T) { Visit(T->getPointeeType()); } @@ -120,9 +253,7 @@ namespace { Visit(T->getClass()); Visit(T->getPointeeType()); } - void VisitArrayType(const ArrayType *T) { - Visit(T->getElementType()); - } + void VisitArrayType(const ArrayType *T) { Visit(T->getElementType()); } void VisitVariableArrayType(const VariableArrayType *T) { VisitArrayType(T); Visit(T->getSizeExpr()); @@ -131,17 +262,13 @@ namespace { Visit(T->getElementType()); Visit(T->getSizeExpr()); } - void VisitDependentSizedExtVectorType( - const DependentSizedExtVectorType *T) { + void + VisitDependentSizedExtVectorType(const DependentSizedExtVectorType *T) { Visit(T->getElementType()); Visit(T->getSizeExpr()); } - void VisitVectorType(const VectorType *T) { - Visit(T->getElementType()); - } - void VisitFunctionType(const FunctionType *T) { - Visit(T->getReturnType()); - } + void VisitVectorType(const VectorType *T) { Visit(T->getElementType()); } + void VisitFunctionType(const FunctionType *T) { Visit(T->getReturnType()); } void VisitFunctionProtoType(const FunctionProtoType *T) { VisitFunctionType(T); for (const QualType &PT : T->getParamTypes()) @@ -163,8 +290,8 @@ namespace { void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) { Visit(T->getReplacedParameter()); } - void VisitSubstTemplateTypeParmPackType( - const SubstTemplateTypeParmPackType *T) { + void + VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) { Visit(T->getReplacedParameter()); Visit(T->getArgumentPack()); } @@ -177,12 +304,8 @@ namespace { void VisitObjCObjectPointerType(const ObjCObjectPointerType *T) { Visit(T->getPointeeType()); } - void VisitAtomicType(const AtomicType *T) { - Visit(T->getValueType()); - } - void VisitPipeType(const PipeType *T) { - Visit(T->getElementType()); - } + void VisitAtomicType(const AtomicType *T) { Visit(T->getValueType()); } + void VisitPipeType(const PipeType *T) { Visit(T->getElementType()); } void VisitAdjustedType(const AdjustedType *T) { Visit(T->getOriginalType()); } @@ -193,21 +316,74 @@ namespace { // FIXME: ElaboratedType, DependentNameType, // DependentTemplateSpecializationType, ObjCObjectType - // Decls - void VisitTypedefDecl(const TypedefDecl *D); - void VisitEnumConstantDecl(const EnumConstantDecl *D); - void VisitFunctionDecl(const FunctionDecl *D); - void VisitFieldDecl(const FieldDecl *D); - void VisitVarDecl(const VarDecl *D); - void VisitDecompositionDecl(const DecompositionDecl *D); - void VisitBindingDecl(const BindingDecl *D); - void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D); - void VisitCapturedDecl(const CapturedDecl *D); - - // OpenMP decls - void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D); - void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D); - void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D); + void VisitTypedefDecl(const TypedefDecl *D) { + Visit(D->getUnderlyingType()); + } + + void VisitEnumConstantDecl(const EnumConstantDecl *D) { + if (const Expr *Init = D->getInitExpr()) + Visit(Init); + } + + void VisitFunctionDecl(const FunctionDecl *D) { + if (const auto *FTSI = D->getTemplateSpecializationInfo()) + dumpTemplateArgumentList(*FTSI->TemplateArguments); + + if (D->param_begin()) + for (const auto *Parameter : D->parameters()) + Visit(Parameter); + + if (const auto *C = dyn_cast(D)) + for (const auto *I : C->inits()) + Visit(I); + + if (D->doesThisDeclarationHaveABody()) + Visit(D->getBody()); + } + + void VisitFieldDecl(const FieldDecl *D) { + if (D->isBitField()) + Visit(D->getBitWidth()); + if (Expr *Init = D->getInClassInitializer()) + Visit(Init); + } + + void VisitVarDecl(const VarDecl *D) { + if (D->hasInit()) + Visit(D->getInit()); + } + + void VisitDecompositionDecl(const DecompositionDecl *D) { + VisitVarDecl(D); + for (const auto *B : D->bindings()) + Visit(B); + } + + void VisitBindingDecl(const BindingDecl *D) { + if (const auto *E = D->getBinding()) + Visit(E); + } + + void VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) { + Visit(D->getAsmString()); + } + + void VisitCapturedDecl(const CapturedDecl *D) { Visit(D->getBody()); } + + void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) { + for (const auto *E : D->varlists()) + Visit(E); + } + + void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) { + Visit(D->getCombiner()); + if (const auto *Initializer = D->getInitializer()) + Visit(Initializer); + } + + void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) { + Visit(D->getInit()); + } template void dumpTemplateDeclSpecialization(const SpecializationDecl *D, @@ -216,205 +392,195 @@ namespace { template void dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst); - // C++ Decls - void VisitTypeAliasDecl(const TypeAliasDecl *D); - void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D); - void VisitStaticAssertDecl(const StaticAssertDecl *D); + void VisitTypeAliasDecl(const TypeAliasDecl *D) { + Visit(D->getUnderlyingType()); + } + + void VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + Visit(D->getTemplatedDecl()); + } + + void VisitStaticAssertDecl(const StaticAssertDecl *D) { + Visit(D->getAssertExpr()); + Visit(D->getMessage()); + } void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D); void VisitClassTemplateDecl(const ClassTemplateDecl *D); + void VisitClassTemplateSpecializationDecl( - const ClassTemplateSpecializationDecl *D); + const ClassTemplateSpecializationDecl *D) { + dumpTemplateArgumentList(D->getTemplateArgs()); + } + void VisitClassTemplatePartialSpecializationDecl( - const ClassTemplatePartialSpecializationDecl *D); + const ClassTemplatePartialSpecializationDecl *D) { + VisitClassTemplateSpecializationDecl(D); + dumpTemplateParameters(D->getTemplateParameters()); + } + void VisitClassScopeFunctionSpecializationDecl( - const ClassScopeFunctionSpecializationDecl *D); + const ClassScopeFunctionSpecializationDecl *D) { + Visit(D->getSpecialization()); + if (D->hasExplicitTemplateArgs()) + dumpTemplateArgumentListInfo(D->templateArgs()); + } void VisitVarTemplateDecl(const VarTemplateDecl *D); - void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D); - void VisitVarTemplateSpecializationDecl( - const VarTemplateSpecializationDecl *D); + + void VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + } + + void + VisitVarTemplateSpecializationDecl(const VarTemplateSpecializationDecl *D) { + dumpTemplateArgumentList(D->getTemplateArgs()); + VisitVarDecl(D); + } + void VisitVarTemplatePartialSpecializationDecl( - const VarTemplatePartialSpecializationDecl *D); - void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D); - void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D); - void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D); - void VisitUsingShadowDecl(const UsingShadowDecl *D); - void VisitFriendDecl(const FriendDecl *D); - - // ObjC Decls - void VisitObjCMethodDecl(const ObjCMethodDecl *D); - void VisitObjCCategoryDecl(const ObjCCategoryDecl *D); - void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D); - void VisitObjCImplementationDecl(const ObjCImplementationDecl *D); - void VisitBlockDecl(const BlockDecl *D); - - // Stmts. - void VisitDeclStmt(const DeclStmt *Node); - void VisitAttributedStmt(const AttributedStmt *Node); - void VisitCXXCatchStmt(const CXXCatchStmt *Node); - void VisitCapturedStmt(const CapturedStmt *Node); - - // OpenMP - void VisitOMPExecutableDirective(const OMPExecutableDirective *Node); - - // Exprs - void VisitInitListExpr(const InitListExpr *ILE); - void VisitBlockExpr(const BlockExpr *Node); - void VisitOpaqueValueExpr(const OpaqueValueExpr *Node); - void VisitGenericSelectionExpr(const GenericSelectionExpr *E); - - // C++ - void VisitLambdaExpr(const LambdaExpr *Node) { - Visit(Node->getLambdaClass()); + const VarTemplatePartialSpecializationDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + VisitVarTemplateSpecializationDecl(D); } - void VisitSizeOfPackExpr(const SizeOfPackExpr *Node); - // ObjC - void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node); + void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { + if (D->hasDefaultArgument()) + Visit(D->getDefaultArgument(), SourceRange(), + D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); + } - void VisitExpressionTemplateArgument(const TemplateArgument &TA) { - Visit(TA.getAsExpr()); + void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { + if (D->hasDefaultArgument()) + Visit(D->getDefaultArgument(), SourceRange(), + D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } - void VisitPackTemplateArgument(const TemplateArgument &TA) { - for (const auto &TArg : TA.pack_elements()) - Visit(TArg); + + void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D) { + dumpTemplateParameters(D->getTemplateParameters()); + if (D->hasDefaultArgument()) + dumpTemplateArgumentLoc( + D->getDefaultArgument(), + D->getDefaultArgStorage().getInheritedFrom(), + D->defaultArgumentWasInherited() ? "inherited from" : "previous"); } -// Implements Visit methods for Attrs. -#include "clang/AST/AttrNodeTraverse.inc" - }; -} + void VisitUsingShadowDecl(const UsingShadowDecl *D) { + if (auto *TD = dyn_cast(D->getUnderlyingDecl())) + Visit(TD->getTypeForDecl()); + } -//===----------------------------------------------------------------------===// -// Utilities -//===----------------------------------------------------------------------===// + void VisitFriendDecl(const FriendDecl *D) { + if (!D->getFriendType()) + Visit(D->getFriendDecl()); + } -void ASTDumper::Visit(const Decl *D) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(D); - if (!D) - return; + void VisitObjCMethodDecl(const ObjCMethodDecl *D) { + if (D->isThisDeclarationADefinition()) + dumpDeclContext(D); + else + for (const ParmVarDecl *Parameter : D->parameters()) + Visit(Parameter); - ConstDeclVisitor::Visit(D); + if (D->hasBody()) + Visit(D->getBody()); + } - for (const auto &A : D->attrs()) - Visit(A); + void VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { + dumpObjCTypeParamList(D->getTypeParamList()); + } - if (const FullComment *Comment = - D->getASTContext().getLocalCommentForDeclUncached(D)) - Visit(Comment, Comment); + void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { + dumpObjCTypeParamList(D->getTypeParamListAsWritten()); + } - // Decls within functions are visited by the body. - if (!isa(*D) && !isa(*D)) { - if (const auto *DC = dyn_cast(D)) - dumpDeclContext(DC); + void VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { + for (const auto &I : D->inits()) + Visit(I); } - }); -} -void ASTDumper::Visit(const Stmt *S, StringRef Label) { - NodeDumper.AddChild(Label, [=] { - NodeDumper.Visit(S); + void VisitBlockDecl(const BlockDecl *D) { + for (const auto &I : D->parameters()) + Visit(I); - if (!S) { - return; + for (const auto &I : D->captures()) + Visit(I); + Visit(D->getBody()); } - ConstStmtVisitor::Visit(S); + void VisitDeclStmt(const DeclStmt *Node) { + for (const auto &D : Node->decls()) + Visit(D); + } - // Some statements have custom mechanisms for dumping their children. - if (isa(S) || isa(S)) { - return; + void VisitAttributedStmt(const AttributedStmt *Node) { + for (const auto *A : Node->getAttrs()) + Visit(A); } - for (const Stmt *SubStmt : S->children()) - Visit(SubStmt); - }); -} + void VisitCXXCatchStmt(const CXXCatchStmt *Node) { + Visit(Node->getExceptionDecl()); + } -void ASTDumper::Visit(QualType T) { - SplitQualType SQT = T.split(); - if (!SQT.Quals.hasQualifiers()) - return Visit(SQT.Ty); + void VisitCapturedStmt(const CapturedStmt *Node) { + Visit(Node->getCapturedDecl()); + } - NodeDumper.AddChild([=] { - NodeDumper.Visit(T); - Visit(T.split().Ty); - }); -} + void VisitOMPExecutableDirective(const OMPExecutableDirective *Node) { + for (const auto *C : Node->clauses()) + Visit(C); + } -void ASTDumper::Visit(const Type *T) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(T); - if (!T) - return; - TypeVisitor::Visit(T); - - QualType SingleStepDesugar = - T->getLocallyUnqualifiedSingleStepDesugaredType(); - if (SingleStepDesugar != QualType(T, 0)) - Visit(SingleStepDesugar); - }); -} + void VisitInitListExpr(const InitListExpr *ILE) { + if (auto *Filler = ILE->getArrayFiller()) { + Visit(Filler, "array_filler"); + } + } -void ASTDumper::Visit(const Attr *A) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(A); - ConstAttrVisitor::Visit(A); - }); -} + void VisitBlockExpr(const BlockExpr *Node) { Visit(Node->getBlockDecl()); } -void ASTDumper::Visit(const CXXCtorInitializer *Init) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(Init); - Visit(Init->getInit()); - }); -} + void VisitOpaqueValueExpr(const OpaqueValueExpr *Node) { + if (Expr *Source = Node->getSourceExpr()) + Visit(Source); + } -void ASTDumper::Visit(const TemplateArgument &A, SourceRange R, - const Decl *From, const char *Label) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(A, R, From, Label); - ConstTemplateArgumentVisitor::Visit(A); - }); -} + void VisitGenericSelectionExpr(const GenericSelectionExpr *E) { + Visit(E->getControllingExpr()); + Visit(E->getControllingExpr()->getType()); // FIXME: remove -void ASTDumper::Visit(const BlockDecl::Capture &C) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(C); - if (C.hasCopyExpr()) - Visit(C.getCopyExpr()); - }); -} + for (const auto &Assoc : E->associations()) { + Visit(Assoc); + } + } -void ASTDumper::Visit(const OMPClause *C) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(C); - for (const auto *S : C->children()) - Visit(S); - }); -} + void VisitLambdaExpr(const LambdaExpr *Node) { + Visit(Node->getLambdaClass()); + } -void ASTDumper::Visit(const GenericSelectionExpr::ConstAssociation &A) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(A); - if (const TypeSourceInfo *TSI = A.getTypeSourceInfo()) - Visit(TSI->getType()); - Visit(A.getAssociationExpr()); - }); -} + void VisitSizeOfPackExpr(const SizeOfPackExpr *Node) { + if (Node->isPartiallySubstituted()) + for (const auto &A : Node->getPartialArguments()) + Visit(A); + } -void ASTDumper::Visit(const Comment *C, const FullComment *FC) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(C, FC); - if (!C) { - return; - } - ConstCommentVisitor::visit(C, FC); - for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); - I != E; ++I) - Visit(*I, FC); - }); -} + void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { + if (const VarDecl *CatchParam = Node->getCatchParamDecl()) + Visit(CatchParam); + } + + void VisitExpressionTemplateArgument(const TemplateArgument &TA) { + Visit(TA.getAsExpr()); + } + void VisitPackTemplateArgument(const TemplateArgument &TA) { + for (const auto &TArg : TA.pack_elements()) + Visit(TArg); + } + + // Implements Visit methods for Attrs. +#include "clang/AST/AttrNodeTraverse.inc" + }; +} // namespace void ASTDumper::dumpDeclContext(const DeclContext *DC) { if (!DC) @@ -483,129 +649,6 @@ void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) { }); } -//===----------------------------------------------------------------------===// -// C++ Utilities -//===----------------------------------------------------------------------===// - -void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) { - if (!TPL) - return; - - for (const auto &TP : *TPL) - Visit(TP); -} - -void ASTDumper::dumpTemplateArgumentListInfo( - const TemplateArgumentListInfo &TALI) { - for (const auto &TA : TALI.arguments()) - dumpTemplateArgumentLoc(TA); -} - -void ASTDumper::dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, - const Decl *From, const char *Label) { - Visit(A.getArgument(), A.getSourceRange(), From, Label); -} - -void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) { - for (unsigned i = 0, e = TAL.size(); i < e; ++i) - Visit(TAL[i]); -} - -//===----------------------------------------------------------------------===// -// Objective-C Utilities -//===----------------------------------------------------------------------===// -void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) { - if (!typeParams) - return; - - for (const auto &typeParam : *typeParams) { - Visit(typeParam); - } -} - -//===----------------------------------------------------------------------===// -// Decl dumping methods. -//===----------------------------------------------------------------------===// - -void ASTDumper::VisitTypedefDecl(const TypedefDecl *D) { - Visit(D->getUnderlyingType()); -} - -void ASTDumper::VisitEnumConstantDecl(const EnumConstantDecl *D) { - if (const Expr *Init = D->getInitExpr()) - Visit(Init); -} - -void ASTDumper::VisitFunctionDecl(const FunctionDecl *D) { - if (const auto *FTSI = D->getTemplateSpecializationInfo()) - dumpTemplateArgumentList(*FTSI->TemplateArguments); - - if (D->param_begin()) - for (const auto *Parameter : D->parameters()) - Visit(Parameter); - - if (const auto *C = dyn_cast(D)) - for (const auto *I : C->inits()) - Visit(I); - - if (D->doesThisDeclarationHaveABody()) - Visit(D->getBody()); -} - -void ASTDumper::VisitFieldDecl(const FieldDecl *D) { - if (D->isBitField()) - Visit(D->getBitWidth()); - if (Expr *Init = D->getInClassInitializer()) - Visit(Init); -} - -void ASTDumper::VisitVarDecl(const VarDecl *D) { - if (D->hasInit()) - Visit(D->getInit()); -} - -void ASTDumper::VisitDecompositionDecl(const DecompositionDecl *D) { - VisitVarDecl(D); - for (const auto *B : D->bindings()) - Visit(B); -} - -void ASTDumper::VisitBindingDecl(const BindingDecl *D) { - if (const auto *E = D->getBinding()) - Visit(E); -} - -void ASTDumper::VisitFileScopeAsmDecl(const FileScopeAsmDecl *D) { - Visit(D->getAsmString()); -} - -void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) { - Visit(D->getBody()); -} - -//===----------------------------------------------------------------------===// -// OpenMP Declarations -//===----------------------------------------------------------------------===// - -void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) { - for (const auto *E : D->varlists()) - Visit(E); -} - -void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) { - Visit(D->getCombiner()); - if (const auto *Initializer = D->getInitializer()) - Visit(Initializer); -} - -void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) { - Visit(D->getInit()); -} - -//===----------------------------------------------------------------------===// -// C++ Declarations -//===----------------------------------------------------------------------===// - template void ASTDumper::dumpTemplateDeclSpecialization(const SpecializationDecl *D, bool DumpExplicitInst, @@ -659,20 +702,6 @@ void ASTDumper::dumpTemplateDecl(const TemplateDecl *D, bool DumpExplicitInst) { !D->isCanonicalDecl()); } -void ASTDumper::VisitTypeAliasDecl(const TypeAliasDecl *D) { - Visit(D->getUnderlyingType()); -} - -void ASTDumper::VisitTypeAliasTemplateDecl(const TypeAliasTemplateDecl *D) { - dumpTemplateParameters(D->getTemplateParameters()); - Visit(D->getTemplatedDecl()); -} - -void ASTDumper::VisitStaticAssertDecl(const StaticAssertDecl *D) { - Visit(D->getAssertExpr()); - Visit(D->getMessage()); -} - void ASTDumper::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) { // FIXME: We don't add a declaration of a function template specialization // to its context when it's explicitly instantiated, so dump explicit @@ -684,194 +713,10 @@ void ASTDumper::VisitClassTemplateDecl(const ClassTemplateDecl *D) { dumpTemplateDecl(D, false); } -void ASTDumper::VisitClassTemplateSpecializationDecl( - const ClassTemplateSpecializationDecl *D) { - dumpTemplateArgumentList(D->getTemplateArgs()); -} - -void ASTDumper::VisitClassTemplatePartialSpecializationDecl( - const ClassTemplatePartialSpecializationDecl *D) { - VisitClassTemplateSpecializationDecl(D); - dumpTemplateParameters(D->getTemplateParameters()); -} - -void ASTDumper::VisitClassScopeFunctionSpecializationDecl( - const ClassScopeFunctionSpecializationDecl *D) { - Visit(D->getSpecialization()); - if (D->hasExplicitTemplateArgs()) - dumpTemplateArgumentListInfo(D->templateArgs()); -} - void ASTDumper::VisitVarTemplateDecl(const VarTemplateDecl *D) { dumpTemplateDecl(D, false); } -void ASTDumper::VisitBuiltinTemplateDecl(const BuiltinTemplateDecl *D) { - dumpTemplateParameters(D->getTemplateParameters()); -} - -void ASTDumper::VisitVarTemplateSpecializationDecl( - const VarTemplateSpecializationDecl *D) { - dumpTemplateArgumentList(D->getTemplateArgs()); - VisitVarDecl(D); -} - -void ASTDumper::VisitVarTemplatePartialSpecializationDecl( - const VarTemplatePartialSpecializationDecl *D) { - dumpTemplateParameters(D->getTemplateParameters()); - VisitVarTemplateSpecializationDecl(D); -} - -void ASTDumper::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) { - if (D->hasDefaultArgument()) - Visit(D->getDefaultArgument(), SourceRange(), - D->getDefaultArgStorage().getInheritedFrom(), - D->defaultArgumentWasInherited() ? "inherited from" : "previous"); -} - -void ASTDumper::VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D) { - if (D->hasDefaultArgument()) - Visit(D->getDefaultArgument(), SourceRange(), - D->getDefaultArgStorage().getInheritedFrom(), - D->defaultArgumentWasInherited() ? "inherited from" : "previous"); -} - -void ASTDumper::VisitTemplateTemplateParmDecl( - const TemplateTemplateParmDecl *D) { - dumpTemplateParameters(D->getTemplateParameters()); - if (D->hasDefaultArgument()) - dumpTemplateArgumentLoc( - D->getDefaultArgument(), D->getDefaultArgStorage().getInheritedFrom(), - D->defaultArgumentWasInherited() ? "inherited from" : "previous"); -} - -void ASTDumper::VisitUsingShadowDecl(const UsingShadowDecl *D) { - if (auto *TD = dyn_cast(D->getUnderlyingDecl())) - Visit(TD->getTypeForDecl()); -} - -void ASTDumper::VisitFriendDecl(const FriendDecl *D) { - if (!D->getFriendType()) - Visit(D->getFriendDecl()); -} - -//===----------------------------------------------------------------------===// -// Obj-C Declarations -//===----------------------------------------------------------------------===// - -void ASTDumper::VisitObjCMethodDecl(const ObjCMethodDecl *D) { - if (D->isThisDeclarationADefinition()) - dumpDeclContext(D); - else - for (const ParmVarDecl *Parameter : D->parameters()) - Visit(Parameter); - - if (D->hasBody()) - Visit(D->getBody()); -} - -void ASTDumper::VisitObjCCategoryDecl(const ObjCCategoryDecl *D) { - dumpObjCTypeParamList(D->getTypeParamList()); -} - -void ASTDumper::VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) { - dumpObjCTypeParamList(D->getTypeParamListAsWritten()); -} - -void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { - for (const auto &I : D->inits()) - Visit(I); -} - -void ASTDumper::VisitBlockDecl(const BlockDecl *D) { - for (const auto &I : D->parameters()) - Visit(I); - - for (const auto &I : D->captures()) - Visit(I); - Visit(D->getBody()); -} - -//===----------------------------------------------------------------------===// -// Stmt dumping methods. -//===----------------------------------------------------------------------===// - -void ASTDumper::VisitDeclStmt(const DeclStmt *Node) { - for (const auto &D : Node->decls()) - Visit(D); -} - -void ASTDumper::VisitAttributedStmt(const AttributedStmt *Node) { - for (const auto *A : Node->getAttrs()) - Visit(A); -} - -void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) { - Visit(Node->getExceptionDecl()); -} - -void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) { - Visit(Node->getCapturedDecl()); -} - -//===----------------------------------------------------------------------===// -// OpenMP dumping methods. -//===----------------------------------------------------------------------===// - -void ASTDumper::VisitOMPExecutableDirective( - const OMPExecutableDirective *Node) { - for (const auto *C : Node->clauses()) - Visit(C); -} - -//===----------------------------------------------------------------------===// -// Expr dumping methods. -//===----------------------------------------------------------------------===// - - -void ASTDumper::VisitInitListExpr(const InitListExpr *ILE) { - if (auto *Filler = ILE->getArrayFiller()) { - Visit(Filler, "array_filler"); - } -} - -void ASTDumper::VisitBlockExpr(const BlockExpr *Node) { - Visit(Node->getBlockDecl()); -} - -void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) { - if (Expr *Source = Node->getSourceExpr()) - Visit(Source); -} - -void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) { - Visit(E->getControllingExpr()); - Visit(E->getControllingExpr()->getType()); // FIXME: remove - - for (const auto &Assoc : E->associations()) { - Visit(Assoc); - } -} - -//===----------------------------------------------------------------------===// -// C++ Expressions -//===----------------------------------------------------------------------===// - -void ASTDumper::VisitSizeOfPackExpr(const SizeOfPackExpr *Node) { - if (Node->isPartiallySubstituted()) - for (const auto &A : Node->getPartialArguments()) - Visit(A); -} - -//===----------------------------------------------------------------------===// -// Obj-C Expressions -//===----------------------------------------------------------------------===// - -void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { - if (const VarDecl *CatchParam = Node->getCatchParamDecl()) - Visit(CatchParam); -} - //===----------------------------------------------------------------------===// // Type method implementations //===----------------------------------------------------------------------===// -- 2.40.0