From 95c7a3dea54a7c23bf5fd3a9a7fd5adfe1f45414 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 18 Mar 2014 11:40:57 -0400 Subject: Output: Fix output of forward-declared classes When adding a dump node for a class, use the class definition, if available, instead of the canonical declaration. They may not be the same when a class is forward-declared before it is defined. We need to use the definition to get all members. --- src/Output.cxx | 11 +++++++++-- test/CMakeLists.txt | 1 + test/expect/gccxml.Class-forward-xml.txt | 17 +++++++++++++++++ test/input/Class-forward.cxx | 8 ++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 test/expect/gccxml.Class-forward-xml.txt create mode 100644 test/input/Class-forward.cxx diff --git a/src/Output.cxx b/src/Output.cxx index c24c451..856a79b 100644 --- a/src/Output.cxx +++ b/src/Output.cxx @@ -380,6 +380,14 @@ public: //---------------------------------------------------------------------------- unsigned int ASTVisitor::AddDumpNode(clang::Decl const* d, bool complete) { + // Select the definition or canonical declaration. + d = d->getCanonicalDecl(); + if(clang::RecordDecl const* rd = clang::dyn_cast(d)) { + if(clang::RecordDecl const* rdd = rd->getDefinition()) { + d = rdd; + } + } + // Replace some decls with those they reference. switch (d->getKind()) { case clang::Decl::UsingShadow: @@ -390,8 +398,7 @@ unsigned int ASTVisitor::AddDumpNode(clang::Decl const* d, bool complete) { break; } - // Add the node for the canonical declaration instance. - return this->AddDumpNodeImpl(d->getCanonicalDecl(), complete); + return this->AddDumpNodeImpl(d, complete); } //---------------------------------------------------------------------------- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fb279cd..5bca07d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -83,6 +83,7 @@ castxml_test_gccxml(ArrayType-incomplete) castxml_test_gccxml(Class) castxml_test_gccxml(Class-abstract) castxml_test_gccxml(Class-bases) +castxml_test_gccxml(Class-forward) castxml_test_gccxml(Class-friends) castxml_test_gccxml(Class-incomplete) castxml_test_gccxml(Class-member-template) diff --git a/test/expect/gccxml.Class-forward-xml.txt b/test/expect/gccxml.Class-forward-xml.txt new file mode 100644 index 0000000..6d8f463 --- /dev/null +++ b/test/expect/gccxml.Class-forward-xml.txt @@ -0,0 +1,17 @@ +^<\?xml version="1.0"\?> +]*> + + + + + + + + + + + + + + +$ diff --git a/test/input/Class-forward.cxx b/test/input/Class-forward.cxx new file mode 100644 index 0000000..38374b6 --- /dev/null +++ b/test/input/Class-forward.cxx @@ -0,0 +1,8 @@ +class start; +class start { +public: + start(); + start(start const&); + start& operator=(start const&); + ~start(); +}; -- cgit v0.12