* src/vm/annotation.c: New file.
[cacao.git] / src / vm / annotation.c
1 /* src/vm/annotation.c - class annotations
2
3    Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    $Id: utf8.h 5920 2006-11-05 21:23:09Z twisti $
30
31 */
32
33
34 #include "config.h"
35 #include "vm/types.h"
36
37 #include "mm/memory.h"
38 #include "vm/annotation.h"
39 #include "vm/class.h"
40 #include "vm/suck.h"
41
42
43 /* annotation_load_attribute_runtimevisibleannotations *************************
44
45    RuntimeVisibleAnnotations_attribute {
46        u2 attribute_name_index;
47        u4 attribute_length;
48        u2 num_annotations;
49        annotation annotations[num_annotations];
50    }
51
52    annotation {
53        u2 type_index;
54        u2 num_element_value_pairs;
55        {
56             u2            element_name_index;
57             element_value element;
58        } element_value_pairs[num_element_value_pairs];
59    }
60                            
61 *******************************************************************************/
62
63 #if defined(ENABLE_JAVASE)
64 bool annotation_load_attribute_runtimevisibleannotations(classbuffer *cb)
65 {
66         classinfo       *c;
67         u4               attribute_length;
68         u2               num_annotations;
69         annotation_t    *aa;
70         element_value_t *aev;
71         u2               type_index;
72         u2               num_element_value_pairs;
73         u2               element_name_index;
74         u4               i, j;
75
76         /* get classinfo */
77
78         c = cb->class;
79
80         if (!suck_check_classbuffer_size(cb, 4 + 2))
81                 return false;
82
83         /* attribute_length */
84
85         attribute_length = suck_u4(cb);
86
87         if (!suck_check_classbuffer_size(cb, attribute_length))
88                 return false;
89
90         /* get number of annotations */
91
92         num_annotations = suck_u2(cb);
93
94         printf("num_annotations: %d\n", num_annotations);
95
96         /* allocate annotations-array */
97
98         aa = MNEW(annotation_t, num_annotations);
99
100         /* parse all annotations */
101
102         for (i = 0; i < num_annotations; i++) {
103                 /* get annotation type */
104
105                 type_index = suck_u2(cb);
106
107                 if (!(aa[i].type = class_getconstant(c, type_index, CONSTANT_Utf8)))
108                         return false;
109
110                 printf("type: ");
111                 utf_display_printable_ascii(aa[i].type);
112                 printf("\n");
113
114                 /* get number of element values */
115
116                 num_element_value_pairs = suck_u2(cb);
117
118                 printf("num_element_value_pairs: %d\n", num_element_value_pairs);
119
120                 aev = MNEW(element_value_t, num_element_value_pairs);
121
122                 /* parse all element values */
123
124                 for (j = 0; j < num_element_value_pairs; j++) {
125                         /* get element name */
126
127                         element_name_index = suck_u2(cb);
128
129                         if (!(aev[j].name =
130                                   class_getconstant(c, element_name_index, CONSTANT_Utf8)))
131                                 return false;
132
133                         /* get element tag */
134
135                         aev[i].tag = suck_u1(cb);
136                 }
137
138                 /* store element value data */
139
140                 aa[i].element_valuescount = num_element_value_pairs;
141                 aa[i].element_values      = aev;
142         }
143
144         /* store annotation variables */
145
146         c->runtimevisibleannotationscount = num_annotations;
147         c->runtimevisibleannotations      = aa;
148
149         return true;
150 }
151 #endif /* defined(ENABLE_JAVASE) */
152
153
154 /*
155  * These are local overrides for various environment variables in Emacs.
156  * Please do not remove this and leave it at the end of the file, where
157  * Emacs will automagically detect them.
158  * ---------------------------------------------------------------------
159  * Local variables:
160  * mode: c
161  * indent-tabs-mode: t
162  * c-basic-offset: 4
163  * tab-width: 4
164  * End:
165  * vim:noexpandtab:sw=4:ts=4:
166  */