home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / string_aliaser.e < prev    next >
Text File  |  1999-06-05  |  8KB  |  294 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 STRING_ALIASER
  17.    --
  18.    -- Singleton object used to share constant immutable strings.
  19.    -- This singleton is shared via the GLOBALS.`string_aliaser' once function.
  20.    --
  21.    -- The goal is to optimize immutable strings comparisons. Thus, any
  22.    -- immutable name must be registered here to get the corresponding
  23.    -- unique reference.
  24.    --
  25.  
  26. inherit GLOBALS;
  27.  
  28. creation make
  29.  
  30. feature
  31.  
  32.    item(model: STRING): STRING is
  33.       require
  34.          not model.empty
  35.       do
  36.          if memory.has(model) then
  37.             Result := memory.at(model);
  38.          else
  39.             Result := model.twin;
  40.             memory.put(Result,Result);
  41.          end;
  42.       ensure
  43.          Result.is_equal(model)
  44.       end;
  45.  
  46.    ecoop99_item(model: STRING): STRING is
  47.          -- *** `item' for ECOOP'99 benchmark ***
  48.       do
  49.          Result := model.twin;
  50.       end;
  51.  
  52. feature {PREFIX_NAME}
  53.  
  54.    for_prefix(to_string: STRING): STRING is
  55.       do
  56.          Result := key_for_prefix_infix("_ix_",to_string);
  57.       end;
  58.  
  59. feature {INFIX_NAME}
  60.  
  61.    for_infix(to_string: STRING): STRING is
  62.       do
  63.          Result := key_for_prefix_infix("_px_",to_string);
  64.       end;
  65.  
  66. feature {COMPILE_TO_C,COMPILE_TO_JVM}
  67.  
  68.    echo_information is
  69.       do
  70.          echo.put_string("Aliased Strings: ");
  71.          echo.put_integer(memory.count);
  72.          echo.put_string(fz_b6);
  73.       end;
  74.  
  75. feature {NONE}
  76.  
  77.    make is
  78.       do 
  79.          -- -------------------------------------- Class names :
  80.          add1(as_any);
  81.          add1(as_array);
  82.          add1(as_bit);
  83.          add1(as_bit_n);
  84.          add1(as_bit_n_ref);
  85.          add1(as_boolean);
  86.          add1(as_boolean_ref);
  87.          add1(as_character);
  88.          add1(as_character_ref);
  89.          add1(as_dictionary);
  90.          add1(as_double);
  91.          add1(as_double_ref);
  92.          add1(as_exceptions);
  93.          add1(as_fixed_array);
  94.          add1(as_general);
  95.          add1(as_integer);
  96.          add1(as_integer_ref);
  97.          add1(as_memory);
  98.          add1(as_native_array);
  99.          add1(as_none);
  100.          add1(as_platform);
  101.          add1(as_pointer);
  102.          add1(as_pointer_ref);
  103.          add1(as_real);
  104.          add1(as_real_ref);
  105.          add1(as_string);
  106.          add1(as_std_file_read);
  107.          add1(as_std_file_write);
  108.          -- ----------------------- Operator/Infix/Prefix list :
  109.          add1(as_and);
  110.          add1(as_and_then);
  111.          add1(as_at);
  112.          add1(as_backslash_backslash);
  113.          add1(as_eq);
  114.          add1(as_ge);
  115.          add1(as_gt);
  116.          add1(as_implies);
  117.          add1(as_le);
  118.          add1(as_lt);
  119.          add1(as_minus);
  120.          add1(as_muls);
  121.          add1(as_neq);
  122.          add1(as_not);
  123.          add1(as_or);
  124.          add1(as_or_else);
  125.          add1(as_plus);
  126.          add1(as_pow);
  127.          add1(as_shift_left);
  128.          add1(as_shift_right);
  129.          add1(as_slash);
  130.          add1(as_slash_slash);
  131.          add1(as_std_neq);
  132.          add1(as_xor);
  133.          -- ------------------------------------ Feature names :
  134.          add1(as_add_last);
  135.          add1(as_blank);
  136.          add1(as_bitn);
  137.          add2(as_boolean_bits);
  138.          add1(as_calloc);
  139.          add1(as_capacity);
  140.          add2(as_character_bits);
  141.          add1(as_clear_all);
  142.          add1(as_count);
  143.          add1(as_code);
  144.          add1(as_conforms_to);
  145.          add1(as_copy);
  146.          add1(as_c_inline_c);
  147.          add1(as_c_inline_h);
  148.          add1(as_dispose);
  149.          add1(as_double_bits);
  150.          add1(as_double_floor);
  151.          add1(as_die_with_code);
  152.          add1(as_element_sizeof);
  153.          add1(as_eof_code);
  154.          add1(as_exception);
  155.          add1(as_fclose);
  156.          add1(as_feof);
  157.          add1(as_first);
  158.          add1(as_floor);
  159.          add1(as_flush_stream);
  160.          add1(as_free);
  161.          add1(as_from_pointer);
  162.          add1(as_generating_type);
  163.          add1(as_generator);
  164.          add1(as_io);
  165.          add2(as_integer_bits);
  166.          add1(as_is_basic_expanded_type);
  167.          add1(as_is_expanded_type);
  168.          add1(as_is_equal);
  169.          add1(as_is_not_null);
  170.          add1(as_item);
  171.          add1(as_last);
  172.          add1(as_lower);
  173.          add1(as_malloc);
  174.          add1(as_make);
  175.          add2(as_minimum_character_code);
  176.          add2(as_minimum_double);
  177.          add2(as_minimum_integer);
  178.          add2(as_minimum_real);
  179.          add2(as_maximum_character_code);
  180.          add2(as_maximum_double);
  181.          add2(as_maximum_integer);
  182.          add2(as_maximum_real);
  183.          add1(as_object_size);
  184.          add1(as_pointer_bits);
  185.          add1(as_pointer_size);
  186.          add1(as_print);
  187.          add1(as_print_on);
  188.          add1(as_print_run_time_stack);
  189.          add1(as_put);
  190.          add1(as_put_0);
  191.          add1(as_put_1);
  192.          add1(as_raise_exception);
  193.          add1(as_read_byte);
  194.          add1(as_real_bits);
  195.          add1(as_realloc);
  196.          add1(as_se_argc);
  197.          add1(as_se_argv);
  198.          add1(as_se_getenv);
  199.          add1(as_se_remove);
  200.          add1(as_se_rename);
  201.          add1(as_se_string2double);
  202.          add1(as_se_system);
  203.          add1(as_sfr_open);
  204.          add1(as_signal_number);
  205.          add1(as_sfw_open);
  206.          add1(as_sprintf_double);
  207.          add1(as_sprintf_pointer);
  208.          add1(as_standard_copy);
  209.          add1(as_standard_is_equal);
  210.          add1(as_standard_twin);
  211.          add1(as_stderr);
  212.          add1(as_stdin);
  213.          add1(as_stdout);
  214.          add1(as_std_error);
  215.          add1(as_std_input);
  216.          add1(as_std_output);
  217.          add1(as_storage);
  218.          add1(as_to_bit);
  219.          add1(as_to_character);
  220.          add1(as_to_double);
  221.          add1(as_to_integer);
  222.          add1(as_to_pointer);
  223.          add1(as_to_real);
  224.          add1(as_trace_switch);
  225.          add1(as_truncated_to_integer);
  226.          add1(as_twin);
  227.          add1(as_upper);
  228.          add1(as_with_capacity);
  229.          add1(as_write_byte);
  230.          -- -------------------------------------- Other names :
  231.          add1(as_current);
  232.          add1(as_native_array_character);
  233.          add1(as_like_current);
  234.          add1(as_precursor);
  235.          add1(as_result);
  236.          add1(as_void);
  237.       end;
  238.  
  239.    add1(str: STRING) is
  240.       require
  241.          not memory.has(str)
  242.       do
  243.          memory.put(str,str);
  244.       end;
  245.  
  246.    add2(str: STRING) is
  247.       do
  248.          if eiffel_parser.case_insensitive then
  249.             str.to_lower;
  250.          end;
  251.          add1(str);
  252.       end;
  253.  
  254.    tmp_string: STRING is "..............................................";
  255.  
  256.    key_for_prefix_infix(tag_prefix_or_infix, to_string: STRING): STRING is
  257.       local
  258.          i: INTEGER;
  259.          c: CHARACTER;
  260.       do
  261.          tmp_string.copy(tag_prefix_or_infix);
  262.          from
  263.             i := 1;
  264.          until
  265.             i > to_string.count
  266.          loop
  267.             c := to_string.item(i);
  268.             if c.is_letter then
  269.                tmp_string.extend(c);
  270.             else
  271.                c.code.append_in(tmp_string);
  272.             end;
  273.             i := i + 1;
  274.          end;
  275.          Result := item(tmp_string);
  276.       end;
  277.  
  278.    memory: DICTIONARY[STRING,STRING] is
  279.       once
  280.          !!Result.with_capacity(16384);
  281.       end;
  282.  
  283.    singleton_memory: STRING_ALIASER is
  284.       once
  285.          Result := Current;
  286.       end;
  287.  
  288. invariant
  289.  
  290.    is_real_singleton: Current = singleton_memory
  291.  
  292. end -- STRING_ALIASER
  293.  
  294.