1 /* src/vm/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/class.hpp"
65 #include "vm/descriptor.h"
66 #include "vm/field.hpp"
67 #include "vm/global.h"
68 #include "vm/method.h"
72 /*----------------------------------------------------------------------------*/
75 /* This header files defines the following types used for references to */
76 /* classes/methods/fields and descriptors: */
78 /* classinfo * a loaded class */
79 /* constant_classref a symbolic reference */
80 /* classref_or_classinfo a loaded class or a symbolic reference */
82 /* constant_FMIref a symb. ref. to a field/method/intf.method */
84 /* typedesc * describes a field type */
85 /* methoddesc * descrives a method type */
86 /* parseddesc describes a field type or a method type */
87 /*----------------------------------------------------------------------------*/
89 /* structs ********************************************************************/
91 /* constant_FMIref ************************************************************/
93 struct constant_FMIref{ /* Fieldref, Methodref and InterfaceMethodref */
95 s4 index; /* used only within the loader */
96 constant_classref *classref; /* class having this field/meth./intfm. */
97 fieldinfo *field; /* resolved field */
98 methodinfo *method; /* resolved method */
100 utf *name; /* field/method/interfacemethod name */
101 utf *descriptor; /* field/method/intfmeth. type descriptor string */
102 parseddesc_t parseddesc; /* parsed descriptor */
106 /* macros *********************************************************************/
108 /* a value that never occurrs in classinfo.header.vftbl */
109 #define CLASSREF_PSEUDO_VFTBL ((void *) 1)
111 /* macro for testing if a classref_or_classinfo is a classref */
112 /* `reforinfo` is only evaluated once */
113 #define IS_CLASSREF(reforinfo) \
114 ((reforinfo).ref->pseudo_vftbl == CLASSREF_PSEUDO_VFTBL)
116 /* macro for testing if a constant_FMIref has been resolved */
117 /* `fmiref` is only evaluated once */
118 #define IS_FMIREF_RESOLVED(fmiref) \
119 ((fmiref)->p.classref->pseudo_vftbl != CLASSREF_PSEUDO_VFTBL)
121 /* the same as IS_CLASSREF, but also check against NULL */
122 #define IS_XCLASSREF(reforinfo) \
123 ((reforinfo).any && IS_CLASSREF(reforinfo))
125 /* macro for casting a classref/classinfo * to a classref_or_classinfo */
126 #define CLASSREF_OR_CLASSINFO(value) \
127 (*((classref_or_classinfo *)(&(value))))
129 /* macro for accessing the name of a classref/classinfo */
130 #define CLASSREF_OR_CLASSINFO_NAME(value) \
131 (IS_CLASSREF(value) ? (value).ref->name : (value).cls->name)
133 /* macro for accessing the class name of a method reference */
134 #define METHODREF_CLASSNAME(fmiref) \
135 (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.method->clazz->name \
136 : (fmiref)->p.classref->name)
138 /* macro for accessing the class name of a field reference */
139 #define FIELDREF_CLASSNAME(fmiref) \
140 (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.field->clazz->name \
141 : (fmiref)->p.classref->name)
143 /* initialize a constant_classref with referer `ref` and name `classname` */
145 #define CLASSREF_INIT(c,ref,classname) \
147 (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL; \
148 (c).referer = (ref); \
149 (c).name = (classname); \
152 #endif /* _REFERENCES_H_ */
155 * These are local overrides for various environment variables in Emacs.
156 * Please do not remove this and leave it at the end of the file, where
157 * Emacs will automagically detect them.
158 * ---------------------------------------------------------------------
161 * indent-tabs-mode: t
165 * vim:noexpandtab:sw=4:ts=4: