Skip to content

Commit 030c6bb

Browse files
Move some code from assign_from_json to new file
This is in preparation for adding a new class in this file, we add there the function and class which will be needed by this class.
1 parent 48453a1 commit 030c6bb

File tree

5 files changed

+64
-27
lines changed

5 files changed

+64
-27
lines changed

jbmc/src/java_bytecode/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SRC = assignments_from_json.cpp \
33
character_refine_preprocess.cpp \
44
ci_lazy_methods.cpp \
55
ci_lazy_methods_needed.cpp \
6+
code_with_references.cpp \
67
convert_java_nondet.cpp \
78
create_array_with_type_intrinsic.cpp \
89
expr2java.cpp \

jbmc/src/java_bytecode/assignments_from_json.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Diffblue Ltd.
99
#include "assignments_from_json.h"
1010

1111
#include "ci_lazy_methods_needed.h"
12+
#include "code_with_references.h"
1213
#include "java_static_initializers.h"
1314
#include "java_string_library_preprocess.h"
1415
#include "java_string_literals.h"
@@ -420,22 +421,6 @@ static void assign_array_data_component_from_json(
420421
}
421422
}
422423

423-
/// Allocate a fresh array of length \p array_length_expr and assigns \p expr
424-
/// to it.
425-
static codet allocate_array(
426-
const exprt &expr,
427-
const exprt &array_length_expr,
428-
const source_locationt &loc)
429-
{
430-
const pointer_typet &pointer_type = to_pointer_type(expr.type());
431-
const auto &element_type =
432-
java_array_element_type(to_struct_tag_type(pointer_type.subtype()));
433-
side_effect_exprt java_new_array{ID_java_new_array, pointer_type};
434-
java_new_array.copy_to_operands(array_length_expr);
435-
java_new_array.type().subtype().set(ID_element_type, element_type);
436-
return code_assignt{expr, java_new_array, loc};
437-
}
438-
439424
/// Declare a non-deterministic length expression
440425
/// \param[out] allocate: allocation functor
441426
/// \param[out] code: code block to which code will get appended

jbmc/src/java_bytecode/assignments_from_json.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,13 @@ Author: Diffblue Ltd.
1111
#ifndef CPROVER_JAVA_BYTECODE_ASSIGNMENTS_FROM_JSON_H
1212
#define CPROVER_JAVA_BYTECODE_ASSIGNMENTS_FROM_JSON_H
1313

14+
#include "code_with_references.h"
1415
#include <util/std_code.h>
1516

1617
class jsont;
1718
class symbol_table_baset;
1819
class ci_lazy_methods_neededt;
1920

20-
/// Information to store when several references point to the same Java object.
21-
struct object_creation_referencet
22-
{
23-
/// Expression for the symbol that stores the value that may be reference
24-
/// equal to other values.
25-
exprt expr;
26-
27-
/// If `symbol` is an array, this expression stores its length.
28-
optionalt<symbol_exprt> array_length;
29-
};
30-
3121
/// Given an expression \p expr representing a Java object or primitive and a
3222
/// JSON representation \p json of the value of a Java object or primitive of a
3323
/// compatible type, adds statements to \p block to assign \p expr to the
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************\
2+
3+
Module: Java bytecode
4+
5+
Author: Romain Brenguier, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "code_with_references.h"
10+
#include "java_types.h"
11+
#include <util/arith_tools.h>
12+
13+
codet allocate_array(
14+
const exprt &expr,
15+
const exprt &array_length_expr,
16+
const source_locationt &loc)
17+
{
18+
const pointer_typet &pointer_type = to_pointer_type(expr.type());
19+
const auto &element_type =
20+
java_array_element_type(to_struct_tag_type(pointer_type.subtype()));
21+
side_effect_exprt java_new_array{ID_java_new_array, pointer_type};
22+
java_new_array.copy_to_operands(array_length_expr);
23+
java_new_array.type().subtype().set(ID_element_type, element_type);
24+
return code_assignt{expr, java_new_array, loc};
25+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************\
2+
3+
Module: Java bytecode
4+
5+
Author: Romain Brenguier, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_JAVA_BYTECODE_CODE_WITH_REFERENCES_H
10+
#define CPROVER_JAVA_BYTECODE_CODE_WITH_REFERENCES_H
11+
12+
#include <memory>
13+
#include <util/std_code.h>
14+
15+
/// Allocate a fresh array of length \p array_length_expr and assigns \p expr
16+
/// to it.
17+
codet allocate_array(
18+
const exprt &expr,
19+
const exprt &array_length_expr,
20+
const source_locationt &loc);
21+
22+
/// Information to store when several references point to the same Java object.
23+
struct object_creation_referencet
24+
{
25+
/// Expression for the symbol that stores the value that may be reference
26+
/// equal to other values.
27+
exprt expr;
28+
29+
/// If `symbol` is an array, this expression stores its length.
30+
/// This should only be set once the actual elements of the array have been
31+
/// seen, not the first time an `@ref` have been seen, only when `@id` is
32+
/// seen.
33+
optionalt<exprt> array_length;
34+
};
35+
36+
#endif // CPROVER_JAVA_BYTECODE_CODE_WITH_REFERENCES_H

0 commit comments

Comments
 (0)