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 @@ -998,24 +998,6 @@ static unsigned get_bytecode_type_width(const typet &ty)
998
998
return ty.get_unsigned_int (ID_width);
999
999
}
1000
1000
1001
- // / Merge code's source location with source_location, and recursively
1002
- // / do the same to operand code. Typically this is used for a code_blockt
1003
- // / as is generated for some Java operations such as "putstatic", but will
1004
- // / also work if they generate conditionals, loops, etc.
1005
- // / Merge means that any fields already set in code.add_source_location()
1006
- // / remain so; any new ones from source_location are added.
1007
- static void merge_source_location_rec (
1008
- codet &code,
1009
- const source_locationt &source_location)
1010
- {
1011
- code.add_source_location ().merge (source_location);
1012
- for (exprt &op : code.operands ())
1013
- {
1014
- if (op.id ()==ID_code)
1015
- merge_source_location_rec (to_code (op), source_location);
1016
- }
1017
- }
1018
-
1019
1001
codet java_bytecode_convert_methodt::convert_instructions (
1020
1002
const methodt &method,
1021
1003
const code_typet &method_type,
Original file line number Diff line number Diff line change @@ -300,6 +300,7 @@ codet java_bytecode_instrumentt::check_array_length(
300
300
void java_bytecode_instrumentt::instrument_code (exprt &expr)
301
301
{
302
302
codet &code=to_code (expr);
303
+ source_locationt old_source_location=code.source_location ();
303
304
304
305
const irep_idt &statement=code.get_statement ();
305
306
@@ -405,6 +406,10 @@ void java_bytecode_instrumentt::instrument_code(exprt &expr)
405
406
block.copy_to_operands (code);
406
407
code=block;
407
408
}
409
+
410
+ // Ensure source location is retained:
411
+ if (!old_source_location.get_line ().empty ())
412
+ merge_source_location_rec (code, old_source_location);
408
413
}
409
414
410
415
// / 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