diff options
author | Ole Troan <ot@cisco.com> | 2019-04-23 17:11:01 +0200 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2019-04-29 12:07:02 +0000 |
commit | 9ac113815511f3ce37b56a1331d6491fc36f7db5 (patch) | |
tree | 574f66ce291ee75de2545a051be77a11bbaa43e2 /src/tools/vppapigen/vppapigen.py | |
parent | de146e5d5f7e919b423feeff3159c4ecd564c353 (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/vppapigen/vppapigen.py')
-rwxr-xr-x | src/tools/vppapigen/vppapigen.py | 16 |
1 files changed, 11 insertions, 5 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 ']' ';' |