@@ -1996,7 +1996,9 @@ codet java_bytecode_convert_methodt::convert_instructions(
1996
1996
const auto &field_name=arg0.get_string (ID_component_name);
1997
1997
const bool is_assertions_disabled_field=
1998
1998
field_name.find (" $assertionsDisabled" )!=std::string::npos;
1999
- symbol_expr.set_identifier (arg0.get_string (ID_class)+" ." +field_name);
1999
+
2000
+ symbol_expr.set_identifier (
2001
+ get_static_field (arg0.get_string (ID_class), field_name));
2000
2002
2001
2003
INVARIANT (
2002
2004
symbol_table.has_symbol (symbol_expr.get_identifier ()),
@@ -2025,6 +2027,9 @@ codet java_bytecode_convert_methodt::convert_instructions(
2025
2027
}
2026
2028
results[0 ]=java_bytecode_promotion (symbol_expr);
2027
2029
2030
+ // Note this initialiser call deliberately inits the class used to make
2031
+ // the reference, which may be a child of the class that actually defines
2032
+ // the field.
2028
2033
codet clinit_call=get_clinit_call (arg0.get_string (ID_class));
2029
2034
if (clinit_call.get_statement ()!=ID_skip)
2030
2035
c=clinit_call;
@@ -2052,7 +2057,8 @@ codet java_bytecode_convert_methodt::convert_instructions(
2052
2057
assert (op.size ()==1 && results.empty ());
2053
2058
symbol_exprt symbol_expr (arg0.type ());
2054
2059
const auto &field_name=arg0.get_string (ID_component_name);
2055
- symbol_expr.set_identifier (arg0.get_string (ID_class)+" ." +field_name);
2060
+ symbol_expr.set_identifier (
2061
+ get_static_field (arg0.get_string (ID_class), field_name));
2056
2062
2057
2063
INVARIANT (
2058
2064
symbol_table.has_symbol (symbol_expr.get_identifier ()),
@@ -2067,6 +2073,9 @@ codet java_bytecode_convert_methodt::convert_instructions(
2067
2073
code_blockt block;
2068
2074
block.add_source_location ()=i_it->source_location ;
2069
2075
2076
+ // Note this initialiser call deliberately inits the class used to make
2077
+ // the reference, which may be a child of the class that actually defines
2078
+ // the field.
2070
2079
codet clinit_call=get_clinit_call (arg0.get_string (ID_class));
2071
2080
if (clinit_call.get_statement ()!=ID_skip)
2072
2081
block.move_to_operands (clinit_call);
@@ -2822,6 +2831,30 @@ bool java_bytecode_convert_methodt::is_method_inherited(
2822
2831
return inherited_method.is_valid ();
2823
2832
}
2824
2833
2834
+ // / Get static field identifier referred to by `class_identifier.component_name`
2835
+ // / Note this may be inherited from either a parent or an interface.
2836
+ // / \param class_identifier: class used to refer to the field
2837
+ // / \param component_name: component (static field) name
2838
+ // / \return identifier of the actual concrete field referred to
2839
+ irep_idt java_bytecode_convert_methodt::get_static_field (
2840
+ const irep_idt &class_identifier,
2841
+ const irep_idt &component_name) const
2842
+ {
2843
+ resolve_inherited_componentt::inherited_componentt inherited_method =
2844
+ get_inherited_component (
2845
+ class_identifier,
2846
+ component_name,
2847
+ symbol_table.lookup_ref (current_method).type .get (ID_C_class),
2848
+ symbol_table,
2849
+ class_hierarchy,
2850
+ true );
2851
+
2852
+ INVARIANT (
2853
+ inherited_method.is_valid (), " static field should be in symbol table" );
2854
+
2855
+ return inherited_method.get_full_component_identifier ();
2856
+ }
2857
+
2825
2858
// / create temporary variables if a write instruction can have undesired side-
2826
2859
// / effects
2827
2860
void java_bytecode_convert_methodt::save_stack_entries (
0 commit comments