@@ -115,9 +115,6 @@ class java_bytecode_convert_classt:public messaget
115
115
void convert (const classt &c, const overlay_classest &overlay_classes);
116
116
void convert (symbolt &class_symbol, const fieldt &f);
117
117
118
- // see definition below for more info
119
- static void add_array_types (symbol_tablet &symbol_table);
120
-
121
118
static bool is_overlay_method (const methodt &method)
122
119
{
123
120
return method.has_annotation (ID_overlay_method);
@@ -717,182 +714,6 @@ void java_bytecode_convert_classt::convert(
717
714
}
718
715
}
719
716
720
- // / Register in the \p symbol_table new symbols for the objects
721
- // / java::array[X] where X is byte, float, int, char...
722
- void java_bytecode_convert_classt::add_array_types (symbol_tablet &symbol_table)
723
- {
724
- const std::string letters=" ijsbcfdza" ;
725
-
726
- for (const char l : letters)
727
- {
728
- symbol_typet symbol_type=
729
- to_symbol_type (java_array_type (l).subtype ());
730
-
731
- const irep_idt &symbol_type_identifier=symbol_type.get_identifier ();
732
- if (symbol_table.has_symbol (symbol_type_identifier))
733
- return ;
734
-
735
- java_class_typet class_type;
736
- // we have the base class, java.lang.Object, length and data
737
- // of appropriate type
738
- class_type.set_tag (symbol_type_identifier);
739
- // Note that non-array types don't have "java::" at the beginning of their
740
- // tag, and their name is "java::" + their tag. Since arrays do have
741
- // "java::" at the beginning of their tag we set the name to be the same as
742
- // the tag.
743
- class_type.set_name (symbol_type_identifier);
744
-
745
- class_type.components ().reserve (3 );
746
- class_typet::componentt base_class_component (
747
- " @java.lang.Object" , symbol_typet (" java::java.lang.Object" ));
748
- base_class_component.set_pretty_name (" @java.lang.Object" );
749
- base_class_component.set_base_name (" @java.lang.Object" );
750
- class_type.components ().push_back (base_class_component);
751
-
752
- class_typet::componentt length_component (" length" , java_int_type ());
753
- length_component.set_pretty_name (" length" );
754
- length_component.set_base_name (" length" );
755
- class_type.components ().push_back (length_component);
756
-
757
- class_typet::componentt data_component (
758
- " data" , java_reference_type (java_type_from_char (l)));
759
- data_component.set_pretty_name (" data" );
760
- data_component.set_base_name (" data" );
761
- class_type.components ().push_back (data_component);
762
-
763
- class_type.add_base (symbol_typet (" java::java.lang.Object" ));
764
-
765
- INVARIANT (
766
- is_valid_java_array (class_type),
767
- " Constructed a new type representing a Java Array "
768
- " object that doesn't match expectations" );
769
-
770
- symbolt symbol;
771
- symbol.name =symbol_type_identifier;
772
- symbol.base_name =symbol_type.get (ID_C_base_name);
773
- symbol.is_type =true ;
774
- symbol.type = class_type;
775
- symbol.mode = ID_java;
776
- symbol_table.add (symbol);
777
-
778
- // Also provide a clone method:
779
- // ----------------------------
780
-
781
- const irep_idt clone_name=
782
- id2string (symbol_type_identifier)+" .clone:()Ljava/lang/Object;" ;
783
- code_typet::parametert this_param;
784
- this_param.set_identifier (id2string (clone_name)+" ::this" );
785
- this_param.set_base_name (" this" );
786
- this_param.set_this ();
787
- this_param.type ()=java_reference_type (symbol_type);
788
- const code_typet clone_type ({this_param}, java_lang_object_type ());
789
-
790
- parameter_symbolt this_symbol;
791
- this_symbol.name =this_param.get_identifier ();
792
- this_symbol.base_name =this_param.get_base_name ();
793
- this_symbol.pretty_name =this_symbol.base_name ;
794
- this_symbol.type =this_param.type ();
795
- this_symbol.mode =ID_java;
796
- symbol_table.add (this_symbol);
797
-
798
- const irep_idt local_name=
799
- id2string (clone_name)+" ::cloned_array" ;
800
- auxiliary_symbolt local_symbol;
801
- local_symbol.name =local_name;
802
- local_symbol.base_name =" cloned_array" ;
803
- local_symbol.pretty_name =local_symbol.base_name ;
804
- local_symbol.type =java_reference_type (symbol_type);
805
- local_symbol.mode =ID_java;
806
- symbol_table.add (local_symbol);
807
- const auto &local_symexpr=local_symbol.symbol_expr ();
808
-
809
- code_blockt clone_body;
810
-
811
- code_declt declare_cloned (local_symexpr);
812
- clone_body.move_to_operands (declare_cloned);
813
-
814
- side_effect_exprt java_new_array (
815
- ID_java_new_array,
816
- java_reference_type (symbol_type));
817
- dereference_exprt old_array (this_symbol.symbol_expr (), symbol_type);
818
- dereference_exprt new_array (local_symexpr, symbol_type);
819
- member_exprt old_length (
820
- old_array, length_component.get_name (), length_component.type ());
821
- java_new_array.copy_to_operands (old_length);
822
- code_assignt create_blank (local_symexpr, java_new_array);
823
- clone_body.move_to_operands (create_blank);
824
-
825
- member_exprt old_data (
826
- old_array, data_component.get_name (), data_component.type ());
827
- member_exprt new_data (
828
- new_array, data_component.get_name (), data_component.type ());
829
-
830
- /*
831
- // TODO use this instead of a loop.
832
- codet array_copy;
833
- array_copy.set_statement(ID_array_copy);
834
- array_copy.move_to_operands(new_data);
835
- array_copy.move_to_operands(old_data);
836
- clone_body.move_to_operands(array_copy);
837
- */
838
-
839
- // Begin for-loop to replace:
840
-
841
- const irep_idt index_name=
842
- id2string (clone_name)+" ::index" ;
843
- auxiliary_symbolt index_symbol;
844
- index_symbol.name =index_name;
845
- index_symbol.base_name =" index" ;
846
- index_symbol.pretty_name =index_symbol.base_name ;
847
- index_symbol.type = length_component.type ();
848
- index_symbol.mode =ID_java;
849
- symbol_table.add (index_symbol);
850
- const auto &index_symexpr=index_symbol.symbol_expr ();
851
-
852
- code_declt declare_index (index_symexpr);
853
- clone_body.move_to_operands (declare_index);
854
-
855
- code_fort copy_loop;
856
-
857
- copy_loop.init ()=
858
- code_assignt (index_symexpr, from_integer (0 , index_symexpr.type ()));
859
- copy_loop.cond ()=
860
- binary_relation_exprt (index_symexpr, ID_lt, old_length);
861
-
862
- side_effect_exprt inc (ID_assign);
863
- inc.operands ().resize (2 );
864
- inc.op0 ()=index_symexpr;
865
- inc.op1 ()=plus_exprt (index_symexpr, from_integer (1 , index_symexpr.type ()));
866
- copy_loop.iter ()=inc;
867
-
868
- dereference_exprt old_cell (
869
- plus_exprt (old_data, index_symexpr), old_data.type ().subtype ());
870
- dereference_exprt new_cell (
871
- plus_exprt (new_data, index_symexpr), new_data.type ().subtype ());
872
- code_assignt copy_cell (new_cell, old_cell);
873
- copy_loop.body ()=copy_cell;
874
-
875
- // End for-loop
876
- clone_body.move_to_operands (copy_loop);
877
-
878
- member_exprt new_base_class (
879
- new_array, base_class_component.get_name (), base_class_component.type ());
880
- address_of_exprt retval (new_base_class);
881
- code_returnt return_inst (retval);
882
- clone_body.move_to_operands (return_inst);
883
-
884
- symbolt clone_symbol;
885
- clone_symbol.name =clone_name;
886
- clone_symbol.pretty_name =
887
- id2string (symbol_type_identifier)+" .clone:()" ;
888
- clone_symbol.base_name =" clone" ;
889
- clone_symbol.type =clone_type;
890
- clone_symbol.value =clone_body;
891
- clone_symbol.mode =ID_java;
892
- symbol_table.add (clone_symbol);
893
- }
894
- }
895
-
896
717
bool java_bytecode_convert_class (
897
718
const java_class_loadert::parse_tree_with_overlayst &parse_trees,
898
719
symbol_tablet &symbol_table,
0 commit comments