@@ -2844,6 +2844,96 @@ codet java_bytecode_convert_methodt::convert_instructions(
2844
2844
return code;
2845
2845
}
2846
2846
2847
+ // / This uses a cut-down version of the logic in
2848
+ // / java_bytecode_convert_methodt::convert to initialize symbols for the
2849
+ // / parameters and update the parameters in the type of method_symbol with
2850
+ // / names read from the local_variable_table read from the bytecode
2851
+ // / \remarks This is useful for pre-initialization for methods generated by
2852
+ // / the string solver
2853
+ // / \param method_symbol: The symbol for the method for which to initialize the
2854
+ // / parameters
2855
+ // / \param local_variable_table: The local variable table containing the
2856
+ // / bytecode for the parameters
2857
+ // / \param symbol_table: The symbol table into which to insert symbols for the
2858
+ // / parameters
2859
+ void java_bytecode_initialize_parameter_names (
2860
+ symbolt &method_symbol,
2861
+ const java_bytecode_parse_treet::methodt::local_variable_tablet
2862
+ &local_variable_table,
2863
+ symbol_table_baset &symbol_table)
2864
+ {
2865
+ // Obtain a std::vector of code_typet::parametert objects from the
2866
+ // (function) type of the symbol
2867
+ code_typet &code_type = to_code_type (method_symbol.type );
2868
+ code_typet::parameterst ¶meters = code_type.parameters ();
2869
+
2870
+ // Find number of parameters
2871
+ unsigned slots_for_parameters = java_method_parameter_slots (code_type);
2872
+
2873
+ // Find parameter names in the local variable table:
2874
+ typedef std::pair<irep_idt, irep_idt> base_name_and_identifiert;
2875
+ std::map<std::size_t , base_name_and_identifiert> param_names;
2876
+ for (const auto &v : local_variable_table)
2877
+ {
2878
+ if (v.index < slots_for_parameters)
2879
+ param_names.emplace (
2880
+ v.index ,
2881
+ make_pair (
2882
+ v.name , id2string (method_symbol.name ) + " ::" + id2string (v.name )));
2883
+ }
2884
+
2885
+ // Assign names to parameters
2886
+ std::size_t param_index = 0 ;
2887
+ for (auto ¶m : parameters)
2888
+ {
2889
+ irep_idt base_name, identifier;
2890
+
2891
+ // Construct a sensible base name (base_name) and a fully qualified name
2892
+ // (identifier) for every parameter of the method under translation,
2893
+ // regardless of whether we have an LVT or not; and assign it to the
2894
+ // parameter object (which is stored in the type of the symbol, not in the
2895
+ // symbol table)
2896
+ if (param_index == 0 && param.get_this ())
2897
+ {
2898
+ // my.package.ClassName.myMethodName:(II)I::this
2899
+ base_name = " this" ;
2900
+ identifier = id2string (method_symbol.name ) + " ::" + id2string (base_name);
2901
+ }
2902
+ else
2903
+ {
2904
+ auto param_name = param_names.find (param_index);
2905
+ if (param_name != param_names.end ())
2906
+ {
2907
+ base_name = param_name->second .first ;
2908
+ identifier = param_name->second .second ;
2909
+ }
2910
+ else
2911
+ {
2912
+ // my.package.ClassName.myMethodName:(II)I::argNT, where N is the local
2913
+ // variable slot where the parameter is stored and T is a character
2914
+ // indicating the type
2915
+ const typet &type = param.type ();
2916
+ char suffix = java_char_from_type (type);
2917
+ base_name = " arg" + std::to_string (param_index) + suffix;
2918
+ identifier =
2919
+ id2string (method_symbol.name ) + " ::" + id2string (base_name);
2920
+ }
2921
+ }
2922
+ param.set_base_name (base_name);
2923
+ param.set_identifier (identifier);
2924
+
2925
+ // Build a new symbol for the parameter and add it to the symbol table
2926
+ parameter_symbolt parameter_symbol;
2927
+ parameter_symbol.base_name = base_name;
2928
+ parameter_symbol.mode = ID_java;
2929
+ parameter_symbol.name = identifier;
2930
+ parameter_symbol.type = param.type ();
2931
+ symbol_table.insert (parameter_symbol);
2932
+
2933
+ param_index += java_local_variable_slots (param.type ());
2934
+ }
2935
+ }
2936
+
2847
2937
void java_bytecode_convert_method (
2848
2938
const symbolt &class_symbol,
2849
2939
const java_bytecode_parse_treet::methodt &method,
0 commit comments