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