Skip to content

Commit b7cdfd3

Browse files
committed
take tautschnig's comments into account
1 parent b4ac05c commit b7cdfd3

15 files changed

+105
-135
lines changed

src/java_bytecode/expr2java.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1515
#include <util/arith_tools.h>
1616

1717
#include <ansi-c/c_qualifiers.h>
18+
#include <ansi-c/c_misc.h>
1819
#include <ansi-c/expr2c_class.h>
1920

2021
#include "java_types.h"
@@ -216,7 +217,8 @@ std::string expr2javat::convert_constant(
216217
dest.reserve(char_representation_length);
217218

218219
mp_integer int_value;
219-
to_integer(src, int_value);
220+
if(!to_integer(src, int_value))
221+
assert(false);
220222

221223
dest+="(char)'";
222224

@@ -238,7 +240,8 @@ std::string expr2javat::convert_constant(
238240
{
239241
// No byte-literals in Java, so just cast:
240242
mp_integer int_value;
241-
to_integer(src, int_value);
243+
if(!to_integer(src, int_value))
244+
assert(false);
242245
std::string dest="(byte)";
243246
dest+=integer2string(int_value);
244247
return dest;
@@ -247,7 +250,8 @@ std::string expr2javat::convert_constant(
247250
{
248251
// No short-literals in Java, so just cast:
249252
mp_integer int_value;
250-
to_integer(src, int_value);
253+
if(!to_integer(src, int_value))
254+
assert(false);
251255
std::string dest="(short)";
252256
dest+=integer2string(int_value);
253257
return dest;
@@ -482,7 +486,7 @@ std::string expr2javat::convert(
482486
const typet &type=ns.follow(src.type());
483487
if(src.id()=="java-this")
484488
return convert_java_this(src, precedence=15);
485-
if(src.id()=="java_instanceof")
489+
if(src.id()==ID_java_instanceof)
486490
return convert_java_instanceof(src, precedence=15);
487491
else if(src.id()==ID_side_effect &&
488492
(src.get(ID_statement)==ID_java_new ||
@@ -506,7 +510,7 @@ std::string expr2javat::convert(
506510
")";
507511
}
508512
else if(src.id()==ID_java_string_literal)
509-
return '"'+id2string(src.get(ID_value))+'"'; // TODO: add escaping as needed
513+
return '"'+MetaString(src.get_string(ID_value))+'"';
510514
else if(src.id()==ID_constant && (type.id()==ID_bool || type.id()==ID_c_bool))
511515
{
512516
if(src.is_true())

src/java_bytecode/expr2java.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ Author: Daniel Kroening, kroening@cs.cmu.edu
1212
#include <string>
1313
#include <ansi-c/expr2c_class.h>
1414

15-
class exprt;
16-
class namespacet;
17-
class typet;
18-
1915
class expr2javat:public expr2ct
2016
{
2117
public:
@@ -56,7 +52,8 @@ class expr2javat:public expr2ct
5652
const std::string &declarator);
5753

5854
// length of string representation of Java Char
59-
const std::size_t char_representation_length=14;
55+
// representation is '\u0000'
56+
const std::size_t char_representation_length=8;
6057
};
6158

6259
std::string expr2java(const exprt &expr, const namespacet &ns);

src/java_bytecode/java_bytecode_convert_class.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ void java_bytecode_convert_classt::generate_class_stub(
173173

174174
if(symbol_table.move(new_symbol, class_symbol))
175175
{
176-
warning() << "stub class symbol "+
177-
id2string(new_symbol.name)+" already exists";
176+
warning() << "stub class symbol " << new_symbol.name
177+
<< " already exists" << eom;
178178
}
179179
else
180180
{
@@ -225,10 +225,7 @@ void java_bytecode_convert_classt::convert(
225225
symbol_table.symbols.erase(s_it); // erase, we stubbed it
226226

227227
if(symbol_table.add(new_symbol))
228-
{
229-
error() << "failed to add static field symbol" << eom;
230-
throw 0;
231-
}
228+
assert(false && "failed to add static field symbol");
232229
}
233230
else
234231
{
@@ -276,6 +273,8 @@ void java_bytecode_convert_classt::add_array_types()
276273
// we have the base class, java.lang.Object, length and data
277274
// of appropriate type
278275
struct_type.set_tag(symbol_type.get_identifier());
276+
277+
struct_type.components().reserve(3);
279278
struct_typet::componentt
280279
comp0("@java.lang.Object", symbol_typet("java::java.lang.Object"));
281280
struct_type.components().push_back(comp0);

src/java_bytecode/java_bytecode_convert_method.cpp

+19-31
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Author: Daniel Kroening, kroening@kroening.com
2626
#include "java_bytecode_convert_method_class.h"
2727
#include "bytecode_info.h"
2828
#include "java_types.h"
29-
#include "java_utils.h"
3029

3130
#include <limits>
3231
#include <algorithm>
@@ -415,7 +414,7 @@ codet java_bytecode_convert_methodt::get_array_bounds_check(
415414
const exprt &idx,
416415
const source_locationt& original_sloc)
417416
{
418-
constant_exprt intzero=as_number(0, java_int_type());
417+
constant_exprt intzero=from_integer(0, java_int_type());
419418
binary_relation_exprt gezero(idx, ID_ge, intzero);
420419
const member_exprt length_field(arraystruct, "length", java_int_type());
421420
binary_relation_exprt ltlength(idx, ID_lt, length_field);
@@ -937,7 +936,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
937936
// The stack isn't modified.
938937
// TODO: convert assertions to exceptions.
939938
assert(op.size()==1 && results.size()==1);
940-
binary_predicate_exprt check(op[0], "java_instanceof", arg0);
939+
binary_predicate_exprt check(op[0], ID_java_instanceof, arg0);
941940
c=code_assertt(check);
942941
c.add_source_location().set_comment("Dynamic cast check");
943942
c.add_source_location().set_property_class("bad-dynamic-cast");
@@ -1011,12 +1010,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
10111010
}
10121011

10131012
code_function_callt call;
1014-
source_locationt loc;
1015-
loc=i_it->source_location;
1013+
source_locationt loc=i_it->source_location;
10161014
loc.set_function(method_id);
1017-
source_locationt &source_loc=loc;
10181015

1019-
call.add_source_location()=source_loc;
1016+
call.add_source_location()=loc;
10201017
call.arguments()=pop(parameters.size());
10211018

10221019
// double-check a bit
@@ -1089,7 +1086,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
10891086
call.function()=symbol_exprt(arg0.get(ID_identifier), arg0.type());
10901087
}
10911088

1092-
call.function().add_source_location()=source_loc;
1089+
call.function().add_source_location()=loc;
10931090
c=call;
10941091
}
10951092
else if(statement=="return")
@@ -1245,7 +1242,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
12451242
irep_idt number=to_constant_expr(arg0).get_value();
12461243
code_gotot code_goto(label(number));
12471244
c=code_goto;
1248-
results[0]=as_number(
1245+
results[0]=from_integer(
12491246
std::next(i_it)->address,
12501247
pointer_typet(void_typet(), 64));
12511248
}
@@ -1267,9 +1264,8 @@ codet java_bytecode_convert_methodt::convert_instructions(
12671264
branches.move_to_operands(g);
12681265
else
12691266
{
1270-
code_ifthenelset
1271-
branch;
1272-
auto address_ptr=as_number(
1267+
code_ifthenelset branch;
1268+
auto address_ptr=from_integer(
12731269
jsr_ret_targets[idx],
12741270
pointer_typet(void_typet(), 64));
12751271
branch.cond()=equal_exprt(retvar, address_ptr);
@@ -1311,9 +1307,9 @@ codet java_bytecode_convert_methodt::convert_instructions(
13111307
}
13121308
else
13131309
{
1314-
const size_t value(arg0.get_unsigned_int(ID_value));
1310+
const unsigned value(arg0.get_unsigned_int(ID_value));
13151311
const typet type=java_type_from_char(statement[0]);
1316-
results[0]=as_number(value, type);
1312+
results[0]=from_integer(value, type);
13171313
}
13181314
}
13191315
else if(statement==patternt("?ipush"))
@@ -1326,8 +1322,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
13261322
irep_idt number=to_constant_expr(arg0).get_value();
13271323
assert(op.size()==2 && results.empty());
13281324

1329-
code_ifthenelset
1330-
code_branch;
1325+
code_ifthenelset code_branch;
13311326
const irep_idt cmp_op=get_if_cmp_operator(statement);
13321327

13331328
binary_relation_exprt condition(op[0], cmp_op, op[1]);
@@ -1360,8 +1355,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
13601355
irep_idt number=to_constant_expr(arg0).get_value();
13611356
assert(op.size()==1 && results.empty());
13621357

1363-
code_ifthenelset
1364-
code_branch;
1358+
code_ifthenelset code_branch;
13651359
code_branch.cond()=
13661360
binary_relation_exprt(op[0], id, gen_zero(op[0].type()));
13671361
code_branch.cond().add_source_location()=i_it->source_location;
@@ -1378,8 +1372,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
13781372
{
13791373
irep_idt number=to_constant_expr(arg0).get_value();
13801374
assert(op.size()==1 && results.empty());
1381-
code_ifthenelset
1382-
code_branch;
1375+
code_ifthenelset code_branch;
13831376
const typecast_exprt lhs(op[0], pointer_typet(empty_typet()));
13841377
const exprt rhs(gen_zero(lhs.type()));
13851378
code_branch.cond()=binary_relation_exprt(lhs, ID_notequal, rhs);
@@ -1393,8 +1386,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
13931386
{
13941387
assert(op.size()==1 && results.empty());
13951388
irep_idt number=to_constant_expr(arg0).get_value();
1396-
code_ifthenelset
1397-
code_branch;
1389+
code_ifthenelset code_branch;
13981390
const typecast_exprt lhs(op[0], pointer_typet(empty_typet()));
13991391
const exprt rhs(gen_zero(lhs.type()));
14001392
code_branch.cond()=binary_relation_exprt(lhs, ID_equal, rhs);
@@ -1506,7 +1498,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
15061498
results[0]=
15071499
if_exprt(
15081500
binary_relation_exprt(op[0], ID_equal, op[1]),
1509-
gen_zero(t),
1501+
from_integer(0, t),
15101502
greater);
15111503
}
15121504
else if(statement==patternt("?cmp?"))
@@ -1637,11 +1629,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
16371629

16381630
// set $assertionDisabled to false
16391631
if(field_name.find("$assertionsDisabled")!=std::string::npos)
1640-
{
1641-
exprt e;
1642-
e.make_false();
1643-
c=code_assignt(symbol_expr, e);
1644-
}
1632+
c=code_assignt(symbol_expr, false_exprt());
16451633
}
16461634
else if(statement=="putfield")
16471635
{
@@ -1721,7 +1709,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
17211709
if(!disable_runtime_checks)
17221710
{
17231711
// TODO make this throw NegativeArrayIndexException instead.
1724-
constant_exprt intzero=as_number(0, java_int_type());
1712+
constant_exprt intzero=from_integer(0, java_int_type());
17251713
binary_relation_exprt gezero(op[0], ID_ge, intzero);
17261714
code_assertt check(gezero);
17271715
check.add_source_location().set_comment("Array size < 0");
@@ -1731,7 +1719,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
17311719
}
17321720
if(max_array_length!=0)
17331721
{
1734-
constant_exprt size_limit=as_number(max_array_length, java_int_type());
1722+
constant_exprt size_limit=from_integer(max_array_length, java_int_type());
17351723
binary_relation_exprt le_max_size(op[0], ID_le, size_limit);
17361724
code_assumet assume_le_max_size(le_max_size);
17371725
c.move_to_operands(assume_le_max_size);
@@ -1750,7 +1738,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
17501738
op=pop(dimension);
17511739
assert(results.size()==1);
17521740

1753-
const pointer_typet ref_type=pointer_typet(arg0.type());
1741+
const pointer_typet ref_type(arg0.type());
17541742

17551743
side_effect_exprt java_new_array(ID_java_new_array, ref_type);
17561744
java_new_array.operands()=op;

src/java_bytecode/java_bytecode_language.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Author: Daniel Kroening, kroening@kroening.com
1414

1515
#include "java_class_loader.h"
1616

17+
#define MAX_NONDET_ARRAY_LENGTH_DEFAULT 5
18+
1719
class java_bytecode_languaget:public languaget
1820
{
1921
public:
@@ -39,7 +41,7 @@ class java_bytecode_languaget:public languaget
3941

4042
virtual ~java_bytecode_languaget();
4143
java_bytecode_languaget():
42-
max_nondet_array_length(5),
44+
max_nondet_array_length(MAX_NONDET_ARRAY_LENGTH_DEFAULT),
4345
max_user_array_length(0) { }
4446

4547
bool from_expr(

src/java_bytecode/java_bytecode_parser.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1449,16 +1449,16 @@ void java_bytecode_parsert::rclass_attribute(classt &parsed_class)
14491449
u2 sourcefile_index=read_u2();
14501450
irep_idt sourcefile_name;
14511451

1452-
std::string fqn=std::string(id2string(parsed_class.name));
1452+
std::string fqn(id2string(parsed_class.name));
14531453
size_t last_index=fqn.find_last_of(".");
14541454
if(last_index==std::string::npos)
14551455
sourcefile_name=pool_entry(sourcefile_index).s;
14561456
else
14571457
{
14581458
std::string packageName=fqn.substr(0, last_index+1);
14591459
std::replace(packageName.begin(), packageName.end(), '.', '/');
1460-
const std::string &fullFileName=
1461-
std::string(packageName+id2string(pool_entry(sourcefile_index).s));
1460+
const std::string
1461+
&fullFileName=(packageName+id2string(pool_entry(sourcefile_index).s));
14621462
sourcefile_name=fullFileName;
14631463
}
14641464

src/java_bytecode/java_bytecode_typecheck_expr.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ void java_bytecode_typecheckt::typecheck_expr_java_new_array(
9393

9494
static void escape_non_alnum(std::string& toescape)
9595
{
96-
for(size_t idx=0, lim=toescape.size(); idx!=lim; ++idx)
97-
if(!isalnum(toescape[idx]))
98-
toescape[idx]='_';
96+
for(auto &ch : toescape)
97+
if(!isalnum(ch))
98+
ch='_';
9999
}
100100

101101
/*******************************************************************\

0 commit comments

Comments
 (0)