Skip to content

Commit 9e27e31

Browse files
committed
Parse java arrays in annotations properly
Previously the value from the arrays was being parsed correctly but into an object which was then immediately thrown away, so the value was never really used.
1 parent ec79bdd commit 9e27e31

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class java_bytecode_parsert:public parsert
125125
void rRuntimeAnnotation_attribute(annotationst &);
126126
void rRuntimeAnnotation(annotationt &);
127127
void relement_value_pairs(annotationt::element_value_pairst &);
128-
void relement_value_pair(annotationt::element_value_pairt &);
128+
exprt get_relement_value();
129129
void rmethod_attribute(methodt &method);
130130
void rfield_attribute(fieldt &);
131131
void rcode_attribute(methodt &method);
@@ -1507,16 +1507,14 @@ void java_bytecode_parsert::relement_value_pairs(
15071507
{
15081508
u2 element_name_index=read_u2();
15091509
element_value_pair.element_name=pool_entry(element_name_index).s;
1510-
1511-
relement_value_pair(element_value_pair);
1510+
element_value_pair.value = get_relement_value();
15121511
}
15131512
}
15141513

15151514
/// Corresponds to the element_value structure
15161515
/// Described in Java 8 specification 4.7.16.1
15171516
/// https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.16.1
1518-
void java_bytecode_parsert::relement_value_pair(
1519-
annotationt::element_value_pairt &element_value_pair)
1517+
exprt java_bytecode_parsert::get_relement_value()
15201518
{
15211519
u1 tag=read_u1();
15221520

@@ -1527,50 +1525,46 @@ void java_bytecode_parsert::relement_value_pair(
15271525
UNUSED_u2(type_name_index);
15281526
UNUSED_u2(const_name_index);
15291527
// todo: enum
1528+
return exprt();
15301529
}
1531-
break;
15321530

15331531
case 'c':
15341532
{
15351533
u2 class_info_index = read_u2();
1536-
element_value_pair.value = symbol_exprt(pool_entry(class_info_index).s);
1534+
return symbol_exprt(pool_entry(class_info_index).s);
15371535
}
1538-
break;
15391536

15401537
case '@':
15411538
{
1539+
// TODO: return this wrapped in an exprt
15421540
// another annotation, recursively
15431541
annotationt annotation;
15441542
rRuntimeAnnotation(annotation);
1543+
return exprt();
15451544
}
1546-
break;
15471545

15481546
case '[':
15491547
{
1548+
array_exprt values;
15501549
u2 num_values=read_u2();
15511550
for(std::size_t i=0; i<num_values; i++)
15521551
{
1553-
annotationt::element_value_pairt element_value;
1554-
relement_value_pair(element_value); // recursive call
1552+
values.operands().push_back(get_relement_value());
15551553
}
1554+
return values;
15561555
}
1557-
break;
15581556

15591557
case 's':
15601558
{
15611559
u2 const_value_index=read_u2();
1562-
element_value_pair.value=string_constantt(
1563-
pool_entry(const_value_index).s);
1560+
return string_constantt(pool_entry(const_value_index).s);
15641561
}
1565-
break;
15661562

15671563
default:
15681564
{
15691565
u2 const_value_index=read_u2();
1570-
element_value_pair.value=constant(const_value_index);
1566+
return constant(const_value_index);
15711567
}
1572-
1573-
break;
15741568
}
15751569
}
15761570

0 commit comments

Comments
 (0)