summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/vapi/vapi_json_parser.py
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2018-09-06 19:31:36 +0200
committerNeale Ranns <nranns@cisco.com>2018-09-11 05:58:06 +0000
commit34a962b728158f3596efaec6b45d89d8ea9ab218 (patch)
tree5bc9ab4566b2d1a97783436e852c33a7941c136f /src/vpp-api/vapi/vapi_json_parser.py
parent19b4a4854e3f50855e68c3a51cd7ae44a8210f24 (diff)
vapi: support VLAs in typedefs
Change-Id: I3af3916b68189c2174020e5ecc29a7bc45b25efa Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'src/vpp-api/vapi/vapi_json_parser.py')
-rw-r--r--src/vpp-api/vapi/vapi_json_parser.py37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/vpp-api/vapi/vapi_json_parser.py b/src/vpp-api/vapi/vapi_json_parser.py
index 799542491f6..8728a1a6bc2 100644
--- a/src/vpp-api/vapi/vapi_json_parser.py
+++ b/src/vpp-api/vapi/vapi_json_parser.py
@@ -28,13 +28,21 @@ class Field(object):
def __str__(self):
if self.len is None:
- return "name: %s, type: %s" % (self.name, self.type)
+ return "Field(name: %s, type: %s)" % (self.name, self.type)
elif self.len > 0:
- return "name: %s, type: %s, length: %s" % (self.name, self.type,
- self.len)
+ return "Field(name: %s, type: %s, length: %s)" % (self.name,
+ self.type,
+ self.len)
else:
- return ("name: %s, type: %s, variable length stored in: %s" %
- (self.name, self.type, self.nelem_field))
+ return (
+ "Field(name: %s, type: %s, variable length stored in: %s)" %
+ (self.name, self.type, self.nelem_field))
+
+ def is_vla(self):
+ return self.nelem_field is not None
+
+ def has_vla(self):
+ return self.is_vla() or self.type.has_vla()
class Type(object):
@@ -53,6 +61,9 @@ class SimpleType (Type):
def __str__(self):
return self.name
+ def has_vla(self):
+ return False
+
def get_msg_header_defs(struct_type_class, field_class, json_parser, logger):
return [
@@ -83,6 +94,12 @@ class Struct(object):
def __str__(self):
return "[%s]" % "], [".join([str(f) for f in self.fields])
+ def has_vla(self):
+ for f in self.fields:
+ if f.has_vla():
+ return True
+ return False
+
class Enum(SimpleType):
def __init__(self, name, value_pairs, enumtype):
@@ -110,6 +127,9 @@ class Union(Type):
"], [" .join(["%s %s" % (i, j) for i, j in self.type_pairs])
)
+ def has_vla(self):
+ return False
+
class Message(object):
@@ -190,6 +210,13 @@ class Message(object):
fields.append(p)
self.fields = fields
self.depends = [f.type for f in self.fields]
+ logger.debug("Parsed message: %s" % self)
+
+ def __str__(self):
+ return "Message(%s, [%s], {crc: %s}" % \
+ (self.name,
+ "], [".join([str(f) for f in self.fields]),
+ self.crc)
class StructType (Type, Struct):