Skip to content

Commit

Permalink
#12 Simplify info updates from source and ns
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Sep 22, 2024
1 parent ecb1c2b commit 5fa3f0b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
22 changes: 4 additions & 18 deletions cppwg/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -274,17 +260,17 @@ 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()

# 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()
Expand Down
9 changes: 7 additions & 2 deletions cppwg/input/class_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions cppwg/input/module_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 19 additions & 0 deletions cppwg/input/package_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 5fa3f0b

Please sign in to comment.