extended type system to use symbolic references
[cacao.git] / src / vm / references.h
1 /* vm/references.h - references to classes/fields/methods
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Edwin Steiner
28
29    Changes:
30
31    $Id: references.h 2181 2005-04-01 16:53:33Z 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 /* References                                                                 */
43 /*                                                                            */
44 /* This header files defines the following types used for references to       */
45 /* classes/methods/fields and descriptors:                                    */
46 /*                                                                            */
47 /*     classinfo *                a loaded class                              */
48 /*     constant_classref          a symbolic reference                        */
49 /*     classref_or_classinfo      a loaded class or a symbolic reference      */
50 /*                                                                            */
51 /*     constant_FMIref            a symb. ref. to a field/method/intf.method  */
52 /*                                                                            */
53 /*     typedesc *                 describes a field type                      */
54 /*     methoddesc *               descrives a method type                     */
55 /*     parseddesc                 describes a field type or a method type     */
56 /*----------------------------------------------------------------------------*/
57
58 /* forward declarations *******************************************************/
59
60 typedef struct classinfo classinfo; 
61 typedef struct typedesc typedesc;
62 typedef struct methoddesc methoddesc;
63
64 /* structs ********************************************************************/
65
66 /* constant_classref **********************************************************/
67
68 typedef struct constant_classref {
69         void      *pseudo_vftbl;      /* for distinguishing it from classinfo     */
70         classinfo *referer;           /* class containing the reference           */
71         utf       *name;              /* name of the class refered to             */
72 } constant_classref;
73
74 /* classref_or_classinfo ******************************************************/
75
76 typedef union {
77         constant_classref *ref;       /* a symbolic class reference               */
78         classinfo         *cls;       /* an already loaded class                  */
79         void              *any;       /* used for general access (x != NULL,...)  */
80 } classref_or_classinfo;
81
82 /* parseddesc *****************************************************************/
83
84 typedef union parseddesc {
85         typedesc          *fd;        /* parsed field descriptor                  */
86         methoddesc        *md;        /* parsed method descriptor                 */
87         void              *any;       /* used for simple test against NULL        */
88 } parseddesc;
89
90 /* constant_FMIref ************************************************************/
91
92 typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
93         classinfo *class;       /* class containing this field/method/intfmeth.   */ /* XXX remove */
94         constant_classref *classref;  /* class containing this field/meth./intfm. */
95         utf       *name;        /* field/method/interfacemethod name              */
96         utf       *descriptor;  /* field/method/intfmeth. type descriptor string  */
97         parseddesc parseddesc;  /* parsed descriptor                              */
98 } constant_FMIref;
99
100 /* macros *********************************************************************/
101
102 /* a value that never occurrs in classinfo.header.vftbl                       */
103 #define CLASSREF_PSEUDO_VFTBL ((void *) 1)
104
105 /* macro for testing if a classref_or_classinfo is a classref                 */
106 /* `reforinfo` is only evaluated once                                         */
107 #define IS_CLASSREF(reforinfo)  \
108         ((reforinfo).ref->pseudo_vftbl == CLASSREF_PSEUDO_VFTBL)
109
110 /* macro for casting a classref/classinfo * to a classref_or_classinfo        */
111 #define CLASSREF_OR_CLASSINFO(value) \
112         (*((classref_or_classinfo *)(&(value))))
113
114 /* initialize a constant_classref with referer `ref` and name `classname`     */
115 #define CLASSREF_INIT(c,ref,classname)                          \
116                         do { (c).pseudo_vftbl = CLASSREF_PSEUDO_VFTBL;      \
117                                  (c).referer = (ref);                           \
118                                  (c).name = (classname); } while (0)
119
120 #endif /* _REFERENCES_H_ */
121
122 /*
123  * These are local overrides for various environment variables in Emacs.
124  * Please do not remove this and leave it at the end of the file, where
125  * Emacs will automagically detect them.
126  * ---------------------------------------------------------------------
127  * Local variables:
128  * mode: c
129  * indent-tabs-mode: t
130  * c-basic-offset: 4
131  * tab-width: 4
132  * End:
133  * vim:noexpandtab:sw=4:ts=4:
134  */
135