Skip to content

Commit 0dcb773

Browse files
Change the step at which we replace String methods code
We now do this at the end of the bytecode conversion, in function java_bytecode_languaget::final instead of the middle of the conversion.
1 parent f4f4c44 commit 0dcb773

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/java_bytecode/java_bytecode_language.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,36 @@ void java_bytecode_languaget::convert_lazy_method(
799799

800800
/*******************************************************************\
801801
802+
Function: java_bytecode_languaget::replace_string_methods
803+
804+
Inputs:
805+
context - a symbol table
806+
807+
Purpose: Replace methods of the String library that are in the symbol table
808+
by code generated by string_preprocess.
809+
810+
\*******************************************************************/
811+
812+
void java_bytecode_languaget::replace_string_methods(
813+
symbol_tablet &context)
814+
{
815+
for(auto &id_symbol_pair : context.symbols)
816+
{
817+
const irep_idt &id=id_symbol_pair.first;
818+
symbolt &symbol=id_symbol_pair.second;
819+
if(symbol.type.id()==ID_code)
820+
{
821+
exprt generated_code=string_preprocess.code_for_function(
822+
id, to_code_type(symbol.type), symbol.location, context);
823+
if(generated_code.is_not_nil())
824+
// Replace body of the function by code generated by string preprocess
825+
symbol.value=generated_code;
826+
}
827+
}
828+
}
829+
830+
/*******************************************************************\
831+
802832
Function: java_bytecode_languaget::final
803833
804834
Inputs:
@@ -816,6 +846,9 @@ bool java_bytecode_languaget::final(symbol_tablet &symbol_table)
816846
*/
817847
java_internal_additions(symbol_table);
818848

849+
// Replace code of String methods calls by code we generate
850+
replace_string_methods(symbol_table);
851+
819852
main_function_resultt res=
820853
get_main_symbol(symbol_table, main_class, get_message_handler());
821854
if(res.stop_convert)

src/java_bytecode/java_bytecode_language.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class java_bytecode_languaget:public languaget
4949
symbol_tablet &context,
5050
const std::string &module) override;
5151

52+
void replace_string_methods(symbol_tablet &context);
53+
5254
virtual bool final(
5355
symbol_tablet &context) override;
5456

0 commit comments

Comments
 (0)