summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-04-23 17:11:01 +0200
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-04-29 12:07:02 +0000
commit9ac113815511f3ce37b56a1331d6491fc36f7db5 (patch)
tree574f66ce291ee75de2545a051be77a11bbaa43e2 /src/tools
parentde146e5d5f7e919b423feeff3159c4ecd564c353 (diff)
API: Add support for limits to language.
string name [limit = 64]; Meta-data to do argument validation. Change-Id: I1f3e0f09b2d5285224399413d25206f77bd3f4b1 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/tools')
-rwxr-xr-xsrc/tools/vppapigen/vppapigen.py16
-rw-r--r--src/tools/vppapigen/vppapigen_json.py5
2 files changed, 15 insertions, 6 deletions
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py
index c2f221b9e79..ae2b0b1ba40 100755
--- a/src/tools/vppapigen/vppapigen.py
+++ b/src/tools/vppapigen/vppapigen.py
@@ -298,10 +298,11 @@ class Array():
class Field():
- def __init__(self, fieldtype, name):
+ def __init__(self, fieldtype, name, limit=None):
self.type = 'Field'
self.fieldtype = fieldtype
self.fieldname = name
+ self.limit = limit
def __repr__(self):
return str([self.fieldtype, self.fieldname])
@@ -504,7 +505,7 @@ class VPPAPIParser(object):
def p_enum_statements(self, p):
'''enum_statements : enum_statement
- | enum_statements enum_statement'''
+ | enum_statements enum_statement'''
if len(p) == 2:
p[0] = [p[1]]
else:
@@ -519,11 +520,16 @@ class VPPAPIParser(object):
p[0] = p[1]
def p_declaration(self, p):
- '''declaration : type_specifier ID ';' '''
- if len(p) != 4:
+ '''declaration : type_specifier ID ';'
+ | type_specifier ID '[' ID '=' assignee ']' ';' '''
+ if len(p) == 9:
+ p[0] = Field(p[1], p[2], {p[4]: p[6]})
+ elif len(p) == 4:
+ p[0] = Field(p[1], p[2])
+ else:
self._parse_error('ERROR')
self.fields.append(p[2])
- p[0] = Field(p[1], p[2])
+
def p_declaration_array(self, p):
'''declaration : type_specifier ID '[' NUM ']' ';'
diff --git a/src/tools/vppapigen/vppapigen_json.py b/src/tools/vppapigen/vppapigen_json.py
index c563a089949..94a9e19577e 100644
--- a/src/tools/vppapigen/vppapigen_json.py
+++ b/src/tools/vppapigen/vppapigen_json.py
@@ -33,7 +33,10 @@ def walk_defs(s):
d.append(t.name)
for b in t.block:
if b.type == 'Field':
- d.append([b.fieldtype, b.fieldname])
+ if b.limit:
+ d.append([b.fieldtype, b.fieldname, b.limit])
+ else:
+ d.append([b.fieldtype, b.fieldname])
elif b.type == 'Array':
if b.lengthfield:
d.append([b.fieldtype, b.fieldname, b.length, b.lengthfield])