* merged default branch into jitcache-arm-x86 branch
[cacao.git] / src / vm / references.h
1 /* src/vm/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/class.hpp"
65 #include "vm/descriptor.h"
66 #include "vm/field.hpp"
67 #include "vm/global.h"
68 #include "vm/method.h"
69 #include "vm/utf8.h"
70
71
72 /*----------------------------------------------------------------------------*/
73 /* References                                                                 */
74 /*                                                                            */
75 /* This header files defines the following types used for references to       */
76 /* classes/methods/fields and descriptors:                                    */
77 /*                                                                            */
78 /*     classinfo *                a loaded class                              */
79 /*     constant_classref          a symbolic reference                        */
80 /*     classref_or_classinfo      a loaded class or a symbolic reference      */
81 /*                                                                            */
82 /*     constant_FMIref            a symb. ref. to a field/method/intf.method  */
83 /*                                                                            */
84 /*     typedesc *                 describes a field type                      */
85 /*     methoddesc *               descrives a method type                     */
86 /*     parseddesc                 describes a field type or a method type     */
87 /*----------------------------------------------------------------------------*/
88
89 /* structs ********************************************************************/
90
91 /* constant_FMIref ************************************************************/
92
93 struct constant_FMIref{      /* Fieldref, Methodref and InterfaceMethodref    */
94         union {
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                      */
99         } p;
100         utf         *name;       /* field/method/interfacemethod name             */
101         utf         *descriptor; /* field/method/intfmeth. type descriptor string */
102         parseddesc_t parseddesc; /* parsed descriptor                             */
103 };
104
105
106 /* macros *********************************************************************/
107
108 /* a value that never occurrs in classinfo.header.vftbl                       */
109 #define CLASSREF_PSEUDO_VFTBL ((void *) 1)
110
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)
115
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)
120
121 /* the same as IS_CLASSREF, but also check against NULL */
122 #define IS_XCLASSREF(reforinfo)  \
123         ((reforinfo).any && IS_CLASSREF(reforinfo))
124
125 /* macro for casting a classref/classinfo * to a classref_or_classinfo        */
126 #define CLASSREF_OR_CLASSINFO(value) \
127         (*((classref_or_classinfo *)(&(value))))
128
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)
132
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)
137
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)
142
143 /* initialize a constant_classref with referer `ref` and name `classname`     */
144
145 #define CLASSREF_INIT(c,ref,classname) \
146     do { \
147         (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL; \
148         (c).referer = (ref); \
149         (c).name = (classname); \
150     } while (0)
151
152 #endif /* _REFERENCES_H_ */
153
154 /*
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  * ---------------------------------------------------------------------
159  * Local variables:
160  * mode: c
161  * indent-tabs-mode: t
162  * c-basic-offset: 4
163  * tab-width: 4
164  * End:
165  * vim:noexpandtab:sw=4:ts=4:
166  */
167