Skip to content

Commit 3e95498

Browse files
author
Thomas Kiley
authored
Merge pull request #2976 from thomasspriggs/tas/final_fields
Store the final status of fields in `componentt`
2 parents 4ca2e14 + 5874f53 commit 3e95498

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ void java_bytecode_convert_classt::convert(
753753
else
754754
component.set_access(ID_default);
755755

756+
component.set_is_final(f.is_final);
757+
756758
// Load annotations
757759
if(!f.annotations.empty())
758760
{

jbmc/unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ SRC += java_bytecode/ci_lazy_methods/lazy_load_lambdas.cpp \
3939
java_bytecode/java_bytecode_parser/parse_java_annotations.cpp \
4040
java_bytecode/java_bytecode_parser/parse_java_attributes.cpp \
4141
java_bytecode/java_bytecode_parser/parse_java_class.cpp \
42+
java_bytecode/java_bytecode_parser/parse_java_field.cpp \
4243
java_bytecode/java_object_factory/gen_nondet_string_init.cpp \
4344
java_bytecode/java_replace_nondet/replace_nondet.cpp \
4445
java_bytecode/java_string_library_preprocess/convert_exprt_to_string_exprt.cpp \
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
class ClassWithFields {
3+
final boolean final1 = true;
4+
final Boolean final2 = false;
5+
final Object final3 = null;
6+
7+
boolean nonFinal1 = true;
8+
Boolean nonFinal2 = false;
9+
Object nonFinal3 = null;
10+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for converting fields
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <java-testing-utils/load_java_class.h>
10+
#include <java_bytecode/java_bytecode_convert_class.h>
11+
#include <java_bytecode/java_bytecode_parse_tree.h>
12+
#include <java_bytecode/java_types.h>
13+
#include <testing-utils/catch.hpp>
14+
15+
SCENARIO(
16+
"java_bytecode_parse_field",
17+
"[core][java_bytecode][java_bytecode_parser]")
18+
{
19+
GIVEN("Some class with final and non final fields")
20+
{
21+
const symbol_tablet &symbol_table = load_java_class(
22+
"ClassWithFields", "./java_bytecode/java_bytecode_parser");
23+
24+
WHEN("Parsing the class file structure")
25+
{
26+
THEN("The the final status of the classes fields should be correct.")
27+
{
28+
const symbolt &class_symbol =
29+
symbol_table.lookup_ref("java::ClassWithFields");
30+
const java_class_typet &java_class =
31+
to_java_class_type(class_symbol.type);
32+
REQUIRE(java_class.get_component("final1").get_is_final());
33+
REQUIRE(java_class.get_component("final2").get_is_final());
34+
REQUIRE(java_class.get_component("final3").get_is_final());
35+
REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
36+
REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
37+
REQUIRE(!java_class.get_component("nonFinal1").get_is_final());
38+
}
39+
}
40+
}
41+
}

src/util/std_types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ class struct_union_typet:public typet
189189
{
190190
return set(ID_C_is_padding, is_padding);
191191
}
192+
193+
bool get_is_final() const
194+
{
195+
return get_bool(ID_final);
196+
}
197+
198+
void set_is_final(const bool is_final)
199+
{
200+
set(ID_final, is_final);
201+
}
192202
};
193203

194204
typedef std::vector<componentt> componentst;

0 commit comments

Comments
 (0)