From: Sam McCall Date: Mon, 22 Jul 2019 15:55:53 +0000 (+0000) Subject: [clangd] Add dlog()s for SelectionTree, enabling -debug-only=SelectionTree.cpp X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=203ac6f293d32bb5fd7e3890edbee49fc152019b;p=clang [clangd] Add dlog()s for SelectionTree, enabling -debug-only=SelectionTree.cpp Summary: SelectionTree is a RecursiveASTVisitor which processes getSourceRange() for every node. This is a lot of surface area with the AST, as getSourceRange() is specialized for *many* node types. And the resulting SelectionTree depends on the source ranges of many visited nodes, and the order of traversal. Put together, this means we really need a traversal log to debug when we get an unexpected SelectionTree. I've built this ad-hoc a few times, now it's time to check it in. Example output: ``` D[14:07:44.184] Computing selection for D[14:07:44.184] push: VarDecl const auto x = 42 D[14:07:44.184] claimRange: D[14:07:44.184] push: NestedNameSpecifierLoc (empty NestedNameSpecifierLoc) D[14:07:44.184] pop: NestedNameSpecifierLoc (empty NestedNameSpecifierLoc) D[14:07:44.184] push: QualifiedTypeLoc const auto D[14:07:44.184] pop: QualifiedTypeLoc const auto D[14:07:44.184] claimRange: D[14:07:44.184] hit selection: D[14:07:44.184] skip: IntegerLiteral 42 D[14:07:44.184] skipped range = D[14:07:44.184] pop: VarDecl const auto x = 42 D[14:07:44.184] claimRange: D[14:07:44.184] skip: VarDecl int y = 43 D[14:07:44.184] skipped range = D[14:07:44.184] Built selection tree TranslationUnitDecl VarDecl const auto x = 42 .QualifiedTypeLoc const auto ``` Reviewers: hokein Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65073 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366698 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTTypeTraits.cpp b/lib/AST/ASTTypeTraits.cpp index ba1581bd3f..ba65c13859 100644 --- a/lib/AST/ASTTypeTraits.cpp +++ b/lib/AST/ASTTypeTraits.cpp @@ -15,6 +15,7 @@ #include "clang/AST/ASTTypeTraits.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/NestedNameSpecifier.h" namespace clang { namespace ast_type_traits { @@ -129,9 +130,12 @@ void DynTypedNode::print(llvm::raw_ostream &OS, TN->print(OS, PP); else if (const NestedNameSpecifier *NNS = get()) NNS->print(OS, PP); - else if (const NestedNameSpecifierLoc *NNSL = get()) - NNSL->getNestedNameSpecifier()->print(OS, PP); - else if (const QualType *QT = get()) + else if (const NestedNameSpecifierLoc *NNSL = get()) { + if (const NestedNameSpecifier *NNS = NNSL->getNestedNameSpecifier()) + NNS->print(OS, PP); + else + OS << "(empty NestedNameSpecifierLoc)"; + } else if (const QualType *QT = get()) QT->print(OS, PP); else if (const TypeLoc *TL = get()) TL->getType().print(OS, PP);