VAPI: Ensure type definitions are generated in same order as .api file.
[vpp.git] / src / vpp-api / vapi / vapi_json_parser.py
index a9186a1..b52b95b 100644 (file)
@@ -195,15 +195,27 @@ class StructType (Type, Struct):
             if len(field) == 1 and 'crc' in field:
                 self.crc = field['crc']
                 continue
-            elif len(field) == 2:
+            field_type = field[0]
+            if field_type in typedict:
+                field_type = typedict[field_type]
+            else:
+                mundane_field_type = remove_magic(field_type)
+                if mundane_field_type in typedict:
+                    field_type = typedict[mundane_field_type]
+                else:
+                    raise ParseError(
+                        "While parsing message `%s': could not find "
+                        "type by magic name `%s' nor by mundane name "
+                        "`%s'" % (name, field_type, mundane_field_type))
+            if len(field) == 2:
                 p = field_class(field_name=field[1],
-                                field_type=typedict[field[0]])
+                                field_type=field_type)
             elif len(field) == 3:
                 if field[2] == 0:
                     raise ParseError("While parsing type `%s': array `%s' has "
                                      "variable length" % (name, field[1]))
                 p = field_class(field_name=field[1],
-                                field_type=typedict[field[0]],
+                                field_type=field_type,
                                 array_len=field[2])
             else:
                 raise ParseError(
@@ -264,7 +276,7 @@ class JsonParser(object):
     def parse_json_file(self, path):
         self.logger.info("Parsing json api file: `%s'" % path)
         self.json_files.append(path)
-        self.types_by_json[path] = {}
+        self.types_by_json[path] = []
         self.messages_by_json[path] = {}
         with open(path) as f:
             j = json.load(f)
@@ -278,7 +290,7 @@ class JsonParser(object):
                     self.exceptions.append(e)
                     continue
                 self.types[type_.name] = type_
-                self.types_by_json[path][type_.name] = type_
+                self.types_by_json[path].append(type_)
                 self.logger.debug("Parsed type: %s" % type_)
             for m in j['messages']:
                 try: