Skip to content

Commit 9096895

Browse files
committed
Support for schemas using TYPE definitions to redeclare BINARY types
1 parent 82143f2 commit 9096895

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

src/ifcexpressparser/mapping.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def flatten_type(self, type):
5252
def simple_type_parent(self, type):
5353
parent = self.schema.types[type].type.type
5454
if isinstance(parent, nodes.AggregationType): parent = None
55-
return None if parent in self.express_to_cpp_typemapping else parent
55+
return None if str(parent) in self.express_to_cpp_typemapping else parent
5656

5757
def make_type_string(self, type):
58-
if isinstance(type, str):
59-
return self.express_to_cpp_typemapping.get(type, type)
58+
if isinstance(type, (str, nodes.BinaryType)):
59+
return self.express_to_cpp_typemapping.get(str(type), type)
6060
else:
6161
is_list = self.schema.is_entity(type.type)
6262
is_nested_list = isinstance(type.type, nodes.AggregationType)
@@ -83,12 +83,8 @@ def make_argument_entity(self, attr):
8383

8484
def make_argument_type(self, attr):
8585
def _make_argument_type(type):
86-
if type in self.express_to_cpp_typemapping:
87-
return self.express_to_cpp_typemapping.get(type, type).split('::')[-1].upper()
88-
elif self.schema.is_entity(type) or isinstance(type, nodes.SelectType):
86+
if self.schema.is_entity(type) or isinstance(type, nodes.SelectType):
8987
return "ENTITY_INSTANCE"
90-
elif self.schema.is_type(type):
91-
return _make_argument_type(self.schema.types[type].type.type)
9288
elif isinstance(type, nodes.BinaryType):
9389
return "BINARY"
9490
elif isinstance(type, nodes.EnumerationType):
@@ -97,17 +93,21 @@ def _make_argument_type(type):
9793
ty = _make_argument_type(type.type)
9894
if ty == "UNKNOWN": return "UNKNOWN"
9995
return "AGGREGATE_OF_" + ty
96+
elif str(type) in self.express_to_cpp_typemapping:
97+
return self.express_to_cpp_typemapping.get(str(type), type).split('::')[-1].upper()
98+
elif self.schema.is_type(type):
99+
return _make_argument_type(self.schema.types[type].type.type)
100100
else:
101101
raise ValueError("Unable to map type %r for attribute %r" % (type, attr))
102102
ty = _make_argument_type(attr.type if hasattr(attr, 'type') else attr)
103103
if ty not in self.supported_argument_types:
104-
print("Attribute %r mapped as 'unknown'" % (type, attr), file=sys.stderr)
104+
print("Attribute %r mapped as 'unknown'" % (attr), file=sys.stderr)
105105
ty = 'UNKNOWN'
106106
return "IfcUtil::Argument_%s" % ty
107107

108108
def get_type_dep(self, type):
109109
if isinstance(type, str):
110-
return self.express_to_cpp_typemapping.get(type, type)
110+
return self.express_to_cpp_typemapping.get(str(type), type)
111111
else:
112112
return self.get_type_dep(type.type)
113113

@@ -124,7 +124,7 @@ def get_parameter_type(self, attr, allow_optional, allow_entities, allow_pointer
124124
ty = self.get_parameter_type(attr_type.type if is_nested_list else attr_type, False, allow_entities, False)
125125
if self.schema.is_select(attr_type.type):
126126
type_str = templates.untyped_list
127-
elif self.schema.is_simpletype(ty) or ty in self.express_to_cpp_typemapping.values():
127+
elif self.schema.is_simpletype(ty) or str(ty) in self.express_to_cpp_typemapping.values():
128128
tmpl = templates.nested_array_type if is_nested_list else templates.array_type
129129
type_str = tmpl % {
130130
'instance_type' : ty,

src/ifcexpressparser/schema.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222

2323
class Schema:
2424
def is_enumeration(self, v):
25-
return v in self.enumerations
25+
return str(v) in self.enumerations
2626
def is_select(self, v):
27-
return v in self.selects
27+
return str(v) in self.selects
2828
def is_simpletype(self, v):
29-
return v in self.simpletypes
29+
return str(v) in self.simpletypes
3030
def is_type(self, v):
31-
return v in self.types
31+
return str(v) in self.types
3232
def is_entity(self, v):
33-
return v in self.entities
33+
return str(v) in self.entities
3434
def __init__(self, parsetree):
3535
self.name = parsetree[1]
3636

@@ -43,4 +43,4 @@ def __init__(self, parsetree):
4343

4444
self.enumerations = of_type(nodes.EnumerationType)
4545
self.selects = of_type(nodes.SelectType)
46-
self.simpletypes = of_type(str, nodes.AggregationType)
46+
self.simpletypes = of_type(str, nodes.AggregationType, nodes.BinaryType)

0 commit comments

Comments
 (0)