diff options
author | Ole Troan <ot@cisco.com> | 2019-04-30 10:04:36 +0200 |
---|---|---|
committer | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2019-06-07 10:38:35 +0000 |
commit | 85465588b18fef9c4712f864f512e00741e2d4f2 (patch) | |
tree | d5914b37782edfa7d85a2366e080ca97bc7ece1f /src/tools/vppapigen/vppapigen.py | |
parent | 8dbfb433619011b649b1b511ad88969a7f909861 (diff) |
API: Add support for "defaults"
Add support in the API language for specifying a field default.
Add default support in Python binding.
define foo {
u16 mtu [default = 1500];
};
This is client side only. I.e. if the mtu argument is not passed to the foo function,
the client language binding will set it default to 1500.
Change-Id: I5df43f3cd87cb300b40ca38e15dcab25b40e424a
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/tools/vppapigen/vppapigen.py')
-rwxr-xr-x | src/tools/vppapigen/vppapigen.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py index c60e43e8ed3..fd87b18792b 100755 --- a/src/tools/vppapigen/vppapigen.py +++ b/src/tools/vppapigen/vppapigen.py @@ -509,18 +509,31 @@ class VPPAPIParser(object): else: p[0] = p[1] + def p_field_options(self, p): + '''field_options : field_option + | field_options field_option''' + if len(p) == 2: + p[0] = p[1] + else: + p[0] = { **p[1], **p[2] } + + def p_field_option(self, p): + '''field_option : ID '=' assignee ',' + | ID '=' assignee + ''' + p[0] = { p[1]: p[3] } + def p_declaration(self, p): '''declaration : type_specifier ID ';' - | type_specifier ID '[' ID '=' assignee ']' ';' ''' - if len(p) == 9: - p[0] = Field(p[1], p[2], {p[4]: p[6]}) + | type_specifier ID '[' field_options ']' ';' ''' + if len(p) == 7: + p[0] = Field(p[1], p[2], p[4]) elif len(p) == 4: p[0] = Field(p[1], p[2]) else: self._parse_error('ERROR') self.fields.append(p[2]) - def p_declaration_array(self, p): '''declaration : type_specifier ID '[' NUM ']' ';' | type_specifier ID '[' ID ']' ';' ''' |