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