Skip to content

Commit 3146679

Browse files
committed
Requested updates in the review of the PR diffblue#133.
1 parent f6e43b5 commit 3146679

File tree

3 files changed

+47
-77
lines changed

3 files changed

+47
-77
lines changed

src/taint-slicer/instrumentation_props.cpp

Lines changed: 39 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -23,90 +23,52 @@ instrumentation_props data structure.
2323

2424
#include <taint-slicer/instrumentation_props.h>
2525
#include <goto-programs/remove_returns.h>
26+
#include <java_bytecode/java_types.h>
27+
#include <java_bytecode/expr2java.h>
2628
#include <util/prefix.h>
2729
#include <util/msgstream.h>
2830
#include <deque>
2931

30-
static std::string parse_type_name(const typet &type)
32+
bool is_primitive_type_name(const std::string &datatype, const namespacet &ns)
3133
{
32-
const typet * restype = &type;
33-
if(type.id()==ID_pointer)
34-
restype=&to_pointer_type(type).subtype();
35-
else if(type.id()==ID_array)
36-
restype=&to_array_type(type).subtype();
37-
if(restype->id()==ID_signedbv)
38-
{
39-
const signedbv_typet &sbv=to_signedbv_type(*restype);
40-
if(sbv.get_width()==8UL)
41-
return as_string(ID_char);
42-
if(sbv.get_width()==16UL)
43-
return as_string(ID_short);
44-
if(sbv.get_width()==32UL)
45-
return as_string(ID_int);
46-
if(sbv.get_width()==64UL)
47-
return as_string(ID_long);
48-
throw std::logic_error(
49-
msgstream() << "ERROR: unexpected bit-width '"
50-
<< sbv.get_width() << "' of signedbv type. Valid sizes "
51-
<< "are 8, 16, 32, and 64.");
52-
}
53-
if(restype->id()==ID_unsignedbv)
54-
{
55-
const unsignedbv_typet &ubv=to_unsignedbv_type(*restype);
56-
if(ubv.get_width()==8UL)
57-
return as_string(ID_byte);
58-
if(ubv.get_width()==16UL)
59-
return as_string(ID_unsigned_short_int);
60-
if(ubv.get_width()==32UL)
61-
return as_string(ID_unsigned_int);
62-
if(ubv.get_width()==64UL)
63-
return as_string(ID_unsigned_long_int);
64-
throw std::logic_error(
65-
msgstream() << "ERROR: unexpected bit-width '"
66-
<< ubv.get_width() << "' of unsignedbv type. Valid "
67-
<< "sizes are 8, 16, 32 and 64.");
68-
}
69-
if(restype->id()!=ID_symbol)
70-
throw std::logic_error(
71-
msgstream() << "ERROR: expecting the '"
72-
<< as_string(ID_symbol) << "' type id, but received '"
73-
<< as_string(restype->id()) << "'.");
74-
return as_string(to_symbol_type(*restype).get_identifier());
34+
return datatype==type2java(java_boolean_type(), ns) ||
35+
datatype==type2java(java_boolean_type(), ns) ||
36+
datatype==type2java(java_byte_type(), ns) ||
37+
datatype==type2java(java_char_type(), ns) ||
38+
datatype==type2java(java_short_type(), ns) ||
39+
datatype==type2java(java_int_type(), ns) ||
40+
datatype==type2java(java_long_type(), ns) ||
41+
datatype==type2java(java_float_type(), ns) ||
42+
datatype==type2java(java_double_type(), ns) ;
7543
}
7644

77-
bool is_primitive_type_name(const std::string &datatype)
45+
static std::string parse_type_name(const typet &type, const namespacet &ns)
7846
{
79-
static const std::set<std::string> names=
80-
{
81-
as_string(ID_bool),
82-
as_string(ID_byte),
83-
as_string(ID_char),
84-
as_string(ID_unsigned_char),
85-
as_string(ID_short),
86-
as_string(ID_unsigned_short_int),
87-
as_string(ID_int),
88-
as_string(ID_unsigned_int),
89-
as_string(ID_long),
90-
as_string(ID_unsigned_long_int),
91-
as_string(ID_unsigned_long_long_int),
92-
as_string(ID_unsigned_int128),
93-
as_string(ID_float),
94-
as_string(ID_double),
95-
as_string(ID_long_double)
96-
};
97-
return names.count(datatype)==1UL;
47+
if(type.id()==ID_pointer)
48+
return parse_type_name(to_pointer_type(type).subtype(), ns);
49+
if(type.id()==ID_array)
50+
return parse_type_name(to_array_type(type).subtype(), ns);
51+
if(type.id()==ID_symbol)
52+
return as_string(to_symbol_type(type).get_identifier());
53+
const std::string result=type2java(type, ns);
54+
if(!is_primitive_type_name(result, ns))
55+
throw std::logic_error(
56+
msgstream() << "ERROR: expecting a primitive data type, "
57+
"but received '" << result << "'.");
58+
return result;
9859
}
9960

