Skip to content

Commit 9de8f23

Browse files
Extract convert_const function
1 parent 5480592 commit 9de8f23

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

+40-32
Original file line numberDiff line numberDiff line change
@@ -1312,38 +1312,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
13121312
else if(statement==patternt("?const"))
13131313
{
13141314
assert(results.size()==1);
1315-
1316-
const char type_char=statement[0];
1317-
const bool is_double('d'==type_char);
1318-
const bool is_float('f'==type_char);
1319-
1320-
if(is_double || is_float)
1321-
{
1322-
const ieee_float_spect spec(
1323-
is_float?ieee_float_spect::single_precision():
1324-
ieee_float_spect::double_precision());
1325-
1326-
ieee_floatt value(spec);
1327-
if(arg0.type().id()!=ID_floatbv)
1328-
{
1329-
mp_integer number;
1330-
bool ret=to_integer(to_constant_expr(arg0), number);
1331-
DATA_INVARIANT(!ret, "failed to convert constant");
1332-
value.from_integer(number);
1333-
}
1334-
else
1335-
value.from_expr(to_constant_expr(arg0));
1336-
1337-
results[0]=value.to_expr();
1338-
}
1339-
else
1340-
{
1341-
mp_integer value;
1342-
bool ret=to_integer(to_constant_expr(arg0), value);
1343-
DATA_INVARIANT(!ret, "failed to convert constant");
1344-
const typet type=java_type_from_char(statement[0]);
1345-
results[0]=from_integer(value, type);
1346-
}
1315+
results = convert_const(statement, arg0, results);
13471316
}
13481317
else if(statement==patternt("?ipush"))
13491318
{
@@ -1974,6 +1943,45 @@ codet java_bytecode_convert_methodt::convert_instructions(
19741943
return code;
19751944
}
19761945

1946+
exprt::operandst &java_bytecode_convert_methodt::convert_const(
1947+
const irep_idt &statement,
1948+
exprt &arg0,
1949+
exprt::operandst &results) const
1950+
{
1951+
const char type_char = statement[0];
1952+
const bool is_double('d' == type_char);
1953+
const bool is_float('f' == type_char);
1954+
1955+
if(is_double || is_float)
1956+
{
1957+
const ieee_float_spect spec(
1958+
is_float ? ieee_float_spect::single_precision()
1959+
: ieee_float_spect::double_precision());
1960+
1961+
ieee_floatt value(spec);
1962+
if(arg0.type().id() != ID_floatbv)
1963+
{
1964+
mp_integer number;
1965+
bool ret = to_integer(to_constant_expr(arg0), number);
1966+
DATA_INVARIANT(!ret, "failed to convert constant");
1967+
value.from_integer(number);
1968+
}
1969+
else
1970+
value.from_expr(to_constant_expr(arg0));
1971+
1972+
results[0] = value.to_expr();
1973+
}
1974+
else
1975+
{
1976+
mp_integer value;
1977+
bool ret = to_integer(to_constant_expr(arg0), value);
1978+
DATA_INVARIANT(!ret, "failed to convert constant");
1979+
const typet type = java_type_from_char(statement[0]);
1980+
results[0] = from_integer(value, type);
1981+
}
1982+
return results;
1983+
}
1984+
19771985
void java_bytecode_convert_methodt::convert_invoke(
19781986
const std::vector<java_bytecode_parse_treet::instructiont>::const_iterator
19791987
&i_it,

src/java_bytecode/java_bytecode_convert_method_class.h

+5
Original file line numberDiff line numberDiff line change
@@ -449,5 +449,10 @@ class java_bytecode_convert_methodt:public messaget
449449
exprt &arg0,
450450
codet &c,
451451
exprt::operandst &results);
452+
453+
exprt::operandst &convert_const(
454+
const irep_idt &statement,
455+
exprt &arg0,
456+
exprt::operandst &results) const;
452457
};
453458
#endif

0 commit comments

Comments
 (0)