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