Skip to content

Commit d8b909b

Browse files
committed
C++: __CPROVER_integer and __CPROVER_rational
This extends the C++ front-end to recognize __CPROVER_integer and __CPROVER_rational, in the same way as done in the C frontend.
1 parent 625df39 commit d8b909b

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/cpp/cpp_typecheck_conversions.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,12 +1451,36 @@ bool cpp_typecheckt::implicit_conversion_sequence(
14511451
{
14521452
rank=backup_rank;
14531453
if(!user_defined_conversion_sequence(e, type, new_expr, rank))
1454+
{
1455+
if(
1456+
type.id() == ID_integer &&
1457+
(expr.type().id() == ID_signedbv || expr.type().id() == ID_unsignedbv))
1458+
{
1459+
// This is a nonstandard implicit conversion, from
1460+
// bit-vectors to unbounded integers.
1461+
rank = 0;
1462+
new_expr = typecast_exprt(expr, type);
1463+
return true;
1464+
}
1465+
else if(
1466+
(type.id() == ID_signedbv || type.id() == ID_unsignedbv) &&
1467+
expr.type().id() == ID_integer)
1468+
{
1469+
// This is a nonstandard implicit conversion, from
1470+
// unbounded integers to bit-vectors.
1471+
rank = 0;
1472+
new_expr = typecast_exprt(expr, type);
1473+
return true;
1474+
}
1475+
1476+
// no conversion
14541477
return false;
1478+
}
14551479

1456-
#if 0
1480+
#if 0
14571481
simplify_exprt simplify(*this);
14581482
simplify.simplify(new_expr);
1459-
#endif
1483+
#endif
14601484
}
14611485

14621486
return true;

src/cpp/cpp_typecheck_type.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Author: Daniel Kroening, [email protected]
1010
/// C++ Language Type Checking
1111

1212
#include <util/c_types.h>
13+
#include <util/cprover_prefix.h>
14+
#include <util/mathematical_types.h>
1315
#include <util/simplify_expr.h>
1416
#include <util/source_location.h>
1517

@@ -69,6 +71,19 @@ void cpp_typecheckt::typecheck_type(typet &type)
6971
if(type.get_bool(ID_C_constant))
7072
qualifiers.is_constant = true;
7173

74+
// CPROVER extensions
75+
irep_idt typedef_identifier = type.get(ID_C_typedef);
76+
if(typedef_identifier == CPROVER_PREFIX "rational")
77+
{
78+
type = rational_typet();
79+
type.add_source_location() = symbol_expr.source_location();
80+
}
81+
else if(typedef_identifier == CPROVER_PREFIX "integer")
82+
{
83+
type = integer_typet();
84+
type.add_source_location() = symbol_expr.source_location();
85+
}
86+
7287
qualifiers.write(type);
7388
}
7489
else if(type.id()==ID_struct ||

0 commit comments

Comments
 (0)