Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
;
ext_module_markup:
| MODULE ext_identifier COLON { $2 }
;
ext_function_markup:
| FUNCTION ext_identifier COLON { $2, loc() }
;
ext_contract_markup:
| CONTRACT ext_identifier_opt COLON { $2 }
;
stmt_markup:
| any_identifier { $1 }
| CONSTANT10 { $1 }
;
stmt_markup_attr:
| stmt_markup { [$1] }
| stmt_markup stmt_markup_attr { $1 :: $2 }
;
ext_at_stmt_markup:
| EXT_AT stmt_markup_attr COLON { $2 }
;
/*** function and statement contracts ***/
spec:
| contract EOF { fst $1 }
;
contract:
| requires terminates decreases simple_clauses behaviors complete_or_disjoint
{ let requires=$1 in
let (allocation,assigns,post_cond,extended) = $4 in
let behaviors = $5 in
let (completes,disjoints) = $6 in
let behaviors =
if requires <> [] || post_cond <> [] ||
allocation <> FreeAllocAny ||
assigns <> WritesAny || extended <> []
then
(Cabshelper.mk_behavior
~requires ~post_cond ~assigns ~allocation ~extended ())
:: behaviors
else if $2<>None || $3<>None ||
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
behaviors<>[] || completes<>[] ||disjoints<>[]
then behaviors
else raise (Not_well_formed (loc(),"Empty annotation is not allowed"))
in
{ spec_terminates = $2;
spec_variant = $3;
spec_behavior = behaviors;
spec_complete_behaviors = completes;
spec_disjoint_behaviors = disjoints;
}, loc()
}
| requires ne_terminates REQUIRES { clause_order 3 "requires" "terminates" }
| requires terminates ne_decreases REQUIRES
{ clause_order 4 "requires" "decreases" }
| requires terminates ne_decreases TERMINATES
{ clause_order 4 "terminates" "decreases" }
| requires terminates decreases ne_simple_clauses REQUIRES
{ clause_order 5 "requires" "post-condition, assigns or allocates" }
| requires terminates decreases ne_simple_clauses TERMINATES
{ clause_order 5 "terminates" "post-condition, assigns or allocates" }
| requires terminates decreases ne_simple_clauses DECREASES
{ clause_order 5 "decreases" "post-condition, assigns or allocates" }
| requires terminates decreases simple_clauses ne_behaviors TERMINATES
{ clause_order 6 "terminates" "behavior" }
| requires terminates decreases simple_clauses ne_behaviors DECREASES
{ clause_order 6 "decreases" "behavior" }
| requires terminates decreases simple_clauses behaviors ne_complete_or_disjoint
REQUIRES
{ clause_order 7 "requires" "complete or disjoint" }
| requires terminates decreases simple_clauses behaviors ne_complete_or_disjoint
TERMINATES
{ clause_order 7 "terminates" "complete or disjoint" }
| requires terminates decreases simple_clauses behaviors ne_complete_or_disjoint
DECREASES
{ clause_order 7 "decreases" "complete or disjoint" }
| requires terminates decreases simple_clauses behaviors ne_complete_or_disjoint
BEHAVIOR
{ clause_order 7 "behavior" "complete or disjoint" }
| requires terminates decreases simple_clauses behaviors ne_complete_or_disjoint
ASSIGNS
{ clause_order 7 "assigns" "complete or disjoint" }
| requires terminates decreases simple_clauses behaviors ne_complete_or_disjoint
ALLOCATES
{ clause_order 7 "allocates" "complete or disjoint" }
| requires terminates decreases simple_clauses behaviors ne_complete_or_disjoint
FREES
{ clause_order 7 "frees" "complete or disjoint" }
| requires terminates decreases simple_clauses behaviors ne_complete_or_disjoint
post_cond_kind
{ clause_order 7 "post-condition" "complete or disjoint" }
;
// use that to detect potentially missing ';' at end of clause
clause_kw:
| CHECK_REQUIRES { "check requires" }
| REQUIRES { "requires" }
| ASSUMES {"assumes"}
| ASSIGNS { "assigns" }
| post_cond { snd $1 }
| DECREASES { "decreases"}
| BEHAVIOR { "behavior"}
| ALLOCATES {"allocates"}
| FREES {"frees"}
| COMPLETE {"complete"}
| DISJOINT {"disjoint"}
/* often, we'll be in c_kw_mode, where these keywords are
recognized as identifiers... */
| IDENTIFIER { $1 }
| EXT_CONTRACT { $1 }
| EOF { "end of annotation" }
;
requires:
| /* epsilon */ { [] }
| ne_requires { $1 }
;
ne_requires:
| REQUIRES full_lexpr SEMICOLON requires { toplevel_pred false $2::$4 }
| CHECK_REQUIRES full_lexpr SEMICOLON requires { toplevel_pred true $2 :: $4 }
| REQUIRES full_lexpr clause_kw { missing 2 ";" $3 }
| CHECK_REQUIRES full_lexpr clause_kw { missing 2 ";" $3 }
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
;
terminates:
| /* epsilon */ { None }
| ne_terminates { Some $1 }
;
ne_terminates:
| TERMINATES full_lexpr SEMICOLON { $2 }
| TERMINATES full_lexpr clause_kw { missing 2 ";" $3 }
;
decreases:
| /* epsilon */ { None }
| ne_decreases { Some $1 }
;
ne_decreases:
| DECREASES variant SEMICOLON { $2 }
| DECREASES variant clause_kw { missing 2 ";" $3 }
;
variant:
| full_lexpr FOR any_identifier { ($1, Some $3) }
| full_lexpr { ($1, None) }
;
simple_clauses:
| /* epsilon */ { FreeAllocAny,WritesAny,[],[] }
| ne_simple_clauses { $1 }
;
allocation:
| ALLOCATES full_zones { FreeAlloc([],$2) }
| FREES full_zones { FreeAlloc($2,[]) }
ne_simple_clauses:
| post_cond_kind full_lexpr SEMICOLON simple_clauses
{ let only_check, kind = $1 in
let allocation,assigns,post_cond,extended = $4 in
allocation,assigns,
((kind,toplevel_pred only_check $2)::post_cond),extended }
| allocation SEMICOLON simple_clauses
{ let allocation,assigns,post_cond,extended = $3 in
let a = concat_allocation allocation $1 in
a,assigns,post_cond,extended
}
| ASSIGNS full_assigns SEMICOLON simple_clauses
{ let allocation,assigns,post_cond,extended = $4 in
let a = concat_assigns assigns $2
in allocation,a,post_cond,extended
}
| EXT_CONTRACT grammar_extension SEMICOLON simple_clauses
{ let allocation,assigns,post_cond,extended = $4 in
let processed = Logic_env.preprocess_extension $1 $2 in
allocation,assigns,post_cond,($1,processed)::extended
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
}
| post_cond_kind full_lexpr clause_kw { missing 2 ";" $3 }
| allocation clause_kw { missing 1 ";" $2 }
| ASSIGNS full_assigns clause_kw { missing 2 ";" $3 }
| EXT_CONTRACT grammar_extension clause_kw { missing 1 ";" $3 }
;
grammar_extension:
/* Grammar Extensibility for plugins */
| full_zones { $1 }
;
post_cond_kind:
| post_cond { fst $1 }
;
behaviors:
| /* epsilon */ { [] }
| ne_behaviors { $1 }
ne_behaviors:
| BEHAVIOR behavior_name COLON behavior_body behaviors
{ let (assumes,requires,(allocation,assigns,post_cond,extended)) = $4 in
let behaviors = $5 in
let b =
Cabshelper.mk_behavior
~name:$2
~assumes ~requires ~post_cond ~assigns ~allocation ~extended ()
in b::behaviors
}
behavior_body:
| assumes requires simple_clauses { $1,$2,$3 }
| assumes ne_requires ASSUMES
{ clause_order 3 "assumes" "requires" }
| assumes requires ne_simple_clauses ASSUMES
{ clause_order 4 "assumes" "assigns or post-condition" }
| assumes requires ne_simple_clauses REQUIRES
{ clause_order 4 "requires" "assigns or post-condition" }
;
assumes:
| /* epsilon */ { [] }
| ASSUMES full_lexpr SEMICOLON assumes { $2::$4 }
| ASSUMES full_lexpr clause_kw { missing 2 ";" $3 }
;
complete_or_disjoint:
| /* epsilon */ { [],[] }
| ne_complete_or_disjoint { $1 }
ne_complete_or_disjoint:
| COMPLETE BEHAVIORS behavior_name_list SEMICOLON
complete_or_disjoint
{ let complete,disjoint = $5 in $3::complete, disjoint }
| DISJOINT BEHAVIORS behavior_name_list SEMICOLON
complete_or_disjoint
{ let complete,disjoint = $5 in complete,$3::disjoint }
/* complete behaviors decreases; is valid (provided there's a behavior
named decreases)
*/
| COMPLETE BEHAVIORS ne_behavior_name_list clause_kw { missing 3 ";" $4 }
| DISJOINT BEHAVIORS ne_behavior_name_list clause_kw { missing 3 ";" $4 }
;
/*** assigns and tsets ***/
assigns:
| zones { List.map (fun x -> (x,FromAny)) $1 }
| ne_zones FROM zones {List.map (fun x -> (x, From $3)) $1}
;
zones:
| ne_zones { $1 }
| NOTHING { [] }
;
ne_zones:
| ne_lexpr_list { $1 }
;
/*** annotations ***/
annot:
| annotation EOF { $1 }
| is_acsl_spec any EOF { Aspec }
| decl_list EOF { Adecl ($1) }
| CUSTOM any_identifier COLON custom_tree EOF { Acustom(loc (),$2, $4) }
;
custom_tree:
| TYPE type_spec { CustomType $2 }
| LOGIC lexpr { CustomLexpr $2 }
| any_identifier_non_logic { CustomOther($1,[]) }
| any_identifier_non_logic LPAR custom_tree_list RPAR { CustomOther($1,$3) }
;
custom_tree_list:
| custom_tree { [$1] }
| custom_tree COMMA custom_tree_list { $1::$3 }
;
annotation:
| loop_annotations
{ let (b,v,p) = $1 in
(* TODO: do better, do not lose the structure ! *)
let l = b@v@p in
Aloop_annot (loc (), l) }
| FOR ne_behavior_name_list COLON contract_or_code_annotation
{ $4 $2 }
| pragma_or_code_annotation { Acode_annot (loc(),$1) }
| pragma_or_code_annotation beg_pragma_or_code_annotation
{ raise
(Not_well_formed (loc(),
"Only one code annotation is allowed per comment"))
}
| full_identifier_or_typename { Aattribute_annot (loc (), $1) }
;
contract_or_code_annotation:
| contract
{ fun bhvs -> let s, pos = $1 in Acode_annot (pos, AStmtSpec (bhvs,s)) }
| code_annotation { fun bhvs -> Acode_annot (loc(), ($1 bhvs)) }
;
/*** loop annotations ***/
loop_annotations:
| loop_annot_stack
{ let (i,fa,a,b,v,p, e) = $1 in
let invs = List.map (fun i -> AInvariant([],true,i)) i in
let ext = List.map (fun x -> AExtended([],true, x)) e in
let oth = match a with
| WritesAny -> b
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
(* by definition all existing AAssigns are tied to at least
one behavior. No need to merge against them. *)
AAssigns ([],a)::b
in
let oth = match fa with
| FreeAllocAny -> oth
| _ -> AAllocation ([],fa)::oth
in
(invs@oth@ext,v,p)
}
;
/* TODO: gather loop assigns that are related to the same behavior */
loop_annot_stack:
| loop_invariant loop_annot_opt
{ let (i,fa,a,b,v,p,e) = $2 in ($1::i,fa,a,b,v,p,e) }
| loop_effects loop_annot_opt
{ let (i,fa,a,b,v,p,e) = $2 in (i,fa,concat_assigns a $1,b,v,p,e) }
| loop_allocation loop_annot_opt
{ let (i,fa,a,b,v,p,e) = $2 in (i,concat_allocation fa $1,a,b,v,p,e) }
| FOR ne_behavior_name_list COLON loop_annot_stack
{ let (i,fa,a,b,v,p,e) = $4 in
let behav = $2 in
let invs = List.map (fun i -> AInvariant(behav,true,i)) i in
let ext = List.map (fun x -> AExtended(behav,true,x)) e in
let oth = concat_loop_assigns_allocation b behav a fa in
([],FreeAllocAny,WritesAny,invs@ext@oth,v,p,[])
}
| loop_variant loop_annot_opt
{ let pos,loop_variant = $1 in
let (i,fa,a,b,v,p,e) = $2 in
check_empty
(pos,"loop invariant is not allowed after loop variant.") i ;
check_empty
(pos, "loop extension is not allowed after loop variant.") e;
(match fa with
| FreeAlloc(f,a) ->
check_empty
(pos,"loop frees is not allowed after loop variant.") f ;
check_empty
(pos,"loop allocates is not allowed after loop variant.") a
| FreeAllocAny -> ());
(match a with
WritesAny -> ()
| Writes _ ->
raise
(Not_well_formed
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
(pos,"loop assigns is not allowed after loop variant.")));
check_empty
(pos,"loop behavior is not allowed after loop variant.") b ;
check_empty
(pos,"loop annotations can have at most one variant.") v ;
(i,fa,a,b,AVariant loop_variant::v,p,e) }
| loop_pragma loop_annot_opt
{ let (i,fa,a,b,v,p,e) = $2 in (i,fa,a,b,v,APragma (Loop_pragma $1)::p,e) }
| loop_grammar_extension loop_annot_opt {
let (i,fa,a,b,v,p,e) = $2 in
(i,fa,a,b,v,p, $1::e)
}
;
loop_annot_opt:
| /* epsilon */
{ ([], FreeAllocAny, WritesAny, [], [], [], []) }
| loop_annot_stack
{ $1 }
;
loop_effects:
| LOOP ASSIGNS full_assigns SEMICOLON { $3 }
;
loop_allocation:
| LOOP allocation SEMICOLON { $2 }
;
loop_invariant:
| LOOP INVARIANT full_lexpr SEMICOLON { toplevel_pred false $3 }
| CHECK_LOOP INVARIANT full_lexpr SEMICOLON { toplevel_pred true $3 }
;
loop_variant:
| LOOP VARIANT variant SEMICOLON { loc(),$3 }
;
/* Grammar Extensibility for plugins */
loop_grammar_extension:
| LOOP EXT_CODE_ANNOT grammar_extension SEMICOLON {
let open Cil_types in
let ext = $2 in
try
begin match Logic_env.extension_category ext with
| Ext_code_annot (Ext_next_loop | Ext_next_both) ->
let processed = Logic_env.preprocess_extension ext $3 in
(ext, processed)
| Ext_code_annot (Ext_here | Ext_next_stmt) ->
raise
(Not_well_formed
(lexeme_loc 2, ext ^ " is not a loop annotation extension"))
| _ -> raise Not_found
end
with Not_found ->
Kernel.fatal ~source:(lexeme_start 2)
"%s is not a code annotation extension. Parser got wrong lexeme." ext
}
;
loop_pragma:
| LOOP PRAGMA any_identifier full_ne_lexpr_list SEMICOLON
{ if $3 = "UNROLL_LOOP" || $3 = "UNROLL" then
(if $3 <> "UNROLL" then
Format.eprintf "Warning: use of deprecated keyword '%s'.\nShould use 'UNROLL' instead.@." $3;
Unroll_specs $4)
else if $3 = "WIDEN_VARIABLES" then
Widen_variables $4
else if $3 = "WIDEN_HINTS" then
Widen_hints $4
else raise (Not_well_formed (loc(),"Unknown loop pragma")) }
;
/*** code annotations ***/
beg_pragma_or_code_annotation:
| IMPACT {}
| SLICE {}
| FOR {}
| ASSERT {}
| INVARIANT {}
| CHECK_INVARIANT {}
| EXT_CODE_ANNOT {}
pragma_or_code_annotation:
| slice_pragma { APragma (Slice_pragma $1) }
| impact_pragma { APragma (Impact_pragma $1) }
| code_annotation { $1 [] }
;
code_annotation:
| ASSERT full_lexpr SEMICOLON
{ fun bhvs -> AAssert (bhvs,toplevel_pred false $2) }
| CHECK full_lexpr SEMICOLON
{ fun bhvs -> AAssert (bhvs,toplevel_pred true $2) }
| INVARIANT full_lexpr SEMICOLON
{ fun bhvs -> AInvariant (bhvs,false,toplevel_pred false $2) }
| CHECK_INVARIANT full_lexpr SEMICOLON
{ fun bhvs -> AInvariant (bhvs,false,toplevel_pred true $2) }
| EXT_CODE_ANNOT grammar_extension SEMICOLON
{ fun bhvs ->
let open Cil_types in
let ext = $1 in
try
begin match Logic_env.extension_category ext with
| Ext_code_annot (Ext_here | Ext_next_stmt | Ext_next_both) ->
let processed = Logic_env.preprocess_extension ext $2 in
Logic_ptree.AExtended(bhvs,false,(ext,processed))
| Ext_code_annot Ext_next_loop ->
raise
(Not_well_formed
(lexeme_loc 1,
ext ^ " is not a loop annotation extension. It can't be used \
as plain code annotation extension"))
| _ -> raise Not_found
end
with Not_found ->
Kernel.fatal ~source:(lexeme_start 1)
"%s is not a code annotation extension. Parser got wrong lexeme" ext
}
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
;
slice_pragma:
| SLICE PRAGMA any_identifier full_lexpr SEMICOLON
{ if $3 = "expr" then SPexpr $4
else raise (Not_well_formed (loc(), "Unknown slice pragma")) }
| SLICE PRAGMA any_identifier SEMICOLON
{ if $3 = "ctrl" then SPctrl
else if $3 = "stmt" then SPstmt
else raise (Not_well_formed (loc(), "Unknown slice pragma")) }
;
impact_pragma:
| IMPACT PRAGMA any_identifier full_lexpr SEMICOLON
{ if $3 = "expr" then IPexpr $4
else raise (Not_well_formed (loc(), "Unknown impact pragma")) }
| IMPACT PRAGMA any_identifier SEMICOLON
{ if $3 = "stmt" then IPstmt
else raise (Not_well_formed (loc(), "Unknown impact pragma")) }
;
/*** declarations and logical definitions ***/
decl_list:
| decl { [loc_decl $1] }
| decl decl_list { (loc_decl $1) :: $2 }
decl:
| GLOBAL INVARIANT any_identifier COLON full_lexpr SEMICOLON
{ LDinvariant ($3, $5) }
Virgile Prevosto
committed
| VOLATILE full_ne_zones volatile_opt SEMICOLON { LDvolatile ($2, $3) }
| type_annot {LDtype_annot $1}
| model_annot {LDmodel_annot $1}
| logic_def { $1 }
| EXT_GLOBAL grammar_extension SEMICOLON {
let processed = Logic_env.preprocess_extension $1 $2 in
LDextended ($1, processed)
}
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
| deprecated_logic_decl { $1 }
;
volatile_opt:
| /* empty */ { None, None }
| READS any_identifier volatile_opt
{ let read,write=$3 in
if read = None then
(Some $2),write
else
(Format.eprintf "Warning: read %s ignored@." $2; $3)
}
| WRITES any_identifier volatile_opt
{ let read,write=$3 in
if write = None then
read,(Some $2)
else
(Format.eprintf "Warning: write %s ignored@." $2; $3)
}
;
type_annot:
| TYPE INVARIANT any_identifier LPAR full_parameter RPAR EQUAL
full_lexpr SEMICOLON
{ let typ,name = $5 in{ inv_name = $3; this_name = name; this_type = typ; inv = $8; } }
;
opt_semicolon:
| /* epsilon */ { }
| SEMICOLON { }
model_annot:
| MODEL type_spec LBRACE full_parameter opt_semicolon RBRACE SEMICOLON
{ let typ,name = $4 in
{ model_for_type = $2; model_name = name; model_type = typ; }
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
}
;
poly_id_type:
| full_identifier
{ enter_type_variables_scope []; ($1,[]) }
| full_identifier LT ne_tvar_list GT
{ enter_type_variables_scope $3; ($1,$3) }
;
/* we need to recognize the typename as soon as it has been declared,
so that it can be used in data constructors in the type definition itself
*/
poly_id_type_add_typename:
| poly_id_type { let (id,_) = $1 in Logic_env.add_typename id; $1 }
;
poly_id:
| poly_id_type { let (id,tvar) = $1 in (id,[],tvar) }
| full_identifier LBRACE ne_label_list RBRACE
{ enter_type_variables_scope []; ($1,$3,[]) }
| full_identifier LBRACE ne_label_list RBRACE LT ne_tvar_list GT
{ enter_type_variables_scope $6; $1,$3,$6 }
;
opt_parameters:
| /*epsilon*/ { [] }
| parameters { $1 }
;
parameters:
| LPAR full_parameters RPAR { $2 }
;
logic_def:
/* logic function definition */
| LOGIC full_logic_rt_type poly_id opt_parameters EQUAL full_lexpr SEMICOLON
{ let (id, labels, tvars) = $3 in
exit_type_variables_scope ();
LDlogic_def (id, labels, tvars, $2, $4, $6) }
/* predicate definition */
| PREDICATE poly_id opt_parameters EQUAL full_lexpr SEMICOLON
{ let (id,labels,tvars) = $2 in
exit_type_variables_scope ();
LDpredicate_def (id, labels, tvars, $3, $5) }
/* inductive predicate definition */
| INDUCTIVE poly_id parameters LBRACE indcases RBRACE
{ let (id,labels,tvars) = $2 in
exit_type_variables_scope ();
LDinductive_def(id, labels, tvars, $3, $5) }
| LEMMA poly_id COLON full_lexpr SEMICOLON
{ let (id,labels,tvars) = $2 in
exit_type_variables_scope ();
LDlemma (id, false, labels, tvars, toplevel_pred false $4) }
| CHECK_LEMMA poly_id COLON full_lexpr SEMICOLON
{ let (id,labels,tvars) = $2 in
exit_type_variables_scope ();
LDlemma (id, false, labels, tvars, toplevel_pred true $4) }
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
| AXIOMATIC any_identifier LBRACE logic_decls RBRACE
{ LDaxiomatic($2,$4) }
| TYPE poly_id_type_add_typename EQUAL typedef SEMICOLON
{ let (id,tvars) = $2 in
exit_type_variables_scope ();
LDtype(id,tvars,Some $4)
}
;
deprecated_logic_decl:
/* OBSOLETE: logic function declaration */
| LOGIC full_logic_rt_type poly_id opt_parameters SEMICOLON
{ let (id, labels, tvars) = $3 in
let source = fst (loc ()) in
exit_type_variables_scope ();
obsolete "logic declaration" ~source ~now:"an axiomatic block";
LDlogic_reads (id, labels, tvars, $2, $4, None) }
/* OBSOLETE: predicate declaration */
| PREDICATE poly_id opt_parameters SEMICOLON
{ let (id,labels,tvars) = $2 in
exit_type_variables_scope ();
let source = fst (loc ()) in
obsolete "logic declaration" ~source ~now:"an axiomatic block";
LDpredicate_reads (id, labels, tvars, $3, None) }
/* OBSOLETE: type declaration */
| TYPE poly_id_type SEMICOLON
{ let (id,tvars) = $2 in
Logic_env.add_typename id;
exit_type_variables_scope ();
let source = fst (loc ()) in
obsolete "logic type declaration" ~source ~now:"an axiomatic block";
LDtype(id,tvars,None)
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
}
/* OBSOLETE: axiom */
| AXIOM poly_id COLON full_lexpr SEMICOLON
{ let (id,_,_) = $2 in
raise
(Not_well_formed
(loc(),"Axiom " ^ id ^ " is declared outside of an axiomatic."))
}
;
logic_decls:
| /* epsilon */
{ [] }
| logic_decl_loc logic_decls
{ $1::$2 }
;
logic_decl:
| logic_def { $1 }
/* logic function declaration */
| LOGIC full_logic_rt_type poly_id opt_parameters reads_clause SEMICOLON
{ let (id, labels, tvars) = $3 in
exit_type_variables_scope ();
LDlogic_reads (id, labels, tvars, $2, $4, $5) }
/* predicate declaration */
| PREDICATE poly_id opt_parameters reads_clause SEMICOLON
{ let (id,labels,tvars) = $2 in
exit_type_variables_scope ();
LDpredicate_reads (id, labels, tvars, $3, $4) }
/* type declaration */
| TYPE poly_id_type SEMICOLON
{ let (id,tvars) = $2 in
Logic_env.add_typename id;
exit_type_variables_scope ();
LDtype(id,tvars,None) }
/* axiom */
| AXIOM poly_id COLON full_lexpr SEMICOLON
{ let (id,labels,tvars) = $2 in
exit_type_variables_scope ();
LDlemma (id, true, labels, tvars, toplevel_pred false $4) }
;
logic_decl_loc:
| logic_decl { loc_decl $1 }
;
reads_clause:
| /* epsilon */ { None }
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
;
typedef:
| ne_datacons_list { TDsum $1 }
| full_logic_type { TDsyn $1 }
;
datacons_list:
| /* epsilon */ { [] }
| PIPE datacons datacons_list { $2 :: $3 }
;
ne_datacons_list:
| datacons datacons_list { $1 :: $2 }
| PIPE datacons datacons_list { $2 :: $3 }
;
datacons:
| full_identifier { ($1,[]) }
| full_identifier LPAR ne_type_list RPAR { ($1,$3) }
;
ne_type_list:
| full_logic_type { [$1] }
| full_logic_type COMMA ne_type_list { $1::$3 }
indcases:
| /* epsilon */
{ [] }
| CASE poly_id COLON full_lexpr SEMICOLON indcases
{ let (id,labels,tvars) = $2 in
exit_type_variables_scope ();
(id,labels,tvars,$4)::$6 }
;
ne_tvar_list:
| full_identifier { [$1] }
| full_identifier COMMA ne_tvar_list { $1 :: $3 }
;
ne_label_list:
| label_name { [$1] }
| label_name COMMA ne_label_list { $1 :: $3 }
;
opt_label_1:
| opt_label_list { match $1 with
| [] -> None
| l::[] -> Some l
| _ -> raise (Not_well_formed (loc(),"Only one label is allowed")) }
;
opt_label_2:
| opt_label_list { match $1 with
| [] -> None
| l1::l2::[] -> Some (l1,l2)
| _::[] -> raise (Not_well_formed (loc(),"One label is missing"))
| _ -> raise (Not_well_formed (loc(),"Only two labels are allowed")) }
;
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
opt_label_list:
| /* epsilon */ { [] }
| LBRACE ne_label_list RBRACE { $2 }
;
/* names */
label_name:
| any_identifier { $1 }
;
behavior_name_list:
| /* epsilon */ { [] }
| ne_behavior_name_list { $1 }
;
ne_behavior_name_list:
| behavior_name { [$1] }
| behavior_name COMMA ne_behavior_name_list {$1 :: $3}
;
behavior_name:
| any_identifier { $1 }
;
any_identifier:
| identifier_or_typename { $1 }
| keyword { $1 }
;
any_identifier_non_logic:
| identifier_or_typename { $1 }
| non_logic_keyword { $1 }
identifier_or_typename: /* allowed as C field names */
| TYPENAME { $1 } /* followed by the same list than 'identifier' */
| IDENTIFIER { $1 }
/* token list used inside ascl clauses: */
| BEHAVIORS { "behaviors" }
| LABEL { "label" }
| READS { "reads" }
| WRITES { "writes" }
identifier: /* part included into 'identifier_or_typename', but duplicated to avoid parsing conflicts */
| IDENTIFIER { $1 }
/* token list used inside ascl clauses: */
| BEHAVIORS { "behaviors" }
| LABEL { "label" }
| READS { "reads" }
| WRITES { "writes" }
;
bounded_var:
| identifier { $1 }
| TYPENAME /* Since TYPENAME cannot be accepted by lexpr rule */
{ raise
(Not_well_formed(loc (),
"Type names are not allowed as binding variable"))
}
;
c_keyword:
| CHAR { "char" }
| BOOLEAN { "boolean" }
| BOOL { "_Bool" }
| CONST { "const" }
| DOUBLE { "double" }
| ENUM { "enum" }
| ELSE { "else" }
| FLOAT { "float" }
| IF { "if" }
| INT { "int" }
| LONG { "long" }
| SHORT { "short" }
| SIGNED { "signed" }
| SIZEOF { "sizeof" }
| STATIC { "static" }
| STRUCT { "struct" }
| UNION { "union" }
| UNSIGNED { "unsigned" }
;
acsl_c_keyword:
| CASE { "case" }
| FOR { "for" }
| VOLATILE { "volatile" }
;
post_cond:
| ENSURES { (false,Normal), "ensures" }
| EXITS { (false,Exits), "exits" }
| BREAKS { (false,Breaks), "breaks" }
| CONTINUES { (false,Continues), "continues" }
| RETURNS { (false,Returns), "returns" }
| CHECK_ENSURES { (true,Normal), "check ensures" }
| CHECK_EXITS { (true,Exits), "check exits" }
| CHECK_BREAKS { (true,Breaks), "check breaks" }
| CHECK_CONTINUES { (true,Continues), "check continues" }
| CHECK_RETURNS { (true,Returns), "check returns" }
;
is_acsl_spec:
| post_cond { snd $1 }
| EXT_CONTRACT { $1 }
| ASSIGNS { "assigns" }
| ALLOCATES { "allocates" }
| FREES { "frees" }
| BEHAVIOR { "behavior" }
| REQUIRES { "requires" }
| CHECK_REQUIRES { "check requires" }
| TERMINATES { "terminates" }
| COMPLETE { "complete" }
| DECREASES { "decreases" }
| DISJOINT { "disjoint" }
;
is_acsl_decl_or_code_annot:
| EXT_CODE_ANNOT { $1 }
| EXT_GLOBAL { $1 }
| ASSUMES { "assumes" }
| ASSERT { "assert" }
| GLOBAL { "global" }
| IMPACT { "impact" }
| INDUCTIVE { "inductive" }
| INVARIANT { "invariant" }
| LEMMA { "lemma" }
| LOOP { "loop" }
| PRAGMA { "pragma" }
| PREDICATE { "predicate" }
| SLICE { "slice" }
| TYPE { "type" }
| MODEL { "model" }
| AXIOM { "axiom" }
| VARIANT { "variant" }
| AXIOMATIC { "axiomatic" }
;
is_acsl_other:
| INTEGER { "integer" (* token that cannot be used in C fields *) }
| REAL { "real" (* token that cannot be used in C fields *) }
;
is_ext_spec:
| CONTRACT { "contract" }
| FUNCTION { "function" }
| MODULE { "module" }
| INCLUDE { "include" }
| EXT_AT { "at" }
| EXT_LET { "let" }
;
keyword:
| non_logic_keyword { $1 }
;
non_logic_keyword:
| c_keyword { $1 }
| acsl_c_keyword { $1 }
| is_ext_spec { $1 }
| is_acsl_spec { $1 }
| is_acsl_decl_or_code_annot { $1 }
| is_acsl_other { $1 }
| CUSTOM { "custom" (* token that cannot be used in C fields *) }
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
;
bs_keyword:
| ALLOCABLE { () }
| ALLOCATION { () }
| AUTOMATIC { () }
| AT { () }
| BASE_ADDR { () }
| BLOCK_LENGTH { () }
| DYNAMIC { () }
| EMPTY { () }
| FALSE { () }
| FORALL { () }
| FREEABLE { () }
| FRESH { () }
| FROM { () }
| INTER { () }
| LAMBDA { () }
| LET { () }
| NOTHING { () }
| NULL { () }
| OLD { () }
| OFFSET { () }
| REGISTER { () }
| RESULT { () }
| SEPARATED { () }
| TRUE { () }
| BSTYPE { () }
| TYPEOF { () }
| BSUNION { () }
| UNALLOCATED { () }
| OBJECT_POINTER { () }
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
| VALID { () }
| VALID_INDEX { () }
| VALID_RANGE { () }
| VALID_READ { () }
| VALID_FUNCTION { () }
| INITIALIZED { () }
| DANGLING { () }
| WITH { () }
;
wildcard:
| any_identifier { () }
| bs_keyword { () }
| AMP { () }
| AND { () }
| ARROW { () }
| BIFF { () }
| BIMPLIES { () }
| COLON { () }
| COLON2 { () }
| COLONCOLON { () }
| COMMA { () }
| CONSTANT { () }
| CONSTANT10 { () }
| DOLLAR { () }
| DOT { () }
| DOTDOT { () }
| DOTDOTDOT { () }
| EQ { () }
| EQUAL { () }
| EXISTS { () }
| GE { () }
| GHOST { () }
| GT { () }
| GTGT { () }
| HAT { () }