CBMC
code_with_references.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Java bytecode
4 
5 Author: Romain Brenguier, romain.brenguier@diffblue.com
6 
7 \*******************************************************************/
8 
9 #include "code_with_references.h"
10 #include "java_types.h"
11 
13 
14 #include <util/arith_tools.h>
15 
17  const exprt &expr,
18  const exprt &array_length_expr,
19  const source_locationt &loc)
20 {
22  const auto &element_type =
24  pointer_type.base_type().set(ID_element_type, element_type);
25  side_effect_exprt java_new_array{
26  ID_java_new_array, {array_length_expr}, pointer_type, loc};
27  return code_frontend_assignt{expr, java_new_array, loc};
28 }
29 
32 {
33  const object_creation_referencet &reference = references(reference_id);
34  INVARIANT(reference.array_length, "Length of reference array must be known");
36  {
37  return code_blockt(
38  {allocate_array(reference.expr, *reference.array_length, loc)});
39  }
40  // Fallback in case the array definition has not been seen yet, this can
41  // happen if `to_code` is called before the whole json file has been processed
42  // or the "@id" json field corresponding to `reference_id` doesn't appear in
43  // the file.
44  code_blockt code;
48  *reference.array_length, ID_ge, from_integer(0, java_int_type())}});
49  code.add(allocate_array(reference.expr, *reference.array_length, loc));
50  return code;
51 }
52 
54 {
55  auto ptr = std::make_shared<code_without_referencest>(std::move(code));
56  list.emplace_back(std::move(ptr));
57 }
58 
60 {
61  add(code_without_referencest{std::move(code)});
62 }
63 
65 {
66  auto ptr = std::make_shared<reference_allocationt>(std::move(ref));
67  list.emplace_back(std::move(ptr));
68 }
69 
71 {
72  list.splice(list.end(), other.list);
73 }
74 
76 {
77  auto ptr = std::make_shared<code_without_referencest>(std::move(code));
78  list.emplace_front(std::move(ptr));
79 }
code_with_references_listt::add
void add(code_without_referencest code)
Definition: code_with_references.cpp:53
code_blockt
A codet representing sequential composition of program statements.
Definition: std_code.h:129
allocate_array
codet allocate_array(const exprt &expr, const exprt &array_length_expr, const source_locationt &loc)
Allocate a fresh array of length array_length_expr and assigns expr to it.
Definition: code_with_references.cpp:16
arith_tools.h
goto_instruction_code.h
code_with_references.h
code_with_referencest::reference_substitutiont
std::function< const object_creation_referencet &(const std::string &)> reference_substitutiont
Definition: code_with_references.h:44
java_array_element_type
const typet & java_array_element_type(const struct_tag_typet &array_symbol)
Return a const reference to the element type of a given java array type.
Definition: java_types.cpp:144
reference_allocationt::loc
source_locationt loc
Definition: code_with_references.h:80
exprt
Base class for all expressions.
Definition: expr.h:55
code_with_references_listt::add_to_front
void add_to_front(code_without_referencest code)
Definition: code_with_references.cpp:75
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:84
object_creation_referencet::expr
exprt expr
Expression for the symbol that stores the value that may be reference equal to other values.
Definition: code_with_references.h:27
code_without_referencest
Code that should not contain reference.
Definition: code_with_references.h:52
reference_allocationt
Allocation code which contains a reference.
Definition: code_with_references.h:76
irept::set
void set(const irep_idt &name, const irep_idt &value)
Definition: irep.h:420
binary_predicate_exprt
A base class for expressions that are predicates, i.e., Boolean-typed, and that take exactly two argu...
Definition: std_expr.h:675
code_assumet
An assumption, which must hold in subsequent code.
Definition: std_code.h:216
to_pointer_type
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Definition: pointer_expr.h:79
pointer_type
pointer_typet pointer_type(const typet &subtype)
Definition: c_types.cpp:253
code_frontend_assignt
A codet representing an assignment in the program.
Definition: std_code.h:23
object_creation_referencet
Information to store when several references point to the same Java object.
Definition: code_with_references.h:23
to_struct_tag_type
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition: std_types.h:474
code_blockt::add
void add(const codet &code)
Definition: std_code.h:168
java_int_type
signedbv_typet java_int_type()
Definition: java_types.cpp:31
object_creation_referencet::array_length
optionalt< exprt > array_length
If symbol is an array, this expression stores its length.
Definition: code_with_references.h:33
source_locationt
Definition: source_location.h:18
side_effect_expr_nondett
A side_effect_exprt that returns a non-deterministically chosen value.
Definition: std_code.h:1519
code_with_references_listt::append
void append(code_with_references_listt &&other)
Definition: code_with_references.cpp:70
code_with_references_listt
Wrapper around a list of shared pointer to code_with_referencest objects, which provides a nicer inte...
Definition: code_with_references.h:92
code_with_references_listt::list
std::list< std::shared_ptr< code_with_referencest > > list
Definition: code_with_references.h:95
reference_allocationt::reference_id
std::string reference_id
Definition: code_with_references.h:79
from_integer
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
Definition: arith_tools.cpp:100
pointer_typet::base_type
const typet & base_type() const
The type of the data what we point to.
Definition: pointer_expr.h:35
can_cast_expr< constant_exprt >
bool can_cast_expr< constant_exprt >(const exprt &base)
Definition: std_expr.h:2976
java_types.h
pointer_typet
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
Definition: pointer_expr.h:23
side_effect_exprt
An expression containing a side effect.
Definition: std_code.h:1449
validation_modet::INVARIANT
@ INVARIANT
reference_allocationt::to_code
code_blockt to_code(reference_substitutiont &references) const override
Definition: code_with_references.cpp:31
codet
Data structure for representing an arbitrary statement in a program.
Definition: std_code_base.h:28