* Removed all Id tags.
[cacao.git] / src / vm / jit / verify / typecheck-multianewarray.inc
1 /* src/vm/jit/verify/typecheck-multianewarray.inc - type checking for MULTIANEWARRAY
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
30 */
31
32
33 {
34         classinfo *arrayclass;
35         arraydescriptor *desc;
36         s4 i;
37
38         /* check the array lengths on the stack */
39         i = state->iptr->s1.argcount;
40
41 #if !defined(TYPECHECK_TYPEINFERER)
42         if (i < 1)
43                 VERIFY_ERROR("Illegal dimension argument");
44
45         while (i--) {
46                 TYPECHECK_INT(state->iptr->sx.s23.s2.args[i]);
47         }
48 #endif /* !defined(TYPECHECK_TYPEINFERER) */
49
50         /* check array descriptor */
51         if (INSTRUCTION_IS_RESOLVED(state->iptr)) {
52                 /* the array class reference has already been resolved */
53                 arrayclass = state->iptr->sx.s23.s3.c.cls;
54                 if (!arrayclass)
55                         VERIFY_ERROR("MULTIANEWARRAY with unlinked class");
56                 if ((desc = arrayclass->vftbl->arraydesc) == NULL)
57                         VERIFY_ERROR("MULTIANEWARRAY with non-array class");
58                 if (desc->dimension < state->iptr->s1.argcount)
59                         VERIFY_ERROR("MULTIANEWARRAY dimension to high");
60
61                 /* set the array type of the result */
62                 typeinfo_init_classinfo(&(dv->typeinfo), arrayclass);
63         }
64         else {
65                 const char *p;
66                 constant_classref *cr;
67
68                 /* the array class reference is still unresolved */
69                 /* check that the reference indicates an array class of correct dimension */
70                 cr = state->iptr->sx.s23.s3.c.ref;
71                 i = 0;
72                 p = cr->name->text;
73                 while (p[i] == '[')
74                         i++;
75                 /* { the dimension of the array class == i } */
76 #if !defined(TYPECHECK_TYPEINFERER)
77                 if (i < 1)
78                         VERIFY_ERROR("MULTIANEWARRAY with non-array class");
79                 if (i < state->iptr->s1.argcount)
80                         VERIFY_ERROR("MULTIANEWARRAY dimension to high");
81 #endif /* !defined(TYPECHECK_TYPEINFERER) */
82
83                 /* set the array type of the result */
84                 if (!typeinfo_init_class(&(dv->typeinfo),CLASSREF_OR_CLASSINFO(cr)))
85                         return false;
86         }
87
88         /* set return type */
89
90         dv->type = TYPE_ADR;
91 }
92
93
94 /*
95  * These are local overrides for various environment variables in Emacs.
96  * Please do not remove this and leave it at the end of the file, where
97  * Emacs will automagically detect them.
98  * ---------------------------------------------------------------------
99  * Local variables:
100  * mode: c
101  * indent-tabs-mode: t
102  * c-basic-offset: 4
103  * tab-width: 4
104  * End:
105  * vim:noexpandtab:sw=4:ts=4:filetype=c:
106  */