diff --git a/src/idl/CMakeLists.txt b/src/idl/CMakeLists.txt index aa7caff31f..65abc0f29c 100644 --- a/src/idl/CMakeLists.txt +++ b/src/idl/CMakeLists.txt @@ -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 diff --git a/src/idl/src/directive.c b/src/idl/src/directive.c index f98589ab95..958e13646a 100644 --- a/src/idl/src/directive.c +++ b/src/idl/src/directive.c @@ -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) { @@ -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 */ diff --git a/src/idl/tests/pragma.c b/src/idl/tests/pragma.c index 62fdde1d74..030c61ec75 100644 --- a/src/idl/tests/pragma.c +++ b/src/idl/tests/pragma.c @@ -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); +} diff --git a/src/tools/idlc/src/idlc.c b/src/tools/idlc/src/idlc.c index c78293e797..0af7820868 100644 --- a/src/tools/idlc/src/idlc.c +++ b/src/tools/idlc/src/idlc.c @@ -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; @@ -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)