Skip to content

Commit bc847ce

Browse files
author
Daniel Kroening
committed
proper conversion for Java literals
1 parent bcd05d8 commit bc847ce

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/java_bytecode/expr2java.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include <util/std_expr.h>
1313
#include <util/symbol.h>
1414
#include <util/hash_cont.h>
15+
#include <util/arith_tools.h>
1516

1617
#include <ansi-c/expr2c_class.h>
1718

@@ -239,6 +240,39 @@ std::string expr2javat::convert_constant(
239240
if(src.is_zero())
240241
return "null";
241242
}
243+
else if(src.type()==java_char_type())
244+
{
245+
std::string dest;
246+
dest.reserve(10);
247+
248+
mp_integer int_value;
249+
to_integer(src, int_value);
250+
251+
dest+='\'';
252+
253+
if(int_value>=' ' && int_value<127)
254+
dest+=(char)(int_value.to_long());
255+
else
256+
{
257+
std::string hex=integer2string(int_value, 16);
258+
while(hex.size()<4) hex='0'+hex;
259+
dest+='\\';
260+
dest+='u';
261+
dest+=hex;
262+
}
263+
264+
dest+='\'';
265+
return dest;
266+
}
267+
else if(src.type()==java_long_type())
268+
{
269+
// long integer literals must have 'L' at the end
270+
mp_integer int_value;
271+
to_integer(src, int_value);
272+
std::string dest=integer2string(int_value);
273+
dest+='L';
274+
return dest;
275+
}
242276

243277
return expr2ct::convert_constant(src, precedence);
244278
}

0 commit comments

Comments
 (0)