config: prefer using $inherit prop in 2.1
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 11 Mar 2016 18:37:09 +0000 (13:37 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 17 Mar 2016 06:44:25 +0000 (02:44 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
README.md
barectf/config.py
doc/examples/linux-fs-simple/config.yaml
doc/examples/parallella/config.yaml

index 8cf3db93120034984c1a994e16bee7433aa49274..4fe944a12bf64697d2676413146e3908503981bf 100644 (file)
--- a/README.md
+++ b/README.md
@@ -323,7 +323,7 @@ type-aliases:
     class: integer
     size: 64
   clock-int:
-    inherit: uint64
+    $inherit: uint64
     property-mappings:
       - type: clock
         name: my_clock
@@ -388,7 +388,7 @@ streams:
           class: struct
           fields:
             value:
-              inherit: uint16
+              $inherit: uint16
               signed: true
 ```
 
@@ -627,8 +627,8 @@ Type objects represent CTF types.
 
 | 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:
 
@@ -642,7 +642,7 @@ 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:
 
index 84f0a1f56f42e30a7e01c560656ab70e15fd42e6..eb816fbce724b7b378d2137d95fccb2dc832de8b 100644 (file)
@@ -187,12 +187,6 @@ def _get_first_unknown_prop(node, known_props):
         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.
 #
@@ -1207,12 +1201,20 @@ class _YamlConfigParser:
         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',
@@ -1342,7 +1344,7 @@ class _YamlConfigParser:
             # 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',
@@ -1417,7 +1419,7 @@ class _YamlConfigParser:
             # 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',
         ])
@@ -1491,7 +1493,7 @@ class _YamlConfigParser:
             # create string object
             obj = metadata.String()
 
-        unk_prop = _get_first_unknown_type_prop(node, [
+        unk_prop = self._get_first_unknown_type_prop(node, [
             'encoding',
         ])
 
@@ -1519,7 +1521,7 @@ class _YamlConfigParser:
             # 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',
         ])
@@ -1562,7 +1564,7 @@ class _YamlConfigParser:
             # 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',
         ])
@@ -1596,7 +1598,7 @@ class _YamlConfigParser:
             # 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',
         ])
@@ -1647,19 +1649,35 @@ class _YamlConfigParser:
         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:
index 6c0b59c94a29062143505fca685d2e957542a1e9..1d8a87c08e5865c35f28747b2c18e2344c324095 100644 (file)
@@ -14,16 +14,16 @@ metadata:
       class: integer
       size: 64
     int8:
-      inherit: uint8
+      $inherit: uint8
       signed: true
     int16:
-      inherit: int8
+      $inherit: int8
       size: 16
     int32:
-      inherit: int8
+      $inherit: int8
       size: 32
     int64:
-      inherit: int8
+      $inherit: int8
       size: 64
     float:
       class: floating-point
@@ -43,7 +43,7 @@ metadata:
       length: 16
       element-type: byte
     clock-int:
-      inherit: uint64
+      $inherit: uint64
       property-mappings:
         - type: clock
           name: default
@@ -147,37 +147,37 @@ metadata:
             min-align: 8
             fields:
               uint1:
-                inherit: uint8
+                $inherit: uint8
                 size: 1
                 align: 1
               int1:
-                inherit: int8
+                $inherit: int8
                 size: 1
                 align: 1
               uint2:
-                inherit: uint8
+                $inherit: uint8
                 size: 2
                 align: 1
               int3:
-                inherit: int8
+                $inherit: int8
                 size: 3
                 align: 1
               uint4:
-                inherit: uint8
+                $inherit: uint8
                 size: 4
                 align: 1
               int5:
-                inherit: int8
+                $inherit: int8
                 size: 5
                 align: 1
               uint6:
-                inherit: uint8
+                $inherit: uint8
                 size: 6
                 align: 1
               int7:
-                inherit: int8
+                $inherit: int8
                 size: 7
                 align: 1
               uint8:
-                inherit: uint8
+                $inherit: uint8
                 align: 1
index 2ff3bbb5492e68e21633f54656187dcd6b49f1b4..13585a2c375970766a8af9382782b17814ff763a 100644 (file)
@@ -17,16 +17,16 @@ metadata:
       class: integer
       size: 64
     int8:
-      inherit: uint8
+      $inherit: uint8
       signed: true
     int16:
-      inherit: int8
+      $inherit: int8
       size: 16
     int32:
-      inherit: int8
+      $inherit: int8
       size: 32
     int64:
-      inherit: int8
+      $inherit: int8
       size: 64
     float:
       class: floating-point
@@ -46,7 +46,7 @@ metadata:
       length: 16
       element-type: byte
     clock_int:
-      inherit: uint64
+      $inherit: uint64
       property-mappings:
         - type: clock
           name: default
@@ -118,27 +118,27 @@ metadata:
             min-align: 8
             fields:
               uint1:
-                inherit: uint8
+                $inherit: uint8
                 size: 1
                 align: 1
               int1:
-                inherit: int8
+                $inherit: int8
                 size: 1
                 align: 1
               uint2:
-                inherit: uint8
+                $inherit: uint8
                 size: 2
                 align: 1
               int3:
-                inherit: int8
+                $inherit: int8
                 size: 3
                 align: 1
               uint4:
-                inherit: uint8
+                $inherit: uint8
                 size: 4
                 align: 1
               int5:
-                inherit: int8
+                $inherit: int8
                 size: 5
                 align: 1
         string_and_float:
This page took 0.029333 seconds and 4 git commands to generate.