API: Add support for limits to language.
[vpp.git] / src / tools / vppapigen / vppapigen.py
index 431a9dc..ae2b0b1 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
 
 from __future__ import print_function
 import ply.lex as lex
@@ -165,10 +165,10 @@ class Using():
         self.name = name
 
         if isinstance(alias, Array):
-            a = { 'type': alias.fieldtype,
-                  'length': alias.length }
+            a = { 'type': alias.fieldtype,  # noqa: E201
+                  'length': alias.length }  # noqa: E202
         else:
-            a = { 'type': alias.fieldtype }
+            a = { 'type': alias.fieldtype }  # noqa: E201,E202
         self.alias = a
         self.crc = binascii.crc32(str(alias).encode()) & 0xffffffff
         global_crc = binascii.crc32(str(alias).encode(), global_crc)
@@ -298,10 +298,11 @@ class Array():
 
 
 class Field():
-    def __init__(self, fieldtype, name):
+    def __init__(self, fieldtype, name, limit=None):
         self.type = 'Field'
         self.fieldtype = fieldtype
         self.fieldname = name
+        self.limit = limit
 
     def __repr__(self):
         return str([self.fieldtype, self.fieldname])
@@ -504,7 +505,7 @@ class VPPAPIParser(object):
 
     def p_enum_statements(self, p):
         '''enum_statements : enum_statement
-                            | enum_statements enum_statement'''
+                           | enum_statements enum_statement'''
         if len(p) == 2:
             p[0] = [p[1]]
         else:
@@ -519,11 +520,16 @@ class VPPAPIParser(object):
             p[0] = p[1]
 
     def p_declaration(self, p):
-        '''declaration : type_specifier ID ';' '''
-        if len(p) != 4:
+        '''declaration : type_specifier ID ';'
+                       | type_specifier ID '[' ID '=' assignee ']' ';' '''
+        if len(p) == 9:
+            p[0] = Field(p[1], p[2], {p[4]: p[6]})
+        elif len(p) == 4:
+            p[0] = Field(p[1], p[2])
+        else:
             self._parse_error('ERROR')
         self.fields.append(p[2])
-        p[0] = Field(p[1], p[2])
+
 
     def p_declaration_array(self, p):
         '''declaration : type_specifier ID '[' NUM ']' ';'
@@ -820,7 +826,7 @@ def main():
     #
     # Generate representation
     #
-    import imp
+    from importlib.machinery import SourceFileLoader
 
     # Default path
     pluginpath = ''
@@ -843,7 +849,8 @@ def main():
                                              args.output_module.lower())
 
     try:
-        plugin = imp.load_source(args.output_module, module_path)
+        plugin = SourceFileLoader(args.output_module,
+                                  module_path).load_module()
     except Exception as err:
         raise Exception('Error importing output plugin: {}, {}'
                         .format(module_path, err))