From 4036d255ab698632bb5414b1417e9107b2f62df7 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 4 Mar 2014 14:26:54 -0500 Subject: Output: Generate Enumeration elements Implement the OutputEnumDecl method to generate the Enumeration element. Report the name="", context="", and location="" of the declaration. Inside the Enumeration element generate EnumValue elements describing the enumeration names and initializers. Also map enum types to the corresponding declarations. --- src/Output.cxx | 30 +++++++++++++++++++++++ test/CMakeLists.txt | 2 ++ test/expect/gccxml.Enumeration-xml.txt | 9 +++++++ test/expect/gccxml.Typedef-to-Enumeration-xml.txt | 7 ++++++ test/input/Enumeration.cxx | 4 +++ test/input/Typedef-to-Enumeration.cxx | 2 ++ 6 files changed, 54 insertions(+) create mode 100644 test/expect/gccxml.Enumeration-xml.txt create mode 100644 test/expect/gccxml.Typedef-to-Enumeration-xml.txt create mode 100644 test/input/Enumeration.cxx create mode 100644 test/input/Typedef-to-Enumeration.cxx diff --git a/src/Output.cxx b/src/Output.cxx index 4643203..99ef36c 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -290,6 +290,7 @@ class ASTVisitor: public ASTVisitorBase void OutputClassTemplateSpecializationDecl( clang::ClassTemplateSpecializationDecl const* d, DumpNode const* dn); void OutputTypedefDecl(clang::TypedefDecl const* d, DumpNode const* dn); + void OutputEnumDecl(clang::EnumDecl const* d, DumpNode const* dn); void OutputFieldDecl(clang::FieldDecl const* d, DumpNode const* dn); void OutputVarDecl(clang::VarDecl const* d, DumpNode const* dn); @@ -396,6 +397,9 @@ unsigned int ASTVisitor::AddDumpNode(DumpType dt, bool complete) { case clang::Type::Elaborated: return this->AddDumpNode(DumpType( t->getAs()->getNamedType(), c), complete); + case clang::Type::Enum: + return this->AddDumpNode(t->getAs()->getDecl(), + complete); case clang::Type::Paren: return this->AddDumpNode(DumpType( t->getAs()->getInnerType(), c), complete); @@ -1049,6 +1053,32 @@ void ASTVisitor::OutputTypedefDecl(clang::TypedefDecl const* d, } //---------------------------------------------------------------------------- +void ASTVisitor::OutputEnumDecl(clang::EnumDecl const* d, DumpNode const* dn) +{ + this->OS << " PrintIdAttribute(dn); + this->PrintNameAttribute(d->getName().str()); + this->PrintContextAttribute(d); + this->PrintLocationAttribute(d); + clang::EnumDecl::enumerator_iterator enum_begin = d->enumerator_begin(); + clang::EnumDecl::enumerator_iterator enum_end = d->enumerator_end(); + if(enum_begin != enum_end) { + this->OS << ">\n"; + for(clang::EnumDecl::enumerator_iterator i = enum_begin; + i != enum_end; ++i) { + clang::EnumConstantDecl const* ecd = *i; + this->OS << " PrintNameAttribute(ecd->getName()); + this->OS << " init=\"" << ecd->getInitVal() << "\""; + this->OS << "/>\n"; + } + this->OS << " \n"; + } else { + this->OS << "/>\n"; + } +} + +//---------------------------------------------------------------------------- void ASTVisitor::OutputFieldDecl(clang::FieldDecl const* d, DumpNode const* dn) { this->OS << " +]*> + + + + + + +$ diff --git a/test/expect/gccxml.Typedef-to-Enumeration-xml.txt b/test/expect/gccxml.Typedef-to-Enumeration-xml.txt new file mode 100644 index 0000000..1e8ec8f --- /dev/null +++ b/test/expect/gccxml.Typedef-to-Enumeration-xml.txt @@ -0,0 +1,7 @@ +^<\?xml version="1.0"\?> +]*> + + + + +$ diff --git a/test/input/Enumeration.cxx b/test/input/Enumeration.cxx new file mode 100644 index 0000000..1cdd25c --- /dev/null +++ b/test/input/Enumeration.cxx @@ -0,0 +1,4 @@ +enum start { + ev0, + ev2 = 2 +}; diff --git a/test/input/Typedef-to-Enumeration.cxx b/test/input/Typedef-to-Enumeration.cxx new file mode 100644 index 0000000..9a1db81 --- /dev/null +++ b/test/input/Typedef-to-Enumeration.cxx @@ -0,0 +1,2 @@ +enum E {}; +typedef E start; -- cgit v0.12