home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / creation_call.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  196 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. deferred class CREATION_CALL
  17. --
  18. -- For creation all kinds of creation call : CREATION_CALL_1,
  19. -- CREATION_CALL_2, CREATION_CALL_3 and CREATION_CALL_4.
  20. --
  21. -- Sorry for the following class names, but I have no more ideas at this
  22. -- time :-(. Classification used is :
  23. --      CREATION_CALL_1    -->    !!foo
  24. --      CREATION_CALL_2    -->    !BAR!foo
  25. --      CREATION_CALL_3    -->    !!foo.bar(...)
  26. --      CREATION_CALL_4    -->    !BAR!foo.bar(...)
  27. --
  28.  
  29. inherit INSTRUCTION;
  30.  
  31. feature
  32.  
  33.    start_position: POSITION;
  34.          -- Of the first character '!'.
  35.  
  36.    type: TYPE is
  37.          -- Explicit optional generator name if any.
  38.       deferred
  39.       end;
  40.  
  41.    writable: EXPRESSION;
  42.          -- The target of the creation call.
  43.  
  44. feature {CREATION_CALL}
  45.  
  46.    current_type: TYPE;
  47.  
  48. feature
  49.  
  50.    end_mark_comment: BOOLEAN is false;
  51.  
  52. feature
  53.  
  54.    call: PROC_CALL is
  55.          -- Optional initialisation call if any.
  56.          -- Target of `call' is `writable'.
  57.       deferred
  58.       end;
  59.  
  60.    run_feature: RUN_FEATURE;
  61.          -- When checked, if any, the only one corresponding
  62.          -- creation procedure.
  63.  
  64.    arg_count: INTEGER is
  65.       do
  66.          if call /= Void then
  67.             Result := call.arg_count;
  68.          end;
  69.       end;
  70.  
  71.    collect_c_tmp is
  72.       do
  73.       end;
  74.  
  75. feature {NONE} -- Tools for to_runnable :
  76.  
  77.    check_writable(ct: TYPE) is
  78.       require
  79.          current_type = Void;
  80.          ct /= Void
  81.       local
  82.          w: like writable;
  83.       do
  84.          current_type := ct;
  85.          w := writable.to_runnable(ct);
  86.          if w = Void then
  87.             eh.add_position(writable.start_position);
  88.             fatal_error("Bad writable target for creation.");
  89.          else
  90.             writable := w;
  91.          end;
  92.       ensure
  93.          current_type = ct
  94.       end;
  95.  
  96.    check_created_type(t: TYPE) is
  97.       require
  98.          t.is_run_type
  99.       local
  100.          rt: like t;
  101.       do
  102.          rt := t.run_type;
  103.          if small_eiffel.short_flag then
  104.          elseif rt.base_class.is_deferred then
  105.             eh.add_type(rt," is deferred. ");
  106.             warning(start_position,"Cannot create object.");
  107.          end;
  108.          if t.is_formal_generic then
  109.             eh.add_position(start_position);
  110.             eh.append("Creation call on formal generic type (");
  111.             eh.add_type(t,").");
  112.             eh.print_as_fatal_error;
  113.          end;
  114.          rt.run_class.set_at_run_time;
  115.       end;
  116.  
  117. feature {NONE}
  118.  
  119.    frozen c2c_opening(t: TYPE) is
  120.       require
  121.          t.is_reference
  122.       local
  123.          rc: RUN_CLASS;
  124.          once_result: ONCE_RESULT;
  125.       do
  126.          rc := t.run_class;
  127.          cpp.se_trace_ins(start_position);
  128.          cpp.put_character('{');
  129.          gc_handler.allocation(rc);
  130.          cpp.expanded_attributes(t);
  131.          once_result ?= writable;
  132.          if once_result /= Void then
  133.             cpp.put_string(once_result.c_variable_name);
  134.             cpp.put_string("=(void*)n;%N");
  135.          end;
  136.       end;
  137.  
  138.    frozen c2c_closing(t: TYPE) is
  139.       require
  140.          t.is_reference
  141.       local
  142.          once_result: ONCE_RESULT;
  143.       do
  144.          once_result ?= writable;
  145.          if once_result = Void then
  146.             writable.compile_to_c;
  147.             cpp.put_character('=');
  148.             cpp.put_string(fz_cast_t0_star);
  149.             cpp.put_character('n');
  150.             cpp.put_string(fz_00);
  151.          end;
  152.          if cpp.call_invariant_start(t) then
  153.             cpp.put_character('n');
  154.             cpp.call_invariant_end;
  155.             cpp.put_character(';');
  156.          end;
  157.          cpp.put_character('}');
  158.          cpp.put_character('%N');
  159.       end;
  160.  
  161.    frozen c2c_clear_expanded(id: INTEGER) is
  162.          -- Produce C code to reset the writable expanded
  163.          -- to the default value.
  164.       do
  165.          writable.compile_to_c;
  166.          cpp.put_character('=');
  167.          cpp.put_character('M');
  168.          cpp.put_integer(id);
  169.          cpp.put_string(fz_00);
  170.       end;
  171.  
  172. feature {NONE}
  173.  
  174.    compile_to_jvm0(t: TYPE) is
  175.          -- Push the new object with default initialization.
  176.       require
  177.          t /= Void
  178.       local
  179.          dummy: INTEGER;
  180.       do
  181.          if t.is_reference then
  182.             t.run_class.jvm_basic_new;
  183.          else
  184.             dummy := t.jvm_push_default;
  185.          end;
  186.       end;
  187.  
  188. invariant
  189.  
  190.    start_position /= Void;
  191.  
  192.    writable.is_writable;
  193.  
  194. end -- CREATION_CALL
  195.  
  196.