126c25c95a1eeeed09265525de300670eb5e9c015John McCall//===--- DumpXML.cpp - Detailed XML dumping ---------------------*- C++ -*-===// 226c25c95a1eeeed09265525de300670eb5e9c015John McCall// 326c25c95a1eeeed09265525de300670eb5e9c015John McCall// The LLVM Compiler Infrastructure 426c25c95a1eeeed09265525de300670eb5e9c015John McCall// 526c25c95a1eeeed09265525de300670eb5e9c015John McCall// This file is distributed under the University of Illinois Open Source 626c25c95a1eeeed09265525de300670eb5e9c015John McCall// License. See LICENSE.TXT for details. 726c25c95a1eeeed09265525de300670eb5e9c015John McCall// 826c25c95a1eeeed09265525de300670eb5e9c015John McCall//===----------------------------------------------------------------------===// 926c25c95a1eeeed09265525de300670eb5e9c015John McCall// 1026c25c95a1eeeed09265525de300670eb5e9c015John McCall// This file defines the Decl::dumpXML() method, a debugging tool to 1126c25c95a1eeeed09265525de300670eb5e9c015John McCall// print a detailed graph of an AST in an unspecified XML format. 1226c25c95a1eeeed09265525de300670eb5e9c015John McCall// 1326c25c95a1eeeed09265525de300670eb5e9c015John McCall// There is no guarantee of stability for this format. 1426c25c95a1eeeed09265525de300670eb5e9c015John McCall// 1526c25c95a1eeeed09265525de300670eb5e9c015John McCall//===----------------------------------------------------------------------===// 1626c25c95a1eeeed09265525de300670eb5e9c015John McCall 1726c25c95a1eeeed09265525de300670eb5e9c015John McCall// Only pay for this in code size in assertions-enabled builds. 1826c25c95a1eeeed09265525de300670eb5e9c015John McCall 1926c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/ASTContext.h" 2026c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/Decl.h" 2126c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/DeclCXX.h" 2226c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/DeclFriend.h" 2326c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/DeclObjC.h" 2426c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/DeclTemplate.h" 2526c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/DeclVisitor.h" 2626c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/Expr.h" 2726c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/ExprCXX.h" 2826c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/ExprObjC.h" 2926c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/NestedNameSpecifier.h" 3026c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/Stmt.h" 3126c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/StmtCXX.h" 3226c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/StmtObjC.h" 3326c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/StmtVisitor.h" 3426c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/TemplateBase.h" 3526c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/TemplateName.h" 3626c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/Type.h" 3726c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/TypeLoc.h" 3826c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/TypeLocVisitor.h" 3926c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/TypeVisitor.h" 4026c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/Expr.h" 4126c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/ExprCXX.h" 428fe83e1df954d72c0f4ffc15d20a5222ec151c21Benjamin Kramer#include "llvm/ADT/SmallString.h" 4326c25c95a1eeeed09265525de300670eb5e9c015John McCall 4426c25c95a1eeeed09265525de300670eb5e9c015John McCallusing namespace clang; 4526c25c95a1eeeed09265525de300670eb5e9c015John McCall 4626c25c95a1eeeed09265525de300670eb5e9c015John McCall#ifndef NDEBUG 4726c25c95a1eeeed09265525de300670eb5e9c015John McCall 4826c25c95a1eeeed09265525de300670eb5e9c015John McCallnamespace { 4926c25c95a1eeeed09265525de300670eb5e9c015John McCall 5026c25c95a1eeeed09265525de300670eb5e9c015John McCallenum NodeState { 5126c25c95a1eeeed09265525de300670eb5e9c015John McCall NS_Attrs, NS_LazyChildren, NS_Children 5226c25c95a1eeeed09265525de300670eb5e9c015John McCall}; 5326c25c95a1eeeed09265525de300670eb5e9c015John McCall 5426c25c95a1eeeed09265525de300670eb5e9c015John McCallstruct Node { 555f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef Name; 5626c25c95a1eeeed09265525de300670eb5e9c015John McCall NodeState State; 575f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner Node(StringRef name) : Name(name), State(NS_Attrs) {} 5826c25c95a1eeeed09265525de300670eb5e9c015John McCall 5926c25c95a1eeeed09265525de300670eb5e9c015John McCall bool isDoneWithAttrs() const { return State != NS_Attrs; } 6026c25c95a1eeeed09265525de300670eb5e9c015John McCall}; 6126c25c95a1eeeed09265525de300670eb5e9c015John McCall 6226c25c95a1eeeed09265525de300670eb5e9c015John McCalltemplate <class Impl> struct XMLDeclVisitor { 6326c25c95a1eeeed09265525de300670eb5e9c015John McCall#define DISPATCH(NAME, CLASS) \ 6426c25c95a1eeeed09265525de300670eb5e9c015John McCall static_cast<Impl*>(this)->NAME(static_cast<CLASS*>(D)) 6526c25c95a1eeeed09265525de300670eb5e9c015John McCall 6626c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch(Decl *D) { 6726c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (D->getKind()) { 6826c25c95a1eeeed09265525de300670eb5e9c015John McCall#define DECL(DERIVED, BASE) \ 6926c25c95a1eeeed09265525de300670eb5e9c015John McCall case Decl::DERIVED: \ 7026c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##DERIVED##DeclAttrs, DERIVED##Decl); \ 7126c25c95a1eeeed09265525de300670eb5e9c015John McCall static_cast<Impl*>(this)->completeAttrs(); \ 7226c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##DERIVED##DeclChildren, DERIVED##Decl); \ 7326c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##DERIVED##DeclAsContext, DERIVED##Decl); \ 7426c25c95a1eeeed09265525de300670eb5e9c015John McCall break; 7526c25c95a1eeeed09265525de300670eb5e9c015John McCall#define ABSTRACT_DECL(DECL) 7626c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/DeclNodes.inc" 7726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 7826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 7926c25c95a1eeeed09265525de300670eb5e9c015John McCall 8026c25c95a1eeeed09265525de300670eb5e9c015John McCall#define DECL(DERIVED, BASE) \ 8126c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch##DERIVED##DeclAttrs(DERIVED##Decl *D) { \ 8226c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##BASE##Attrs, BASE); \ 8326c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visit##DERIVED##DeclAttrs, DERIVED##Decl); \ 8426c25c95a1eeeed09265525de300670eb5e9c015John McCall } \ 8526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visit##DERIVED##DeclAttrs(DERIVED##Decl *D) {} \ 8626c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch##DERIVED##DeclChildren(DERIVED##Decl *D) { \ 8726c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##BASE##Children, BASE); \ 8826c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visit##DERIVED##DeclChildren, DERIVED##Decl); \ 8926c25c95a1eeeed09265525de300670eb5e9c015John McCall } \ 9026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visit##DERIVED##DeclChildren(DERIVED##Decl *D) {} \ 9126c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch##DERIVED##DeclAsContext(DERIVED##Decl *D) { \ 9226c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##BASE##AsContext, BASE); \ 9326c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visit##DERIVED##DeclAsContext, DERIVED##Decl); \ 9426c25c95a1eeeed09265525de300670eb5e9c015John McCall } \ 9526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visit##DERIVED##DeclAsContext(DERIVED##Decl *D) {} 9626c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/DeclNodes.inc" 9726c25c95a1eeeed09265525de300670eb5e9c015John McCall 9826c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatchDeclAttrs(Decl *D) { 9926c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visitDeclAttrs, Decl); 10026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 10126c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitDeclAttrs(Decl *D) {} 10226c25c95a1eeeed09265525de300670eb5e9c015John McCall 10326c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatchDeclChildren(Decl *D) { 10426c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visitDeclChildren, Decl); 10526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 10626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitDeclChildren(Decl *D) {} 10726c25c95a1eeeed09265525de300670eb5e9c015John McCall 10826c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatchDeclAsContext(Decl *D) { 10926c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visitDeclAsContext, Decl); 11026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 11126c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitDeclAsContext(Decl *D) {} 11226c25c95a1eeeed09265525de300670eb5e9c015John McCall 11326c25c95a1eeeed09265525de300670eb5e9c015John McCall#undef DISPATCH 11426c25c95a1eeeed09265525de300670eb5e9c015John McCall}; 11526c25c95a1eeeed09265525de300670eb5e9c015John McCall 11626c25c95a1eeeed09265525de300670eb5e9c015John McCalltemplate <class Impl> struct XMLTypeVisitor { 11726c25c95a1eeeed09265525de300670eb5e9c015John McCall#define DISPATCH(NAME, CLASS) \ 11826c25c95a1eeeed09265525de300670eb5e9c015John McCall static_cast<Impl*>(this)->NAME(static_cast<CLASS*>(T)) 11926c25c95a1eeeed09265525de300670eb5e9c015John McCall 12026c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch(Type *T) { 12126c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (T->getTypeClass()) { 12226c25c95a1eeeed09265525de300670eb5e9c015John McCall#define TYPE(DERIVED, BASE) \ 12326c25c95a1eeeed09265525de300670eb5e9c015John McCall case Type::DERIVED: \ 12426c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##DERIVED##TypeAttrs, DERIVED##Type); \ 12526c25c95a1eeeed09265525de300670eb5e9c015John McCall static_cast<Impl*>(this)->completeAttrs(); \ 12626c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##DERIVED##TypeChildren, DERIVED##Type); \ 12726c25c95a1eeeed09265525de300670eb5e9c015John McCall break; 12826c25c95a1eeeed09265525de300670eb5e9c015John McCall#define ABSTRACT_TYPE(DERIVED, BASE) 12926c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/TypeNodes.def" 13026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 13126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 13226c25c95a1eeeed09265525de300670eb5e9c015John McCall 13326c25c95a1eeeed09265525de300670eb5e9c015John McCall#define TYPE(DERIVED, BASE) \ 13426c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch##DERIVED##TypeAttrs(DERIVED##Type *T) { \ 13526c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##BASE##Attrs, BASE); \ 13626c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visit##DERIVED##TypeAttrs, DERIVED##Type); \ 13726c25c95a1eeeed09265525de300670eb5e9c015John McCall } \ 13826c25c95a1eeeed09265525de300670eb5e9c015John McCall void visit##DERIVED##TypeAttrs(DERIVED##Type *T) {} \ 13926c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch##DERIVED##TypeChildren(DERIVED##Type *T) { \ 14026c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(dispatch##BASE##Children, BASE); \ 14126c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visit##DERIVED##TypeChildren, DERIVED##Type); \ 14226c25c95a1eeeed09265525de300670eb5e9c015John McCall } \ 14326c25c95a1eeeed09265525de300670eb5e9c015John McCall void visit##DERIVED##TypeChildren(DERIVED##Type *T) {} 14426c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/TypeNodes.def" 14526c25c95a1eeeed09265525de300670eb5e9c015John McCall 14626c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatchTypeAttrs(Type *T) { 14726c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visitTypeAttrs, Type); 14826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 14926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTypeAttrs(Type *T) {} 15026c25c95a1eeeed09265525de300670eb5e9c015John McCall 15126c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatchTypeChildren(Type *T) { 15226c25c95a1eeeed09265525de300670eb5e9c015John McCall DISPATCH(visitTypeChildren, Type); 15326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 15426c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTypeChildren(Type *T) {} 15526c25c95a1eeeed09265525de300670eb5e9c015John McCall 15626c25c95a1eeeed09265525de300670eb5e9c015John McCall#undef DISPATCH 15726c25c95a1eeeed09265525de300670eb5e9c015John McCall}; 15826c25c95a1eeeed09265525de300670eb5e9c015John McCall 1595f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnerstatic StringRef getTypeKindName(Type *T) { 16026c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (T->getTypeClass()) { 16126c25c95a1eeeed09265525de300670eb5e9c015John McCall#define TYPE(DERIVED, BASE) case Type::DERIVED: return #DERIVED "Type"; 16226c25c95a1eeeed09265525de300670eb5e9c015John McCall#define ABSTRACT_TYPE(DERIVED, BASE) 16326c25c95a1eeeed09265525de300670eb5e9c015John McCall#include "clang/AST/TypeNodes.def" 16426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 16526c25c95a1eeeed09265525de300670eb5e9c015John McCall 16626c25c95a1eeeed09265525de300670eb5e9c015John McCall llvm_unreachable("unknown type kind!"); 16726c25c95a1eeeed09265525de300670eb5e9c015John McCall} 16826c25c95a1eeeed09265525de300670eb5e9c015John McCall 16926c25c95a1eeeed09265525de300670eb5e9c015John McCallstruct XMLDumper : public XMLDeclVisitor<XMLDumper>, 17026c25c95a1eeeed09265525de300670eb5e9c015John McCall public XMLTypeVisitor<XMLDumper> { 1715f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner raw_ostream &out; 17226c25c95a1eeeed09265525de300670eb5e9c015John McCall ASTContext &Context; 1735f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner SmallVector<Node, 16> Stack; 17426c25c95a1eeeed09265525de300670eb5e9c015John McCall unsigned Indent; 1755f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner explicit XMLDumper(raw_ostream &OS, ASTContext &context) 17626c25c95a1eeeed09265525de300670eb5e9c015John McCall : out(OS), Context(context), Indent(0) {} 17726c25c95a1eeeed09265525de300670eb5e9c015John McCall 17826c25c95a1eeeed09265525de300670eb5e9c015John McCall void indent() { 17926c25c95a1eeeed09265525de300670eb5e9c015John McCall for (unsigned I = Indent; I; --I) 18026c25c95a1eeeed09265525de300670eb5e9c015John McCall out << ' '; 18126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 18226c25c95a1eeeed09265525de300670eb5e9c015John McCall 18326c25c95a1eeeed09265525de300670eb5e9c015John McCall /// Push a new node on the stack. 1845f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void push(StringRef name) { 18526c25c95a1eeeed09265525de300670eb5e9c015John McCall if (!Stack.empty()) { 18626c25c95a1eeeed09265525de300670eb5e9c015John McCall assert(Stack.back().isDoneWithAttrs()); 18726c25c95a1eeeed09265525de300670eb5e9c015John McCall if (Stack.back().State == NS_LazyChildren) { 18826c25c95a1eeeed09265525de300670eb5e9c015John McCall Stack.back().State = NS_Children; 18926c25c95a1eeeed09265525de300670eb5e9c015John McCall out << ">\n"; 19026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 19126c25c95a1eeeed09265525de300670eb5e9c015John McCall Indent++; 19226c25c95a1eeeed09265525de300670eb5e9c015John McCall indent(); 19326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 19426c25c95a1eeeed09265525de300670eb5e9c015John McCall Stack.push_back(Node(name)); 19526c25c95a1eeeed09265525de300670eb5e9c015John McCall out << '<' << name; 19626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 19726c25c95a1eeeed09265525de300670eb5e9c015John McCall 19826c25c95a1eeeed09265525de300670eb5e9c015John McCall /// Set the given attribute to the given value. 1995f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void set(StringRef attr, StringRef value) { 20026c25c95a1eeeed09265525de300670eb5e9c015John McCall assert(!Stack.empty() && !Stack.back().isDoneWithAttrs()); 20126c25c95a1eeeed09265525de300670eb5e9c015John McCall out << ' ' << attr << '=' << '"' << value << '"'; // TODO: quotation 20226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 20326c25c95a1eeeed09265525de300670eb5e9c015John McCall 20426c25c95a1eeeed09265525de300670eb5e9c015John McCall /// Finish attributes. 20526c25c95a1eeeed09265525de300670eb5e9c015John McCall void completeAttrs() { 20626c25c95a1eeeed09265525de300670eb5e9c015John McCall assert(!Stack.empty() && !Stack.back().isDoneWithAttrs()); 20726c25c95a1eeeed09265525de300670eb5e9c015John McCall Stack.back().State = NS_LazyChildren; 20826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 20926c25c95a1eeeed09265525de300670eb5e9c015John McCall 21026c25c95a1eeeed09265525de300670eb5e9c015John McCall /// Pop a node. 21126c25c95a1eeeed09265525de300670eb5e9c015John McCall void pop() { 21226c25c95a1eeeed09265525de300670eb5e9c015John McCall assert(!Stack.empty() && Stack.back().isDoneWithAttrs()); 21326c25c95a1eeeed09265525de300670eb5e9c015John McCall if (Stack.back().State == NS_LazyChildren) { 21426c25c95a1eeeed09265525de300670eb5e9c015John McCall out << "/>\n"; 21526c25c95a1eeeed09265525de300670eb5e9c015John McCall } else { 21626c25c95a1eeeed09265525de300670eb5e9c015John McCall indent(); 21726c25c95a1eeeed09265525de300670eb5e9c015John McCall out << "</" << Stack.back().Name << ">\n"; 21826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 21926c25c95a1eeeed09265525de300670eb5e9c015John McCall if (Stack.size() > 1) Indent--; 22026c25c95a1eeeed09265525de300670eb5e9c015John McCall Stack.pop_back(); 22126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 22226c25c95a1eeeed09265525de300670eb5e9c015John McCall 22326c25c95a1eeeed09265525de300670eb5e9c015John McCall //---- General utilities -------------------------------------------// 22426c25c95a1eeeed09265525de300670eb5e9c015John McCall 2255f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void setPointer(StringRef prop, const void *p) { 226f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<10> buffer; 22726c25c95a1eeeed09265525de300670eb5e9c015John McCall llvm::raw_svector_ostream os(buffer); 22826c25c95a1eeeed09265525de300670eb5e9c015John McCall os << p; 22926c25c95a1eeeed09265525de300670eb5e9c015John McCall os.flush(); 23026c25c95a1eeeed09265525de300670eb5e9c015John McCall set(prop, buffer); 23126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 23226c25c95a1eeeed09265525de300670eb5e9c015John McCall 23326c25c95a1eeeed09265525de300670eb5e9c015John McCall void setPointer(void *p) { 23426c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer("ptr", p); 23526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 23626c25c95a1eeeed09265525de300670eb5e9c015John McCall 2375f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void setInteger(StringRef prop, const llvm::APSInt &v) { 23826c25c95a1eeeed09265525de300670eb5e9c015John McCall set(prop, v.toString(10)); 23926c25c95a1eeeed09265525de300670eb5e9c015John McCall } 24026c25c95a1eeeed09265525de300670eb5e9c015John McCall 2415f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void setInteger(StringRef prop, unsigned n) { 242f7ccbad5d9949e7ddd1cbef43d482553b811e026Dylan Noblesmith SmallString<10> buffer; 24326c25c95a1eeeed09265525de300670eb5e9c015John McCall llvm::raw_svector_ostream os(buffer); 24426c25c95a1eeeed09265525de300670eb5e9c015John McCall os << n; 24526c25c95a1eeeed09265525de300670eb5e9c015John McCall os.flush(); 24626c25c95a1eeeed09265525de300670eb5e9c015John McCall set(prop, buffer); 24726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 24826c25c95a1eeeed09265525de300670eb5e9c015John McCall 2495f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void setFlag(StringRef prop, bool flag) { 25026c25c95a1eeeed09265525de300670eb5e9c015John McCall if (flag) set(prop, "true"); 25126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 25226c25c95a1eeeed09265525de300670eb5e9c015John McCall 25326c25c95a1eeeed09265525de300670eb5e9c015John McCall void setName(DeclarationName Name) { 2546710cf1d5f3ab31524af6d72278ec5952f75b3c4John McCall if (!Name) 2556710cf1d5f3ab31524af6d72278ec5952f75b3c4John McCall return set("name", ""); 2566710cf1d5f3ab31524af6d72278ec5952f75b3c4John McCall 25726c25c95a1eeeed09265525de300670eb5e9c015John McCall // Common case. 25826c25c95a1eeeed09265525de300670eb5e9c015John McCall if (Name.isIdentifier()) 25926c25c95a1eeeed09265525de300670eb5e9c015John McCall return set("name", Name.getAsIdentifierInfo()->getName()); 26026c25c95a1eeeed09265525de300670eb5e9c015John McCall 2617bd245b42cb3fb3da8877faf748538dd0b0154fbJohn McCall set("name", Name.getAsString()); 26226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 26326c25c95a1eeeed09265525de300670eb5e9c015John McCall 26426c25c95a1eeeed09265525de300670eb5e9c015John McCall class TemporaryContainer { 26526c25c95a1eeeed09265525de300670eb5e9c015John McCall XMLDumper &Dumper; 26626c25c95a1eeeed09265525de300670eb5e9c015John McCall public: 2675f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner TemporaryContainer(XMLDumper &dumper, StringRef name) 26826c25c95a1eeeed09265525de300670eb5e9c015John McCall : Dumper(dumper) { 26926c25c95a1eeeed09265525de300670eb5e9c015John McCall Dumper.push(name); 27026c25c95a1eeeed09265525de300670eb5e9c015John McCall Dumper.completeAttrs(); 27126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 27226c25c95a1eeeed09265525de300670eb5e9c015John McCall 27326c25c95a1eeeed09265525de300670eb5e9c015John McCall ~TemporaryContainer() { 27426c25c95a1eeeed09265525de300670eb5e9c015John McCall Dumper.pop(); 27526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 27626c25c95a1eeeed09265525de300670eb5e9c015John McCall }; 27726c25c95a1eeeed09265525de300670eb5e9c015John McCall 27826c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTemplateParameters(TemplateParameterList *L) { 27926c25c95a1eeeed09265525de300670eb5e9c015John McCall push("template_parameters"); 28026c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 28126c25c95a1eeeed09265525de300670eb5e9c015John McCall for (TemplateParameterList::iterator 28226c25c95a1eeeed09265525de300670eb5e9c015John McCall I = L->begin(), E = L->end(); I != E; ++I) 28326c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(*I); 28426c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 28526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 28626c25c95a1eeeed09265525de300670eb5e9c015John McCall 28726c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTemplateArguments(const TemplateArgumentList &L) { 28826c25c95a1eeeed09265525de300670eb5e9c015John McCall push("template_arguments"); 28926c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 29026c25c95a1eeeed09265525de300670eb5e9c015John McCall for (unsigned I = 0, E = L.size(); I != E; ++I) 29126c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(L[I]); 29226c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 29326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 29426c25c95a1eeeed09265525de300670eb5e9c015John McCall 29526c25c95a1eeeed09265525de300670eb5e9c015John McCall /// Visits a reference to the given declaration. 29626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitDeclRef(Decl *D) { 29726c25c95a1eeeed09265525de300670eb5e9c015John McCall push(D->getDeclKindName()); 29826c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer("ref", D); 29926c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 30026c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 30126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 3025f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void visitDeclRef(StringRef Name, Decl *D) { 3033bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall TemporaryContainer C(*this, Name); 3043bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall if (D) visitDeclRef(D); 3053bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 30626c25c95a1eeeed09265525de300670eb5e9c015John McCall 30726c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch(const TemplateArgument &A) { 30826c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (A.getKind()) { 30926c25c95a1eeeed09265525de300670eb5e9c015John McCall case TemplateArgument::Null: { 31026c25c95a1eeeed09265525de300670eb5e9c015John McCall TemporaryContainer C(*this, "null"); 31126c25c95a1eeeed09265525de300670eb5e9c015John McCall break; 31226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 31326c25c95a1eeeed09265525de300670eb5e9c015John McCall case TemplateArgument::Type: { 31426c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(A.getAsType()); 31526c25c95a1eeeed09265525de300670eb5e9c015John McCall break; 31626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 31726c25c95a1eeeed09265525de300670eb5e9c015John McCall case TemplateArgument::Template: 318a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 319a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor // FIXME: Implement! 320a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 321a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 32226c25c95a1eeeed09265525de300670eb5e9c015John McCall case TemplateArgument::Declaration: { 323d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor if (Decl *D = A.getAsDecl()) 324d2008e2c80d6c9282044ec873a937a17a0f33579Douglas Gregor visitDeclRef(D); 32526c25c95a1eeeed09265525de300670eb5e9c015John McCall break; 32626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 32726c25c95a1eeeed09265525de300670eb5e9c015John McCall case TemplateArgument::Integral: { 32826c25c95a1eeeed09265525de300670eb5e9c015John McCall push("integer"); 32926c25c95a1eeeed09265525de300670eb5e9c015John McCall setInteger("value", *A.getAsIntegral()); 33026c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 33126c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 33226c25c95a1eeeed09265525de300670eb5e9c015John McCall break; 33326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 33426c25c95a1eeeed09265525de300670eb5e9c015John McCall case TemplateArgument::Expression: { 33526c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(A.getAsExpr()); 33626c25c95a1eeeed09265525de300670eb5e9c015John McCall break; 33726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 33826c25c95a1eeeed09265525de300670eb5e9c015John McCall case TemplateArgument::Pack: { 33987dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor for (TemplateArgument::pack_iterator P = A.pack_begin(), 34087dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor PEnd = A.pack_end(); 34187dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor P != PEnd; ++P) 34287dd697dcc8ecb64df73ae64d61b8c80ff0c157cDouglas Gregor dispatch(*P); 34326c25c95a1eeeed09265525de300670eb5e9c015John McCall break; 34426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 34526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 34626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 34726c25c95a1eeeed09265525de300670eb5e9c015John McCall 34826c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch(const TemplateArgumentLoc &A) { 34926c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(A.getArgument()); 35026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 35126c25c95a1eeeed09265525de300670eb5e9c015John McCall 35226c25c95a1eeeed09265525de300670eb5e9c015John McCall //---- Declarations ------------------------------------------------// 35326c25c95a1eeeed09265525de300670eb5e9c015John McCall // Calls are made in this order: 35426c25c95a1eeeed09265525de300670eb5e9c015John McCall // # Enter a new node. 35526c25c95a1eeeed09265525de300670eb5e9c015John McCall // push("FieldDecl") 35626c25c95a1eeeed09265525de300670eb5e9c015John McCall // 35726c25c95a1eeeed09265525de300670eb5e9c015John McCall // # In this phase, attributes are set on the node. 35826c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitDeclAttrs(D) 35926c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitNamedDeclAttrs(D) 36026c25c95a1eeeed09265525de300670eb5e9c015John McCall // ... 36126c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitFieldDeclAttrs(D) 36226c25c95a1eeeed09265525de300670eb5e9c015John McCall // 36326c25c95a1eeeed09265525de300670eb5e9c015John McCall // # No more attributes after this point. 36426c25c95a1eeeed09265525de300670eb5e9c015John McCall // completeAttrs() 36526c25c95a1eeeed09265525de300670eb5e9c015John McCall // 36626c25c95a1eeeed09265525de300670eb5e9c015John McCall // # Create "header" child nodes, i.e. those which logically 36726c25c95a1eeeed09265525de300670eb5e9c015John McCall // # belong to the declaration itself. 36826c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitDeclChildren(D) 36926c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitNamedDeclChildren(D) 37026c25c95a1eeeed09265525de300670eb5e9c015John McCall // ... 37126c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitFieldDeclChildren(D) 37226c25c95a1eeeed09265525de300670eb5e9c015John McCall // 37326c25c95a1eeeed09265525de300670eb5e9c015John McCall // # Create nodes for the lexical children. 37426c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitDeclAsContext(D) 37526c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitNamedDeclAsContext(D) 37626c25c95a1eeeed09265525de300670eb5e9c015John McCall // ... 37726c25c95a1eeeed09265525de300670eb5e9c015John McCall // visitFieldDeclAsContext(D) 37826c25c95a1eeeed09265525de300670eb5e9c015John McCall // 37926c25c95a1eeeed09265525de300670eb5e9c015John McCall // # Finish the node. 38026c25c95a1eeeed09265525de300670eb5e9c015John McCall // pop(); 38126c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch(Decl *D) { 38226c25c95a1eeeed09265525de300670eb5e9c015John McCall push(D->getDeclKindName()); 38313cf5e2e223ebfc8ec0459913b2fc9ec1e5fa760John McCall XMLDeclVisitor<XMLDumper>::dispatch(D); 38426c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 38526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 38626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitDeclAttrs(Decl *D) { 38726c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer(D); 38826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 38926c25c95a1eeeed09265525de300670eb5e9c015John McCall 39026c25c95a1eeeed09265525de300670eb5e9c015John McCall /// Visit all the lexical decls in the given context. 39126c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitDeclContext(DeclContext *DC) { 39226c25c95a1eeeed09265525de300670eb5e9c015John McCall for (DeclContext::decl_iterator 39326c25c95a1eeeed09265525de300670eb5e9c015John McCall I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) 39426c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(*I); 39526c25c95a1eeeed09265525de300670eb5e9c015John McCall 39626c25c95a1eeeed09265525de300670eb5e9c015John McCall // FIXME: point out visible declarations not in lexical context? 39726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 39826c25c95a1eeeed09265525de300670eb5e9c015John McCall 39926c25c95a1eeeed09265525de300670eb5e9c015John McCall /// Set the "access" attribute on the current node according to the 40026c25c95a1eeeed09265525de300670eb5e9c015John McCall /// given specifier. 40126c25c95a1eeeed09265525de300670eb5e9c015John McCall void setAccess(AccessSpecifier AS) { 40226c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (AS) { 40326c25c95a1eeeed09265525de300670eb5e9c015John McCall case AS_public: return set("access", "public"); 40426c25c95a1eeeed09265525de300670eb5e9c015John McCall case AS_protected: return set("access", "protected"); 40526c25c95a1eeeed09265525de300670eb5e9c015John McCall case AS_private: return set("access", "private"); 40626c25c95a1eeeed09265525de300670eb5e9c015John McCall case AS_none: llvm_unreachable("explicit forbidden access"); 40726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 40826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 40926c25c95a1eeeed09265525de300670eb5e9c015John McCall 41026c25c95a1eeeed09265525de300670eb5e9c015John McCall template <class T> void visitRedeclarableAttrs(T *D) { 411ef96ee0be5f100789f451641542a69cd719144d2Douglas Gregor if (T *Prev = D->getPreviousDecl()) 41226c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer("previous", Prev); 41326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 41426c25c95a1eeeed09265525de300670eb5e9c015John McCall 41526c25c95a1eeeed09265525de300670eb5e9c015John McCall 41626c25c95a1eeeed09265525de300670eb5e9c015John McCall // TranslationUnitDecl 41726c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTranslationUnitDeclAsContext(TranslationUnitDecl *D) { 41826c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclContext(D); 41926c25c95a1eeeed09265525de300670eb5e9c015John McCall } 42026c25c95a1eeeed09265525de300670eb5e9c015John McCall 42126c25c95a1eeeed09265525de300670eb5e9c015John McCall // LinkageSpecDecl 42226c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitLinkageSpecDeclAttrs(LinkageSpecDecl *D) { 4235f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner StringRef lang = ""; 42426c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (D->getLanguage()) { 42526c25c95a1eeeed09265525de300670eb5e9c015John McCall case LinkageSpecDecl::lang_c: lang = "C"; break; 42626c25c95a1eeeed09265525de300670eb5e9c015John McCall case LinkageSpecDecl::lang_cxx: lang = "C++"; break; 42726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 42826c25c95a1eeeed09265525de300670eb5e9c015John McCall set("lang", lang); 42926c25c95a1eeeed09265525de300670eb5e9c015John McCall } 43026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitLinkageSpecDeclAsContext(LinkageSpecDecl *D) { 43126c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclContext(D); 43226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 43326c25c95a1eeeed09265525de300670eb5e9c015John McCall 43426c25c95a1eeeed09265525de300670eb5e9c015John McCall // NamespaceDecl 43526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitNamespaceDeclAttrs(NamespaceDecl *D) { 43626c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("inline", D->isInline()); 43726c25c95a1eeeed09265525de300670eb5e9c015John McCall if (!D->isOriginalNamespace()) 43826c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer("original", D->getOriginalNamespace()); 43926c25c95a1eeeed09265525de300670eb5e9c015John McCall } 44026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitNamespaceDeclAsContext(NamespaceDecl *D) { 44126c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclContext(D); 44226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 44326c25c95a1eeeed09265525de300670eb5e9c015John McCall 44426c25c95a1eeeed09265525de300670eb5e9c015John McCall // NamedDecl 44526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitNamedDeclAttrs(NamedDecl *D) { 44626c25c95a1eeeed09265525de300670eb5e9c015John McCall setName(D->getDeclName()); 44726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 44826c25c95a1eeeed09265525de300670eb5e9c015John McCall 44926c25c95a1eeeed09265525de300670eb5e9c015John McCall // ValueDecl 45026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitValueDeclChildren(ValueDecl *D) { 45126c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getType()); 45226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 45326c25c95a1eeeed09265525de300670eb5e9c015John McCall 45426c25c95a1eeeed09265525de300670eb5e9c015John McCall // DeclaratorDecl 45526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitDeclaratorDeclChildren(DeclaratorDecl *D) { 45626c25c95a1eeeed09265525de300670eb5e9c015John McCall //dispatch(D->getTypeSourceInfo()->getTypeLoc()); 45726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 45826c25c95a1eeeed09265525de300670eb5e9c015John McCall 45926c25c95a1eeeed09265525de300670eb5e9c015John McCall // VarDecl 46026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitVarDeclAttrs(VarDecl *D) { 46126c25c95a1eeeed09265525de300670eb5e9c015John McCall visitRedeclarableAttrs(D); 46226c25c95a1eeeed09265525de300670eb5e9c015John McCall if (D->getStorageClass() != SC_None) 46326c25c95a1eeeed09265525de300670eb5e9c015John McCall set("storage", 46426c25c95a1eeeed09265525de300670eb5e9c015John McCall VarDecl::getStorageClassSpecifierString(D->getStorageClass())); 4655b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl StringRef initStyle = ""; 4665b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl switch (D->getInitStyle()) { 4675b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl case VarDecl::CInit: initStyle = "c"; break; 4685b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl case VarDecl::CallInit: initStyle = "call"; break; 4695b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl case VarDecl::ListInit: initStyle = "list"; break; 4705b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl } 4715b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl set("initstyle", initStyle); 47226c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("nrvo", D->isNRVOVariable()); 47326c25c95a1eeeed09265525de300670eb5e9c015John McCall // TODO: instantiation, etc. 47426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 47526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitVarDeclChildren(VarDecl *D) { 47626c25c95a1eeeed09265525de300670eb5e9c015John McCall if (D->hasInit()) dispatch(D->getInit()); 47726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 47826c25c95a1eeeed09265525de300670eb5e9c015John McCall 47926c25c95a1eeeed09265525de300670eb5e9c015John McCall // ParmVarDecl? 48026c25c95a1eeeed09265525de300670eb5e9c015John McCall 48126c25c95a1eeeed09265525de300670eb5e9c015John McCall // FunctionDecl 48226c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFunctionDeclAttrs(FunctionDecl *D) { 48326c25c95a1eeeed09265525de300670eb5e9c015John McCall visitRedeclarableAttrs(D); 48426c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("pure", D->isPure()); 48526c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("trivial", D->isTrivial()); 48626c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("returnzero", D->hasImplicitReturnZero()); 48726c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("prototype", D->hasWrittenPrototype()); 48810620eb5164e31208fcbf0437cd79ae535ed0559Sean Hunt setFlag("deleted", D->isDeletedAsWritten()); 48926c25c95a1eeeed09265525de300670eb5e9c015John McCall if (D->getStorageClass() != SC_None) 49026c25c95a1eeeed09265525de300670eb5e9c015John McCall set("storage", 49126c25c95a1eeeed09265525de300670eb5e9c015John McCall VarDecl::getStorageClassSpecifierString(D->getStorageClass())); 49226c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("inline", D->isInlineSpecified()); 493cbea7635a9a33fe768ed9611b57beae23bd7c98eJoerg Sonnenberger if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) 494cbea7635a9a33fe768ed9611b57beae23bd7c98eJoerg Sonnenberger set("asmlabel", ALA->getLabel()); 49526c25c95a1eeeed09265525de300670eb5e9c015John McCall // TODO: instantiation, etc. 49626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 49726c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFunctionDeclChildren(FunctionDecl *D) { 49826c25c95a1eeeed09265525de300670eb5e9c015John McCall for (FunctionDecl::param_iterator 49926c25c95a1eeeed09265525de300670eb5e9c015John McCall I = D->param_begin(), E = D->param_end(); I != E; ++I) 50026c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(*I); 50116f1f717af196b1448258857b2e6dcfe144b39d0James Molloy for (llvm::ArrayRef<NamedDecl*>::iterator 50216f1f717af196b1448258857b2e6dcfe144b39d0James Molloy I = D->getDeclsInPrototypeScope().begin(), E = D->getDeclsInPrototypeScope().end(); 50316f1f717af196b1448258857b2e6dcfe144b39d0James Molloy I != E; ++I) 50416f1f717af196b1448258857b2e6dcfe144b39d0James Molloy dispatch(*I); 50510620eb5164e31208fcbf0437cd79ae535ed0559Sean Hunt if (D->doesThisDeclarationHaveABody()) 50626c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getBody()); 50726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 50826c25c95a1eeeed09265525de300670eb5e9c015John McCall 50926c25c95a1eeeed09265525de300670eb5e9c015John McCall // CXXMethodDecl ? 51026c25c95a1eeeed09265525de300670eb5e9c015John McCall // CXXConstructorDecl ? 51126c25c95a1eeeed09265525de300670eb5e9c015John McCall // CXXDestructorDecl ? 51226c25c95a1eeeed09265525de300670eb5e9c015John McCall // CXXConversionDecl ? 51326c25c95a1eeeed09265525de300670eb5e9c015John McCall 514cbb67480094b3bcb5b715acd827cbad55e2a204cSean Hunt void dispatch(CXXCtorInitializer *Init) { 5153bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // TODO 5163bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 5173bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 51826c25c95a1eeeed09265525de300670eb5e9c015John McCall // FieldDecl 51926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFieldDeclAttrs(FieldDecl *D) { 52026c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("mutable", D->isMutable()); 52126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 52226c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFieldDeclChildren(FieldDecl *D) { 52326c25c95a1eeeed09265525de300670eb5e9c015John McCall if (D->isBitField()) { 52426c25c95a1eeeed09265525de300670eb5e9c015John McCall TemporaryContainer C(*this, "bitwidth"); 52526c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getBitWidth()); 52626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 52726c25c95a1eeeed09265525de300670eb5e9c015John McCall // TODO: C++0x member initializer 52826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 52926c25c95a1eeeed09265525de300670eb5e9c015John McCall 53026c25c95a1eeeed09265525de300670eb5e9c015John McCall // EnumConstantDecl 53126c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitEnumConstantDeclChildren(EnumConstantDecl *D) { 53226c25c95a1eeeed09265525de300670eb5e9c015John McCall // value in any case? 53326c25c95a1eeeed09265525de300670eb5e9c015John McCall if (D->getInitExpr()) dispatch(D->getInitExpr()); 53426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 53526c25c95a1eeeed09265525de300670eb5e9c015John McCall 53626c25c95a1eeeed09265525de300670eb5e9c015John McCall // IndirectFieldDecl 53726c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitIndirectFieldDeclChildren(IndirectFieldDecl *D) { 53826c25c95a1eeeed09265525de300670eb5e9c015John McCall for (IndirectFieldDecl::chain_iterator 53926c25c95a1eeeed09265525de300670eb5e9c015John McCall I = D->chain_begin(), E = D->chain_end(); I != E; ++I) { 54026c25c95a1eeeed09265525de300670eb5e9c015John McCall NamedDecl *VD = const_cast<NamedDecl*>(*I); 54126c25c95a1eeeed09265525de300670eb5e9c015John McCall push(isa<VarDecl>(VD) ? "variable" : "field"); 54226c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer("ptr", VD); 54326c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 54426c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 54526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 54626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 54726c25c95a1eeeed09265525de300670eb5e9c015John McCall 54826c25c95a1eeeed09265525de300670eb5e9c015John McCall // TypeDecl 54926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTypeDeclAttrs(TypeDecl *D) { 55026c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer("typeptr", D->getTypeForDecl()); 55126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 55226c25c95a1eeeed09265525de300670eb5e9c015John McCall 55326c25c95a1eeeed09265525de300670eb5e9c015John McCall // TypedefDecl 55426c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTypedefDeclAttrs(TypedefDecl *D) { 555162e1c1b487352434552147967c3dd296ebee2f7Richard Smith visitRedeclarableAttrs<TypedefNameDecl>(D); 55626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 55726c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTypedefDeclChildren(TypedefDecl *D) { 55826c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getTypeSourceInfo()->getTypeLoc()); 55926c25c95a1eeeed09265525de300670eb5e9c015John McCall } 56026c25c95a1eeeed09265525de300670eb5e9c015John McCall 561162e1c1b487352434552147967c3dd296ebee2f7Richard Smith // TypeAliasDecl 562162e1c1b487352434552147967c3dd296ebee2f7Richard Smith void visitTypeAliasDeclAttrs(TypeAliasDecl *D) { 563162e1c1b487352434552147967c3dd296ebee2f7Richard Smith visitRedeclarableAttrs<TypedefNameDecl>(D); 564162e1c1b487352434552147967c3dd296ebee2f7Richard Smith } 565162e1c1b487352434552147967c3dd296ebee2f7Richard Smith void visitTypeAliasDeclChildren(TypeAliasDecl *D) { 566162e1c1b487352434552147967c3dd296ebee2f7Richard Smith dispatch(D->getTypeSourceInfo()->getTypeLoc()); 567162e1c1b487352434552147967c3dd296ebee2f7Richard Smith } 568162e1c1b487352434552147967c3dd296ebee2f7Richard Smith 56926c25c95a1eeeed09265525de300670eb5e9c015John McCall // TagDecl 57026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTagDeclAttrs(TagDecl *D) { 57126c25c95a1eeeed09265525de300670eb5e9c015John McCall visitRedeclarableAttrs(D); 57226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 57326c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTagDeclAsContext(TagDecl *D) { 57426c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclContext(D); 57526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 57626c25c95a1eeeed09265525de300670eb5e9c015John McCall 57726c25c95a1eeeed09265525de300670eb5e9c015John McCall // EnumDecl 57826c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitEnumDeclAttrs(EnumDecl *D) { 57926c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("scoped", D->isScoped()); 58026c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("fixed", D->isFixed()); 58126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 58226c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitEnumDeclChildren(EnumDecl *D) { 58326c25c95a1eeeed09265525de300670eb5e9c015John McCall { 58426c25c95a1eeeed09265525de300670eb5e9c015John McCall TemporaryContainer C(*this, "promotion_type"); 58526c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getPromotionType()); 58626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 58726c25c95a1eeeed09265525de300670eb5e9c015John McCall { 58826c25c95a1eeeed09265525de300670eb5e9c015John McCall TemporaryContainer C(*this, "integer_type"); 58926c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getIntegerType()); 59026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 59126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 59226c25c95a1eeeed09265525de300670eb5e9c015John McCall 59326c25c95a1eeeed09265525de300670eb5e9c015John McCall // RecordDecl ? 59426c25c95a1eeeed09265525de300670eb5e9c015John McCall 59526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitCXXRecordDeclChildren(CXXRecordDecl *D) { 59626c25c95a1eeeed09265525de300670eb5e9c015John McCall if (!D->isThisDeclarationADefinition()) return; 59726c25c95a1eeeed09265525de300670eb5e9c015John McCall 59826c25c95a1eeeed09265525de300670eb5e9c015John McCall for (CXXRecordDecl::base_class_iterator 59926c25c95a1eeeed09265525de300670eb5e9c015John McCall I = D->bases_begin(), E = D->bases_end(); I != E; ++I) { 60026c25c95a1eeeed09265525de300670eb5e9c015John McCall push("base"); 60126c25c95a1eeeed09265525de300670eb5e9c015John McCall setAccess(I->getAccessSpecifier()); 60226c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 60326c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(I->getTypeSourceInfo()->getTypeLoc()); 60426c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 60526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 60626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 60726c25c95a1eeeed09265525de300670eb5e9c015John McCall 60826c25c95a1eeeed09265525de300670eb5e9c015John McCall // ClassTemplateSpecializationDecl ? 60926c25c95a1eeeed09265525de300670eb5e9c015John McCall 61026c25c95a1eeeed09265525de300670eb5e9c015John McCall // FileScopeAsmDecl ? 61126c25c95a1eeeed09265525de300670eb5e9c015John McCall 61226c25c95a1eeeed09265525de300670eb5e9c015John McCall // BlockDecl 61326c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitBlockDeclAttrs(BlockDecl *D) { 61426c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("variadic", D->isVariadic()); 61526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 61626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitBlockDeclChildren(BlockDecl *D) { 61726c25c95a1eeeed09265525de300670eb5e9c015John McCall for (FunctionDecl::param_iterator 61826c25c95a1eeeed09265525de300670eb5e9c015John McCall I = D->param_begin(), E = D->param_end(); I != E; ++I) 61926c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(*I); 62026c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getBody()); 62126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 62226c25c95a1eeeed09265525de300670eb5e9c015John McCall 62326c25c95a1eeeed09265525de300670eb5e9c015John McCall // AccessSpecDecl 62426c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitAccessSpecDeclAttrs(AccessSpecDecl *D) { 62526c25c95a1eeeed09265525de300670eb5e9c015John McCall setAccess(D->getAccess()); 62626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 62726c25c95a1eeeed09265525de300670eb5e9c015John McCall 62826c25c95a1eeeed09265525de300670eb5e9c015John McCall // TemplateDecl 62926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTemplateDeclChildren(TemplateDecl *D) { 63026c25c95a1eeeed09265525de300670eb5e9c015John McCall visitTemplateParameters(D->getTemplateParameters()); 6313e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (D->getTemplatedDecl()) 6323e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith dispatch(D->getTemplatedDecl()); 63326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 63426c25c95a1eeeed09265525de300670eb5e9c015John McCall 63526c25c95a1eeeed09265525de300670eb5e9c015John McCall // FunctionTemplateDecl 63626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFunctionTemplateDeclAttrs(FunctionTemplateDecl *D) { 63726c25c95a1eeeed09265525de300670eb5e9c015John McCall visitRedeclarableAttrs(D); 63826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 63926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFunctionTemplateDeclChildren(FunctionTemplateDecl *D) { 64026c25c95a1eeeed09265525de300670eb5e9c015John McCall // Mention all the specializations which don't have explicit 64126c25c95a1eeeed09265525de300670eb5e9c015John McCall // declarations elsewhere. 64226c25c95a1eeeed09265525de300670eb5e9c015John McCall for (FunctionTemplateDecl::spec_iterator 64326c25c95a1eeeed09265525de300670eb5e9c015John McCall I = D->spec_begin(), E = D->spec_end(); I != E; ++I) { 64426c25c95a1eeeed09265525de300670eb5e9c015John McCall FunctionTemplateSpecializationInfo *Info 64526c25c95a1eeeed09265525de300670eb5e9c015John McCall = I->getTemplateSpecializationInfo(); 64626c25c95a1eeeed09265525de300670eb5e9c015John McCall 64726c25c95a1eeeed09265525de300670eb5e9c015John McCall bool Unknown = false; 64826c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (Info->getTemplateSpecializationKind()) { 64926c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_ImplicitInstantiation: Unknown = false; break; 65026c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_Undeclared: Unknown = true; break; 65126c25c95a1eeeed09265525de300670eb5e9c015John McCall 65226c25c95a1eeeed09265525de300670eb5e9c015John McCall // These will be covered at their respective sites. 65326c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_ExplicitSpecialization: continue; 65426c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_ExplicitInstantiationDeclaration: continue; 65526c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_ExplicitInstantiationDefinition: continue; 65626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 65726c25c95a1eeeed09265525de300670eb5e9c015John McCall 65826c25c95a1eeeed09265525de300670eb5e9c015John McCall TemporaryContainer C(*this, 65926c25c95a1eeeed09265525de300670eb5e9c015John McCall Unknown ? "uninstantiated" : "instantiation"); 66026c25c95a1eeeed09265525de300670eb5e9c015John McCall visitTemplateArguments(*Info->TemplateArguments); 66126c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(Info->Function); 66226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 66326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 66426c25c95a1eeeed09265525de300670eb5e9c015John McCall 66526c25c95a1eeeed09265525de300670eb5e9c015John McCall // ClasTemplateDecl 66626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitClassTemplateDeclAttrs(ClassTemplateDecl *D) { 66726c25c95a1eeeed09265525de300670eb5e9c015John McCall visitRedeclarableAttrs(D); 66826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 66926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitClassTemplateDeclChildren(ClassTemplateDecl *D) { 67026c25c95a1eeeed09265525de300670eb5e9c015John McCall // Mention all the specializations which don't have explicit 67126c25c95a1eeeed09265525de300670eb5e9c015John McCall // declarations elsewhere. 67226c25c95a1eeeed09265525de300670eb5e9c015John McCall for (ClassTemplateDecl::spec_iterator 67326c25c95a1eeeed09265525de300670eb5e9c015John McCall I = D->spec_begin(), E = D->spec_end(); I != E; ++I) { 67426c25c95a1eeeed09265525de300670eb5e9c015John McCall 67526c25c95a1eeeed09265525de300670eb5e9c015John McCall bool Unknown = false; 67626c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (I->getTemplateSpecializationKind()) { 67726c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_ImplicitInstantiation: Unknown = false; break; 67826c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_Undeclared: Unknown = true; break; 67926c25c95a1eeeed09265525de300670eb5e9c015John McCall 68026c25c95a1eeeed09265525de300670eb5e9c015John McCall // These will be covered at their respective sites. 68126c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_ExplicitSpecialization: continue; 68226c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_ExplicitInstantiationDeclaration: continue; 68326c25c95a1eeeed09265525de300670eb5e9c015John McCall case TSK_ExplicitInstantiationDefinition: continue; 68426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 68526c25c95a1eeeed09265525de300670eb5e9c015John McCall 68626c25c95a1eeeed09265525de300670eb5e9c015John McCall TemporaryContainer C(*this, 68726c25c95a1eeeed09265525de300670eb5e9c015John McCall Unknown ? "uninstantiated" : "instantiation"); 68826c25c95a1eeeed09265525de300670eb5e9c015John McCall visitTemplateArguments(I->getTemplateArgs()); 68926c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(*I); 69026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 69126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 69226c25c95a1eeeed09265525de300670eb5e9c015John McCall 69326c25c95a1eeeed09265525de300670eb5e9c015John McCall // TemplateTypeParmDecl 69426c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTemplateTypeParmDeclAttrs(TemplateTypeParmDecl *D) { 69526c25c95a1eeeed09265525de300670eb5e9c015John McCall setInteger("depth", D->getDepth()); 69626c25c95a1eeeed09265525de300670eb5e9c015John McCall setInteger("index", D->getIndex()); 69726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 69826c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTemplateTypeParmDeclChildren(TemplateTypeParmDecl *D) { 69926c25c95a1eeeed09265525de300670eb5e9c015John McCall if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) 70026c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getDefaultArgumentInfo()->getTypeLoc()); 70126c25c95a1eeeed09265525de300670eb5e9c015John McCall // parameter pack? 70226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 70326c25c95a1eeeed09265525de300670eb5e9c015John McCall 70426c25c95a1eeeed09265525de300670eb5e9c015John McCall // NonTypeTemplateParmDecl 70526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitNonTypeTemplateParmDeclAttrs(NonTypeTemplateParmDecl *D) { 70626c25c95a1eeeed09265525de300670eb5e9c015John McCall setInteger("depth", D->getDepth()); 70726c25c95a1eeeed09265525de300670eb5e9c015John McCall setInteger("index", D->getIndex()); 70826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 70926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitNonTypeTemplateParmDeclChildren(NonTypeTemplateParmDecl *D) { 71026c25c95a1eeeed09265525de300670eb5e9c015John McCall if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) 71126c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getDefaultArgument()); 71226c25c95a1eeeed09265525de300670eb5e9c015John McCall // parameter pack? 71326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 71426c25c95a1eeeed09265525de300670eb5e9c015John McCall 71526c25c95a1eeeed09265525de300670eb5e9c015John McCall // TemplateTemplateParmDecl 71626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTemplateTemplateParmDeclAttrs(TemplateTemplateParmDecl *D) { 71726c25c95a1eeeed09265525de300670eb5e9c015John McCall setInteger("depth", D->getDepth()); 71826c25c95a1eeeed09265525de300670eb5e9c015John McCall setInteger("index", D->getIndex()); 71926c25c95a1eeeed09265525de300670eb5e9c015John McCall } 72026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTemplateTemplateParmDeclChildren(TemplateTemplateParmDecl *D) { 72126c25c95a1eeeed09265525de300670eb5e9c015John McCall if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) 72226c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getDefaultArgument()); 72326c25c95a1eeeed09265525de300670eb5e9c015John McCall // parameter pack? 72426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 72526c25c95a1eeeed09265525de300670eb5e9c015John McCall 72626c25c95a1eeeed09265525de300670eb5e9c015John McCall // FriendDecl 72726c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFriendDeclChildren(FriendDecl *D) { 72826c25c95a1eeeed09265525de300670eb5e9c015John McCall if (TypeSourceInfo *T = D->getFriendType()) 72926c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(T->getTypeLoc()); 73026c25c95a1eeeed09265525de300670eb5e9c015John McCall else 73126c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(D->getFriendDecl()); 73226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 73326c25c95a1eeeed09265525de300670eb5e9c015John McCall 73426c25c95a1eeeed09265525de300670eb5e9c015John McCall // UsingDirectiveDecl ? 73526c25c95a1eeeed09265525de300670eb5e9c015John McCall // UsingDecl ? 73626c25c95a1eeeed09265525de300670eb5e9c015John McCall // UsingShadowDecl ? 73726c25c95a1eeeed09265525de300670eb5e9c015John McCall // NamespaceAliasDecl ? 73826c25c95a1eeeed09265525de300670eb5e9c015John McCall // UnresolvedUsingValueDecl ? 73926c25c95a1eeeed09265525de300670eb5e9c015John McCall // UnresolvedUsingTypenameDecl ? 74026c25c95a1eeeed09265525de300670eb5e9c015John McCall // StaticAssertDecl ? 74126c25c95a1eeeed09265525de300670eb5e9c015John McCall 7423bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCImplDecl 7433bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCImplDeclChildren(ObjCImplDecl *D) { 7443bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef(D->getClassInterface()); 7453bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7463bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCImplDeclAsContext(ObjCImplDecl *D) { 7473bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclContext(D); 7483bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7493bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 7503bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCInterfaceDecl 7513bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitCategoryList(ObjCCategoryDecl *D) { 7523bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall if (!D) return; 7533bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 7543bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall TemporaryContainer C(*this, "categories"); 7553bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall for (; D; D = D->getNextClassCategory()) 7563bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef(D); 7573bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7583bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCInterfaceDeclAttrs(ObjCInterfaceDecl *D) { 7593bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setPointer("typeptr", D->getTypeForDecl()); 7607723fec9b45b7258c0eddf4cbfd0d335348f5edcDouglas Gregor setFlag("forward_decl", !D->isThisDeclarationADefinition()); 7613bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("implicit_interface", D->isImplicitInterfaceDecl()); 7623bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7633bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCInterfaceDeclChildren(ObjCInterfaceDecl *D) { 7643bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef("super", D->getSuperClass()); 7653bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef("implementation", D->getImplementation()); 7663bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall if (D->protocol_begin() != D->protocol_end()) { 7673bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall TemporaryContainer C(*this, "protocols"); 7683bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall for (ObjCInterfaceDecl::protocol_iterator 7693bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I) 7703bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef(*I); 7713bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7723bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitCategoryList(D->getCategoryList()); 7733bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7743bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCInterfaceDeclAsContext(ObjCInterfaceDecl *D) { 7753bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclContext(D); 7763bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7773bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 7783bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCCategoryDecl 7793bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCCategoryDeclAttrs(ObjCCategoryDecl *D) { 7803bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("extension", D->IsClassExtension()); 7813bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("synth_bitfield", D->hasSynthBitfield()); 7823bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7833bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCCategoryDeclChildren(ObjCCategoryDecl *D) { 7843bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef("interface", D->getClassInterface()); 7853bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef("implementation", D->getImplementation()); 7863bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall if (D->protocol_begin() != D->protocol_end()) { 7873bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall TemporaryContainer C(*this, "protocols"); 7883bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall for (ObjCCategoryDecl::protocol_iterator 7893bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I) 7903bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef(*I); 7913bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7923bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7933bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCCategoryDeclAsContext(ObjCCategoryDecl *D) { 7943bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclContext(D); 7953bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 7963bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 7973bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCCategoryImplDecl 7983bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCCategoryImplDeclAttrs(ObjCCategoryImplDecl *D) { 7993bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall set("identifier", D->getName()); 8003bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8013bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCCategoryImplDeclChildren(ObjCCategoryImplDecl *D) { 8023bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef(D->getCategoryDecl()); 8033bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8043bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 8053bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCImplementationDecl 8063bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCImplementationDeclAttrs(ObjCImplementationDecl *D) { 8073bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("synth_bitfield", D->hasSynthBitfield()); 8083bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall set("identifier", D->getName()); 8093bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8103bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCImplementationDeclChildren(ObjCImplementationDecl *D) { 8113bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef("super", D->getSuperClass()); 8123bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall if (D->init_begin() != D->init_end()) { 8133bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall TemporaryContainer C(*this, "initializers"); 8143bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall for (ObjCImplementationDecl::init_iterator 8153bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall I = D->init_begin(), E = D->init_end(); I != E; ++I) 8163bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall dispatch(*I); 8173bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8183bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8193bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 8203bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCProtocolDecl 8213bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCProtocolDeclChildren(ObjCProtocolDecl *D) { 822bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor if (!D->isThisDeclarationADefinition()) 823bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return; 824bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor 8253bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall if (D->protocol_begin() != D->protocol_end()) { 8263bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall TemporaryContainer C(*this, "protocols"); 8273bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall for (ObjCInterfaceDecl::protocol_iterator 8283bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall I = D->protocol_begin(), E = D->protocol_end(); I != E; ++I) 8293bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef(*I); 8303bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8313bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8323bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCProtocolDeclAsContext(ObjCProtocolDecl *D) { 833bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor if (!D->isThisDeclarationADefinition()) 834bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor return; 835bd9482d859a74bf2c45ef8b8aedec61c0e1c8374Douglas Gregor 8363bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclContext(D); 8373bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8383bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 8393bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCMethodDecl 8403bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCMethodDeclAttrs(ObjCMethodDecl *D) { 8413bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // decl qualifier? 8423bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // implementation control? 8433bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 8443bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("instance", D->isInstanceMethod()); 8453bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("variadic", D->isVariadic()); 8463bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("synthesized", D->isSynthesized()); 8473bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("defined", D->isDefined()); 848926df6cfabf3eaa4afc990c097fa4619b76a9b57Douglas Gregor setFlag("related_result_type", D->hasRelatedResultType()); 8493bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8503bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCMethodDeclChildren(ObjCMethodDecl *D) { 8513bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall dispatch(D->getResultType()); 8523bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall for (ObjCMethodDecl::param_iterator 8533bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall I = D->param_begin(), E = D->param_end(); I != E; ++I) 8543bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall dispatch(*I); 8553bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall if (D->isThisDeclarationADefinition()) 8563bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall dispatch(D->getBody()); 8573bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8583bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 8593bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCIvarDecl 8605f9e272e632e951b1efe824cd16acb4d96077930Chris Lattner void setAccessControl(StringRef prop, ObjCIvarDecl::AccessControl AC) { 8613bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall switch (AC) { 8623bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall case ObjCIvarDecl::None: return set(prop, "none"); 8633bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall case ObjCIvarDecl::Private: return set(prop, "private"); 8643bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall case ObjCIvarDecl::Protected: return set(prop, "protected"); 8653bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall case ObjCIvarDecl::Public: return set(prop, "public"); 8663bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall case ObjCIvarDecl::Package: return set(prop, "package"); 8673bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8683bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8693bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCIvarDeclAttrs(ObjCIvarDecl *D) { 8703bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setFlag("synthesize", D->getSynthesize()); 8713bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall setAccessControl("access", D->getAccessControl()); 8723bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8733bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 8743bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // ObjCCompatibleAliasDecl 8753bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall void visitObjCCompatibleAliasDeclChildren(ObjCCompatibleAliasDecl *D) { 8763bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall visitDeclRef(D->getClassInterface()); 8773bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall } 8783bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 8793bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // FIXME: ObjCPropertyDecl 8803bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall // FIXME: ObjCPropertyImplDecl 8813bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall 88226c25c95a1eeeed09265525de300670eb5e9c015John McCall //---- Types -----------------------------------------------------// 88326c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch(TypeLoc TL) { 88426c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(TL.getType()); // for now 88526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 88626c25c95a1eeeed09265525de300670eb5e9c015John McCall 88726c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch(QualType T) { 88826c25c95a1eeeed09265525de300670eb5e9c015John McCall if (T.hasLocalQualifiers()) { 88926c25c95a1eeeed09265525de300670eb5e9c015John McCall push("QualType"); 89026c25c95a1eeeed09265525de300670eb5e9c015John McCall Qualifiers Qs = T.getLocalQualifiers(); 89126c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("const", Qs.hasConst()); 89226c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("volatile", Qs.hasVolatile()); 89326c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("restrict", Qs.hasRestrict()); 89426c25c95a1eeeed09265525de300670eb5e9c015John McCall if (Qs.hasAddressSpace()) setInteger("addrspace", Qs.getAddressSpace()); 89526c25c95a1eeeed09265525de300670eb5e9c015John McCall if (Qs.hasObjCGCAttr()) { 89626c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (Qs.getObjCGCAttr()) { 89726c25c95a1eeeed09265525de300670eb5e9c015John McCall case Qualifiers::Weak: set("gc", "weak"); break; 89826c25c95a1eeeed09265525de300670eb5e9c015John McCall case Qualifiers::Strong: set("gc", "strong"); break; 89926c25c95a1eeeed09265525de300670eb5e9c015John McCall case Qualifiers::GCNone: llvm_unreachable("explicit none"); 90026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 90126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 90226c25c95a1eeeed09265525de300670eb5e9c015John McCall 90326c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 90426c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(QualType(T.getTypePtr(), 0)); 90526c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 90626c25c95a1eeeed09265525de300670eb5e9c015John McCall return; 90726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 90826c25c95a1eeeed09265525de300670eb5e9c015John McCall 90926c25c95a1eeeed09265525de300670eb5e9c015John McCall Type *Ty = const_cast<Type*>(T.getTypePtr()); 91026c25c95a1eeeed09265525de300670eb5e9c015John McCall push(getTypeKindName(Ty)); 91113cf5e2e223ebfc8ec0459913b2fc9ec1e5fa760John McCall XMLTypeVisitor<XMLDumper>::dispatch(const_cast<Type*>(T.getTypePtr())); 91226c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 91326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 91426c25c95a1eeeed09265525de300670eb5e9c015John McCall 91526c25c95a1eeeed09265525de300670eb5e9c015John McCall void setCallingConv(CallingConv CC) { 91626c25c95a1eeeed09265525de300670eb5e9c015John McCall switch (CC) { 91726c25c95a1eeeed09265525de300670eb5e9c015John McCall case CC_Default: return; 91826c25c95a1eeeed09265525de300670eb5e9c015John McCall case CC_C: return set("cc", "cdecl"); 91926c25c95a1eeeed09265525de300670eb5e9c015John McCall case CC_X86FastCall: return set("cc", "x86_fastcall"); 92026c25c95a1eeeed09265525de300670eb5e9c015John McCall case CC_X86StdCall: return set("cc", "x86_stdcall"); 92126c25c95a1eeeed09265525de300670eb5e9c015John McCall case CC_X86ThisCall: return set("cc", "x86_thiscall"); 92226c25c95a1eeeed09265525de300670eb5e9c015John McCall case CC_X86Pascal: return set("cc", "x86_pascal"); 923414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS: return set("cc", "aapcs"); 924414d8967e1d760ea1e19a4aca96b13777a8cf8c5Anton Korobeynikov case CC_AAPCS_VFP: return set("cc", "aapcs_vfp"); 92526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 92626c25c95a1eeeed09265525de300670eb5e9c015John McCall } 92726c25c95a1eeeed09265525de300670eb5e9c015John McCall 92826c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTypeAttrs(Type *D) { 92926c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer(D); 93026c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("dependent", D->isDependentType()); 93126c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("variably_modified", D->isVariablyModifiedType()); 93226c25c95a1eeeed09265525de300670eb5e9c015John McCall 93326c25c95a1eeeed09265525de300670eb5e9c015John McCall setPointer("canonical", D->getCanonicalTypeInternal().getAsOpaquePtr()); 93426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 93526c25c95a1eeeed09265525de300670eb5e9c015John McCall 93626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitPointerTypeChildren(PointerType *T) { 93726c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(T->getPointeeType()); 93826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 93926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitReferenceTypeChildren(ReferenceType *T) { 94026c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(T->getPointeeType()); 94126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 94226c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitObjCObjectPointerTypeChildren(ObjCObjectPointerType *T) { 94326c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(T->getPointeeType()); 94426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 94526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitBlockPointerTypeChildren(BlockPointerType *T) { 94626c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(T->getPointeeType()); 94726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 94826c25c95a1eeeed09265525de300670eb5e9c015John McCall 94926c25c95a1eeeed09265525de300670eb5e9c015John McCall // Types that just wrap declarations. 95026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTagTypeChildren(TagType *T) { 95126c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclRef(T->getDecl()); 95226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 95326c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTypedefTypeChildren(TypedefType *T) { 95426c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclRef(T->getDecl()); 95526c25c95a1eeeed09265525de300670eb5e9c015John McCall } 95626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitObjCInterfaceTypeChildren(ObjCInterfaceType *T) { 95726c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclRef(T->getDecl()); 95826c25c95a1eeeed09265525de300670eb5e9c015John McCall } 95926c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitUnresolvedUsingTypeChildren(UnresolvedUsingType *T) { 96026c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclRef(T->getDecl()); 96126c25c95a1eeeed09265525de300670eb5e9c015John McCall } 96226c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitInjectedClassNameTypeChildren(InjectedClassNameType *T) { 96326c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclRef(T->getDecl()); 96426c25c95a1eeeed09265525de300670eb5e9c015John McCall } 96526c25c95a1eeeed09265525de300670eb5e9c015John McCall 96626c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFunctionTypeAttrs(FunctionType *T) { 96726c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("noreturn", T->getNoReturnAttr()); 96826c25c95a1eeeed09265525de300670eb5e9c015John McCall setCallingConv(T->getCallConv()); 969a49218e17bcbb1acde0245773173e2c0c42f4f19Eli Friedman if (T->getHasRegParm()) setInteger("regparm", T->getRegParmType()); 97026c25c95a1eeeed09265525de300670eb5e9c015John McCall } 97126c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFunctionTypeChildren(FunctionType *T) { 97226c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(T->getResultType()); 97326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 97426c25c95a1eeeed09265525de300670eb5e9c015John McCall 97526c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFunctionProtoTypeAttrs(FunctionProtoType *T) { 97626c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("const", T->getTypeQuals() & Qualifiers::Const); 97726c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("volatile", T->getTypeQuals() & Qualifiers::Volatile); 97826c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("restrict", T->getTypeQuals() & Qualifiers::Restrict); 97926c25c95a1eeeed09265525de300670eb5e9c015John McCall } 98026c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitFunctionProtoTypeChildren(FunctionProtoType *T) { 98126c25c95a1eeeed09265525de300670eb5e9c015John McCall push("parameters"); 98226c25c95a1eeeed09265525de300670eb5e9c015John McCall setFlag("variadic", T->isVariadic()); 98326c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 98426c25c95a1eeeed09265525de300670eb5e9c015John McCall for (FunctionProtoType::arg_type_iterator 98526c25c95a1eeeed09265525de300670eb5e9c015John McCall I = T->arg_type_begin(), E = T->arg_type_end(); I != E; ++I) 98626c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(*I); 98726c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 98826c25c95a1eeeed09265525de300670eb5e9c015John McCall 98960618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl if (T->hasDynamicExceptionSpec()) { 99026c25c95a1eeeed09265525de300670eb5e9c015John McCall push("exception_specifiers"); 99160618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl setFlag("any", T->getExceptionSpecType() == EST_MSAny); 99226c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 99326c25c95a1eeeed09265525de300670eb5e9c015John McCall for (FunctionProtoType::exception_iterator 99426c25c95a1eeeed09265525de300670eb5e9c015John McCall I = T->exception_begin(), E = T->exception_end(); I != E; ++I) 99526c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(*I); 99626c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 99726c25c95a1eeeed09265525de300670eb5e9c015John McCall } 99860618fa7f88d5162bb5b40988b6b38d4d75d6fc6Sebastian Redl // FIXME: noexcept specifier 99926c25c95a1eeeed09265525de300670eb5e9c015John McCall } 100026c25c95a1eeeed09265525de300670eb5e9c015John McCall 100126c25c95a1eeeed09265525de300670eb5e9c015John McCall void visitTemplateSpecializationTypeChildren(TemplateSpecializationType *T) { 100226c25c95a1eeeed09265525de300670eb5e9c015John McCall if (const RecordType *RT = T->getAs<RecordType>()) 100326c25c95a1eeeed09265525de300670eb5e9c015John McCall visitDeclRef(RT->getDecl()); 100426c25c95a1eeeed09265525de300670eb5e9c015John McCall 100526c25c95a1eeeed09265525de300670eb5e9c015John McCall // TODO: TemplateName 100626c25c95a1eeeed09265525de300670eb5e9c015John McCall 100726c25c95a1eeeed09265525de300670eb5e9c015John McCall push("template_arguments"); 100826c25c95a1eeeed09265525de300670eb5e9c015John McCall completeAttrs(); 100926c25c95a1eeeed09265525de300670eb5e9c015John McCall for (unsigned I = 0, E = T->getNumArgs(); I != E; ++I) 101026c25c95a1eeeed09265525de300670eb5e9c015John McCall dispatch(T->getArg(I)); 101126c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 101226c25c95a1eeeed09265525de300670eb5e9c015John McCall } 101326c25c95a1eeeed09265525de300670eb5e9c015John McCall 101426c25c95a1eeeed09265525de300670eb5e9c015John McCall //---- Statements ------------------------------------------------// 101526c25c95a1eeeed09265525de300670eb5e9c015John McCall void dispatch(Stmt *S) { 101626c25c95a1eeeed09265525de300670eb5e9c015John McCall // FIXME: this is not really XML at all 101726c25c95a1eeeed09265525de300670eb5e9c015John McCall push("Stmt"); 10183bddf5c2173a0a8bf900fe10f07b38e95e09c745John McCall out << ">\n"; 101926c25c95a1eeeed09265525de300670eb5e9c015John McCall Stack.back().State = NS_Children; // explicitly become non-lazy 102026c25c95a1eeeed09265525de300670eb5e9c015John McCall S->dump(out, Context.getSourceManager()); 102126c25c95a1eeeed09265525de300670eb5e9c015John McCall out << '\n'; 102226c25c95a1eeeed09265525de300670eb5e9c015John McCall pop(); 102326c25c95a1eeeed09265525de300670eb5e9c015John McCall } 102426c25c95a1eeeed09265525de300670eb5e9c015John McCall}; 102526c25c95a1eeeed09265525de300670eb5e9c015John McCall} 102626c25c95a1eeeed09265525de300670eb5e9c015John McCall 102726c25c95a1eeeed09265525de300670eb5e9c015John McCallvoid Decl::dumpXML() const { 102826c25c95a1eeeed09265525de300670eb5e9c015John McCall dumpXML(llvm::errs()); 102926c25c95a1eeeed09265525de300670eb5e9c015John McCall} 103026c25c95a1eeeed09265525de300670eb5e9c015John McCall 10315f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid Decl::dumpXML(raw_ostream &out) const { 103226c25c95a1eeeed09265525de300670eb5e9c015John McCall XMLDumper(out, getASTContext()).dispatch(const_cast<Decl*>(this)); 103326c25c95a1eeeed09265525de300670eb5e9c015John McCall} 103426c25c95a1eeeed09265525de300670eb5e9c015John McCall 103526c25c95a1eeeed09265525de300670eb5e9c015John McCall#else /* ifndef NDEBUG */ 103626c25c95a1eeeed09265525de300670eb5e9c015John McCall 103726c25c95a1eeeed09265525de300670eb5e9c015John McCallvoid Decl::dumpXML() const {} 10385f9e272e632e951b1efe824cd16acb4d96077930Chris Lattnervoid Decl::dumpXML(raw_ostream &out) const {} 103926c25c95a1eeeed09265525de300670eb5e9c015John McCall 104026c25c95a1eeeed09265525de300670eb5e9c015John McCall#endif 1041