CBMC
Loading...
Searching...
No Matches
create_array_with_type_intrinsic.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Implementation of CProver.createArrayWithType intrinsic
4
5Author: Diffblue Ltd.
6
7\*******************************************************************/
8
11
13
15
16#include <util/fresh_symbol.h>
17#include <util/namespace.h>
18#include <util/pointer_expr.h>
19#include <util/std_code.h>
21
24{
26 "java::org.cprover.CProver.createArrayWithType:"
27 "(I[Ljava/lang/Object;)[Ljava/lang/Object;";
29}
30
42 const irep_idt &function_id,
43 symbol_table_baset &symbol_table,
44 message_handlert &message_handler)
45{
46 // Replace CProver.createArrayWithType, which uses reflection to copy the
47 // type but not the content of a given array, with a java_new_array statement
48 // followed by overwriting its element type and dimension, similar to our
49 // implementation (in java_bytecode_convert_class.cpp) of the
50 // array[reference].clone() method.
51
53
54 namespacet ns{symbol_table};
55
58 const auto &function_type = to_code_type(function_symbol.type);
59 const auto &length_argument = function_type.parameters().at(0);
61 length_argument.type()};
62 const auto &existing_array_argument = function_type.parameters().at(1);
64 existing_array_argument.get_identifier(), existing_array_argument.type()};
65
67 function_type.parameters().at(1).type(),
69 "new_array",
71 ID_java,
72 symbol_table);
73 const auto new_array_symbol_expr = new_array_symbol.symbol_expr();
74
76
77 // Declare new_array temporary:
79
80 // new_array = new Object[length];
85
88
89 // new_array.@array_dimensions = existing_array.@array_dimensions
90 // new_array.@element_class_identifier =
91 // existing_array.@element_class_identifier
96
101
102 code_block.add(
106
107 // return new_array
109
110 return std::move(code_block);
111}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
A codet representing sequential composition of program statements.
Definition std_code.h:130
A codet representing an assignment in the program.
Definition std_code.h:24
A codet representing the declaration of a local variable.
Definition std_code.h:347
codet representation of a "return from a function" statement.
Definition std_code.h:893
Data structure for representing an arbitrary statement in a program.
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Extract member of struct or union.
Definition std_expr.h:2972
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
An expression containing a side effect.
Definition std_code.h:1450
String type.
Definition std_types.h:966
Expression to hold a symbol (variable)
Definition std_expr.h:131
The symbol table base class interface.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
Symbol table entry.
Definition symbol.h:28
irep_idt get_create_array_with_type_name()
Returns the symbol name for org.cprover.CProver.createArrayWithType
codet create_array_with_type_body(const irep_idt &function_id, symbol_table_baset &symbol_table, message_handlert &message_handler)
Returns the internal implementation for org.cprover.CProver.createArrayWithType.
Implementation of CProver.createArrayWithType intrinsic.
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, const namespacet &ns, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with respect to the given namespace ns with the requested name pattern ...
Fresh auxiliary symbol creation.
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
signedbv_typet java_int_type()
#define JAVA_ARRAY_ELEMENT_CLASSID_FIELD_NAME
Definition java_types.h:670
#define JAVA_ARRAY_DIMENSION_FIELD_NAME
Definition java_types.h:668
API to expression classes for Pointers.
#define PRECONDITION(CONDITION)
Definition invariant.h:463
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition std_types.h:788
Author: Diffblue Ltd.