summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-03-18 18:27:56 (GMT)
committerBrad King <brad.king@kitware.com>2014-03-24 15:37:20 (GMT)
commit906edbb74f1a4687a759e354b3e52212a724d6ba (patch)
tree398c7557b7db362336035a0931e0c6ef0e5cb975
parentf78a3ef51eee06aabb83581c3cdc049bb8737eaf (diff)
downloadCastXML-906edbb74f1a4687a759e354b3e52212a724d6ba.zip
CastXML-906edbb74f1a4687a759e354b3e52212a724d6ba.tar.gz
CastXML-906edbb74f1a4687a759e354b3e52212a724d6ba.tar.bz2
Output: Use typedef name for anonymous enum
When an enum has no name but does have a typedef, use the typedef name.
-rw-r--r--src/Output.cxx8
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/expect/gccxml.Enumeration-anonymous-xml.txt10
-rw-r--r--test/expect/gccxml.Typedef-to-Enumeration-anonymous-xml.txt7
-rw-r--r--test/input/Enumeration-anonymous.cxx6
-rw-r--r--test/input/Typedef-to-Enumeration-anonymous.cxx2
6 files changed, 34 insertions, 1 deletions
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 << " <Enumeration";
this->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"\?>
+<GCC_XML[^>]*>
+ <Namespace id="_1" name="start" context="_2" members="_3"/>
+ <Enumeration id="_3" name="" context="_1" location="f1:2" file="f1" line="2">
+ <EnumValue name="ev0" init="0"/>
+ <EnumValue name="ev1" init="1"/>
+ </Enumeration>
+ <Namespace id="_2" name="::"/>
+ <File id="f1" name=".*/test/input/Enumeration-anonymous.cxx"/>
+</GCC_XML>$
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"\?>
+<GCC_XML[^>]*>
+ <Typedef id="_1" name="start" type="_2" context="_3" location="f1:2" file="f1" line="2"/>
+ <Enumeration id="_2" name="start" context="_3" location="f1:1" file="f1" line="1"/>
+ <Namespace id="_3" name="::"/>
+ <File id="f1" name=".*/test/input/Typedef-to-Enumeration-anonymous.cxx"/>
+</GCC_XML>$
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;