Skip to content

Commit d862595

Browse files
committed
fix: test new fix
1 parent b318730 commit d862595

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/pygccxml/parser/project_reader.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,12 @@ def __parse_all_at_once(self, files):
353353
header_content.append(
354354
'#include "%s" %s' %
355355
(header, os.linesep))
356-
return self.read_string(''.join(header_content))
356+
declarations = self.read_string(''.join(header_content))
357+
declarations = self._join_top_namespaces(declarations, [])
358+
for ns in declarations:
359+
if isinstance(ns, pygccxml.declarations.namespace_t):
360+
declarations_joiner.join_declarations(ns)
361+
return declarations
357362

358363
def read_string(self, content):
359364
"""Parse a string containing C/C++ source code.
@@ -419,20 +424,25 @@ def read_xml(self, file_configuration):
419424
@staticmethod
420425
def _join_top_namespaces(main_ns_list, other_ns_list):
421426
answer = main_ns_list[:]
422-
for n in main_ns_list:
423-
print("_join_top_namespaces", n, n.name)
424-
print("--------------")
425427
for other_ns in other_ns_list:
426-
print("_join_top_namespaces", other_ns, other_ns.name)
427-
main_ns = pygccxml.declarations.find_declaration(
428+
same_name_namespaces = pygccxml.declarations.find_all_declarations(
428429
answer,
429430
decl_type=pygccxml.declarations.namespace_t,
430-
name=other_ns._name,
431-
recursive=False)
432-
if main_ns:
433-
main_ns.take_parenting(other_ns)
434-
else:
431+
name=other_ns.name,
432+
parent=None, # top-level only
433+
recursive=False
434+
)
435+
if len(same_name_namespaces) == 0:
435436
answer.append(other_ns)
437+
elif len(same_name_namespaces) == 1:
438+
same_name_namespaces[0].take_parenting(other_ns)
439+
else:
440+
primary_ns = same_name_namespaces[0]
441+
for extra_ns in same_name_namespaces[1:]:
442+
primary_ns.take_parenting(extra_ns)
443+
answer.remove(extra_ns)
444+
# then unify the new other_ns
445+
primary_ns.take_parenting(other_ns)
436446
return answer
437447

438448
@staticmethod

tests/test_core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,14 @@ def global_ns(request):
222222
@pytest.mark.parametrize(
223223
"global_ns",
224224
[
225-
# "global_ns_fixture_all_at_once1",
226-
# "global_ns_fixture_all_at_once2",
225+
"global_ns_fixture_all_at_once1",
226+
"global_ns_fixture_all_at_once2",
227227
"global_ns_fixture_file_by_file1",
228-
# "global_ns_fixture_file_by_file2",
228+
"global_ns_fixture_file_by_file2",
229229
],
230230
indirect=True,
231231
)
232232
def test_mangled_name_namespace(global_ns):
233233
std = global_ns.namespace("std")
234234
assert std is not None
235235
assert std.mangled is None
236-
raise

0 commit comments

Comments
 (0)