summaryrefslogtreecommitdiffstats
path: root/src/tools
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
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')
-rwxr-xr-xsrc/tools/vppapigen/vppapigen.py29
-rw-r--r--src/tools/vppapigen/vppapigen_c.py13
-rw-r--r--src/tools/vppapigen/vppapigen_json.py1
3 files changed, 40 insertions, 3 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)
diff --git a/src/tools/vppapigen/vppapigen_c.py b/src/tools/vppapigen/vppapigen_c.py
index b56e0722122..2a66ff3159e 100644
--- a/src/tools/vppapigen/vppapigen_c.py
+++ b/src/tools/vppapigen/vppapigen_c.py
@@ -94,7 +94,7 @@ def duplicate_wrapper_tail():
return '#endif\n\n'
-def typedefs(objs, filename):
+def typedefs(objs, aliases, filename):
name = filename.replace('.', '_')
output = '''\
@@ -106,6 +106,15 @@ def typedefs(objs, filename):
#define included_{module}
'''
output = output.format(module=name)
+
+ for k, v in aliases.items():
+ output += duplicate_wrapper_head(k)
+ if 'length' in v:
+ output += 'typedef %s vl_api_%s_t[%s];\n' % (v['type'], k, v['length'])
+ else:
+ output += 'typedef %s vl_api_%s_t;\n' % (v['type'], k)
+ output += duplicate_wrapper_tail()
+
for o in objs:
tname = o.__class__.__name__
output += duplicate_wrapper_head(o.name)
@@ -276,7 +285,7 @@ def run(input_filename, s, file_crc):
output += msg_ids(s)
output += msg_names(s)
output += msg_name_crc_list(s, filename)
- output += typedefs(s['types'] + s['Define'], filename + file_extension)
+ output += typedefs(s['types'] + s['Define'], s['Alias'], filename + file_extension)
output += printfun(s['types'] + s['Define'])
output += endianfun(s['types'] + s['Define'])
output += version_tuple(s, basename)
diff --git a/src/tools/vppapigen/vppapigen_json.py b/src/tools/vppapigen/vppapigen_json.py
index 2991bec57ac..b57e16c990d 100644
--- a/src/tools/vppapigen/vppapigen_json.py
+++ b/src/tools/vppapigen/vppapigen_json.py
@@ -65,5 +65,6 @@ def run(filename, s, file_crc):
j['unions'] = walk_defs([o for o in s['types'] if o.__class__.__name__ == 'Union'])
j['enums'] = walk_enums([o for o in s['types'] if o.__class__.__name__ == 'Enum'])
j['services'] = walk_services(s['Service'])
+ j['aliases'] = s['Alias']
j['vl_api_version'] = hex(file_crc)
return json.dumps(j, indent=4, separators=(',', ': '))