X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Ftools%2Fvppapigen%2Fvppapigen.py;h=ae2b0b1ba40c5496e947f358bbcc7b7237f91112;hb=9ac113815;hp=431a9dc7f939177b086f0beadf788ff0893056e2;hpb=7e0c48e3a941ce874361b442a02624e586db810b;p=vpp.git diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py index 431a9dc7f93..ae2b0b1ba40 100755 --- a/src/tools/vppapigen/vppapigen.py +++ b/src/tools/vppapigen/vppapigen.py @@ -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))