Skip to content

Commit 5e84ac2

Browse files
authored
Merge pull request #3197 from diffblue/acsl-operators
fix ACSL unicode operators
2 parents 565a92b + 00c8512 commit 5e84ac2

File tree

6 files changed

+84
-12
lines changed

6 files changed

+84
-12
lines changed

regression/cbmc/ACSL/operators.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
void boolean()
2+
{
3+
__CPROVER_bool a, b;
4+
__CPROVER_assert((ab) == (a == b), "≥");
5+
__CPROVER_assert((ab) == (a != b), "≢");
6+
__CPROVER_assert((ab) == (!a || b), "⇒");
7+
__CPROVER_assert((ab) == (a == b), "⇔");
8+
__CPROVER_assert((ab) == (a && b), "∧");
9+
__CPROVER_assert((ab) == (a || b), "∨");
10+
__CPROVER_assert((ab) == (a != b), "⊻");
11+
__CPROVER_assert((¬ a) == (!a), "¬");
12+
}
13+
14+
void relations()
15+
{
16+
int a, b;
17+
__CPROVER_assert((ab) == (a >= b), "≥");
18+
__CPROVER_assert((ab) == (a <= b), "≤");
19+
__CPROVER_assert((ab) == (a == b), "≥");
20+
__CPROVER_assert((ab) == (a != b), "≢");
21+
__CPROVER_assert((− a) == (-a), "−");
22+
}
23+
24+
int main()
25+
{
26+
boolean();
27+
relations();
28+
}

regression/cbmc/ACSL/operators.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
operators.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/ansi-c/c_typecheck_expr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ void c_typecheck_baset::typecheck_expr_main(exprt &expr)
180180
typecheck_expr_unary_arithmetic(expr);
181181
else if(expr.id()==ID_not)
182182
typecheck_expr_unary_boolean(expr);
183-
else if(expr.id()==ID_and || expr.id()==ID_or || expr.id()==ID_implies)
183+
else if(
184+
expr.id() == ID_and || expr.id() == ID_or || expr.id() == ID_implies ||
185+
expr.id() == ID_xor)
184186
typecheck_expr_binary_boolean(expr);
185187
else if(expr.id()==ID_address_of)
186188
typecheck_expr_address_of(expr);

