home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / switch_collection.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  5.4 KB  |  210 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. expanded class SWITCH_COLLECTION
  17.    -- 
  18.    -- Unique Global Object in charge of the `switch_collection'.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. feature {NONE}
  24.  
  25.    dictionary: DICTIONARY[DICTIONARY[RUN_FEATURE,STRING],STRING] is
  26.      -- First STRING key is the name of a run type corresponding 
  27.      -- to a RUN_CLASS.
  28.          -- Embedded dictionary gives all switching points.
  29.       once
  30.      !!Result.make;
  31.       end;
  32.  
  33. feature {CALL_PROC_CALL}
  34.  
  35.    update(target: EXPRESSION; run_feature: RUN_FEATURE) is
  36.       -- Update the switch_collection such that `run_feature' can be 
  37.       -- applied with `target'.
  38.       require
  39.      target /= Void;
  40.      run_feature /= Void
  41.       local
  42.      current_type: TYPE;
  43.      running: ARRAY[RUN_CLASS];
  44.       do
  45.      if target.is_current then
  46.      elseif target.is_manifest_string then
  47.      else
  48.         current_type := run_feature.current_type;
  49.         if current_type.is_reference then
  50.            running := current_type.run_class.running;
  51.            if running /= Void and then running.count > 1 then
  52.           update_with(run_feature);
  53.            end;
  54.         end;
  55.      end;
  56.       end;
  57.  
  58. feature {C_PRETTY_PRINTER}
  59.  
  60.    c_define is
  61.      -- Produce C code for switches.
  62.       local
  63.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  64.      count1, count2, total: INTEGER;
  65.      switch: SWITCH;
  66.       do
  67.      if not dictionary.empty then
  68.         cpp.swap_on_c;
  69.         cpp.split_c_now;
  70.         from  
  71.            count1 := 1;
  72.         until
  73.            count1 > dictionary.count
  74.         loop
  75.            dictionary2 := dictionary.item(count1);
  76.            from  
  77.           count2 := 1;
  78.            until
  79.           count2 > dictionary2.count
  80.            loop
  81.           switch.c_define(dictionary2.item(count2));
  82.           total := total + 1;
  83.           cpp.incr_elt_c_count(20);
  84.           count2 := count2 + 1;
  85.            end;
  86.            count1 := count1 + 1;
  87.         end;
  88.         cpp.split_c_now;
  89.      end;
  90.      echo.print_count("Defined Switche",total);
  91.       end;
  92.  
  93. feature {SMALL_EIFFEL}
  94.  
  95.    falling_down is
  96.       local
  97.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  98.      count1, count2: INTEGER;
  99.       do
  100.      if not dictionary.empty then
  101.         from  
  102.            count1 := 1;
  103.         until
  104.            count1 > dictionary.count
  105.         loop
  106.            dictionary2 := dictionary.item(count1);
  107.            from  
  108.           count2 := 1;
  109.            until
  110.           count2 > dictionary2.count
  111.            loop
  112.           dictionary2.item(count2).fall_down;
  113.           count2 := count2 + 1;
  114.            end;
  115.            count1 := count1 + 1;
  116.         end;
  117.      end;
  118.       end;
  119.  
  120. feature {CECIL_POOL}
  121.  
  122.    update_with(run_feature: RUN_FEATURE) is
  123.       require
  124.      run_feature /= Void
  125.       local
  126.      current_type: TYPE;
  127.      key1, key2: STRING;
  128.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  129.      running: ARRAY[RUN_CLASS];
  130.       do
  131.      current_type := run_feature.current_type;
  132.      running := current_type.run_class.running;
  133.      if running /= Void and then running.count > 1 then
  134.         key1 := current_type.run_time_mark;
  135.         key2 := run_feature.name.to_key;
  136.         if dictionary.has(key1) then
  137.            dictionary2 := dictionary.at(key1);
  138.            if not dictionary2.has(key2) then
  139.           dictionary2.put(run_feature,key2);
  140.            end;
  141.         else
  142.            !!dictionary2.make;
  143.            dictionary2.put(run_feature,key2);
  144.            dictionary.put(dictionary2,key1);
  145.         end;
  146.         check
  147.            dictionary.at(key1).at(key2) = run_feature
  148.         end;
  149.      end;
  150.       end;
  151.  
  152. feature {C_PRETTY_PRINTER}
  153.  
  154.    remove(run_feature: RUN_FEATURE) is
  155.       require
  156.      run_feature /= Void
  157.       local
  158.      current_type: TYPE;
  159.      key1, key2: STRING;
  160.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  161.       do
  162.      current_type := run_feature.current_type;
  163.      key1 := current_type.run_time_mark;
  164.      if dictionary.has(key1) then
  165.         dictionary2 := dictionary.at(key1);
  166.         key2 := run_feature.name.to_key;
  167.         dictionary2.remove(key2);
  168.         check
  169.            not dictionary.at(key1).has(key2)
  170.         end;
  171.      end;
  172.       end;
  173.  
  174. feature {JVM}
  175.  
  176.    jvm_define is
  177.      -- Produce Java byte code for switches.
  178.       local
  179.      dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  180.      count1, count2, total: INTEGER;
  181.      switch: SWITCH;
  182.      up_rf: RUN_FEATURE;
  183.       do
  184.      if not dictionary.empty then
  185.         from  
  186.            count1 := 1;
  187.         until
  188.            count1 > dictionary.count
  189.         loop
  190.            dictionary2 := dictionary.item(count1);
  191.            from  
  192.           count2 := 1;
  193.            until
  194.           count2 > dictionary2.count
  195.            loop
  196.           up_rf := dictionary2.item(count2);
  197.           jvm.set_current_frame(up_rf);
  198.           switch.jvm_define(up_rf);
  199.           total := total + 1;
  200.           count2 := count2 + 1;
  201.            end;
  202.            count1 := count1 + 1;
  203.         end;
  204.      end;
  205.      echo.print_count("Defined Switche",total);
  206.       end;
  207.    
  208. end -- SWITCH_COLLECTION
  209.  
  210.