Skip to content

Commit ffb732c

Browse files
author
Remi Delmas
committed
Function contracts: modified parser to allow conditional assigns clause targets.
The new syntax for conditional targets is `c ? t` or `c ? {t1, .., tn}`.
1 parent 6916359 commit ffb732c

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/ansi-c/parser.y

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3297,8 +3297,55 @@ cprover_function_contract:
32973297
| cprover_contract_assigns
32983298
;
32993299

3300+
logical_equivalence_expression_list:
3301+
logical_equivalence_expression
3302+
{
3303+
init($$, ID_expression_list);
3304+
mto($$, $1);
3305+
}
3306+
| logical_equivalence_expression_list ',' logical_equivalence_expression
3307+
{
3308+
$$=$1;
3309+
mto($$, $3);
3310+
}
3311+
;
3312+
3313+
3314+
assigns_target_expression:
3315+
logical_equivalence_expression
3316+
{
3317+
$$=$1;
3318+
}
3319+
| logical_equivalence_expression '?' '{' logical_equivalence_expression_list '}'
3320+
{
3321+
$$=$2;
3322+
parser_stack($$).id(ID_conditional_assigns_target);
3323+
mto($$, $1);
3324+
mto($$, $4);
3325+
}
3326+
| logical_equivalence_expression '?' logical_equivalence_expression
3327+
{ $$=$2;
3328+
parser_stack($$).id(ID_conditional_assigns_target);
3329+
mto($$, $1);
3330+
mto($$, $3);
3331+
}
3332+
;
3333+
3334+
assigns_target_expression_list:
3335+
assigns_target_expression
3336+
{
3337+
init($$, ID_target_list);
3338+
mto($$, $1);
3339+
}
3340+
| assigns_target_expression_list ',' assigns_target_expression
3341+
{
3342+
$$=$1;
3343+
mto($$, $3);
3344+
}
3345+
;
3346+
33003347
cprover_contract_assigns:
3301-
TOK_CPROVER_ASSIGNS '(' argument_expression_list ')'
3348+
TOK_CPROVER_ASSIGNS '(' assigns_target_expression_list ')'
33023349
{
33033350
$$=$1;
33043351
set($$, ID_C_spec_assigns);

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ IREP_ID_TWO(C_spec_requires, #spec_requires)
578578
IREP_ID_TWO(C_spec_ensures, #spec_ensures)
579579
IREP_ID_TWO(C_spec_assigns, #spec_assigns)
580580
IREP_ID_ONE(target_list)
581+
IREP_ID_ONE(conditional_assigns_target)
581582
IREP_ID_ONE(virtual_function)
582583
IREP_ID_TWO(element_type, element_type)
583584
IREP_ID_ONE(working_directory)

0 commit comments

Comments
 (0)