1 /* src/vmcore/references.h - references to classes/fields/methods
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #ifndef _REFERENCES_H_
26 #define _REFERENCES_H_
28 /* forward typedefs ***********************************************************/
30 typedef struct constant_classref constant_classref;
31 typedef struct constant_FMIref constant_FMIref;
34 /* constant_classref **********************************************************/
36 struct constant_classref {
37 void *pseudo_vftbl; /* for distinguishing it from classinfo */
38 struct classinfo *referer; /* class containing the reference */
39 struct utf *name; /* name of the class refered to */
43 /* classref_or_classinfo ******************************************************/
45 typedef union classref_or_classinfo {
46 constant_classref *ref; /* a symbolic class reference */
47 struct classinfo *cls; /* an already loaded class */
48 void *any; /* used for general access (x != NULL,...) */
49 } classref_or_classinfo;
52 /* parseddesc_t ***************************************************************/
54 typedef union parseddesc {
55 struct typedesc *fd; /* parsed field descriptor */
56 struct methoddesc *md; /* parsed method descriptor */
57 void *any; /* used for simple test against NULL */
64 #include "vm/global.h"
66 #include "vmcore/class.h"
67 #include "vmcore/descriptor.h"
68 #include "vmcore/field.h"
69 #include "vmcore/method.h"
70 #include "vmcore/utf8.h"
73 /*----------------------------------------------------------------------------*/
76 /* This header files defines the following types used for references to */
77 /* classes/methods/fields and descriptors: */
79 /* classinfo * a loaded class */
80 /* constant_classref a symbolic reference */
81 /* classref_or_classinfo a loaded class or a symbolic reference */
83 /* constant_FMIref a symb. ref. to a field/method/intf.method */
85 /* typedesc * describes a field type */
86 /* methoddesc * descrives a method type */
87 /* parseddesc describes a field type or a method type */
88 /*----------------------------------------------------------------------------*/
90 /* structs ********************************************************************/
92 /* constant_FMIref ************************************************************/
94 struct constant_FMIref{ /* Fieldref, Methodref and InterfaceMethodref */
96 s4 index; /* used only within the loader */
97 constant_classref *classref; /* class having this field/meth./intfm. */
98 fieldinfo *field; /* resolved field */
99 methodinfo *method; /* resolved method */
101 utf *name; /* field/method/interfacemethod name */
102 utf *descriptor; /* field/method/intfmeth. type descriptor string */
103 parseddesc_t parseddesc; /* parsed descriptor */
107 /* macros *********************************************************************/
109 /* a value that never occurrs in classinfo.header.vftbl */
110 #define CLASSREF_PSEUDO_VFTBL ((void *) 1)
112 /* macro for testing if a classref_or_classinfo is a classref */
113 /* `reforinfo` is only evaluated once */
114 #define IS_CLASSREF(reforinfo) \
115 ((reforinfo).ref->pseudo_vftbl == CLASSREF_PSEUDO_VFTBL)
117 /* macro for testing if a constant_FMIref has been resolved */
118 /* `fmiref` is only evaluated once */
119 #define IS_FMIREF_RESOLVED(fmiref) \
120 ((fmiref)->p.classref->pseudo_vftbl != CLASSREF_PSEUDO_VFTBL)
122 /* the same as IS_CLASSREF, but also check against NULL */
123 #define IS_XCLASSREF(reforinfo) \
124 ((reforinfo).any && IS_CLASSREF(reforinfo))
126 /* macro for casting a classref/classinfo * to a classref_or_classinfo */
127 #define CLASSREF_OR_CLASSINFO(value) \
128 (*((classref_or_classinfo *)(&(value))))
130 /* macro for accessing the name of a classref/classinfo */
131 #define CLASSREF_OR_CLASSINFO_NAME(value) \
132 (IS_CLASSREF(value) ? (value).ref->name : (value).cls->name)
134 /* macro for accessing the class name of a method reference */
135 #define METHODREF_CLASSNAME(fmiref) \
136 (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.method->clazz->name \
137 : (fmiref)->p.classref->name)
139 /* macro for accessing the class name of a method reference */
140 #define FIELDREF_CLASSNAME(fmiref) \
141 (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.field->clazz->name \
142 : (fmiref)->p.classref->name)
144 /* initialize a constant_classref with referer `ref` and name `classname` */
146 #define CLASSREF_INIT(c,ref,classname) \
148 (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL; \
149 (c).referer = (ref); \
150 (c).name = (classname); \
153 #endif /* _REFERENCES_H_ */
156 * These are local overrides for various environment variables in Emacs.
157 * Please do not remove this and leave it at the end of the file, where
158 * Emacs will automagically detect them.
159 * ---------------------------------------------------------------------
162 * indent-tabs-mode: t
166 * vim:noexpandtab:sw=4:ts=4: