Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore unsupported pragmas #737

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/idl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ add_library(
src/string.c
src/annotation.c
src/scope.c
src/hashid.c
src/string.c
src/tree.c
src/visit.c
Expand Down
9 changes: 6 additions & 3 deletions src/idl/src/directive.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@ idl_retcode_t idl_parse_directive(idl_pstate_t *pstate, idl_token_t *tok)
return parse_line(pstate, tok);
} else if ((pstate->scanner.state & IDL_SCAN_KEYLIST) == IDL_SCAN_KEYLIST) {
return parse_keylist(pstate, tok);
} else if (pstate->scanner.state == IDL_SCAN_UNKNOWN_PRAGMA) {
if (tok->code == '\n')
pstate->scanner.state = IDL_SCAN;
return IDL_RETCODE_OK;
} else if (pstate->scanner.state == IDL_SCAN_PRAGMA) {
/* expect keylist */
if (tok->code == IDL_TOKEN_IDENTIFIER) {
Expand All @@ -576,10 +580,9 @@ idl_retcode_t idl_parse_directive(idl_pstate_t *pstate, idl_token_t *tok)
pstate->scanner.state = IDL_SCAN_KEYLIST;
return IDL_RETCODE_OK;
}
idl_error(pstate, &tok->location,
"Unsupported #pragma directive %s", tok->value.str);
return IDL_RETCODE_SYNTAX_ERROR;
}
pstate->scanner.state = IDL_SCAN_UNKNOWN_PRAGMA;
return IDL_RETCODE_OK;
} else if (pstate->scanner.state == IDL_SCAN_DIRECTIVE_NAME) {
if (tok->code == IDL_TOKEN_PP_NUMBER) {
/* expect linemarker */
Expand Down
16 changes: 16 additions & 0 deletions src/idl/tests/pragma.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,19 @@ CU_Test(idl_pragma, keylist_outer_scope)
CU_ASSERT((idl_mask(s1->keylist) & IDL_KEYLIST) != 0);
idl_delete_pstate(pstate);
}

CU_Test(idl_pragma, unknown)
{
idl_retcode_t ret;
idl_pstate_t *pstate = NULL;
idl_struct_t *s1;
static const char str[] = "struct s1 { char c; };\n"
"#pragma foo \"bar::baz\"";

ret = parse_string(str, &pstate);
CU_ASSERT_EQUAL_FATAL(ret, IDL_RETCODE_OK);
CU_ASSERT_PTR_NOT_NULL_FATAL(pstate);
s1 = (idl_struct_t *)pstate->root;
CU_ASSERT_FATAL(idl_is_struct(s1));
idl_delete_pstate(pstate);
}
8 changes: 5 additions & 3 deletions src/tools/idlc/src/idlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ static idl_retcode_t idlc_parse(void)
if (mcpp_lib_main(config.argc, config.argv) == 0) {
assert(!config.compile || retcode == IDL_RETCODE_OK);
} else if (config.compile) {
assert(retcode != IDL_RETCODE_OK);
ret = retcode;
/* retcode is not set on preprocessor error */
ret = retcode ? retcode : IDL_RETCODE_SYNTAX_ERROR;
}
if (pstate) {
pstate->flags &= ~IDL_WRITE;
Expand Down Expand Up @@ -576,7 +576,9 @@ int main(int argc, char *argv[])
config.file = argv[optind];
config.argv[config.argc++] = config.file;
if ((ret = idlc_parse())) {
fprintf(stderr, "Cannot parse '%s'\n", config.file);
/* assume other errors are reported by processor */
if (ret == IDL_RETCODE_NO_MEMORY)
fprintf(stderr, "Out of memory\n");
goto err_parse;
} else if (config.compile) {
if (gen.generate)
Expand Down