summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-03-23 17:36:21 (GMT)
committerBrad King <brad.king@kitware.com>2015-03-23 17:38:28 (GMT)
commitd687d1d00346d81cf51bc9eb177d1c090b608bbe (patch)
tree2d06ac9366a70de9c4f016f719fbdb7e87c4d9c9
parent94256f359999905034ff0065b2a7627348c35220 (diff)
downloadCastXML-d687d1d00346d81cf51bc9eb177d1c090b608bbe.zip
CastXML-d687d1d00346d81cf51bc9eb177d1c090b608bbe.tar.gz
CastXML-d687d1d00346d81cf51bc9eb177d1c090b608bbe.tar.bz2
Output: Traverse namespace redeclarations
A namespace may be redeclared to add more members: namespace ns { void f1(); } namespace ns { void f2(); } Fix our AST traversal to consider members from all redeclarations of each namespace instead of only the canonical (first) one. Previously we generated members from later redeclarations only if they were referenced from other declarations we happened to encounter. Reported-by: Michka Popoff <michkapopoff@gmail.com>
-rw-r--r--src/Output.cxx6
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/expect/gccxml.any.Namespace-repeat-start.xml.txt9
-rw-r--r--test/expect/gccxml.any.Namespace-repeat.xml.txt10
-rw-r--r--test/input/Namespace-repeat-start.cxx6
-rw-r--r--test/input/Namespace-repeat.cxx8
6 files changed, 40 insertions, 1 deletions
diff --git a/src/Output.cxx b/src/Output.cxx
index 0d4931b..6299cb8 100644
--- a/src/Output.cxx
+++ b/src/Output.cxx
@@ -1239,7 +1239,11 @@ void ASTVisitor::OutputNamespaceDecl(
this->PrintNameAttribute(d->getName().str());
this->PrintContextAttribute(d);
if(dn->Complete) {
- this->PrintMembersAttribute(d);
+ std::set<unsigned int> emitted;
+ for (clang::NamespaceDecl const* r: d->redecls()) {
+ this->AddDeclContextMembers(r, emitted);
+ }
+ this->PrintMembersAttribute(emitted);
}
this->OS << "/>\n";
}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9febe91..aa0a2fa 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -191,6 +191,8 @@ castxml_test_gccxml(Namespace-Class-template-members)
castxml_test_gccxml(Namespace-Function-template-members)
castxml_test_gccxml(Namespace-empty)
castxml_test_gccxml(Namespace-extern-C-members)
+castxml_test_gccxml(Namespace-repeat)
+castxml_test_gccxml(Namespace-repeat-start)
castxml_test_gccxml(OffsetType)
castxml_test_gccxml(OffsetType-cv)
castxml_test_gccxml(OperatorFunction)
diff --git a/test/expect/gccxml.any.Namespace-repeat-start.xml.txt b/test/expect/gccxml.any.Namespace-repeat-start.xml.txt
new file mode 100644
index 0000000..7ead3fe
--- /dev/null
+++ b/test/expect/gccxml.any.Namespace-repeat-start.xml.txt
@@ -0,0 +1,9 @@
+^<\?xml version="1.0"\?>
+<GCC_XML[^>]*>
+ <Namespace id="_1" name="start" context="_2" members="_3 _4"/>
+ <Function id="_3" name="f1" returns="_5" context="_1" location="f1:2" file="f1" line="2"/>
+ <Function id="_4" name="f2" returns="_5" context="_1" location="f1:5" file="f1" line="5"/>
+ <FundamentalType id="_5" name="void"/>
+ <Namespace id="_2" name="::"/>
+ <File id="f1" name=".*/test/input/Namespace-repeat-start.cxx"/>
+</GCC_XML>$
diff --git a/test/expect/gccxml.any.Namespace-repeat.xml.txt b/test/expect/gccxml.any.Namespace-repeat.xml.txt
new file mode 100644
index 0000000..0468c7b
--- /dev/null
+++ b/test/expect/gccxml.any.Namespace-repeat.xml.txt
@@ -0,0 +1,10 @@
+^<\?xml version="1.0"\?>
+<GCC_XML[^>]*>
+ <Namespace id="_1" name="start" context="_2" members="_3"/>
+ <Namespace id="_3" name="ns" context="_1" members="_4 _5"/>
+ <Function id="_4" name="f1" returns="_6" context="_3" location="f1:3" file="f1" line="3"/>
+ <Function id="_5" name="f2" returns="_6" context="_3" location="f1:6" file="f1" line="6"/>
+ <FundamentalType id="_6" name="void"/>
+ <Namespace id="_2" name="::"/>
+ <File id="f1" name=".*/test/input/Namespace-repeat.cxx"/>
+</GCC_XML>$
diff --git a/test/input/Namespace-repeat-start.cxx b/test/input/Namespace-repeat-start.cxx
new file mode 100644
index 0000000..feb9d5c
--- /dev/null
+++ b/test/input/Namespace-repeat-start.cxx
@@ -0,0 +1,6 @@
+namespace start {
+ void f1();
+}
+namespace start {
+ void f2();
+}
diff --git a/test/input/Namespace-repeat.cxx b/test/input/Namespace-repeat.cxx
new file mode 100644
index 0000000..00f3d38
--- /dev/null
+++ b/test/input/Namespace-repeat.cxx
@@ -0,0 +1,8 @@
+namespace start {
+ namespace ns {
+ void f1();
+ }
+ namespace ns {
+ void f2();
+ }
+}