Line data Source code
1 : /* src/vm/jit/verify/typecheck-multianewarray.inc - type checking for MULTIANEWARRAY
2 :
3 : Copyright (C) 1996-2013
4 : CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 :
6 : This file is part of CACAO.
7 :
8 : This program is free software; you can redistribute it and/or
9 : modify it under the terms of the GNU General Public License as
10 : published by the Free Software Foundation; either version 2, or (at
11 : your option) any later version.
12 :
13 : This program is distributed in the hope that it will be useful, but
14 : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with this program; if not, write to the Free Software
20 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 : 02110-1301, USA.
22 :
23 : Contact: cacao@cacaojvm.org
24 :
25 : Authors: Edwin Steiner
26 :
27 :
28 : */
29 :
30 :
31 : {
32 : classinfo *arrayclass;
33 : arraydescriptor *desc;
34 : s4 i;
35 :
36 : /* check the array lengths on the stack */
37 15 : i = state->iptr->s1.argcount;
38 :
39 : #if !defined(TYPECHECK_TYPEINFERER)
40 15 : if (i < 1)
41 0 : VERIFY_ERROR("Illegal dimension argument");
42 :
43 67 : while (i--) {
44 37 : TYPECHECK_INT(state->iptr->sx.s23.s2.args[i]);
45 : }
46 : #endif /* !defined(TYPECHECK_TYPEINFERER) */
47 :
48 : /* check array descriptor */
49 15 : if (INSTRUCTION_IS_RESOLVED(state->iptr)) {
50 : /* the array class reference has already been resolved */
51 13 : arrayclass = state->iptr->sx.s23.s3.c.cls;
52 13 : if (!arrayclass)
53 0 : VERIFY_ERROR("MULTIANEWARRAY with unlinked class");
54 13 : if ((desc = arrayclass->vftbl->arraydesc) == NULL)
55 0 : VERIFY_ERROR("MULTIANEWARRAY with non-array class");
56 13 : if (desc->dimension < state->iptr->s1.argcount)
57 0 : VERIFY_ERROR("MULTIANEWARRAY dimension to high");
58 :
59 : /* set the array type of the result */
60 13 : dv->typeinfo.init_class(arrayclass);
61 : }
62 : else {
63 : const char *p;
64 : constant_classref *cr;
65 :
66 : /* the array class reference is still unresolved */
67 : /* check that the reference indicates an array class of correct dimension */
68 2 : cr = state->iptr->sx.s23.s3.c.ref;
69 2 : i = 0;
70 2 : p = cr->name.begin();
71 8 : while (p[i] == '[')
72 4 : i++;
73 : /* { the dimension of the array class == i } */
74 : #if !defined(TYPECHECK_TYPEINFERER)
75 2 : if (i < 1)
76 0 : VERIFY_ERROR("MULTIANEWARRAY with non-array class");
77 2 : if (i < state->iptr->s1.argcount)
78 0 : VERIFY_ERROR("MULTIANEWARRAY dimension to high");
79 : #endif /* !defined(TYPECHECK_TYPEINFERER) */
80 :
81 : /* set the array type of the result */
82 2 : if (!dv->typeinfo.init_class(cr))
83 0 : return false;
84 : }
85 :
86 : /* set return type */
87 :
88 15 : dv->type = TYPE_ADR;
89 : }
90 :
91 :
92 : /*
93 : * These are local overrides for various environment variables in Emacs.
94 : * Please do not remove this and leave it at the end of the file, where
95 : * Emacs will automagically detect them.
96 : * ---------------------------------------------------------------------
97 : * Local variables:
98 : * mode: c
99 : * indent-tabs-mode: t
100 : * c-basic-offset: 4
101 : * tab-width: 4
102 : * End:
103 : * vim:noexpandtab:sw=4:ts=4:filetype=c:
104 : */
|