6ac233618293bbebde516c81cc4574a9df1fe234
[cacao.git] / src / vmcore / references.h
1 /* src/vmcore/references.h - references to classes/fields/methods
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25 #ifndef _REFERENCES_H_
26 #define _REFERENCES_H_
27
28 /* forward typedefs ***********************************************************/
29
30 typedef struct constant_classref constant_classref;
31 typedef struct constant_FMIref   constant_FMIref;
32
33
34 /* constant_classref **********************************************************/
35
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             */
40 };
41
42
43 /* classref_or_classinfo ******************************************************/
44
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;
50
51
52 /* parseddesc_t ***************************************************************/
53
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        */
58 } parseddesc_t;
59
60
61 #include "config.h"
62 #include "vm/types.h"
63
64 #include "vm/global.h"
65
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"
71
72
73 /*----------------------------------------------------------------------------*/
74 /* References                                                                 */
75 /*                                                                            */
76 /* This header files defines the following types used for references to       */
77 /* classes/methods/fields and descriptors:                                    */
78 /*                                                                            */
79 /*     classinfo *                a loaded class                              */
80 /*     constant_classref          a symbolic reference                        */
81 /*     classref_or_classinfo      a loaded class or a symbolic reference      */
82 /*                                                                            */
83 /*     constant_FMIref            a symb. ref. to a field/method/intf.method  */
84 /*                                                                            */
85 /*     typedesc *                 describes a field type                      */
86 /*     methoddesc *               descrives a method type                     */
87 /*     parseddesc                 describes a field type or a method type     */
88 /*----------------------------------------------------------------------------*/
89
90 /* structs ********************************************************************/
91
92 /* constant_FMIref ************************************************************/
93
94 struct constant_FMIref{      /* Fieldref, Methodref and InterfaceMethodref    */
95         union {
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                      */
100         } p;
101         utf         *name;       /* field/method/interfacemethod name             */
102         utf         *descriptor; /* field/method/intfmeth. type descriptor string */
103         parseddesc_t parseddesc; /* parsed descriptor                             */
104 };
105
106
107 /* macros *********************************************************************/
108
109 /* a value that never occurrs in classinfo.header.vftbl                       */
110 #define CLASSREF_PSEUDO_VFTBL ((void *) 1)
111
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)
116
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)
121
122 /* the same as IS_CLASSREF, but also check against NULL */
123 #define IS_XCLASSREF(reforinfo)  \
124         ((reforinfo).any && IS_CLASSREF(reforinfo))
125
126 /* macro for casting a classref/classinfo * to a classref_or_classinfo        */
127 #define CLASSREF_OR_CLASSINFO(value) \
128         (*((classref_or_classinfo *)(&(value))))
129
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)
133
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)
138
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)
143
144 /* initialize a constant_classref with referer `ref` and name `classname`     */
145
146 #define CLASSREF_INIT(c,ref,classname) \
147     do { \
148         (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL; \
149         (c).referer = (ref); \
150         (c).name = (classname); \
151     } while (0)
152
153 #endif /* _REFERENCES_H_ */
154
155 /*
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  * ---------------------------------------------------------------------
160  * Local variables:
161  * mode: c
162  * indent-tabs-mode: t
163  * c-basic-offset: 4
164  * tab-width: 4
165  * End:
166  * vim:noexpandtab:sw=4:ts=4:
167  */
168