|
9 | 9 | #include "smv_typecheck.h"
|
10 | 10 |
|
11 | 11 | #include <util/arith_tools.h>
|
| 12 | +#include <util/bitvector_types.h> |
12 | 13 | #include <util/expr_util.h>
|
13 | 14 | #include <util/mathematical_expr.h>
|
14 | 15 | #include <util/namespace.h>
|
@@ -565,7 +566,15 @@ typet smv_typecheckt::type_union(
|
565 | 566 |
|
566 | 567 | if(type2.is_nil())
|
567 | 568 | return type1;
|
568 |
| - |
| 569 | + |
| 570 | + if( |
| 571 | + type1.id() == ID_signedbv || type1.id() == ID_unsignedbv || |
| 572 | + type2.id() == ID_signedbv || type2.id() == ID_unsignedbv) |
| 573 | + { |
| 574 | + throw errort() << "no type union for types" << to_string(type1) << " and " |
| 575 | + << to_string(type2); |
| 576 | + } |
| 577 | + |
569 | 578 | // both enums?
|
570 | 579 | if(type1.id()==ID_enumeration && type2.id()==ID_enumeration)
|
571 | 580 | {
|
@@ -1033,6 +1042,26 @@ void smv_typecheckt::typecheck_expr_rec(
|
1033 | 1042 | {
|
1034 | 1043 | expr.type()=bool_typet();
|
1035 | 1044 | }
|
| 1045 | + else if(expr.id() == ID_smv_swconst) |
| 1046 | + { |
| 1047 | + auto &binary_expr = to_binary_expr(expr); |
| 1048 | + auto bits = numeric_cast_v<mp_integer>(to_constant_expr(binary_expr.op1())); |
| 1049 | + auto type = signedbv_typet{bits}; |
| 1050 | + auto value = |
| 1051 | + numeric_cast_v<mp_integer>(to_constant_expr(binary_expr.op0())); |
| 1052 | + expr = |
| 1053 | + from_integer(value, type).with_source_location(expr.source_location()); |
| 1054 | + } |
| 1055 | + else if(expr.id() == ID_smv_uwconst) |
| 1056 | + { |
| 1057 | + auto &binary_expr = to_binary_expr(expr); |
| 1058 | + auto bits = numeric_cast_v<mp_integer>(to_constant_expr(binary_expr.op1())); |
| 1059 | + auto type = unsignedbv_typet{bits}; |
| 1060 | + auto value = |
| 1061 | + numeric_cast_v<mp_integer>(to_constant_expr(binary_expr.op0())); |
| 1062 | + expr = |
| 1063 | + from_integer(value, type).with_source_location(expr.source_location()); |
| 1064 | + } |
1036 | 1065 | else
|
1037 | 1066 | {
|
1038 | 1067 | throw errort().with_location(expr.find_source_location())
|
@@ -1061,30 +1090,36 @@ void smv_typecheckt::convert_expr_to(exprt &expr, const typet &type)
|
1061 | 1090 |
|
1062 | 1091 | if(expr.type() != type)
|
1063 | 1092 | {
|
1064 |
| - smv_ranget e=convert_type(expr.type()); |
1065 |
| - smv_ranget t=convert_type(type); |
1066 |
| - |
1067 |
| - if(e.is_contained_in(t) && expr.type().id() != ID_enumeration) |
| 1093 | + if(type.id() == ID_signedbv || type.id() == ID_unsignedbv) |
1068 | 1094 | {
|
1069 |
| - if(e.is_singleton()) |
| 1095 | + } |
| 1096 | + else |
| 1097 | + { |
| 1098 | + smv_ranget e = convert_type(expr.type()); |
| 1099 | + smv_ranget t = convert_type(type); |
| 1100 | + |
| 1101 | + if(e.is_contained_in(t) && expr.type().id() != ID_enumeration) |
1070 | 1102 | {
|
1071 |
| - if(type.id()==ID_bool) |
| 1103 | + if(e.is_singleton()) |
1072 | 1104 | {
|
1073 |
| - if(e.from==0) |
1074 |
| - expr=false_exprt(); |
| 1105 | + if(type.id() == ID_bool) |
| 1106 | + { |
| 1107 | + if(e.from == 0) |
| 1108 | + expr = false_exprt(); |
| 1109 | + else |
| 1110 | + expr = true_exprt(); |
| 1111 | + } |
1075 | 1112 | else
|
1076 |
| - expr=true_exprt(); |
| 1113 | + { |
| 1114 | + expr = exprt(ID_constant, type); |
| 1115 | + expr.set(ID_value, integer2string(e.from)); |
| 1116 | + } |
1077 | 1117 | }
|
1078 | 1118 | else
|
1079 |
| - { |
1080 |
| - expr=exprt(ID_constant, type); |
1081 |
| - expr.set(ID_value, integer2string(e.from)); |
1082 |
| - } |
1083 |
| - } |
1084 |
| - else |
1085 |
| - expr = typecast_exprt{expr, type}; |
| 1119 | + expr = typecast_exprt{expr, type}; |
1086 | 1120 |
|
1087 |
| - return; |
| 1121 | + return; |
| 1122 | + } |
1088 | 1123 | }
|
1089 | 1124 |
|
1090 | 1125 | throw errort().with_location(expr.find_source_location())
|
|
0 commit comments