10061
bool is_java_array_type_name(const std::string &datatype)
10162
{
10263
return has_prefix(datatype, "java::array[") && *datatype.rbegin()==']';
10364
}
10465

105-
bool does_instrumentation_of_type_require_subclass(const std::string &datatype)
66+
bool does_instrumentation_of_type_require_subclass(
67+
const std::string &datatype, const namespacet &ns)
10668
{
107-
return is_primitive_type_name(datatype) ||
108-
is_java_array_type_name(datatype)
109-
|| datatype=="java::java.lang.Object";
69+
return is_primitive_type_name(datatype, ns) ||
70+
is_java_array_type_name(datatype) ||
71+
datatype=="java::java.lang.Object";
11072
}
11173

11274
static std::string get_return_type_name_from_function_name(
@@ -116,7 +78,7 @@ static std::string get_return_type_name_from_function_name(
11678
typet t=symbol_table.lookup(fname+RETURN_VALUE_SUFFIX).type;
11779
if(t.id()==ID_pointer)
11880
t=to_pointer_type(t).subtype();
119-
return parse_type_name(t);
81+
return parse_type_name(t, namespacet(symbol_table));
12082
}
12183

12284
/*******************************************************************\
@@ -254,9 +216,10 @@ void taint_instrumentation_propst::build_map_from_typenames_to_tokennames(
254216
else
255217
{
256218
datatype=parse_type_name(
257-
fn_type.parameters().at(arg_token.get_argidx()).type());
219+
fn_type.parameters().at(arg_token.get_argidx()).type(),
220+
program.get_namespace());
258221
}
259-
assert(is_primitive_type_name(datatype)
222+
assert(is_primitive_type_name(datatype, program.get_namespace())
260223
|| program.get_symbol_table().has_symbol(datatype));
261224
datatypes[datatype].insert(arg_token.get_token_name());
262225
}
@@ -374,7 +337,10 @@ void taint_build_instrumentation_props(
374337
}
375338
}
376339

377-
void dump_as_json(const taint_instrumentation_propst &props, json_objectt &out)
340+
void dump_as_json(
341+
const taint_instrumentation_propst &props,
342+
json_objectt &out,
343+
const namespacet &ns)
378344
{
379345
{
380346
json_arrayt out_types;
@@ -386,7 +352,7 @@ void dump_as_json(const taint_instrumentation_propst &props, json_objectt &out)
386352
json_objectt out_type_props;
387353
out_type_props["type_name"]=json_stringt(elem.first);
388354
out_type_props["shadow_vars"]=out_tokens;
389-
if(does_instrumentation_of_type_require_subclass(elem.first))
355+
if(does_instrumentation_of_type_require_subclass(elem.first, ns))
390356
out_type_props["make_subclass"]=json_truet();
391357
else
392358
out_type_props["make_subclass"]=json_falset();

src/taint-slicer/instrumentation_props.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ void taint_build_instrumentation_props(
125125
std::vector<taint_instrumentation_propst> &output);
126126

127127

128-
bool is_primitive_type_name(const std::string &datatype);
128+
bool is_primitive_type_name(const std::string &datatype, const namespacet &ns);
129129
bool is_java_array_type_name(const std::string &datatype);
130-
bool does_instrumentation_of_type_require_subclass(const std::string &datatype);
130+
bool does_instrumentation_of_type_require_subclass(
131+
const std::string &datatype, const namespacet &ns);
131132

132-
void dump_as_json(const taint_instrumentation_propst &props, json_objectt &out);
133+
void dump_as_json(
134+
const taint_instrumentation_propst &props,
135+
json_objectt &out,
136+
const namespacet &ns);
133137

134138
#endif

src/taint-slicer/slicer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void taint_slicert::compute_slice()
9494
for(std::size_t i=0U; i!=instrumentation_props.size(); ++i)
9595
{
9696
json_objectt jobj;
97-
dump_as_json(instrumentation_props.at(i),jobj);
97+
dump_as_json(instrumentation_props.at(i), jobj, program->get_namespace());
9898
std::ofstream ostr(
9999
fileutl_concatenate_file_paths(
100100
results_dir,

0 commit comments

Comments
 (0)