Skip to content

Commit ed545cb

Browse files
author
thk123
committed
Refactored out the code for erasing generic types
1 parent effc1b2 commit ed545cb

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/java_bytecode/java_types.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,19 @@ exprt java_bytecode_promotion(const exprt &expr)
167167
return typecast_exprt(expr, new_type);
168168
}
169169

170-
/// Returns the full class name, skipping over the generics
171-
/// \param src: a type descriptor or signature like LOuterClass<TT;>.Inner;
172-
/// \return The full name of the class like OuterClass.Inner
173-
std::string gather_full_class_name(const std::string &src)
170+
void add_generic_type_information(
171+
java_generic_typet &generic_type,
172+
const std::string &parameters)
174173
{
175-
PRECONDITION(src[0] == 'L');
176-
PRECONDITION(src[src.size() - 1] == ';');
177-
178-
std::string class_name = src.substr(1, src.size() - 2);
174+
}
179175

176+
/// Take a signature string and remove everything in angle brackets allowing
177+
/// for the type to be parsed normally.
178+
/// \param src: The input string
179+
/// \return The input string with everything between angle brackets removed
180+
std::string erase_type_arguments(const std::string &src)
181+
{
182+
std::string class_name = src;
180183
std::size_t f_pos = class_name.find('<', 1);
181184

182185
while(f_pos != std::string::npos)
@@ -196,6 +199,24 @@ std::string gather_full_class_name(const std::string &src)
196199
// Search the remainder of the string for generic signature
197200
f_pos = class_name.find('<', e_pos + 1);
198201
}
202+
return class_name;
203+
}
204+
205+
/// Returns the full class name, skipping over the generics.
206+
/// \param src: a type descriptor or signature
207+
/// 1. Signature: Lcom/package/OuterClass<TT;>.Inner;
208+
/// 2. Descriptor: Lcom.pacakge.OuterClass$Inner;
209+
/// \return The full name of the class like com.package.OuterClass.Inner (for
210+
/// both examples).
211+
std::string gather_full_class_name(const std::string &src)
212+
{
213+
PRECONDITION(src.size() >= 2);
214+
PRECONDITION(src[0] == 'L');
215+
PRECONDITION(src[src.size() - 1] == ';');
216+
217+
std::string class_name = src.substr(1, src.size() - 2);
218+
219+
class_name = erase_type_arguments(class_name);
199220

200221
std::replace(class_name.begin(), class_name.end(), '.', '$');
201222
std::replace(class_name.begin(), class_name.end(), '/', '.');

0 commit comments

Comments
 (0)