vppapigen: list imports in JSON
[vpp.git] / src / tools / vppapigen / vppapigen_json.py
index 124c0d3..35dcbca 100644 (file)
@@ -1,6 +1,12 @@
 # JSON generation
 import json
 
+def walk_imports(s):
+    r = []
+    for e in s:
+        r.append(str(e))
+    return r
+
 
 def walk_enums(s):
     r = []
@@ -26,12 +32,14 @@ def walk_services(s):
     return r
 
 
-def walk_defs(s, is_message = False):
+def walk_defs(s, is_message=False):
     r = []
     for t in s:
         d = []
         d.append(t.name)
         for b in t.block:
+            if b.type == 'Option':
+                continue
             if b.type == 'Field':
                 if b.limit:
                     d.append([b.fieldtype, b.fieldname, b.limit])
@@ -39,7 +47,8 @@ def walk_defs(s, is_message = False):
                     d.append([b.fieldtype, b.fieldname])
             elif b.type == 'Array':
                 if b.lengthfield:
-                    d.append([b.fieldtype, b.fieldname, b.length, b.lengthfield])
+                    d.append([b.fieldtype, b.fieldname,
+                              b.length, b.lengthfield])
                 else:
                     d.append([b.fieldtype, b.fieldname, b.length])
             elif b.type == 'Union':
@@ -55,19 +64,22 @@ def walk_defs(s, is_message = False):
         r.append(d)
     return r
 
-
 #
 # Plugin entry point
 #
-def run(filename, s):
+def run(args, filename, s):
     j = {}
 
-    j['types'] = walk_defs([o for o in s['types'] if o.__class__.__name__ == 'Typedef'])
+    j['types'] = (walk_defs([o for o in s['types']
+                             if o.__class__.__name__ == 'Typedef']))
     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['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['options'] = s['Option']
-    j['aliases'] = s['Alias']
+    j['aliases'] = {o.name:o.alias for o in s['types'] if o.__class__.__name__ == 'Using'}
     j['vl_api_version'] = hex(s['file_crc'])
+    j['imports'] = walk_imports(i for i in s['Import'])
     return json.dumps(j, indent=4, separators=(',', ': '))