Skip to content

Commit e93eaae

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 6b280e6 commit e93eaae

File tree

4 files changed

+42
-26
lines changed

4 files changed

+42
-26
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+14-15
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,14 @@ void java_bytecode_convert_methodt::convert(
444444

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

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

456456
debug() << "Generating codet: class "
457457
<< class_symbol.name << ", method "
@@ -587,11 +587,11 @@ void java_bytecode_convert_methodt::convert(
587587
method_symbol.location=m.source_location;
588588
method_symbol.location.set_function(method_identifier);
589589

590-
std::vector<irept> &exceptions_list = code_type.throws_exceptions();
590+
std::vector<irept> &exceptions_list = method_type.throws_exceptions();
591591
for(const auto &exception_name : m.throws_exception_table)
592592
exceptions_list.push_back(irept(exception_name));
593593

594-
const std::string signature_string = pretty_signature(code_type);
594+
const std::string signature_string = pretty_signature(method_type);
595595

596596
// Set up the pretty name for the method entry in the symbol table.
597597
// The pretty name of a constructor includes the base name of the class
@@ -605,7 +605,7 @@ void java_bytecode_convert_methodt::convert(
605605
method_symbol.pretty_name =
606606
id2string(class_symbol.pretty_name) + signature_string;
607607
INVARIANT(
608-
code_type.get_is_constructor(),
608+
method_type.get_is_constructor(),
609609
"Member type should have already been marked as a constructor");
610610
}
611611
else
@@ -614,14 +614,13 @@ void java_bytecode_convert_methodt::convert(
614614
id2string(m.base_name) + signature_string;
615615
}
616616

617-
method_symbol.type = code_type;
618-
619-
current_method=method_symbol.name;
620-
method_has_this=code_type.has_this();
617+
method_symbol.type = method_type;
618+
current_method = method_symbol.name;
619+
method_has_this = method_type.has_this();
621620
if((!m.is_abstract) && (!m.is_native))
622621
method_symbol.value = convert_instructions(
623622
m,
624-
code_type,
623+
method_type,
625624
method_symbol.name,
626625
to_java_class_type(class_symbol.type).lambda_method_handles());
627626
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ 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 =
614+
to_java_method_type(method_symbol.type);
614615
const std::vector<irept> exceptions = method.throws_exceptions();
615616
REQUIRE(exceptions.size() == 2);
616617
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)