Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d700434
Make std=c++11 optional
kwabenantim Feb 29, 2024
11cd043
#11 update source_parser
kwabenantim Mar 1, 2024
62c645d
#11 further source parser updates
kwabenantim Mar 2, 2024
47da70a
#11 more source parser updates
kwabenantim Mar 2, 2024
71f2366
#11 Additional source parser updates
kwabenantim Mar 3, 2024
9501ad9
#11 extra source parser updates
kwabenantim Mar 4, 2024
a537581
#11 update generator and source parser
kwabenantim Mar 4, 2024
ea1decf
#11 update generators
kwabenantim Mar 4, 2024
a9ef41d
#11 more generator updates
kwabenantim Mar 4, 2024
90465d6
#11 update header collection writer
kwabenantim Mar 4, 2024
8b6d89b
#11 update package info parser
kwabenantim Mar 4, 2024
dcc0610
#11 Update info classes
kwabenantim Mar 4, 2024
5214376
#11 update info helper
kwabenantim Mar 4, 2024
b497b32
#11 update package info parser
kwabenantim Mar 5, 2024
951e7ad
#11 update package info parser
kwabenantim Mar 5, 2024
04176f9
#11 update module_info and package_info
kwabenantim Mar 5, 2024
eacfc8c
#11 update base_info
kwabenantim Mar 5, 2024
925edc7
#11 update cpp type info
kwabenantim Mar 5, 2024
f789684
#11 fix circular type hint imports
kwabenantim Mar 5, 2024
6812433
#11 more updates to info
kwabenantim Mar 5, 2024
0a9666b
#11 extra info updates
kwabenantim Mar 5, 2024
87aba13
#11 set castxml cflags in generator
kwabenantim Mar 5, 2024
4998896
#11 update cpp type info
kwabenantim Mar 6, 2024
5a85db0
#11 additional info updates
kwabenantim Mar 7, 2024
89c491d
#11 update info helper
kwabenantim Mar 7, 2024
565256d
#11 extra info helper updates
kwabenantim Mar 7, 2024
cdcae0d
#11 update generators
kwabenantim Mar 8, 2024
c196845
#11 update info helper
kwabenantim Mar 8, 2024
9a6ce01
#11 extra info helper updates
kwabenantim Mar 8, 2024
5c56287
#11 update parsers
kwabenantim Mar 9, 2024
b54d956
#11 update generator
kwabenantim Mar 11, 2024
71517ce
#11 update class writer
kwabenantim Mar 11, 2024
07facf0
#11 update writers
kwabenantim Mar 12, 2024
7e14486
#11 update module writer
kwabenantim Mar 13, 2024
7ec9409
#11 update module writer
kwabenantim Mar 13, 2024
7346b00
#11 update base writer
kwabenantim Mar 13, 2024
aa1d347
#11 update PYBIND11_OVERRIDE
kwabenantim Mar 13, 2024
566c530
#11 update free function writer
kwabenantim Mar 14, 2024
560295b
#11 update class writer
kwabenantim Mar 14, 2024
4085e3c
#11 more class writer updates
kwabenantim Mar 14, 2024
c461abb
#11 update class writer
kwabenantim Mar 14, 2024
e66432b
#11 additional class writer updates
kwabenantim Mar 14, 2024
684f58f
#11 minor writer edits
kwabenantim Mar 14, 2024
b0a374d
#11 update class writer registration
kwabenantim Mar 15, 2024
9662c9e
#11 update constructor writer
kwabenantim Mar 15, 2024
56922e0
#11 update method writer
kwabenantim Mar 16, 2024
deb4e8b
#11 update method writer add self
kwabenantim Mar 16, 2024
7ff85ad
#11 update method writer
kwabenantim Mar 17, 2024
d6faa94
#11 update method writer add override
kwabenantim Mar 17, 2024
000e925
#11 update method writer
kwabenantim Mar 17, 2024
d0ad79b
#11 update generator
kwabenantim Mar 18, 2024
641fd87
Merge branch 'ci-testing' into liberate-cxx-standard
kwabenantim Mar 18, 2024
9b2a32a
#11 use Python3.8 compatible type hints
kwabenantim Mar 18, 2024
394312d
#11 fix free_function_info_collection
kwabenantim Mar 18, 2024
d44a4ac
Merge branch 'develop' into liberate-cxx-standard
kwabenantim Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
434 changes: 291 additions & 143 deletions cppwg/generators.py

