diff options
author | Brad King <brad.king@kitware.com> | 2014-03-18 15:40:57 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-03-24 15:37:20 (GMT) |
commit | 95c7a3dea54a7c23bf5fd3a9a7fd5adfe1f45414 (patch) | |
tree | 6712ab58b1ff81fea60c51a9df2e9ea2fca7db5e | |
parent | fbc3aa539f7db36f949daeb37472b807d48e03c9 (diff) | |
download | CastXML-95c7a3dea54a7c23bf5fd3a9a7fd5adfe1f45414.zip CastXML-95c7a3dea54a7c23bf5fd3a9a7fd5adfe1f45414.tar.gz CastXML-95c7a3dea54a7c23bf5fd3a9a7fd5adfe1f45414.tar.bz2 |
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.
-rw-r--r-- | src/Output.cxx | 11 | ||||
-rw-r--r-- | test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | test/expect/gccxml.Class-forward-xml.txt | 17 | ||||
-rw-r--r-- | test/input/Class-forward.cxx | 8 |
4 files changed, 35 insertions, 2 deletions
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<clang::RecordDecl>(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"\?> +<GCC_XML[^>]*> + <Class id="_1" name="start" context="_2" location="f1:2" file="f1" line="2" members="_3 _4 _5 _6"/> + <Constructor id="_3" name="start" context="_1" access="public" location="f1:4" file="f1" line="4"/> + <Constructor id="_4" name="start" context="_1" access="public" location="f1:5" file="f1" line="5"> + <Argument type="_7" location="f1:5" file="f1" line="5"/> + </Constructor> + <OperatorMethod id="_5" name="=" returns="_8" context="_1" access="public" location="f1:6" file="f1" line="6"> + <Argument type="_7" location="f1:6" file="f1" line="6"/> + </OperatorMethod> + <Destructor id="_6" name="start" context="_1" access="public" location="f1:7" file="f1" line="7"/> + <ReferenceType id="_7" type="_1c"/> + <ReferenceType id="_8" type="_1"/> + <Namespace id="_2" name="::"/> + <CvQualifiedType id="_1c" type="_1" const="1"/> + <File id="f1" name=".*/test/input/Class-forward.cxx"/> +</GCC_XML>$ 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(); +}; |