Skip to content

Commit eab5668

Browse files
committed
project reader: try to simplify code
Align variable names Remove superfluous loops Regroup code
1 parent d1a2203 commit eab5668

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/pygccxml/parser/project_reader.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,7 @@ def __parse_file_by_file(self, files):
321321
self.logger.debug(
322322
"Cache has been flushed in %.1f secs",
323323
(timeit.default_timer() - start_time))
324-
namespaces = []
325-
self.logger.debug("Joining namespaces ...")
326-
for file_nss in namespaces:
327-
namespaces = self._join_top_namespaces(namespaces, file_nss)
328-
self.logger.debug("Joining declarations ...")
329-
for namespace in namespaces:
330-
if isinstance(namespace, pygccxml.declarations.namespace_t):
331-
declarations_joiner.join_declarations(namespace)
324+
namespaces = self.__join_namespaces_and_declarations(namespaces)
332325
leaved_classes = self._join_class_hierarchy(namespaces)
333326
types = self.__declarated_types(namespaces)
334327
self.logger.debug("Relinking declared types ...")
@@ -354,9 +347,14 @@ def __parse_all_at_once(self, files):
354347
'#include "%s" %s' %
355348
(header, os.linesep))
356349
namespaces = self.read_string(''.join(header_content))
357-
namespaces = self._join_top_namespaces(namespaces, [])
350+
return self.__join_namespaces_and_declarations(namespaces)
351+
352+
def __join_namespaces_and_declarations(self, namespaces):
358353
for namespace in namespaces:
359354
if isinstance(namespace, pygccxml.declarations.namespace_t):
355+
self.logger.debug("Joining namespaces ...")
356+
namespace = self._join_top_namespaces(namespace)
357+
self.logger.debug("Joining declarations ...")
360358
declarations_joiner.join_declarations(namespace)
361359
return namespaces
362360

@@ -422,27 +420,27 @@ def read_xml(self, file_configuration):
422420
utils.remove_file_no_raise(xml_file_path, self.__config)
423421

424422
@staticmethod
425-
def _join_top_namespaces(main_ns_list, other_ns_list):
426-
answer = main_ns_list[:]
427-
for other_ns in other_ns_list:
423+
def _join_top_namespaces(namespaces):
424+
answer = namespaces[:]
425+
for namespace in namespaces:
428426
same_name_namespaces = pygccxml.declarations.find_all_declarations(
429427
answer,
430428
decl_type=pygccxml.declarations.namespace_t,
431-
name=other_ns.name,
429+
name=namespace.name,
432430
parent=None, # top-level only
433431
recursive=False
434432
)
435433
if len(same_name_namespaces) == 0:
436-
answer.append(other_ns)
434+
answer.append(namespace)
437435
elif len(same_name_namespaces) == 1:
438-
same_name_namespaces[0].take_parenting(other_ns)
436+
same_name_namespaces[0].take_parenting(namespace)
439437
else:
440438
primary_ns = same_name_namespaces[0]
441439
for extra_ns in same_name_namespaces[1:]:
442440
primary_ns.take_parenting(extra_ns)
443441
answer.remove(extra_ns)
444442
# then unify the new other_ns
445-
primary_ns.take_parenting(other_ns)
443+
primary_ns.take_parenting(namespace)
446444
return answer
447445

448446
@staticmethod

0 commit comments

Comments
 (0)