home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / short.e < prev    next >
Text File  |  1999-06-05  |  8KB  |  275 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 SHORT
  17.    --
  18.    -- The `short' command.
  19.    --
  20.  
  21. inherit COMMAND_FLAGS;
  22.  
  23. creation make
  24.  
  25. feature {NONE}
  26.  
  27.    command_name: STRING is "short";
  28.  
  29.    root_class: STRING;
  30.  
  31.    format: STRING;
  32.  
  33.    parents: FIXED_ARRAY[BASE_CLASS] is
  34.          -- From `root_class' up to ANY included.
  35.       once
  36.          !!Result.with_capacity(4);
  37.       end;
  38.  
  39.    run_class: RUN_CLASS;
  40.  
  41.    rf_list: FIXED_ARRAY[RUN_FEATURE] is
  42.       once
  43.          !!Result.with_capacity(256);
  44.       end;
  45.  
  46.    sort: BOOLEAN;
  47.  
  48.    short: BOOLEAN;
  49.  
  50.    make is
  51.       local
  52.          bc: BASE_CLASS;
  53.          i: INTEGER;
  54.          ccl: CREATION_CLAUSE_LIST;
  55.       do
  56.          small_eiffel.set_short_flag;
  57.          if argument_count = 0 then
  58.             fatal_bad_usage
  59.          else
  60.             automat;
  61.             if root_class = Void then
  62.                fatal_bad_usage
  63.             end;
  64.             bc := small_eiffel.load_class(root_class);
  65.             parents.add_last(bc);
  66.             if not short then
  67.                bc.up_to_any_in(parents);
  68.             end;
  69.             if format = Void then
  70.                format := "plain";
  71.             end;
  72.             -- Prepare data :
  73.             compute_run_class(bc);
  74.             run_class.runnable_class_invariant;
  75.             -- Print the class interface :
  76.             short_print.start(format,bc,run_class);
  77.             ccl := bc.creation_clause_list;
  78.             if ccl = Void or else not ccl.short then
  79.                short_print.hook("hook102");
  80.             end;
  81.             compute_rf_list;
  82.             if sort then
  83.                short_print.hook_or("hook200","feature(s)%N");
  84.                sort_rf_list;
  85.                from
  86.                   i := 0;
  87.                until
  88.                   i > rf_list.upper
  89.                loop
  90.                   short_print.a_run_feature(rf_list.item(i));
  91.                   i := i + 1;
  92.                end;
  93.                short_print.hook("hook201");
  94.             end;
  95.             short_print.finish;
  96.          end;
  97.       end;
  98.  
  99.    automat is
  100.       local
  101.          arg: INTEGER;
  102.          a: STRING;
  103.       do
  104.          from
  105.             arg := 1;
  106.          until
  107.             arg > argument_count
  108.          loop
  109.             a := argument(arg);
  110.             if ("-sort").is_equal(a) then
  111.                sort := true;
  112.             elseif ("-short").is_equal(a) then
  113.                short := true;
  114.             elseif is_flag_case_insensitive(a) then
  115.             elseif is_flag_no_style_warning(a) then
  116.             elseif is_flag_no_warning(a) then
  117.             elseif is_flag_version(a) then
  118.             elseif a.item(1) = '-' then
  119.                a.remove_first(1);
  120.                format := a;
  121.             else
  122.                if a.has_suffix(eiffel_suffix) then
  123.                   a.remove_suffix(eiffel_suffix);
  124.                end;
  125.                if as_bit_n_ref.same_as(a) then
  126.                   a := as_bit_n;
  127.                end;
  128.                root_class := a;
  129.             end;
  130.             arg := arg + 1;
  131.          end;
  132.       end;
  133.  
  134.    compute_run_class(bc: BASE_CLASS) is
  135.       local
  136.          fgl: FORMAL_GENERIC_LIST;
  137.          bcn: STRING;
  138.          sp: POSITION;
  139.          t, ct: TYPE;
  140.          gl: ARRAY[TYPE];
  141.          i: INTEGER;
  142.          fga: FORMAL_GENERIC_ARG;
  143.       do
  144.          bcn := bc.name.to_string;
  145.          sp := bc.name.start_position;
  146.          fgl := bc.formal_generic_list;
  147.          if as_any = bcn then
  148.             !TYPE_ANY!ct.make(sp);
  149.          elseif as_native_array = bcn then
  150.             !TYPE_CHARACTER!t.make(sp);
  151.             !TYPE_NATIVE_ARRAY!ct.make(sp,t);
  152.          elseif as_array = bcn then
  153.             !TYPE_ANY!t.make(sp);
  154.             !TYPE_ARRAY!ct.make(sp,t);
  155.          elseif as_integer = bcn then
  156.             !TYPE_INTEGER!ct.make(sp);
  157.          elseif as_real = bcn then
  158.             !TYPE_REAL!ct.make(sp);
  159.          elseif as_double = bcn then
  160.             !TYPE_DOUBLE!ct.make(sp);
  161.          elseif as_character = bcn then
  162.             !TYPE_CHARACTER!ct.make(sp);
  163.          elseif as_boolean = bcn then
  164.             !TYPE_BOOLEAN!ct.make(sp);
  165.          elseif as_pointer = bcn then
  166.             !TYPE_POINTER!ct.make(sp);
  167.          elseif as_string = bcn then
  168.             !TYPE_STRING!ct.make(sp);
  169.          elseif fgl /= Void then
  170.             from
  171.                i := 1;
  172.                !!gl.with_capacity(fgl.count,1);
  173.             until
  174.                i > fgl.count
  175.             loop
  176.                fga := fgl.item(i);
  177.                if fga.constraint = Void then
  178.                   !TYPE_ANY!t.make(sp);
  179.                else
  180.                   t := fga.constraint;
  181.                end;
  182.                gl.add_last(t);
  183.                i := i + 1;
  184.             end;
  185.             !TYPE_GENERIC!ct.make(bc.name,gl);
  186.          else
  187.             !TYPE_CLASS!ct.make(bc.name);
  188.          end;
  189.          run_class := ct.run_class;
  190.       end;
  191.  
  192.    compute_rf_list is
  193.       local
  194.          i: INTEGER;
  195.          bc: BASE_CLASS;
  196.          rc: RUN_CLASS;
  197.          fcl: FEATURE_CLAUSE_LIST;
  198.       do
  199.          from
  200.             i := parents.upper;
  201.             rc := run_class;
  202.          until
  203.             i < 0
  204.          loop
  205.             bc := parents.item(i);
  206.             fcl := bc.feature_clause_list;
  207.             if fcl /= Void then
  208.                fcl.for_short(bc.name,sort,rf_list,rc);
  209.             end;
  210.             i := i - 1;
  211.          end;
  212.       end;
  213.  
  214.    sort_rf_list is
  215.       local
  216.          min, max, buble: INTEGER;
  217.          moved: BOOLEAN;
  218.       do
  219.          from
  220.             max := rf_list.upper;
  221.             min := 0;
  222.             moved := true;
  223.          until
  224.             not moved
  225.          loop
  226.             moved := false;
  227.             if max - min > 0 then
  228.                from
  229.                   buble := min + 1;
  230.                until
  231.                   buble > max
  232.                loop
  233.                   if gt(buble - 1,buble) then
  234.                      rf_list.swap(buble - 1,buble);
  235.                      moved := true;
  236.                   end;
  237.                   buble := buble + 1;
  238.                end;
  239.                max := max - 1;
  240.             end;
  241.             if moved and then max - min > 0 then
  242.                from
  243.                   moved := false;
  244.                   buble := max - 1;
  245.                until
  246.                   buble < min
  247.                loop
  248.                   if gt(buble,buble + 1) then
  249.                      rf_list.swap(buble,buble + 1);
  250.                      moved := true;
  251.                   end;
  252.                   buble := buble - 1;
  253.                end;
  254.                min := min + 1;
  255.             end;
  256.          end;
  257.       end;
  258.  
  259.    gt(i,j: INTEGER): BOOLEAN is
  260.       local
  261.          n1, n2: STRING;
  262.       do
  263.          n1 := rf_list.item(i).name.to_key;
  264.          n2 := rf_list.item(j).name.to_key;
  265.          Result :=  n1 > n2;
  266.       end;
  267.  
  268.    fatal_bad_usage is
  269.       do
  270.          system_tools.bad_use_exit(command_name);
  271.       end;
  272.  
  273. end -- SHORT -- The command.
  274.  
  275.