From 5fa3f0b7ca518d0cfb4fd9341e386796cd00389a Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Sun, 22 Sep 2024 14:13:04 +0000 Subject: [PATCH] #12 Simplify info updates from source and ns --- cppwg/generators.py | 22 ++++------------------ cppwg/input/class_info.py | 9 +++++++-- cppwg/input/module_info.py | 9 +++++++-- cppwg/input/package_info.py | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/cppwg/generators.py b/cppwg/generators.py index b1e304b..b32c999 100644 --- a/cppwg/generators.py +++ b/cppwg/generators.py @@ -227,20 +227,6 @@ def parse_package_info(self) -> None: # If no package info file exists, create a PackageInfo object with default settings self.package_info = PackageInfo("cppwg_package", self.source_root) - def update_modules_from_ns(self) -> None: - """ - Update modules with information from the parsed source namespace. - """ - for module_info in self.package_info.module_info_collection: - module_info.update_from_ns(self.source_ns) - - def update_modules_from_source(self) -> None: - """ - Update modules with information from the source headers. - """ - for module_info in self.package_info.module_info_collection: - module_info.update_from_source(self.package_info.source_hpp_files) - def write_header_collection(self) -> None: """ Write the header collection to file. @@ -274,8 +260,8 @@ def generate_wrappers(self) -> None: # Collect header files, skipping wrappers to avoid pollution self.package_info.collect_source_headers(restricted_paths=[self.wrapper_root]) - # Update modules with information from the source headers - self.update_modules_from_source() + # Update info objects with data from the source headers + self.package_info.update_from_source() # Write the header collection file self.write_header_collection() @@ -283,8 +269,8 @@ def generate_wrappers(self) -> None: # Parse the headers with pygccxml (+ castxml) self.parse_headers() - # Update modules with information from the parsed source namespace - self.update_modules_from_ns() + # Update info objects with data from the parsed source namespace + self.package_info.update_from_ns(self.source_ns) # Log list of unknown classes in the source root self.log_unknown_classes() diff --git a/cppwg/input/class_info.py b/cppwg/input/class_info.py index 61587ae..531d6fb 100644 --- a/cppwg/input/class_info.py +++ b/cppwg/input/class_info.py @@ -216,16 +216,21 @@ def update_from_ns(self, source_ns: "namespace_t") -> None: # noqa: F821 base.related_class for decl in self.decls for base in decl.bases ] - def update_from_source(self, source_files: List[str]) -> None: + def update_from_source(self, source_file_paths: List[str]) -> None: """ Update class with information from the source headers. + + Parameters + ---------- + source_file_paths : List[str] + A list of source file paths """ # Skip excluded classes if self.excluded: return # Map class to a source file, assuming the file name is the class name - for file_path in source_files: + for file_path in source_file_paths: file_name = os.path.basename(file_path) if self.name == os.path.splitext(file_name)[0]: self.source_file_full_path = file_path diff --git a/cppwg/input/module_info.py b/cppwg/input/module_info.py index f0b0b28..2746cf9 100644 --- a/cppwg/input/module_info.py +++ b/cppwg/input/module_info.py @@ -162,9 +162,14 @@ def update_from_ns(self, source_ns: "namespace_t") -> None: # noqa: F821 for ff_info in self.free_function_info_collection: ff_info.update_from_ns(source_ns) - def update_from_source(self, source_files: List[str]) -> None: + def update_from_source(self, source_file_paths: List[str]) -> None: """ Update module with information from the source headers. + + Parameters + ---------- + source_files : List[str] + A list of source file paths. """ for class_info in self.class_info_collection: - class_info.update_from_source(source_files) + class_info.update_from_source(source_file_paths) diff --git a/cppwg/input/package_info.py b/cppwg/input/package_info.py index 0d26547..f90f24a 100644 --- a/cppwg/input/package_info.py +++ b/cppwg/input/package_info.py @@ -110,3 +110,22 @@ def collect_source_headers(self, restricted_paths: List[str]) -> None: if not self.source_hpp_files: logger.error(f"No header files found in source root: {self.source_root}") raise FileNotFoundError() + + def update_from_source(self) -> None: + """ + Update modules with information from the source headers. + """ + for module_info in self.module_info_collection: + module_info.update_from_source(self.source_hpp_files) + + def update_from_ns(self, source_ns: "namespace_t") -> None: # noqa: F821 + """ + Update modules with information from the parsed source namespace. + + Parameters + ---------- + source_ns : pygccxml.declarations.namespace_t + The source namespace + """ + for module_info in self.module_info_collection: + module_info.update_from_ns(source_ns)