home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / e_old.e < prev    next >
Text File  |  1999-06-05  |  7KB  |  313 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_OLD
  17.    --
  18.    -- To store instruction "old ..." usable in an ensure clause.
  19.    --
  20.  
  21. inherit EXPRESSION;
  22.  
  23. creation make
  24.  
  25. feature
  26.  
  27.    expression: EXPRESSION;
  28.  
  29. feature {NONE}
  30.  
  31.    current_type: TYPE;
  32.  
  33.    local_c_name_memory: STRING;
  34.          -- The C name for the local variable.
  35.  
  36.    id: INTEGER;
  37.          -- Used in Java byte code to gives a number to the
  38.          -- the extra local variable.
  39.  
  40.    make(exp: like expression) is
  41.       require
  42.          exp /= Void
  43.       do
  44.          expression := exp;
  45.       ensure
  46.          expression = exp;
  47.       end;
  48.  
  49. feature
  50.  
  51.    is_current: BOOLEAN is false;
  52.  
  53.    is_writable: BOOLEAN is false;
  54.  
  55.    is_static: BOOLEAN is false;
  56.  
  57.    is_pre_computable: BOOLEAN is false;
  58.  
  59.    is_manifest_string: BOOLEAN is false;
  60.  
  61.    is_result: BOOLEAN is false;
  62.  
  63.    is_void: BOOLEAN is false;
  64.  
  65.    can_be_dropped: BOOLEAN is false;
  66.  
  67.    c_simple: 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 := expression.static_result_base_class;
  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.    result_type: TYPE is
  85.       do
  86.          Result := expression.result_type;
  87.       end;
  88.  
  89.    assertion_check(tag: CHARACTER) is
  90.       do
  91.          if vaol_check_memory.item = Void then
  92.             vaol_check_memory.set_item(Current);
  93.          else
  94.             eh.add_position(vaol_check_memory.item.start_position);
  95.             eh.append("Must not use old inside some old %
  96.                        %expression (VAOL.2).");
  97.             eh.print_as_fatal_error;
  98.          end;
  99.          expression.assertion_check(tag);
  100.          vaol_check_memory.clear;
  101.       end;
  102.  
  103.    afd_check is
  104.       do
  105.          expression.afd_check;
  106.       end;
  107.  
  108.    to_runnable(ct: TYPE): like Current is
  109.       local
  110.          exp: like expression;
  111.       do
  112.          if current_type = Void then
  113.             current_type := ct;
  114.             exp := expression.to_runnable(ct);
  115.             if exp = Void then
  116.                error(start_position,"Bad old expression.");
  117.             else
  118.                expression := exp;
  119.             end;
  120.             Result := Current;
  121.          else
  122.             !!Result.make(expression);
  123.             Result := Result.to_runnable(ct);
  124.          end;
  125.       end;
  126.  
  127.    start_position: POSITION is
  128.       do
  129.          Result := expression.start_position;
  130.       end;
  131.  
  132.    pretty_print is
  133.       do
  134.          fmt.put_string("old ");
  135.          fmt.level_incr;
  136.          expression.pretty_print;
  137.          fmt.level_decr;
  138.       end;
  139.  
  140.    print_as_target is
  141.       do
  142.          fmt.put_character('(');
  143.          pretty_print;
  144.          fmt.put_character(')');
  145.          fmt.put_character('.');
  146.       end;
  147.  
  148.    bracketed_pretty_print is
  149.       do
  150.          fmt.put_character('(');
  151.          pretty_print;
  152.          fmt.put_character(')');
  153.       end;
  154.  
  155.    short is
  156.       do
  157.          short_print.hook_or("old","old ");
  158.          expression.short;
  159.       end;
  160.  
  161.    short_target is
  162.       do
  163.          bracketed_short;
  164.          short_print.a_dot;
  165.       end;
  166.  
  167.    precedence: INTEGER is
  168.       do
  169.          Result := 11;
  170.       end;
  171.  
  172.    frozen mapping_c_target(target_type: TYPE) is
  173.       do
  174.          compile_to_c;
  175.       end;
  176.  
  177.    frozen mapping_c_arg(formal_arg_type: TYPE) is
  178.       do
  179.          compile_to_c;
  180.       end;
  181.  
  182.    c_declare_for_old is
  183.       local
  184.          t: TYPE;
  185.          name: STRING;
  186.          p: POSITION;
  187.       do
  188.          name := local_c_name;
  189.          t := result_type.run_type;
  190.          tmp_string.clear;
  191.          t.c_type_for_argument_in(tmp_string);
  192.          tmp_string.extend(' ');
  193.          tmp_string.append(name);
  194.          tmp_string.extend('=');
  195.          t.c_initialize_in(tmp_string);
  196.          tmp_string.append(fz_00);
  197.          cpp.put_string(tmp_string);
  198.          if run_control.no_check then
  199.             c_frame_descriptor_locals.append("(void**)&");
  200.             c_frame_descriptor_locals.append(name);
  201.             c_frame_descriptor_locals.extend(',');
  202.             c_frame_descriptor_local_count.increment;
  203.             p := start_position;
  204.             c_frame_descriptor_format.append("old l");
  205.             p.line.append_in(c_frame_descriptor_format);
  206.             c_frame_descriptor_format.extend('c');
  207.             p.column.append_in(c_frame_descriptor_format);
  208.             c_frame_descriptor_format.append(p.base_class_name.to_string);
  209.             t.c_frame_descriptor;
  210.          end;
  211.       end;
  212.  
  213.    compile_to_c_old is
  214.       local
  215.          t: TYPE;
  216.       do
  217.          t := result_type.run_type;
  218.          tmp_string.copy(local_c_name);
  219.          tmp_string.extend('=');
  220.          cpp.put_string(tmp_string);
  221.          expression.mapping_c_arg(t);
  222.          cpp.put_string(fz_00);
  223.       end;
  224.  
  225.    collect_c_tmp is
  226.       do
  227.       end;
  228.  
  229.    compile_to_c is
  230.       do
  231.          cpp.put_string(local_c_name);
  232.       end;
  233.  
  234.    compile_to_jvm_old is
  235.       local
  236.          e: like expression;
  237.          rt: TYPE;
  238.       do
  239.          e := expression;
  240.          rt := e.result_type.run_type;
  241.          id := code_attribute.extra_local(rt);
  242.          e.compile_to_jvm;
  243.          rt.jvm_write_local(id);
  244.       end;
  245.  
  246.    compile_to_jvm is
  247.       do
  248.          expression.result_type.jvm_push_local(id);
  249.       end;
  250.  
  251.    compile_target_to_jvm is
  252.       do
  253.          standard_compile_target_to_jvm;
  254.       end;
  255.  
  256.    jvm_branch_if_false: INTEGER is
  257.       do
  258.          Result := jvm_standard_branch_if_false;
  259.       end;
  260.  
  261.    jvm_branch_if_true: INTEGER is
  262.       do
  263.          Result := jvm_standard_branch_if_true;
  264.       end;
  265.  
  266.    compile_to_jvm_into(dest: TYPE): INTEGER is
  267.       do
  268.          Result := standard_compile_to_jvm_into(dest);
  269.       end;
  270.  
  271.    jvm_assign is
  272.       do
  273.       end;
  274.  
  275.    use_current: BOOLEAN is
  276.       do
  277.          Result := expression.use_current;
  278.       end;
  279.  
  280. feature {NONE}
  281.  
  282.    local_c_name: STRING is
  283.       do
  284.          if local_c_name_memory = Void then
  285.             tmp_string.clear;
  286.             tmp_string.extend('o');
  287.             start_position.base_class.id.append_in(tmp_string);
  288.             tmp_string.extend('_');
  289.             start_position.line.append_in(tmp_string);
  290.             tmp_string.extend('_');
  291.             start_position.column.append_in(tmp_string);
  292.             local_c_name_memory := tmp_string.twin;
  293.          end;
  294.          Result := local_c_name_memory;
  295.       end;
  296.  
  297.    tmp_string: STRING is
  298.       once
  299.          !!Result.make(12);
  300.       end;
  301.  
  302.    vaol_check_memory: MEMO[E_OLD] is
  303.       once
  304.          !!Result;
  305.       end;
  306.  
  307. invariant
  308.  
  309.    expression /= Void;
  310.  
  311. end -- E_OLD
  312.  
  313.