home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / creation_call.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  4.3 KB  |  170 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://www.loria.fr/SmallEiffel
  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 sort 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
  45.    
  46.    end_mark_comment: BOOLEAN is false;
  47.  
  48. feature
  49.    
  50.    call: PROC_CALL is
  51.      -- Optional initialisation call if any.
  52.      -- Target of `call' is `writable'.
  53.       deferred
  54.       end;
  55.    
  56.    run_feature: RUN_FEATURE;
  57.      -- When checked, if any, the only one corresponding 
  58.      -- creation procedure.
  59.    
  60.    arg_count: INTEGER is
  61.       do
  62.      if call /= Void then
  63.         Result := call.arg_count;
  64.      end;
  65.       end;
  66.    
  67. feature {NONE} -- Tools for to_runnable :
  68.    
  69.    check_writable(rc: like run_compound) is
  70.       require
  71.      run_compound = Void;
  72.      rc /= Void;
  73.       local
  74.      w: like writable;
  75.       do
  76.      run_compound := rc;
  77.      w := writable.to_runnable(current_type);
  78.      if w = Void then
  79.         eh.add_position(writable.start_position);
  80.         fatal_error("Bad writable target for creation.");
  81.      else
  82.         writable := w;
  83.      end;
  84.       ensure
  85.      run_compound = rc;
  86.      writable.is_checked;
  87.       end;
  88.    
  89.    check_created_type(t: TYPE) is
  90.       require
  91.      t.is_run_type
  92.       local
  93.      rt: like t;
  94.       do
  95.      rt := t.run_type;
  96.      if small_eiffel.short_flag then
  97.      elseif rt.base_class.is_deferred then
  98.         eh.add_type(rt," is deferred. ");
  99.         eh.add_position(start_position);
  100.         fatal_error("Cannot create object.");
  101.      end;
  102.      if t.is_formal_generic then
  103.         eh.add_position(start_position);
  104.         eh.append("Creation call on formal generic type (");
  105.         eh.add_type(t,").");
  106.         eh.print_as_fatal_error;
  107.      end;
  108.      rt.run_class.set_at_run_time;
  109.       end;
  110.    
  111. feature {NONE}
  112.    
  113.    frozen c2c_opening(t: TYPE) is
  114.       local
  115.      rc: RUN_CLASS;
  116.       do
  117.      rc := t.run_class;
  118.      cpp.rs_push_position('5',start_position);
  119.      cpp.put_character('{');
  120.      gc_handler.put_new(rc);
  121.      cpp.expanded_attributes(t);
  122.       end;
  123.  
  124.    frozen c2c_closing(t: TYPE) is
  125.       do
  126.            writable.compile_to_c;
  127.      cpp.put_character('=');
  128.      cpp.put_string(fz_cast_t0_star);
  129.      cpp.put_character('n');
  130.      cpp.put_string(fz_00);
  131.      if cpp.call_invariant_start(t) then
  132.         cpp.put_character('n');
  133.         cpp.call_invariant_end;
  134.         cpp.put_character(';');
  135.      end;
  136.      cpp.put_character('}');
  137.      cpp.put_character('%N');
  138.      cpp.rs_pop_position;
  139.       end;
  140.  
  141.    frozen c2c_clear_expanded(id: INTEGER) is
  142.      -- Produce C code to reset the writable expanded
  143.      -- to the default value.
  144.       do
  145.      writable.compile_to_c;
  146.      cpp.put_character('=');
  147.      cpp.put_character('M');
  148.      cpp.put_integer(id);
  149.      cpp.put_string(fz_00);
  150.       end;
  151.  
  152. feature {NONE}
  153.  
  154.    compile_to_jvm0(t: TYPE) is
  155.      -- Push the new object with default initialization.
  156.       require
  157.      t /= Void
  158.       do
  159.      t.run_class.jvm_push_default;
  160.       end;
  161.  
  162. invariant
  163.    
  164.    start_position /= Void;
  165.    
  166.    writable.is_writable;
  167.  
  168. end -- CREATION_CALL
  169.  
  170.