Skip to content

Commit ac38580

Browse files
Add can_cast_type and precondition.
Also removes an irrelevant unit test due to this change.
1 parent 85cff2c commit ac38580

File tree

4 files changed

+14
-41
lines changed

4 files changed

+14
-41
lines changed

jbmc/src/java_bytecode/java_types.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,21 @@ class java_method_typet : public code_typet
280280
}
281281
};
282282

283+
template <>
284+
inline bool can_cast_type<java_method_typet>(const typet &type)
285+
{
286+
return type.id() == ID_code && type.get_bool(ID_C_java_method_type);
287+
}
288+
283289
inline const java_method_typet &to_java_method_type(const typet &type)
284290
{
285-
PRECONDITION(type.id() == ID_code);
291+
PRECONDITION(can_cast_type<java_method_typet>(type));
286292
return static_cast<const java_method_typet &>(type);
287293
}
288294

289295
inline java_method_typet &to_java_method_type(typet &type)
290296
{
291-
PRECONDITION(type.id() == ID_code);
292-
type.set(ID_C_java_method_type, true);
297+
PRECONDITION(can_cast_type<java_method_typet>(type));
293298
return static_cast<java_method_typet &>(type);
294299
}
295300

jbmc/unit/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ SRC += java_bytecode/goto-programs/class_hierarchy_output.cpp \
2121
java_bytecode/java_types/erase_type_arguments.cpp \
2222
java_bytecode/java_types/generic_type_index.cpp \
2323
java_bytecode/java_types/java_generic_symbol_type.cpp \
24-
java_bytecode/java_types/java_method_type.cpp \
2524
java_bytecode/java_types/java_type_from_string.cpp \
2625
java_bytecode/java_utils_test.cpp \
2726
java_bytecode/load_method_by_regex.cpp \

jbmc/unit/java_bytecode/java_bytecode_convert_method/convert_method.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ SCENARIO(
3030
symbol_table.lookup_ref(method_name + ":(Ljava/lang/Object;)I");
3131

3232
const java_method_typet &function_type =
33-
require_type::require_code(function_symbol.type);
34-
THEN("The method should be marked as a bridge method")
33+
require_type::require_java_method(function_symbol.type);
34+
THEN("The method symbol should be of java_method_typet")
35+
{
36+
REQUIRE(function_type.get_bool(ID_C_java_method_type));
37+
}
38+
THEN("And the method should be marked as a bridge method")
3539
{
3640
REQUIRE(function_type.get_bool(ID_is_bridge_method));
3741
}

jbmc/unit/java_bytecode/java_types/java_method_type.cpp

-35
This file was deleted.

0 commit comments

Comments
 (0)