home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / switch_collection.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  205 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. 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.with_capacity(1024);
  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 {SMALL_EIFFEL}
  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.             from
  70.                count1 := 1;
  71.             until
  72.                count1 > dictionary.count
  73.             loop
  74.                dictionary2 := dictionary.item(count1);
  75.                from
  76.                   count2 := 1;
  77.                until
  78.                   count2 > dictionary2.count
  79.                loop
  80.                   switch.c_define(dictionary2.item(count2));
  81.                   total := total + 1;
  82.                   count2 := count2 + 1;
  83.                end;
  84.                count1 := count1 + 1;
  85.             end;
  86.          end;
  87.          echo.print_count("Defined Switche",total);
  88.       end;
  89.  
  90.    falling_down is
  91.       local
  92.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  93.          count1, count2: INTEGER;
  94.       do
  95.          if not dictionary.empty then
  96.             from
  97.                count1 := 1;
  98.             until
  99.                count1 > dictionary.count
  100.             loop
  101.                dictionary2 := dictionary.item(count1);
  102.                from
  103.                   count2 := 1;
  104.                until
  105.                   count2 > dictionary2.count
  106.                loop
  107.                   dictionary2.item(count2).fall_down;
  108.                   count2 := count2 + 1;
  109.                end;
  110.                count1 := count1 + 1;
  111.             end;
  112.          end;
  113.       end;
  114.  
  115. feature {CECIL_POOL,ADDRESS_OF_POOL}
  116.  
  117.    update_with(run_feature: RUN_FEATURE) is
  118.       require
  119.          run_feature /= Void
  120.       local
  121.          current_type: TYPE;
  122.          key1, key2: STRING;
  123.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  124.          running: ARRAY[RUN_CLASS];
  125.       do
  126.          current_type := run_feature.current_type;
  127.          running := current_type.run_class.running;
  128.          if running /= Void and then running.count > 1 then
  129.             key1 := current_type.run_time_mark;
  130.             key2 := run_feature.name.to_key;
  131.             if dictionary.has(key1) then
  132.                dictionary2 := dictionary.at(key1);
  133.                if not dictionary2.has(key2) then
  134.                   dictionary2.put(run_feature,key2);
  135.                end;
  136.             else
  137.                !!dictionary2.make;
  138.                dictionary2.put(run_feature,key2);
  139.                dictionary.put(dictionary2,key1);
  140.             end;
  141.             check
  142.                dictionary.at(key1).at(key2) = run_feature
  143.             end;
  144.          end;
  145.       end;
  146.  
  147. feature {C_PRETTY_PRINTER}
  148.  
  149.    remove(run_feature: RUN_FEATURE) is
  150.       require
  151.          run_feature /= Void
  152.       local
  153.          current_type: TYPE;
  154.          key1, key2: STRING;
  155.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  156.       do
  157.          current_type := run_feature.current_type;
  158.          key1 := current_type.run_time_mark;
  159.          if dictionary.has(key1) then
  160.             dictionary2 := dictionary.at(key1);
  161.             key2 := run_feature.name.to_key;
  162.             dictionary2.remove(key2);
  163.             check
  164.                not dictionary.at(key1).has(key2)
  165.             end;
  166.          end;
  167.       end;
  168.  
  169. feature {JVM}
  170.  
  171.    jvm_define is
  172.          -- Produce Java byte code for switches.
  173.       local
  174.          dictionary2: DICTIONARY[RUN_FEATURE,STRING];
  175.          count1, count2, total: INTEGER;
  176.          switch: SWITCH;
  177.          up_rf: RUN_FEATURE;
  178.       do
  179.          if not dictionary.empty then
  180.             from
  181.                count1 := 1;
  182.             until
  183.                count1 > dictionary.count
  184.             loop
  185.                dictionary2 := dictionary.item(count1);
  186.                from
  187.                   count2 := 1;
  188.                until
  189.                   count2 > dictionary2.count
  190.                loop
  191.                   up_rf := dictionary2.item(count2);
  192.                   jvm.set_current_frame(up_rf);
  193.                   switch.jvm_define(up_rf);
  194.                   total := total + 1;
  195.                   count2 := count2 + 1;
  196.                end;
  197.                count1 := count1 + 1;
  198.             end;
  199.          end;
  200.          echo.print_count("Defined Switche",total);
  201.       end;
  202.  
  203. end -- SWITCH_COLLECTION
  204.  
  205.