aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/vapi/vapi_json_parser.py
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-11-13 12:36:56 +0100
committerFlorin Coras <florin.coras@gmail.com>2018-11-29 07:39:22 +0000
commit53fffa1db7cb04982db8977acd61b808ef60d5a8 (patch)
tree7f8c8b25b51d722cc6353c028ddad4e0ad6fcd31 /src/vpp-api/vapi/vapi_json_parser.py
parent4f10db317382832068d67b5d19be4a696d80c19a (diff)
API: Add support for type aliases
Previously all types are compound. This adds support for aliases, so one can do things like: typedef u32 interface_index; or typedef u8 ip4_address[4]; Change-Id: I0455cad0123fc88acb491d2a3ea2725426bdb246 Signed-off-by: Ole Troan <ot@cisco.com> 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.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/vpp-api/vapi/vapi_json_parser.py b/src/vpp-api/vapi/vapi_json_parser.py
index 39acca0b538..3eb5d3616e1 100644
--- a/src/vpp-api/vapi/vapi_json_parser.py
+++ b/src/vpp-api/vapi/vapi_json_parser.py
@@ -45,6 +45,10 @@ class Field(object):
return self.is_vla() or self.type.has_vla()
+class Alias(Field):
+ pass
+
+
class Type(object):
def __init__(self, name):
self.name = name
@@ -55,12 +59,6 @@ class Type(object):
class SimpleType (Type):
- def __init__(self, name):
- super(SimpleType, self).__init__(name)
-
- def __str__(self):
- return self.name
-
def has_vla(self):
return False
@@ -290,11 +288,12 @@ class JsonParser(object):
def __init__(self, logger, files, simple_type_class=SimpleType,
enum_class=Enum, union_class=Union,
struct_type_class=StructType, field_class=Field,
- message_class=Message):
+ message_class=Message, alias_class=Alias):
self.services = {}
self.messages = {}
self.enums = {}
self.unions = {}
+ self.aliases = {}
self.types = {
x: simple_type_class(x) for x in [
'i8', 'i16', 'i32', 'i64',
@@ -310,6 +309,7 @@ class JsonParser(object):
self.union_class = union_class
self.struct_type_class = struct_type_class
self.field_class = field_class
+ self.alias_class = alias_class
self.message_class = message_class
self.exceptions = []
@@ -317,6 +317,7 @@ class JsonParser(object):
self.types_by_json = {}
self.enums_by_json = {}
self.unions_by_json = {}
+ self.aliases_by_json = {}
self.messages_by_json = {}
self.logger = logger
for f in files:
@@ -329,6 +330,7 @@ class JsonParser(object):
self.types_by_json[path] = []
self.enums_by_json[path] = []
self.unions_by_json[path] = []
+ self.aliases_by_json[path] = []
self.messages_by_json[path] = {}
with open(path) as f:
j = json.load(f)
@@ -369,6 +371,19 @@ class JsonParser(object):
self.unions[union.name] = union
self.logger.debug("Parsed union: %s" % union)
self.unions_by_json[path].append(union)
+ for name, body in j['aliases'].iteritems():
+ if name in self.aliases:
+ progress = progress + 1
+ continue
+ if 'length' in body:
+ array_len = body['length']
+ else:
+ array_len = None
+ t = self.types[body['type']]
+ alias = self.alias_class(name, t, array_len)
+ self.aliases[name] = alias
+ self.logger.debug("Parsed alias: %s" % alias)
+ self.aliases_by_json[path].append(alias)
for t in j['types']:
if t[0] in self.types:
progress = progress + 1
@@ -429,12 +444,16 @@ class JsonParser(object):
return self.enums[name]
elif name in self.unions:
return self.unions[name]
+ elif name in self.aliases:
+ return self.aliases[name]
elif mundane_name in self.types:
return self.types[mundane_name]
elif mundane_name in self.enums:
return self.enums[mundane_name]
elif mundane_name in self.unions:
return self.unions[mundane_name]
+ elif mundane_name in self.aliases:
+ return self.aliases[mundane_name]
raise ParseError(
"Could not find type, enum or union by magic name `%s' nor by "
"mundane name `%s'" % (name, mundane_name))