@@ -1597,50 +1597,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
1597
1597
statement==" lookupswitch" )
1598
1598
{
1599
1599
PRECONDITION (op.size () == 1 && results.empty ());
1600
-
1601
- // we turn into switch-case
1602
- code_switcht code_switch;
1603
- code_switch.add_source_location ()=i_it->source_location ;
1604
- code_switch.value ()=op[0 ];
1605
- code_blockt code_block;
1606
- code_block.add_source_location ()=i_it->source_location ;
1607
-
1608
- bool is_label=true ;
1609
- for (instructiont::argst::const_iterator
1610
- a_it=i_it->args .begin ();
1611
- a_it!=i_it->args .end ();
1612
- a_it++, is_label=!is_label)
1613
- {
1614
- if (is_label)
1615
- {
1616
- code_switch_caset code_case;
1617
- code_case.add_source_location ()=i_it->source_location ;
1618
-
1619
- mp_integer number;
1620
- bool ret=to_integer (to_constant_expr (*a_it), number);
1621
- DATA_INVARIANT (!ret, " case label expected to be integer" );
1622
- code_case.code ()=code_gotot (label (integer2string (number)));
1623
- code_case.code ().add_source_location ()=
1624
- address_map.at (integer2unsigned (number)).source ->source_location ;
1625
-
1626
- if (a_it==i_it->args .begin ())
1627
- code_case.set_default ();
1628
- else
1629
- {
1630
- instructiont::argst::const_iterator prev=a_it;
1631
- prev--;
1632
- code_case.case_op ()=*prev;
1633
- if (code_case.case_op ().type ()!=op[0 ].type ())
1634
- code_case.case_op ().make_typecast (op[0 ].type ());
1635
- code_case.case_op ().add_source_location ()=i_it->source_location ;
1636
- }
1637
-
1638
- code_block.add (code_case);
1639
- }
1640
- }
1641
-
1642
- code_switch.body ()=code_block;
1643
- c=code_switch;
1600
+ c = convert_switch (address_map, i_it, op);
1644
1601
}
1645
1602
else if (statement==" pop" || statement==" pop2" )
1646
1603
{
@@ -1923,6 +1880,55 @@ codet java_bytecode_convert_methodt::convert_instructions(
1923
1880
return code;
1924
1881
}
1925
1882
1883
+ codet java_bytecode_convert_methodt::convert_switch (
1884
+ java_bytecode_convert_methodt::address_mapt &address_map,
1885
+ const std::vector<java_bytecode_parse_treet::instructiont>::const_iterator
1886
+ &i_it,
1887
+ const exprt::operandst &op)
1888
+ {
1889
+ // we turn into switch-case
1890
+ code_switcht code_switch;
1891
+ code_switch.add_source_location () = i_it->source_location ;
1892
+ code_switch.value () = op[0 ];
1893
+ code_blockt code_block;
1894
+ code_block.add_source_location () = i_it->source_location ;
1895
+
1896
+ bool is_label = true ;
1897
+ for (auto a_it = i_it->args .begin (); a_it != i_it->args .end ();
1898
+ a_it++, is_label = !is_label)
1899
+ {
1900
+ if (is_label)
1901
+ {
1902
+ code_switch_caset code_case;
1903
+ code_case.add_source_location () = i_it->source_location ;
1904
+
1905
+ mp_integer number;
1906
+ bool ret = to_integer (to_constant_expr (*a_it), number);
1907
+ DATA_INVARIANT (!ret, " case label expected to be integer" );
1908
+ code_case.code () = code_gotot (label (integer2string (number)));
1909
+ code_case.code ().add_source_location () =
1910
+ address_map.at (integer2unsigned (number)).source ->source_location ;
1911
+
1912
+ if (a_it == i_it->args .begin ())
1913
+ code_case.set_default ();
1914
+ else
1915
+ {
1916
+ auto prev = a_it;
1917
+ prev--;
1918
+ code_case.case_op () = *prev;
1919
+ if (code_case.case_op ().type () != op[0 ].type ())
1920
+ code_case.case_op ().make_typecast (op[0 ].type ());
1921
+ code_case.case_op ().add_source_location () = i_it->source_location ;
1922
+ }
1923
+
1924
+ code_block.add (code_case);
1925
+ }
1926
+ }
1927
+
1928
+ code_switch.body () = code_block;
1929
+ return code_switch;
1930
+ }
1931
+
1926
1932
void java_bytecode_convert_methodt::convert_dup2 (
1927
1933
exprt::operandst &op,
1928
1934
exprt::operandst &results)
0 commit comments