home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / globals.e < prev    next >
Text File  |  1999-06-05  |  13KB  |  535 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 GLOBALS
  17.    --
  18.    -- Global Tools for the SmallEiffel system.
  19.    --
  20.  
  21. inherit ALIASED_STRING_LIST; FROZEN_STRING_LIST;
  22.  
  23. feature
  24.  
  25. -----------------------------------------------------------------------------
  26. -- Following shared objects are singletons :
  27.  
  28.    frozen small_eiffel: SMALL_EIFFEL is
  29.       once
  30.          !!Result.make;
  31.       end;
  32.  
  33.    frozen system_tools: SYSTEM_TOOLS is
  34.       once
  35.          !!Result.make;
  36.       end;
  37.  
  38.    frozen eiffel_parser : EIFFEL_PARSER is
  39.       once
  40.          !!Result.make;
  41.       end;
  42.  
  43.    frozen string_aliaser: STRING_ALIASER is
  44.       once
  45.          !!Result.make;
  46.       end;
  47.  
  48.    frozen id_provider: ID_PROVIDER is
  49.       once
  50.          !!Result.make;
  51.       end;
  52.  
  53.    frozen manifest_string_pool: MANIFEST_STRING_POOL is
  54.       once
  55.          !!Result;
  56.       end;
  57.  
  58.    frozen manifest_array_pool: MANIFEST_ARRAY_POOL is
  59.       once
  60.          !!Result;
  61.       end;
  62.  
  63.    frozen once_routine_pool: ONCE_ROUTINE_POOL is
  64.       once
  65.          !!Result;
  66.       end;
  67.  
  68.    frozen cecil_pool: CECIL_POOL is
  69.       once
  70.          !!Result;
  71.       end;
  72.  
  73.    frozen parser_buffer: PARSER_BUFFER is
  74.       once
  75.          !!Result.make;
  76.       end;
  77.  
  78.    frozen address_of_pool: ADDRESS_OF_POOL is
  79.       once
  80.          !!Result;
  81.       end;
  82.  
  83.    frozen fmt: FMT is
  84.       once
  85.          !!Result.make;
  86.       end;
  87.  
  88.    frozen short_print: SHORT_PRINT is
  89.       once
  90.          !!Result.make;
  91.       end;
  92.  
  93.    frozen eh: ERROR_HANDLER is
  94.       once
  95.          !!Result.make
  96.       end;
  97.  
  98.    frozen echo: ECHO is
  99.       once
  100.          !!Result.make;
  101.       end;
  102.  
  103.    frozen run_control: RUN_CONTROL is
  104.       once
  105.          !!Result.make;
  106.       end;
  107.  
  108.    frozen switch_collection: SWITCH_COLLECTION is
  109.       once
  110.       end;
  111.  
  112.    frozen assertion_collector: ASSERTION_COLLECTOR is
  113.       once
  114.          !!Result.make;
  115.       end;
  116.  
  117.    frozen cpp: C_PRETTY_PRINTER is
  118.       once
  119.          !!Result.make;
  120.       end;
  121.  
  122.    frozen gc_handler: GC_HANDLER is
  123.       once
  124.          !!Result.make;
  125.       end;
  126.  
  127.    frozen exceptions_handler: EXCEPTIONS_HANDLER is
  128.       once
  129.          !!Result.make;
  130.       end;
  131.  
  132.    frozen jvm: JVM is
  133.       once
  134.          !!Result.make;
  135.       end;
  136.  
  137.    frozen constant_pool: CONSTANT_POOL is
  138.       once
  139.          !!Result;
  140.       end;
  141.  
  142.    frozen field_info: FIELD_INFO is
  143.       once
  144.          !!Result;
  145.       end;
  146.  
  147.    frozen code_attribute: CODE_ATTRIBUTE is
  148.       once
  149.          !!Result;
  150.       end;
  151.  
  152.    frozen method_info: METHOD_INFO is
  153.       once
  154.          !!Result;
  155.       end;
  156.  
  157. -----------------------------------------------------------------------------
  158. -- Error messages handling :
  159.  
  160.    nb_errors: INTEGER is
  161.       do
  162.          Result := eh.error_counter;
  163.       ensure
  164.          Result >= 0
  165.       end;
  166.  
  167.    nb_warnings: INTEGER is
  168.       do
  169.          Result := eh.warning_counter;
  170.       ensure
  171.          Result >= 0
  172.       end;
  173.  
  174.    warning(p: POSITION; msg: STRING) is
  175.          -- Warning `msg' at position `p'.
  176.       require
  177.          not msg.empty
  178.       do
  179.          eh.add_position(p);
  180.          eh.append(msg);
  181.          eh.print_as_warning;
  182.       ensure
  183.          nb_warnings = old nb_warnings + 1
  184.       end;
  185.  
  186.    error(p: POSITION; msg: STRING) is
  187.          -- When error `msg' occurs at position `p'.
  188.       require
  189.          not msg.empty
  190.       do
  191.          eh.add_position(p);
  192.          eh.append(msg);
  193.          eh.print_as_error;
  194.       ensure
  195.          nb_errors = old nb_errors + 1
  196.       end;
  197.  
  198.    fatal_error(msg: STRING) is
  199.          -- Should not append but it is better to know :-)
  200.       require
  201.          not msg.empty
  202.       do
  203.          eh.append(msg);
  204.          eh.print_as_fatal_error;
  205.       end;
  206.  
  207. -----------------------------------------------------------------------------
  208. -- Common globals buffers :
  209.  
  210.    tmp_path: STRING is ".......................................................%
  211.                        %.......................................................";
  212.  
  213.    tmp_file_read: STD_FILE_READ is
  214.       once
  215.          !!Result.make;
  216.       end;
  217.  
  218. -----------------------------------------------------------------------------
  219. -- Globals implicits expressions :
  220.  
  221.    class_with(str: STRING): BASE_CLASS is
  222.       require
  223.          not str.empty;
  224.       do
  225.          Result := small_eiffel.get_class(str);
  226.       end;
  227.  
  228.    class_any: BASE_CLASS is
  229.       once
  230.          Result := class_with(as_any);
  231.       end;
  232.  
  233.    class_general: BASE_CLASS is
  234.       once
  235.          Result := class_with(as_general);
  236.       end;
  237.  
  238. -----------------------------------------------------------------------------
  239. -- Globals implicits types :
  240.  
  241.    type_boolean_ref: TYPE_CLASS is
  242.       local
  243.          boolean_ref: CLASS_NAME;
  244.       once
  245.          !!boolean_ref.make(as_boolean_ref,Void);
  246.          !!Result.make(boolean_ref);
  247.       end;
  248.  
  249.    type_character_ref: TYPE_CLASS is
  250.       local
  251.          character_ref: CLASS_NAME;
  252.       once
  253.          !!character_ref.make(as_character_ref,Void);
  254.          !!Result.make(character_ref);
  255.       end;
  256.  
  257.    type_integer_ref: TYPE_CLASS is
  258.       local
  259.          integer_ref: CLASS_NAME;
  260.       once
  261.          !!integer_ref.make(as_integer_ref,Void);
  262.          !!Result.make(integer_ref);
  263.       end;
  264.  
  265.    type_real_ref: TYPE_CLASS is
  266.       local
  267.          real_ref: CLASS_NAME;
  268.       once
  269.          !!real_ref.make(as_real_ref,Void);
  270.          !!Result.make(real_ref);
  271.       end;
  272.  
  273.    type_double_ref: TYPE_CLASS is
  274.       local
  275.          double_ref: CLASS_NAME;
  276.       once
  277.          !!double_ref.make(as_double_ref,Void);
  278.          !!Result.make(double_ref);
  279.       end;
  280.  
  281.    type_pointer_ref: TYPE_CLASS is
  282.       local
  283.          pointer_ref: CLASS_NAME;
  284.       once
  285.          !!pointer_ref.make(as_pointer_ref,Void);
  286.          !!Result.make(pointer_ref);
  287.       end;
  288.  
  289.    type_boolean: TYPE_BOOLEAN is
  290.       once
  291.          !!Result.make(Void);
  292.       end;
  293.  
  294.    type_double: TYPE_DOUBLE is
  295.       once
  296.          !!Result.make(Void);
  297.       end;
  298.  
  299.    type_string: TYPE_STRING is
  300.       once
  301.          !!Result.make(Void);
  302.       end;
  303.  
  304.    type_any: TYPE_ANY is
  305.       once
  306.          !!Result.make(Void);
  307.       end;
  308.  
  309.    type_pointer: TYPE_POINTER is
  310.       once
  311.          !!Result.make(Void);
  312.       end;
  313.  
  314. -----------------------------------------------------------------------------
  315. -- Globals procedures/functions :
  316.  
  317.    sort_running(run: ARRAY[RUN_CLASS]) is
  318.          -- Sort `run' to put small `id' first.
  319.       require
  320.          run.lower = 1;
  321.          run.upper >= 2;
  322.       local
  323.          min, max, buble: INTEGER;
  324.          moved: BOOLEAN;
  325.       do
  326.          from
  327.             max := run.upper;
  328.             min := 1;
  329.             moved := true;
  330.          until
  331.             not moved
  332.          loop
  333.             moved := false;
  334.             if max - min > 0 then
  335.                from
  336.                   buble := min + 1;
  337.                until
  338.                   buble > max
  339.                loop
  340.                   if run.item(buble - 1).id > run.item(buble).id then
  341.                      run.swap(buble - 1,buble);
  342.                      moved := true;
  343.                   end;
  344.                   buble := buble + 1;
  345.                end;
  346.                max := max - 1;
  347.             end;
  348.             if moved and then max - min > 0 then
  349.                from
  350.                   moved := false;
  351.                   buble := max - 1;
  352.                until
  353.                   buble < min
  354.                loop
  355.                   if run.item(buble).id > run.item(buble + 1).id then
  356.                      run.swap(buble,buble + 1);
  357.                      moved := true;
  358.                   end;
  359.                   buble := buble - 1;
  360.                end;
  361.                min := min + 1;
  362.             end;
  363.          end;
  364.       end;
  365.  
  366.    pos(line, column: INTEGER): POSITION is
  367.       require
  368.          line >= 1;
  369.          column >= 1;
  370.       do
  371.          !!Result.make(line,column);
  372.       end;
  373.  
  374.    no_errors: BOOLEAN is
  375.       do
  376.          Result := nb_errors = 0;
  377.       end;
  378.  
  379.    character_coding(c: CHARACTER; str: STRING) is
  380.          -- Append in `str' the Eiffel coding of the character (Table
  381.          -- in chapter 25 of ETL, page 423).
  382.          -- When letter notation exists, it is returned in priority :
  383.          --  '%N' gives "%N", '%T' gives "%T", ...
  384.          -- When letter notation does not exists (not in ETL table),
  385.          -- numbered coding is used ("%/1/", "%/2/" etc).
  386.       local
  387.          special: CHARACTER
  388.       do
  389.          inspect
  390.             c
  391.          when '%A' then special := 'A';
  392.          when '%B' then special := 'B';
  393.          when '%C' then special := 'C';
  394.          when '%D' then special := 'D';
  395.          when '%F' then special := 'F';
  396.          when '%H' then special := 'H';
  397.          when '%L' then special := 'L';
  398.          when '%N' then special := 'N';
  399.          when '%Q' then special := 'Q';
  400.          when '%R' then special := 'R';
  401.          when '%S' then special := 'S';
  402.          when '%T' then special := 'T';
  403.          when '%U' then special := 'U';
  404.          when '%V' then special := 'V';
  405.          when '%%' then special := '%%';
  406.          when '%'' then special := '%'';
  407.          when '%"' then special := '"';
  408.          when '%(' then special := '(';
  409.          when '%)' then special := ')';
  410.          when '%<' then special := '<';
  411.          when '%>' then special := '>';
  412.          else
  413.          end;
  414.          str.extend('%%');
  415.          if special = '%U' then
  416.             str.extend('/');
  417.             c.code.append_in(str);
  418.             str.extend('/');
  419.          else
  420.             str.extend(special);
  421.          end;
  422.       end;
  423.  
  424.    sfw_connect(sfw: STD_FILE_WRITE; path: STRING) is
  425.       require
  426.          not sfw.is_connected;
  427.          path /= Void
  428.       do
  429.          sfw.connect_to(path);
  430.          if sfw.is_connected then
  431.             echo.put_string("Writing %"");
  432.             echo.put_string(path);
  433.             echo.put_string("%" file.%N");
  434.          else
  435.             echo.w_put_string("Cannot write file %"");
  436.             echo.w_put_string(path);
  437.             echo.w_put_string(fz_b0);
  438.             die_with_code(exit_failure_code);
  439.          end;
  440.       ensure
  441.          sfw.is_connected
  442.       end;
  443.  
  444.    fatal_error_vtec_2 is
  445.       do
  446.          fatal_error("Expanded class must have no creation procedure,%
  447.                       % or only one creation procedure with%
  448.                       % no arguments (VTEC.2).");
  449.       end;
  450.  
  451.    eiffel_suffix: STRING is ".e";
  452.          -- Eiffel Source file suffix.
  453.  
  454.    c_suffix: STRING is ".c";
  455.          -- C files suffix.
  456.  
  457.    h_suffix: STRING is ".h";
  458.          -- Heading C files suffix.
  459.  
  460.    backup_suffix: STRING is ".bak";
  461.          -- Backup suffix for command `pretty'.
  462.  
  463.    help_suffix: STRING is ".txt";
  464.          -- Suffix for SmallEiffel On-line Help Files.
  465.  
  466.    class_suffix: STRING is ".class";
  467.  
  468.    dot_precedence: INTEGER is 12;
  469.          -- The highest precedence value according to ETL.
  470.  
  471.    atomic_precedence: INTEGER is 13;
  472.          -- Used for atomic elements.
  473.  
  474.    jvm_root_class: STRING is
  475.          -- Fully qualified name for the jvm SmallEiffel object's
  476.          -- added root : "<Package>/<fz_jvm_root>".
  477.       once
  478.          !!Result.make(12);
  479.          Result.copy(jvm.output_name);
  480.          Result.extend('/');
  481.          Result.append(fz_jvm_root);
  482.       end;
  483.  
  484.    jvm_root_descriptor: STRING is
  485.          -- Descriptor for `jvm_root_class': "L<jvm_root_class>;"
  486.       once
  487.          !!Result.make(12);
  488.          Result.extend('L');
  489.          Result.append(jvm_root_class);
  490.          Result.extend(';');
  491.       end;
  492.  
  493.    append_u1(str: STRING; u1: INTEGER) is
  494.       require
  495.          u1.in_range(0,255);
  496.       do
  497.          str.extend(u1.to_character);
  498.       end;
  499.  
  500.    append_u2(str: STRING; u2: INTEGER) is
  501.       require
  502.          u2.in_range(0,65536)
  503.       do
  504.          append_u1(str,u2 // 256);
  505.          append_u1(str,u2 \\ 256);
  506.       end;
  507.  
  508.    append_u4(str: STRING; u4: INTEGER) is
  509.       require
  510.          u4.in_range(0,(2 ^ 31) - 1)
  511.       do
  512.          append_u2(str,u4 // 65536);
  513.          append_u2(str,u4 \\ 65536);
  514.       end;
  515.  
  516.    c_frame_descriptor_local_count: COUNTER is
  517.          -- Current is not in this total.
  518.       once
  519.          !!Result;
  520.       end;
  521.  
  522.    c_frame_descriptor_format: STRING is
  523.          -- The format to print Current and other locals.
  524.       once
  525.          !!Result.make(512);
  526.       end;
  527.  
  528.    c_frame_descriptor_locals: STRING is
  529.          -- To initialize field `locals' of `se_dump_stack'.
  530.       once
  531.          !!Result.make(512);
  532.       end;
  533.  
  534. end -- GLOBALS
  535.