home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #4 / amigaacscoverdisc1998-041998.iso / utilities / shareware / dev / ppcsmalleiffel / lib_se / cp_info.e < prev    next >
Encoding:
Text File  |  1998-01-16  |  7.3 KB  |  370 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 CP_INFO
  17.    --  
  18.    -- Print a human readable version of a JVM *.class generated
  19.    -- by SmallEiffel.
  20.    --
  21.  
  22. inherit 
  23.    CP_INFO_TAGS
  24.       redefine fill_tagged_out_memory 
  25.       end;
  26.  
  27. creation clear
  28.  
  29. feature {NONE}
  30.  
  31.    tag: CHARACTER; -- Must be one defined in CP_INFO_TAGS.
  32.    
  33.    info: STRING; -- Contains the corresponding information.
  34.  
  35. feature {CONSTANT_POOL}
  36.  
  37.    clear is
  38.       do
  39.      tag := empty_code;
  40.      if info = Void then
  41.         !!info.make(4);
  42.      else 
  43.         info.clear;
  44.      end;
  45.       end;
  46.  
  47.    is_tagged(tag_value: CHARACTER): BOOLEAN is
  48.       do
  49.      Result := tag = tag_value;
  50.       end;
  51.  
  52. feature
  53.  
  54.    set_class(i: STRING) is
  55.       require
  56.      i.count = 2
  57.       do
  58.      tag := class_code;
  59.      info.copy(i);
  60.       end;
  61.  
  62.    set_fieldref(i: STRING) is
  63.       require
  64.      i.count = 4
  65.       do
  66.      tag := fieldref_code;
  67.      info.copy(i);
  68.       end;
  69.  
  70.    set_methodref(i: STRING) is
  71.       require
  72.      i.count = 4
  73.       do
  74.      tag := methodref_code;
  75.      info.copy(i);
  76.       end;
  77.  
  78.    set_interface_methodref(i: STRING) is
  79.       require
  80.      i.count = 4
  81.       do
  82.      tag := interface_methodref_code;
  83.      info.copy(i);
  84.       end;
  85.  
  86.    set_string(str: STRING) is
  87.       require
  88.      str.count >= 2
  89.       local
  90.      i: INTEGER;
  91.      c: CHARACTER;
  92.       do
  93.      tag := string_code;
  94.      info.clear;
  95.      info.extend(str.item(1));
  96.      info.extend(str.item(2));
  97.      from
  98.         i := 3;
  99.      until
  100.         i > str.count
  101.      loop
  102.         c := str.item(i);
  103.         if c = '%U' then
  104.            info.extend('%/192/');
  105.            info.extend('%/128/');
  106.         else
  107.            info.extend(c);
  108.         end;
  109.         i := i + 1;
  110.      end;
  111.       end;
  112.  
  113.    set_integer(i: STRING) is
  114.       require
  115.      i.count = 4
  116.       do
  117.      tag := integer_code;
  118.      info.copy(i);
  119.       end;
  120.  
  121.    set_float(i: STRING) is
  122.       require
  123.      i.count = 4
  124.       do
  125.      tag := float_code;
  126.      info.copy(i);
  127.       end;
  128.  
  129.    set_long(i: STRING) is
  130.       require
  131.      i.count = 8
  132.       do
  133.      tag := long_code;
  134.      info.copy(i);
  135.       end;
  136.  
  137.    set_double(i: STRING) is
  138.       require
  139.      i.count = 8
  140.       do
  141.      tag := double_code;
  142.      info.copy(i);
  143.       end;
  144.  
  145.    set_name_and_type(i: STRING) is
  146.       require
  147.      i.count = 4
  148.       do
  149.      tag := name_and_type_code;
  150.      info.copy(i);
  151.       end;
  152.  
  153.    set_uft8(i: STRING) is
  154.       require
  155.      i.count >= 2
  156.       do
  157.      tag := uft8_code;
  158.      info.copy(i);
  159.       ensure
  160.      info.count = u2_to_integer(1) + 2
  161.       end;
  162.  
  163. feature -- Testing :
  164.  
  165.    is_class: BOOLEAN is
  166.       do
  167.      Result := tag = class_code;
  168.       end;
  169.  
  170.    is_fieldref: BOOLEAN is
  171.       do
  172.      Result := tag = fieldref_code;
  173.       end;
  174.  
  175.    is_methodref: BOOLEAN is
  176.       do
  177.      Result := tag = methodref_code;
  178.       end;
  179.  
  180.    is_interface_methodref: BOOLEAN is
  181.       do
  182.      Result := tag = interface_methodref_code;
  183.       end;
  184.  
  185.    is_string: BOOLEAN is
  186.       do
  187.      Result := tag = string_code;
  188.       end;
  189.  
  190.    is_integer: BOOLEAN is
  191.       do
  192.      Result := tag = integer_code;
  193.       end;
  194.  
  195.    is_float: BOOLEAN is
  196.       do
  197.      Result := tag = float_code;
  198.       end;
  199.  
  200.    is_long: BOOLEAN is
  201.       do
  202.      Result := tag = long_code;
  203.       end;
  204.  
  205.    is_double: BOOLEAN is
  206.       do
  207.      Result := tag = double_code;
  208.       end;
  209.  
  210.    is_name_and_type: BOOLEAN is
  211.       do
  212.      Result := tag = name_and_type_code;
  213.       end;
  214.  
  215.    is_uft8: BOOLEAN is
  216.       do
  217.      Result := tag = uft8_code;
  218.       end;
  219.  
  220. feature 
  221.  
  222.    view_in(str: STRING) is
  223.      -- Append in `str' a human readable version.
  224.      -- Note: assume `constant_pool' is checked.
  225.       local
  226.      idx, length, i: INTEGER;
  227.       do
  228.      inspect
  229.         tag
  230.      when class_code then
  231.         idx := u2_to_integer(1);
  232.         constant_pool.view_in(str,idx);
  233.      when fieldref_code then
  234.         idx := u2_to_integer(1);
  235.         constant_pool.view_in(str,idx);
  236.         str.extend('.');
  237.         idx := u2_to_integer(3);
  238.         constant_pool.view_in(str,idx);
  239.      when methodref_code then
  240.         idx := u2_to_integer(1);
  241.         constant_pool.view_in(str,idx);
  242.         str.extend('.');
  243.         idx := u2_to_integer(3);
  244.         constant_pool.view_in(str,idx);
  245.      when interface_methodref_code then
  246.      when string_code then
  247.         idx := u2_to_integer(1);
  248.         constant_pool.view_in(str,idx);
  249.      when integer_code then
  250.      when float_code then
  251.      when long_code then
  252.      when double_code then
  253.      when name_and_type_code then
  254.         idx := u2_to_integer(1);
  255.         constant_pool.view_in(str,idx);
  256.         str.extend(':');
  257.         idx := u2_to_integer(3);
  258.         constant_pool.view_in(str,idx);
  259.      when uft8_code then
  260.         from
  261.            length := u2_to_integer(1);
  262.            i := 3;
  263.         until
  264.            length = 0
  265.         loop
  266.            str.extend(info.item(i));
  267.            i := i + 1;
  268.            length := length - 1;
  269.         end;
  270.      end;
  271.       end;
  272.  
  273. feature {CONSTANT_POOL}
  274.  
  275.    b_put is
  276.       do
  277.      jvm.b_put_u1(tag)
  278.      jvm.b_put_byte_string(info);
  279.       end;
  280.  
  281. feature {CONSTANT_POOL} -- Update and search :
  282.    -- *** ACOMPLETER AU FUR ET A MESURE ***
  283.  
  284.    is_class_idx(uft8: INTEGER): BOOLEAN is
  285.       do
  286.      if class_code = tag then
  287.         Result := u2_to_integer(1) = uft8;
  288.      end;
  289.       end;
  290.  
  291.    is_fieldref_idx(c, nt: INTEGER): BOOLEAN is
  292.       do
  293.      if fieldref_code = tag then
  294.         if u2_to_integer(1) = c then
  295.            Result := u2_to_integer(3) = nt;
  296.         end;
  297.      end;
  298.       end;
  299.    
  300.    is_methodref_idx(c, nt: INTEGER): BOOLEAN is
  301.       do
  302.      if methodref_code = tag then
  303.         if u2_to_integer(1) = c then
  304.            Result := u2_to_integer(3) = nt;
  305.         end;
  306.      end;
  307.       end;
  308.  
  309.    is_name_and_type_idx(n, d: INTEGER): BOOLEAN is
  310.       do
  311.      if name_and_type_code = tag then
  312.         if u2_to_integer(1) = n then
  313.            Result := u2_to_integer(3) = d;
  314.         end;
  315.      end;
  316.       end;
  317.    
  318.    is_string_idx(uft8: INTEGER): BOOLEAN is
  319.       do
  320.      if string_code = tag then
  321.         Result := u2_to_integer(1) = uft8;
  322.      end;
  323.       end;
  324.  
  325.    is_uft8_idx(contents: STRING): BOOLEAN is
  326.       local
  327.      i1, i2: INTEGER;
  328.       do
  329.      if uft8_code = tag then
  330.         if u2_to_integer(1) = contents.count then
  331.            from
  332.           i1 := contents.count + 1;
  333.           i2 := info.count + 1;
  334.           check
  335.              i1 + 2 = i2
  336.           end;
  337.           Result := true;
  338.            until
  339.           not Result or else i1 = 1
  340.            loop
  341.           i1 := i1 - 1;
  342.           i2 := i2 - 1;
  343.           Result := contents.item(i1) = info.item(i2);
  344.            end;
  345.         end;
  346.      end;
  347.       end;
  348.  
  349. feature
  350.  
  351.    fill_tagged_out_memory is
  352.       do
  353.      tagged_out_memory.append("tag=");
  354.      tag.code.append_in(tagged_out_memory);
  355.      tagged_out_memory.extend('%"');
  356.      tagged_out_memory.append(info);     
  357.      tagged_out_memory.extend('%"');
  358.       end;
  359.  
  360. feature {NONE}
  361.  
  362.    u2_to_integer(i: INTEGER): INTEGER is
  363.       do
  364.      Result := info.item(i).to_integer * 256;
  365.      Result := Result + info.item(i + 1).to_integer;
  366.       end;
  367.  
  368. end -- CP_INFO
  369.  
  370.