* configure.ac,
[cacao.git] / src / vmcore / field.c
1 /* src/vmcore/field.c - field functions
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: field.c 8132 2007-06-22 11:15:47Z twisti $
26
27 */
28
29
30 #include "config.h"
31
32 #include <assert.h>
33 #include <stdio.h>
34
35 #include "vm/types.h"
36
37 #include "vmcore/class.h"
38 #include "vmcore/field.h"
39 #include "vmcore/primitive.h"
40 #include "vmcore/references.h"
41 #include "vmcore/utf8.h"
42
43
44 /* field_get_type **************************************************************
45
46    Returns the type of the field as class.
47
48 *******************************************************************************/
49
50 classinfo *field_get_type(fieldinfo *f)
51 {
52         typedesc  *td;
53         utf       *u;
54         classinfo *c;
55
56         td = f->parseddesc;
57
58         if (td->type == TYPE_ADR) {
59                 assert(td->classref);
60
61                 u = td->classref->name;
62
63                 /* load the class of the field-type with the field's
64                    classloader */
65
66                 c = load_class_from_classloader(u, f->class->classloader);
67         }
68         else {
69                 c = primitive_class_get_by_type(td->decltype);
70         }
71
72         return c;
73 }
74
75
76 /* field_free ******************************************************************
77
78    Frees a fields' resources.
79
80 *******************************************************************************/
81
82 void field_free(fieldinfo *f)
83 {
84         /* empty */
85 }
86
87
88 /* field_printflags ************************************************************
89
90    (debugging only)
91
92 *******************************************************************************/
93
94 #if !defined(NDEBUG)
95 void field_printflags(fieldinfo *f)
96 {
97         if (f == NULL) {
98                 printf("NULL");
99                 return;
100         }
101
102         if (f->flags & ACC_PUBLIC)       printf(" PUBLIC");
103         if (f->flags & ACC_PRIVATE)      printf(" PRIVATE");
104         if (f->flags & ACC_PROTECTED)    printf(" PROTECTED");
105         if (f->flags & ACC_STATIC)       printf(" STATIC");
106         if (f->flags & ACC_FINAL)        printf(" FINAL");
107         if (f->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
108         if (f->flags & ACC_VOLATILE)     printf(" VOLATILE");
109         if (f->flags & ACC_TRANSIENT)    printf(" TRANSIENT");
110         if (f->flags & ACC_NATIVE)       printf(" NATIVE");
111         if (f->flags & ACC_INTERFACE)    printf(" INTERFACE");
112         if (f->flags & ACC_ABSTRACT)     printf(" ABSTRACT");
113 }
114 #endif
115
116
117 /* field_print *****************************************************************
118
119    (debugging only)
120
121 *******************************************************************************/
122
123 #if !defined(NDEBUG)
124 void field_print(fieldinfo *f)
125 {
126         if (f == NULL) {
127                 printf("(fieldinfo*)NULL");
128                 return;
129         }
130
131         utf_display_printable_ascii_classname(f->class->name);
132         printf(".");
133         utf_display_printable_ascii(f->name);
134         printf(" ");
135         utf_display_printable_ascii(f->descriptor);     
136
137         field_printflags(f);
138 }
139 #endif
140
141
142 /* field_println ***************************************************************
143
144    (debugging only)
145
146 *******************************************************************************/
147
148 #if !defined(NDEBUG)
149 void field_println(fieldinfo *f)
150 {
151         field_print(f);
152         printf("\n");
153 }
154 #endif
155
156 /* field_fieldref_print ********************************************************
157
158    (debugging only)
159
160 *******************************************************************************/
161
162 #if !defined(NDEBUG)
163 void field_fieldref_print(constant_FMIref *fr)
164 {
165         if (fr == NULL) {
166                 printf("(constant_FMIref *)NULL");
167                 return;
168         }
169
170         if (IS_FMIREF_RESOLVED(fr)) {
171                 printf("<field> ");
172                 field_print(fr->p.field);
173         }
174         else {
175                 printf("<fieldref> ");
176                 utf_display_printable_ascii_classname(fr->p.classref->name);
177                 printf(".");
178                 utf_display_printable_ascii(fr->name);
179                 printf(" ");
180                 utf_display_printable_ascii(fr->descriptor);
181         }
182 }
183 #endif
184
185 /* field_fieldref_println ******************************************************
186
187    (debugging only)
188
189 *******************************************************************************/
190
191 #if !defined(NDEBUG)
192 void field_fieldref_println(constant_FMIref *fr)
193 {
194         field_fieldref_print(fr);
195         printf("\n");
196 }
197 #endif
198
199 /*
200  * These are local overrides for various environment variables in Emacs.
201  * Please do not remove this and leave it at the end of the file, where
202  * Emacs will automagically detect them.
203  * ---------------------------------------------------------------------
204  * Local variables:
205  * mode: c
206  * indent-tabs-mode: t
207  * c-basic-offset: 4
208  * tab-width: 4
209  * End:
210  */