home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / type_character.e < prev    next >
Text File  |  1999-06-05  |  5KB  |  230 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 TYPE_CHARACTER
  17. --
  18. -- For CHARACTER declaration :
  19. --        foo : CHARACTER;
  20. --
  21.  
  22. inherit
  23.    TYPE_BASIC_EIFFEL_EXPANDED
  24.       redefine is_character
  25.       end;
  26.  
  27. creation make
  28.  
  29. feature
  30.  
  31.    is_character: BOOLEAN is true;
  32.  
  33.    id: INTEGER is 3;
  34.  
  35. feature
  36.  
  37.    make(sp: like start_position) is
  38.       do
  39.          !!base_class_name.make(as_character,sp);
  40.       end;
  41.  
  42. feature
  43.  
  44.    space_for_variable, space_for_object: INTEGER is
  45.       do
  46.          Result := 1;
  47.       end;
  48.  
  49.    used_as_reference is
  50.       once
  51.          load_ref(as_character_ref);
  52.       end;
  53.  
  54.    smallest_ancestor(other: TYPE): TYPE is
  55.       local
  56.          rto: TYPE;
  57.       do
  58.          rto := other.run_type;
  59.          if rto.is_character then
  60.             Result := Current;
  61.          else
  62.             Result := type_character_ref.smallest_ancestor(rto);
  63.          end;
  64.       end;
  65.  
  66.    is_a(other: TYPE): BOOLEAN is
  67.       do
  68.          if other.is_character then
  69.             Result := true;
  70.          else
  71.             Result := base_class.is_subclass_of(other.base_class);
  72.             if Result then
  73.                used_as_reference;
  74.             end;
  75.          end;
  76.          if not Result then
  77.             eh.add_type(Current,fz_inako);
  78.             eh.add_type(other,fz_dot);
  79.          end;
  80.       end;
  81.  
  82.    to_runnable(rt: TYPE): like Current is
  83.       do
  84.          Result := Current;
  85.          check_type;
  86.       end;
  87.  
  88.    written_mark, run_time_mark: STRING is
  89.       do
  90.          Result := as_character;
  91.       end;
  92.  
  93.    c_type_for_argument_in(str: STRING) is
  94.       do
  95.          str.extend('T');
  96.          str.extend('3');
  97.       end;
  98.  
  99.    cast_to_ref is
  100.       do
  101.          type_character_ref.mapping_cast;
  102.       end;
  103.  
  104.    jvm_descriptor_in(str: STRING) is
  105.       do
  106.          str.extend('B');
  107.       end;
  108.  
  109.    jvm_return_code is
  110.       do
  111.          code_attribute.opcode_ireturn;
  112.       end;
  113.  
  114.    jvm_push_local(offset: INTEGER) is
  115.       do
  116.          code_attribute.opcode_iload(offset);
  117.       end;
  118.  
  119.    jvm_push_default: INTEGER is
  120.       do
  121.          code_attribute.opcode_iconst_0;
  122.          Result := 1;
  123.       end;
  124.  
  125.    jvm_write_local(offset: INTEGER) is
  126.       do
  127.          code_attribute.opcode_istore(offset);
  128.       end;
  129.  
  130.    jvm_xnewarray is
  131.       do
  132.          code_attribute.opcode_newarray(8);
  133.       end;
  134.  
  135.    jvm_xastore is
  136.       do
  137.          code_attribute.opcode_bastore;
  138.       end;
  139.  
  140.    jvm_xaload is
  141.       do
  142.          code_attribute.opcode_baload;
  143.       end;
  144.  
  145.    jvm_if_x_eq: INTEGER is
  146.       do
  147.          Result := code_attribute.opcode_if_icmpeq;
  148.       end;
  149.  
  150.    jvm_if_x_ne: INTEGER is
  151.       do
  152.          Result := code_attribute.opcode_if_icmpne;
  153.       end;
  154.  
  155.    jvm_to_reference is
  156.       local
  157.          rc: RUN_CLASS;
  158.          idx: INTEGER;
  159.          ca: like code_attribute;
  160.       do
  161.          ca := code_attribute;
  162.          rc := type_character_ref.run_class;
  163.          rc.jvm_basic_new;
  164.          ca.opcode_dup_x1;
  165.          ca.opcode_swap;
  166.          idx := rc.jvm_constant_pool_index;
  167.          idx := constant_pool.idx_fieldref4(idx,as_item,fz_41);
  168.          ca.opcode_putfield(idx,-2);
  169.       end;
  170.  
  171.    jvm_expanded_from_reference(other: TYPE): INTEGER is
  172.       local
  173.          rc: RUN_CLASS;
  174.          idx: INTEGER;
  175.          ca: like code_attribute;
  176.       do
  177.          ca := code_attribute;
  178.          rc := type_character_ref.run_class;
  179.          rc.opcode_checkcast;
  180.          idx := rc.jvm_constant_pool_index;
  181.          idx := constant_pool.idx_fieldref4(idx,as_item,fz_41);
  182.          ca.opcode_getfield(idx,0);
  183.          Result := 1;
  184.       end;
  185.  
  186.    jvm_convert_to(destination: TYPE): INTEGER is
  187.       do
  188.          if destination.is_reference then
  189.             jvm_to_reference;
  190.          end;
  191.          Result := 1;
  192.       end;
  193.  
  194.    to_reference is
  195.       do
  196.          cpp.to_reference(Current,type_character_ref);
  197.       end;
  198.  
  199.    to_expanded is
  200.       do
  201.          cpp.to_expanded(type_character_ref,Current);
  202.       end;
  203.  
  204. feature {NONE}
  205.  
  206.    check_type is
  207.       -- Do some checking for type CHARACTER to be runnable.
  208.       local
  209.          bc: BASE_CLASS;
  210.          rc: RUN_CLASS;
  211.       once
  212.          bc := base_class;
  213.          if nb_errors = 0 then
  214.             rc := run_class;
  215.          end;
  216.          if nb_errors = 0 then
  217.             if not bc.is_expanded then
  218.                error(start_position,"CHARACTER must be expanded.");
  219.             end;
  220.          end;
  221.       end;
  222.  
  223. invariant
  224.  
  225.    written_mark = as_character
  226.  
  227. end -- TYPE_CHARACTER
  228.  
  229.  
  230.