1
|
1 |
/*
|
|
2 |
* Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
# include "incls/_precompiled.incl"
|
|
26 |
# include "incls/_fieldType.cpp.incl"
|
|
27 |
|
|
28 |
void FieldType::skip_optional_size(symbolOop signature, int* index) {
|
|
29 |
jchar c = signature->byte_at(*index);
|
|
30 |
while (c >= '0' && c <= '9') {
|
|
31 |
*index = *index + 1;
|
|
32 |
c = signature->byte_at(*index);
|
|
33 |
}
|
|
34 |
}
|
|
35 |
|
|
36 |
BasicType FieldType::basic_type(symbolOop signature) {
|
|
37 |
return char2type(signature->byte_at(0));
|
|
38 |
}
|
|
39 |
|
|
40 |
// Check if it is a valid array signature
|
|
41 |
bool FieldType::is_valid_array_signature(symbolOop sig) {
|
|
42 |
assert(sig->utf8_length() > 1, "this should already have been checked");
|
|
43 |
assert(sig->byte_at(0) == '[', "this should already have been checked");
|
|
44 |
// The first character is already checked
|
|
45 |
int i = 1;
|
|
46 |
int len = sig->utf8_length();
|
|
47 |
// First skip all '['s
|
|
48 |
while(i < len - 1 && sig->byte_at(i) == '[') i++;
|
|
49 |
|
|
50 |
// Check type
|
|
51 |
switch(sig->byte_at(i)) {
|
|
52 |
case 'B': // T_BYTE
|
|
53 |
case 'C': // T_CHAR
|
|
54 |
case 'D': // T_DOUBLE
|
|
55 |
case 'F': // T_FLOAT
|
|
56 |
case 'I': // T_INT
|
|
57 |
case 'J': // T_LONG
|
|
58 |
case 'S': // T_SHORT
|
|
59 |
case 'Z': // T_BOOLEAN
|
|
60 |
// If it is an array, the type is the last character
|
|
61 |
return (i + 1 == len);
|
|
62 |
case 'L':
|
|
63 |
// If it is an object, the last character must be a ';'
|
|
64 |
return sig->byte_at(len - 1) == ';';
|
|
65 |
}
|
|
66 |
|
|
67 |
return false;
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
BasicType FieldType::get_array_info(symbolOop signature, jint* dimension, symbolOop* object_key, TRAPS) {
|
|
72 |
assert(basic_type(signature) == T_ARRAY, "must be array");
|
|
73 |
int index = 1;
|
|
74 |
int dim = 1;
|
|
75 |
skip_optional_size(signature, &index);
|
|
76 |
while (signature->byte_at(index) == '[') {
|
|
77 |
index++;
|
|
78 |
dim++;
|
|
79 |
skip_optional_size(signature, &index);
|
|
80 |
}
|
|
81 |
ResourceMark rm;
|
|
82 |
symbolOop element = oopFactory::new_symbol(signature->as_C_string() + index, CHECK_(T_BYTE));
|
|
83 |
BasicType element_type = FieldType::basic_type(element);
|
|
84 |
if (element_type == T_OBJECT) {
|
|
85 |
char* object_type = element->as_C_string();
|
|
86 |
object_type[element->utf8_length() - 1] = '\0';
|
|
87 |
*object_key = oopFactory::new_symbol(object_type + 1, CHECK_(T_BYTE));
|
|
88 |
}
|
|
89 |
// Pass dimension back to caller
|
|
90 |
*dimension = dim;
|
|
91 |
return element_type;
|
|
92 |
}
|