File tree 5 files changed +50
-1
lines changed
5 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 21
21
22
22
class ansi_c_declarationt ;
23
23
class c_bit_field_typet ;
24
+ class mathematical_function_typet ;
24
25
class shift_exprt ;
25
26
26
27
class c_typecheck_baset :
@@ -237,6 +238,7 @@ class c_typecheck_baset:
237
238
virtual void typecheck_code_type (code_typet &type);
238
239
virtual void typecheck_typedef_type (typet &type);
239
240
virtual void typecheck_c_bit_field_type (c_bit_field_typet &type);
241
+ virtual void typecheck_map_type (mathematical_function_typet &);
240
242
virtual void typecheck_typeof_type (typet &type);
241
243
virtual void typecheck_array_type (array_typet &type);
242
244
virtual void typecheck_vector_type (typet &type);
Original file line number Diff line number Diff line change @@ -114,6 +114,10 @@ void c_typecheck_baset::typecheck_type(typet &type)
114
114
{
115
115
typecheck_vector_type (type);
116
116
}
117
+ else if (type.id () == ID_mathematical_function)
118
+ {
119
+ typecheck_map_type (to_mathematical_function_type (type));
120
+ }
117
121
else if (type.id ()==ID_custom_unsignedbv ||
118
122
type.id ()==ID_custom_signedbv ||
119
123
type.id ()==ID_custom_floatbv ||
@@ -728,7 +732,6 @@ void c_typecheck_baset::typecheck_vector_type(typet &type)
728
732
error () << " type had size 0: '" << to_string (subtype) << " '" << eom;
729
733
throw 0 ;
730
734
}
731
-
732
735
// adjust by width of base type
733
736
if (s % *sub_size != 0 )
734
737
{
@@ -748,6 +751,14 @@ void c_typecheck_baset::typecheck_vector_type(typet &type)
748
751
type = new_type;
749
752
}
750
753
754
+ void c_typecheck_baset::typecheck_map_type (mathematical_function_typet &type)
755
+ {
756
+ for (auto &t : type.domain ())
757
+ typecheck_type (t);
758
+
759
+ typecheck_type (type.codomain ());
760
+ }
761
+
751
762
void c_typecheck_baset::typecheck_compound_type (struct_union_typet &type)
752
763
{
753
764
// These get replaced by symbol types later.
Original file line number Diff line number Diff line change @@ -613,6 +613,27 @@ std::string expr2ct::convert_rec(
613
613
614
614
return q+dest+d;
615
615
}
616
+ else if (src.id () == ID_mathematical_function)
617
+ {
618
+ const mathematical_function_typet &function_type =
619
+ to_mathematical_function_type (src);
620
+ std::string dest = " __CPROVER_map " ;
621
+ bool first = true ;
622
+ for (auto &t : function_type.domain ())
623
+ {
624
+ if (first)
625
+ first = false ;
626
+ else
627
+ dest += " , " ;
628
+
629
+ dest += convert (t);
630
+ }
631
+
632
+ dest += " -> " ;
633
+ dest += convert (function_type.codomain ());
634
+
635
+ return q + dest + d;
636
+ }
616
637
else if (src.id ()==ID_constructor ||
617
638
src.id ()==ID_destructor)
618
639
{
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ extern char *yyansi_ctext;
195
195
%token TOK_CPROVER_BITVECTOR " __CPROVER_bitvector"
196
196
%token TOK_CPROVER_FLOATBV " __CPROVER_floatbv"
197
197
%token TOK_CPROVER_FIXEDBV " __CPROVER_fixedbv"
198
+ %token TOK_CPROVER_MAP " __CPROVER_map"
198
199
%token TOK_CPROVER_ATOMIC " __CPROVER_atomic"
199
200
%token TOK_CPROVER_BOOL " __CPROVER_bool"
200
201
%token TOK_CPROVER_THROW " __CPROVER_throw"
@@ -1090,6 +1091,7 @@ type_specifier:
1090
1091
| typedef_type_specifier
1091
1092
| typeof_type_specifier
1092
1093
| atomic_type_specifier
1094
+ | map_type_specifier
1093
1095
;
1094
1096
1095
1097
declaration_qualifier_list :
@@ -1533,6 +1535,18 @@ array_of_construct:
1533
1535
{ $$ =$1 ; stack_type($$ ).subtype().swap(parser_stack($2 )); }
1534
1536
;
1535
1537
1538
+ map_type_specifier :
1539
+ TOK_CPROVER_MAP type_specifier TOK_ARROW type_specifier
1540
+ {
1541
+ $$ =$1 ;
1542
+ parser_stack ($$).id(ID_mathematical_function);
1543
+ irept domain;
1544
+ domain.move_to_sub(parser_stack($2 ));
1545
+ parser_stack ($$).move_to_sub(domain);
1546
+ mts ($$, $4 );
1547
+ }
1548
+ ;
1549
+
1536
1550
pragma_packed :
1537
1551
{
1538
1552
init ($$);
Original file line number Diff line number Diff line change @@ -1281,6 +1281,7 @@ __decltype { if(PARSER.cpp98 &&
1281
1281
{CPROVER_PREFIX }" bitvector" { loc (); return TOK_CPROVER_BITVECTOR; }
1282
1282
{CPROVER_PREFIX }" floatbv" { loc (); return TOK_CPROVER_FLOATBV; }
1283
1283
{CPROVER_PREFIX }" fixedbv" { loc (); return TOK_CPROVER_FIXEDBV; }
1284
+ {CPROVER_PREFIX }" map" { loc (); return TOK_CPROVER_MAP; }
1284
1285
{CPROVER_PREFIX }" bool" { loc (); return TOK_CPROVER_BOOL; }
1285
1286
{CPROVER_PREFIX }" throw" { loc (); return TOK_CPROVER_THROW; }
1286
1287
{CPROVER_PREFIX }" catch" { loc (); return TOK_CPROVER_CATCH; }
You can’t perform that action at this time.
0 commit comments