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 <elder@linaro.org>
Message-Id: <20211001232338.769309-26-elder@linaro.org>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Alex Elder 2021-10-01 18:23:29 -05:00 committed by Bjorn Andersson
parent 61f6fe9d1c
commit 83931b750f
3 changed files with 45 additions and 3 deletions

View File

@ -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");
}

16
tests/no_package.qmi Normal file
View File

@ -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;

19
tests/two_packages.qmi Normal file
View File

@ -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;