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