src/ansi-c/expr2c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3815,7 +3815,7 @@ std::string expr2ct::convert_with_precedence(
38153815
return convert_multi_ary(src, "||", precedence=4, false);
38163816

38173817
else if(src.id()==ID_xor)
3818-
return convert_multi_ary(src, "^", precedence=7, false);
3818+
return convert_multi_ary(src, "!=", precedence = 9, false);
38193819

38203820
else if(src.id()==ID_implies)
38213821
return convert_binary(src, "==>", precedence=3, true);

src/ansi-c/parser.y

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ extern char *yyansi_ctext;
174174
%token TOK_EXISTS "exists"
175175
%token TOK_ACSL_FORALL "\\forall"
176176
%token TOK_ACSL_EXISTS "\\exists"
177+
%token TOK_ACSL_LET "\\let"
177178
%token TOK_ARRAY_OF "array_of"
178179
%token TOK_CPROVER_BITVECTOR "__CPROVER_bitvector"
179180
%token TOK_CPROVER_FLOATBV "__CPROVER_floatbv"
@@ -190,6 +191,7 @@ extern char *yyansi_ctext;
190191
%token TOK_CPROVER_ENSURES "__CPROVER_ensures"
191192
%token TOK_IMPLIES "==>"
192193
%token TOK_EQUIVALENT "<==>"
194+
%token TOK_XORXOR "^^"
193195
%token TOK_TRUE "TRUE"
194196
%token TOK_FALSE "FALSE"
195197
%token TOK_REAL "__real__"
@@ -775,9 +777,15 @@ logical_and_expression:
775777
{ binary($$, $1, $2, ID_and, $3); }
776778
;
777779

778-
logical_or_expression:
780+
logical_xor_expression:
779781
logical_and_expression
780-
| logical_or_expression TOK_OROR logical_and_expression
782+
| logical_xor_expression TOK_XORXOR logical_and_expression
783+
{ binary($$, $1, $2, ID_xor, $3); }
784+
;
785+
786+
logical_or_expression:
787+
logical_xor_expression
788+
| logical_or_expression TOK_OROR logical_xor_expression
781789
{ binary($$, $1, $2, ID_or, $3); }
782790
;
783791

src/ansi-c/scanner.l

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,41 +1223,67 @@ __decltype { if(PARSER.cpp98 &&
12231223
"__CPROVER_requires" { loc(); return TOK_CPROVER_REQUIRES; }
12241224
"__CPROVER_ensures" { loc(); return TOK_CPROVER_ENSURES; }
12251225

1226-
"\x22\x00" |
1226+
"\xe2\x88\x80" |
12271227
"\\forall" { /* Non-standard, obviously. Found in ACSL syntax. */
12281228
loc(); return TOK_ACSL_FORALL;
12291229
}
12301230

1231-
"\x22\x03" |
1231+
"\xe2\x88\x83" |
12321232
"\\exists" { /* Non-standard, obviously. Found in ACSL syntax. */
12331233
loc(); return TOK_ACSL_EXISTS;
12341234
}
1235-
"\x21\xD2" |
1235+
1236+
"\\let" { /* Non-standard, obviously. Found in ACSL syntax. */
1237+
loc(); return TOK_ACSL_LET;
1238+
}
1239+
1240+
"\xe2\x87\x92" |
12361241
"==>" { /* Non-standard, obviously. Found in Spec# and ACSL syntax. */
12371242
loc(); return TOK_IMPLIES;
12381243
}
12391244

1240-
"\x21\xD4" |
1245+
"\xe2\x87\x94" |
12411246
"<==>" { /* Non-standard, obviously. Found in Spec# and ACSL syntax. */
12421247
loc(); return TOK_EQUIVALENT;
12431248
}
12441249

1245-
"\x22\x65" { /* Non-standard, obviously. Found in ACSL syntax. */
1250+
"\xe2\x89\xa5" { /* Non-standard, obviously. Found in ACSL syntax. */
12461251
loc(); return TOK_GE;
12471252
}
12481253

1249-
"\x22\x64" { /* Non-standard, obviously. Found in ACSL syntax. */
1254+
"\xe2\x89\xa1" { /* Non-standard, obviously. Found in ACSL syntax. */
1255+
loc(); return TOK_EQ;
1256+
}
1257+
1258+
"\xe2\x89\xa2" { /* Non-standard, obviously. Found in ACSL syntax. */
1259+
loc(); return TOK_NE;
1260+
}
1261+
1262+
"\xe2\x89\xa4" { /* Non-standard, obviously. Found in ACSL syntax. */
12501263
loc(); return TOK_LE;
12511264
}
12521265

1253-
"\x22\x27" { /* Non-standard, obviously. Found in ACSL syntax. */
1266+
"\xe2\x88\xa7" { /* Non-standard, obviously. Found in ACSL syntax. */
12541267
loc(); return TOK_ANDAND;
12551268
}
12561269

1257-
"\x22\x28" { /* Non-standard, obviously. Found in ACSL syntax. */
1270+
"\xe2\x88\xa8" { /* Non-standard, obviously. Found in ACSL syntax. */
12581271
loc(); return TOK_OROR;
12591272
}
12601273

1274+
"\xc2\xac" { /* Non-standard, obviously. Found in ACSL syntax. */
1275+
loc(); return '!';
1276+
}
1277+
1278+
"\xe2\x8a\xbb" |
1279+
"^^" { /* Non-standard, obviously. Found in ACSL syntax. */
1280+
loc(); return TOK_XORXOR;
1281+
}
1282+
1283+
"\xe2\x88\x92" { /* Non-standard, obviously. Found in ACSL syntax. */
1284+
loc(); return '-';
1285+
}
1286+
12611287
"\\true" { /* Non-standard, obviously. Found in ACSL syntax. */
12621288
loc(); return TOK_TRUE;
12631289
}

0 commit comments

Comments
 (0)