2007-10-07 14:04:32 +08:00
|
|
|
//===--- ASTConsumers.cpp - ASTConsumer implementations -------------------===//
|
2007-06-23 08:39:57 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-23 08:39:57 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2007-10-07 14:04:32 +08:00
|
|
|
// AST Consumer Implementations.
|
2007-06-23 08:39:57 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-05-19 06:50:54 +08:00
|
|
|
#include "clang/Frontend/ASTConsumers.h"
|
2007-06-23 08:39:57 +08:00
|
|
|
#include "clang/AST/AST.h"
|
2007-09-16 07:02:28 +08:00
|
|
|
#include "clang/AST/ASTConsumer.h"
|
2009-03-28 12:27:18 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2009-05-30 04:38:28 +08:00
|
|
|
#include "clang/AST/PrettyPrinter.h"
|
2012-07-27 00:01:23 +08:00
|
|
|
#include "clang/AST/RecordLayout.h"
|
|
|
|
#include "clang/AST/RecursiveASTVisitor.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
2010-11-30 02:12:39 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-07-27 00:01:23 +08:00
|
|
|
#include "llvm/Support/Timer.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2007-08-09 06:51:59 +08:00
|
|
|
using namespace clang;
|
2007-06-23 08:39:57 +08:00
|
|
|
|
2007-11-28 05:46:50 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-05-30 08:08:05 +08:00
|
|
|
/// ASTPrinter - Pretty-printer and dumper of ASTs
|
2007-11-28 05:46:50 +08:00
|
|
|
|
|
|
|
namespace {
|
2012-07-27 00:01:23 +08:00
|
|
|
class ASTPrinter : public ASTConsumer,
|
|
|
|
public RecursiveASTVisitor<ASTPrinter> {
|
|
|
|
typedef RecursiveASTVisitor<ASTPrinter> base;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2007-11-28 05:46:50 +08:00
|
|
|
public:
|
2017-03-10 06:00:01 +08:00
|
|
|
enum Kind { DumpFull, Dump, Print, None };
|
|
|
|
ASTPrinter(std::unique_ptr<raw_ostream> Out, Kind K, StringRef FilterString,
|
|
|
|
bool DumpLookups = false)
|
|
|
|
: Out(Out ? *Out : llvm::outs()), OwnedOut(std::move(Out)),
|
|
|
|
OutputKind(K), FilterString(FilterString), DumpLookups(DumpLookups) {}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2014-03-13 14:07:04 +08:00
|
|
|
void HandleTranslationUnit(ASTContext &Context) override {
|
2012-07-27 00:01:23 +08:00
|
|
|
TranslationUnitDecl *D = Context.getTranslationUnitDecl();
|
|
|
|
|
2013-06-24 09:45:33 +08:00
|
|
|
if (FilterString.empty())
|
|
|
|
return print(D);
|
2012-07-27 00:01:23 +08:00
|
|
|
|
|
|
|
TraverseDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldWalkTypesOfTypeLocs() const { return false; }
|
|
|
|
|
|
|
|
bool TraverseDecl(Decl *D) {
|
2014-05-22 12:46:25 +08:00
|
|
|
if (D && filterMatches(D)) {
|
2012-11-21 18:54:55 +08:00
|
|
|
bool ShowColors = Out.has_colors();
|
|
|
|
if (ShowColors)
|
2013-01-13 03:30:44 +08:00
|
|
|
Out.changeColor(raw_ostream::BLUE);
|
2017-03-10 06:00:01 +08:00
|
|
|
Out << (OutputKind != Print ? "Dumping " : "Printing ") << getName(D)
|
2014-08-12 06:11:07 +08:00
|
|
|
<< ":\n";
|
2012-11-21 18:54:55 +08:00
|
|
|
if (ShowColors)
|
|
|
|
Out.resetColor();
|
2013-06-24 09:45:33 +08:00
|
|
|
print(D);
|
2012-08-18 01:38:39 +08:00
|
|
|
Out << "\n";
|
2012-07-27 00:01:23 +08:00
|
|
|
// Don't traverse child nodes to avoid output duplication.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return base::TraverseDecl(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string getName(Decl *D) {
|
|
|
|
if (isa<NamedDecl>(D))
|
|
|
|
return cast<NamedDecl>(D)->getQualifiedNameAsString();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
bool filterMatches(Decl *D) {
|
|
|
|
return getName(D).find(FilterString) != std::string::npos;
|
2007-06-23 08:39:57 +08:00
|
|
|
}
|
2013-06-24 09:45:33 +08:00
|
|
|
void print(Decl *D) {
|
|
|
|
if (DumpLookups) {
|
2014-08-12 06:11:07 +08:00
|
|
|
if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
|
|
|
|
if (DC == DC->getPrimaryContext())
|
2017-03-10 06:00:01 +08:00
|
|
|
DC->dumpLookups(Out, OutputKind != None, OutputKind == DumpFull);
|
2014-08-12 06:11:07 +08:00
|
|
|
else
|
|
|
|
Out << "Lookup map is in primary DeclContext "
|
|
|
|
<< DC->getPrimaryContext() << "\n";
|
|
|
|
} else
|
2013-06-24 09:45:33 +08:00
|
|
|
Out << "Not a DeclContext\n";
|
2017-03-10 06:00:01 +08:00
|
|
|
} else if (OutputKind == Print)
|
2013-06-24 09:45:33 +08:00
|
|
|
D->print(Out, /*Indentation=*/0, /*PrintInstantiation=*/true);
|
2017-03-10 06:00:01 +08:00
|
|
|
else if (OutputKind != None)
|
|
|
|
D->dump(Out, OutputKind == DumpFull);
|
2013-06-24 09:45:33 +08:00
|
|
|
}
|
2012-07-27 00:01:23 +08:00
|
|
|
|
|
|
|
raw_ostream &Out;
|
2016-07-15 08:55:40 +08:00
|
|
|
std::unique_ptr<raw_ostream> OwnedOut;
|
2017-03-10 06:00:01 +08:00
|
|
|
|
|
|
|
/// How to output individual declarations.
|
|
|
|
Kind OutputKind;
|
|
|
|
|
|
|
|
/// Which declarations or DeclContexts to display.
|
2012-07-27 00:01:23 +08:00
|
|
|
std::string FilterString;
|
2017-03-10 06:00:01 +08:00
|
|
|
|
|
|
|
/// Whether the primary output is lookup results or declarations. Individual
|
|
|
|
/// results will be output with a format determined by OutputKind. This is
|
|
|
|
/// incompatible with OutputKind == Print.
|
2013-06-24 09:45:33 +08:00
|
|
|
bool DumpLookups;
|
2007-09-16 07:02:28 +08:00
|
|
|
};
|
2012-07-31 17:37:40 +08:00
|
|
|
|
|
|
|
class ASTDeclNodeLister : public ASTConsumer,
|
|
|
|
public RecursiveASTVisitor<ASTDeclNodeLister> {
|
|
|
|
public:
|
2014-05-22 12:46:25 +08:00
|
|
|
ASTDeclNodeLister(raw_ostream *Out = nullptr)
|
2012-07-31 17:37:40 +08:00
|
|
|
: Out(Out ? *Out : llvm::outs()) {}
|
|
|
|
|
2014-03-13 14:07:04 +08:00
|
|
|
void HandleTranslationUnit(ASTContext &Context) override {
|
2012-07-31 17:37:40 +08:00
|
|
|
TraverseDecl(Context.getTranslationUnitDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool shouldWalkTypesOfTypeLocs() const { return false; }
|
|
|
|
|
2014-03-13 15:14:47 +08:00
|
|
|
bool VisitNamedDecl(NamedDecl *D) {
|
2013-02-23 21:53:57 +08:00
|
|
|
D->printQualifiedName(Out);
|
|
|
|
Out << '\n';
|
2012-07-31 17:37:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
raw_ostream &Out;
|
|
|
|
};
|
2009-03-28 13:44:17 +08:00
|
|
|
} // end anonymous namespace
|
2007-08-09 06:51:59 +08:00
|
|
|
|
2016-07-15 08:55:40 +08:00
|
|
|
std::unique_ptr<ASTConsumer>
|
|
|
|
clang::CreateASTPrinter(std::unique_ptr<raw_ostream> Out,
|
|
|
|
StringRef FilterString) {
|
2017-03-10 06:00:01 +08:00
|
|
|
return llvm::make_unique<ASTPrinter>(std::move(Out), ASTPrinter::Print,
|
2016-07-15 08:55:40 +08:00
|
|
|
FilterString);
|
2007-11-29 05:32:21 +08:00
|
|
|
}
|
2007-11-28 05:46:50 +08:00
|
|
|
|
2014-08-11 03:56:51 +08:00
|
|
|
std::unique_ptr<ASTConsumer> clang::CreateASTDumper(StringRef FilterString,
|
2014-08-12 06:11:07 +08:00
|
|
|
bool DumpDecls,
|
2017-03-10 06:00:01 +08:00
|
|
|
bool Deserialize,
|
2014-08-11 03:56:51 +08:00
|
|
|
bool DumpLookups) {
|
2017-06-15 08:00:08 +08:00
|
|
|
assert((DumpDecls || Deserialize || DumpLookups) && "nothing to dump");
|
2017-03-10 06:00:01 +08:00
|
|
|
return llvm::make_unique<ASTPrinter>(nullptr,
|
|
|
|
Deserialize ? ASTPrinter::DumpFull :
|
|
|
|
DumpDecls ? ASTPrinter::Dump :
|
|
|
|
ASTPrinter::None,
|
|
|
|
FilterString, DumpLookups);
|
2009-04-26 10:02:08 +08:00
|
|
|
}
|
2007-09-16 07:02:28 +08:00
|
|
|
|
2014-08-11 03:56:51 +08:00
|
|
|
std::unique_ptr<ASTConsumer> clang::CreateASTDeclNodeLister() {
|
|
|
|
return llvm::make_unique<ASTDeclNodeLister>(nullptr);
|
2012-07-31 17:37:40 +08:00
|
|
|
}
|
|
|
|
|
2007-11-28 05:46:50 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// ASTViewer - AST Visualization
|
|
|
|
|
2007-09-20 05:29:43 +08:00
|
|
|
namespace {
|
|
|
|
class ASTViewer : public ASTConsumer {
|
2009-05-30 08:08:05 +08:00
|
|
|
ASTContext *Context;
|
2007-09-20 05:29:43 +08:00
|
|
|
public:
|
2014-03-13 14:07:04 +08:00
|
|
|
void Initialize(ASTContext &Context) override {
|
2009-05-30 08:08:05 +08:00
|
|
|
this->Context = &Context;
|
2007-09-20 05:29:43 +08:00
|
|
|
}
|
2009-03-30 00:50:03 +08:00
|
|
|
|
2014-03-13 14:07:04 +08:00
|
|
|
bool HandleTopLevelDecl(DeclGroupRef D) override {
|
2009-03-30 00:50:03 +08:00
|
|
|
for (DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I)
|
|
|
|
HandleTopLevelSingleDecl(*I);
|
2011-11-18 08:26:59 +08:00
|
|
|
return true;
|
2009-03-30 00:50:03 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-03-30 00:50:03 +08:00
|
|
|
void HandleTopLevelSingleDecl(Decl *D);
|
2007-09-20 05:29:43 +08:00
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2007-09-20 05:29:43 +08:00
|
|
|
|
2009-03-30 00:50:03 +08:00
|
|
|
void ASTViewer::HandleTopLevelSingleDecl(Decl *D) {
|
2010-07-07 19:31:23 +08:00
|
|
|
if (isa<FunctionDecl>(D) || isa<ObjCMethodDecl>(D)) {
|
|
|
|
D->print(llvm::errs());
|
|
|
|
|
|
|
|
if (Stmt *Body = D->getBody()) {
|
2009-08-23 20:08:50 +08:00
|
|
|
llvm::errs() << '\n';
|
2009-09-12 08:08:48 +08:00
|
|
|
Body->viewAST();
|
2009-08-23 20:08:50 +08:00
|
|
|
llvm::errs() << '\n';
|
2009-03-28 13:44:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 03:56:51 +08:00
|
|
|
std::unique_ptr<ASTConsumer> clang::CreateASTViewer() {
|
|
|
|
return llvm::make_unique<ASTViewer>();
|
|
|
|
}
|
2007-09-20 05:29:43 +08:00
|
|
|
|
2009-01-13 09:29:24 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// DeclContextPrinter - Decl and DeclContext Visualization
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class DeclContextPrinter : public ASTConsumer {
|
2011-07-23 18:55:15 +08:00
|
|
|
raw_ostream& Out;
|
2009-01-13 09:29:24 +08:00
|
|
|
public:
|
|
|
|
DeclContextPrinter() : Out(llvm::errs()) {}
|
|
|
|
|
2014-03-13 14:07:04 +08:00
|
|
|
void HandleTranslationUnit(ASTContext &C) override {
|
2009-03-28 12:11:33 +08:00
|
|
|
PrintDeclContext(C.getTranslationUnitDecl(), 4);
|
2009-01-13 09:29:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrintDeclContext(const DeclContext* DC, unsigned Indentation);
|
|
|
|
};
|
2009-03-28 13:44:17 +08:00
|
|
|
} // end anonymous namespace
|
2009-01-13 09:29:24 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
|
2009-01-13 09:29:24 +08:00
|
|
|
unsigned Indentation) {
|
|
|
|
// Print DeclContext name.
|
2009-01-13 21:11:58 +08:00
|
|
|
switch (DC->getDeclKind()) {
|
2009-01-13 09:29:24 +08:00
|
|
|
case Decl::TranslationUnit:
|
|
|
|
Out << "[translation unit] " << DC;
|
|
|
|
break;
|
|
|
|
case Decl::Namespace: {
|
|
|
|
Out << "[namespace] ";
|
2009-02-16 22:29:59 +08:00
|
|
|
const NamespaceDecl* ND = cast<NamespaceDecl>(DC);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *ND;
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-01-13 10:41:08 +08:00
|
|
|
case Decl::Enum: {
|
2009-02-16 22:29:59 +08:00
|
|
|
const EnumDecl* ED = cast<EnumDecl>(DC);
|
2011-10-07 14:10:15 +08:00
|
|
|
if (ED->isCompleteDefinition())
|
2009-01-13 10:41:08 +08:00
|
|
|
Out << "[enum] ";
|
|
|
|
else
|
|
|
|
Out << "<enum> ";
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *ED;
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
2009-01-13 10:41:08 +08:00
|
|
|
}
|
2009-01-13 09:29:24 +08:00
|
|
|
case Decl::Record: {
|
2009-02-16 22:29:59 +08:00
|
|
|
const RecordDecl* RD = cast<RecordDecl>(DC);
|
2011-10-07 14:10:15 +08:00
|
|
|
if (RD->isCompleteDefinition())
|
2009-01-13 09:29:24 +08:00
|
|
|
Out << "[struct] ";
|
|
|
|
else
|
|
|
|
Out << "<struct> ";
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *RD;
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::CXXRecord: {
|
2009-02-16 22:29:59 +08:00
|
|
|
const CXXRecordDecl* RD = cast<CXXRecordDecl>(DC);
|
2011-10-07 14:10:15 +08:00
|
|
|
if (RD->isCompleteDefinition())
|
2009-01-13 09:29:24 +08:00
|
|
|
Out << "[class] ";
|
|
|
|
else
|
|
|
|
Out << "<class> ";
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *RD << ' ' << DC;
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ObjCMethod:
|
|
|
|
Out << "[objc method]";
|
|
|
|
break;
|
|
|
|
case Decl::ObjCInterface:
|
|
|
|
Out << "[objc interface]";
|
|
|
|
break;
|
|
|
|
case Decl::ObjCCategory:
|
|
|
|
Out << "[objc category]";
|
|
|
|
break;
|
|
|
|
case Decl::ObjCProtocol:
|
|
|
|
Out << "[objc protocol]";
|
|
|
|
break;
|
|
|
|
case Decl::ObjCImplementation:
|
|
|
|
Out << "[objc implementation]";
|
|
|
|
break;
|
|
|
|
case Decl::ObjCCategoryImpl:
|
|
|
|
Out << "[objc categoryimpl]";
|
|
|
|
break;
|
|
|
|
case Decl::LinkageSpec:
|
|
|
|
Out << "[linkage spec]";
|
|
|
|
break;
|
|
|
|
case Decl::Block:
|
|
|
|
Out << "[block]";
|
|
|
|
break;
|
|
|
|
case Decl::Function: {
|
2009-02-16 22:29:59 +08:00
|
|
|
const FunctionDecl* FD = cast<FunctionDecl>(DC);
|
2011-05-07 04:44:56 +08:00
|
|
|
if (FD->doesThisDeclarationHaveABody())
|
2009-01-13 09:29:24 +08:00
|
|
|
Out << "[function] ";
|
|
|
|
else
|
|
|
|
Out << "<function> ";
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *FD;
|
2009-01-13 14:25:33 +08:00
|
|
|
// Print the parameters.
|
|
|
|
Out << "(";
|
|
|
|
bool PrintComma = false;
|
2016-06-24 12:05:48 +08:00
|
|
|
for (auto I : FD->parameters()) {
|
2009-01-13 14:25:33 +08:00
|
|
|
if (PrintComma)
|
|
|
|
Out << ", ";
|
|
|
|
else
|
|
|
|
PrintComma = true;
|
2014-03-07 23:12:56 +08:00
|
|
|
Out << *I;
|
2009-01-13 14:25:33 +08:00
|
|
|
}
|
|
|
|
Out << ")";
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::CXXMethod: {
|
2009-02-16 22:29:59 +08:00
|
|
|
const CXXMethodDecl* D = cast<CXXMethodDecl>(DC);
|
2009-06-18 06:49:50 +08:00
|
|
|
if (D->isOutOfLine())
|
2009-01-13 09:29:24 +08:00
|
|
|
Out << "[c++ method] ";
|
2009-01-13 11:26:38 +08:00
|
|
|
else if (D->isImplicit())
|
|
|
|
Out << "(c++ method) ";
|
2009-01-13 09:29:24 +08:00
|
|
|
else
|
|
|
|
Out << "<c++ method> ";
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *D;
|
2009-01-13 14:25:33 +08:00
|
|
|
// Print the parameters.
|
|
|
|
Out << "(";
|
|
|
|
bool PrintComma = false;
|
2016-06-24 13:33:44 +08:00
|
|
|
for (ParmVarDecl *Parameter : D->parameters()) {
|
2009-01-13 14:25:33 +08:00
|
|
|
if (PrintComma)
|
|
|
|
Out << ", ";
|
|
|
|
else
|
|
|
|
PrintComma = true;
|
2016-06-24 13:33:44 +08:00
|
|
|
Out << *Parameter;
|
2009-01-13 14:25:33 +08:00
|
|
|
}
|
|
|
|
Out << ")";
|
2009-01-13 09:29:24 +08:00
|
|
|
|
|
|
|
// Check the semantic DeclContext.
|
2009-02-16 22:29:59 +08:00
|
|
|
const DeclContext* SemaDC = D->getDeclContext();
|
|
|
|
const DeclContext* LexicalDC = D->getLexicalDeclContext();
|
2009-01-13 11:26:38 +08:00
|
|
|
if (SemaDC != LexicalDC)
|
2009-01-13 09:29:24 +08:00
|
|
|
Out << " [[" << SemaDC << "]]";
|
2009-01-13 11:26:38 +08:00
|
|
|
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::CXXConstructor: {
|
2009-02-16 22:29:59 +08:00
|
|
|
const CXXConstructorDecl* D = cast<CXXConstructorDecl>(DC);
|
2009-06-18 06:49:50 +08:00
|
|
|
if (D->isOutOfLine())
|
2009-01-13 09:29:24 +08:00
|
|
|
Out << "[c++ ctor] ";
|
2009-01-13 11:26:38 +08:00
|
|
|
else if (D->isImplicit())
|
|
|
|
Out << "(c++ ctor) ";
|
2009-01-13 09:29:24 +08:00
|
|
|
else
|
|
|
|
Out << "<c++ ctor> ";
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *D;
|
2009-01-13 14:25:33 +08:00
|
|
|
// Print the parameters.
|
|
|
|
Out << "(";
|
|
|
|
bool PrintComma = false;
|
2016-06-24 13:33:44 +08:00
|
|
|
for (ParmVarDecl *Parameter : D->parameters()) {
|
2009-01-13 14:25:33 +08:00
|
|
|
if (PrintComma)
|
|
|
|
Out << ", ";
|
|
|
|
else
|
|
|
|
PrintComma = true;
|
2016-06-24 13:33:44 +08:00
|
|
|
Out << *Parameter;
|
2009-01-13 14:25:33 +08:00
|
|
|
}
|
|
|
|
Out << ")";
|
|
|
|
|
2009-01-13 11:26:38 +08:00
|
|
|
// Check the semantic DC.
|
2009-02-16 22:29:59 +08:00
|
|
|
const DeclContext* SemaDC = D->getDeclContext();
|
|
|
|
const DeclContext* LexicalDC = D->getLexicalDeclContext();
|
2009-01-13 11:26:38 +08:00
|
|
|
if (SemaDC != LexicalDC)
|
|
|
|
Out << " [[" << SemaDC << "]]";
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::CXXDestructor: {
|
2009-02-16 22:29:59 +08:00
|
|
|
const CXXDestructorDecl* D = cast<CXXDestructorDecl>(DC);
|
2009-06-18 06:49:50 +08:00
|
|
|
if (D->isOutOfLine())
|
2009-01-13 09:29:24 +08:00
|
|
|
Out << "[c++ dtor] ";
|
2009-01-13 11:26:38 +08:00
|
|
|
else if (D->isImplicit())
|
|
|
|
Out << "(c++ dtor) ";
|
2009-01-13 09:29:24 +08:00
|
|
|
else
|
|
|
|
Out << "<c++ dtor> ";
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *D;
|
2009-01-13 11:26:38 +08:00
|
|
|
// Check the semantic DC.
|
2009-02-16 22:29:59 +08:00
|
|
|
const DeclContext* SemaDC = D->getDeclContext();
|
|
|
|
const DeclContext* LexicalDC = D->getLexicalDeclContext();
|
2009-01-13 11:26:38 +08:00
|
|
|
if (SemaDC != LexicalDC)
|
|
|
|
Out << " [[" << SemaDC << "]]";
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::CXXConversion: {
|
2009-02-16 22:29:59 +08:00
|
|
|
const CXXConversionDecl* D = cast<CXXConversionDecl>(DC);
|
2009-06-18 06:49:50 +08:00
|
|
|
if (D->isOutOfLine())
|
2009-01-13 09:29:24 +08:00
|
|
|
Out << "[c++ conversion] ";
|
2009-01-13 11:26:38 +08:00
|
|
|
else if (D->isImplicit())
|
|
|
|
Out << "(c++ conversion) ";
|
2009-01-13 09:29:24 +08:00
|
|
|
else
|
|
|
|
Out << "<c++ conversion> ";
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << *D;
|
2009-01-13 11:26:38 +08:00
|
|
|
// Check the semantic DC.
|
2009-02-16 22:29:59 +08:00
|
|
|
const DeclContext* SemaDC = D->getDeclContext();
|
|
|
|
const DeclContext* LexicalDC = D->getLexicalDeclContext();
|
2009-01-13 11:26:38 +08:00
|
|
|
if (SemaDC != LexicalDC)
|
|
|
|
Out << " [[" << SemaDC << "]]";
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-03 20:11:17 +08:00
|
|
|
case Decl::ClassTemplateSpecialization: {
|
|
|
|
const auto *CTSD = cast<ClassTemplateSpecializationDecl>(DC);
|
|
|
|
if (CTSD->isCompleteDefinition())
|
|
|
|
Out << "[class template specialization] ";
|
|
|
|
else
|
|
|
|
Out << "<class template specialization> ";
|
|
|
|
Out << *CTSD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Decl::ClassTemplatePartialSpecialization: {
|
|
|
|
const auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl>(DC);
|
|
|
|
if (CTPSD->isCompleteDefinition())
|
|
|
|
Out << "[class template partial specialization] ";
|
|
|
|
else
|
|
|
|
Out << "<class template partial specialization> ";
|
|
|
|
Out << *CTPSD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-13 09:29:24 +08:00
|
|
|
default:
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("a decl that inherits DeclContext isn't handled");
|
2009-01-13 09:29:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Out << "\n";
|
|
|
|
|
|
|
|
// Print decls in the DeclContext.
|
2014-03-08 03:56:05 +08:00
|
|
|
for (auto *I : DC->decls()) {
|
2009-01-13 09:29:24 +08:00
|
|
|
for (unsigned i = 0; i < Indentation; ++i)
|
2009-02-11 04:16:46 +08:00
|
|
|
Out << " ";
|
2009-01-13 09:29:24 +08:00
|
|
|
|
|
|
|
Decl::Kind DK = I->getKind();
|
|
|
|
switch (DK) {
|
|
|
|
case Decl::Namespace:
|
|
|
|
case Decl::Enum:
|
|
|
|
case Decl::Record:
|
|
|
|
case Decl::CXXRecord:
|
|
|
|
case Decl::ObjCMethod:
|
|
|
|
case Decl::ObjCInterface:
|
2009-09-09 23:08:12 +08:00
|
|
|
case Decl::ObjCCategory:
|
2009-01-13 09:29:24 +08:00
|
|
|
case Decl::ObjCProtocol:
|
|
|
|
case Decl::ObjCImplementation:
|
|
|
|
case Decl::ObjCCategoryImpl:
|
|
|
|
case Decl::LinkageSpec:
|
|
|
|
case Decl::Block:
|
|
|
|
case Decl::Function:
|
|
|
|
case Decl::CXXMethod:
|
|
|
|
case Decl::CXXConstructor:
|
|
|
|
case Decl::CXXDestructor:
|
|
|
|
case Decl::CXXConversion:
|
2017-01-03 20:11:17 +08:00
|
|
|
case Decl::ClassTemplateSpecialization:
|
|
|
|
case Decl::ClassTemplatePartialSpecialization: {
|
2014-03-08 03:56:05 +08:00
|
|
|
DeclContext* DC = cast<DeclContext>(I);
|
2009-02-11 04:16:46 +08:00
|
|
|
PrintDeclContext(DC, Indentation+2);
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-12-21 11:08:02 +08:00
|
|
|
case Decl::IndirectField: {
|
2014-03-08 03:56:05 +08:00
|
|
|
IndirectFieldDecl* IFD = cast<IndirectFieldDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<IndirectField> " << *IFD << '\n';
|
2010-12-21 11:08:02 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-02-18 08:52:55 +08:00
|
|
|
case Decl::Label: {
|
2014-03-08 03:56:05 +08:00
|
|
|
LabelDecl *LD = cast<LabelDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<Label> " << *LD << '\n';
|
2011-02-18 08:52:55 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-01-13 09:29:24 +08:00
|
|
|
case Decl::Field: {
|
2014-03-08 03:56:05 +08:00
|
|
|
FieldDecl *FD = cast<FieldDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<field> " << *FD << '\n';
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-04-15 22:24:37 +08:00
|
|
|
case Decl::Typedef:
|
|
|
|
case Decl::TypeAlias: {
|
2014-03-08 03:56:05 +08:00
|
|
|
TypedefNameDecl* TD = cast<TypedefNameDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<typedef> " << *TD << '\n';
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::EnumConstant: {
|
2014-03-08 03:56:05 +08:00
|
|
|
EnumConstantDecl* ECD = cast<EnumConstantDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<enum constant> " << *ECD << '\n';
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::Var: {
|
2014-03-08 03:56:05 +08:00
|
|
|
VarDecl* VD = cast<VarDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<var> " << *VD << '\n';
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ImplicitParam: {
|
2014-03-08 03:56:05 +08:00
|
|
|
ImplicitParamDecl* IPD = cast<ImplicitParamDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<implicit parameter> " << *IPD << '\n';
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ParmVar: {
|
2014-03-08 03:56:05 +08:00
|
|
|
ParmVarDecl* PVD = cast<ParmVarDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<parameter> " << *PVD << '\n';
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ObjCProperty: {
|
2014-03-08 03:56:05 +08:00
|
|
|
ObjCPropertyDecl* OPD = cast<ObjCPropertyDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<objc property> " << *OPD << '\n';
|
2009-01-13 09:29:24 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-12-08 14:22:37 +08:00
|
|
|
case Decl::FunctionTemplate: {
|
2014-03-08 03:56:05 +08:00
|
|
|
FunctionTemplateDecl* FTD = cast<FunctionTemplateDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<function template> " << *FTD << '\n';
|
2009-12-08 14:22:37 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-01-03 10:01:11 +08:00
|
|
|
case Decl::FileScopeAsm: {
|
|
|
|
Out << "<file-scope asm>\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::UsingDirective: {
|
|
|
|
Out << "<using directive>\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::NamespaceAlias: {
|
2014-03-08 03:56:05 +08:00
|
|
|
NamespaceAliasDecl* NAD = cast<NamespaceAliasDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<namespace alias> " << *NAD << '\n';
|
2010-01-03 10:01:11 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-01-20 11:21:28 +08:00
|
|
|
case Decl::ClassTemplate: {
|
2014-03-08 03:56:05 +08:00
|
|
|
ClassTemplateDecl *CTD = cast<ClassTemplateDecl>(I);
|
2011-10-15 02:45:37 +08:00
|
|
|
Out << "<class template> " << *CTD << '\n';
|
2010-01-20 11:21:28 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-03-22 14:34:35 +08:00
|
|
|
case Decl::OMPThreadPrivate: {
|
2014-03-08 03:56:05 +08:00
|
|
|
Out << "<omp threadprivate> " << '"' << I << "\"\n";
|
2013-03-22 14:34:35 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-01-03 20:07:20 +08:00
|
|
|
case Decl::Friend: {
|
|
|
|
Out << "<friend>";
|
|
|
|
if (const NamedDecl *ND = cast<FriendDecl>(I)->getFriendDecl())
|
|
|
|
Out << ' ' << *ND;
|
|
|
|
Out << "\n";
|
|
|
|
break;
|
|
|
|
}
|
2017-01-03 20:08:40 +08:00
|
|
|
case Decl::Using: {
|
|
|
|
Out << "<using> " << *cast<UsingDecl>(I) << "\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::UsingShadow: {
|
|
|
|
Out << "<using shadow> " << *cast<UsingShadowDecl>(I) << "\n";
|
|
|
|
break;
|
|
|
|
}
|
2017-01-03 20:09:39 +08:00
|
|
|
case Decl::Empty: {
|
|
|
|
Out << "<empty>\n";
|
|
|
|
break;
|
|
|
|
}
|
2017-01-03 20:12:36 +08:00
|
|
|
case Decl::AccessSpec: {
|
|
|
|
Out << "<access specifier>\n";
|
|
|
|
break;
|
|
|
|
}
|
2017-01-03 20:14:59 +08:00
|
|
|
case Decl::VarTemplate: {
|
|
|
|
Out << "<var template> " << *cast<VarTemplateDecl>(I) << "\n";
|
|
|
|
break;
|
|
|
|
}
|
2017-01-03 20:16:02 +08:00
|
|
|
case Decl::StaticAssert: {
|
|
|
|
Out << "<static assert>\n";
|
|
|
|
break;
|
|
|
|
}
|
2009-01-13 09:29:24 +08:00
|
|
|
default:
|
2014-03-08 03:56:05 +08:00
|
|
|
Out << "DeclKind: " << DK << '"' << I << "\"\n";
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("decl unhandled");
|
2009-01-13 09:29:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-11 03:56:51 +08:00
|
|
|
std::unique_ptr<ASTConsumer> clang::CreateDeclContextPrinter() {
|
|
|
|
return llvm::make_unique<DeclContextPrinter>();
|
2009-01-13 09:29:24 +08:00
|
|
|
}
|