1 /* src/vmcore/references.h - references to classes/fields/methods
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #ifndef _REFERENCES_H_
28 #define _REFERENCES_H_
30 /* forward typedefs ***********************************************************/
32 typedef struct constant_classref constant_classref;
33 typedef struct constant_FMIref constant_FMIref;
36 /* constant_classref **********************************************************/
38 struct constant_classref {
39 void *pseudo_vftbl; /* for distinguishing it from classinfo */
40 struct classinfo *referer; /* class containing the reference */
41 struct utf *name; /* name of the class refered to */
45 /* classref_or_classinfo ******************************************************/
47 typedef union classref_or_classinfo {
48 constant_classref *ref; /* a symbolic class reference */
49 struct classinfo *cls; /* an already loaded class */
50 void *any; /* used for general access (x != NULL,...) */
51 } classref_or_classinfo;
54 /* parseddesc *****************************************************************/
56 typedef union parseddesc {
57 struct typedesc *fd; /* parsed field descriptor */
58 struct methoddesc *md; /* parsed method descriptor */
59 void *any; /* used for simple test against NULL */
66 #include "vm/global.h"
68 #include "vmcore/class.h"
69 #include "vmcore/descriptor.h"
70 #include "vmcore/field.h"
71 #include "vmcore/method.h"
72 #include "vmcore/utf8.h"
75 /*----------------------------------------------------------------------------*/
78 /* This header files defines the following types used for references to */
79 /* classes/methods/fields and descriptors: */
81 /* classinfo * a loaded class */
82 /* constant_classref a symbolic reference */
83 /* classref_or_classinfo a loaded class or a symbolic reference */
85 /* constant_FMIref a symb. ref. to a field/method/intf.method */
87 /* typedesc * describes a field type */
88 /* methoddesc * descrives a method type */
89 /* parseddesc describes a field type or a method type */
90 /*----------------------------------------------------------------------------*/
92 /* structs ********************************************************************/
94 /* constant_FMIref ************************************************************/
96 struct constant_FMIref{ /* Fieldref, Methodref and InterfaceMethodref */
98 s4 index; /* used only within the loader */
99 constant_classref *classref; /* class having this field/meth./intfm. */
100 fieldinfo *field; /* resolved field */
101 methodinfo *method; /* resolved method */
103 utf *name; /* field/method/interfacemethod name */
104 utf *descriptor; /* field/method/intfmeth. type descriptor string */
105 parseddesc parseddesc; /* parsed descriptor */
109 /* macros *********************************************************************/
111 /* a value that never occurrs in classinfo.header.vftbl */
112 #define CLASSREF_PSEUDO_VFTBL ((void *) 1)
114 /* macro for testing if a classref_or_classinfo is a classref */
115 /* `reforinfo` is only evaluated once */
116 #define IS_CLASSREF(reforinfo) \
117 ((reforinfo).ref->pseudo_vftbl == CLASSREF_PSEUDO_VFTBL)
119 /* macro for testing if a constant_FMIref has been resolved */
120 /* `fmiref` is only evaluated once */
121 #define IS_FMIREF_RESOLVED(fmiref) \
122 ((fmiref)->p.classref->pseudo_vftbl != CLASSREF_PSEUDO_VFTBL)
124 /* the same as IS_CLASSREF, but also check against NULL */
125 #define IS_XCLASSREF(reforinfo) \
126 ((reforinfo).any && IS_CLASSREF(reforinfo))
128 /* macro for casting a classref/classinfo * to a classref_or_classinfo */
129 #define CLASSREF_OR_CLASSINFO(value) \
130 (*((classref_or_classinfo *)(&(value))))
132 /* macro for accessing the name of a classref/classinfo */
133 #define CLASSREF_OR_CLASSINFO_NAME(value) \
134 (IS_CLASSREF(value) ? (value).ref->name : (value).cls->name)
136 /* macro for accessing the class name of a method reference */
137 #define METHODREF_CLASSNAME(fmiref) \
138 (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.method->class->name \
139 : (fmiref)->p.classref->name)
141 /* macro for accessing the class name of a method reference */
142 #define FIELDREF_CLASSNAME(fmiref) \
143 (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.field->class->name \
144 : (fmiref)->p.classref->name)
146 /* initialize a constant_classref with referer `ref` and name `classname` */
148 #define CLASSREF_INIT(c,ref,classname) \
150 (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL; \
151 (c).referer = (ref); \
152 (c).name = (classname); \
155 #endif /* _REFERENCES_H_ */
158 * These are local overrides for various environment variables in Emacs.
159 * Please do not remove this and leave it at the end of the file, where
160 * Emacs will automagically detect them.
161 * ---------------------------------------------------------------------
164 * indent-tabs-mode: t
168 * vim:noexpandtab:sw=4:ts=4: