Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

attribute.c

Go to the documentation of this file.
00001 /*!
00002  * @file attribute.c
00003  *
00004  * @brief Manipulate ClassFile attributes.
00005  *
00006  *
00007  * @section Control
00008  *
00009  * \$URL: https://svn.apache.org/path/name/attribute.c $ \$Id: attribute.c 0 09/28/2005 dlydick $
00010  *
00011  * Copyright 2005 The Apache Software Foundation
00012  * or its licensors, as applicable.
00013  *
00014  * Licensed under the Apache License, Version 2.0 ("the License");
00015  * you may not use this file except in compliance with the License.
00016  * You may obtain a copy of the License at
00017  *
00018  *     http://www.apache.org/licenses/LICENSE-2.0
00019  *
00020  * Unless required by applicable law or agreed to in writing,
00021  * software distributed under the License is distributed on an
00022  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
00023  * either express or implied.
00024  *
00025  * See the License for the specific language governing permissions
00026  * and limitations under the License.
00027  *
00028  * @version \$LastChangedRevision: 0 $
00029  *
00030  * @date \$LastChangedDate: 09/28/2005 $
00031  *
00032  * @author \$LastChangedBy: dlydick $
00033  *         Original code contributed by Daniel Lydick on 09/28/2005.
00034  *
00035  * @section Reference
00036  *
00037  */
00038 
00039 #include "arch.h"
00040 ARCH_COPYRIGHT_APACHE(attribute, c, "$URL: https://svn.apache.org/path/name/attribute.c $ $Id: attribute.c 0 09/28/2005 dlydick $");
00041 
00042 
00043 #include "jvmcfg.h"
00044 #include "cfmacros.h"
00045 #include "classfile.h"
00046 #include "jvm.h"
00047 #include "linkage.h"
00048 #include "utf.h"
00049 
00050 
00051 /*!
00052  * @brief Locate an attribute by constant_pool entry for a field,
00053  * method, or class.  The attribute pointer passed in is valid for
00054  * all three types.
00055  *
00056  *
00057  * @param  pcfs     Pointer to ClassFile area
00058  *
00059  * @param  acount   Attribute count from field, method, or class.
00060  *
00061  * @param  patr     Attribute array for a field, method, or class.
00062  *
00063  * @param  atrname  UTF8 constant_pool entry of name of attribute in
00064  *                    field, method, or class.
00065  *
00066  *
00067  * @returns Attribute table index ofthie attribute or
00068  *        @link #jvm_attribute_index_bad jvm_attribute_index_bad@endlink
00069  *          if not found.
00070  *
00071  */
00072 static jvm_attribute_index attribute_name_common_find(
00073                                ClassFile           *pcfs,
00074                                u2                   acount,
00075                                attribute_info_dup **patr,
00076                                cp_info_dup         *atrname)
00077 {
00078     /* Search for match of attribute array against requested name */
00079     jvm_attribute_index atridx;
00080 
00081     for (atridx = 0; atridx < acount; atridx++)
00082     {
00083         if (0 == utf_pcfs_strcmp(PTR_THIS_CP_Utf8(atrname),
00084                                  pcfs,
00085                                  atridx))
00086         {
00087             return(atridx);
00088         }
00089     }
00090 
00091     /* Not found */
00092     return(jvm_attribute_index_bad);
00093 
00094 } /* END of attribute_name_common_find() */
00095 
00096 
00097 /*!
00098  * @brief Locate an attribute by enumeration for a field, method,
00099  * or class.
00100  *
00101  * The attribute pointer passed in is valid for all three types.
00102  *
00103  *
00104  * @param  pcfs     Pointer to ClassFile area
00105  *
00106  * @param  acount   Attribute count from field, method, or class.
00107  *
00108  * @param  patr     Attribute array for a field, method, or class.
00109  *
00110  * @param  atrenum  Attribute enumeration (from
00111  *                    @link jvm/src/classfile.h classfile.h@endlink)
00112  *                    for attribute of field, method, or class to locate
00113  *                    (e.g. LOCAL_CODE_ATTRIBUTE).
00114  *
00115  *
00116  * @returns Attribute table index ofthie attribute or
00117  *        @link #jvm_attribute_index_bad jvm_attribute_index_bad@endlink
00118  *          if not found.
00119  *
00120  */
00121 static jvm_attribute_index attribute_enum_common_find(
00122                                ClassFile                 *pcfs,
00123                                u2                         acount,
00124                                attribute_info_dup       **patr,
00125                                classfile_attribute_enum   atrenum)
00126 {
00127     /* Search for match of attribute array against requested enum */
00128     jvm_attribute_index atridx;
00129 
00130     for (atridx = 0; atridx < acount; atridx++)
00131     {
00132         if (atrenum ==
00133             cfattrib_atr2enum(pcfs,
00134                               patr[atridx]->ai.attribute_name_index))
00135         {
00136             return(atridx);
00137         }
00138     }
00139 
00140     /* Not found */
00141     return(jvm_attribute_index_bad);
00142 
00143 } /* END of attribute_enum_common_find() */
00144 
00145 
00146 /*!
00147  * @brief Locate by constant_pool entry the attribute_info index for an
00148  * attribute in a field attribute area.
00149  *
00150  *
00151  * @param  clsidx            Class index of class whose field is to be
00152  *                             searched for an attribute.
00153  *
00154  * @param  fldidx            Field index of field to search.
00155  *
00156  * @param  atrname           UTF8 constant_pool entry of name of
00157  *                             attribute name to locate.
00158  *
00159  *
00160  * @returns attribute table index of this attribute in field, or
00161  *        @link #jvm_attribute_index_bad jvm_attribute_index_bad@endlink
00162  *         if not found.
00163  *
00164  */
00165 jvm_attribute_index
00166     attribute_find_in_field_by_cp_entry(jvm_class_index  clsidx,
00167                                         jvm_field_index  fldidx,
00168                                         cp_info_dup     *atrname)
00169 {
00170     /* Prohibit invalid class parameter */
00171     if (jvm_class_index_null == clsidx)
00172     {
00173         return(jvm_attribute_index_bad);
00174     }
00175 
00176     /* Point to class structure, then look for attribute */
00177     ClassFile *pcfs = CLASS_OBJECT_LINKAGE(clsidx)->pcfs;
00178 
00179     /* Prohibit invalid field parameter */
00180     if (pcfs->fields_count <= fldidx)
00181     {
00182         return(jvm_attribute_index_bad);
00183     }
00184 
00185     return(
00186         attribute_name_common_find(pcfs,
00187                                  pcfs->fields[fldidx]->attributes_count,
00188                                    pcfs->fields[fldidx]->attributes,
00189                                    atrname));
00190 
00191 } /* END of attribute_find_in_field_by_cp_entry() */
00192 
00193 
00194 /*!
00195  * @brief Locate by enumeration the attribute_info index for an
00196  * attribute in a field attribute area.
00197  *
00198  *
00199  * @param  clsidx            Class index of class whose field is to be
00200  *                             searched for an attribute.
00201  *
00202  * @param  fldidx            Field index of field to search.
00203  *
00204  * @param  atrenum           @link #classfile_attribute_enum
00205                              LOCAL_xxxx_ATTRIBUTE@endlink enumeration of
00206  *                           attribute to locate.
00207  *
00208  * @returns attribute table index of this attribute in field, or
00209  *        @link #jvm_attribute_index_bad jvm_attribute_index_bad@endlink
00210  *          if not found.
00211  *
00212  */
00213 jvm_attribute_index
00214     attribute_find_in_field_by_enum(jvm_class_index          clsidx,
00215                                     jvm_field_index          fldidx,
00216                                     classfile_attribute_enum atrenum)
00217 {
00218     /* Prohibit invalid class parameter */
00219     if (jvm_class_index_null == clsidx)
00220     {
00221         return(jvm_attribute_index_bad);
00222     }
00223 
00224     /* Point to class structure, then look for attribute */
00225     ClassFile *pcfs = CLASS_OBJECT_LINKAGE(clsidx)->pcfs;
00226 
00227     /* Prohibit invalid field parameter */
00228     if (pcfs->fields_count <= fldidx)
00229     {
00230         return(jvm_attribute_index_bad);
00231     }
00232 
00233     return(attribute_enum_common_find(pcfs,
00234                                  pcfs->fields[fldidx]->attributes_count,
00235                                       pcfs->fields[fldidx]->attributes,
00236                                       atrenum));
00237 
00238 } /* END of attribute_find_in_field_by_enum() */
00239 
00240 
00241 /*!
00242  * @brief Locate by constant_pool entry the attribute_info index for
00243  * an attribute in a method attribute area.
00244  *
00245  *
00246  * @param  clsidx            Class index of class whose method is to be
00247  *                             searched for an attribute.
00248  *
00249  * @param  mthidx            Method index of method to search.
00250  *
00251  * @param  atrname           UTF8 constant_pool entry of name of
00252  *                             attribute name to locate.
00253  *
00254  * @returns attribute table index of this attribute in method, or
00255  *        @link #jvm_attribute_index_bad jvm_attribute_index_bad@endlink
00256  *          if not found.
00257  *
00258  */
00259 jvm_attribute_index
00260     attribute_find_in_method_by_cp_entry(jvm_class_index   clsidx,
00261                                          jvm_method_index  mthidx,
00262                                          cp_info_dup      *atrname)
00263 {
00264     /* Prohibit invalid class parameter */
00265     if (jvm_class_index_null == clsidx)
00266     {
00267         return(jvm_attribute_index_bad);
00268     }
00269 
00270     /* Point to class structure, then look for attribute */
00271     ClassFile *pcfs = CLASS_OBJECT_LINKAGE(clsidx)->pcfs;
00272 
00273     /* Prohibit invalid method parameter */
00274     if (pcfs->methods_count <= mthidx)
00275     {
00276         return(jvm_attribute_index_bad);
00277     }
00278 
00279     return(
00280         attribute_name_common_find(pcfs,
00281                                 pcfs->methods[mthidx]->attributes_count,
00282                                    pcfs->methods[mthidx]->attributes,
00283                                    atrname));
00284 
00285 } /* END of attribute_find_in_method_by_cp_entry() */
00286 
00287 
00288 /*!
00289  * @brief Locate by enumeration the attribute_info index for an
00290  * attribute in a method attribute area.
00291  *
00292  *
00293  * @param  clsidx            Class index of class whose method is to be
00294  *                             searched for an attribute.
00295  *
00296  * @param  mthidx            Method index of method to search.
00297  *
00298  * @param  atrenum           @link #classfile_attribute_enum
00299                              LOCAL_xxxx_ATTRIBUTE@endlink enumeration of
00300  *                           attribute to locate.
00301  *
00302  * @returns attribute table index of this attribute in method, or
00303  *        @link #jvm_attribute_index_bad jvm_attribute_index_bad@endlink
00304  *          if not found.
00305  *
00306  */
00307 jvm_attribute_index
00308     attribute_find_in_method_by_enum(jvm_class_index          clsidx,
00309                                      jvm_method_index         mthidx,
00310                                      classfile_attribute_enum atrenum)
00311 {
00312     /* Prohibit invalid class parameter */
00313     if (jvm_class_index_null == clsidx)
00314     {
00315         return(jvm_attribute_index_bad);
00316     }
00317 
00318     /* Point to class structure, then look for attribute */
00319     ClassFile *pcfs = CLASS_OBJECT_LINKAGE(clsidx)->pcfs;
00320 
00321     /* Prohibit invalid method parameter */
00322     if (pcfs->methods_count <= mthidx)
00323     {
00324         return(jvm_attribute_index_bad);
00325     }
00326 
00327     return(attribute_enum_common_find(pcfs,
00328                                 pcfs->methods[mthidx]->attributes_count,
00329                                       pcfs->methods[mthidx]->attributes,
00330                                       atrenum));
00331 
00332 } /* END of attribute_find_in_method_by_enum() */
00333 
00334 
00335 /*!
00336  * @brief Locate by constant_pool entry the attribute_info index for
00337  * an attribute in a class attribute area.
00338  *
00339  *
00340  * @param  clsidx            Class index of class be searched for an
00341  *                             attribute.
00342  *
00343  * @param  atrname           UTF8 constant_pool entry of name of
00344  *                             attribute name to locate.
00345  *
00346  * @returns attribute table index of this attribute in class, or
00347  *        @link #jvm_attribute_index_bad jvm_attribute_index_bad@endlink
00348  *          if not found.
00349  *
00350  */
00351 jvm_attribute_index
00352     attribute_find_in_class_by_cp_entry(jvm_class_index  clsidx,
00353                                         cp_info_dup     *atrname)
00354 {
00355     /* Prohibit invalid class parameter */
00356     if (jvm_class_index_null == clsidx)
00357     {
00358         return(jvm_attribute_index_bad);
00359     }
00360 
00361     /* Point to class structure, then look for attribute */
00362     ClassFile *pcfs = CLASS_OBJECT_LINKAGE(clsidx)->pcfs;
00363 
00364     return(
00365         attribute_name_common_find(pcfs,
00366                                    pcfs->attributes_count,
00367                                    pcfs->attributes,
00368                                    atrname));
00369 
00370 } /* END of attribute_find_in_method_by_cp_entry() */
00371 
00372 
00373 /*!
00374  * @brief Locate by enumeration the attribute_info index for
00375  * an attribute in a class attribute area.
00376  *
00377  *
00378  * @param  clsidx            Class index of class whose method is to be
00379  *                             searched for an attribute.
00380  *
00381  * @param  atrenum           @link #classfile_attribute_enum
00382                              LOCAL_xxxx_ATTRIBUTE@endlink enumeration of
00383  *                           attribute to locate.
00384  *
00385  * @returns attribute table index of this attribute in class, or
00386  *        @link #jvm_attribute_index_bad jvm_attribute_index_bad@endlink
00387  *          if not found.
00388  *
00389  */
00390 jvm_attribute_index
00391     attribute_find_in_class_by_enum(jvm_class_index          clsidx,
00392                                     classfile_attribute_enum atrenum)
00393 {
00394     /* Prohibit invalid class parameter */
00395     if (jvm_class_index_null == clsidx)
00396     {
00397         return(jvm_attribute_index_bad);
00398     }
00399 
00400     /* Point to class structure, then look for attribute */
00401     ClassFile *pcfs = CLASS_OBJECT_LINKAGE(clsidx)->pcfs;
00402 
00403     return(attribute_enum_common_find(pcfs,
00404                                       pcfs->attributes_count,
00405                                       pcfs->attributes,
00406                                       atrenum));
00407 
00408 } /* END of attribute_find_in_class_by_enum() */
00409 
00410 
00411 /* EOF */
00412 

Generated on Fri Sep 30 18:59:24 2005 by  doxygen 1.4.4