home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / ifthenlist.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  257 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 IFTHENLIST
  17.  
  18. inherit IF_GLOBALS;
  19.  
  20. creation make
  21.  
  22. feature {NONE}
  23.  
  24.    list: ARRAY[IFTHEN];
  25.  
  26.    current_type: TYPE;
  27.  
  28. feature
  29.  
  30.    make(l: like list) is
  31.       require
  32.          not l.empty;
  33.          l.lower = 1;
  34.       do
  35.          list := l;
  36.       ensure
  37.          list = l;
  38.       end;
  39.  
  40.    pretty_print is
  41.       local
  42.          i: INTEGER;
  43.       do
  44.          from
  45.             i := 1;
  46.          until
  47.             i > list.upper
  48.          loop
  49.             list.item(i).pretty_print;
  50.             i := i + 1;
  51.             if i <= list.upper then
  52.                fmt.indent;
  53.                fmt.keyword("elseif");
  54.             end;
  55.          end;
  56.       end;
  57.  
  58.    afd_check is
  59.       local
  60.          i: INTEGER;
  61.       do
  62.          from
  63.             i := list.upper;
  64.          until
  65.             i = 0
  66.          loop
  67.             list.item(i).afd_check;
  68.             i := i - 1;
  69.          end;
  70.       end;
  71.  
  72.    collect_c_tmp is
  73.       local
  74.          i: INTEGER;
  75.       do
  76.          from
  77.             i := list.upper;
  78.          until
  79.             i = 0
  80.          loop
  81.             list.item(i).collect_c_tmp;
  82.             i := i - 1;
  83.          end;
  84.       end;
  85.  
  86.    compile_to_c: INTEGER is
  87.          -- state 0: no printing done.
  88.          -- state 1: already print `non_static'.
  89.          -- state 2: end of list or previous `static_true'.
  90.       local
  91.          state, previous, i: INTEGER;
  92.       do
  93.          from
  94.             i := 1;
  95.          until
  96.             state = 2
  97.          loop
  98.             inspect
  99.                state
  100.             when 0 then
  101.                if i > list.upper then
  102.                   state := 2;
  103.                   Result := previous;
  104.                else
  105.                   previous := list.item(i).compile_to_c(false);
  106.                   inspect
  107.                      previous
  108.                   when non_static then
  109.                      state := 1;
  110.                   when static_false then
  111.                   when static_true then
  112.                      Result := static_true;
  113.                      state := 2;
  114.                   end;
  115.                end;
  116.             else -- 1
  117.                if i > list.upper then
  118.                   state := 2;
  119.                   inspect
  120.                      previous
  121.                   when static_true then
  122.                      Result := static_true;
  123.                   else
  124.                      Result := non_static;
  125.                   end;
  126.                else
  127.                   previous := list.item(i).compile_to_c(true);
  128.                   inspect
  129.                      previous
  130.                   when non_static then
  131.                   when static_false then
  132.                   when static_true then
  133.                      state := 2;
  134.                      Result := static_true;
  135.                   end;
  136.                end;
  137.             end;
  138.             i := i + 1;
  139.          end;
  140.       ensure
  141.          (<<static_true,static_false,non_static>>).fast_has(Result)
  142.       end;
  143.  
  144.    compile_to_jvm: INTEGER is
  145.       local
  146.          i: INTEGER;
  147.       do
  148.          from
  149.             Result := list.item(1).compile_to_jvm;
  150.             i := 2;
  151.          until
  152.             Result = static_true or else i > list.upper
  153.          loop
  154.             inspect
  155.                list.item(i).compile_to_jvm
  156.             when static_true then
  157.                Result := static_true
  158.             when static_false then
  159.                if Result = static_false then
  160.                else
  161.                   Result := non_static;
  162.                end;
  163.             else -- non_static :
  164.                Result := non_static;
  165.             end;
  166.             i := i + 1;
  167.          end;
  168.       ensure
  169.          (<<static_true,static_false,non_static>>).fast_has(Result)
  170.       end;
  171.  
  172.    use_current: BOOLEAN is
  173.       local
  174.          i: INTEGER;
  175.       do
  176.          from
  177.             i := 1;
  178.          until
  179.             i > list.upper or else Result
  180.          loop
  181.             Result := list.item(i).use_current;
  182.             i := i + 1;
  183.          end;
  184.       end;
  185.  
  186.    count: INTEGER is
  187.       do
  188.          Result := list.upper;
  189.       end;
  190.  
  191.    to_runnable(ct: TYPE): like Current is
  192.       require
  193.          ct /= Void
  194.       local
  195.          i: INTEGER;
  196.       do
  197.          if current_type /= Void then
  198.             !!Result.make(list.twin);
  199.             Result := Result.to_runnable(ct);
  200.          else
  201.             current_type := ct;
  202.             from
  203.                i := 1;
  204.             until
  205.                i > list.upper or else nb_errors > 0
  206.             loop
  207.                list.put(list.item(i).to_runnable(ct),i);
  208.                debug
  209.                   if nb_errors = 0 then
  210.                      check
  211.                         list.item(i) /= Void;
  212.                      end;
  213.                   end;
  214.                end;
  215.                i := i + 1;
  216.             end;
  217.             Result := Current;
  218.          end;
  219.       end;
  220.  
  221. feature {IFTHENELSE}
  222.  
  223.    add_last(it: IFTHEN) is
  224.       require
  225.          it /= Void
  226.       do
  227.          list.add_last(it);
  228.       ensure
  229.          count = old count + 1
  230.       end;
  231.  
  232. feature {IFTHENELSE}
  233.  
  234.    compile_to_jvm_resolve_branch is
  235.       local
  236.          i, static: INTEGER;
  237.       do
  238.          from
  239.             i := 1;
  240.             static := non_static;
  241.          until
  242.             static = static_true or else i > list.upper
  243.          loop
  244.             static := list.item(i).compile_to_jvm_resolve_branch;
  245.             i := i + 1;
  246.          end;
  247.       end;
  248.  
  249. invariant
  250.  
  251.    list.lower = 1;
  252.  
  253.    count >= 1;
  254.  
  255. end -- IFTHENLIST
  256.  
  257.