Skip to content

Commit 809c5a3

Browse files
author
Daniel Kroening
committedApr 7, 2019
move is_final to java component type
'final' is a field modifier for Java, and has no meaning in C or C++. It should thus move to java_class_typet::componentt.
1 parent 0bf28f0 commit 809c5a3

File tree

7 files changed

+48
-17
lines changed

7 files changed

+48
-17
lines changed
 

‎jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,10 @@ void java_bytecode_convert_classt::convert(
740740
}
741741
else
742742
{
743-
class_typet &class_type=to_class_type(class_symbol.type);
743+
auto &class_type = to_java_class_type(class_symbol.type);
744744

745745
class_type.components().emplace_back();
746-
class_typet::componentt &component=class_type.components().back();
746+
auto &component = class_type.components().back();
747747

748748
component.set_name(f.name);
749749
component.set_base_name(f.name);

‎jbmc/src/java_bytecode/java_bytecode_language.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static void infer_opaque_type_fields(
332332
symbolt &writable_class_symbol =
333333
symbol_table.get_writeable_ref(class_symbol_id);
334334
auto &components =
335-
to_struct_type(writable_class_symbol.type).components();
335+
to_java_class_type(writable_class_symbol.type).components();
336336
components.emplace_back(component_name, fieldref.type());
337337
components.back().set_base_name(component_name);
338338
components.back().set_pretty_name(component_name);

‎jbmc/src/java_bytecode/java_types.h

+18
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ class java_class_typet:public class_typet
112112
{
113113
}
114114

115+
/// is a method or field 'final'?
116+
bool get_is_final() const
117+
{
118+
return get_bool(ID_final);
119+
}
120+
121+
/// is a method or field 'final'?
122+
void set_is_final(const bool is_final)
123+
{
124+
set(ID_final, is_final);
125+
}
126+
115127
/// is a method 'native'?
116128
bool get_is_native() const
117129
{
@@ -137,6 +149,12 @@ class java_class_typet:public class_typet
137149
return (componentst &)(add(ID_components).get_sub());
138150
}
139151

152+
const componentt &get_component(const irep_idt &component_name) const
153+
{
154+
return static_cast<const componentt &>(
155+
class_typet::get_component(component_name));
156+
}
157+
140158
const irep_idt &get_access() const
141159
{
142160
return get(ID_access);

‎jbmc/unit/java-testing-utils/require_type.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,30 @@ pointer_typet require_type::require_pointer(
3030
return pointer;
3131
}
3232

33+
/// Checks that a class has a component with a specific name
34+
/// \param java_class_type: The class that should have the component
35+
/// \param component_name: The name of the component
36+
/// \return The component with the specified name
37+
java_class_typet::componentt require_type::require_component(
38+
const java_class_typet &java_class_type,
39+
const irep_idt &component_name)
40+
{
41+
const auto &component = std::find_if(
42+
java_class_type.components().begin(),
43+
java_class_type.components().end(),
44+
[&component_name](const java_class_typet::componentt &component) {
45+
return component.get_name() == component_name;
46+
});
47+
48+
REQUIRE(component != java_class_type.components().end());
49+
return *component;
50+
}
51+
3352
/// Checks a struct like type has a component with a specific name
3453
/// \param struct_type: The structure that should have the component
3554
/// \param component_name: The name of the component
3655
/// \return The component with the specified name
37-
struct_union_typet::componentt require_type::require_component(
56+
struct_typet::componentt require_type::require_component(
3857
const struct_typet &struct_type,
3958
const irep_idt &component_name)
4059
{

‎jbmc/unit/java-testing-utils/require_type.h

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const pointer_typet require_pointer_to_tag(
3232
const typet &type,
3333
const irep_idt &identifier = irep_idt());
3434

35+
java_class_typet::componentt require_component(
36+
const java_class_typet &java_class_type,
37+
const irep_idt &component_name);
38+
3539
struct_typet::componentt require_component(
3640
const struct_typet &struct_type,
3741
const irep_idt &component_name);

‎jbmc/unit/java_bytecode/java_bytecode_language/language.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ SCENARIO(
3636
{
3737
const symbolt &opaque_class_symbol =
3838
symbol_table.lookup_ref(opaque_class_prefix);
39-
const struct_typet &opaque_class_struct =
40-
to_struct_type(opaque_class_symbol.type);
41-
const struct_union_typet::componentt &field =
39+
const auto &opaque_class_struct =
40+
to_java_class_type(opaque_class_symbol.type);
41+
const auto &field =
4242
require_type::require_component(opaque_class_struct, "field2");
4343
REQUIRE(field.get_is_final());
4444
}

‎src/util/std_types.h

-10
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,6 @@ class struct_union_typet:public typet
123123
{
124124
return set(ID_C_is_padding, is_padding);
125125
}
126-
127-
bool get_is_final() const
128-
{
129-
return get_bool(ID_final);
130-
}
131-
132-
void set_is_final(const bool is_final)
133-
{
134-
set(ID_final, is_final);
135-
}
136126
};
137127

138128
typedef std::vector<componentt> componentst;

0 commit comments

Comments
 (0)
Please sign in to comment.