Skip to content

Commit 6dde5dc

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 94bc851 commit 6dde5dc

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 11 additions & 11 deletions
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

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

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

590-
code_typet::exceptionst &exceptions_list = code_type.throws_exceptions();
590+
java_method_typet::exceptionst &exceptions_list = method_type.throws_exceptions();
591591
for(const auto &p : m.throws_exception_table)
592592
{
593593
if(!p.empty())
594594
exceptions_list.push_back(irept(p));
595595
}
596596

597-
const std::string signature_string = pretty_signature(code_type);
597+
const std::string signature_string = pretty_signature(method_type);
598598

599599
// Set up the pretty name for the method entry in the symbol table.
600600
// The pretty name of a constructor includes the base name of the class
@@ -608,7 +608,7 @@ void java_bytecode_convert_methodt::convert(
608608
method_symbol.pretty_name =
609609
id2string(class_symbol.pretty_name) + signature_string;
610610
INVARIANT(
611-
code_type.get_is_constructor(),
611+
method_type.get_is_constructor(),
612612
"Member type should have already been marked as a constructor");
613613
}
614614
else
@@ -617,14 +617,14 @@ void java_bytecode_convert_methodt::convert(
617617
id2string(m.base_name) + signature_string;
618618
}
619619

620-
method_symbol.type = code_type;
620+
method_symbol.type = method_type;
621621

622622
current_method=method_symbol.name;
623-
method_has_this=code_type.has_this();
623+
method_has_this=method_type.has_this();
624624
if((!m.is_abstract) && (!m.is_native))
625625
method_symbol.value = convert_instructions(
626626
m,
627-
code_type,
627+
method_type,
628628
method_symbol.name,
629629
to_java_class_type(class_symbol.type).lambda_method_handles());
630630
}

jbmc/src/java_bytecode/java_types.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,33 @@ 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+
typedef std::vector<irept> exceptionst;
249+
const exceptionst &throws_exceptions() const
250+
{
251+
return find(ID_exceptions_thrown_list).get_sub();
252+
}
253+
254+
exceptionst &throws_exceptions()
255+
{
256+
return add(ID_exceptions_thrown_list).get_sub();
257+
}
258+
};
259+
260+
inline const java_method_typet &to_java_method_type(const typet &type)
261+
{
262+
assert(type.id()==ID_code);
263+
return static_cast<const java_method_typet &>(type);
264+
}
265+
266+
inline java_method_typet &to_java_method_type(typet &type)
267+
{
268+
assert(type.id()==ID_code);
269+
return static_cast<java_method_typet &>(type);
270+
}
271+
245272
typet java_int_type();
246273
typet java_long_type();
247274
typet java_short_type();

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_attributes.cpp

Lines changed: 1 addition & 1 deletion
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(id2string(exceptions.at(0).id()) == "CustomException");
616616
REQUIRE(id2string(exceptions.at(1).id()) == "java.io.IOException");

src/util/std_types.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,6 @@ class code_typet:public typet
767767
class parametert;
768768
typedef std::vector<parametert> parameterst;
769769

770-
typedef std::vector<irept> exceptionst;
771-
772770
/// Constructs a new code type, i.e. function type
773771
/// \param _parameters: the vector of function parameters
774772
/// \param _return_type: the return type
@@ -914,16 +912,6 @@ class code_typet:public typet
914912
return (parameterst &)add(ID_parameters).get_sub();
915913
}
916914

917-
const exceptionst &throws_exceptions() const
918-
{
919-
return find(ID_exceptions_thrown_list).get_sub();
920-
}
921-
922-
exceptionst &throws_exceptions()
923-
{
924-
return add(ID_exceptions_thrown_list).get_sub();
925-
}
926-
927915
bool get_inlined() const
928916
{
929917
return get_bool(ID_C_inlined);

0 commit comments

Comments
 (0)