From 4139529eb6f8ea3b93f5cf71e1d48fd163840308 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 30 Jan 2019 20:03:47 +0000 Subject: [PATCH] [ASTDump] Re-arrange method declarations to group Visit together This will make follow-up commits easier to review. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@352661 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTDumper.cpp | 232 ++++++++++++++++++++---------------------- 1 file changed, 112 insertions(+), 120 deletions(-) diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 2c2b1e5f8e..e8585b2749 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -76,24 +76,26 @@ namespace { void Visit(const Decl *D); void Visit(const Stmt *S, StringRef Label = {}); - - // Utilities void Visit(QualType T); void Visit(const Type *T); - void dumpDeclContext(const DeclContext *DC); - void dumpLookups(const DeclContext *DC, bool DumpDecls); 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 CXXCtorInitializer *Init); + void dumpDeclContext(const DeclContext *DC); + void dumpLookups(const DeclContext *DC, bool DumpDecls); void dumpTemplateParameters(const TemplateParameterList *TPL); void dumpTemplateArgumentListInfo(const TemplateArgumentListInfo &TALI); void dumpTemplateArgumentLoc(const TemplateArgumentLoc &A, const Decl *From = nullptr, const char *Label = nullptr); void dumpTemplateArgumentList(const TemplateArgumentList &TAL); - void Visit(const TemplateArgument &A, SourceRange R = SourceRange(), - const Decl *From = nullptr, const char *Label = nullptr); template void dumpTemplateDeclSpecialization(const SpecializationDecl *D, bool DumpExplicitInst, @@ -242,7 +244,6 @@ namespace { void VisitObjCCategoryDecl(const ObjCCategoryDecl *D); void VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D); void VisitObjCImplementationDecl(const ObjCImplementationDecl *D); - void Visit(const BlockDecl::Capture &C); void VisitBlockDecl(const BlockDecl *D); // Stmts. @@ -252,14 +253,12 @@ namespace { void VisitCapturedStmt(const CapturedStmt *Node); // OpenMP - void Visit(const OMPClause *C); void VisitOMPExecutableDirective(const OMPExecutableDirective *Node); // Exprs void VisitInitListExpr(const InitListExpr *ILE); void VisitBlockExpr(const BlockExpr *Node); void VisitOpaqueValueExpr(const OpaqueValueExpr *Node); - void Visit(const GenericSelectionExpr::ConstAssociation &A); void VisitGenericSelectionExpr(const GenericSelectionExpr *E); // C++ @@ -271,9 +270,6 @@ namespace { // ObjC void VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node); - // Comments. - void Visit(const Comment *C, const FullComment *FC); - void VisitExpressionTemplateArgument(const TemplateArgument &TA) { Visit(TA.getAsExpr()); } @@ -291,6 +287,49 @@ namespace { // Utilities //===----------------------------------------------------------------------===// +void ASTDumper::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 ASTDumper::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 ASTDumper::Visit(QualType T) { SplitQualType SQT = T.split(); if (!SQT.Quals.hasQualifiers()) @@ -316,6 +355,66 @@ void ASTDumper::Visit(const Type *T) { }); } +void ASTDumper::Visit(const Attr *A) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(A); + ConstAttrVisitor::Visit(A); + }); +} + +void ASTDumper::Visit(const CXXCtorInitializer *Init) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(Init); + Visit(Init->getInit()); + }); +} + +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 ASTDumper::Visit(const BlockDecl::Capture &C) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(C); + if (C.hasCopyExpr()) + Visit(C.getCopyExpr()); + }); +} + +void ASTDumper::Visit(const OMPClause *C) { + NodeDumper.AddChild([=] { + NodeDumper.Visit(C); + for (const auto *S : C->children()) + Visit(S); + }); +} + +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 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 ASTDumper::dumpDeclContext(const DeclContext *DC) { if (!DC) return; @@ -383,24 +482,10 @@ void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) { }); } -void ASTDumper::Visit(const Attr *A) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(A); - ConstAttrVisitor::Visit(A); - }); -} - //===----------------------------------------------------------------------===// // C++ Utilities //===----------------------------------------------------------------------===// -void ASTDumper::Visit(const CXXCtorInitializer *Init) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(Init); - Visit(Init->getInit()); - }); -} - void ASTDumper::dumpTemplateParameters(const TemplateParameterList *TPL) { if (!TPL) return; @@ -425,14 +510,6 @@ void ASTDumper::dumpTemplateArgumentList(const TemplateArgumentList &TAL) { Visit(TAL[i]); } -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); - }); -} - //===----------------------------------------------------------------------===// // Objective-C Utilities //===----------------------------------------------------------------------===// @@ -449,29 +526,6 @@ void ASTDumper::dumpObjCTypeParamList(const ObjCTypeParamList *typeParams) { // Decl dumping methods. //===----------------------------------------------------------------------===// -void ASTDumper::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 ASTDumper::VisitTypedefDecl(const TypedefDecl *D) { Visit(D->getUnderlyingType()); } @@ -728,14 +782,6 @@ void ASTDumper::VisitObjCImplementationDecl(const ObjCImplementationDecl *D) { Visit(I); } -void ASTDumper::Visit(const BlockDecl::Capture &C) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(C); - if (C.hasCopyExpr()) - Visit(C.getCopyExpr()); - }); -} - void ASTDumper::VisitBlockDecl(const BlockDecl *D) { for (const auto &I : D->parameters()) Visit(I); @@ -749,26 +795,6 @@ void ASTDumper::VisitBlockDecl(const BlockDecl *D) { // Stmt dumping methods. //===----------------------------------------------------------------------===// -void ASTDumper::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 ASTDumper::VisitDeclStmt(const DeclStmt *Node) { for (const auto &D : Node->decls()) Visit(D); @@ -791,14 +817,6 @@ void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) { // OpenMP dumping methods. //===----------------------------------------------------------------------===// -void ASTDumper::Visit(const OMPClause *C) { - NodeDumper.AddChild([=] { - NodeDumper.Visit(C); - for (const auto *S : C->children()) - Visit(S); - }); -} - void ASTDumper::VisitOMPExecutableDirective( const OMPExecutableDirective *Node) { for (const auto *C : Node->clauses()) @@ -825,15 +843,6 @@ void ASTDumper::VisitOpaqueValueExpr(const OpaqueValueExpr *Node) { Visit(Source); } -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 ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) { Visit(E->getControllingExpr()); Visit(E->getControllingExpr()->getType()); // FIXME: remove @@ -862,23 +871,6 @@ void ASTDumper::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *Node) { Visit(CatchParam); } -//===----------------------------------------------------------------------===// -// Comments -//===----------------------------------------------------------------------===// - -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); - }); -} - //===----------------------------------------------------------------------===// // Type method implementations //===----------------------------------------------------------------------===// -- 2.40.0