Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

method_info.java

00001 package ca.mcgill.sable.soot.coffi;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Jimple, a 3-address code Java(TM) bytecode representation.        *
00005  * Copyright (C) 1997, 1998 Raja Vallee-Rai (kor@sable.mcgill.ca)    *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project of the Sable Research Group,      *
00009  * School of Computer Science, McGill University, Canada             *
00010  * (http://www.sable.mcgill.ca/).  It is understood that any         *
00011  * modification not identified as such is not covered by the         *
00012  * preceding statement.                                              *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this library; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other Sable Research Group projects, please      *
00033  * visit the web site: http://www.sable.mcgill.ca/                   *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 
00036 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00037  * Coffi, a bytecode parser for the Java(TM) language.               *
00038  * Copyright (C) 1996, 1997 Clark Verbrugge (clump@sable.mcgill.ca). *
00039  * All rights reserved.                                              *
00040  *                                                                   *
00041  * This work was done as a project of the Sable Research Group,      *
00042  * School of Computer Science, McGill University, Canada             *
00043  * (http://www.sable.mcgill.ca/).  It is understood that any         *
00044  * modification not identified as such is not covered by the         *
00045  * preceding statement.                                              *
00046  *                                                                   *
00047  * This work is free software; you can redistribute it and/or        *
00048  * modify it under the terms of the GNU Library General Public       *
00049  * License as published by the Free Software Foundation; either      *
00050  * version 2 of the License, or (at your option) any later version.  *
00051  *                                                                   *
00052  * This work is distributed in the hope that it will be useful,      *
00053  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00054  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00055  * Library General Public License for more details.                  *
00056  *                                                                   *
00057  * You should have received a copy of the GNU Library General Public *
00058  * License along with this library; if not, write to the             *
00059  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00060  * Boston, MA  02111-1307, USA.                                      *
00061  *                                                                   *
00062  * Java is a trademark of Sun Microsystems, Inc.                     *
00063  *                                                                   *
00064  * To submit a bug report, send a comment, or get the latest news on *
00065  * this project and other Sable Research Group projects, please      *
00066  * visit the web site: http://www.sable.mcgill.ca/                   *
00067  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00068 
00069 /*
00070  Reference Version
00071  -----------------
00072  This is the latest official version on which this file is based.
00073  The reference version is: $CoffiVersion: 1.1 $
00074                            $SootVersion: 1.beta.4 $
00075 
00076  Change History
00077  --------------
00078  A) Notes:
00079 
00080  Please use the following template.  Most recent changes should
00081  appear at the top of the list.
00082 
00083  - Modified on [date (March 1, 1900)] by [name]. [(*) if appropriate]
00084    [description of modification].
00085 
00086  Any Modification flagged with "(*)" was done as a project of the
00087  Sable Research Group, School of Computer Science,
00088  McGill University, Canada (http://www.sable.mcgill.ca/).
00089 
00090  You should add your copyright, using the following template, at
00091  the top of this file, along with other copyrights.
00092 
00093  *                                                                   *
00094  * Modifications by [name] are                                       *
00095  * Copyright (C) [year(s)] [your name (or company)].  All rights     *
00096  * reserved.                                                         *
00097  *                                                                   *
00098 
00099  B) Changes:
00100 
00101  
00102  - Modified on November 13, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca) (*)
00103    Changed some short's to int's to properly contain unsigned
00104    short values.
00105 
00106  - Modified on November 2, 1998 by Raja Vallee-Rai (kor@sable.mcgill.ca) (*)
00107    Repackaged all source files and performed extensive modifications.
00108    First initial release of Soot.
00109 
00110  - Modified on 15-Jun-1998 by Raja Vallee-Rai (kor@sable.mcgill.ca). (*)
00111    First internal release (Version 0.1).
00112 */
00113 
00114 import java.io.*;
00115 import java.util.Vector;
00116 
00117 /** Represents a single method_info object.
00118  * @see ClassFile
00119  * @author Clark Verbrugge
00120  */
00121 public class method_info {
00122    /** Access flags for this field. */
00123     int access_flags;
00124    /** Constant pool index of the name of this method.
00125     * @see ClassFile#constant_pool
00126     * @see CONSTANT_Utf8_info
00127     */
00128     int name_index;
00129    /** Constant pool index of the type descriptor of this method.
00130     * @see ClassFile#constant_pool
00131     * @see CONSTANT_Utf8_info
00132     */
00133     int descriptor_index;
00134    /** Count of attributes this method contains. */
00135     int attributes_count;
00136    /** Array of attribute_info objects for this method.
00137     * @see attribute_info
00138     */
00139     attribute_info attributes[];
00140    /** List of Instructions constructed when the method is parsed.
00141     * @see ClassFile@parse
00142     * @see ClassFile@parseMethod
00143     * @see Instruction
00144     */
00145     Instruction instructions;
00146    /** Control Flow Graph constructed when the method is parsed.
00147     * @see ClassFile@parse
00148     * @see CFG
00149     */
00150     public CFG cfg;
00151 
00152     ca.mcgill.sable.soot.SootMethod jmethod;
00153 
00154     ca.mcgill.sable.util.List instructionList;
00155 
00156    /** Locates and returns the code attribute for this method.
00157     * @return the single code attribute, or null if not found.
00158     * @see Code_attribute
00159     */
00160     Code_attribute locate_code_attribute() {
00161       attribute_info ai;
00162       int i;
00163 
00164       for (i=0; i<attributes_count; i++) {
00165          ai = attributes[i];
00166          if (ai instanceof Code_attribute)
00167             return (Code_attribute)ai;
00168       }
00169       return null;
00170    }   
00171    /** Displays this method, printing a prototype followed by list of Instructions.
00172     * @param constant_pool the constant_pool for this class.
00173     * @see prototype
00174     * @see ByteCode#showCode
00175     */
00176     void print(cp_info constant_pool[]) {
00177       System.out.println(prototype(constant_pool));
00178       ByteCode.showCode(instructions,constant_pool);
00179    }   
00180    /** Returns the prototype of this field.
00181     * @param constant_pool the constant_pool for this class.
00182     * @return the prototype (access + return + name + parameters) of this method.
00183     */
00184     String prototype(cp_info constant_pool[]) {
00185       String access,rt,name,params;
00186       Code_attribute c = locate_code_attribute();
00187 
00188       access = ClassFile.access_string(access_flags," ");
00189       rt = ClassFile.parseMethodDesc_return(cp_info.getTypeDescr(constant_pool,
00190                                                                  descriptor_index));
00191       name = toName(constant_pool);
00192       params = ClassFile.parseMethodDesc_params(cp_info.
00193                                                 getTypeDescr(constant_pool,
00194                                                              descriptor_index));
00195       if (access.length()>0)
00196          return access + " " + rt + " " + name + "(" + params + ")";
00197       return rt + " " + name + "(" + params + ")";
00198    }   
00199    /** Returns the name of this method.
00200     * @param constant_pool the constant_pool for this class.
00201     * @return the name of this method.
00202     */
00203     String toName(cp_info constant_pool[]) {
00204       CONSTANT_Utf8_info ci;
00205       ci = (CONSTANT_Utf8_info)(constant_pool[name_index]);
00206       return ci.convert();
00207    }   
00208 }

Generated at Thu Feb 7 06:50:20 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001