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