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