Skip to content

Commit 7537302

Browse files
romainbrenguiersmowton
authored andcommitted
Adding a java_lang_object_init function
This is to make object mandatory fields intialization easier.
1 parent b97a766 commit 7537302

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/java_bytecode/java_bytecode_typecheck_expr.cpp

+2-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
2323
#include "java_pointer_casts.h"
2424
#include "java_types.h"
2525
#include "java_utils.h"
26+
#include "java_root_class.h"
2627

2728
void java_bytecode_typecheckt::typecheck_expr(exprt &expr)
2829
{
@@ -134,15 +135,7 @@ void java_bytecode_typecheckt::typecheck_expr_java_string_literal(exprt &expr)
134135
const auto &jlo_struct=to_struct_type(ns.follow(jlo_symbol));
135136
struct_exprt jlo_init(jlo_symbol);
136137
const auto &jls_struct=to_struct_type(ns.follow(string_type));
137-
138-
jlo_init.copy_to_operands(
139-
constant_exprt(
140-
"java::java.lang.String",
141-
jlo_struct.components()[0].type()));
142-
jlo_init.copy_to_operands(
143-
from_integer(
144-
0,
145-
jlo_struct.components()[1].type()));
138+
java_root_class_init(jlo_init, jlo_struct, false, "java::java.lang.String");
146139

147140
// If string refinement *is* around, populate the actual
148141
// contents as well:

src/java_bytecode/java_root_class.cpp

+24-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Author: Daniel Kroening, [email protected]
88

99
#include "java_root_class.h"
1010

11+
#include <util/arith_tools.h>
1112
#include <util/symbol.h>
12-
#include <util/std_types.h>
1313

1414
#include "java_types.h"
1515

@@ -52,3 +52,26 @@ void java_root_class(symbolt &class_symbol)
5252
components.insert(components.begin(), component);
5353
}
5454
}
55+
56+
/// Adds members for an object of the root class (usually java.lang.Object).
57+
/// \param jlo [out] : object to initialize
58+
/// \param root_type: type of the root class
59+
/// \param lock: lock field
60+
/// \param class_identifier: class identifier field
61+
void java_root_class_init(
62+
struct_exprt &jlo,
63+
const struct_typet &root_type,
64+
const bool lock,
65+
const irep_idt &class_identifier)
66+
{
67+
jlo.operands().resize(root_type.components().size());
68+
69+
const std::size_t clsid_nb=root_type.component_number("@class_identifier");
70+
const typet &clsid_type=root_type.components()[clsid_nb].type();
71+
constant_exprt clsid(class_identifier, clsid_type);
72+
jlo.operands()[clsid_nb]=clsid;
73+
74+
const std::size_t lock_nb=root_type.component_number("@lock");
75+
const typet &lock_type=root_type.components()[lock_nb].type();
76+
jlo.operands()[lock_nb]=from_integer(lock, lock_type);
77+
}

src/java_bytecode/java_root_class.h

+6
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ Author: Daniel Kroening, [email protected]
1818
void java_root_class(
1919
class symbolt &class_symbol);
2020

21+
void java_root_class_init(
22+
struct_exprt &jlo,
23+
const struct_typet &root_type,
24+
bool lock,
25+
const irep_idt &class_identifier);
26+
2127
#endif // CPROVER_JAVA_BYTECODE_JAVA_ROOT_CLASS_H

0 commit comments

Comments
 (0)