summaryrefslogtreecommitdiffstats
path: root/src/tools/vppapigen/vppapigen.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/vppapigen/vppapigen.py')
-rwxr-xr-xsrc/tools/vppapigen/vppapigen.py69
1 files changed, 34 insertions, 35 deletions
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py
index c5304db834c..79f2da91b19 100755
--- a/src/tools/vppapigen/vppapigen.py
+++ b/src/tools/vppapigen/vppapigen.py
@@ -127,6 +127,33 @@ def crc_block_combine(block, crc):
return binascii.crc32(s, crc) & 0xffffffff
+def vla_is_last_check(name, block):
+ vla = False
+ for i, b in enumerate(block):
+ if isinstance(b, Array) and b.vla:
+ vla = True
+ if i + 1 < len(block):
+ raise ValueError(
+ 'VLA field "{}" must be the last field in message "{}"'
+ .format(b.fieldname, name))
+ elif b.fieldtype.startswith('vl_api_'):
+ if global_types[b.fieldtype].vla:
+ vla = True
+ if i + 1 < len(block):
+ raise ValueError(
+ 'VLA field "{}" must be the last '
+ 'field in message "{}"'
+ .format(b.fieldname, name))
+ elif b.fieldtype == 'string' and b.length == 0:
+ vla = True
+ if i + 1 < len(block):
+ raise ValueError(
+ 'VLA field "{}" must be the last '
+ 'field in message "{}"'
+ .format(b.fieldname, name))
+ return vla
+
+
class Service():
def __init__(self, caller, reply, events=None, stream=False):
self.caller = caller
@@ -148,26 +175,10 @@ class Typedef():
self.manual_print = True
elif f == 'manual_endian':
self.manual_endian = True
- global_type_add(name, self)
- self.vla = False
+ global_type_add(name, self)
- for i, b in enumerate(block):
- if isinstance(b, Array):
- if b.length == 0:
- self.vla = True
- if i + 1 < len(block):
- raise ValueError(
- 'VLA field "{}" must be the last '
- 'field in message "{}"'
- .format(b.fieldname, name))
- elif b.fieldtype == 'string':
- self.vla = True
- if i + 1 < len(block):
- raise ValueError(
- 'VLA field "{}" must be the last '
- 'field in message "{}"'
- .format(b.fieldname, name))
+ self.vla = vla_is_last_check(name, block)
def __repr__(self):
return self.name + str(self.flags) + str(self.block)
@@ -200,8 +211,11 @@ class Union():
self.manual_print = False
self.manual_endian = False
self.name = name
+
self.block = block
self.crc = str(block).encode()
+ self.vla = vla_is_last_check(name, block)
+
global_type_add(name, self)
def __repr__(self):
@@ -229,28 +243,13 @@ class Define():
elif f == 'autoreply':
self.autoreply = True
- for i, b in enumerate(block):
+ for b in block:
if isinstance(b, Option):
if b[1] == 'singular' and b[2] == 'true':
self.singular = True
block.remove(b)
- if isinstance(b, Array) and b.vla and i + 1 < len(block):
- raise ValueError(
- 'VLA field "{}" must be the last field in message "{}"'
- .format(b.fieldname, name))
- elif b.fieldtype.startswith('vl_api_'):
- if (global_types[b.fieldtype].vla and i + 1 < len(block)):
- raise ValueError(
- 'VLA field "{}" must be the last '
- 'field in message "{}"'
- .format(b.fieldname, name))
- elif b.fieldtype == 'string' and b.length == 0:
- if i + 1 < len(block):
- raise ValueError(
- 'VLA field "{}" must be the last '
- 'field in message "{}"'
- .format(b.fieldname, name))
+ self.vla = vla_is_last_check(name, block)
def __repr__(self):
return self.name + str(self.flags) + str(self.block)