class: integer
size: 64
clock-int:
- inherit: uint64
+ $inherit: uint64
property-mappings:
- type: clock
name: my_clock
class: struct
fields:
value:
- inherit: uint16
+ $inherit: uint16
signed: true
```
| Property | Type | Description | Required? | Default value |
|---|---|---|---|---|
-| `class` | String | Type class | Required if `inherit` property is absent | N/A |
-| `inherit` | String | Name of type alias from which to inherit properties | Required if `class` property is absent | N/A |
+| `class` | String | Type class | Required if `$inherit` property is absent | N/A |
+| `$inherit` | String | Name of type alias from which to inherit properties | Required if `class` property is absent | N/A |
The accepted values for the `class` property are:
| `array` | Array/sequence types |
| `var`<br>`variant` | Variant type |
-The `inherit` property accepts the name of any previously defined
+The `$inherit` property accepts the name of any previously defined
type alias. Any propery in a type object that inherits from another
type object overrides the parent properties as follows:
return prop_name
-def _get_first_unknown_type_prop(type_node, known_props):
- kp = known_props + ['inherit', 'class']
-
- return _get_first_unknown_prop(type_node, kp)
-
-
# This validator validates the configured metadata for barectf specific
# needs.
#
mapped_clock = self._clocks[clock_name]
int_obj.property_mappings.append(metadata.PropertyMapping(mapped_clock, prop))
+ def _get_first_unknown_type_prop(self, type_node, known_props):
+ kp = known_props + ['inherit', 'class']
+
+ if self._version >= 201:
+ kp.append('$inherit')
+
+ return _get_first_unknown_prop(type_node, kp)
+
def _create_integer(self, obj, node):
if obj is None:
# create integer object
obj = metadata.Integer()
- unk_prop = _get_first_unknown_type_prop(node, [
+ unk_prop = self._get_first_unknown_type_prop(node, [
'size',
'align',
'signed',
# create floating point number object
obj = metadata.FloatingPoint()
- unk_prop = _get_first_unknown_type_prop(node, [
+ unk_prop = self._get_first_unknown_type_prop(node, [
'size',
'align',
'byte-order',
# create enumeration object
obj = metadata.Enum()
- unk_prop = _get_first_unknown_type_prop(node, [
+ unk_prop = self._get_first_unknown_type_prop(node, [
'value-type',
'members',
])
# create string object
obj = metadata.String()
- unk_prop = _get_first_unknown_type_prop(node, [
+ unk_prop = self._get_first_unknown_type_prop(node, [
'encoding',
])
# create structure object
obj = metadata.Struct()
- unk_prop = _get_first_unknown_type_prop(node, [
+ unk_prop = self._get_first_unknown_type_prop(node, [
'min-align',
'fields',
])
# create array object
obj = metadata.Array()
- unk_prop = _get_first_unknown_type_prop(node, [
+ unk_prop = self._get_first_unknown_type_prop(node, [
'length',
'element-type',
])
# create variant object
obj = metadata.Variant()
- unk_prop = _get_first_unknown_type_prop(node, [
+ unk_prop = self._get_first_unknown_type_prop(node, [
'tag',
'types',
])
if not _is_assoc_array_prop(type_node):
raise ConfigError('type objects must be associative arrays')
- if 'inherit' in type_node and 'class' in type_node:
- raise ConfigError('cannot specify both "inherit" and "class" properties in type object')
+ # inherit:
+ # v2.0: "inherit"
+ # v2.1+: "$inherit"
+ inherit_node = None
+
+ if self._version >= 200:
+ if 'inherit' in type_node:
+ inherit_prop = 'inherit'
+ inherit_node = type_node[inherit_prop]
+
+ if self._version >= 201:
+ if '$inherit' in type_node:
+ if inherit_node is not None:
+ raise ConfigError('cannot specify both "inherit" and "$inherit" properties of type object: prefer "$inherit"')
+
+ inherit_prop = '$inherit'
+ inherit_node = type_node[inherit_prop]
- if 'inherit' in type_node:
- inherit = type_node['inherit']
+ if inherit_node is not None and 'class' in type_node:
+ raise ConfigError('cannot specify both "{}" and "class" properties in type object'.format(inherit_prop))
- if not _is_str_prop(inherit):
- raise ConfigError('"inherit" property of type object must be a string')
+ if inherit_node is not None:
+ if not _is_str_prop(inherit_node):
+ raise ConfigError('"{}" property of type object must be a string'.format(inherit_prop))
- base = self._lookup_type_alias(inherit)
+ base = self._lookup_type_alias(inherit_node)
if base is None:
- raise ConfigError('cannot inherit from type alias "{}": type alias does not exist'.format(inherit))
+ raise ConfigError('cannot inherit from type alias "{}": type alias does not exist at this point'.format(inherit_node))
func = self._type_to_create_type_func[type(base)]
else: