2012-10-18 15:55:46 +08:00
|
|
|
//===--- DumpXML.cpp - Detailed XML dumping -------------------------------===//
|
2010-11-24 19:30:07 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the Decl::dumpXML() method, a debugging tool to
|
|
|
|
// print a detailed graph of an AST in an unspecified XML format.
|
|
|
|
//
|
|
|
|
// There is no guarantee of stability for this format.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// Only pay for this in code size in assertions-enabled builds.
|
|
|
|
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2012-12-01 23:09:41 +08:00
|
|
|
#include "clang/AST/Attr.h"
|
2010-11-24 19:30:07 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
#include "clang/AST/DeclFriend.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
|
|
|
#include "clang/AST/DeclVisitor.h"
|
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
#include "clang/AST/ExprCXX.h"
|
|
|
|
#include "clang/AST/ExprObjC.h"
|
|
|
|
#include "clang/AST/NestedNameSpecifier.h"
|
|
|
|
#include "clang/AST/Stmt.h"
|
|
|
|
#include "clang/AST/StmtCXX.h"
|
|
|
|
#include "clang/AST/StmtObjC.h"
|
|
|
|
#include "clang/AST/StmtVisitor.h"
|
|
|
|
#include "clang/AST/TemplateBase.h"
|
|
|
|
#include "clang/AST/TemplateName.h"
|
|
|
|
#include "clang/AST/Type.h"
|
|
|
|
#include "clang/AST/TypeLoc.h"
|
|
|
|
#include "clang/AST/TypeLocVisitor.h"
|
|
|
|
#include "clang/AST/TypeVisitor.h"
|
2012-02-04 21:45:25 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2010-11-24 19:30:07 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum NodeState {
|
|
|
|
NS_Attrs, NS_LazyChildren, NS_Children
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Node {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef Name;
|
2010-11-24 19:30:07 +08:00
|
|
|
NodeState State;
|
2011-07-23 18:55:15 +08:00
|
|
|
Node(StringRef name) : Name(name), State(NS_Attrs) {}
|
2010-11-24 19:30:07 +08:00
|
|
|
|
|
|
|
bool isDoneWithAttrs() const { return State != NS_Attrs; }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Impl> struct XMLDeclVisitor {
|
|
|
|
#define DISPATCH(NAME, CLASS) \
|
|
|
|
static_cast<Impl*>(this)->NAME(static_cast<CLASS*>(D))
|
|
|
|
|
|
|
|
void dispatch(Decl *D) {
|
2012-10-18 15:55:46 +08:00
|
|
|
if (D->isUsed())
|
|
|
|
static_cast<Impl*>(this)->set("used", "1");
|
2010-11-24 19:30:07 +08:00
|
|
|
switch (D->getKind()) {
|
|
|
|
#define DECL(DERIVED, BASE) \
|
|
|
|
case Decl::DERIVED: \
|
|
|
|
DISPATCH(dispatch##DERIVED##DeclAttrs, DERIVED##Decl); \
|
|
|
|
static_cast<Impl*>(this)->completeAttrs(); \
|
|
|
|
DISPATCH(dispatch##DERIVED##DeclChildren, DERIVED##Decl); \
|
|
|
|
DISPATCH(dispatch##DERIVED##DeclAsContext, DERIVED##Decl); \
|
|
|
|
break;
|
|
|
|
#define ABSTRACT_DECL(DECL)
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DECL(DERIVED, BASE) \
|
|
|
|
void dispatch##DERIVED##DeclAttrs(DERIVED##Decl *D) { \
|
|
|
|
DISPATCH(dispatch##BASE##Attrs, BASE); \
|
|
|
|
DISPATCH(visit##DERIVED##DeclAttrs, DERIVED##Decl); \
|
|
|
|
} \
|
|
|
|
void visit##DERIVED##DeclAttrs(DERIVED##Decl *D) {} \
|
|
|
|
void dispatch##DERIVED##DeclChildren(DERIVED##Decl *D) { \
|
|
|
|
DISPATCH(dispatch##BASE##Children, BASE); \
|
|
|
|
DISPATCH(visit##DERIVED##DeclChildren, DERIVED##Decl); \
|
|
|
|
} \
|
|
|
|
void visit##DERIVED##DeclChildren(DERIVED##Decl *D) {} \
|
|
|
|
void dispatch##DERIVED##DeclAsContext(DERIVED##Decl *D) { \
|
|
|
|
DISPATCH(dispatch##BASE##AsContext, BASE); \
|
|
|
|
DISPATCH(visit##DERIVED##DeclAsContext, DERIVED##Decl); \
|
|
|
|
} \
|
|
|
|
void visit##DERIVED##DeclAsContext(DERIVED##Decl *D) {}
|
|
|
|
#include "clang/AST/DeclNodes.inc"
|
|
|
|
|
|
|
|
void dispatchDeclAttrs(Decl *D) {
|
|
|
|
DISPATCH(visitDeclAttrs, Decl);
|
|
|
|
}
|
|
|
|
void visitDeclAttrs(Decl *D) {}
|
|
|
|
|
|
|
|
void dispatchDeclChildren(Decl *D) {
|
|
|
|
DISPATCH(visitDeclChildren, Decl);
|
|
|
|
}
|
|
|
|
void visitDeclChildren(Decl *D) {}
|
|
|
|
|
|
|
|
void dispatchDeclAsContext(Decl *D) {
|
|
|
|
DISPATCH(visitDeclAsContext, Decl);
|
|
|
|
}
|
|
|
|
void visitDeclAsContext(Decl *D) {}
|
|
|
|
|
|
|
|
#undef DISPATCH
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Impl> struct XMLTypeVisitor {
|
|
|
|
#define DISPATCH(NAME, CLASS) \
|
|
|
|
static_cast<Impl*>(this)->NAME(static_cast<CLASS*>(T))
|
|
|
|
|
|
|
|
void dispatch(Type *T) {
|
|
|
|
switch (T->getTypeClass()) {
|
|
|
|
#define TYPE(DERIVED, BASE) \
|
|
|
|
case Type::DERIVED: \
|
|
|
|
DISPATCH(dispatch##DERIVED##TypeAttrs, DERIVED##Type); \
|
|
|
|
static_cast<Impl*>(this)->completeAttrs(); \
|
|
|
|
DISPATCH(dispatch##DERIVED##TypeChildren, DERIVED##Type); \
|
|
|
|
break;
|
|
|
|
#define ABSTRACT_TYPE(DERIVED, BASE)
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TYPE(DERIVED, BASE) \
|
|
|
|
void dispatch##DERIVED##TypeAttrs(DERIVED##Type *T) { \
|
|
|
|
DISPATCH(dispatch##BASE##Attrs, BASE); \
|
|
|
|
DISPATCH(visit##DERIVED##TypeAttrs, DERIVED##Type); \
|
|
|
|
} \
|
|
|
|
void visit##DERIVED##TypeAttrs(DERIVED##Type *T) {} \
|
|
|
|
void dispatch##DERIVED##TypeChildren(DERIVED##Type *T) { \
|
|
|
|
DISPATCH(dispatch##BASE##Children, BASE); \
|
|
|
|
DISPATCH(visit##DERIVED##TypeChildren, DERIVED##Type); \
|
|
|
|
} \
|
|
|
|
void visit##DERIVED##TypeChildren(DERIVED##Type *T) {}
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
|
|
|
|
void dispatchTypeAttrs(Type *T) {
|
|
|
|
DISPATCH(visitTypeAttrs, Type);
|
|
|
|
}
|
|
|
|
void visitTypeAttrs(Type *T) {}
|
|
|
|
|
|
|
|
void dispatchTypeChildren(Type *T) {
|
|
|
|
DISPATCH(visitTypeChildren, Type);
|
|
|
|
}
|
|
|
|
void visitTypeChildren(Type *T) {}
|
|
|
|
|
|
|
|
#undef DISPATCH
|
|
|
|
};
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
static StringRef getTypeKindName(Type *T) {
|
2010-11-24 19:30:07 +08:00
|
|
|
switch (T->getTypeClass()) {
|
|
|
|
#define TYPE(DERIVED, BASE) case Type::DERIVED: return #DERIVED "Type";
|
|
|
|
#define ABSTRACT_TYPE(DERIVED, BASE)
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("unknown type kind!");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct XMLDumper : public XMLDeclVisitor<XMLDumper>,
|
|
|
|
public XMLTypeVisitor<XMLDumper> {
|
2011-07-23 18:55:15 +08:00
|
|
|
raw_ostream &out;
|
2010-11-24 19:30:07 +08:00
|
|
|
ASTContext &Context;
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<Node, 16> Stack;
|
2010-11-24 19:30:07 +08:00
|
|
|
unsigned Indent;
|
2011-07-23 18:55:15 +08:00
|
|
|
explicit XMLDumper(raw_ostream &OS, ASTContext &context)
|
2010-11-24 19:30:07 +08:00
|
|
|
: out(OS), Context(context), Indent(0) {}
|
|
|
|
|
|
|
|
void indent() {
|
|
|
|
for (unsigned I = Indent; I; --I)
|
|
|
|
out << ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Push a new node on the stack.
|
2011-07-23 18:55:15 +08:00
|
|
|
void push(StringRef name) {
|
2010-11-24 19:30:07 +08:00
|
|
|
if (!Stack.empty()) {
|
|
|
|
assert(Stack.back().isDoneWithAttrs());
|
|
|
|
if (Stack.back().State == NS_LazyChildren) {
|
|
|
|
Stack.back().State = NS_Children;
|
|
|
|
out << ">\n";
|
|
|
|
}
|
|
|
|
Indent++;
|
|
|
|
indent();
|
|
|
|
}
|
|
|
|
Stack.push_back(Node(name));
|
|
|
|
out << '<' << name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the given attribute to the given value.
|
2011-07-23 18:55:15 +08:00
|
|
|
void set(StringRef attr, StringRef value) {
|
2010-11-24 19:30:07 +08:00
|
|
|
assert(!Stack.empty() && !Stack.back().isDoneWithAttrs());
|
|
|
|
out << ' ' << attr << '=' << '"' << value << '"'; // TODO: quotation
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finish attributes.
|
|
|
|
void completeAttrs() {
|
|
|
|
assert(!Stack.empty() && !Stack.back().isDoneWithAttrs());
|
|
|
|
Stack.back().State = NS_LazyChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Pop a node.
|
|
|
|
void pop() {
|
|
|
|
assert(!Stack.empty() && Stack.back().isDoneWithAttrs());
|
|
|
|
if (Stack.back().State == NS_LazyChildren) {
|
|
|
|
out << "/>\n";
|
|
|
|
} else {
|
|
|
|
indent();
|
|
|
|
out << "</" << Stack.back().Name << ">\n";
|
|
|
|
}
|
|
|
|
if (Stack.size() > 1) Indent--;
|
|
|
|
Stack.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---- General utilities -------------------------------------------//
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void setPointer(StringRef prop, const void *p) {
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<10> buffer;
|
2010-11-24 19:30:07 +08:00
|
|
|
llvm::raw_svector_ostream os(buffer);
|
|
|
|
os << p;
|
|
|
|
os.flush();
|
|
|
|
set(prop, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPointer(void *p) {
|
|
|
|
setPointer("ptr", p);
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void setInteger(StringRef prop, const llvm::APSInt &v) {
|
2010-11-24 19:30:07 +08:00
|
|
|
set(prop, v.toString(10));
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void setInteger(StringRef prop, unsigned n) {
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<10> buffer;
|
2010-11-24 19:30:07 +08:00
|
|
|
llvm::raw_svector_ostream os(buffer);
|
|
|
|
os << n;
|
|
|
|
os.flush();
|
|
|
|
set(prop, buffer);
|
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void setFlag(StringRef prop, bool flag) {
|
2010-11-24 19:30:07 +08:00
|
|
|
if (flag) set(prop, "true");
|
|
|
|
}
|
|
|
|
|
|
|
|
void setName(DeclarationName Name) {
|
2010-11-30 18:12:16 +08:00
|
|
|
if (!Name)
|
|
|
|
return set("name", "");
|
|
|
|
|
2010-11-24 19:30:07 +08:00
|
|
|
// Common case.
|
|
|
|
if (Name.isIdentifier())
|
|
|
|
return set("name", Name.getAsIdentifierInfo()->getName());
|
|
|
|
|
2010-12-02 18:37:08 +08:00
|
|
|
set("name", Name.getAsString());
|
2010-11-24 19:30:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class TemporaryContainer {
|
|
|
|
XMLDumper &Dumper;
|
|
|
|
public:
|
2011-07-23 18:55:15 +08:00
|
|
|
TemporaryContainer(XMLDumper &dumper, StringRef name)
|
2010-11-24 19:30:07 +08:00
|
|
|
: Dumper(dumper) {
|
|
|
|
Dumper.push(name);
|
|
|
|
Dumper.completeAttrs();
|
|
|
|
}
|
|
|
|
|
|
|
|
~TemporaryContainer() {
|
|
|
|
Dumper.pop();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void visitTemplateParameters(TemplateParameterList *L) {
|
|
|
|
push("template_parameters");
|
|
|
|
completeAttrs();
|
|
|
|
for (TemplateParameterList::iterator
|
|
|
|
I = L->begin(), E = L->end(); I != E; ++I)
|
|
|
|
dispatch(*I);
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitTemplateArguments(const TemplateArgumentList &L) {
|
|
|
|
push("template_arguments");
|
|
|
|
completeAttrs();
|
|
|
|
for (unsigned I = 0, E = L.size(); I != E; ++I)
|
|
|
|
dispatch(L[I]);
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Visits a reference to the given declaration.
|
|
|
|
void visitDeclRef(Decl *D) {
|
|
|
|
push(D->getDeclKindName());
|
|
|
|
setPointer("ref", D);
|
|
|
|
completeAttrs();
|
|
|
|
pop();
|
|
|
|
}
|
2011-07-23 18:55:15 +08:00
|
|
|
void visitDeclRef(StringRef Name, Decl *D) {
|
2010-12-02 18:24:56 +08:00
|
|
|
TemporaryContainer C(*this, Name);
|
|
|
|
if (D) visitDeclRef(D);
|
|
|
|
}
|
2010-11-24 19:30:07 +08:00
|
|
|
|
|
|
|
void dispatch(const TemplateArgument &A) {
|
|
|
|
switch (A.getKind()) {
|
|
|
|
case TemplateArgument::Null: {
|
|
|
|
TemporaryContainer C(*this, "null");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TemplateArgument::Type: {
|
|
|
|
dispatch(A.getAsType());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TemplateArgument::Template:
|
2011-01-06 02:58:31 +08:00
|
|
|
case TemplateArgument::TemplateExpansion:
|
2012-09-26 10:36:12 +08:00
|
|
|
case TemplateArgument::NullPtr:
|
2011-01-06 02:58:31 +08:00
|
|
|
// FIXME: Implement!
|
|
|
|
break;
|
|
|
|
|
2010-11-24 19:30:07 +08:00
|
|
|
case TemplateArgument::Declaration: {
|
2012-09-26 10:36:12 +08:00
|
|
|
visitDeclRef(A.getAsDecl());
|
2010-11-24 19:30:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TemplateArgument::Integral: {
|
|
|
|
push("integer");
|
2012-06-07 23:09:51 +08:00
|
|
|
setInteger("value", A.getAsIntegral());
|
2010-11-24 19:30:07 +08:00
|
|
|
completeAttrs();
|
|
|
|
pop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TemplateArgument::Expression: {
|
|
|
|
dispatch(A.getAsExpr());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TemplateArgument::Pack: {
|
2010-12-21 00:52:59 +08:00
|
|
|
for (TemplateArgument::pack_iterator P = A.pack_begin(),
|
|
|
|
PEnd = A.pack_end();
|
|
|
|
P != PEnd; ++P)
|
|
|
|
dispatch(*P);
|
2010-11-24 19:30:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void dispatch(const TemplateArgumentLoc &A) {
|
|
|
|
dispatch(A.getArgument());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---- Declarations ------------------------------------------------//
|
|
|
|
// Calls are made in this order:
|
|
|
|
// # Enter a new node.
|
|
|
|
// push("FieldDecl")
|
|
|
|
//
|
|
|
|
// # In this phase, attributes are set on the node.
|
|
|
|
// visitDeclAttrs(D)
|
|
|
|
// visitNamedDeclAttrs(D)
|
|
|
|
// ...
|
|
|
|
// visitFieldDeclAttrs(D)
|
|
|
|
//
|
|
|
|
// # No more attributes after this point.
|
|
|
|
// completeAttrs()
|
|
|
|
//
|
|
|
|
// # Create "header" child nodes, i.e. those which logically
|
|
|
|
// # belong to the declaration itself.
|
|
|
|
// visitDeclChildren(D)
|
|
|
|
// visitNamedDeclChildren(D)
|
|
|
|
// ...
|
|
|
|
// visitFieldDeclChildren(D)
|
|
|
|
//
|
|
|
|
// # Create nodes for the lexical children.
|
|
|
|
// visitDeclAsContext(D)
|
|
|
|
// visitNamedDeclAsContext(D)
|
|
|
|
// ...
|
|
|
|
// visitFieldDeclAsContext(D)
|
|
|
|
//
|
|
|
|
// # Finish the node.
|
|
|
|
// pop();
|
|
|
|
void dispatch(Decl *D) {
|
|
|
|
push(D->getDeclKindName());
|
2010-11-24 19:53:13 +08:00
|
|
|
XMLDeclVisitor<XMLDumper>::dispatch(D);
|
2010-11-24 19:30:07 +08:00
|
|
|
pop();
|
|
|
|
}
|
|
|
|
void visitDeclAttrs(Decl *D) {
|
|
|
|
setPointer(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Visit all the lexical decls in the given context.
|
|
|
|
void visitDeclContext(DeclContext *DC) {
|
|
|
|
for (DeclContext::decl_iterator
|
|
|
|
I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I)
|
|
|
|
dispatch(*I);
|
|
|
|
|
|
|
|
// FIXME: point out visible declarations not in lexical context?
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the "access" attribute on the current node according to the
|
|
|
|
/// given specifier.
|
|
|
|
void setAccess(AccessSpecifier AS) {
|
|
|
|
switch (AS) {
|
|
|
|
case AS_public: return set("access", "public");
|
|
|
|
case AS_protected: return set("access", "protected");
|
|
|
|
case AS_private: return set("access", "private");
|
|
|
|
case AS_none: llvm_unreachable("explicit forbidden access");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> void visitRedeclarableAttrs(T *D) {
|
2012-01-15 00:38:05 +08:00
|
|
|
if (T *Prev = D->getPreviousDecl())
|
2010-11-24 19:30:07 +08:00
|
|
|
setPointer("previous", Prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TranslationUnitDecl
|
|
|
|
void visitTranslationUnitDeclAsContext(TranslationUnitDecl *D) {
|
|
|
|
visitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
// LinkageSpecDecl
|
|
|
|
void visitLinkageSpecDeclAttrs(LinkageSpecDecl *D) {
|
2011-07-23 18:55:15 +08:00
|
|
|
StringRef lang = "";
|
2010-11-24 19:30:07 +08:00
|
|
|
switch (D->getLanguage()) {
|
|
|
|
case LinkageSpecDecl::lang_c: lang = "C"; break;
|
|
|
|
case LinkageSpecDecl::lang_cxx: lang = "C++"; break;
|
|
|
|
}
|
|
|
|
set("lang", lang);
|
|
|
|
}
|
|
|
|
void visitLinkageSpecDeclAsContext(LinkageSpecDecl *D) {
|
|
|
|
visitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NamespaceDecl
|
|
|
|
void visitNamespaceDeclAttrs(NamespaceDecl *D) {
|
|
|
|
setFlag("inline", D->isInline());
|
|
|
|
if (!D->isOriginalNamespace())
|
|
|
|
setPointer("original", D->getOriginalNamespace());
|
|
|
|
}
|
|
|
|
void visitNamespaceDeclAsContext(NamespaceDecl *D) {
|
|
|
|
visitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NamedDecl
|
|
|
|
void visitNamedDeclAttrs(NamedDecl *D) {
|
|
|
|
setName(D->getDeclName());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ValueDecl
|
|
|
|
void visitValueDeclChildren(ValueDecl *D) {
|
|
|
|
dispatch(D->getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeclaratorDecl
|
|
|
|
void visitDeclaratorDeclChildren(DeclaratorDecl *D) {
|
|
|
|
//dispatch(D->getTypeSourceInfo()->getTypeLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
// VarDecl
|
|
|
|
void visitVarDeclAttrs(VarDecl *D) {
|
|
|
|
visitRedeclarableAttrs(D);
|
|
|
|
if (D->getStorageClass() != SC_None)
|
|
|
|
set("storage",
|
|
|
|
VarDecl::getStorageClassSpecifierString(D->getStorageClass()));
|
Represent C++ direct initializers as ParenListExprs before semantic analysis
instead of having a special-purpose function.
- ActOnCXXDirectInitializer, which was mostly duplication of
AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days
ago), is dropped completely.
- MultiInitializer, which was an ugly hack I added, is dropped again.
- We now have the infrastructure in place to distinguish between
int x = {1};
int x({1});
int x{1};
-- VarDecl now has getInitStyle(), which indicates which of the above was used.
-- CXXConstructExpr now has a flag to indicate that it represents list-
initialization, although this is not yet used.
- InstantiateInitializer was renamed to SubstInitializer and simplified.
- ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which
always produces a ParenListExpr. Placed that so far failed to convert that
back to a ParenExpr containing comma operators have been fixed. I'm pretty
sure I could have made a crashing test case before this.
The end result is a (I hope) considerably cleaner design of initializers.
More importantly, the fact that I can now distinguish between the various
initialization kinds means that I can get the tricky generalized initializer
test cases Johannes Schaub supplied to work. (This is not yet done.)
This commit passed self-host, with the resulting compiler passing the tests. I
hope it doesn't break more complicated code. It's a pretty big change, but one
that I feel is necessary.
llvm-svn: 150318
2012-02-12 07:51:47 +08:00
|
|
|
StringRef initStyle = "";
|
|
|
|
switch (D->getInitStyle()) {
|
|
|
|
case VarDecl::CInit: initStyle = "c"; break;
|
|
|
|
case VarDecl::CallInit: initStyle = "call"; break;
|
|
|
|
case VarDecl::ListInit: initStyle = "list"; break;
|
|
|
|
}
|
|
|
|
set("initstyle", initStyle);
|
2010-11-24 19:30:07 +08:00
|
|
|
setFlag("nrvo", D->isNRVOVariable());
|
|
|
|
// TODO: instantiation, etc.
|
|
|
|
}
|
|
|
|
void visitVarDeclChildren(VarDecl *D) {
|
|
|
|
if (D->hasInit()) dispatch(D->getInit());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParmVarDecl?
|
|
|
|
|
|
|
|
// FunctionDecl
|
|
|
|
void visitFunctionDeclAttrs(FunctionDecl *D) {
|
|
|
|
visitRedeclarableAttrs(D);
|
|
|
|
setFlag("pure", D->isPure());
|
|
|
|
setFlag("trivial", D->isTrivial());
|
|
|
|
setFlag("returnzero", D->hasImplicitReturnZero());
|
|
|
|
setFlag("prototype", D->hasWrittenPrototype());
|
2011-05-07 04:44:56 +08:00
|
|
|
setFlag("deleted", D->isDeletedAsWritten());
|
2010-11-24 19:30:07 +08:00
|
|
|
if (D->getStorageClass() != SC_None)
|
|
|
|
set("storage",
|
|
|
|
VarDecl::getStorageClassSpecifierString(D->getStorageClass()));
|
|
|
|
setFlag("inline", D->isInlineSpecified());
|
2011-05-14 05:10:39 +08:00
|
|
|
if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>())
|
|
|
|
set("asmlabel", ALA->getLabel());
|
2010-11-24 19:30:07 +08:00
|
|
|
// TODO: instantiation, etc.
|
|
|
|
}
|
|
|
|
void visitFunctionDeclChildren(FunctionDecl *D) {
|
|
|
|
for (FunctionDecl::param_iterator
|
|
|
|
I = D->param_begin(), E = D->param_end(); I != E; ++I)
|
|
|
|
dispatch(*I);
|
2013-01-13 03:30:44 +08:00
|
|
|
for (ArrayRef<NamedDecl *>::iterator I = D->getDeclsInPrototypeScope().begin(),
|
|
|
|
E = D->getDeclsInPrototypeScope().end();
|
2012-02-29 18:24:19 +08:00
|
|
|
I != E; ++I)
|
|
|
|
dispatch(*I);
|
2011-05-07 04:44:56 +08:00
|
|
|
if (D->doesThisDeclarationHaveABody())
|
2010-11-24 19:30:07 +08:00
|
|
|
dispatch(D->getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
// CXXMethodDecl ?
|
|
|
|
// CXXConstructorDecl ?
|
|
|
|
// CXXDestructorDecl ?
|
|
|
|
// CXXConversionDecl ?
|
|
|
|
|
2011-01-09 04:30:50 +08:00
|
|
|
void dispatch(CXXCtorInitializer *Init) {
|
2010-12-02 18:24:56 +08:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2010-11-24 19:30:07 +08:00
|
|
|
// FieldDecl
|
|
|
|
void visitFieldDeclAttrs(FieldDecl *D) {
|
|
|
|
setFlag("mutable", D->isMutable());
|
|
|
|
}
|
|
|
|
void visitFieldDeclChildren(FieldDecl *D) {
|
|
|
|
if (D->isBitField()) {
|
|
|
|
TemporaryContainer C(*this, "bitwidth");
|
|
|
|
dispatch(D->getBitWidth());
|
|
|
|
}
|
|
|
|
// TODO: C++0x member initializer
|
|
|
|
}
|
|
|
|
|
|
|
|
// EnumConstantDecl
|
|
|
|
void visitEnumConstantDeclChildren(EnumConstantDecl *D) {
|
|
|
|
// value in any case?
|
|
|
|
if (D->getInitExpr()) dispatch(D->getInitExpr());
|
|
|
|
}
|
|
|
|
|
|
|
|
// IndirectFieldDecl
|
|
|
|
void visitIndirectFieldDeclChildren(IndirectFieldDecl *D) {
|
|
|
|
for (IndirectFieldDecl::chain_iterator
|
|
|
|
I = D->chain_begin(), E = D->chain_end(); I != E; ++I) {
|
|
|
|
NamedDecl *VD = const_cast<NamedDecl*>(*I);
|
|
|
|
push(isa<VarDecl>(VD) ? "variable" : "field");
|
|
|
|
setPointer("ptr", VD);
|
|
|
|
completeAttrs();
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TypeDecl
|
|
|
|
void visitTypeDeclAttrs(TypeDecl *D) {
|
|
|
|
setPointer("typeptr", D->getTypeForDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
// TypedefDecl
|
|
|
|
void visitTypedefDeclAttrs(TypedefDecl *D) {
|
2011-04-15 22:24:37 +08:00
|
|
|
visitRedeclarableAttrs<TypedefNameDecl>(D);
|
2010-11-24 19:30:07 +08:00
|
|
|
}
|
|
|
|
void visitTypedefDeclChildren(TypedefDecl *D) {
|
|
|
|
dispatch(D->getTypeSourceInfo()->getTypeLoc());
|
|
|
|
}
|
|
|
|
|
2011-04-15 22:24:37 +08:00
|
|
|
// TypeAliasDecl
|
|
|
|
void visitTypeAliasDeclAttrs(TypeAliasDecl *D) {
|
|
|
|
visitRedeclarableAttrs<TypedefNameDecl>(D);
|
|
|
|
}
|
|
|
|
void visitTypeAliasDeclChildren(TypeAliasDecl *D) {
|
|
|
|
dispatch(D->getTypeSourceInfo()->getTypeLoc());
|
|
|
|
}
|
|
|
|
|
2010-11-24 19:30:07 +08:00
|
|
|
// TagDecl
|
|
|
|
void visitTagDeclAttrs(TagDecl *D) {
|
|
|
|
visitRedeclarableAttrs(D);
|
|
|
|
}
|
|
|
|
void visitTagDeclAsContext(TagDecl *D) {
|
|
|
|
visitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
// EnumDecl
|
|
|
|
void visitEnumDeclAttrs(EnumDecl *D) {
|
|
|
|
setFlag("scoped", D->isScoped());
|
|
|
|
setFlag("fixed", D->isFixed());
|
|
|
|
}
|
|
|
|
void visitEnumDeclChildren(EnumDecl *D) {
|
|
|
|
{
|
|
|
|
TemporaryContainer C(*this, "promotion_type");
|
|
|
|
dispatch(D->getPromotionType());
|
|
|
|
}
|
|
|
|
{
|
|
|
|
TemporaryContainer C(*this, "integer_type");
|
|
|
|
dispatch(D->getIntegerType());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RecordDecl ?
|
|
|
|
|
|
|
|
void visitCXXRecordDeclChildren(CXXRecordDecl *D) {
|
|
|
|
if (!D->isThisDeclarationADefinition()) return;
|
|
|
|
|
|
|
|
for (CXXRecordDecl::base_class_iterator
|
|
|
|
I = D->bases_begin(), E = D->bases_end(); I != E; ++I) {
|
|
|
|
push("base");
|
|
|
|
setAccess(I->getAccessSpecifier());
|
|
|
|
completeAttrs();
|
|
|
|
dispatch(I->getTypeSourceInfo()->getTypeLoc());
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClassTemplateSpecializationDecl ?
|
|
|
|
|
|
|
|
// FileScopeAsmDecl ?
|
|
|
|
|
|
|
|
// BlockDecl
|
|
|
|
void visitBlockDeclAttrs(BlockDecl *D) {
|
|
|
|
setFlag("variadic", D->isVariadic());
|
|
|
|
}
|
|
|
|
void visitBlockDeclChildren(BlockDecl *D) {
|
|
|
|
for (FunctionDecl::param_iterator
|
|
|
|
I = D->param_begin(), E = D->param_end(); I != E; ++I)
|
|
|
|
dispatch(*I);
|
|
|
|
dispatch(D->getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
// AccessSpecDecl
|
|
|
|
void visitAccessSpecDeclAttrs(AccessSpecDecl *D) {
|
|
|
|
setAccess(D->getAccess());
|
|
|
|
}
|
|
|
|
|
|
|
|
// TemplateDecl
|
|
|
|
void visitTemplateDeclChildren(TemplateDecl *D) {
|
|
|
|
visitTemplateParameters(D->getTemplateParameters());
|
2011-05-06 05:57:07 +08:00
|
|
|
if (D->getTemplatedDecl())
|
|
|
|
dispatch(D->getTemplatedDecl());
|
2010-11-24 19:30:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// FunctionTemplateDecl
|
|
|
|
void visitFunctionTemplateDeclAttrs(FunctionTemplateDecl *D) {
|
|
|
|
visitRedeclarableAttrs(D);
|
|
|
|
}
|
|
|
|
void visitFunctionTemplateDeclChildren(FunctionTemplateDecl *D) {
|
|
|
|
// Mention all the specializations which don't have explicit
|
|
|
|
// declarations elsewhere.
|
|
|
|
for (FunctionTemplateDecl::spec_iterator
|
|
|
|
I = D->spec_begin(), E = D->spec_end(); I != E; ++I) {
|
|
|
|
FunctionTemplateSpecializationInfo *Info
|
|
|
|
= I->getTemplateSpecializationInfo();
|
|
|
|
|
|
|
|
bool Unknown = false;
|
|
|
|
switch (Info->getTemplateSpecializationKind()) {
|
|
|
|
case TSK_ImplicitInstantiation: Unknown = false; break;
|
|
|
|
case TSK_Undeclared: Unknown = true; break;
|
|
|
|
|
|
|
|
// These will be covered at their respective sites.
|
|
|
|
case TSK_ExplicitSpecialization: continue;
|
|
|
|
case TSK_ExplicitInstantiationDeclaration: continue;
|
|
|
|
case TSK_ExplicitInstantiationDefinition: continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryContainer C(*this,
|
|
|
|
Unknown ? "uninstantiated" : "instantiation");
|
|
|
|
visitTemplateArguments(*Info->TemplateArguments);
|
|
|
|
dispatch(Info->Function);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClasTemplateDecl
|
|
|
|
void visitClassTemplateDeclAttrs(ClassTemplateDecl *D) {
|
|
|
|
visitRedeclarableAttrs(D);
|
|
|
|
}
|
|
|
|
void visitClassTemplateDeclChildren(ClassTemplateDecl *D) {
|
|
|
|
// Mention all the specializations which don't have explicit
|
|
|
|
// declarations elsewhere.
|
|
|
|
for (ClassTemplateDecl::spec_iterator
|
|
|
|
I = D->spec_begin(), E = D->spec_end(); I != E; ++I) {
|
|
|
|
|
|
|
|
bool Unknown = false;
|
|
|
|
switch (I->getTemplateSpecializationKind()) {
|
|
|
|
case TSK_ImplicitInstantiation: Unknown = false; break;
|
|
|
|
case TSK_Undeclared: Unknown = true; break;
|
|
|
|
|
|
|
|
// These will be covered at their respective sites.
|
|
|
|
case TSK_ExplicitSpecialization: continue;
|
|
|
|
case TSK_ExplicitInstantiationDeclaration: continue;
|
|
|
|
case TSK_ExplicitInstantiationDefinition: continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemporaryContainer C(*this,
|
|
|
|
Unknown ? "uninstantiated" : "instantiation");
|
|
|
|
visitTemplateArguments(I->getTemplateArgs());
|
|
|
|
dispatch(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TemplateTypeParmDecl
|
|
|
|
void visitTemplateTypeParmDeclAttrs(TemplateTypeParmDecl *D) {
|
|
|
|
setInteger("depth", D->getDepth());
|
|
|
|
setInteger("index", D->getIndex());
|
|
|
|
}
|
|
|
|
void visitTemplateTypeParmDeclChildren(TemplateTypeParmDecl *D) {
|
|
|
|
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
|
|
|
|
dispatch(D->getDefaultArgumentInfo()->getTypeLoc());
|
|
|
|
// parameter pack?
|
|
|
|
}
|
|
|
|
|
|
|
|
// NonTypeTemplateParmDecl
|
|
|
|
void visitNonTypeTemplateParmDeclAttrs(NonTypeTemplateParmDecl *D) {
|
|
|
|
setInteger("depth", D->getDepth());
|
|
|
|
setInteger("index", D->getIndex());
|
|
|
|
}
|
|
|
|
void visitNonTypeTemplateParmDeclChildren(NonTypeTemplateParmDecl *D) {
|
|
|
|
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
|
|
|
|
dispatch(D->getDefaultArgument());
|
|
|
|
// parameter pack?
|
|
|
|
}
|
|
|
|
|
|
|
|
// TemplateTemplateParmDecl
|
|
|
|
void visitTemplateTemplateParmDeclAttrs(TemplateTemplateParmDecl *D) {
|
|
|
|
setInteger("depth", D->getDepth());
|
|
|
|
setInteger("index", D->getIndex());
|
|
|
|
}
|
|
|
|
void visitTemplateTemplateParmDeclChildren(TemplateTemplateParmDecl *D) {
|
|
|
|
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
|
|
|
|
dispatch(D->getDefaultArgument());
|
|
|
|
// parameter pack?
|
|
|
|
}
|
|
|
|
|
|
|
|
// FriendDecl
|
|
|
|
void visitFriendDeclChildren(FriendDecl *D) {
|
|
|
|
if (TypeSourceInfo *T = D->getFriendType())
|
|
|
|
dispatch(T->getTypeLoc());
|
|
|
|
else
|
|
|
|
dispatch(D->getFriendDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
// UsingDirectiveDecl ?
|
|
|
|
// UsingDecl ?
|
|
|
|
// UsingShadowDecl ?
|
|
|
|
// NamespaceAliasDecl ?
|
|
|
|
// UnresolvedUsingValueDecl ?
|
|
|
|
// UnresolvedUsingTypenameDecl ?
|
|
|
|
// StaticAssertDecl ?
|
|
|
|
|
2010-12-02 18:24:56 +08:00
|
|
|
// ObjCImplDecl
|
|
|
|
void visitObjCImplDeclChildren(ObjCImplDecl *D) {
|
|
|
|
visitDeclRef(D->getClassInterface());
|
|
|
|
}
|
|
|
|
void visitObjCImplDeclAsContext(ObjCImplDecl *D) {
|
|
|
|
visitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitObjCInterfaceDeclAttrs(ObjCInterfaceDecl *D) {
|
|
|
|
setPointer("typeptr", D->getTypeForDecl());
|
2011-12-16 04:29:51 +08:00
|
|
|
setFlag("forward_decl", !D->isThisDeclarationADefinition());
|
2010-12-02 18:24:56 +08:00
|
|
|
setFlag("implicit_interface", D->isImplicitInterfaceDecl());
|
|
|
|
}
|
|
|
|
void visitObjCInterfaceDeclChildren(ObjCInterfaceDecl *D) {
|
|
|
|
visitDeclRef("super", D->getSuperClass());
|
|
|
|
visitDeclRef("implementation", D->getImplementation());
|
|
|
|
if (D->protocol_begin() != D->protocol_end()) {
|
|
|
|
TemporaryContainer C(*this, "protocols");
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator
|
|
|
|
I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I)
|
|
|
|
visitDeclRef(*I);
|
|
|
|
}
|
2013-01-17 07:00:23 +08:00
|
|
|
|
|
|
|
if (!D->visible_categories_empty()) {
|
|
|
|
TemporaryContainer C(*this, "categories");
|
|
|
|
|
|
|
|
for (ObjCInterfaceDecl::visible_categories_iterator
|
|
|
|
Cat = D->visible_categories_begin(),
|
|
|
|
CatEnd = D->visible_categories_end();
|
|
|
|
Cat != CatEnd; ++Cat) {
|
|
|
|
visitDeclRef(*Cat);
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 18:24:56 +08:00
|
|
|
}
|
|
|
|
void visitObjCInterfaceDeclAsContext(ObjCInterfaceDecl *D) {
|
|
|
|
visitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjCCategoryDecl
|
|
|
|
void visitObjCCategoryDeclAttrs(ObjCCategoryDecl *D) {
|
|
|
|
setFlag("extension", D->IsClassExtension());
|
|
|
|
}
|
|
|
|
void visitObjCCategoryDeclChildren(ObjCCategoryDecl *D) {
|
|
|
|
visitDeclRef("interface", D->getClassInterface());
|
|
|
|
visitDeclRef("implementation", D->getImplementation());
|
|
|
|
if (D->protocol_begin() != D->protocol_end()) {
|
|
|
|
TemporaryContainer C(*this, "protocols");
|
|
|
|
for (ObjCCategoryDecl::protocol_iterator
|
|
|
|
I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I)
|
|
|
|
visitDeclRef(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void visitObjCCategoryDeclAsContext(ObjCCategoryDecl *D) {
|
|
|
|
visitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjCCategoryImplDecl
|
|
|
|
void visitObjCCategoryImplDeclAttrs(ObjCCategoryImplDecl *D) {
|
|
|
|
set("identifier", D->getName());
|
|
|
|
}
|
|
|
|
void visitObjCCategoryImplDeclChildren(ObjCCategoryImplDecl *D) {
|
|
|
|
visitDeclRef(D->getCategoryDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjCImplementationDecl
|
|
|
|
void visitObjCImplementationDeclAttrs(ObjCImplementationDecl *D) {
|
|
|
|
set("identifier", D->getName());
|
|
|
|
}
|
|
|
|
void visitObjCImplementationDeclChildren(ObjCImplementationDecl *D) {
|
|
|
|
visitDeclRef("super", D->getSuperClass());
|
|
|
|
if (D->init_begin() != D->init_end()) {
|
|
|
|
TemporaryContainer C(*this, "initializers");
|
|
|
|
for (ObjCImplementationDecl::init_iterator
|
|
|
|
I = D->init_begin(), E = D->init_end(); I != E; ++I)
|
|
|
|
dispatch(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjCProtocolDecl
|
|
|
|
void visitObjCProtocolDeclChildren(ObjCProtocolDecl *D) {
|
2012-01-02 05:23:57 +08:00
|
|
|
if (!D->isThisDeclarationADefinition())
|
|
|
|
return;
|
|
|
|
|
2010-12-02 18:24:56 +08:00
|
|
|
if (D->protocol_begin() != D->protocol_end()) {
|
|
|
|
TemporaryContainer C(*this, "protocols");
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator
|
|
|
|
I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I)
|
|
|
|
visitDeclRef(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void visitObjCProtocolDeclAsContext(ObjCProtocolDecl *D) {
|
2012-01-02 05:23:57 +08:00
|
|
|
if (!D->isThisDeclarationADefinition())
|
|
|
|
return;
|
|
|
|
|
2010-12-02 18:24:56 +08:00
|
|
|
visitDeclContext(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjCMethodDecl
|
|
|
|
void visitObjCMethodDeclAttrs(ObjCMethodDecl *D) {
|
|
|
|
// decl qualifier?
|
|
|
|
// implementation control?
|
|
|
|
|
|
|
|
setFlag("instance", D->isInstanceMethod());
|
|
|
|
setFlag("variadic", D->isVariadic());
|
2012-10-11 00:42:25 +08:00
|
|
|
setFlag("property_accessor", D->isPropertyAccessor());
|
2010-12-02 18:24:56 +08:00
|
|
|
setFlag("defined", D->isDefined());
|
2011-06-11 09:09:30 +08:00
|
|
|
setFlag("related_result_type", D->hasRelatedResultType());
|
2010-12-02 18:24:56 +08:00
|
|
|
}
|
|
|
|
void visitObjCMethodDeclChildren(ObjCMethodDecl *D) {
|
|
|
|
dispatch(D->getResultType());
|
|
|
|
for (ObjCMethodDecl::param_iterator
|
|
|
|
I = D->param_begin(), E = D->param_end(); I != E; ++I)
|
|
|
|
dispatch(*I);
|
|
|
|
if (D->isThisDeclarationADefinition())
|
|
|
|
dispatch(D->getBody());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjCIvarDecl
|
2011-07-23 18:55:15 +08:00
|
|
|
void setAccessControl(StringRef prop, ObjCIvarDecl::AccessControl AC) {
|
2010-12-02 18:24:56 +08:00
|
|
|
switch (AC) {
|
|
|
|
case ObjCIvarDecl::None: return set(prop, "none");
|
|
|
|
case ObjCIvarDecl::Private: return set(prop, "private");
|
|
|
|
case ObjCIvarDecl::Protected: return set(prop, "protected");
|
|
|
|
case ObjCIvarDecl::Public: return set(prop, "public");
|
|
|
|
case ObjCIvarDecl::Package: return set(prop, "package");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void visitObjCIvarDeclAttrs(ObjCIvarDecl *D) {
|
|
|
|
setFlag("synthesize", D->getSynthesize());
|
|
|
|
setAccessControl("access", D->getAccessControl());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjCCompatibleAliasDecl
|
|
|
|
void visitObjCCompatibleAliasDeclChildren(ObjCCompatibleAliasDecl *D) {
|
|
|
|
visitDeclRef(D->getClassInterface());
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: ObjCPropertyDecl
|
|
|
|
// FIXME: ObjCPropertyImplDecl
|
|
|
|
|
2010-11-24 19:30:07 +08:00
|
|
|
//---- Types -----------------------------------------------------//
|
|
|
|
void dispatch(TypeLoc TL) {
|
|
|
|
dispatch(TL.getType()); // for now
|
|
|
|
}
|
|
|
|
|
|
|
|
void dispatch(QualType T) {
|
|
|
|
if (T.hasLocalQualifiers()) {
|
|
|
|
push("QualType");
|
|
|
|
Qualifiers Qs = T.getLocalQualifiers();
|
|
|
|
setFlag("const", Qs.hasConst());
|
|
|
|
setFlag("volatile", Qs.hasVolatile());
|
|
|
|
setFlag("restrict", Qs.hasRestrict());
|
|
|
|
if (Qs.hasAddressSpace()) setInteger("addrspace", Qs.getAddressSpace());
|
|
|
|
if (Qs.hasObjCGCAttr()) {
|
|
|
|
switch (Qs.getObjCGCAttr()) {
|
|
|
|
case Qualifiers::Weak: set("gc", "weak"); break;
|
|
|
|
case Qualifiers::Strong: set("gc", "strong"); break;
|
|
|
|
case Qualifiers::GCNone: llvm_unreachable("explicit none");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
completeAttrs();
|
|
|
|
dispatch(QualType(T.getTypePtr(), 0));
|
|
|
|
pop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Type *Ty = const_cast<Type*>(T.getTypePtr());
|
|
|
|
push(getTypeKindName(Ty));
|
2010-11-24 19:53:13 +08:00
|
|
|
XMLTypeVisitor<XMLDumper>::dispatch(const_cast<Type*>(T.getTypePtr()));
|
2010-11-24 19:30:07 +08:00
|
|
|
pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCallingConv(CallingConv CC) {
|
|
|
|
switch (CC) {
|
|
|
|
case CC_Default: return;
|
|
|
|
case CC_C: return set("cc", "cdecl");
|
|
|
|
case CC_X86FastCall: return set("cc", "x86_fastcall");
|
|
|
|
case CC_X86StdCall: return set("cc", "x86_stdcall");
|
|
|
|
case CC_X86ThisCall: return set("cc", "x86_thiscall");
|
|
|
|
case CC_X86Pascal: return set("cc", "x86_pascal");
|
2011-04-15 04:06:49 +08:00
|
|
|
case CC_AAPCS: return set("cc", "aapcs");
|
|
|
|
case CC_AAPCS_VFP: return set("cc", "aapcs_vfp");
|
2012-10-17 06:30:41 +08:00
|
|
|
case CC_PnaclCall: return set("cc", "pnaclcall");
|
2012-12-25 16:53:55 +08:00
|
|
|
case CC_IntelOclBicc: return set("cc", "intel_ocl_bicc");
|
2010-11-24 19:30:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitTypeAttrs(Type *D) {
|
|
|
|
setPointer(D);
|
|
|
|
setFlag("dependent", D->isDependentType());
|
|
|
|
setFlag("variably_modified", D->isVariablyModifiedType());
|
|
|
|
|
|
|
|
setPointer("canonical", D->getCanonicalTypeInternal().getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitPointerTypeChildren(PointerType *T) {
|
|
|
|
dispatch(T->getPointeeType());
|
|
|
|
}
|
|
|
|
void visitReferenceTypeChildren(ReferenceType *T) {
|
|
|
|
dispatch(T->getPointeeType());
|
|
|
|
}
|
|
|
|
void visitObjCObjectPointerTypeChildren(ObjCObjectPointerType *T) {
|
|
|
|
dispatch(T->getPointeeType());
|
|
|
|
}
|
|
|
|
void visitBlockPointerTypeChildren(BlockPointerType *T) {
|
|
|
|
dispatch(T->getPointeeType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Types that just wrap declarations.
|
|
|
|
void visitTagTypeChildren(TagType *T) {
|
|
|
|
visitDeclRef(T->getDecl());
|
|
|
|
}
|
|
|
|
void visitTypedefTypeChildren(TypedefType *T) {
|
|
|
|
visitDeclRef(T->getDecl());
|
|
|
|
}
|
|
|
|
void visitObjCInterfaceTypeChildren(ObjCInterfaceType *T) {
|
|
|
|
visitDeclRef(T->getDecl());
|
|
|
|
}
|
|
|
|
void visitUnresolvedUsingTypeChildren(UnresolvedUsingType *T) {
|
|
|
|
visitDeclRef(T->getDecl());
|
|
|
|
}
|
|
|
|
void visitInjectedClassNameTypeChildren(InjectedClassNameType *T) {
|
|
|
|
visitDeclRef(T->getDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitFunctionTypeAttrs(FunctionType *T) {
|
|
|
|
setFlag("noreturn", T->getNoReturnAttr());
|
|
|
|
setCallingConv(T->getCallConv());
|
2011-04-09 16:18:08 +08:00
|
|
|
if (T->getHasRegParm()) setInteger("regparm", T->getRegParmType());
|
2010-11-24 19:30:07 +08:00
|
|
|
}
|
|
|
|
void visitFunctionTypeChildren(FunctionType *T) {
|
|
|
|
dispatch(T->getResultType());
|
|
|
|
}
|
|
|
|
|
|
|
|
void visitFunctionProtoTypeAttrs(FunctionProtoType *T) {
|
2012-08-10 08:55:35 +08:00
|
|
|
setFlag("const", T->isConst());
|
|
|
|
setFlag("volatile", T->isVolatile());
|
|
|
|
setFlag("restrict", T->isRestrict());
|
2012-10-22 07:00:34 +08:00
|
|
|
switch (T->getExceptionSpecType()) {
|
|
|
|
case EST_None: break;
|
|
|
|
case EST_DynamicNone: set("exception_spec", "throw()"); break;
|
|
|
|
case EST_Dynamic: set("exception_spec", "throw(T)"); break;
|
|
|
|
case EST_MSAny: set("exception_spec", "throw(...)"); break;
|
|
|
|
case EST_BasicNoexcept: set("exception_spec", "noexcept"); break;
|
|
|
|
case EST_ComputedNoexcept: set("exception_spec", "noexcept(expr)"); break;
|
|
|
|
case EST_Unevaluated: set("exception_spec", "unevaluated"); break;
|
|
|
|
case EST_Uninstantiated: set("exception_spec", "uninstantiated"); break;
|
|
|
|
}
|
2010-11-24 19:30:07 +08:00
|
|
|
}
|
|
|
|
void visitFunctionProtoTypeChildren(FunctionProtoType *T) {
|
|
|
|
push("parameters");
|
|
|
|
setFlag("variadic", T->isVariadic());
|
|
|
|
completeAttrs();
|
|
|
|
for (FunctionProtoType::arg_type_iterator
|
|
|
|
I = T->arg_type_begin(), E = T->arg_type_end(); I != E; ++I)
|
|
|
|
dispatch(*I);
|
|
|
|
pop();
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
if (T->hasDynamicExceptionSpec()) {
|
2010-11-24 19:30:07 +08:00
|
|
|
push("exception_specifiers");
|
2011-03-12 19:50:43 +08:00
|
|
|
setFlag("any", T->getExceptionSpecType() == EST_MSAny);
|
2010-11-24 19:30:07 +08:00
|
|
|
completeAttrs();
|
|
|
|
for (FunctionProtoType::exception_iterator
|
|
|
|
I = T->exception_begin(), E = T->exception_end(); I != E; ++I)
|
|
|
|
dispatch(*I);
|
|
|
|
pop();
|
|
|
|
}
|
2011-03-12 19:50:43 +08:00
|
|
|
// FIXME: noexcept specifier
|
2010-11-24 19:30:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void visitTemplateSpecializationTypeChildren(TemplateSpecializationType *T) {
|
|
|
|
if (const RecordType *RT = T->getAs<RecordType>())
|
|
|
|
visitDeclRef(RT->getDecl());
|
|
|
|
|
|
|
|
// TODO: TemplateName
|
|
|
|
|
|
|
|
push("template_arguments");
|
|
|
|
completeAttrs();
|
|
|
|
for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I)
|
|
|
|
dispatch(T->getArg(I));
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---- Statements ------------------------------------------------//
|
|
|
|
void dispatch(Stmt *S) {
|
|
|
|
// FIXME: this is not really XML at all
|
|
|
|
push("Stmt");
|
2010-12-02 18:24:56 +08:00
|
|
|
out << ">\n";
|
2010-11-24 19:30:07 +08:00
|
|
|
Stack.back().State = NS_Children; // explicitly become non-lazy
|
|
|
|
S->dump(out, Context.getSourceManager());
|
|
|
|
out << '\n';
|
|
|
|
pop();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-08-14 22:50:32 +08:00
|
|
|
void Decl::dumpXML() const {
|
2012-08-22 16:38:23 +08:00
|
|
|
dumpXML(llvm::errs());
|
2012-08-14 22:50:32 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
void Decl::dumpXML(raw_ostream &out) const {
|
2010-11-24 19:30:07 +08:00
|
|
|
XMLDumper(out, getASTContext()).dispatch(const_cast<Decl*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* ifndef NDEBUG */
|
|
|
|
|
2012-08-14 22:50:32 +08:00
|
|
|
void Decl::dumpXML() const {}
|
2011-07-23 18:55:15 +08:00
|
|
|
void Decl::dumpXML(raw_ostream &out) const {}
|
2010-11-24 19:30:07 +08:00
|
|
|
|
|
|
|
#endif
|