04344fb874fc89b55d557831dbb6d83a99623371
[cacao.git] / src / vmcore / references.h
1 /* src/vmcore/references.h - references to classes/fields/methods
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    $Id: references.h 7246 2007-01-29 18:49:05Z twisti $
26
27 */
28
29 #ifndef _REFERENCES_H_
30 #define _REFERENCES_H_
31
32 /* forward typedefs ***********************************************************/
33
34 typedef struct constant_classref constant_classref;
35 typedef struct constant_FMIref   constant_FMIref;
36
37
38 /* constant_classref **********************************************************/
39
40 struct constant_classref {
41         void             *pseudo_vftbl; /* for distinguishing it from classinfo   */
42         struct classinfo *referer;    /* class containing the reference           */
43         struct utf       *name;       /* name of the class refered to             */
44 };
45
46
47 /* classref_or_classinfo ******************************************************/
48
49 typedef union classref_or_classinfo {
50         constant_classref *ref;       /* a symbolic class reference               */
51         struct classinfo  *cls;       /* an already loaded class                  */
52         void              *any;       /* used for general access (x != NULL,...)  */
53 } classref_or_classinfo;
54
55
56 /* parseddesc *****************************************************************/
57
58 typedef union parseddesc {
59         struct typedesc   *fd;        /* parsed field descriptor                  */
60         struct methoddesc *md;        /* parsed method descriptor                 */
61         void              *any;       /* used for simple test against NULL        */
62 } parseddesc;
63
64
65 #include "config.h"
66 #include "vm/types.h"
67
68 #include "vm/global.h"
69
70 #include "vmcore/class.h"
71 #include "vmcore/descriptor.h"
72 #include "vmcore/field.h"
73 #include "vmcore/method.h"
74 #include "vmcore/utf8.h"
75
76
77 /*----------------------------------------------------------------------------*/
78 /* References                                                                 */
79 /*                                                                            */
80 /* This header files defines the following types used for references to       */
81 /* classes/methods/fields and descriptors:                                    */
82 /*                                                                            */
83 /*     classinfo *                a loaded class                              */
84 /*     constant_classref          a symbolic reference                        */
85 /*     classref_or_classinfo      a loaded class or a symbolic reference      */
86 /*                                                                            */
87 /*     constant_FMIref            a symb. ref. to a field/method/intf.method  */
88 /*                                                                            */
89 /*     typedesc *                 describes a field type                      */
90 /*     methoddesc *               descrives a method type                     */
91 /*     parseddesc                 describes a field type or a method type     */
92 /*----------------------------------------------------------------------------*/
93
94 /* structs ********************************************************************/
95
96 /* constant_FMIref ************************************************************/
97
98 struct constant_FMIref{     /* Fieldref, Methodref and InterfaceMethodref     */
99         union {
100                 s4                 index;     /* used only within the loader          */
101                 constant_classref *classref;  /* class having this field/meth./intfm. */
102                 fieldinfo         *field;     /* resolved field                       */
103                 methodinfo        *method;    /* resolved method                      */
104         } p;
105         utf       *name;        /* field/method/interfacemethod name              */
106         utf       *descriptor;  /* field/method/intfmeth. type descriptor string  */
107         parseddesc parseddesc;  /* parsed descriptor                              */
108 };
109
110
111 /* macros *********************************************************************/
112
113 /* a value that never occurrs in classinfo.header.vftbl                       */
114 #define CLASSREF_PSEUDO_VFTBL ((void *) 1)
115
116 /* macro for testing if a classref_or_classinfo is a classref                 */
117 /* `reforinfo` is only evaluated once                                         */
118 #define IS_CLASSREF(reforinfo)  \
119         ((reforinfo).ref->pseudo_vftbl == CLASSREF_PSEUDO_VFTBL)
120
121 /* macro for testing if a constant_FMIref has been resolved                   */
122 /* `fmiref` is only evaluated once                                            */
123 #define IS_FMIREF_RESOLVED(fmiref)  \
124         ((fmiref)->p.classref->pseudo_vftbl != CLASSREF_PSEUDO_VFTBL)
125
126 /* the same as IS_CLASSREF, but also check against NULL */
127 #define IS_XCLASSREF(reforinfo)  \
128         ((reforinfo).any && IS_CLASSREF(reforinfo))
129
130 /* macro for casting a classref/classinfo * to a classref_or_classinfo        */
131 #define CLASSREF_OR_CLASSINFO(value) \
132         (*((classref_or_classinfo *)(&(value))))
133
134 /* macro for accessing the name of a classref/classinfo                       */
135 #define CLASSREF_OR_CLASSINFO_NAME(value) \
136         (IS_CLASSREF(value) ? (value).ref->name : (value).cls->name)
137
138 /* macro for accessing the class name of a method reference                   */
139 #define METHODREF_CLASSNAME(fmiref) \
140         (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.method->class->name \
141                                                                 : (fmiref)->p.classref->name)
142
143 /* macro for accessing the class name of a method reference                   */
144 #define FIELDREF_CLASSNAME(fmiref) \
145         (IS_FMIREF_RESOLVED(fmiref) ? (fmiref)->p.field->class->name \
146                                                                 : (fmiref)->p.classref->name)
147
148 /* initialize a constant_classref with referer `ref` and name `classname`     */
149
150 #define CLASSREF_INIT(c,ref,classname) \
151     do { \
152         (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL; \
153         (c).referer = (ref); \
154         (c).name = (classname); \
155     } while (0)
156
157 #endif /* _REFERENCES_H_ */
158
159 /*
160  * These are local overrides for various environment variables in Emacs.
161  * Please do not remove this and leave it at the end of the file, where
162  * Emacs will automagically detect them.
163  * ---------------------------------------------------------------------
164  * Local variables:
165  * mode: c
166  * indent-tabs-mode: t
167  * c-basic-offset: 4
168  * tab-width: 4
169  * End:
170  * vim:noexpandtab:sw=4:ts=4:
171  */
172