home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / short_print.e < prev    next >
Text File  |  1999-06-05  |  10KB  |  391 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_PRINT
  17.    --
  18.    -- Driver for the `short' command.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. creation make
  24.  
  25. feature {NONE}
  26.  
  27.    format_directory: STRING;
  28.          -- For the output style.
  29.  
  30.    base_class: BASE_CLASS;
  31.          -- The one printed.
  32.  
  33.    run_class: RUN_CLASS;
  34.          -- The one printed.
  35.  
  36. feature {NONE}
  37.  
  38.    make is
  39.       do
  40.       end;
  41.  
  42. feature {SHORT}
  43.  
  44.    start(format: STRING; bc: BASE_CLASS; rc: RUN_CLASS) is
  45.       local
  46.          hc2: COMMENT;
  47.          fgl: FORMAL_GENERIC_LIST;
  48.       do
  49.          base_class := bc;
  50.          run_class := rc;
  51.          format_directory := system_tools.format_directory(format);
  52.          -- Start output :
  53.          hook("hook000");
  54.          hook_and("hook002",bc.name.to_string);
  55.          if bc.is_expanded then
  56.             hook_or("hook010","expanded class interface ");
  57.          elseif bc.is_deferred then
  58.             hook_or("hook011","deferred class interface ");
  59.          else
  60.             hook_or("hook012","class interface ");
  61.          end;
  62.          hook("hook013");
  63.          a_class_name(bc.name);
  64.          fgl := bc.formal_generic_list;
  65.          if fgl /= Void then
  66.             fgl.short;
  67.          end;
  68.          hook_or("hook014","%N");
  69.          hc2 := bc.heading_comment2;
  70.          if hc2 /= Void then
  71.             hook("hook015");
  72.             hc2.short("hook016","   -- ","hook017","%N");
  73.             hook("hook018");
  74.          else
  75.             hook("hook019");
  76.          end;
  77.       end;
  78.  
  79.    finish is
  80.       local
  81.          fgl: FORMAL_GENERIC_LIST;
  82.          ci: CLASS_INVARIANT;
  83.       do
  84.          ci := run_class.class_invariant;
  85.          if ci = Void then
  86.             hook("hook800");
  87.          else
  88.             ci.short(base_class);
  89.          end;
  90.          hook("hook900");
  91.          if base_class.is_expanded then
  92.             hook_or("hook901","end of expanded ");
  93.          elseif base_class.is_deferred then
  94.             hook_or("hook902","end of deferred ");
  95.          else
  96.             hook_or("hook903","end of ");
  97.          end;
  98.          hook("hook904");
  99.          a_class_name(base_class.name);
  100.          fgl := base_class.formal_generic_list;
  101.          if fgl /= Void then
  102.             fgl.short;
  103.          end;
  104.          hook_or("hook905","%N");
  105.          hook("hook999");
  106.       end;
  107.  
  108. feature
  109.  
  110.    hook_or(h, str: STRING) is
  111.       do
  112.          if hook_exists(h) then
  113.             from
  114.                tmp_hook.read_character;
  115.             until
  116.                tmp_hook.end_of_input
  117.             loop
  118.                std_output.put_character(tmp_hook.last_character);
  119.                tmp_hook.read_character;
  120.             end;
  121.             tmp_hook.disconnect;
  122.          else
  123.             std_output.put_string(str);
  124.          end;
  125.       end;
  126.  
  127.    hook_and_lower(h, name: STRING) is
  128.          -- When hook `h' exists, the corresponding `name' is printed 
  129.          -- one more time (using lower case letters) just before the 
  130.          -- contents of `h' hook file.
  131.       do
  132.          if hook_exists(h) then
  133.             tmp_string.copy(name);
  134.             tmp_string.to_lower;
  135.             std_output.put_string(tmp_string);
  136.             from
  137.                tmp_hook.read_character;
  138.             until
  139.                tmp_hook.end_of_input
  140.             loop
  141.                std_output.put_character(tmp_hook.last_character);
  142.                tmp_hook.read_character;
  143.             end;
  144.             tmp_hook.disconnect;
  145.          end;
  146.       end;
  147.  
  148.    hook_and(h, name: STRING) is
  149.          -- When hook `h' exists, the corresponding `name' is printed 
  150.          -- just before the contents of `h' hook file.
  151.       do
  152.          if hook_exists(h) then
  153.             std_output.put_string(name);
  154.             from
  155.                tmp_hook.read_character;
  156.             until
  157.                tmp_hook.end_of_input
  158.             loop
  159.                std_output.put_character(tmp_hook.last_character);
  160.                tmp_hook.read_character;
  161.             end;
  162.             tmp_hook.disconnect;
  163.          end;
  164.       end;
  165.  
  166.    hook(h: STRING) is
  167.       do
  168.          if hook_exists(h) then
  169.             from
  170.                tmp_hook.read_character;
  171.             until
  172.                tmp_hook.end_of_input
  173.             loop
  174.                std_output.put_character(tmp_hook.last_character);
  175.                tmp_hook.read_character;
  176.             end;
  177.             tmp_hook.disconnect;
  178.          end;
  179.       end;
  180.  
  181.    a_class_name(name: CLASS_NAME) is
  182.       local
  183.          i: INTEGER;
  184.          c: CHARACTER;
  185.          str: STRING;
  186.       do
  187.          hook("Bcn");
  188.          hook_and_lower("Mcn",name.to_string);
  189.          from
  190.             str := name.to_string;
  191.             i := 1;
  192.          until
  193.             i > str.count
  194.          loop
  195.             c := str.item(i);
  196.             if c = '_' then
  197.                hook_or("Ucn","_");
  198.             else
  199.                std_output.put_character(c);
  200.             end;
  201.             i := i + 1;
  202.          end;
  203.          hook("Acn");
  204.       end;
  205.  
  206.    a_feature(fn: FEATURE_NAME) is
  207.          -- Where `fn' is really the final name to print.
  208.       local
  209.          rf: RUN_FEATURE;
  210.       do
  211.          rf := run_class.get_feature(fn);
  212.          a_run_feature(rf);
  213.       end;
  214.  
  215.    a_run_feature(rf: RUN_FEATURE) is
  216.       local
  217.          args: FORMAL_ARG_LIST;
  218.          rt: TYPE;
  219.          hc: COMMENT;
  220.          rr: RUN_REQUIRE;
  221.          ea: E_ENSURE;
  222.       do
  223.          hook_or("hook300","   ");
  224.          rf.name.short;
  225.          args := rf.arguments;
  226.          if args = Void then
  227.             hook_or("hook301","");
  228.          else
  229.             args.short;
  230.          end;
  231.          rt := rf.result_type;
  232.          if rt = Void then
  233.             hook_or("hook307","%N");
  234.          else
  235.             hook_or("hook308",": ");
  236.             rt.short;
  237.             hook_or("hook309","%N");
  238.          end;
  239.          hc := rf.base_feature.header_comment;
  240.          if hc /= Void then
  241.             hook("hook310");
  242.             hc.short("hook311","      -- ","hook312","%N");
  243.             hook("hook313");
  244.          else
  245.             hook("hook314");
  246.          end;
  247.          rr := rf.require_assertion;
  248.          if rr = Void then
  249.             hook("hook400");
  250.          else
  251.             rr.short;
  252.          end;
  253.          ea := rf.ensure_assertion;
  254.          if ea = Void then
  255.             hook_or("hook500","");
  256.          else
  257.             ea.short;
  258.          end;
  259.          hook_or("hook599","");
  260.       end;
  261.  
  262.    a_integer(value: INTEGER) is
  263.       local
  264.          s: STRING;
  265.          c: CHARACTER;
  266.          i: INTEGER;
  267.       do
  268.          s := "";
  269.          s.clear;
  270.          value.append_in(s);
  271.          from
  272.             i := 1;
  273.          until
  274.             i > s.count
  275.          loop
  276.             c := s.item(i);
  277.             std_output.put_character(c);
  278.             i := i + 1;
  279.          end;
  280.       end;
  281.  
  282.    a_character(c: CHARACTER) is
  283.       do
  284.          std_output.put_character(c);
  285.       end;
  286.  
  287.    a_dot is
  288.       do
  289.          hook_or("dot",fz_dot);
  290.       end;
  291.  
  292. feature {CALL_PREFIX}
  293.  
  294.    a_prefix_name(pn: PREFIX_NAME) is
  295.          -- Used in an expression.
  296.       local
  297.          i: INTEGER;
  298.          c: CHARACTER;
  299.          str: STRING;
  300.       do
  301.          from
  302.             str := pn.to_string;
  303.             i := 1;
  304.          until
  305.             i > str.count
  306.          loop
  307.             c := str.item(i);
  308.             if c = '_' then
  309.                hook_or("Usfn","_");
  310.             else
  311.                std_output.put_character(c);
  312.             end;
  313.             i := i + 1;
  314.          end;
  315.          a_character(' ');
  316.       end;
  317.  
  318. feature {CALL_INFIX,INFIX_NAME}
  319.  
  320.    a_infix_name(h1,r1,h2,r2: STRING; in: INFIX_NAME) is
  321.       local
  322.          i: INTEGER;
  323.          str: STRING;
  324.       do
  325.          hook_or(h1,r1);
  326.          str := in.to_string;
  327.          if as_backslash_backslash = str then
  328.             hook_or("rem",as_backslash_backslash);
  329.          else
  330.             from
  331.                i := 1;
  332.             until
  333.                i > str.count
  334.             loop
  335.                std_output.put_character(str.item(i));
  336.                i := i + 1;
  337.             end;
  338.          end;
  339.          hook_or(h2,r2);
  340.       end;
  341.  
  342. feature {BASE_TYPE_CONSTANT}
  343.  
  344.    a_base_type_constant(str: STRING) is
  345.       local
  346.          i: INTEGER;
  347.          c: CHARACTER;
  348.       do
  349.          from
  350.             i := 1;
  351.          until
  352.             i > str.count
  353.          loop
  354.             c := str.item(i);
  355.             if c = '.' then
  356.                hook_or("dot",".");
  357.             else
  358.                std_output.put_character(c);
  359.             end;
  360.             i := i + 1;
  361.          end;
  362.       end;
  363.  
  364. feature {NONE}
  365.  
  366.    hook_exists(h: STRING): BOOLEAN is
  367.       do
  368.          tmp_hook_path.copy(format_directory);
  369.          tmp_hook_path.append(h);
  370.          tmp_hook.connect_to(tmp_hook_path);
  371.          Result := tmp_hook.is_connected;
  372.       end;
  373.  
  374.    tmp_hook: STD_FILE_READ is
  375.       once
  376.          !!Result.make;
  377.       end;
  378.  
  379.    tmp_hook_path: STRING is
  380.       once
  381.          !!Result.make(80);
  382.       end;
  383.  
  384.    tmp_string: STRING is
  385.       once
  386.          !!Result.make(16);
  387.       end;
  388.  
  389. end -- SHORT_PRINT
  390.  
  391.