From d1a2203fa2713ca0d54e28df0f40f805e040d5bf Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Thu, 6 Mar 2025 23:56:52 +0100 Subject: [PATCH 1/2] project_reader: clarify variable names --- src/pygccxml/parser/project_reader.py | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/pygccxml/parser/project_reader.py b/src/pygccxml/parser/project_reader.py index a4eaace1..9344dbca 100644 --- a/src/pygccxml/parser/project_reader.py +++ b/src/pygccxml/parser/project_reader.py @@ -321,21 +321,21 @@ def __parse_file_by_file(self, files): self.logger.debug( "Cache has been flushed in %.1f secs", (timeit.default_timer() - start_time)) - answer = [] + namespaces = [] self.logger.debug("Joining namespaces ...") for file_nss in namespaces: - answer = self._join_top_namespaces(answer, file_nss) + namespaces = self._join_top_namespaces(namespaces, file_nss) self.logger.debug("Joining declarations ...") - for ns in answer: - if isinstance(ns, pygccxml.declarations.namespace_t): - declarations_joiner.join_declarations(ns) - leaved_classes = self._join_class_hierarchy(answer) - types = self.__declarated_types(answer) + for namespace in namespaces: + if isinstance(namespace, pygccxml.declarations.namespace_t): + declarations_joiner.join_declarations(namespace) + leaved_classes = self._join_class_hierarchy(namespaces) + types = self.__declarated_types(namespaces) self.logger.debug("Relinking declared types ...") self._relink_declarated_types(leaved_classes, types) declarations_joiner.bind_aliases( - pygccxml.declarations.make_flatten(answer)) - return answer + pygccxml.declarations.make_flatten(namespaces)) + return namespaces def __parse_all_at_once(self, files): config = self.__config.clone() @@ -353,12 +353,12 @@ def __parse_all_at_once(self, files): header_content.append( '#include "%s" %s' % (header, os.linesep)) - declarations = self.read_string(''.join(header_content)) - declarations = self._join_top_namespaces(declarations, []) - for ns in declarations: - if isinstance(ns, pygccxml.declarations.namespace_t): - declarations_joiner.join_declarations(ns) - return declarations + namespaces = self.read_string(''.join(header_content)) + namespaces = self._join_top_namespaces(namespaces, []) + for namespace in namespaces: + if isinstance(namespace, pygccxml.declarations.namespace_t): + declarations_joiner.join_declarations(namespace) + return namespaces def read_string(self, content): """Parse a string containing C/C++ source code. From 44f7c38c095e1d5bbd9b78b874a9da139116f238 Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Fri, 7 Mar 2025 17:44:55 +0100 Subject: [PATCH 2/2] project reader: try to simplify code Align variable names Remove superfluous loops Regroup code --- src/pygccxml/parser/project_reader.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pygccxml/parser/project_reader.py b/src/pygccxml/parser/project_reader.py index 9344dbca..59a7fa1d 100644 --- a/src/pygccxml/parser/project_reader.py +++ b/src/pygccxml/parser/project_reader.py @@ -321,14 +321,9 @@ def __parse_file_by_file(self, files): self.logger.debug( "Cache has been flushed in %.1f secs", (timeit.default_timer() - start_time)) - namespaces = [] - self.logger.debug("Joining namespaces ...") - for file_nss in namespaces: - namespaces = self._join_top_namespaces(namespaces, file_nss) - self.logger.debug("Joining declarations ...") - for namespace in namespaces: - if isinstance(namespace, pygccxml.declarations.namespace_t): - declarations_joiner.join_declarations(namespace) + namespaces = self.__join_namespaces_and_declarations( + namespaces, namespaces + ) leaved_classes = self._join_class_hierarchy(namespaces) types = self.__declarated_types(namespaces) self.logger.debug("Relinking declared types ...") @@ -354,7 +349,14 @@ def __parse_all_at_once(self, files): '#include "%s" %s' % (header, os.linesep)) namespaces = self.read_string(''.join(header_content)) - namespaces = self._join_top_namespaces(namespaces, []) + return self.__join_namespaces_and_declarations( + namespaces, namespaces + ) + + def __join_namespaces_and_declarations(self, main_ns_list, other_ns_list): + self.logger.debug("Joining namespaces ...") + namespaces = self._join_top_namespaces(main_ns_list, other_ns_list) + self.logger.debug("Joining declarations ...") for namespace in namespaces: if isinstance(namespace, pygccxml.declarations.namespace_t): declarations_joiner.join_declarations(namespace)