vppapigen: allow decimal number in NUM token
[vpp.git] / src / tools / vppapigen / vppapigen_json.py
index 2991bec..124c0d3 100644 (file)
@@ -26,26 +26,28 @@ def walk_services(s):
     return r
 
 
-def walk_defs(s):
+def walk_defs(s, is_message = False):
     r = []
     for t in s:
         d = []
         d.append(t.name)
         for b in t.block:
-            f = []
             if b.type == 'Field':
-                f = [b.fieldtype, b.fieldname]
+                if b.limit:
+                    d.append([b.fieldtype, b.fieldname, b.limit])
+                else:
+                    d.append([b.fieldtype, b.fieldname])
             elif b.type == 'Array':
                 if b.lengthfield:
-                    f = [b.fieldtype, b.fieldname, b.length, b.lengthfield]
+                    d.append([b.fieldtype, b.fieldname, b.length, b.lengthfield])
                 else:
-                    f = [b.fieldtype, b.fieldname, b.length]
+                    d.append([b.fieldtype, b.fieldname, b.length])
             elif b.type == 'Union':
-                print('UNION')
+                pass
             else:
                 raise ValueError("Error in processing array type %s" % b)
-            d.append(f)
-        if t.crc:
+
+        if is_message and t.crc:
             c = {}
             c['crc'] = "{0:#0{1}x}".format(t.crc, 10)
             d.append(c)
@@ -57,13 +59,15 @@ def walk_defs(s):
 #
 # Plugin entry point
 #
-def run(filename, s, file_crc):
+def run(filename, s):
     j = {}
 
     j['types'] = walk_defs([o for o in s['types'] if o.__class__.__name__ == 'Typedef'])
-    j['messages'] = walk_defs(s['Define'])
+    j['messages'] = walk_defs(s['Define'], True)
     j['unions'] = walk_defs([o for o in s['types'] if o.__class__.__name__ == 'Union'])
     j['enums'] = walk_enums([o for o in s['types'] if o.__class__.__name__ == 'Enum'])
     j['services'] = walk_services(s['Service'])
-    j['vl_api_version'] = hex(file_crc)
+    j['options'] = s['Option']
+    j['aliases'] = s['Alias']
+    j['vl_api_version'] = hex(s['file_crc'])
     return json.dumps(j, indent=4, separators=(',', ': '))