home *** CD-ROM | disk | FTP | other *** search
/ Hacker / Hacker.iso / HACKER / DECOMP / DECAF / fielmeth.adb < prev    next >
Encoding:
Text File  |  1996-09-19  |  4.8 KB  |  146 lines

  1. --
  2. -- Copyright (C) 1996 Ada Resource Association (ARA), Columbus, Ohio.
  3. -- Author: Gilles Demailly
  4. --
  5. --
  6. -- Permission to use, copy, modify, and distribute this software and its
  7. -- documentation for any purpose and without fee is hereby granted,
  8. -- provided that the above copyright and authorship notice appear in all
  9. -- copies and that both that copyright notice and this permission notice
  10. -- appear in supporting documentation.
  11. -- 
  12. -- The ARA makes no representations about the suitability of this software
  13. -- for any purpose.  It is provided "as is" without express
  14. -- or implied warranty.
  15. -- 
  16.  
  17. with Ada.Text_Io;
  18.  
  19. with Ada.Tags; use type Ada.Tags.Tag;
  20.  
  21. with Flags;
  22. with Attribute;
  23. with Attribute.Code;
  24. with Attribute.Exceptions;
  25.  
  26. package body Field.Method is
  27.    
  28.    function Read_Field 
  29.                (From_File : Byte_Utilities.File_Type;
  30.                 Context   : in CP.Acc_CP_Infos)      
  31.             return Acc_Field_Info is
  32.       New_One : Acc_Field_Info;
  33.    begin
  34.       -- creates the Method Info
  35.       New_One := new Method_Info;
  36.  
  37.       -- Decoding inside informations is done by the superclass
  38.       Decode (From_File, New_One, Context);
  39.       return New_One;
  40.    end Read_Field;
  41.  
  42.  
  43.    procedure Display_Java_Spec (Infos     : access Method_Info;
  44.                                 Context   : in CP.Acc_CP_Infos;
  45.                                 For_Class : in Unsigned_16;
  46.                                 For_Body  : in Boolean) is
  47.       Signature : constant String := CP.Java_Decoded_String
  48.                                         (Context (Infos.Signature_Index),
  49.                                          Context,
  50.                                          CP.Method_Signature);
  51.       Method_Name : constant String := CP.Print_String
  52.                                           (Context (Infos.Name_Index), Context);
  53.       Return_Index : Natural := Signature'First;
  54.    begin
  55.    
  56.       -- gets the type of the method return value
  57.       while Return_Index <= Signature'Last and then
  58.             Signature (Return_Index) /= ')' loop
  59.          Return_Index := Return_Index + 1;
  60.       end loop;
  61.       
  62.       Ada.Text_Io.Put ("   ");
  63.       
  64.       -- displays the method access categories
  65.       Flags.Display (Infos.Access_Flags, Flags.Method_Flag);
  66.  
  67.       -- Displays the type of the method return value
  68.       Ada.Text_Io.Put (Signature (Return_Index + 1..Signature'Last) & " ");
  69.       
  70.       -- displays the method name (special treatment for constructors)
  71.       if Method_Name = "<init>" then
  72.          Ada.Text_Io.Put (CP.Java_Decoded_String
  73.                              (Context (For_Class),
  74.                               Context,
  75.                               CP.Class_Name));
  76.       else
  77.          Ada.Text_Io.Put (Method_Name);
  78.       end if;
  79.       
  80.       -- displays the method arguments
  81.       Ada.Text_Io.Put
  82.          (" " & Signature (Signature'First .. Return_Index));
  83.          
  84.       -- displays the exceptions thrown by the method
  85.       if Infos.Attributes_Count > 0 then
  86.          for J in 1 .. Infos.Attributes_Count loop
  87.             if Infos.Attributes (J).all'Tag = 
  88.                Attribute.Exceptions.Exceptions_Attribute'Tag then
  89.                Ada.Text_Io.Put (" throws ");
  90.                Attribute.Display (Infos.Attributes (J), Context);
  91.             end if;
  92.          end loop;
  93.       end if;
  94.  
  95.       -- if there is not a body generated, this is the end.
  96.       if not For_Body then
  97.          Ada.Text_Io.Put_Line (";");
  98.       end if;
  99.       
  100.    end Display_Java_Spec;
  101.  
  102.    procedure Display_Ada_Spec (Infos     : access Method_Info;
  103.                                Context   : in CP.Acc_CP_Infos;
  104.                                For_Class : in Unsigned_16) is
  105.    begin
  106.       null;
  107.    end Display_Ada_Spec;
  108.  
  109.    procedure Display_Java_Body (Infos     : access Method_Info;
  110.                                 Context   : in CP.Acc_CP_Infos;
  111.                                 For_Class : in Unsigned_16) is
  112.       
  113.       No_Code : Boolean := True;
  114.       
  115.    begin
  116.       -- displays the method definition
  117.       Display_Java_Spec (Infos, Context, For_Class, True);
  118.            
  119.       -- displays the method's code (if applicable)
  120.       if Infos.Attributes_Count > 0 then
  121.          for J in 1 .. Infos.Attributes_Count loop
  122.             if Infos.Attributes (J).all'Tag = 
  123.                Attribute.Code.Code_Attribute'Tag then
  124.                Ada.Text_Io.Put_Line (" {");
  125.                Attribute.Display (Infos.Attributes (J), Context);
  126.                Ada.Text_Io.Put_Line ("      }");
  127.                No_Code := False;
  128.             end if;
  129.          end loop;
  130.       end if;
  131.  
  132.       if No_Code then
  133.          Ada.Text_Io.Put_Line (";");
  134.       end if;
  135.  
  136.    end Display_Java_Body;
  137.  
  138.    procedure Display_Ada_Body (Infos     : access Method_Info;
  139.                                Context   : in CP.Acc_CP_Infos;
  140.                                For_Class : in Unsigned_16) is
  141.    begin
  142.       null;
  143.    end Display_Ada_Body;
  144.  
  145. end Field.Method;
  146.