Large diffs are not rendered by default.

196 changes: 123 additions & 73 deletions cppwg/input/base_info.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,139 @@
"""
Generic information structure for packages, modules and cpp types
"""
from typing import Any, Dict, List, Optional


class BaseInfo(object):

class BaseInfo:
"""
:param: name - the feature name, as it appears in its definition
:param: source_includes - a list of source files to be included with the feature
:param: calldef_excludes - do not include calldefs matching these patterns
:param: smart_ptr_type - handle classes with this smart pointer type
:param: template_substitutions - a list of template substitution sequences
:param: pointer_call_policy - the default pointer call policy
:param: reference_call_policy - the default reference call policy
:param: extra_code - any extra wrapper code for the feature
:param: prefix_code - any wrapper code that precedes the feature
:param: excluded_methods - do not include these methods
:param: excluded_variables - do not include these variables
:param: constructor_arg_type_excludes - list of exlude patterns for ctors
:param: return_type_exludes - list of exlude patterns for return types
:param: arg_type_excludes - list of exlude patterns for arg types
Generic information structure for features (i.e packages, modules, classes,
free functions, etc.)

Attributes
----------
name : str
The feature name, as it appears in its definition.
source_includes : List[str]
A list of source files to be included with the feature.
calldef_excludes : List[str]
Do not include calldefs matching these patterns.
smart_ptr_type : str, optional
Handle classes with this smart pointer type.
template_substitutions : Dict[str, List[Any]]
A list of template substitution sequences.
pointer_call_policy : str, optional
The default pointer call policy.
reference_call_policy : str, optional
The default reference call policy.
extra_code : List[str]
Any extra wrapper code for the feature.
prefix_code : List[str]
Any wrapper code that precedes the feature.
custom_generator : str, optional
A custom generator for the feature.
excluded_methods : List[str]
Do not include these methods.
excluded_variables : List[str]
Do not include these variables.
constructor_arg_type_excludes : List[str]
List of exclude patterns for ctors.
return_type_excludes : List[str]
List of exclude patterns for return types.
arg_type_excludes : List[str]
List of exclude patterns for arg types.
name_replacements : Dict[str, str]
A dictionary of name replacements e.g. {"double":"Double", "unsigned int":"Unsigned"}
"""

def __init__(self, name):

self.name = name
self.source_includes = []
self.calldef_excludes = []
self.smart_ptr_type = None
self.template_substitutions = []
self.pointer_call_policy = None
self.reference_call_policy = None
self.extra_code = []
self.prefix_code = []
self.custom_generator = None
self.excluded_methods = None
self.excluded_variables = None
self.constructor_arg_type_excludes = []
self.return_type_excludes = []
self.arg_type_excludes = []
self.name_replacements = {"double": "Double",
"unsigned int": "Unsigned",
"Unsigned int": "Unsigned",
"unsigned": "Unsigned",
"double": "Double",
"std::vector": "Vector",
"std::pair": "Pair",
"std::map": "Map",
"std::string": "String",
"boost::shared_ptr": "SharedPtr",
"*": "Ptr",
"c_vector": "CVector",
"std::set": "Set"}

