home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / position.e < prev    next >
Text File  |  1999-06-05  |  6KB  |  234 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 POSITION
  17. --
  18. -- A position in an Eiffel base class text.
  19. --
  20.  
  21. inherit GLOBALS redefine is_equal end;
  22.  
  23. creation make
  24.  
  25. creation {CLASS_NAME} with
  26.  
  27. feature
  28.  
  29.    base_class_name: CLASS_NAME;
  30.          -- The corresponding Eiffel text of the position.
  31.  
  32. feature {NONE}
  33.  
  34.    mem_line_column: INTEGER;
  35.          -- Line and Column on a single INTEGER value (column must
  36.          -- less than 999).
  37.  
  38. feature
  39.  
  40.    line: INTEGER is
  41.       do
  42.          Result := mem_line_column // 1000;
  43.       end;
  44.  
  45.    column: INTEGER is
  46.       do
  47.          Result := mem_line_column \\ 1000;
  48.       end;
  49.  
  50. feature {NONE}
  51.  
  52.    with(li, co: INTEGER; bcn: like base_class_name) is
  53.       require
  54.          li >= 1;
  55.          co >= 1;
  56.          bcn /= Void;
  57.       do
  58.          mem_line_column := li * 1000 + co;
  59.          base_class_name := bcn;
  60.       ensure
  61.          line = li;
  62.          column = co;
  63.          base_class_name = bcn;
  64.       end;
  65.  
  66.    make(li, co: INTEGER) is
  67.       require
  68.          li >= 1;
  69.          co >= 1;
  70.          eiffel_parser.is_running
  71.       do
  72.          mem_line_column := li * 1000 + co;
  73.          base_class_name := eiffel_parser.current_class_name;
  74.       ensure
  75.          line = li;
  76.          column = co;
  77.          base_class_name /= Void
  78.       end;
  79.  
  80. feature
  81.  
  82.    is_equal(other: like Current): BOOLEAN is
  83.       do
  84.          Result :=
  85.             ((line = other.line) and then
  86.              (column = other.column) and then
  87.              (base_class_name /= Void) and then
  88.              (other.base_class_name /= Void) and then
  89.              (base_class_name.to_string = other.base_class_name.to_string));
  90.       end;
  91.  
  92.    before(other: like Current): BOOLEAN is
  93.          -- Is current position strictly before `other' (in
  94.          -- the same base class).
  95.       require
  96.          base_class_name = other.base_class_name
  97.       do
  98.          if line < other.line then
  99.             Result := true;
  100.          elseif line = other.line then
  101.             Result := column < other.column;
  102.          end;
  103.       end;
  104.  
  105.    base_class: BASE_CLASS is
  106.       do
  107.          if eiffel_parser.is_running then
  108.             if base_class_name.to_string.empty then
  109.                fatal_error("Internal Error #1 in POSITION.");
  110.             elseif small_eiffel.is_used(base_class_name.to_string) then
  111.                Result := base_class_name.base_class;
  112.             else
  113.                fatal_error("Internal Error #2 in POSITION.");
  114.             end;
  115.          else
  116.             Result := base_class_name.base_class;
  117.          end;
  118.       end;
  119.  
  120.    path: STRING is
  121.       local
  122.          bcn: STRING;
  123.          bc: BASE_CLASS;
  124.       do
  125.          bcn := base_class_name.to_string;
  126.          if bcn /= Void then
  127.             if small_eiffel.is_used(bcn) then
  128.                bc := base_class_name.base_class;
  129.             elseif eiffel_parser.is_running then
  130.                if eiffel_parser.current_class_name.to_string = bcn then
  131.                   bc := eiffel_parser.current_class;
  132.                end;
  133.             else
  134.                bc := base_class_name.base_class;
  135.             end;
  136.             if bc /= Void then
  137.                Result := bc.path;
  138.             end;
  139.          end;
  140.       end;
  141.  
  142.    show is
  143.       local
  144.          c: INTEGER;
  145.          nb: INTEGER;
  146.          n, str, the_line: STRING;
  147.       do
  148.          n := base_class_name.to_string;
  149.          echo.w_put_string("Line ");
  150.          echo.w_put_integer(line);
  151.          echo.w_put_string(" column ");
  152.          echo.w_put_integer(column);
  153.          echo.w_put_string(" in ");
  154.          echo.w_put_string(n);
  155.          str := path;
  156.          if str /= Void then
  157.             echo.w_put_string(" (");
  158.             echo.w_put_string(str);
  159.             echo.w_put_character(')');
  160.          end;
  161.          echo.w_put_string(" :%N");
  162.          the_line := get_line;
  163.          if the_line /= Void then
  164.             c := column;
  165.             echo.w_put_string(the_line);
  166.             echo.w_put_character('%N');
  167.             from
  168.                nb := 1;
  169.             until
  170.                nb = c
  171.             loop
  172.                if the_line.item(nb) = '%T' then
  173.                   echo.w_put_character('%T');
  174.                else
  175.                   echo.w_put_character(' ');
  176.                end;
  177.                nb := nb + 1;
  178.             end;
  179.             echo.w_put_string("^%N");
  180.          else
  181.             echo.w_put_string("SmallEiffel cannot load base class : ");
  182.             echo.w_put_string(n);
  183.             echo.w_put_string("%N");
  184.          end;
  185.       end;
  186.  
  187.    append_in(str: STRING) is
  188.       require
  189.          str /= Void
  190.       do
  191.          str.append("Line ");
  192.          line.append_in(str);
  193.          str.append(" column ");
  194.          column.append_in(str);
  195.          str.append(" in %"");
  196.          str.append(path);
  197.          str.append(fz_03);
  198.       end;
  199.  
  200. feature {EIFFEL_PARSER}
  201.  
  202.    set_line_column(li, co: INTEGER) is
  203.       do
  204.          mem_line_column := li * 1000 + co;
  205.       ensure
  206.          line = li;
  207.          column = co
  208.       end;
  209.  
  210. feature {NONE}
  211.  
  212.    get_line: STRING is
  213.       local
  214.          p: like path;
  215.          i: INTEGER;
  216.       do
  217.          p := path;
  218.          if p /= Void then
  219.             tmp_file_read.connect_to(p);
  220.             from
  221.             until
  222.                i = line
  223.             loop
  224.                tmp_file_read.read_line;
  225.                i := i + 1;
  226.             end;
  227.             Result := tmp_file_read.last_string;
  228.             tmp_file_read.disconnect;
  229.          end;
  230.       end;
  231.  
  232. end -- POSITION
  233.  
  234.