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