self.name: str = name
self.source_includes: List[str] = []
self.calldef_excludes: List[str] = []
self.smart_ptr_type: Optional[str] = None
self.template_substitutions: Dict[str, List[Any]] = []
self.pointer_call_policy: Optional[str] = None
self.reference_call_policy: Optional[str] = None
self.extra_code: List[str] = []
self.prefix_code: List[str] = []
self.custom_generator: Optional[str] = None
self.excluded_methods: List[str] = []
self.excluded_variables: List[str] = []
self.constructor_arg_type_excludes: List[str] = []
self.return_type_excludes: List[str] = []
self.arg_type_excludes: List[str] = []
self.name_replacements: Dict[str, str] = {
"double": "Double",
"unsigned int": "Unsigned",
"Unsigned int": "Unsigned",
"unsigned": "Unsigned",
"double": "Double",
"std::vector": "Vector",
"std::pair": "Pair",
"std::map": "Map",
"std::string": "String",
"boost::shared_ptr": "SharedPtr",
"*": "Ptr",
"c_vector": "CVector",
"std::set": "Set",
}

@property
def parent(self):
def parent(self) -> Optional["BaseInfo"]:
"""
Return the parent object of the feature in the hierarchy. This is
overriden in subclasses e.g. ModuleInfo returns a PackageInfo, ClassInfo
returns a ModuleInfo, etc.

Returns
-------
Optional[BaseInfo]
The parent object.
"""
return None

def hierarchy_attribute(self, attribute_name):


def hierarchy_attribute(self, attribute_name: str) -> Any:
"""
For the supplied attribute iterate through parents until a non None
value is found. If the tope level parent attribute is None, return None.
For the supplied attribute, iterate through parent objects until a non-None
value is found. If the top level parent (i.e. package) attribute is
None, return None.

Parameters
----------
attribute_name : str
The attribute name to search for.

Returns
-------
Any
The attribute value.
"""

if hasattr(self, attribute_name) and getattr(self, attribute_name) is not None:
return getattr(self, attribute_name)
else:
if hasattr(self, 'parent') and self.parent is not None:
return self.parent.hierarchy_attribute(attribute_name)
else:
return None

def hierarchy_attribute_gather(self, attribute_name):


if hasattr(self, "parent") and self.parent is not None:
return self.parent.hierarchy_attribute(attribute_name)

return None

def hierarchy_attribute_gather(self, attribute_name: str) -> List[Any]:
"""
For the supplied attribute iterate through parents gathering list entries.
For the supplied attribute, iterate through parent objects gathering list entries.

Parameters
----------
attribute_name : str
The attribute name to search for.

Returns
-------
List[Any]
The list of attribute values.
"""

att_list = []

att_list: List[Any] = []

if hasattr(self, attribute_name) and getattr(self, attribute_name) is not None:
att_list.extend(getattr(self, attribute_name))
if hasattr(self, 'parent') and self.parent is not None:
att_list.extend(self.parent.hierarchy_attribute_gather(attribute_name))
else:
if hasattr(self, 'parent') and self.parent is not None:
att_list.extend(self.parent.hierarchy_attribute_gather(attribute_name))
return att_list

if hasattr(self, "parent") and self.parent is not None:
att_list.extend(self.parent.hierarchy_attribute_gather(attribute_name))

return att_list
23 changes: 13 additions & 10 deletions cppwg/input/class_info.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""
Information structure common to C++ classes
"""
from typing import Any, Dict, Optional

from cppwg.input import cpp_type_info
from cppwg.input.cpp_type_info import CppTypeInfo


class CppClassInfo(cpp_type_info.CppTypeInfo):
class CppClassInfo(CppTypeInfo):
"""
This class holds information for individual C++ classes to be wrapped
"""

def __init__(self, name: str, class_config: Optional[Dict[str, Any]] = None):

super(CppClassInfo, self).__init__(name, class_config)

def __init__(self, name, type_info_dict = None):

super(CppClassInfo, self).__init__(name, type_info_dict)

@property
def parent(self):
def parent(self) -> "ModuleInfo":
"""
Returns the parent module info object
"""
return self.module_info
Loading