CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ci_lazy_methods_needed.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Context-insensitive lazy methods container
4
5Author: Chris Smowton, chris.smowton@diffblue.com
6
7\*******************************************************************/
8
11
13
14#include <util/namespace.h>
15#include <util/std_types.h>
17
19
20#include "generic_parameter_specialization_map.h" // IWYU pragma: keep
22#include "java_types.h"
23#include "select_pointer_type.h"
24
33
48
53 const irep_idt &class_id)
54{
56 std::optional<resolve_inherited_componentt::inherited_componentt>
58 class_id, "cproverNondetInitialize:()V", true);
59
61 {
63 cprover_nondet_initialize->get_full_component_identifier());
64 }
65}
66
74{
75 if(!instantiated_classes.insert(class_symbol_name).second)
76 return false;
77
79
80 // Special case for enums. We may want to generalise this, the comment in
81 // \ref java_object_factoryt::gen_nondet_pointer_init (TG-4689).
83 const auto &class_type =
85 if(class_type.get_base("java::java.lang.Enum"))
87
88 return true;
89}
90
96{
98
100
101 // TODO we should be passing here a map that maps generic parameters
102 // to concrete types in the current context TG-2664
104 pointer_type_selector.convert_pointer_type(pointer_type, {}, ns);
105
107 {
109 }
110}
111
118 const namespacet &ns)
119{
121 const auto &param_classid = class_type.get_identifier();
122
123 // Note here: different arrays may have different element types, so we should
124 // explore again even if we've seen this classid before in the array case.
126 {
128 }
129
131 {
132 // Assume if this is a generic like X<A, B, C>, then any concrete parameters
133 // will at some point be instantiated.
134 const auto &generic_args =
135 to_java_generic_type(pointer_type).generic_type_arguments();
136 for(const auto &generic_arg : generic_args)
137 {
140 }
141 }
142}
143
149 const namespacet &ns)
150{
151 const auto &underlying_type = ns.follow_tag(class_type);
152
153 if(is_java_array_tag(underlying_type.get_tag()))
154 {
155 const typet &element_type = java_array_element_type(class_type);
156 if(
157 element_type.id() == ID_pointer &&
158 to_pointer_type(element_type).base_type().id() != ID_empty)
159 {
160 // This is a reference array -- mark its element type available.
162 }
163 }
164 else
165 {
166 for(const auto &field : underlying_type.components())
167 {
168 if(field.type().id() == ID_struct_tag)
170 else if(field.type().id() == ID_struct)
172 else if(field.type().id() == ID_pointer)
173 {
174 if(to_pointer_type(field.type()).base_type().id() == ID_struct_tag)
175 {
177 }
178 else
179 {
180 // If raw structs were possible this would lead to missed
181 // dependencies, as both array element and specialised generic type
182 // information cannot be obtained in this case.
183 // We should therefore only be skipping pointers such as the uint16t*
184 // in our internal String representation.
185 INVARIANT(
186 to_pointer_type(field.type()).base_type().id() != ID_struct,
187 "struct types should be referred to by symbol at this stage");
188 }
189 }
190 }
191 }
192}
pointer_typet pointer_type(const typet &subtype)
Definition c_types.cpp:235
Context-insensitive lazy methods container.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
std::unordered_set< irep_idt > & instantiated_classes
void initialize_instantiated_classes_from_pointer(const pointer_typet &pointer_type, const namespacet &ns)
Build up list of methods for types for a specific pointer type.
const select_pointer_typet & pointer_type_selector
void gather_field_types(const struct_tag_typet &class_type, const namespacet &ns)
For a given type, gather all fields referenced by that type.
void add_needed_method(const irep_idt &)
Notes method_symbol_name is referenced from some reachable function, and should therefore be elaborat...
void add_all_needed_classes(const pointer_typet &pointer_type)
Add to the needed classes all classes specified, the replacement type if it will be replaced,...
std::unordered_set< irep_idt > & callable_methods
const symbol_table_baset & symbol_table
bool add_needed_class(const irep_idt &)
Notes class class_symbol_name will be instantiated, or a static field belonging to it will be accesse...
void add_cprover_nondet_initialize_if_it_exists(const irep_idt &class_id)
For a given class id, if cproverNondetInitialize exists on it or any of its ancestors then note that ...
void add_clinit_call(const irep_idt &class_id)
For a given class id, note that its static initializer is needed.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
const irep_idt & id() const
Definition irep.h:388
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
Definition namespace.cpp:49
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
const typet & base_type() const
The type of the data what we point to.
A struct tag type, i.e., struct_typet with an identifier.
Definition std_types.h:493
The type of an expression, extends irept.
Definition type.h:29
irep_idt clinit_wrapper_name(const irep_idt &class_name)
Get the Java static initializer wrapper name for a given class (the wrapper checks if static initiali...
bool is_java_array_tag(const irep_idt &tag)
See above.
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.
const java_generic_typet & to_java_generic_type(const typet &type)
Definition java_types.h:953
const java_class_typet & to_java_class_type(const typet &type)
Definition java_types.h:581
bool is_java_generic_type(const typet &type)
Definition java_types.h:946
bool is_java_generic_parameter(const typet &type)
Checks whether the type is a java generic parameter/variable, e.g., T in List<T>.
Definition java_types.h:819
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
Given a class and a component (either field or method), find the closest parent that defines that com...
Handle selection of correct pointer type (for example changing abstract classes to concrete versions)...
#define UNREACHABLE
This should be used to mark dead code.
Definition invariant.h:525
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
Pre-defined types.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
Definition std_types.h:518
Author: Diffblue Ltd.