home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / command_flags.e < prev    next >
Text File  |  1999-06-18  |  10KB  |  318 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. deferred class COMMAND_FLAGS
  17.    --
  18.    -- Some useful tools to handle command flags (inherited by compile,
  19.    -- compile_to_c, compile_to_jvm, finder, clean, short, pretty, etc.).
  20.    --
  21.  
  22. inherit GLOBALS;
  23.  
  24. feature {NONE}
  25.  
  26.    Command_compile_to_c:    STRING is "compile_to_c";
  27.    Command_clean:           STRING is "clean";
  28.  
  29.    command_name: STRING is
  30.       deferred
  31.       end;
  32.  
  33.    search_for_verbose_flag is
  34.          -- To become verbose as soon as possible.
  35.       local
  36.          i: INTEGER;
  37.       do
  38.          from
  39.             i := argument_count;
  40.          until
  41.             i = 0
  42.          loop
  43.             if is_flag_verbose(argument(i)) then
  44.                echo.set_verbose;
  45.                i := 0;
  46.             else
  47.                i := i - 1;
  48.             end;
  49.          end;
  50.       end;
  51.  
  52.    search_for_cc_flag(argc: INTEGER) is
  53.          -- To know about the C compiler as soon as possible.
  54.       local
  55.          i: INTEGER;
  56.          c_compiler: STRING;
  57.       do
  58.          from
  59.             i := 1;
  60.          until
  61.             i > argc
  62.          loop
  63.             if Flag_cc.is_equal(argument(i)) then
  64.                if i < argc then
  65.                   i := i + 1;
  66.                   c_compiler := argument(i);
  67.                   i := argc + 1;
  68.                end;
  69.             end;
  70.             i := i + 1;
  71.          end;
  72.          system_tools.set_c_compiler(c_compiler);
  73.       end;
  74.  
  75.    search_for_size_flag(argc: INTEGER) is
  76.          -- Maximum number of units per chunk. Two values can be given:
  77.          -- first one is compared after a feature has just been output
  78.          -- and might split a class across several chunks of C code;
  79.          -- second one is compared only after a whole class has just
  80.          -- been output. First value should be greater than the second
  81.          -- one. A unit equals approximately one source line.
  82.       local
  83.          i: INTEGER;
  84.          limit: INTEGER;
  85.          smaller_limit: INTEGER;
  86.          values: ARRAY[STRING];
  87.       do
  88.          limit := 5000;
  89.          smaller_limit := 4000;
  90.          from
  91.             i := 1;
  92.          until
  93.             i > argc
  94.         loop
  95.            if Flag_size.is_equal(argument(i)) then
  96.                if i < argc then
  97.                   i := i + 1;
  98.                   -- split value string on occurences of character ","
  99.                   argument(i).replace_all(',', ' ');
  100.                   values := argument(i).split;
  101.                   if values /= Void then
  102.                      limit := values.item(1).to_integer;
  103.                      smaller_limit := 0;
  104.                      if values.count > 1 then
  105.                         smaller_limit := values.item(2).to_integer;
  106.                      end
  107.                      if smaller_limit = 0 or else smaller_limit > limit then
  108.                         smaller_limit := (limit * 4) // 5;
  109.                      end
  110.                   else
  111.                      echo.w_put_string(command_name);
  112.                      echo.w_put_string(": illegal value after -size flag.%N");
  113.                      die_with_code(exit_failure_code);
  114.                   end
  115.                   i := argc + 1;
  116.                end;
  117.             end;
  118.             i := i + 1;
  119.          end;
  120.          cpp.set_c_count_max(limit);
  121.          cpp.set_c_size(smaller_limit);
  122.         end;
  123.  
  124.    is_flag_case_insensitive(flag: STRING): BOOLEAN is
  125.       do
  126.          if ("-case_insensitive").is_equal(flag) then
  127.             Result := true;
  128.             eiffel_parser.set_case_insensitive;
  129.          end;
  130.       end;
  131.  
  132.    is_flag_no_style_warning(flag: STRING): BOOLEAN is
  133.       do
  134.          if ("-no_style_warning").is_equal(flag) then
  135.             Result := true;
  136.             eiffel_parser.set_no_style_warning;
  137.          end;
  138.       end;
  139.  
  140.    is_flag_no_warning(flag: STRING): BOOLEAN is
  141.       do
  142.          if ("-no_warning").is_equal(flag) then
  143.             Result := true;
  144.             eh.set_no_warning;
  145.          end;
  146.       end;
  147.  
  148.    is_flag_trace(flag: STRING): BOOLEAN is
  149.       do
  150.          if ("-trace").is_equal(flag) then
  151.             Result := true;
  152.             run_control.set_trace;
  153.          end;
  154.       end;
  155.  
  156.    is_flag_verbose(flag: STRING): BOOLEAN is
  157.       do
  158.          if ("-verbose").is_equal(flag) then
  159.             Result := true;
  160.          end;
  161.       end;
  162.  
  163.    is_flag_version(flag: STRING): BOOLEAN is
  164.       do
  165.          if ("-version").is_equal(flag) then
  166.             Result := true;
  167.             std_output.put_string("Version of command %"");
  168.             std_output.put_string(command_name);
  169.             std_output.put_string("%" is:%N");
  170.             std_output.put_string(small_eiffel.copyright);
  171.             if argument_count = 1 then
  172.                die_with_code(exit_success_code);
  173.             end;
  174.          end;
  175.       end;
  176.  
  177.    is_flag_boost(flag: STRING): BOOLEAN is
  178.       do
  179.          if ("-boost").is_equal(flag) then
  180.             Result := true;
  181.             run_control.set_boost;
  182.             check_for_level(flag);
  183.          end;
  184.       end;
  185.  
  186.    is_flag_no_check(flag: STRING): BOOLEAN is
  187.       do
  188.          if ("-no_check").is_equal(flag) then
  189.             Result := true;
  190.             run_control.set_no_check;
  191.             check_for_level(flag);
  192.          end;
  193.       end;
  194.  
  195.    is_flag_require_check(flag: STRING): BOOLEAN is
  196.       do
  197.          if ("-require_check").is_equal(flag) then
  198.             Result := true;
  199.             run_control.set_require_check;
  200.             check_for_level(flag);
  201.          end;
  202.       end;
  203.  
  204.    is_flag_ensure_check(flag: STRING): BOOLEAN is
  205.       do
  206.          if ("-ensure_check").is_equal(flag) then
  207.             Result := true;
  208.             run_control.set_ensure_check;
  209.             check_for_level(flag);
  210.          end;
  211.       end;
  212.  
  213.    is_flag_invariant_check(flag: STRING): BOOLEAN is
  214.       do
  215.          if ("-invariant_check").is_equal(flag) then
  216.             Result := true;
  217.             run_control.set_invariant_check;
  218.             check_for_level(flag);
  219.          end;
  220.       end;
  221.  
  222.    is_flag_loop_check(flag: STRING): BOOLEAN is
  223.       do
  224.          if ("-loop_check").is_equal(flag) then
  225.             Result := true;
  226.             run_control.set_loop_check;
  227.             check_for_level(flag);
  228.          end;
  229.       end;
  230.  
  231.    is_flag_all_check(flag: STRING): BOOLEAN is
  232.       do
  233.          if ("-all_check").is_equal(flag) then
  234.             Result := true;
  235.             run_control.set_all_check;
  236.             check_for_level(flag);
  237.          end;
  238.       end;
  239.  
  240.    is_flag_debug_check(flag: STRING): BOOLEAN is
  241.       do
  242.          if ("-debug_check").is_equal(flag) then
  243.             Result := true;
  244.             run_control.set_debug_check;
  245.          end;
  246.       end;
  247.  
  248.    is_flag_cecil(flag: STRING; argi, argc: INTEGER): BOOLEAN is
  249.       do
  250.          if ("-cecil").is_equal(flag) then
  251.             Result := true;
  252.             if argi < argc then
  253.                run_control.set_cecil_path(argument(argi + 1));
  254.             else
  255.                echo.w_put_string(command_name);
  256.                echo.w_put_string(" : missing file name after -cecil flag.%N");
  257.                die_with_code(exit_failure_code);
  258.             end;
  259.          end;
  260.       end;
  261.  
  262.    is_flag_o(flag: STRING; argi, argc: INTEGER;
  263.              code_printer: CODE_PRINTER): BOOLEAN is
  264.       do
  265.          if ("-o").is_equal(flag) then
  266.             Result := true;
  267.             if argi < argc then
  268.                code_printer.set_output_name(argument(argi + 1));
  269.             else
  270.                echo.w_put_string(command_name);
  271.                echo.w_put_string(" : missing output name after -o flag.%N");
  272.                die_with_code(exit_failure_code);
  273.             end;
  274.          end;
  275.       end;
  276.  
  277.    check_for_root_class is
  278.       do
  279.          if run_control.root_class = Void then
  280.             echo.w_put_string(command_name);
  281.             echo.w_put_string(" : error : No <Root-Class> in command line.%N");
  282.             die_with_code(exit_failure_code);
  283.          end;
  284.       end;
  285.  
  286.    level_flag: STRING;
  287.  
  288.    check_for_level(new_level_flag: STRING) is
  289.       do
  290.          if level_flag /= Void then
  291.             if not level_flag.is_equal(new_level_flag) then
  292.                echo.w_put_string(command_name);
  293.                echo.w_put_string(": level is already set to ");
  294.                echo.w_put_string(level_flag);
  295.                echo.w_put_string(". Bad flag ");
  296.                echo.w_put_string(new_level_flag);
  297.                echo.w_put_string(fz_dot);
  298.                die_with_code(exit_failure_code);
  299.             end;
  300.          else
  301.             level_flag := new_level_flag;
  302.          end;
  303.       end;
  304.  
  305.    unknown_flag_exit(flag: STRING) is
  306.       do
  307.          echo.w_put_string(command_name);
  308.          echo.w_put_string(" : unknown flag %"");
  309.          echo.w_put_string(flag);
  310.          echo.w_put_string("%".%N");
  311.          die_with_code(exit_failure_code);
  312.       end;
  313.  
  314.    Flag_cc: STRING is "-cc";
  315.    Flag_size: STRING is "-size";
  316.  
  317. end -- COMMAND_FLAGS
  318.