diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-05-10 17:43:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-05-10 17:43:18 +0000 |
commit | e5279cea49708a7dcddb7c36d0cedbfac27ebee0 (patch) | |
tree | c8c5e6adb285415f8d7a770ba08bb7b2d11c4e2f /clang/lib/Frontend | |
parent | c2ae5f546fe5a1d904886b5b0f420c7229f4f4d6 (diff) | |
download | bcm5719-llvm-e5279cea49708a7dcddb7c36d0cedbfac27ebee0.tar.gz bcm5719-llvm-e5279cea49708a7dcddb7c36d0cedbfac27ebee0.zip |
Improved -ast-print-xml for C++, from Sebastien Binet!
llvm-svn: 103412
Diffstat (limited to 'clang/lib/Frontend')
-rw-r--r-- | clang/lib/Frontend/DeclXML.cpp | 47 | ||||
-rw-r--r-- | clang/lib/Frontend/DocumentXML.cpp | 29 |
2 files changed, 72 insertions, 4 deletions
diff --git a/clang/lib/Frontend/DeclXML.cpp b/clang/lib/Frontend/DeclXML.cpp index 8750b1efcab..3ae25f9b7da 100644 --- a/clang/lib/Frontend/DeclXML.cpp +++ b/clang/lib/Frontend/DeclXML.cpp @@ -47,11 +47,38 @@ class DocumentXML::DeclPrinter : public DeclVisitor<DocumentXML::DeclPrinter> { void addSubNodes(CXXRecordDecl* RD) { addSubNodes(cast<RecordDecl>(RD)); - for (CXXRecordDecl::method_iterator i = RD->method_begin(), - e = RD->method_end(); i != e; ++i) { - Visit(*i); - Doc.toParent(); + + if (RD->isDefinition()) { + 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(); + } + + for (CXXRecordDecl::method_iterator i = RD->method_begin(), + e = RD->method_end(); i != e; ++i) { + Visit(*i); + Doc.toParent(); + } + } + } void addSubNodes(EnumDecl* ED) { @@ -82,6 +109,18 @@ class DocumentXML::DeclPrinter : public DeclVisitor<DocumentXML::DeclPrinter> { Doc.PrintStmt(argDecl->getDefaultArg()); } + void addSubNodes(NamespaceDecl* 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()) diff --git a/clang/lib/Frontend/DocumentXML.cpp b/clang/lib/Frontend/DocumentXML.cpp index 0263c30bfd5..894f230216f 100644 --- a/clang/lib/Frontend/DocumentXML.cpp +++ b/clang/lib/Frontend/DocumentXML.cpp @@ -199,6 +199,35 @@ void DocumentXML::addPtrAttribute(const char* pAttributeName, } //--------------------------------------------------------- +void DocumentXML::addPtrAttribute(const char* pAttributeName, + const NestedNameSpecifier* pNNS) { + switch (pNNS->getKind()) { + case NestedNameSpecifier::Identifier: { + IdentifierInfo *ii = pNNS->getAsIdentifier(); + // FIXME how should we handle those ? + addPtrAttribute(pAttributeName, ii->getName().data()); + break; + } + case NestedNameSpecifier::Namespace: { + addPtrAttribute(pAttributeName, pNNS->getAsNamespace()); + break; + } + case NestedNameSpecifier::TypeSpec: { + addPtrAttribute(pAttributeName, pNNS->getAsType()); + break; + } + case NestedNameSpecifier::TypeSpecWithTemplate: { + addPtrAttribute(pAttributeName, pNNS->getAsType()); + break; + } + case NestedNameSpecifier::Global: { + addPtrAttribute(pAttributeName, "::"); + break; + } + } +} + +//--------------------------------------------------------- void DocumentXML::addTypeRecursively(const QualType& pType) { if (addToMap(Types, pType)) |