home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / declaration_list.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  6.2 KB  |  309 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 DECLARATION_LIST
  17. --
  18. -- For a formal arguments list (FORMAL_ARG_LIST) or for a local 
  19. -- variable list (LOCAL_VAR_LIST).
  20. --
  21. -- Exemple :
  22. --
  23. --   foo, bar : ZOO; x : INTEGER
  24. --
  25.    
  26. inherit 
  27.    GLOBALS
  28.       redefine fill_tagged_out_memory 
  29.       end;
  30.    
  31. feature 
  32.    
  33.    start_position: POSITION;
  34.      -- Of keyword "local" or of "(".
  35.  
  36. feature {DECLARATION_LIST}
  37.    
  38.    list: ARRAY[DECLARATION];
  39.      -- Really written list including declaration groups.
  40.  
  41.    flat_list: ARRAY[like name];
  42.      -- The same contents as `list' but flat.
  43.    
  44.    current_type: TYPE;
  45.      -- Not Void when runnable in.
  46.  
  47. feature {NONE} -- Parsing creation procedure :
  48.    
  49.    make(sp: like start_position; l: like list) is
  50.       require
  51.      sp /= Void;
  52.      l.lower = 1;
  53.      not l.empty;
  54.       local
  55.      il, actual_count: INTEGER;
  56.       do
  57.      start_position := sp;
  58.      list := l;
  59.      from  
  60.         il := 1;
  61.      until
  62.         il > list.upper
  63.      loop
  64.         actual_count := actual_count + list.item(il).count;
  65.         il := il + 1;
  66.      end;
  67.      from  
  68.         !!flat_list.make(1,actual_count);
  69.         il := 1;
  70.      until
  71.         il > list.upper
  72.      loop
  73.         list.item(il).append_in(Current);
  74.         il := il + 1;
  75.      end;
  76.       ensure
  77.      start_position = sp;
  78.      list = l;
  79.      flat_list /= Void
  80.       end;
  81.  
  82. feature {NONE} -- To runnable creation procedure :
  83.  
  84.    runnable_from_current(dl: like Current; ct: TYPE) is
  85.       local
  86.      i: INTEGER;
  87.      n1, n2: like name;
  88.       do
  89.      start_position := dl.start_position;
  90.      list := dl.list;
  91.      current_type := ct;
  92.      from
  93.         flat_list := dl.flat_list.twin;
  94.         i := flat_list.upper;
  95.      until
  96.         i = 0
  97.      loop
  98.         n1 := flat_list.item(i);
  99.         n2 := n1.to_runnable(ct);
  100.         if n2 = Void then
  101.            error(n1.start_position,em1);
  102.         end;
  103.         flat_list.put(n2,i);
  104.         i := i - 1;
  105.      end;
  106.       end;
  107.  
  108. feature 
  109.  
  110.    fill_tagged_out_memory is
  111.       local
  112.      p: POSITION;
  113.      ct: TYPE;
  114.      rtm: STRING;
  115.       do
  116.      p := start_position;
  117.      if p /= Void then
  118.         p.fill_tagged_out_memory;
  119.      end;
  120.      ct := current_type;
  121.      if ct /= Void then
  122.         rtm := ct.run_time_mark;
  123.         if rtm /= Void then
  124.            tagged_out_memory.append(" ct=");
  125.            tagged_out_memory.append(rtm);
  126.         end;
  127.      end;
  128.       end;
  129.    
  130.    is_written_runnable: BOOLEAN is
  131.       local
  132.      i: INTEGER;
  133.      t: TYPE;
  134.       do
  135.      from
  136.         Result := true;
  137.         i := count;
  138.      until
  139.         not Result or else i = 0
  140.      loop
  141.         t := type(i);
  142.         if t.is_run_type and then t.run_type = t then
  143.         else
  144.            Result := false;
  145.         end;
  146.         i := i - 1;
  147.      end;
  148.       end;
  149.    
  150.    pretty_print is
  151.       require
  152.      fmt.indent_level >= 2;
  153.       deferred
  154.       ensure
  155.      fmt.indent_level = old fmt.indent_level;
  156.       end;
  157.    
  158.    count: INTEGER is
  159.       do 
  160.      Result := flat_list.upper;
  161.       end;
  162.    
  163.    rank_of(n: STRING): INTEGER is
  164.      -- Result is greater than 0 when `n' is in the list.
  165.       require
  166.      unique_string.item(n) = n
  167.       do
  168.      from
  169.         Result := count
  170.      until
  171.         Result = 0 or else n = name(Result).to_string
  172.      loop
  173.         Result := Result - 1;
  174.      end;
  175.       ensure
  176.      0 <= Result;
  177.      Result <= count;
  178.       end;
  179.      
  180.    name(i: INTEGER): LOCAL_ARGUMENT is
  181.       require
  182.      1 <= i;
  183.      i <= count
  184.       deferred
  185.       ensure
  186.      Result /= Void
  187.       end;
  188.    
  189.    type(i: INTEGER): TYPE is
  190.       require
  191.      1 <= i;
  192.      i <= count;
  193.       do
  194.      Result := name(i).result_type;
  195.       ensure
  196.      Result /= Void
  197.       end;
  198.       
  199.    frozen to_runnable(ct: TYPE): like Current is
  200.       require
  201.      ct.run_type = ct
  202.       local
  203.      i: INTEGER;
  204.      n1, n2: like name;
  205.       do
  206.      if current_type = Void then
  207.         current_type := ct;
  208.         Result := Current;
  209.         from  
  210.            i := flat_list.upper;
  211.         until
  212.            i = 0 or else nb_errors > 0
  213.         loop
  214.            n1 := flat_list.item(i);
  215.            n2 := n1.to_runnable(ct);
  216.            if n2 = Void then
  217.           error(n1.start_position,em1);
  218.            elseif n1 /= n2 then
  219.           flat_list.put(n2,i);
  220.            end;
  221.            n2.name_clash;
  222.            i := i - 1;
  223.         end;
  224.      else
  225.         !!Result.runnable_from_current(Current,ct);
  226.      end;
  227.       ensure
  228.      Result.count = count
  229.       end;
  230.  
  231. feature {DECLARATION}
  232.  
  233.    add_last(n: like name) is
  234.       local
  235.      i: INTEGER;
  236.      n2: like name;
  237.       do
  238.      from
  239.         i := 1;
  240.      until
  241.         flat_list.item(i) = Void
  242.      loop
  243.         n2 := flat_list.item(i);
  244.         if n2.to_string = n.to_string then
  245.            eh.add_position(n.start_position);
  246.            eh.add_position(n2.start_position);
  247.            fatal_error("Same name appears twice.");
  248.         end;
  249.         i := i + 1;
  250.      end;
  251.      flat_list.put(n,i);
  252.      n.set_rank(i);
  253.       end;
  254.  
  255. feature {RUN_FEATURE}
  256.  
  257.    frozen jvm_stack_space: INTEGER is
  258.      -- Number of needed words in the JVM stack.
  259.       local
  260.      i: INTEGER;
  261.       do
  262.      from
  263.         i := count;
  264.      until
  265.         i = 0
  266.      loop
  267.         Result := Result + type(i).run_type.jvm_stack_space;
  268.         i := i - 1;
  269.      end;
  270.       end;
  271.    
  272. feature {RUN_FEATURE}
  273.  
  274.    frozen jvm_offset_of(la: LOCAL_ARGUMENT): INTEGER is
  275.       local
  276.      i, rank: INTEGER;
  277.       do
  278.      from
  279.         rank := la.rank;
  280.         i := 1;
  281.      variant
  282.         count - i
  283.      until
  284.         i = rank
  285.      loop
  286.         Result := Result + type(i).run_type.jvm_stack_space;
  287.         i := i + 1;
  288.      end;
  289.       end;
  290.  
  291. feature {NONE}
  292.  
  293.    em1: STRING is "Bad declaration.";
  294.    
  295. invariant
  296.    
  297.    start_position /= Void;
  298.    
  299.    count > 0;
  300.    
  301.    flat_list.lower = 1;
  302.    
  303.    count = flat_list.count;
  304.    
  305.    list.count <= count;
  306.    
  307. end -- DECLARATION_LIST
  308.  
  309.