From e6ec11aa15c7104d57009c6e036bf4ae29c35fb2 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 7 Mar 2011 01:03:30 +0000 Subject: Remove the AST printer (-ast-print-xml), which is too incomplete and too low-level to actually be useful but is just interesting enough for people to try to use it (which won't actually work beyond toy examples). To bring back the AST printer, it needs to be: - Complete, covering all of C/C++/Objective-C - Documented, with appropriate Schema against which we can validate the output - Designed for C/C++/Objective-C, not Clang's specific ASTs - Stable across Clang versions - Well-tested git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127141 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/DeclXML.cpp | 183 ----------------------------------------------- 1 file changed, 183 deletions(-) delete mode 100644 lib/Frontend/DeclXML.cpp (limited to 'lib/Frontend/DeclXML.cpp') diff --git a/lib/Frontend/DeclXML.cpp b/lib/Frontend/DeclXML.cpp deleted file mode 100644 index 8d3d225a4b..0000000000 --- a/lib/Frontend/DeclXML.cpp +++ /dev/null @@ -1,183 +0,0 @@ -//===--- DeclXML.cpp - XML implementation for Decl ASTs -------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the XML document class, which provides the means to -// dump out the AST in a XML form that exposes type details and other fields. -// -//===----------------------------------------------------------------------===// - -#include "clang/Frontend/DocumentXML.h" -#include "clang/AST/DeclVisitor.h" -#include "clang/AST/Expr.h" - -namespace clang { - -//--------------------------------------------------------- -class DocumentXML::DeclPrinter : public DeclVisitor { - DocumentXML& Doc; - - void addSubNodes(FunctionDecl* FD) { - for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { - Visit(FD->getParamDecl(i)); - Doc.toParent(); - } - } - - void addFunctionBody(FunctionDecl* FD) { - if (FD->isThisDeclarationADefinition()) { - Doc.addSubNode("Body"); - Doc.PrintStmt(FD->getBody()); - Doc.toParent(); - } - } - - void addSubNodes(RecordDecl* RD) { - for (RecordDecl::decl_iterator i = RD->decls_begin(), - e = RD->decls_end(); i != e; ++i) { - if (!(*i)->isImplicit()) { - Visit(*i); - Doc.toParent(); - } - } - } - - void addSubNodes(CXXRecordDecl* RD) { - addSubNodes(cast(RD)); - - if (RD->isDefinition()) { - // FIXME: This breaks XML generation - //Doc.addAttribute("num_bases", RD->getNumBases()); - - for (CXXRecordDecl::base_class_iterator - base = RD->bases_begin(), - bend = RD->bases_end(); - base != bend; - ++base) { - Doc.addSubNode("Base"); - Doc.addAttribute("id", base->getType()); - AccessSpecifier as = base->getAccessSpecifierAsWritten(); - const char* as_name = ""; - switch(as) { - case AS_none: as_name = ""; break; - case AS_public: as_name = "public"; break; - case AS_protected: as_name = "protected"; break; - case AS_private: as_name = "private"; break; - } - Doc.addAttributeOptional("access", as_name); - Doc.addAttribute("is_virtual", base->isVirtual()); - Doc.toParent(); - } - } - } - - void addSubNodes(EnumDecl* ED) { - for (EnumDecl::enumerator_iterator i = ED->enumerator_begin(), - e = ED->enumerator_end(); i != e; ++i) { - Visit(*i); - Doc.toParent(); - } - } - - void addSubNodes(EnumConstantDecl* ECD) { - if (ECD->getInitExpr()) - Doc.PrintStmt(ECD->getInitExpr()); - } - - void addSubNodes(FieldDecl* FdD) { - if (FdD->isBitField()) - Doc.PrintStmt(FdD->getBitWidth()); - } - - void addSubNodes(VarDecl* V) { - if (V->getInit()) - Doc.PrintStmt(V->getInit()); - } - - void addSubNodes(ParmVarDecl* argDecl) { - if (argDecl->getDefaultArg()) - Doc.PrintStmt(argDecl->getDefaultArg()); - } - - void addSubNodes(DeclContext* ns) { - - for (DeclContext::decl_iterator - d = ns->decls_begin(), - dend = ns->decls_end(); - d != dend; - ++d) { - Visit(*d); - Doc.toParent(); - } - } - - void addSpecialAttribute(const char* pName, EnumDecl* ED) { - const QualType& enumType = ED->getIntegerType(); - if (!enumType.isNull()) - Doc.addAttribute(pName, enumType); - } - - void addIdAttribute(LinkageSpecDecl* ED) { - Doc.addAttribute("id", ED); - } - - void addIdAttribute(NamedDecl* ND) { - Doc.addAttribute("id", ND); - } - -public: - DeclPrinter(DocumentXML& doc) : Doc(doc) {} - -#define NODE_XML( CLASS, NAME ) \ - void Visit##CLASS(CLASS* T) \ - { \ - Doc.addSubNode(NAME); - -#define ID_ATTRIBUTE_XML addIdAttribute(T); -#define ATTRIBUTE_XML( FN, NAME ) Doc.addAttribute(NAME, T->FN); -#define ATTRIBUTE_OPT_XML( FN, NAME ) Doc.addAttributeOptional(NAME, T->FN); -#define ATTRIBUTE_FILE_LOCATION_XML Doc.addLocation(T->getLocation()); -#define ATTRIBUTE_SPECIAL_XML( FN, NAME ) addSpecialAttribute(NAME, T); - -#define ATTRIBUTE_ENUM_XML( FN, NAME ) \ - { \ - const char* pAttributeName = NAME; \ - const bool optional = false; \ - switch (T->FN) { \ - default: assert(0 && "unknown enum value"); - -#define ATTRIBUTE_ENUM_OPT_XML( FN, NAME ) \ - { \ - const char* pAttributeName = NAME; \ - const bool optional = true; \ - switch (T->FN) { \ - default: assert(0 && "unknown enum value"); - -#define ENUM_XML( VALUE, NAME ) case VALUE: if ((!optional) || NAME[0]) Doc.addAttribute(pAttributeName, NAME); break; -#define END_ENUM_XML } } -#define END_NODE_XML } - -#define SUB_NODE_XML( CLASS ) addSubNodes(T); -#define SUB_NODE_SEQUENCE_XML( CLASS ) addSubNodes(T); -#define SUB_NODE_OPT_XML( CLASS ) addSubNodes(T); - -#define SUB_NODE_FN_BODY_XML addFunctionBody(T); - -#include "clang/Frontend/DeclXML.def" -}; - - -//--------------------------------------------------------- -void DocumentXML::writeDeclToXML(Decl *D) { - DeclPrinter(*this).Visit(D); - toParent(); -} - -//--------------------------------------------------------- -} // NS clang - -- cgit v1.2.3-18-g5258