summaryrefslogtreecommitdiffstats
path: root/src/tools/vppapigen/vppapigen.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/tools/vppapigen/vppapigen.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/tools/vppapigen/vppapigen.py')
-rwxr-xr-xsrc/tools/vppapigen/vppapigen.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py
index 9d04ec24cfc..3f882c455e6 100755
--- a/src/tools/vppapigen/vppapigen.py
+++ b/src/tools/vppapigen/vppapigen.py
@@ -151,6 +151,25 @@ class Typedef():
return self.name + str(self.flags) + str(self.block)
+class Using():
+ def __init__(self, name, alias):
+ global global_crc
+ self.name = name
+
+ if isinstance(alias, Array):
+ a = { 'type': alias.fieldtype,
+ 'length': alias.length }
+ else:
+ a = { 'type': alias.fieldtype }
+ self.alias = a
+ self.crc = binascii.crc32(str(alias)) & 0xffffffff
+ global_crc = binascii.crc32(str(alias), global_crc)
+ global_type_add(name)
+
+ def __repr__(self):
+ return self.name + str(self.alias)
+
+
class Union():
def __init__(self, name, block):
self.type = 'Union'
@@ -457,6 +476,10 @@ class VPPAPIParser(object):
'''typedef : TYPEDEF ID '{' block_statements_opt '}' ';' '''
p[0] = Typedef(p[2], [], p[4])
+ def p_typedef_alias(self, p):
+ '''typedef : TYPEDEF declaration '''
+ p[0] = Using(p[2].fieldname, p[2])
+
def p_block_statements_opt(self, p):
'''block_statements_opt : block_statements '''
p[0] = p[1]
@@ -594,6 +617,7 @@ class VPPAPI(object):
s['Service'] = []
s['types'] = []
s['Import'] = []
+ s['Alias'] = {}
for o in objs:
tname = o.__class__.__name__
if isinstance(o, Define):
@@ -608,6 +632,8 @@ class VPPAPI(object):
s['Service'].append(o2)
elif isinstance(o, Enum) or isinstance(o, Typedef) or isinstance(o, Union):
s['types'].append(o)
+ elif isinstance(o, Using):
+ s['Alias'][o.name] = o.alias
else:
if tname not in s:
raise ValueError('Unknown class type: {} {}'.format(tname, o))
@@ -686,7 +712,8 @@ class VPPAPI(object):
if in_import and not (isinstance(o, Enum) or
isinstance(o, Union) or
isinstance(o, Typedef) or
- isinstance(o, Import)):
+ isinstance(o, Import) or
+ isinstance(o, Using)):
continue
if isinstance(o, Import):
self.process_imports(o.result, True, result)