[cfe-commits] r103412 - in /cfe/trunk: include/clang/Frontend/DeclXML.def include/clang/Frontend/DocumentXML.h include/clang/Frontend/TypeXML.def lib/Frontend/DeclXML.cpp lib/Frontend/DocumentXML.cpp
Douglas Gregor
dgregor at apple.com
Mon May 10 10:43:18 PDT 2010
Author: dgregor
Date: Mon May 10 12:43:18 2010
New Revision: 103412
URL: http://llvm.org/viewvc/llvm-project?rev=103412&view=rev
Log:
Improved -ast-print-xml for C++, from Sebastien Binet!
Modified:
cfe/trunk/include/clang/Frontend/DeclXML.def
cfe/trunk/include/clang/Frontend/DocumentXML.h
cfe/trunk/include/clang/Frontend/TypeXML.def
cfe/trunk/lib/Frontend/DeclXML.cpp
cfe/trunk/lib/Frontend/DocumentXML.cpp
Modified: cfe/trunk/include/clang/Frontend/DeclXML.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/DeclXML.def?rev=103412&r1=103411&r2=103412&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/DeclXML.def (original)
+++ cfe/trunk/include/clang/Frontend/DeclXML.def Mon May 10 12:43:18 2010
@@ -84,6 +84,7 @@
NODE_XML(Decl, "FIXME_Decl")
ATTRIBUTE_FILE_LOCATION_XML
+ ATTRIBUTE_XML(getDeclKindName(), "unhandled_decl_name")
END_NODE_XML
NODE_XML(FunctionDecl, "Function")
@@ -106,7 +107,7 @@
SUB_NODE_FN_BODY_XML
END_NODE_XML
-NODE_XML(CXXMethodDecl, "CXXMethodDecl")
+NODE_XML(CXXMethodDecl, "CXXMethod")
ID_ATTRIBUTE_XML
ATTRIBUTE_FILE_LOCATION_XML
ATTRIBUTE_XML(getDeclContext(), "context")
@@ -116,6 +117,79 @@
ATTRIBUTE_OPT_XML(isInlineSpecified(), "inline")
ATTRIBUTE_OPT_XML(isStatic(), "static")
ATTRIBUTE_OPT_XML(isVirtual(), "virtual")
+ ATTRIBUTE_ENUM_OPT_XML(getAccess(), "access")
+ ENUM_XML(AS_none, "")
+ ENUM_XML(AS_public, "public")
+ ENUM_XML(AS_protected, "protected")
+ ENUM_XML(AS_private, "private")
+ END_ENUM_XML
+ ATTRIBUTE_XML(getNumParams(), "num_args")
+ SUB_NODE_SEQUENCE_XML(ParmVarDecl)
+ SUB_NODE_FN_BODY_XML
+END_NODE_XML
+
+NODE_XML(CXXConstructorDecl, "CXXConstructor")
+ ID_ATTRIBUTE_XML
+ ATTRIBUTE_FILE_LOCATION_XML
+ ATTRIBUTE_XML(getDeclContext(), "context")
+ ATTRIBUTE_XML(getNameAsString(), "name")
+ TYPE_ATTRIBUTE_XML(getType()->getAs<FunctionType>()->getResultType())
+ ATTRIBUTE_XML(getType()->getAs<FunctionType>(), "function_type")
+ ATTRIBUTE_OPT_XML(isExplicit(), "is_explicit")
+ ATTRIBUTE_OPT_XML(isDefaultConstructor(), "is_default_ctor")
+ ATTRIBUTE_OPT_XML(isCopyConstructor(), "is_copy_ctor")
+ ATTRIBUTE_OPT_XML(isInlineSpecified(), "inline")
+ ATTRIBUTE_OPT_XML(isStatic(), "static")
+ ATTRIBUTE_OPT_XML(isVirtual(), "virtual")
+ ATTRIBUTE_ENUM_OPT_XML(getAccess(), "access")
+ ENUM_XML(AS_none, "")
+ ENUM_XML(AS_public, "public")
+ ENUM_XML(AS_protected, "protected")
+ ENUM_XML(AS_private, "private")
+ END_ENUM_XML
+ ATTRIBUTE_XML(getNumParams(), "num_args")
+ SUB_NODE_SEQUENCE_XML(ParmVarDecl)
+ SUB_NODE_FN_BODY_XML
+END_NODE_XML
+
+NODE_XML(CXXDestructorDecl, "CXXDestructor")
+ ID_ATTRIBUTE_XML
+ ATTRIBUTE_FILE_LOCATION_XML
+ ATTRIBUTE_XML(getDeclContext(), "context")
+ ATTRIBUTE_XML(getNameAsString(), "name")
+ TYPE_ATTRIBUTE_XML(getType()->getAs<FunctionType>()->getResultType())
+ ATTRIBUTE_XML(getType()->getAs<FunctionType>(), "function_type")
+ ATTRIBUTE_OPT_XML(isInlineSpecified(), "inline")
+ ATTRIBUTE_OPT_XML(isStatic(), "static")
+ ATTRIBUTE_OPT_XML(isVirtual(), "virtual")
+ ATTRIBUTE_ENUM_OPT_XML(getAccess(), "access")
+ ENUM_XML(AS_none, "")
+ ENUM_XML(AS_public, "public")
+ ENUM_XML(AS_protected, "protected")
+ ENUM_XML(AS_private, "private")
+ END_ENUM_XML
+ ATTRIBUTE_XML(getNumParams(), "num_args")
+ SUB_NODE_SEQUENCE_XML(ParmVarDecl)
+ SUB_NODE_FN_BODY_XML
+END_NODE_XML
+
+NODE_XML(CXXConversionDecl, "CXXConversion")
+ ID_ATTRIBUTE_XML
+ ATTRIBUTE_FILE_LOCATION_XML
+ ATTRIBUTE_XML(getDeclContext(), "context")
+ ATTRIBUTE_XML(getNameAsString(), "name")
+ TYPE_ATTRIBUTE_XML(getType()->getAs<FunctionType>()->getResultType())
+ ATTRIBUTE_XML(getType()->getAs<FunctionType>(), "function_type")
+ ATTRIBUTE_OPT_XML(isExplicit(), "is_explicit")
+ ATTRIBUTE_OPT_XML(isInlineSpecified(), "inline")
+ ATTRIBUTE_OPT_XML(isStatic(), "static")
+ ATTRIBUTE_OPT_XML(isVirtual(), "virtual")
+ ATTRIBUTE_ENUM_OPT_XML(getAccess(), "access")
+ ENUM_XML(AS_none, "")
+ ENUM_XML(AS_public, "public")
+ ENUM_XML(AS_protected, "protected")
+ ENUM_XML(AS_private, "private")
+ END_ENUM_XML
ATTRIBUTE_XML(getNumParams(), "num_args")
SUB_NODE_SEQUENCE_XML(ParmVarDecl)
SUB_NODE_FN_BODY_XML
@@ -126,6 +200,7 @@
ATTRIBUTE_FILE_LOCATION_XML
ATTRIBUTE_XML(getDeclContext(), "context")
ATTRIBUTE_XML(getNameAsString(), "name")
+ SUB_NODE_SEQUENCE_XML(DeclContext)
END_NODE_XML
NODE_XML(UsingDirectiveDecl, "UsingDirective")
@@ -189,6 +264,12 @@
ATTRIBUTE_XML(getNameAsString(), "name")
TYPE_ATTRIBUTE_XML(getType())
ATTRIBUTE_OPT_XML(isMutable(), "mutable")
+ ATTRIBUTE_ENUM_OPT_XML(getAccess(), "access")
+ ENUM_XML(AS_none, "")
+ ENUM_XML(AS_public, "public")
+ ENUM_XML(AS_protected, "protected")
+ ENUM_XML(AS_private, "private")
+ END_ENUM_XML
ATTRIBUTE_OPT_XML(isBitField(), "bitfield")
SUB_NODE_OPT_XML(Expr) // init expr of a bit field
END_NODE_XML
@@ -237,6 +318,35 @@
END_ENUM_XML
END_NODE_XML
+NODE_XML(TemplateDecl, "Template")
+ ID_ATTRIBUTE_XML
+ ATTRIBUTE_FILE_LOCATION_XML
+ ATTRIBUTE_XML(getDeclContext(), "context")
+ ATTRIBUTE_XML(getNameAsString(), "name")
+END_NODE_XML
+
+NODE_XML(TemplateTypeParmDecl, "TemplateTypeParm")
+ ID_ATTRIBUTE_XML
+ ATTRIBUTE_FILE_LOCATION_XML
+ ATTRIBUTE_XML(getDeclContext(), "context")
+ ATTRIBUTE_XML(getNameAsString(), "name")
+END_NODE_XML
+
+NODE_XML(UsingShadowDecl, "UsingShadow")
+ ID_ATTRIBUTE_XML
+ ATTRIBUTE_FILE_LOCATION_XML
+ ATTRIBUTE_XML(getDeclContext(), "context")
+ ATTRIBUTE_XML(getTargetDecl(), "target_decl")
+ ATTRIBUTE_XML(getUsingDecl(), "using_decl")
+END_NODE_XML
+
+NODE_XML(UsingDecl, "Using")
+ ID_ATTRIBUTE_XML
+ ATTRIBUTE_FILE_LOCATION_XML
+ ATTRIBUTE_XML(getDeclContext(), "context")
+ ATTRIBUTE_XML(getTargetNestedNameDecl(), "target_nested_namespace_decl")
+ ATTRIBUTE_XML(isTypeName(), "is_typename")
+END_NODE_XML
//===----------------------------------------------------------------------===//
#undef NODE_XML
Modified: cfe/trunk/include/clang/Frontend/DocumentXML.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/DocumentXML.h?rev=103412&r1=103411&r2=103412&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/DocumentXML.h (original)
+++ cfe/trunk/include/clang/Frontend/DocumentXML.h Mon May 10 12:43:18 2010
@@ -114,6 +114,7 @@
void addPtrAttribute(const char* pName, const NamedDecl* D);
void addPtrAttribute(const char* pName, const DeclContext* D);
void addPtrAttribute(const char* pName, const NamespaceDecl* D); // disambiguation
+ void addPtrAttribute(const char* pName, const NestedNameSpecifier* N);
void addPtrAttribute(const char* pName, const LabelStmt* L);
void addPtrAttribute(const char* pName, const char* text);
Modified: cfe/trunk/include/clang/Frontend/TypeXML.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TypeXML.def?rev=103412&r1=103411&r2=103412&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/TypeXML.def (original)
+++ cfe/trunk/include/clang/Frontend/TypeXML.def Mon May 10 12:43:18 2010
@@ -61,6 +61,10 @@
# define CONTEXT_ATTRIBUTE_XML( FN ) ATTRIBUTE_XML(FN, "context")
#endif
+NODE_XML(Type, "FIXME_Type")
+ ID_ATTRIBUTE_XML
+ ATTRIBUTE_XML(getTypeClassName(), "unhandled_type_name")
+END_NODE_XML
NODE_XML(QualType, "CvQualifiedType")
ID_ATTRIBUTE_XML
@@ -242,6 +246,10 @@
TYPE_ATTRIBUTE_XML(getNamedType())
END_NODE_XML
+NODE_XML(InjectedClassNameType, "InjectedClassNameType")
+ ID_ATTRIBUTE_XML
+END_NODE_XML
+
NODE_XML(DependentNameType, "DependentNameType")
ID_ATTRIBUTE_XML
END_NODE_XML
Modified: cfe/trunk/lib/Frontend/DeclXML.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DeclXML.cpp?rev=103412&r1=103411&r2=103412&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DeclXML.cpp (original)
+++ cfe/trunk/lib/Frontend/DeclXML.cpp Mon May 10 12:43:18 2010
@@ -47,11 +47,38 @@
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 @@
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())
Modified: cfe/trunk/lib/Frontend/DocumentXML.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DocumentXML.cpp?rev=103412&r1=103411&r2=103412&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DocumentXML.cpp (original)
+++ cfe/trunk/lib/Frontend/DocumentXML.cpp Mon May 10 12:43:18 2010
@@ -199,6 +199,35 @@
}
//---------------------------------------------------------
+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))
More information about the cfe-commits
mailing list