home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / e_strip.e < prev    next >
Text File  |  1999-06-05  |  10KB  |  378 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class E_STRIP
  17.    --
  18.    -- To store a strip expression like :
  19.    --                                        strip(foo, bar)
  20.    --
  21.  
  22. inherit EXPRESSION;
  23.  
  24. creation make
  25.  
  26. feature
  27.  
  28.    start_position: POSITION;
  29.  
  30. feature {E_STRIP}
  31.  
  32.    current_type: TYPE;
  33.  
  34. feature {NONE}
  35.  
  36.    list: FEATURE_NAME_LIST;
  37.  
  38.    make(sp: like start_position; l: like list) is
  39.       require
  40.          sp /= Void
  41.       do
  42.          start_position := sp;
  43.          list := l;
  44.       ensure
  45.          start_position = sp;
  46.          list = l
  47.       end;
  48.  
  49. feature
  50.  
  51.    is_current: BOOLEAN is false;
  52.  
  53.    is_writable: BOOLEAN is false;
  54.  
  55.    is_manifest_string: BOOLEAN is false;
  56.  
  57.    is_result: BOOLEAN is false;
  58.  
  59.    is_void: BOOLEAN is false;
  60.  
  61.    use_current: BOOLEAN is true;
  62.  
  63.    can_be_dropped, c_simple: BOOLEAN is false;
  64.  
  65.    is_static: BOOLEAN is false;
  66.  
  67.    is_pre_computable: BOOLEAN is false;
  68.  
  69.    isa_dca_inline_argument: INTEGER is 0;
  70.  
  71.    static_result_base_class: BASE_CLASS is
  72.       do
  73.          Result := small_eiffel.get_class(as_array);
  74.       end;
  75.  
  76.    static_value: INTEGER is
  77.       do
  78.       end;
  79.  
  80.    dca_inline_argument(formal_arg_type: TYPE) is
  81.       do
  82.       end;
  83.  
  84.    assertion_check(tag: CHARACTER) is
  85.       do
  86.       end;
  87.  
  88.    afd_check is
  89.       do
  90.       end;
  91.  
  92.    frozen mapping_c_target(target_type: TYPE) is
  93.       do
  94.          compile_to_c;
  95.       end;
  96.  
  97.    frozen mapping_c_arg(formal_arg_type: TYPE) is
  98.       do
  99.          compile_to_c;
  100.       end;
  101.  
  102.    collect_c_tmp is
  103.       do
  104.       end;
  105.  
  106.    compile_to_c is
  107.       local
  108.          wa: ARRAY[RUN_FEATURE_2]
  109.          rf2: RUN_FEATURE_2;
  110.          i: INTEGER;
  111.          ct: TYPE;
  112.       do
  113.          manifest_array_pool.c_call(result_type);
  114.          cpp.put_character('(');
  115.          ct := current_type;
  116.          wa := ct.run_class.writable_attributes;
  117.          vwst1_check(wa);
  118.          cpp.put_integer(array_count(wa));
  119.          if wa /= Void then
  120.             from
  121.                i := wa.upper;
  122.             until
  123.                i = 0
  124.             loop
  125.                rf2 := wa.item(i);
  126.                if list = Void or else not list.has(rf2.name) then
  127.                   cpp.put_character(',');
  128.                   rf2.result_type.to_reference;
  129.                   cpp.put_character('(');
  130.                   cpp.print_current;
  131.                   if current_type.is_expanded then
  132.                      cpp.put_character('.');
  133.                   else
  134.                      cpp.put_string("->");
  135.                   end;
  136.                   cpp.put_character('_');
  137.                   cpp.put_string(rf2.name.to_string);
  138.                   cpp.put_character(')');
  139.                end;
  140.                i := i - 1;
  141.             end;
  142.          end;
  143.          cpp.put_character(')');
  144.       end;
  145.  
  146.    c_declare_for_old is
  147.       do
  148.       end;
  149.  
  150.    compile_to_c_old is
  151.       do
  152.       end;
  153.  
  154.    compile_to_jvm_old is
  155.       do
  156.       end;
  157.  
  158.    compile_to_jvm is
  159.       local
  160.          ca: like code_attribute;
  161.          cp: like constant_pool;
  162.          count, i, j, idx, idx_array, space: INTEGER;
  163.          wa: ARRAY[RUN_FEATURE_2]
  164.          rf2: RUN_FEATURE_2;
  165.       do
  166.          ca := code_attribute;
  167.          cp := constant_pool;
  168.          wa := current_type.run_class.writable_attributes;
  169.          count := array_count(wa);
  170.          result_type.run_class.jvm_basic_new;
  171.          ca.opcode_dup;
  172.          ca.opcode_iconst_1;
  173.          idx_array := result_type.run_class.jvm_constant_pool_index;
  174.          idx := cp.idx_fieldref4(idx_array,as_lower,fz_i);
  175.          ca.opcode_putfield(idx,-2);
  176.          ca.opcode_dup;
  177.          ca.opcode_push_integer(count);
  178.          idx := cp.idx_fieldref4(idx_array,as_upper,fz_i);
  179.          ca.opcode_putfield(idx,-2);
  180.          ca.opcode_dup;
  181.          ca.opcode_push_integer(count);
  182.          idx := cp.idx_fieldref4(idx_array,as_capacity,fz_i);
  183.          ca.opcode_putfield(idx,-2);
  184.          if count > 0 then
  185.             -- pile = array
  186.             ca.opcode_push_integer(count);
  187.             type_any.jvm_xnewarray;
  188.             -- pile = array storage
  189.             ca.opcode_dup2;
  190.             -- pile = array storage array storage
  191.             tmp_string.clear;
  192.             tmp_string.extend('[');
  193.             tmp_string.append(jvm_root_descriptor);
  194.             idx := cp.idx_fieldref4(idx_array,as_storage,tmp_string);
  195.             ca.opcode_putfield(idx,-2);
  196.             -- pile = array storage
  197.             from
  198.                i := wa.upper;
  199.                j := 0;
  200.             until
  201.                i = 0
  202.             loop
  203.                rf2 := wa.item(i);
  204.                if list = Void or else not list.has(rf2.name) then
  205.                   if j < count - 1 then
  206.                      ca.opcode_dup;
  207.                   end;
  208.                   ca.opcode_push_integer(j);
  209.                   current_type.jvm_push_local(0);
  210.                   idx := cp.idx_fieldref(rf2);
  211.                   ca.opcode_getfield(idx,0);
  212.                   space := rf2.result_type.jvm_convert_to(type_any);
  213.                   result_type.jvm_xastore;
  214.                   j := j + 1;
  215.                end;
  216.                i := i - 1;
  217.             end;
  218.          end;
  219.       end;
  220.  
  221.    compile_target_to_jvm is
  222.       do
  223.       end;
  224.  
  225.    jvm_branch_if_false: INTEGER is
  226.       do
  227.       end;
  228.  
  229.    jvm_branch_if_true: INTEGER is
  230.       do
  231.       end;
  232.  
  233.    compile_to_jvm_into(dest: TYPE): INTEGER is
  234.       do
  235.          Result := 1;
  236.          compile_to_jvm;
  237.       end;
  238.  
  239.    result_type: TYPE_ARRAY is
  240.       do
  241.          if result_type_memory = Void then
  242.             !!result_type_memory.make(start_position,type_any);
  243.             result_type_memory := result_type_memory.to_runnable(type_any);
  244.             result_type_memory.run_class.set_at_run_time;
  245.             result_type_memory.load_basic_features;
  246.             manifest_array_pool.register(result_type_memory);
  247.          end;
  248.          Result := result_type_memory;
  249.       end;
  250.  
  251.    to_runnable(ct: TYPE): like Current is
  252.       do
  253.          if current_type = Void then
  254.             current_type := ct;
  255.             current_type.run_class.set_strip_used;
  256.             Result := Current;
  257.          else
  258.             !!Result.make(start_position,list);
  259.             Result := Result.to_runnable(ct);
  260.          end;
  261.       end;
  262.  
  263.    pretty_print is
  264.       do
  265.          fmt.put_string("strip (");
  266.          fmt.level_incr;
  267.          if list /= Void then
  268.             list.pretty_print;
  269.          end;
  270.          fmt.put_string(")");
  271.          fmt.level_decr;
  272.       end;
  273.  
  274.    print_as_target is
  275.       do
  276.          pretty_print;
  277.          fmt.put_character('.');
  278.       end;
  279.  
  280.    bracketed_pretty_print is
  281.       do
  282.          fmt.put_character('(');
  283.          pretty_print;
  284.          fmt.put_character(')');
  285.       end;
  286.  
  287.    short is
  288.       do
  289.          short_print.hook_or("op_strip","strip (");
  290.          if list /= Void then
  291.             list.short;
  292.          end;
  293.          short_print.hook_or("cl_strip",")");
  294.       end;
  295.  
  296.    short_target is
  297.       do
  298.          short;
  299.          short_print.a_dot;
  300.       end;
  301.  
  302.    precedence: INTEGER is
  303.       do
  304.          Result := 11;
  305.       end;
  306.  
  307.    jvm_assign is
  308.       do
  309.       end;
  310.  
  311. feature {NONE}
  312.  
  313.    vwst1: STRING is "This is not an attribute of Current (VWST.1)."
  314.  
  315.    vwst1_check(wa: ARRAY[RUN_FEATURE_2]) is
  316.       local
  317.          i, j: INTEGER;
  318.          fn: FEATURE_NAME;
  319.          rf2: RUN_FEATURE_2;
  320.       do
  321.          if wa = Void then
  322.             if list = Void then
  323.             else
  324.                eh.add_position(list.item(1).start_position);
  325.                eh.append(vwst1);
  326.                eh.print_as_error;
  327.             end;
  328.          elseif list /= Void then
  329.             from
  330.                i := list.count;
  331.             until
  332.                i = 0
  333.             loop
  334.                fn := list.item(i);
  335.                from
  336.                   j := wa.upper;
  337.                   rf2 := Void;
  338.                until
  339.                   j <= 0
  340.                loop
  341.                   rf2 := wa.item(j);
  342.                   if rf2.name.to_string = fn.to_string then
  343.                      j := -1;
  344.                   else
  345.                      j := j - 1;
  346.                   end;
  347.                end;
  348.                if j = 0 then
  349.                   eh.add_position(fn.start_position);
  350.                   eh.append(vwst1);
  351.                   eh.print_as_error;
  352.                end;
  353.                i := i - 1;
  354.             end;
  355.          end;
  356.       end;
  357.  
  358.    result_type_memory: like result_type;
  359.  
  360.    array_count(wa: ARRAY[RUN_FEATURE_2]): INTEGER is
  361.       do
  362.          if wa /= Void then
  363.             Result := wa.count;
  364.          end;
  365.          if list /= Void then
  366.             Result := Result - list.count;
  367.          end;
  368.       ensure
  369.          Result >= 0
  370.       end;
  371.  
  372.    tmp_string: STRING is
  373.       once
  374.          !!Result.make(32);
  375.       end;
  376.  
  377. end -- E_STRIP
  378.