Skip to content

Commit

Permalink
Remove annotation_appl midrule action
Browse files Browse the repository at this point in the history
Destructors are not executed for untyped midrule actions because Bison
does not know which destructor to run. annotation_appl nodes were not
cleaned up if the annotation_appl could not be successfully finalized.
Remove use of midrule actions in annotation_appl as some platforms still
ship with Bison 3.0.4.

Fixes eclipse-cyclonedds#950.

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
  • Loading branch information
k0ekk0ek committed Sep 24, 2021
1 parent 152ebe1 commit 1564a7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
34 changes: 19 additions & 15 deletions src/idl/src/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void idl_yypstate_delete_stack(idl_yypstate *yyps);
%type <const_dcl> const_dcl
%type <annotation> annotation_dcl annotation_header
%type <annotation_member> annotation_body annotation_member
%type <annotation_appl> annotations annotation_appl annotation_appls
%type <annotation_appl> annotations annotation_appl annotation_appls annotation_appl_header
%type <annotation_appl_param> annotation_appl_params
annotation_appl_keyword_param
annotation_appl_keyword_params
Expand Down Expand Up @@ -973,31 +973,35 @@ annotation_appls:
;

annotation_appl:
annotation_appl_header annotation_appl_params
{ if (pstate->parser.state != IDL_PARSE_UNKNOWN_ANNOTATION_APPL_PARAMS)
TRY(idl_finalize_annotation_appl(pstate, LOC(@1.first, @2.last), $1, $2));
pstate->parser.state = IDL_PARSE;
pstate->annotation_scope = NULL;
$$ = $1;
}
;

annotation_appl_header:
"@"
{ pstate->parser.state = IDL_PARSE_ANNOTATION_APPL; }
annotation_appl_name
{ idl_annotation_appl_t *node = NULL;
const idl_annotation_t *annotation;
{ const idl_annotation_t *annotation;
const idl_declaration_t *declaration =
idl_find_scoped_name(pstate, NULL, $3, IDL_FIND_ANNOTATION);

pstate->annotations = true; /* register annotation occurence */
if (!declaration) {
pstate->parser.state = IDL_PARSE_UNKNOWN_ANNOTATION_APPL_PARAMS;
} else {

$$ = NULL;
if (declaration) {
annotation = idl_reference_node((idl_node_t *)declaration->node);
TRY(idl_create_annotation_appl(pstate, LOC(@1.first, @3.last), annotation, &node));
TRY(idl_create_annotation_appl(pstate, LOC(@1.first, @3.last), annotation, &$$));
pstate->parser.state = IDL_PARSE_ANNOTATION_APPL_PARAMS;
pstate->annotation_scope = declaration->scope;
} else {
pstate->parser.state = IDL_PARSE_UNKNOWN_ANNOTATION_APPL_PARAMS;
}
$<annotation_appl>$ = node;
}
annotation_appl_params
{ if (pstate->parser.state != IDL_PARSE_UNKNOWN_ANNOTATION_APPL_PARAMS)
TRY(idl_finalize_annotation_appl(pstate, LOC(@1.first, @5.last), $<annotation_appl>4, $5));
pstate->parser.state = IDL_PARSE;
pstate->annotation_scope = NULL;
$$ = $<annotation_appl>4;

idl_delete_scoped_name($3);
}
;
Expand Down
4 changes: 1 addition & 3 deletions src/idl/tests/annotation.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ CU_Test(idl_annotation, idl_default)
{"struct s { @default(\"false\") boolean b; };", IDL_RETCODE_ILLEGAL_EXPRESSION, false, IDL_NULL, NULL}, //parameter type mismatch (string vs bool)
{"struct s { @default(123) boolean b; };", IDL_RETCODE_ILLEGAL_EXPRESSION, false, IDL_NULL, NULL}, //parameter type mismatch (int vs bool)
{"struct s { @default(-123) unsigned long l; };", IDL_RETCODE_OUT_OF_RANGE, false, IDL_NULL, NULL}, //parameter type mismatch (unsigned vs signed)
/* skipping this test as idl_create_annotation_appl leaks memory if idl_resolve cannot resolve the scoped name (https://github.com/eclipse-cyclonedds/cyclonedds/issues/950)
{"@default(e_0) enum e { e_0, e_1, e_2, e_3 };", IDL_RETCODE_SEMANTIC_ERROR, false, IDL_NULL, NULL} //setting default on enums is done through @default_literal
*/
{"@default(e_0) enum e { e_0, e_1, e_2, e_3 };", IDL_RETCODE_SEMANTIC_ERROR, false, IDL_NULL, NULL} //setting default on enums is done through @default_literal
};

for (size_t i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
Expand Down

0 comments on commit 1564a7e

Please sign in to comment.