Skip to content

Commit ccd22e8

Browse files
committed
Split parse_list_types into two functions
In some situations you might want to know what the bytecode type is and then manually perform some operation afterwards, in this case it's useful to have a method that returns the string representation of the bytecode type.
1 parent 6030b9e commit ccd22e8

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

jbmc/src/java_bytecode/java_types.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,40 @@ std::vector<typet> parse_list_types(
333333
const std::string class_name_prefix,
334334
const char opening_bracket,
335335
const char closing_bracket)
336+
{
337+
// Loop over the types in the given string, parsing each one in turn
338+
// and adding to the type_list
339+
std::vector<typet> type_list;
340+
for(const std::string &raw_type :
341+
parse_raw_list_types(src, opening_bracket, closing_bracket))
342+
{
343+
const typet new_type = java_type_from_string(raw_type, class_name_prefix);
344+
INVARIANT(new_type != nil_typet(), "Failed to parse type");
345+
type_list.push_back(new_type);
346+
}
347+
return type_list;
348+
}
349+
350+
/// Given a substring of a descriptor or signature that contains one or more
351+
/// types parse out the individual type strings.
352+
/// \param src: The input string that is wrapped in either ( ) or < >
353+
/// \param opening_bracket: For checking string is passed in as expected, the
354+
/// opening bracket (i.e. '(' or '<').
355+
/// \param closing_bracket: For checking string is passed in as expected, the
356+
/// closing bracket (i.e. ')' or '>').
357+
/// \return A vector of strings that represent the bytecode type.
358+
std::vector<std::string> parse_raw_list_types(
359+
const std::string src,
360+
const char opening_bracket,
361+
const char closing_bracket)
336362
{
337363
PRECONDITION(src.size() >= 2);
338364
PRECONDITION(src[0] == opening_bracket);
339365
PRECONDITION(src[src.size() - 1] == closing_bracket);
340366

341367
// Loop over the types in the given string, parsing each one in turn
342368
// and adding to the type_list
343-
std::vector<typet> type_list;
369+
std::vector<std::string> type_list;
344370
for(std::size_t i = 1; i < src.size() - 1; i++)
345371
{
346372
size_t start = i;
@@ -369,10 +395,7 @@ std::vector<typet> parse_list_types(
369395
}
370396

371397
std::string sub_str = src.substr(start, i - start + 1);
372-
const typet &new_type = java_type_from_string(sub_str, class_name_prefix);
373-
INVARIANT(new_type != nil_typet(), "Failed to parse type");
374-
375-
type_list.push_back(new_type);
398+
type_list.emplace_back(sub_str);
376399
}
377400
return type_list;
378401
}

jbmc/src/java_bytecode/java_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ size_t find_closing_semi_colon_for_reference_type(
362362
const std::string src,
363363
size_t starting_point = 0);
364364

365+
std::vector<std::string> parse_raw_list_types(
366+
std::string src,
367+
char opening_bracket,
368+
char closing_bracket);
365369

366370
bool is_java_array_tag(const irep_idt &tag);
367371
bool is_valid_java_array(const struct_typet &);

0 commit comments

Comments
 (0)