From 9ac113815511f3ce37b56a1331d6491fc36f7db5 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Tue, 23 Apr 2019 17:11:01 +0200 Subject: 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 --- src/tools/vppapigen/vppapigen.py | 16 +++++++++++----- src/tools/vppapigen/vppapigen_json.py | 5 ++++- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'src/tools/vppapigen') 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]) -- cgit 1.2.3-korg