From 44b2a79924734d5dc5ff1c7afeea4efb30ac6b54 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 12 Feb 2014 16:21:01 -0500 Subject: Output: Generate Class, Struct, and Union elements Implement the OutputRecordDecl and OutputCXXRecordDecl methods to generate Class, Struct, and Union elements. Report the name="", context="", location="", incomplete="", and members="" of the declaration. Queue its members. Also map record types to the corresponding declarations. --- src/Output.cxx | 42 +++++++++++++++++++++++++++++ test/CMakeLists.txt | 2 ++ test/expect/gccxml.Class-incomplete-xml.txt | 6 +++++ test/expect/gccxml.Class-xml.txt | 6 +++++ test/input/Class-incomplete.cxx | 1 + test/input/Class.cxx | 1 + 6 files changed, 58 insertions(+) create mode 100644 test/expect/gccxml.Class-incomplete-xml.txt create mode 100644 test/expect/gccxml.Class-xml.txt create mode 100644 test/input/Class-incomplete.cxx create mode 100644 test/input/Class.cxx diff --git a/src/Output.cxx b/src/Output.cxx index 59e8279..bd0ac07 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -211,6 +211,8 @@ class ASTVisitor: public ASTVisitorBase void OutputTranslationUnitDecl(clang::TranslationUnitDecl const* d, DumpNode const* dn); void OutputNamespaceDecl(clang::NamespaceDecl const* d, DumpNode const* dn); + void OutputRecordDecl(clang::RecordDecl const* d, DumpNode const* dn); + void OutputCXXRecordDecl(clang::CXXRecordDecl const* d, DumpNode const* dn); void OutputTypedefDecl(clang::TypedefDecl const* d, DumpNode const* dn); // Type node output methods. @@ -276,6 +278,9 @@ unsigned int ASTVisitor::AddDumpNode(clang::QualType t, bool complete) { // Replace some types with their decls. if(!t.hasLocalQualifiers()) { switch (t->getTypeClass()) { + case clang::Type::Record: + return this->AddDumpNode(t->getAs()->getDecl(), + complete); case clang::Type::Typedef: return this->AddDumpNode(t->getAs()->getDecl(), complete); @@ -613,6 +618,43 @@ void ASTVisitor::OutputNamespaceDecl( } //---------------------------------------------------------------------------- +void ASTVisitor::OutputRecordDecl(clang::RecordDecl const* d, + DumpNode const* dn) +{ + const char* tag; + switch (d->getTagKind()) { + case clang::TTK_Class: tag = "Class"; break; + case clang::TTK_Union: tag = "Union"; break; + case clang::TTK_Struct: tag = "Struct"; break; + case clang::TTK_Interface: return; + case clang::TTK_Enum: return; + } + + this->OS << " <" << tag; + this->PrintIdAttribute(dn); + if(!d->isAnonymousStructOrUnion()) { + this->PrintNameAttribute(d->getName().str()); + } + this->PrintContextAttribute(d); + this->PrintLocationAttribute(d); + if(d->getDefinition()) { + if(dn->Complete) { + this->PrintMembersAttribute(d); + } + } else { + this->OS << " incomplete=\"1\""; + } + this->OS << "/>\n"; +} + +//---------------------------------------------------------------------------- +void ASTVisitor::OutputCXXRecordDecl(clang::CXXRecordDecl const* d, + DumpNode const* dn) +{ + this->OutputRecordDecl(d, dn); +} + +//---------------------------------------------------------------------------- void ASTVisitor::OutputTypedefDecl(clang::TypedefDecl const* d, DumpNode const* dn) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5eb89cd..a56f5ef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -51,6 +51,8 @@ castxml_test_cmd(gccxml-twice --castxml-gccxml --castxml-gccxml) castxml_test_cmd(o-missing -o) castxml_test_cmd(start-missing --castxml-start) +castxml_test_gccxml(Class) +castxml_test_gccxml(Class-incomplete) castxml_test_gccxml(CvQualifiedType) castxml_test_gccxml(FundamentalType) castxml_test_gccxml(Namespace) diff --git a/test/expect/gccxml.Class-incomplete-xml.txt b/test/expect/gccxml.Class-incomplete-xml.txt new file mode 100644 index 0000000..62bb502 --- /dev/null +++ b/test/expect/gccxml.Class-incomplete-xml.txt @@ -0,0 +1,6 @@ +^<\?xml version="1.0"\?> +]*> + + + +$ diff --git a/test/expect/gccxml.Class-xml.txt b/test/expect/gccxml.Class-xml.txt new file mode 100644 index 0000000..05028ca --- /dev/null +++ b/test/expect/gccxml.Class-xml.txt @@ -0,0 +1,6 @@ +^<\?xml version="1.0"\?> +]*> + + + +$ diff --git a/test/input/Class-incomplete.cxx b/test/input/Class-incomplete.cxx new file mode 100644 index 0000000..2e739ef --- /dev/null +++ b/test/input/Class-incomplete.cxx @@ -0,0 +1 @@ +class start; diff --git a/test/input/Class.cxx b/test/input/Class.cxx new file mode 100644 index 0000000..92a7e59 --- /dev/null +++ b/test/input/Class.cxx @@ -0,0 +1 @@ +class start {}; -- cgit v0.12