Skip to content

Commit 9f3333f

Browse files
Creates java_method_typet which extends code_typet
This is so that we do not need to have java-specific fields and related methods, like those relating to throws exceptions, in std_types
1 parent c5012ac commit 9f3333f

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,14 @@ void java_bytecode_convert_methodt::convert(
445445

446446
// Obtain a std::vector of code_typet::parametert objects from the
447447
// (function) type of the symbol
448-
code_typet code_type = to_code_type(method_symbol.type);
449-
code_type.set(ID_C_class, class_symbol.name);
450-
method_return_type = code_type.return_type();
451-
code_typet::parameterst &parameters = code_type.parameters();
448+
java_method_typet method_type = to_java_method_type(method_symbol.type);
449+
method_type.set(ID_C_class, class_symbol.name);
450+
method_return_type=method_type.return_type();
451+
code_typet::parameterst &parameters=method_type.parameters();
452452

453-
// Determine the number of local variable slots used by the JVM to maintan the
454-
// formal parameters
455-
slots_for_parameters = java_method_parameter_slots(code_type);
453+
// Determine the number of local variable slots used by the JVM to maintain
454+
// the formal parameters
455+
slots_for_parameters=java_method_parameter_slots(method_type);
456456

457457
debug() << "Generating codet: class " << class_symbol.name << ", method "
458458
<< m.name << eom;
@@ -584,11 +584,11 @@ void java_bytecode_convert_methodt::convert(
584584
method_symbol.location = m.source_location;
585585
method_symbol.location.set_function(method_identifier);
586586

587-
std::vector<irept> &exceptions_list = code_type.throws_exceptions();
587+
std::vector<irept> &exceptions_list = method_type.throws_exceptions();
588588
for(const auto &exception_name : m.throws_exception_table)
589589
exceptions_list.push_back(irept(exception_name));
590590

591-
const std::string signature_string = pretty_signature(code_type);
591+
const std::string signature_string = pretty_signature(method_type);
592592

593593
// Set up the pretty name for the method entry in the symbol table.
594594
// The pretty name of a constructor includes the base name of the class
@@ -602,7 +602,7 @@ void java_bytecode_convert_methodt::convert(
602602
method_symbol.pretty_name =
603603
id2string(class_symbol.pretty_name) + signature_string;
604604
INVARIANT(
605-
code_type.get_is_constructor(),
605+
method_type.get_is_constructor(),
606606
"Member type should have already been marked as a constructor");
607607
}
608608
else
@@ -611,14 +611,14 @@ void java_bytecode_convert_methodt::convert(
611611
id2string(m.base_name) + signature_string;
612612
}
613613

614-
method_symbol.type = code_type;
615-
614+
method_symbol.type = method_type;
615+
616616
current_method = method_symbol.name;
617-
method_has_this = code_type.has_this();
617+
method_has_this = method_type.has_this();
618618
if((!m.is_abstract) && (!m.is_native))
619619
method_symbol.value = convert_instructions(
620620
m,
621-
code_type,
621+
method_type,
622622
method_symbol.name,
623623
to_java_class_type(class_symbol.type).lambda_method_handles());
624624
}

jbmc/src/java_bytecode/java_types.h

+26
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,32 @@ inline bool can_cast_type<java_class_typet>(const typet &type)
242242
return can_cast_type<class_typet>(type);
243243
}
244244

245+
class java_method_typet:public code_typet
246+
{
247+
public:
248+
const std::vector<irept> &throws_exceptions() const
249+
{
250+
return find(ID_exceptions_thrown_list).get_sub();
251+
}
252+
253+
std::vector<irept> &throws_exceptions()
254+
{
255+
return add(ID_exceptions_thrown_list).get_sub();
256+
}
257+
};
258+
259+
inline const java_method_typet &to_java_method_type(const typet &type)
260+
{
261+
PRECONDITION(type.id() == ID_code);
262+
return static_cast<const java_method_typet &>(type);
263+
}
264+
265+
inline java_method_typet &to_java_method_type(typet &type)
266+
{
267+
PRECONDITION(type.id() == ID_code);
268+
return static_cast<java_method_typet &>(type);
269+
}
270+
245271
typet java_int_type();
246272
typet java_long_type();
247273
typet java_short_type();

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_attributes.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ SCENARIO(
610610
new_symbol_table.lookup_ref("java::ThrowsExceptions");
611611
const symbolt &method_symbol =
612612
new_symbol_table.lookup_ref("java::ThrowsExceptions.test:()V");
613-
const code_typet method = to_code_type(method_symbol.type);
613+
const java_method_typet method = to_java_method_type(method_symbol.type);
614614
const std::vector<irept> exceptions = method.throws_exceptions();
615615
REQUIRE(exceptions.size() == 2);
616616
REQUIRE(

src/util/std_types.h

-10
Original file line numberDiff line numberDiff line change
@@ -912,16 +912,6 @@ class code_typet:public typet
912912
return (parameterst &)add(ID_parameters).get_sub();
913913
}
914914

915-
const std::vector<irept> &throws_exceptions() const
916-
{
917-
return find(ID_exceptions_thrown_list).get_sub();
918-
}
919-
920-
std::vector<irept> &throws_exceptions()
921-
{
922-
return add(ID_exceptions_thrown_list).get_sub();
923-
}
924-
925915
bool get_inlined() const
926916
{
927917
return get_bool(ID_C_inlined);

0 commit comments

Comments
 (0)