home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / short.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  6.2 KB  |  274 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. class SHORT -- The command.
  17.  
  18. inherit GLOBALS;
  19.  
  20. creation make
  21.    
  22. feature {NONE}
  23.  
  24.    root_class: STRING;
  25.  
  26.    format: STRING;
  27.  
  28.    parents: FIXED_ARRAY[BASE_CLASS] is
  29.      -- From `root_class' up to ANY included.
  30.       once
  31.      !!Result.with_capacity(4);
  32.       end;
  33.  
  34.    run_class: RUN_CLASS;
  35.  
  36.    rf_list: FIXED_ARRAY[RUN_FEATURE] is
  37.       once
  38.      !!Result.with_capacity(4);
  39.       end;
  40.  
  41.    sort: BOOLEAN;
  42.  
  43.    short: BOOLEAN;
  44.  
  45. feature 
  46.    
  47.    make is
  48.       local
  49.      bc: BASE_CLASS;
  50.      stop: BOOLEAN;
  51.      i: INTEGER;
  52.      ccl: CREATION_CLAUSE_LIST;
  53.       do
  54.      if argument_count = 0 then
  55.         std_error.put_string("Bad use of command `short'.%N");
  56.         print_help("short");
  57.         die_with_code(exit_failure_code);
  58.      else
  59.         automat;
  60.         small_eiffel.set_short_flag;
  61.         bc := small_eiffel.load_class(root_class);
  62.         parents.add_last(bc);
  63.         if not short then
  64.            bc.up_to_any_in(parents);
  65.         end;
  66.         if format = Void then
  67.            format := "plain";
  68.         end;
  69.         -- Prepare data :
  70.         compute_run_class(bc);
  71.         -- Print the class interface :
  72.         short_print.start(format,bc,run_class);
  73.         ccl := bc.creation_clause_list;
  74.         if ccl = Void or else not ccl.short then
  75.            short_print.hook("hook102");
  76.         end;
  77.         compute_rf_list;
  78.         if sort then
  79.            short_print.hook_or("hook200","feature(s)%N");
  80.            sort_rf_list;
  81.            from
  82.           i := 0;
  83.            until
  84.           i > rf_list.upper
  85.            loop
  86.           short_print.a_run_feature(rf_list.item(i));
  87.           i := i + 1;
  88.            end;
  89.            short_print.hook("hook201");
  90.         end;
  91.         short_print.finish;
  92.      end;
  93.       end;
  94.    
  95. feature {NONE}
  96.    
  97.    automat is
  98.       local
  99.      arg: INTEGER;
  100.      a: STRING;
  101.       do
  102.      from  
  103.         arg := 1;
  104.      until
  105.         arg > argument_count
  106.      loop
  107.         a := argument(arg);
  108.         if ("-sort").is_equal(a) then
  109.            sort := true;
  110.         elseif ("-short").is_equal(a) then
  111.            short := true;
  112.         elseif ("-case_insensitive").is_equal(a) then
  113.            eiffel_parser.set_case_insensitive;
  114.         elseif ("-no_warning").is_equal(a) then
  115.            eh.set_no_warning;
  116.         elseif a.item(1) = '-' then
  117.            a.remove_first(1);
  118.            format := a;
  119.         else
  120.            if a.has_suffix(eiffel_suffix) then
  121.           a.remove_suffix(eiffel_suffix);
  122.            end;
  123.            if us_bit_n_ref.same_as(a) then
  124.           a := us_bit_n;
  125.            end;
  126.            root_class := a;
  127.         end;
  128.         arg := arg + 1;
  129.      end;
  130.       end;
  131.  
  132. feature {NONE}
  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.base_class_name.to_string;
  145.      sp := bc.base_class_name.start_position;
  146.      fgl := bc.formal_generic_list;
  147.      if us_any = bcn then
  148.         !TYPE_ANY!ct.make(sp);
  149.      elseif us_native_array = bcn then
  150.         !TYPE_CHARACTER!t.make(sp);
  151.         !TYPE_NATIVE_ARRAY!ct.make(sp,t);
  152.      elseif us_array = bcn then
  153.         !TYPE_ANY!t.make(sp);
  154.         !TYPE_ARRAY!ct.make(sp,t);
  155.      elseif us_integer = bcn then
  156.         !TYPE_INTEGER!ct.make(sp);
  157.      elseif us_real = bcn then
  158.         !TYPE_REAL!ct.make(sp);
  159.      elseif us_double = bcn then
  160.         !TYPE_DOUBLE!ct.make(sp);
  161.      elseif us_character = bcn then
  162.         !TYPE_CHARACTER!ct.make(sp);
  163.      elseif us_boolean = bcn then
  164.         !TYPE_BOOLEAN!ct.make(sp);
  165.      elseif us_pointer = bcn then
  166.         !TYPE_POINTER!ct.make(sp);
  167.      elseif us_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.base_class_name,gl);
  186.      else
  187.         !TYPE_CLASS!ct.make(bc.base_class_name);
  188.      end;
  189.      run_class := ct.run_class;
  190.       end;
  191.  
  192. feature {NONE}
  193.  
  194.    compute_rf_list is
  195.       local
  196.      i: INTEGER;
  197.      bc: BASE_CLASS;
  198.      rc: RUN_CLASS;
  199.      fcl: FEATURE_CLAUSE_LIST;
  200.       do
  201.      from
  202.         i := parents.upper;
  203.         rc := run_class;
  204.      until
  205.         i < 0
  206.      loop
  207.         bc := parents.item(i);
  208.         fcl := bc.feature_clause_list;
  209.         if fcl /= Void then
  210.            fcl.for_short(bc.base_class_name,sort,rf_list,rc);
  211.         end;
  212.         i := i - 1;
  213.      end;
  214.       end;
  215.  
  216. feature {NONE}
  217.  
  218.    sort_rf_list is
  219.       local
  220.      min, max, buble: INTEGER;
  221.      moved: BOOLEAN;
  222.       do
  223.      from  
  224.         max := rf_list.upper;
  225.         min := 0;
  226.         moved := true;
  227.      until
  228.         not moved
  229.      loop
  230.         moved := false;
  231.         if max - min > 0 then
  232.            from  
  233.           buble := min + 1;
  234.            until
  235.           buble > max
  236.            loop
  237.           if gt(buble - 1,buble) then
  238.              rf_list.swap(buble - 1,buble);
  239.              moved := true;
  240.           end;
  241.           buble := buble + 1;
  242.            end;
  243.            max := max - 1;
  244.         end;
  245.         if moved and then max - min > 0 then
  246.            from  
  247.           moved := false;
  248.           buble := max - 1;
  249.            until
  250.           buble < min
  251.            loop
  252.           if gt(buble,buble + 1) then
  253.              rf_list.swap(buble,buble + 1);
  254.              moved := true;
  255.           end;
  256.           buble := buble - 1;
  257.            end;
  258.            min := min + 1;
  259.         end;
  260.      end;
  261.       end;
  262.  
  263.    gt(i,j: INTEGER): BOOLEAN is
  264.       local
  265.      n1, n2: STRING;
  266.       do
  267.      n1 := rf_list.item(i).name.to_key;
  268.      n2 := rf_list.item(j).name.to_key;
  269.      Result :=  n1 > n2;
  270.       end;
  271.    
  272. end -- SHORT -- The command.
  273.  
  274.