home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / unique_string.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  6.6 KB  |  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://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 UNIQUE_STRING
  17.    --
  18.    -- Unique global object to share constant strings.
  19.    -- To ensure that only one STRING is used for the same frozen
  20.    -- contents (for example, everywhere the name "INTEGER" is
  21.    -- used, the same object of class STRING is shared).
  22.    -- Assume (checked in mode -debug_check) that STRING are not 
  23.    -- dynamically changed.
  24.    --
  25.  
  26. inherit GLOBALS;
  27.  
  28. creation make
  29.  
  30. feature
  31.  
  32.    item(model: STRING): STRING is
  33.       require
  34.      model /= Void
  35.       do
  36.      initialize;
  37.      if memory.has(model) then
  38.         Result := read(model);
  39.      else
  40.         Result := model.twin;
  41.         add1(Result);
  42.      end;
  43.       ensure
  44.      Result.is_equal(model)
  45.       end;
  46.  
  47.    count: INTEGER is
  48.       do
  49.      Result := memory.count;
  50.       end;
  51.  
  52. feature {PREFIX_NAME}
  53.  
  54.    for_prefix(to_string: STRING): STRING is
  55.       do
  56.      pfx_ifx.copy("_ix_");
  57.      key_pfx_ifx(to_string);
  58.      Result := item(pfx_ifx);
  59.       end;
  60.  
  61. feature {INFIX_NAME}
  62.  
  63.    for_infix(to_string: STRING): STRING is
  64.       do
  65.      pfx_ifx.copy("_px_");
  66.      key_pfx_ifx(to_string);
  67.      Result := item(pfx_ifx);
  68.       end;
  69.  
  70. feature {NONE}
  71.  
  72.    make is
  73.       do
  74.       end;
  75.  
  76.    initialize is
  77.       once
  78.      -- -------------------------------------- Class names :
  79.      add1(us_any);
  80.      add1(us_array);
  81.      add1(us_bit);
  82.      add1(us_bit_n);
  83.      add1(us_bit_n_ref);
  84.      add1(us_boolean);
  85.      add1(us_boolean_ref);
  86.      add1(us_character);
  87.      add1(us_character_ref);
  88.      add1(us_dictionary);
  89.      add1(us_double);
  90.      add1(us_double_ref);
  91.      add1(us_fixed_array);
  92.      add1(us_general);
  93.      add1(us_integer);
  94.      add1(us_integer_ref);
  95.      add1(us_memory);
  96.      add1(us_native_array);
  97.      add1(us_none);
  98.      add1(us_platform);
  99.      add1(us_pointer);
  100.      add1(us_pointer_ref);
  101.      add1(us_real);
  102.      add1(us_real_ref);
  103.      add1(us_string);
  104.      add1(us_std_file_read);
  105.      -- ----------------------- Operator/Infix/Prefix list :
  106.      add1(us_and);
  107.      add1(us_and_then);
  108.      add1(us_at);
  109.      add1(us_backslash_backslash);
  110.      add1(us_eq);
  111.      add1(us_ge);
  112.      add1(us_gt);
  113.      add1(us_implies);
  114.      add1(us_le);
  115.      add1(us_lt);
  116.      add1(us_minus);
  117.      add1(us_muls);
  118.      add1(us_neq);
  119.      add1(us_not);
  120.      add1(us_or);
  121.      add1(us_or_else);
  122.      add1(us_plus);
  123.      add1(us_pow);
  124.      add1(us_shift_left);
  125.      add1(us_shift_right);
  126.      add1(us_slash);
  127.      add1(us_slash_slash);
  128.      add1(us_std_neq);
  129.      add1(us_xor);
  130.      -- ------------------------------------ Feature names :
  131.      add1(us_blank);
  132.      add1(us_bitn);
  133.      add1(us_boolean_bits);
  134.      add1(us_calloc);
  135.      add1(us_capacity);
  136.      add1(us_character_bits);
  137.      add1(us_clear_all);
  138.      add1(us_compile_to_c);
  139.      add1(us_compile_to_jvm);
  140.      add1(us_count);
  141.      add1(us_crash);
  142.      add1(us_code);
  143.      add1(us_conforms_to);
  144.      add1(us_copy);
  145.      add1(us_c_inline_c);
  146.      add1(us_c_inline_h);
  147.      add1(us_double_bits);
  148.      add1(us_double_floor);
  149.      add1(us_die_with_code);
  150.      add1(us_element_sizeof);
  151.      add1(us_eof_code);
  152.      add1(us_fclose);
  153.      add1(us_feof);
  154.      add1(us_floor);
  155.      add1(us_flush_stream);
  156.      add1(us_free);
  157.      add1(us_from_pointer);
  158.      add1(us_generating_type);
  159.      add1(us_generator);
  160.      add1(us_io);
  161.      add1(us_integer_bits);
  162.      add1(us_is_basic_expanded_type);
  163.      add1(us_is_expanded_type);
  164.      add1(us_is_equal);
  165.      add1(us_is_not_void);
  166.      add1(us_item);
  167.      add1(us_lower);
  168.      add1(us_malloc);
  169.      add1(us_make);
  170.      add2(us_minimum_character_code);
  171.      add2(us_minimum_double);
  172.      add2(us_minimum_integer);
  173.      add2(us_minimum_real);
  174.      add2(us_maximum_character_code);
  175.      add2(us_maximum_double);
  176.      add2(us_maximum_integer);
  177.      add2(us_maximum_real);
  178.      add1(us_object_size);
  179.      add1(us_pointer_bits);
  180.      add1(us_pointer_size);
  181.      add1(us_print);
  182.      add1(us_print_on);
  183.      add1(us_print_run_time_stack);
  184.      add1(us_put);
  185.      add1(us_put_0);
  186.      add1(us_put_1);
  187.      add1(us_read_byte);
  188.      add1(us_real_bits);
  189.      add1(us_realloc);
  190.      add1(us_se_argc);
  191.      add1(us_se_argv);
  192.      add1(us_se_getenv);
  193.      add1(us_se_remove);
  194.      add1(us_se_rename);
  195.      add1(us_se_string2double);
  196.      add1(us_se_system);
  197.      add1(us_sfr_open);
  198.      add1(us_sfw_open);
  199.      add1(us_sprintf_double);
  200.      add1(us_sprintf_pointer);
  201.      add1(us_standard_copy);
  202.      add1(us_standard_is_equal);
  203.      add1(us_standard_twin);
  204.      add1(us_stderr);
  205.      add1(us_stdin);
  206.      add1(us_stdout);
  207.      add1(us_std_error);
  208.      add1(us_std_input);
  209.      add1(us_std_output);
  210.      add1(us_storage);
  211.      add1(us_to_bit);
  212.      add1(us_to_character);
  213.      add1(us_to_double);
  214.      add1(us_to_integer);
  215.      add1(us_to_pointer);
  216.      add1(us_to_real);
  217.      add1(us_trace_switch);
  218.      add1(us_truncated_to_integer);
  219.      add1(us_twin);
  220.      add1(us_upper);
  221.      add1(us_with_capacity);
  222.      add1(us_write_byte);
  223.      -- -------------------------------------- Other names :
  224.      add1(us_current);
  225.      add1(us_native_array_character);
  226.      add1(us_like_current);
  227.      add1(us_result);
  228.      add1(us_void);
  229.       end;
  230.  
  231.    add1(str: STRING) is
  232.       require
  233.      not memory.has(str)
  234.       do
  235.      memory.put(str,str);
  236.      debug
  237.         check_memory.put(str.twin,str);
  238.      end
  239.       end;
  240.  
  241.    add2(str: STRING) is
  242.       do
  243.      if eiffel_parser.case_insensitive then
  244.         str.to_lower;
  245.      end;
  246.      add1(str);
  247.       end;
  248.  
  249.    read(model: STRING): STRING is
  250.       do
  251.      Result := memory.at(model);
  252.      debug
  253.         if not check_memory.at(Result).is_equal(Result) then
  254.            eh.append("UNIQUE_STRING error report : ");
  255.            eh.append(check_memory.at(Result));
  256.            eh.append("%" changed to %"");
  257.            eh.append(Result);
  258.            fatal_error("%".");
  259.         end;
  260.      end;
  261.       end;
  262.  
  263.    memory: DICTIONARY[STRING,STRING] is
  264.       once
  265.      !!Result.with_capacity(4096);
  266.       end;
  267.  
  268.    pfx_ifx: STRING is 
  269.       once
  270.      !!Result.make(16);
  271.       end;
  272.  
  273.    key_pfx_ifx(to_string: STRING) is
  274.       local
  275.      i: INTEGER;
  276.      c: CHARACTER;
  277.       do
  278.      from
  279.         i := 1;
  280.      until
  281.         i > to_string.count
  282.      loop
  283.         c := to_string.item(i);
  284.         if c.is_letter then
  285.            pfx_ifx.extend(c);
  286.         else 
  287.            c.code.append_in(pfx_ifx);
  288.         end;
  289.         i := i + 1;
  290.      end;
  291.       end;
  292. end -- UNIQUE_STRING
  293.  
  294.