home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_se / manifest_string.e < prev    next >
Text File  |  1999-06-05  |  9KB  |  397 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 MANIFEST_STRING
  17.    --
  18.    -- When using Manifest Constant STRING.
  19.    --
  20.  
  21. inherit EXPRESSION;
  22.  
  23. creation {EIFFEL_PARSER} make
  24.  
  25. feature
  26.  
  27.    start_position: POSITION;
  28.          -- Of the first character '%"'.
  29.  
  30.    to_string: STRING;
  31.          -- Eiffel contents of the string.
  32.  
  33. feature {NONE}
  34.  
  35.    break: ARRAY[INTEGER];
  36.          -- If not Void, places in `to_string' where extended notation (with
  37.          -- line(s) break) is used. The corresponding character in to string
  38.          -- is put on next line.
  39.  
  40.    ascii: ARRAY[INTEGER];
  41.          -- If not Void, places in `to_string' where character are to be
  42.          -- printed using asci code notation.
  43.  
  44.    percent: ARRAY[INTEGER];
  45.          -- If not Void, places in `to_string' where character are to be
  46.          -- printed using percent.
  47.  
  48. feature {MANIFEST_STRING,MANIFEST_STRING_POOL}
  49.  
  50.    mangling: STRING;
  51.          -- When runnable. Name to be used for the corresponding C
  52.          -- global variable or for the JVM corresponding field.
  53.  
  54. feature
  55.  
  56.    is_manifest_string: BOOLEAN is true;
  57.  
  58.    is_writable: BOOLEAN is false;
  59.  
  60.    is_current: BOOLEAN is false;
  61.  
  62.    is_static: BOOLEAN is false;
  63.  
  64.    is_void: BOOLEAN is false;
  65.  
  66.    is_result: BOOLEAN is false;
  67.  
  68.    use_current: BOOLEAN is false;
  69.  
  70.    is_pre_computable: BOOLEAN is true;
  71.  
  72.    c_simple: BOOLEAN is true;
  73.  
  74.    can_be_dropped: BOOLEAN is true;
  75.  
  76. feature {NONE}
  77.  
  78.    make(sp: like start_position) is
  79.       require
  80.          sp /= Void
  81.       do
  82.          start_position := sp;
  83.          !!to_string.make(0);
  84.       ensure
  85.          start_position = sp
  86.       end;
  87.  
  88. feature
  89.  
  90.    static_result_base_class: BASE_CLASS is
  91.       do
  92.          Result := small_eiffel.get_class(as_string);
  93.       end;
  94.  
  95.    result_type: TYPE_STRING is
  96.       do
  97.          Result := type_string;
  98.       end;
  99.  
  100.    assertion_check(tag: CHARACTER) is
  101.       do
  102.       end;
  103.  
  104.    static_value: INTEGER is
  105.       do
  106.       end;
  107.  
  108.    isa_dca_inline_argument: INTEGER is
  109.       do
  110.       end;
  111.  
  112.    dca_inline_argument(formal_arg_type: TYPE) is
  113.       do
  114.       end;
  115.  
  116.    mapping_c_target(target_type: TYPE) is
  117.       do
  118.          cpp.put_string(mangling);
  119.       end;
  120.  
  121.    mapping_c_arg(formal_arg_type: TYPE) is
  122.       do
  123.          compile_to_c;
  124.       end;
  125.  
  126.    collect_c_tmp is
  127.       do
  128.       end;
  129.  
  130.    compile_to_c is
  131.       do
  132.          cpp.put_character('(');
  133.          cpp.put_string(fz_cast_t0_star);
  134.          cpp.put_string(mangling);
  135.          cpp.put_character(')');
  136.       end;
  137.  
  138.    c_declare_for_old is
  139.       do
  140.       end;
  141.  
  142.    compile_to_c_old is
  143.       do
  144.       end;
  145.  
  146.    compile_to_jvm_old is
  147.       do
  148.       end;
  149.  
  150.    afd_check is
  151.       do
  152.       end;
  153.  
  154.    count: INTEGER is
  155.       do
  156.          Result := to_string.count;
  157.       end;
  158.  
  159.    compile_target_to_jvm, compile_to_jvm is
  160.       local
  161.          idx: INTEGER;
  162.       do
  163.          idx := fieldref_idx;
  164.          code_attribute.opcode_getstatic(idx,1);
  165.       end;
  166.  
  167.    compile_to_jvm_assignment(a: ASSIGNMENT) is
  168.       do
  169.       end;
  170.  
  171.    jvm_branch_if_false: INTEGER is
  172.       do
  173.       end;
  174.  
  175.    jvm_branch_if_true: INTEGER is
  176.       do
  177.       end;
  178.  
  179.    compile_to_jvm_into(dest: TYPE): INTEGER is
  180.       do
  181.          Result := 1;
  182.          compile_to_jvm;
  183.       end;
  184.  
  185.    to_runnable(ct: TYPE): MANIFEST_STRING is
  186.       do
  187.          if mangling = Void then
  188.             mangling := manifest_string_pool.register(Current);
  189.          end;
  190.          Result := Current;
  191.       end;
  192.  
  193.    precedence: INTEGER is
  194.       do
  195.          Result := atomic_precedence;
  196.       end;
  197.  
  198.    bracketed_pretty_print, pretty_print is
  199.       local
  200.          i, column: INTEGER;
  201.       do
  202.          from
  203.             column := fmt.column;
  204.             fmt.put_character('%"');
  205.             i := 1;
  206.          until
  207.             i > to_string.count
  208.          loop
  209.             if is_on_next_line(i) then
  210.                fmt.put_string("%%%N");
  211.                from
  212.                until
  213.                   column = fmt.column
  214.                loop
  215.                   fmt.put_character(' ');
  216.                end;
  217.                fmt.put_character('%%');
  218.             end;
  219.             pretty_print_character(i);
  220.             i := i + 1;
  221.          end;
  222.          fmt.put_character('%"');
  223.       end;
  224.  
  225.    print_as_target is
  226.       do
  227.          fmt.put_character('(');
  228.          pretty_print;
  229.          fmt.put_character(')');
  230.          fmt.put_character('.');
  231.       end;
  232.  
  233.    short is
  234.       local
  235.          i: INTEGER;
  236.       do
  237.          short_print.hook_or("open_ms","%"");
  238.          from
  239.             i := 1;
  240.          until
  241.             i > to_string.count
  242.          loop
  243.             short_character(i);
  244.             i := i + 1;
  245.          end;
  246.          short_print.hook_or("close_ms","%"");
  247.       end;
  248.  
  249.    short_target is
  250.       do
  251.          bracketed_short;
  252.          short_print.a_dot;
  253.       end;
  254.  
  255. feature {EIFFEL_PARSER}
  256.  
  257.    add(ch: CHARACTER) is
  258.          -- Append `ch' to manifest string setting
  259.          -- ordinary printing mode.
  260.       do
  261.          to_string.extend(ch);
  262.       end;
  263.  
  264.    add_ascii(ch: CHARACTER) is
  265.          -- Append `ch' to manifest string setting
  266.          -- `ascii'  printing mode.
  267.       do
  268.          to_string.extend(ch);
  269.          if ascii = Void then
  270.             ascii := <<to_string.count>>;
  271.          else
  272.             ascii.add_last(to_string.count);
  273.          end;
  274.       end;
  275.  
  276.    add_percent(ch: CHARACTER) is
  277.          -- Append `ch' to manifest string setting
  278.          -- `percent'  printing mode.
  279.       do
  280.          to_string.extend(ch);
  281.          if percent = Void then
  282.             percent := <<to_string.count>>;
  283.          else
  284.             percent.add_last(to_string.count);
  285.          end;
  286.       end;
  287.  
  288.    break_line is
  289.          -- Next character will be a `break'.
  290.       do
  291.          if break = Void then
  292.             break := <<to_string.count + 1>>;
  293.          else
  294.             break.add_last(to_string.count + 1);
  295.          end;
  296.       end;
  297.  
  298. feature {NONE}
  299.  
  300.    pretty_print_character(i: INTEGER) is
  301.       require
  302.          1 <= i;
  303.          i <= count;
  304.       local
  305.          val: INTEGER;
  306.       do
  307.          if percent /= Void and then percent.fast_has(i) then
  308.             tmp_string.clear;
  309.             character_coding(to_string.item(i),tmp_string);
  310.             fmt.put_string(tmp_string);
  311.          elseif ascii /= Void and then ascii.fast_has(i) then
  312.             val := to_string.item(i).code;
  313.             fmt.put_string("%%/");
  314.             fmt.put_integer(val);
  315.             fmt.put_string(as_slash);
  316.          else
  317.             fmt.put_character(to_string.item(i));
  318.          end;
  319.       end;
  320.  
  321.    short_character(i: INTEGER) is
  322.       require
  323.          1 <= i;
  324.          i <= count;
  325.       local
  326.          val: INTEGER;
  327.          c: CHARACTER;
  328.       do
  329.          tmp_string.clear;
  330.          if percent /= Void and then percent.fast_has(i) then
  331.             character_coding(to_string.item(i),tmp_string);
  332.          elseif ascii /= Void and then ascii.fast_has(i) then
  333.             val := to_string.item(i).code;
  334.             tmp_string.append("%%/");
  335.             val.append_in(tmp_string);
  336.             tmp_string.append(as_slash);
  337.          end;
  338.          if tmp_string.count = 0 then
  339.             short_print.a_character(to_string.item(i));
  340.          else
  341.             from
  342.                val := 1;
  343.             until
  344.                val > tmp_string.count
  345.             loop
  346.                c := tmp_string.item(val);
  347.                if c = '%%' then
  348.                   short_print.hook_or("Prcnt_ms","%%");
  349.                elseif c = '/' then
  350.                   short_print.hook_or("Slash_ms",as_slash);
  351.                else
  352.                   short_print.a_character(c);
  353.                end;
  354.                val := val + 1;
  355.             end;
  356.          end;
  357.       end;
  358.  
  359.    is_on_next_line(i: INTEGER): BOOLEAN is
  360.       require
  361.          1 <= i;
  362.          i <= count;
  363.       do
  364.          if break /= Void then
  365.             Result := break.fast_has(i);
  366.          end;
  367.       end;
  368.  
  369. feature {NONE}
  370.  
  371.    tmp_string: STRING is
  372.       once
  373.          !!Result.make(8);
  374.       end;
  375.  
  376. feature {CREATION_CALL,EXPRESSION_WITH_COMMENT}
  377.  
  378.    jvm_assign is
  379.       do
  380.       end;
  381.  
  382. feature {MANIFEST_STRING_POOL}
  383.  
  384.    fieldref_idx: INTEGER is
  385.       do
  386.          Result := constant_pool.idx_fieldref_for_manifest_string(mangling);
  387.       end;
  388.  
  389. invariant
  390.  
  391.    start_position /= Void;
  392.  
  393.    to_string /= Void;
  394.  
  395. end -- MANIFEST_STRING
  396.  
  397.