22 #include "llvm/Support/Path.h"
23 #include "llvm/Support/Timer.h"
24 #include "llvm/Support/raw_ostream.h"
25 using namespace clang;
37 ASTPrinter(std::unique_ptr<raw_ostream> Out,
Kind K,
39 bool DumpLookups =
false,
bool DumpDeclTypes =
false)
40 : Out(Out ? *Out :
llvm::outs()), OwnedOut(
std::move(Out)),
41 OutputKind(K), OutputFormat(Format), FilterString(FilterString),
42 DumpLookups(DumpLookups), DumpDeclTypes(DumpDeclTypes) {}
44 void HandleTranslationUnit(
ASTContext &Context)
override {
47 if (FilterString.empty())
53 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
55 bool TraverseDecl(
Decl *
D) {
56 if (
D && filterMatches(
D)) {
59 Out.changeColor(raw_ostream::BLUE);
62 Out << (OutputKind != Print ?
"Dumping " :
"Printing ") <<
getName(
D)
72 return base::TraverseDecl(
D);
77 if (isa<NamedDecl>(
D))
78 return cast<NamedDecl>(
D)->getQualifiedNameAsString();
81 bool filterMatches(
Decl *
D) {
82 return getName(
D).find(FilterString) != std::string::npos;
87 if (DC == DC->getPrimaryContext())
88 DC->dumpLookups(Out, OutputKind != None, OutputKind == DumpFull);
90 Out <<
"Lookup map is in primary DeclContext "
91 << DC->getPrimaryContext() <<
"\n";
93 Out <<
"Not a DeclContext\n";
94 }
else if (OutputKind == Print) {
96 D->
print(Out, Policy, 0,
true);
97 }
else if (OutputKind != None) {
98 D->
dump(Out, OutputKind == DumpFull, OutputFormat);
103 if (
auto *TD = dyn_cast<TemplateDecl>(
D))
104 InnerD = TD->getTemplatedDecl();
108 if (
auto *VD = dyn_cast<ValueDecl>(InnerD))
109 VD->getType().
dump(Out, VD->getASTContext());
110 if (
auto *TD = dyn_cast<TypeDecl>(InnerD))
111 TD->getTypeForDecl()->dump(Out, TD->getASTContext());
116 std::unique_ptr<raw_ostream> OwnedOut;
125 std::string FilterString;
139 ASTDeclNodeLister(raw_ostream *Out =
nullptr)
140 : Out(Out ? *Out :
llvm::outs()) {}
142 void HandleTranslationUnit(
ASTContext &Context)
override {
146 bool shouldWalkTypesOfTypeLocs()
const {
return false; }
149 D->printQualifiedName(Out);
159 std::unique_ptr<ASTConsumer>
161 StringRef FilterString) {
162 return std::make_unique<ASTPrinter>(std::move(Out), ASTPrinter::Print,
166 std::unique_ptr<ASTConsumer>
168 bool DumpDecls,
bool Deserialize,
bool DumpLookups,
170 assert((DumpDecls || Deserialize || DumpLookups) &&
"nothing to dump");
171 return std::make_unique<ASTPrinter>(
173 Deserialize ? ASTPrinter::DumpFull
175 Format, FilterString, DumpLookups, DumpDeclTypes);
179 return std::make_unique<ASTDeclNodeLister>(
nullptr);
190 void Initialize(
ASTContext &Context)
override { this->Context = &Context; }
194 HandleTopLevelSingleDecl(*I);
198 void HandleTopLevelSingleDecl(
Decl *
D);
202 void ASTViewer::HandleTopLevelSingleDecl(
Decl *
D) {
203 if (isa<FunctionDecl>(
D) || isa<ObjCMethodDecl>(
D)) {
207 llvm::errs() <<
'\n';
209 llvm::errs() <<
'\n';
215 return std::make_unique<ASTViewer>();
Defines the clang::ASTContext interface.
Defines the Diagnostic-related interfaces.
enum clang::sema::@1659::IndirectLocalPathEntry::EntryKind Kind
void print(llvm::raw_ostream &OS, const Pointer &P, ASTContext &Ctx, QualType Ty)
static std::string getName(const CallEvent &Call)
Defines the SourceManager interface.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
const LangOptions & getLangOpts() const
TranslationUnitDecl * getTranslationUnitDecl() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
void print(raw_ostream &Out, unsigned Indentation=0, bool PrintInstantiation=false) const
This represents a decl that may have a name.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Stmt - This represents one statement.
The top declaration context.
constexpr XRayInstrMask None
bool Dump(InterpState &S, CodePtr OpPC)
The JSON file list parser is used to communicate input to InstallAPI.
ASTDumpOutputFormat
Used to specify the format for printing AST dump information.
std::unique_ptr< ASTConsumer > CreateASTDeclNodeLister()
std::unique_ptr< ASTConsumer > CreateASTDumper(std::unique_ptr< raw_ostream > OS, StringRef FilterString, bool DumpDecls, bool Deserialize, bool DumpLookups, bool DumpDeclTypes, ASTDumpOutputFormat Format)
std::unique_ptr< ASTConsumer > CreateASTPrinter(std::unique_ptr< raw_ostream > OS, StringRef FilterString)
std::unique_ptr< ASTConsumer > CreateASTViewer()
Diagnostic wrappers for TextAPI types for error reporting.
Describes how types, statements, expressions, and declarations should be printed.