home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / run_control.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  264 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 RUN_CONTROL
  17.    --
  18.    -- Singleton object in charge of Eiffel run time options..
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. creation make
  24.  
  25. feature {NONE} -- Numbering of levels is that of E.T.L. (pp 133) :
  26.  
  27.    level: INTEGER;
  28.          -- Actual level of checking;
  29.  
  30.    level_no: INTEGER is -5;
  31.          -- No assertion checking of any kind.
  32.  
  33.    level_require: INTEGER is -4;
  34.          -- Evaluate the preconditions.
  35.  
  36.    level_ensure: INTEGER is -3;
  37.          -- Also evaluate postconditions.
  38.  
  39.    level_invariant: INTEGER is -2;
  40.          -- Also evaluate the class invariant on entry to and return from.
  41.  
  42.    level_loop: INTEGER is -1;
  43.          -- Also evaluate the loop variant and the loop invariant.
  44.  
  45.    level_check_all: INTEGER is 0;
  46.          -- Also evaluate the check instruction.
  47.          -- The default value.
  48.  
  49.    level_check_debug: INTEGER is 1;
  50.          -- Also evaluate the debug instruction.
  51.  
  52.    level_boost: INTEGER is -6;
  53.          -- BOOST :-). Very very speed level.
  54.          -- Do not check for Void target.
  55.          -- Do not check system level validity.
  56.  
  57.    make is
  58.       do
  59.       end;
  60.  
  61. feature  -- Consultation :
  62.  
  63.    trace: BOOLEAN;
  64.          -- Flag for trace mode.
  65.  
  66.    boost: BOOLEAN is
  67.       do
  68.          Result := level = level_boost;
  69.       end;
  70.  
  71.    no_check: BOOLEAN is
  72.       do
  73.          Result := level >= level_no;
  74.       end;
  75.  
  76.    require_check: BOOLEAN is
  77.       do
  78.          Result := level >= level_require;
  79.       end;
  80.  
  81.    ensure_check: BOOLEAN is
  82.       do
  83.          Result := level >= level_ensure;
  84.       end;
  85.  
  86.    invariant_check: BOOLEAN is
  87.       do
  88.          Result := level >= level_invariant;
  89.       end;
  90.  
  91.    loop_check: BOOLEAN is
  92.       do
  93.          Result := level >= level_loop;
  94.       end;
  95.  
  96.    all_check: BOOLEAN is
  97.       do
  98.          Result := level >= level_check_all;
  99.       end;
  100.  
  101.    debug_check: BOOLEAN is
  102.       do
  103.          Result := level = level_check_debug;
  104.       end;
  105.  
  106.    root_class: STRING;
  107.          -- Name of the root class using only upper case letter.
  108.  
  109.    root_procedure: STRING is
  110.          -- Name of the root procedure.
  111.       do
  112.          Result := root_procedure_memory;
  113.          if Result = Void then
  114.             Result := as_make;
  115.          end;
  116.       end;
  117.  
  118. feature
  119.  
  120.    compute_root_class(command_line_name: STRING) is
  121.          -- Create and compute the `root_class' name using the `command_line_name'
  122.          -- as a model.
  123.          -- Trailing Eiffel file suffix is removed if any.
  124.          -- Leading path is also removed if any.
  125.          -- Finally, the feature `to_upper' is applied.
  126.       require
  127.          not command_line_name.empty
  128.       local
  129.          i: INTEGER;
  130.          c: CHARACTER;
  131.       do
  132.          root_class := command_line_name.twin;
  133.          if root_class.has_suffix(eiffel_suffix) then
  134.             root_class.remove_last(2);
  135.          end;
  136.          from
  137.             i := root_class.count;
  138.          until
  139.             i = 0
  140.          loop
  141.             c := root_class.item(i);
  142.             if c.is_letter then
  143.                i := i - 1;
  144.             elseif c = '_' then
  145.                i := i - 1;
  146.             elseif c.is_digit then
  147.                i := i - 1;
  148.             else
  149.                root_class.remove_first(i);
  150.                i := 0;
  151.             end;
  152.          end;
  153.          root_class.to_upper;
  154.       ensure
  155.          root_class /= command_line_name;
  156.          not root_class.has_suffix(eiffel_suffix)
  157.       end;
  158.  
  159. feature
  160.  
  161.    generating_type_used: BOOLEAN;
  162.          -- When GENERAL `generating_type' is used.
  163.  
  164.    generator_used: BOOLEAN;
  165.          -- When GENERAL `generator' is used.
  166.  
  167. feature -- Setting :
  168.  
  169.    set_boost is
  170.       do
  171.          level := level_boost;
  172.       end;
  173.  
  174.    set_no_check is
  175.       do
  176.          level := level_no;
  177.       end;
  178.  
  179.    set_require_check is
  180.       do
  181.          level := level_require;
  182.       end;
  183.  
  184.    set_ensure_check is
  185.       do
  186.          level := level_ensure;
  187.       end;
  188.  
  189.    set_invariant_check is
  190.       do
  191.          level := level_invariant;
  192.       end;
  193.  
  194.    set_loop_check is
  195.       do
  196.          level := level_loop;
  197.       end;
  198.  
  199.    set_all_check is
  200.       do
  201.          level := level_check_all;
  202.       end;
  203.  
  204.    set_debug_check is
  205.       do
  206.          level := level_check_debug;
  207.       end;
  208.  
  209.    set_trace is
  210.       do
  211.          trace := true;
  212.       end;
  213.  
  214. feature
  215.  
  216.    set_generating_type_used is
  217.       do
  218.          generating_type_used := true;
  219.       end;
  220.  
  221.    set_generator_used is
  222.       do
  223.          generator_used := true;
  224.       end;
  225.  
  226. feature -- Other settings :
  227.  
  228.    set_cecil_path(path: STRING) is
  229.       do
  230.          cecil_path := path;
  231.       ensure
  232.          cecil_path = path
  233.       end;
  234.  
  235.    cecil_path: STRING;
  236.          -- Not Void when option -cecil used.
  237.  
  238.    set_root_procedure(rp: STRING) is
  239.       do
  240.          root_procedure_memory := rp;
  241.       ensure
  242.          root_procedure = rp
  243.       end;
  244.  
  245. feature {NONE}
  246.  
  247.    root_procedure_memory: STRING;
  248.  
  249.    singleton_memory: RUN_CONTROL is
  250.       once
  251.          Result := Current;
  252.       end;
  253.  
  254. invariant
  255.  
  256.    is_real_singleton: Current = singleton_memory;
  257.  
  258.    level_boost <= level ;
  259.  
  260.    level <= level_check_debug;
  261.  
  262. end -- RUN_CONTROL
  263.  
  264.