@@ -1616,50 +1616,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
1616
1616
statement==" lookupswitch" )
1617
1617
{
1618
1618
PRECONDITION (op.size () == 1 && results.empty ());
1619
-
1620
- // we turn into switch-case
1621
- code_switcht code_switch;
1622
- code_switch.add_source_location ()=i_it->source_location ;
1623
- code_switch.value ()=op[0 ];
1624
- code_blockt code_block;
1625
- code_block.add_source_location ()=i_it->source_location ;
1626
-
1627
- bool is_label=true ;
1628
- for (instructiont::argst::const_iterator
1629
- a_it=i_it->args .begin ();
1630
- a_it!=i_it->args .end ();
1631
- a_it++, is_label=!is_label)
1632
- {
1633
- if (is_label)
1634
- {
1635
- code_switch_caset code_case;
1636
- code_case.add_source_location ()=i_it->source_location ;
1637
-
1638
- mp_integer number;
1639
- bool ret=to_integer (to_constant_expr (*a_it), number);
1640
- DATA_INVARIANT (!ret, " case label expected to be integer" );
1641
- code_case.code ()=code_gotot (label (integer2string (number)));
1642
- code_case.code ().add_source_location ()=
1643
- address_map.at (integer2unsigned (number)).source ->source_location ;
1644
-
1645
- if (a_it==i_it->args .begin ())
1646
- code_case.set_default ();
1647
- else
1648
- {
1649
- instructiont::argst::const_iterator prev=a_it;
1650
- prev--;
1651
- code_case.case_op ()=*prev;
1652
- if (code_case.case_op ().type ()!=op[0 ].type ())
1653
- code_case.case_op ().make_typecast (op[0 ].type ());
1654
- code_case.case_op ().add_source_location ()=i_it->source_location ;
1655
- }
1656
-
1657
- code_block.add (code_case);
1658
- }
1659
- }
1660
-
1661
- code_switch.body ()=code_block;
1662
- c=code_switch;
1619
+ c = convert_switch (
1620
+ address_map,
1621
+ op,
1622
+ i_it->args ,
1623
+ i_it->source_location );
1663
1624
}
1664
1625
else if (statement==" pop" || statement==" pop2" )
1665
1626
{
@@ -1942,6 +1903,55 @@ codet java_bytecode_convert_methodt::convert_instructions(
1942
1903
return code;
1943
1904
}
1944
1905
1906
+ codet java_bytecode_convert_methodt::convert_switch (
1907
+ java_bytecode_convert_methodt::address_mapt &address_map,
1908
+ const exprt::operandst &op,
1909
+ const java_bytecode_parse_treet::instructiont::argst &args,
1910
+ const source_locationt &location)
1911
+ {
1912
+ // we turn into switch-case
1913
+ code_switcht code_switch;
1914
+ code_switch.add_source_location () = location;
1915
+ code_switch.value () = op[0 ];
1916
+ code_blockt code_block;
1917
+ code_block.add_source_location () = location;
1918
+
1919
+ bool is_label = true ;
1920
+ for (auto a_it = args.begin (); a_it != args.end ();
1921
+ a_it++, is_label = !is_label)
1922
+ {
1923
+ if (is_label)
1924
+ {
1925
+ code_switch_caset code_case;
1926
+ code_case.add_source_location () = location;
1927
+
1928
+ mp_integer number;
1929
+ bool ret = to_integer (to_constant_expr (*a_it), number);
1930
+ DATA_INVARIANT (!ret, " case label expected to be integer" );
1931
+ code_case.code () = code_gotot (label (integer2string (number)));
1932
+ code_case.code ().add_source_location () =
1933
+ address_map.at (integer2unsigned (number)).source ->source_location ;
1934
+
1935
+ if (a_it == args.begin ())
1936
+ code_case.set_default ();
1937
+ else
1938
+ {
1939
+ auto prev = a_it;
1940
+ prev--;
1941
+ code_case.case_op () = *prev;
1942
+ if (code_case.case_op ().type () != op[0 ].type ())
1943
+ code_case.case_op ().make_typecast (op[0 ].type ());
1944
+ code_case.case_op ().add_source_location () = location;
1945
+ }
1946
+
1947
+ code_block.add (code_case);
1948
+ }
1949
+ }
1950
+
1951
+ code_switch.body () = code_block;
1952
+ return code_switch;
1953
+ }
1954
+
1945
1955
void java_bytecode_convert_methodt::convert_dup2 (
1946
1956
exprt::operandst &op,
1947
1957
exprt::operandst &results)
0 commit comments