Skip to content

Commit f3630f0

Browse files
author
svorenova
authored
Merge pull request diffblue#2612 from svorenova/multidim_arrays_tg3821_util
Add functions for checking (multi-dimensional) array types [TG-3821]
2 parents c010edb + c572866 commit f3630f0

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

jbmc/src/java_bytecode/java_types.cpp

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ reference_typet java_lang_object_type()
8787
return java_reference_type(symbol_typet("java::java.lang.Object"));
8888
}
8989

90+
/// Construct an array pointer type. It is a pointer to a symbol with identifier
91+
/// java::array[]. Its ID_C_element_type is set to the corresponding primitive
92+
/// type, or void* for arrays of references.
93+
/// \param subtype Character indicating the type of array
9094
reference_typet java_array_type(const char subtype)
9195
{
9296
std::string subtype_str;
@@ -140,19 +144,48 @@ typet &java_array_element_type(symbol_typet &array_symbol)
140144
return array_symbol.add_type(ID_C_element_type);
141145
}
142146

143-
/// See above
144-
/// \par parameters: Struct tag 'tag'
145-
/// \return True if the given struct is a Java array
146-
bool is_java_array_tag(const irep_idt& tag)
147+
/// Checks whether the given type is an array pointer type
148+
bool is_java_array_type(const typet &type)
147149
{
148-
return has_prefix(id2string(tag), "java::array[");
150+
if(
151+
!can_cast_type<pointer_typet>(type) ||
152+
!can_cast_type<symbol_typet>(type.subtype()))
153+
{
154+
return false;
155+
}
156+
const auto &subtype_symbol = to_symbol_type(type.subtype());
157+
return is_java_array_tag(subtype_symbol.get_identifier());
149158
}
150159

151-
bool is_reference_type(const char t)
160+
/// Checks whether the given type is a multi-dimensional array pointer type,
161+
// i.e., a pointer to an array type with element type also being a pointer to an
162+
/// array type.
163+
bool is_multidim_java_array_type(const typet &type)
152164
{
153-
return 'a'==t;
165+
return is_java_array_type(type) &&
166+
is_java_array_type(
167+
java_array_element_type(to_symbol_type(type.subtype())));
168+
}
169+
170+
/// See above
171+
/// \param tag Tag of a struct
172+
/// \return True if the given string is a Java array tag, i.e., has a prefix
173+
/// of java::array[
174+
bool is_java_array_tag(const irep_idt& tag)
175+
{
176+
return has_prefix(id2string(tag), "java::array[");
154177
}
155178

179+
/// Constructs a type indicated by the given character:
180+
/// - i integer
181+
/// - l long
182+
/// - s short
183+
/// - b byte
184+
/// - c character
185+
/// - f float
186+
/// - d double
187+
/// - z boolean
188+
/// - a reference
156189
typet java_type_from_char(char t)
157190
{
158191
switch(t)

jbmc/src/java_bytecode/java_types.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,8 @@ symbol_typet java_classname(const std::string &);
247247
reference_typet java_array_type(const char subtype);
248248
const typet &java_array_element_type(const symbol_typet &array_symbol);
249249
typet &java_array_element_type(symbol_typet &array_symbol);
250-
251-
bool is_reference_type(char t);
252-
253-
// i integer
254-
// l long
255-
// s short
256-
// b byte
257-
// c character
258-
// f float
259-
// d double
260-
// z boolean
261-
// a reference
250+
bool is_java_array_type(const typet &type);
251+
bool is_multidim_java_array_type(const typet &type);
262252

263253
typet java_type_from_char(char t);
264254
typet java_type_from_string(

0 commit comments

Comments
 (0)