From 906edbb74f1a4687a759e354b3e52212a724d6ba Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 18 Mar 2014 14:27:56 -0400 Subject: Output: Use typedef name for anonymous enum When an enum has no name but does have a typedef, use the typedef name. --- src/Output.cxx | 8 +++++++- test/CMakeLists.txt | 2 ++ test/expect/gccxml.Enumeration-anonymous-xml.txt | 10 ++++++++++ test/expect/gccxml.Typedef-to-Enumeration-anonymous-xml.txt | 7 +++++++ test/input/Enumeration-anonymous.cxx | 6 ++++++ test/input/Typedef-to-Enumeration-anonymous.cxx | 2 ++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/expect/gccxml.Enumeration-anonymous-xml.txt create mode 100644 test/expect/gccxml.Typedef-to-Enumeration-anonymous-xml.txt create mode 100644 test/input/Enumeration-anonymous.cxx create mode 100644 test/input/Typedef-to-Enumeration-anonymous.cxx diff --git a/src/Output.cxx b/src/Output.cxx index b988560..e3a8ffb 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -1174,7 +1174,13 @@ void ASTVisitor::OutputEnumDecl(clang::EnumDecl const* d, DumpNode const* dn) { this->OS << " PrintIdAttribute(dn); - this->PrintNameAttribute(d->getName().str()); + std::string name = d->getName().str(); + if(name.empty()) { + if(clang::TypedefNameDecl const* td = d->getTypedefNameForAnonDecl()) { + name = td->getName().str(); + } + } + this->PrintNameAttribute(name); this->PrintContextAttribute(d); this->PrintLocationAttribute(d); clang::EnumDecl::enumerator_iterator enum_begin = d->enumerator_begin(); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ec842d2..6fc5cf8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -95,6 +95,7 @@ castxml_test_gccxml(Class-template-bases) castxml_test_gccxml(Class-template-member-template) castxml_test_gccxml(CvQualifiedType) castxml_test_gccxml(Enumeration) +castxml_test_gccxml(Enumeration-anonymous) castxml_test_gccxml(Field) castxml_test_gccxml(Function) castxml_test_gccxml(Function-Argument-default) @@ -118,6 +119,7 @@ castxml_test_gccxml(ReferenceType) castxml_test_gccxml(Typedef-paren) castxml_test_gccxml(Typedef-to-Class-template) castxml_test_gccxml(Typedef-to-Enumeration) +castxml_test_gccxml(Typedef-to-Enumeration-anonymous) castxml_test_gccxml(Variable) castxml_test_gccxml(Variable-in-Class) castxml_test_gccxml(Variable-init) diff --git a/test/expect/gccxml.Enumeration-anonymous-xml.txt b/test/expect/gccxml.Enumeration-anonymous-xml.txt new file mode 100644 index 0000000..385975b --- /dev/null +++ b/test/expect/gccxml.Enumeration-anonymous-xml.txt @@ -0,0 +1,10 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + +$ diff --git a/test/expect/gccxml.Typedef-to-Enumeration-anonymous-xml.txt b/test/expect/gccxml.Typedef-to-Enumeration-anonymous-xml.txt new file mode 100644 index 0000000..bb21d49 --- /dev/null +++ b/test/expect/gccxml.Typedef-to-Enumeration-anonymous-xml.txt @@ -0,0 +1,7 @@ +^<\?xml version="1.0"\?> +]*> + + + + +$ diff --git a/test/input/Enumeration-anonymous.cxx b/test/input/Enumeration-anonymous.cxx new file mode 100644 index 0000000..f1325d1 --- /dev/null +++ b/test/input/Enumeration-anonymous.cxx @@ -0,0 +1,6 @@ +namespace start { + enum { + ev0, + ev1 + }; +} diff --git a/test/input/Typedef-to-Enumeration-anonymous.cxx b/test/input/Typedef-to-Enumeration-anonymous.cxx new file mode 100644 index 0000000..cf5f26f --- /dev/null +++ b/test/input/Typedef-to-Enumeration-anonymous.cxx @@ -0,0 +1,2 @@ +typedef enum { +} start; -- cgit v0.12