From 83931b750fc3f56c2aeb8b747d6b51abdbcba697 Mon Sep 17 00:00:00 2001 From: Alex Elder Date: Fri, 1 Oct 2021 18:23:29 -0500 Subject: [PATCH] parser: introduce qmi_package_parse() Rename parse_package() to be qmi_package_parse(), and have it assign the qmi_package pointer internally rather returning it. This makes the function name match the pattern used for all other production rules. The one caller of qmi_package_parse() assumes the package name has been specified. When parsing has completed, check to ensure the package is specified, and only allow it to be specified once. Signed-off-by: Alex Elder Message-Id: <20211001232338.769309-26-elder@linaro.org> Signed-off-by: Bjorn Andersson --- parser.c | 13 ++++++++++--- tests/no_package.qmi | 16 ++++++++++++++++ tests/two_packages.qmi | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/no_package.qmi create mode 100644 tests/two_packages.qmi diff --git a/parser.c b/parser.c index fc40274..bc3454e 100644 --- a/parser.c +++ b/parser.c @@ -315,13 +315,16 @@ static void token_expect(enum token_id token_id, struct token *tok) } } -static const char *parse_package() +static void qmi_package_parse(void) { struct token tok; token_expect(TOK_ID, &tok); token_expect(';', NULL); - return tok.str; + + if (qmi_package) + yyerror("package may only be specified once"); + qmi_package = tok.str; } static void qmi_const_parse() @@ -482,7 +485,7 @@ void qmi_parse(void) token_init(); while (!token_accept(TOK_EOF, NULL)) { if (token_accept(TOK_PACKAGE, NULL)) { - qmi_package = parse_package(); + qmi_package_parse(); } else if (token_accept(TOK_CONST, NULL)) { qmi_const_parse(); } else if (token_accept(TOK_STRUCT, NULL)) { @@ -495,4 +498,8 @@ void qmi_parse(void) break; } } + + /* The package name must have been specified */ + if (!qmi_package) + yyerror("package not specified"); } diff --git a/tests/no_package.qmi b/tests/no_package.qmi new file mode 100644 index 0000000..97684d5 --- /dev/null +++ b/tests/no_package.qmi @@ -0,0 +1,16 @@ +struct qmi_result { + u16 result; + u16 error; +}; + +request test_request { + required u8 test_number = 0x12; +} = 0x23; + +response test_response { + required qmi_result r = 2; +} = 043; + +indication test_indication { + optional u64 value = 0x99; +} = 0x7; diff --git a/tests/two_packages.qmi b/tests/two_packages.qmi new file mode 100644 index 0000000..3f1619e --- /dev/null +++ b/tests/two_packages.qmi @@ -0,0 +1,19 @@ +package test; +package test2; + +struct qmi_result { + u16 result; + u16 error; +}; + +request test_request { + required u8 test_number = 0x12; +} = 0x23; + +response test_response { + required qmi_result r = 2; +} = 043; + +indication test_indication { + optional u64 value = 0x99; +} = 0x7;