KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > coffi > method_info


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 1997 Clark Verbrugge
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26
27
28
29
30
31
32 package soot.coffi;
33 import soot.*;
34
35 import java.util.*;
36 import java.io.*;
37 import java.util.Vector JavaDoc;
38 import soot.util.*;
39
40 /** Represents a single method_info object.
41  * @see ClassFile
42  * @author Clark Verbrugge
43  */

44 public class method_info {
45    /** Access flags for this field. */
46     public int access_flags;
47    /** Constant pool index of the name of this method.
48     * @see ClassFile#constant_pool
49     * @see CONSTANT_Utf8_info
50     */

51     public int name_index;
52    /** Constant pool index of the type descriptor of this method.
53     * @see ClassFile#constant_pool
54     * @see CONSTANT_Utf8_info
55     */

56     public int descriptor_index;
57    /** Count of attributes this method contains. */
58     public int attributes_count;
59    /** Array of attribute_info objects for this method.
60     * @see attribute_info
61     */

62     public attribute_info attributes[];
63
64     /** A shortcut into attributes array for Code_attribute
65      * @see Code_attribute
66      */

67     public Code_attribute code_attr;
68
69    /** List of Instructions constructed when the method is parsed.
70     * @see Instruction
71     */

72     public Instruction instructions;
73    /** Control Flow Graph constructed when the method is parsed.
74     * @see CFG
75     */

76     public CFG cfg;
77
78     public soot.SootMethod jmethod;
79
80     List instructionList;
81
82    /** Returns the name of this method.
83     * @param constant_pool the constant_pool for this class.
84     * @return the name of this method.
85     */

86     public String JavaDoc toName(cp_info constant_pool[]) {
87       CONSTANT_Utf8_info ci;
88       ci = (CONSTANT_Utf8_info)(constant_pool[name_index]);
89       return ci.convert();
90    }
91
92    /** Locates and returns the code attribute for this method.
93     * @return the single code attribute, or null if not found.
94     * @see Code_attribute
95     */

96     Code_attribute locate_code_attribute() {
97       attribute_info ai;
98       int i;
99
100       for (i=0; i<attributes_count; i++) {
101          ai = attributes[i];
102          if (ai instanceof Code_attribute)
103             return (Code_attribute)ai;
104       }
105       return null;
106    }
107
108    /** Returns the prototype of this field.
109     * @param constant_pool the constant_pool for this class.
110     * @return the prototype (access + return + name + parameters) of this method.
111     */

112     public String JavaDoc prototype(cp_info constant_pool[]) {
113       String JavaDoc access,rt,name,params;
114       Code_attribute c = locate_code_attribute();
115
116       access = ClassFile.access_string(access_flags," ");
117       rt = ClassFile.parseMethodDesc_return(cp_info.getTypeDescr(constant_pool,
118                                                                  descriptor_index));
119       name = toName(constant_pool);
120       params = ClassFile.parseMethodDesc_params(cp_info.
121                                                 getTypeDescr(constant_pool,
122                                                              descriptor_index));
123       if (access.length()>0)
124          return access + " " + rt + " " + name + "(" + params + ")";
125       return rt + " " + name + "(" + params + ")";
126    }
127
128    /** Displays this method, printing a prototype followed by list of Instructions.
129     * @param constant_pool the constant_pool for this class.
130     * @see prototype
131     * @see ByteCode#showCode
132     */

133     void print(cp_info constant_pool[]) {
134       G.v().out.println(prototype(constant_pool));
135       ByteCode.showCode(instructions,constant_pool);
136    }
137 }
138
Popular Tags