home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / assignment.e < prev    next >
Text File  |  1999-06-05  |  8KB  |  288 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 ASSIGNMENT
  17.    --
  18.    -- For instruction like :
  19.    --                          foo := bar;
  20.    --                          foo := bar + 1;
  21.    --
  22.    --
  23.  
  24. inherit INSTRUCTION;
  25.  
  26. creation make
  27.  
  28. feature
  29.  
  30.    left_side: EXPRESSION;
  31.  
  32.    right_side: EXPRESSION;
  33.  
  34. feature {NONE}
  35.  
  36.    current_type: TYPE;
  37.  
  38. feature
  39.  
  40.    make(ls: like left_side; rs: like right_side) is
  41.       require
  42.          ls.is_writable;
  43.          ls.start_position /= Void;
  44.          rs /= Void
  45.       do
  46.          left_side := ls;
  47.          right_side := rs;
  48.       ensure
  49.          left_side = ls;
  50.          right_side = rs
  51.       end;
  52.  
  53. feature
  54.  
  55.    end_mark_comment: BOOLEAN is false;
  56.  
  57. feature
  58.  
  59.    is_pre_computable: BOOLEAN is
  60.       local
  61.          call: CALL;
  62.          rf6: RUN_FEATURE_6;
  63.       do
  64.          if right_side.is_pre_computable then
  65.             call ?= right_side;
  66.             if call /= Void then
  67.                rf6 ?= call.run_feature;
  68.                Result := rf6 = Void;
  69.             else
  70.                Result := true;
  71.             end;
  72.          end;
  73.       end;
  74.  
  75.    afd_check is
  76.       do
  77.          right_side.afd_check;
  78.       end;
  79.  
  80.    collect_c_tmp is
  81.       do
  82.          right_side.collect_c_tmp;
  83.       end;
  84.  
  85.    compile_to_c is
  86.       local
  87.          left_run_type, right_run_type: TYPE;
  88.       do
  89.          if run_control.no_check then
  90.             cpp.se_trace_ins(start_position);
  91.          end;
  92.          left_run_type := left_type.run_type;
  93.          right_run_type := right_type.run_type;
  94.          if left_run_type.is_reference then
  95.             if right_run_type.is_reference then
  96.                -- ------------------------ Reference into Reference :
  97.                left_side.compile_to_c;
  98.                cpp.put_character('=');
  99.                if right_side.is_current then
  100.                   cpp.put_string(fz_cast_t0_star);
  101.                end;
  102.                right_side.compile_to_c;
  103.                cpp.put_string(fz_00);
  104.             else
  105.                -- ------------------------- Expanded into Reference :
  106.                left_side.compile_to_c;
  107.                cpp.put_character('=');
  108.                right_run_type.to_reference;
  109.                cpp.put_character('(');
  110.                right_side.compile_to_c;
  111.                cpp.put_character(')');
  112.                cpp.put_string(fz_00);
  113.             end;
  114.          else
  115.             check
  116.                left_run_type.is_expanded
  117.             end;
  118.             if right_run_type.is_reference then
  119.                -- ------------------------- Reference into Expanded :
  120.                -- (std_copy or fail when Void).
  121.                eh.add_position(left_side.start_position);
  122.                fatal_error("Not Yet Implemented %
  123.                            %(ASSIGNMENT/Reference into Expanded).");
  124.             else
  125.                -- -------------------------- Expanded into Expanded :
  126.                if left_run_type.is_bit then
  127.                   bit_into_bit(left_run_type,right_run_type);
  128.                else
  129.                   c_coding1;
  130.                end;
  131.             end;
  132.          end;
  133.       end;
  134.  
  135.    compile_to_jvm is
  136.       local
  137.          space: INTEGER;
  138.          ls: EXPRESSION;
  139.       do
  140.          ls := left_side;
  141.          space := right_side.compile_to_jvm_into(ls.result_type.run_type);
  142.          ls.jvm_assign;
  143.       end;
  144.  
  145.    use_current: BOOLEAN is
  146.       do
  147.          Result := left_side.use_current;
  148.          Result := Result or else right_side.use_current;
  149.       end;
  150.  
  151.    right_type: TYPE is
  152.       do
  153.          Result := right_side.result_type;
  154.       ensure
  155.          Result /= Void
  156.       end;
  157.  
  158.    left_type: TYPE is
  159.       do
  160.          Result := left_side.result_type;
  161.       ensure
  162.          Result /= Void
  163.       end;
  164.  
  165.    start_position: POSITION is
  166.       do
  167.          Result := left_side.start_position;
  168.       end;
  169.  
  170.    to_runnable(ct: TYPE): like Current is
  171.       local
  172.          l, r: EXPRESSION;
  173.       do
  174.          l := left_side.to_runnable(ct);
  175.          if l = Void then
  176.             eh.add_position(left_side.start_position);
  177.             fatal_error(fz_blhsoa);
  178.          end;
  179.          r := right_side.to_runnable(ct);
  180.          if r = Void then
  181.             eh.add_position(right_side.start_position);
  182.             fatal_error(fz_brhsoa);
  183.          end;
  184.          if not r.result_type.is_a(l.result_type) then
  185.             eh.add_position(l.start_position);
  186.             fatal_error(" Bad assignment.");
  187.          end;
  188.          if l = left_side and then r = right_side then
  189.             Result := Current;
  190.             implicit_conversion;
  191.          else
  192.             !!Result.make(l,r);
  193.             Result.implicit_conversion;
  194.          end;
  195.       end;
  196.  
  197.    pretty_print is
  198.       do
  199.          pretty_print_assignment(left_side,":=",right_side);
  200.       end;
  201.  
  202. feature {ASSIGNMENT}
  203.  
  204.    implicit_conversion is
  205.       local
  206.          left_run_type, right_run_type: TYPE;
  207.       do
  208.          if nb_errors = 0 then
  209.             left_run_type := left_type.run_type;
  210.             right_run_type := right_type.run_type;
  211.             if left_run_type.is_reference then
  212.                if right_run_type.is_reference then
  213.                   -- ------------------------- Reference into Reference :
  214.                else
  215.                   -- -------------------------- Expanded into Reference :
  216.                   right_run_type.used_as_reference;
  217.                end;
  218.             else
  219.                if right_run_type.is_reference then
  220.                   -- -------------------------- Reference into Expanded :
  221.                   if right_side.is_void then
  222.                      eh.add_position(right_side.start_position);
  223.                      eh.append("Void may not be assigned to an %
  224.                                %expanded entity. Left hand side is ");
  225.                      eh.add_type(left_type,".");
  226.                      eh.print_as_error;
  227.                   else
  228.                      warning(left_side.start_position,
  229.                              "ASSIGNMENT/Not Yet Implemented.");
  230.                   end;
  231.                else
  232.                   -- --------------------------- Expanded into Expanded :
  233.                end;
  234.             end;
  235.          end;
  236.       end;
  237.  
  238. feature {NONE}
  239.  
  240.    c_coding1 is
  241.       do
  242.          left_side.compile_to_c;
  243.          cpp.put_character('=');
  244.          right_side.compile_to_c;
  245.          cpp.put_string(fz_00);
  246.       end;
  247.  
  248.    bit_into_bit(left_t, right_t: TYPE) is
  249.       require
  250.          left_t.is_bit;
  251.          right_t.is_bit
  252.       local
  253.          left, right: TYPE_BIT;
  254.       do
  255.          left ?= left_t;
  256.          right ?= right_t;
  257.          if left.is_c_char then -- ------- unsigned char <- unsigned char :
  258.                c_coding1;
  259.          elseif left.is_c_int then
  260.             -- ---------------------- unsigned int <- unsigned [char|int] :
  261.             c_coding1;
  262.          elseif right.is_c_unsigned_ptr then -- -- unsigned* <- unsigned* :
  263.             cpp.put_string("memcpy(");
  264.             left_side.mapping_c_arg(left);
  265.             cpp.put_character(',');
  266.             right_side.mapping_c_arg(right);
  267.             cpp.put_character(',');
  268.             cpp.put_integer(left.space_for_variable);
  269.             cpp.put_character(')');
  270.             cpp.put_string(fz_00);
  271.          else
  272.             cpp.put_string("memset(&");
  273.             left_side.compile_to_c;
  274.             cpp.put_string(",0,sizeof(");
  275.             left_side.compile_to_c;
  276.             cpp.put_string(fz_16);
  277.          end;
  278.       end;
  279.  
  280. invariant
  281.  
  282.    left_side.is_writable;
  283.  
  284.    right_side /= Void
  285.  
  286. end -- ASSIGNMENT
  287.  
  288.