File tree 4 files changed +27
-19
lines changed
4 files changed +27
-19
lines changed Original file line number Diff line number Diff line change @@ -999,24 +999,6 @@ static unsigned get_bytecode_type_width(const typet &ty)
999
999
return ty.get_unsigned_int (ID_width);
1000
1000
}
1001
1001
1002
- // / Merge code's source location with source_location, and recursively
1003
- // / do the same to operand code. Typically this is used for a code_blockt
1004
- // / as is generated for some Java operations such as "putstatic", but will
1005
- // / also work if they generate conditionals, loops, etc.
1006
- // / Merge means that any fields already set in code.add_source_location()
1007
- // / remain so; any new ones from source_location are added.
1008
- static void merge_source_location_rec (
1009
- codet &code,
1010
- const source_locationt &source_location)
1011
- {
1012
- code.add_source_location ().merge (source_location);
1013
- for (exprt &op : code.operands ())
1014
- {
1015
- if (op.id ()==ID_code)
1016
- merge_source_location_rec (to_code (op), source_location);
1017
- }
1018
- }
1019
-
1020
1002
codet java_bytecode_convert_methodt::convert_instructions (
1021
1003
const methodt &method,
1022
1004
const code_typet &method_type,
Original file line number Diff line number Diff line change @@ -305,6 +305,7 @@ codet java_bytecode_instrumentt::check_array_length(
305
305
void java_bytecode_instrumentt::instrument_code (exprt &expr)
306
306
{
307
307
codet &code=to_code (expr);
308
+ source_locationt old_source_location=code.source_location ();
308
309
309
310
const irep_idt &statement=code.get_statement ();
310
311
@@ -408,6 +409,10 @@ void java_bytecode_instrumentt::instrument_code(exprt &expr)
408
409
block.copy_to_operands (code);
409
410
code=block;
410
411
}
412
+
413
+ // Ensure source location is retained:
414
+ if (!old_source_location.get_line ().empty ())
415
+ merge_source_location_rec (code, old_source_location);
411
416
}
412
417
413
418
// / Computes the instrumentation for `expr` in the form of
Original file line number Diff line number Diff line change @@ -55,7 +55,6 @@ unsigned java_method_parameter_slots(const code_typet &t)
55
55
return slots;
56
56
}
57
57
58
-
59
58
const std::string java_class_to_package (const std::string &canonical_classname)
60
59
{
61
60
return trim_from_last_delimiter (canonical_classname, ' .' );
@@ -99,3 +98,12 @@ void generate_class_stub(
99
98
java_root_class (*class_symbol);
100
99
}
101
100
}
101
+
102
+ void merge_source_location_rec (
103
+ exprt &expr,
104
+ const source_locationt &source_location)
105
+ {
106
+ expr.add_source_location ().merge (source_location);
107
+ for (exprt &op : expr.operands ())
108
+ merge_source_location_rec (op, source_location);
109
+ }
Original file line number Diff line number Diff line change @@ -32,4 +32,17 @@ unsigned java_method_parameter_slots(const code_typet &t);
32
32
33
33
const std::string java_class_to_package (const std::string &canonical_classname);
34
34
35
+ // / Attaches a source location to an expression and all of its subexpressions.
36
+ // / Usually only codet needs this, but there are a few known examples of
37
+ // / expressions needing a location, such as
38
+ // / `goto_convertt::do_function_call_symbol` (function() needs a location)
39
+ // / and `goto_convertt::clean_expr` (any subexpression being split into a
40
+ // / separate instruction needs a location), so for safety we give every
41
+ // / mentioned expression a location.
42
+ // / Any code or expressions with source location fields already set keep those
43
+ // / fields using rules of source_locationt::merge.
44
+ void merge_source_location_rec (
45
+ exprt &expr,
46
+ const source_locationt &source_location);
47
+
35
48
#endif // CPROVER_JAVA_BYTECODE_JAVA_UTILS_H
You can’t perform that action at this time.
0 commit comments