OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [java/] [lang/] [reflect/] [natField.cc] - Blame information for rev 758

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 758 jeremybenn
// natField.cc - Implementation of java.lang.reflect.Field native methods.
2
 
3
/* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2006  Free Software Foundation
4
 
5
   This file is part of libgcj.
6
 
7
This software is copyrighted work licensed under the terms of the
8
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
9
details.  */
10
 
11
#include <config.h>
12
 
13
#include <stdlib.h>
14
 
15
#include <jvm.h>
16
#include <java-stack.h>
17
#include <java/lang/reflect/Field.h>
18
#include <java/lang/reflect/Modifier.h>
19
#include <java/lang/ArrayIndexOutOfBoundsException.h>
20
#include <java/lang/IllegalArgumentException.h>
21
#include <java/lang/IllegalAccessException.h>
22
#include <java/lang/NullPointerException.h>
23
#include <java/lang/Byte.h>
24
#include <java/lang/Short.h>
25
#include <java/lang/Integer.h>
26
#include <java/lang/Long.h>
27
#include <java/lang/Float.h>
28
#include <java/lang/Double.h>
29
#include <java/lang/Boolean.h>
30
#include <java/lang/Character.h>
31
 
32
typedef JArray< ::java::lang::annotation::Annotation * > * anno_a_t;
33
 
34
jint
35
java::lang::reflect::Field::getModifiersInternal ()
36
{
37
  return _Jv_FromReflectedField (this)->flags;
38
}
39
 
40
jstring
41
java::lang::reflect::Field::getSignature()
42
{
43
  return declaringClass->getReflectionSignature (this);
44
}
45
 
46
anno_a_t
47
java::lang::reflect::Field::getDeclaredAnnotationsInternal()
48
{
49
  return (anno_a_t) declaringClass->getDeclaredAnnotations(this);
50
}
51
 
52
jstring
53
java::lang::reflect::Field::getName ()
54
{
55
  if (name == NULL)
56
    name = _Jv_NewStringUtf8Const (_Jv_FromReflectedField (this)->name);
57
  return name;
58
}
59
 
60
jclass
61
java::lang::reflect::Field::getType ()
62
{
63
  if (type == NULL)
64
    {
65
      jfieldID fld = _Jv_FromReflectedField (this);
66
      JvSynchronize sync (declaringClass);
67
      _Jv_Linker::resolve_field (fld, declaringClass->getClassLoaderInternal ());
68
      type = fld->type;
69
    }
70
  return type;
71
}
72
 
73
static void*
74
getAddr (java::lang::reflect::Field* field, jclass caller, jobject obj,
75
         jboolean checkFinal)
76
{
77
  using namespace java::lang::reflect;
78
 
79
  jfieldID fld = _Jv_FromReflectedField (field);
80
  _Jv_ushort flags = fld->getModifiers();
81
 
82
  // Setting a final field is usually not allowed.
83
  if (checkFinal
84
      // As of 1.5, you can set a non-static final field if it is
85
      // accessible.
86
      && (! field->isAccessible()
87
          || (field->getModifiers() & java::lang::reflect::Modifier::STATIC))
88
      && (field->getModifiers() & java::lang::reflect::Modifier::FINAL))
89
    throw new java::lang::IllegalAccessException(JvNewStringUTF
90
      ("Field is final"));
91
 
92
  // Check accessibility, if required.
93
  if (! (Modifier::isPublic (flags) || field->isAccessible()))
94
    {
95
      if (! caller)
96
        caller = _Jv_StackTrace::GetCallingClass (&Field::class$);
97
      if (! _Jv_CheckAccess (caller, field->getDeclaringClass(), flags))
98
        throw new java::lang::IllegalAccessException;
99
    }
100
 
101
  if (flags & Modifier::STATIC)
102
    {
103
      jclass fldClass = field->getDeclaringClass ();
104
      JvInitClass(fldClass);
105
      return fld->u.addr;
106
    }
107
  else
108
    {
109
      if (obj == NULL)
110
        throw new java::lang::NullPointerException;
111
      if (! _Jv_IsInstanceOf (obj, field->getDeclaringClass()))
112
        throw new java::lang::IllegalArgumentException;
113
      return (void*) ((char*) obj + fld->getOffset ());
114
    }
115
}
116
 
117
static jboolean
118
getBoolean (jclass cls, void* addr)
119
{
120
  if (cls == JvPrimClass (boolean))
121
    return * (jboolean *) addr;
122
  throw new java::lang::IllegalArgumentException;
123
}
124
 
125
static jchar
126
getChar (jclass cls, void* addr)
127
{
128
  if (cls == JvPrimClass (char))
129
    return * (jchar *) addr;
130
  throw new java::lang::IllegalArgumentException;
131
}
132
 
133
static jbyte
134
getByte (jclass cls, void* addr)
135
{
136
  if (cls == JvPrimClass (byte))
137
    return * (jbyte *) addr;
138
  throw new java::lang::IllegalArgumentException;
139
}
140
 
141
static jshort
142
getShort (jclass cls, void* addr)
143
{
144
  if (cls == JvPrimClass (short))
145
    return * (jshort *) addr;
146
  if (cls == JvPrimClass (byte))
147
    return * (jbyte *) addr;
148
  throw new java::lang::IllegalArgumentException;
149
}
150
 
151
static jint
152
getInt (jclass cls, void* addr)
153
{
154
  if (cls == JvPrimClass (int))
155
    return * (jint *) addr;
156
  if (cls == JvPrimClass (short))
157
    return * (jshort *) addr;
158
  if (cls == JvPrimClass (char))
159
    return * (jchar *) addr;
160
  if (cls == JvPrimClass (byte))
161
    return * (jbyte *) addr;
162
  throw new java::lang::IllegalArgumentException;
163
}
164
 
165
static jlong
166
getLong (jclass cls, void* addr)
167
{
168
  if (cls == JvPrimClass (long))
169
    return * (jlong *) addr;
170
  return ::getInt(cls, addr);
171
}
172
 
173
static jfloat
174
getFloat (jclass cls, void* addr)
175
{
176
  if (cls == JvPrimClass (float))
177
    return * (jfloat *) addr;
178
  if (cls == JvPrimClass (long))
179
    return * (jlong *) addr;
180
  return ::getInt(cls, addr);
181
}
182
 
183
static jdouble
184
getDouble (jclass cls, void* addr)
185
{
186
  if (cls == JvPrimClass (double))
187
    return * (jdouble *) addr;
188
  if (cls == JvPrimClass (float))
189
    return * (jfloat *) addr;
190
  if (cls == JvPrimClass (long))
191
    return * (jlong *) addr;
192
  return ::getInt(cls, addr);
193
}
194
 
195
jboolean
196
java::lang::reflect::Field::getBoolean (jclass caller, jobject obj)
197
{
198
  return ::getBoolean (this->getType(), getAddr (this, caller, obj, false));
199
}
200
 
201
jchar
202
java::lang::reflect::Field::getChar (jclass caller, jobject obj)
203
{
204
  return ::getChar (this->getType(), getAddr (this, caller, obj, false));
205
}
206
 
207
jbyte
208
java::lang::reflect::Field::getByte (jclass caller, jobject obj)
209
{
210
  return ::getByte (this->getType(), getAddr (this, caller, obj, false));
211
}
212
 
213
jshort
214
java::lang::reflect::Field::getShort (jclass caller, jobject obj)
215
{
216
  return ::getShort (this->getType(), getAddr (this, caller, obj, false));
217
}
218
 
219
jint
220
java::lang::reflect::Field::getInt (jclass caller, jobject obj)
221
{
222
  return ::getInt (this->getType(), getAddr (this, caller, obj, false));
223
}
224
 
225
jlong
226
java::lang::reflect::Field::getLong (jclass caller, jobject obj)
227
{
228
  return ::getLong (this->getType(), getAddr (this, caller, obj, false));
229
}
230
 
231
jfloat
232
java::lang::reflect::Field::getFloat (jclass caller, jobject obj)
233
{
234
  return ::getFloat (this->getType(), getAddr (this, caller, obj, false));
235
}
236
 
237
jdouble
238
java::lang::reflect::Field::getDouble (jclass caller, jobject obj)
239
{
240
  return ::getDouble (this->getType(), getAddr (this, caller, obj, false));
241
}
242
 
243
jobject
244
java::lang::reflect::Field::get (jclass caller, jobject obj)
245
{
246
  jclass type = this->getType();
247
  void* addr = getAddr (this, caller, obj, false);
248
  if (! type->isPrimitive ())
249
    return * (jobject*) addr;
250
  if (type == JvPrimClass (double))
251
    return new java::lang::Double (* (jdouble*) addr);
252
  if (type == JvPrimClass (float))
253
    return new java::lang::Float (* (jfloat*) addr);
254
  if (type == JvPrimClass (long))
255
    return new java::lang::Long (* (jlong*) addr);
256
  if (type == JvPrimClass (int))
257
    return new java::lang::Integer (* (jint*) addr);
258
  if (type == JvPrimClass (short))
259
    return new java::lang::Short (* (jshort*) addr);
260
  if (type == JvPrimClass (byte))
261
    return new java::lang::Byte (* (jbyte*) addr);
262
  if (type == JvPrimClass (char))
263
    return new java::lang::Character (* (jchar*) addr);
264
  if (type == JvPrimClass (boolean))
265
    {
266
      _Jv_InitClass (&java::lang::Boolean::class$);
267
      if (* (jboolean*) addr)
268
        return java::lang::Boolean::TRUE;
269
      else
270
        return java::lang::Boolean::FALSE;
271
    }
272
  throw new java::lang::IllegalArgumentException;
273
}
274
 
275
static void
276
setBoolean (jclass type, void *addr, jboolean value)
277
{
278
  if (type == JvPrimClass (boolean))
279
    * (jboolean *) addr = value;
280
  else
281
    throw new java::lang::IllegalArgumentException;
282
}
283
 
284
static void
285
setChar (jclass type, void *addr, jchar value)
286
{
287
  if (type == JvPrimClass (char))
288
    * (jchar *) addr = value;
289
  else if (type == JvPrimClass (int))
290
    * (jint *) addr = value;
291
  else if (type == JvPrimClass (long))
292
    * (jlong *) addr = value;
293
  else if (type == JvPrimClass (float))
294
    * (jfloat *) addr = value;
295
  else if (type == JvPrimClass (double))
296
    * (jdouble *) addr = value;
297
  else
298
    throw new java::lang::IllegalArgumentException;
299
}
300
 
301
static void
302
setByte (jclass type, void *addr, jbyte value)
303
{
304
  if (type == JvPrimClass (byte))
305
    * (jbyte *) addr = value;
306
  else if (type == JvPrimClass (short))
307
    * (jshort *) addr = value;
308
  else if (type == JvPrimClass (int))
309
    * (jint *) addr = value;
310
  else if (type == JvPrimClass (long))
311
    * (jlong *) addr = value;
312
  else if (type == JvPrimClass (float))
313
    * (jfloat *) addr = value;
314
  else if (type == JvPrimClass (double))
315
    * (jdouble *) addr = value;
316
  else
317
    throw new java::lang::IllegalArgumentException;
318
}
319
 
320
static void
321
setShort (jclass type, void *addr, jshort value)
322
{
323
  if (type == JvPrimClass (short))
324
    * (jshort *) addr = value;
325
  else if (type == JvPrimClass (int))
326
    * (jint *) addr = value;
327
  else if (type == JvPrimClass (long))
328
    * (jlong *) addr = value;
329
  else if (type == JvPrimClass (float))
330
    * (jfloat *) addr = value;
331
  else if (type == JvPrimClass (double))
332
    * (jdouble *) addr = value;
333
  else
334
    throw new java::lang::IllegalArgumentException;
335
}
336
 
337
static void
338
setInt (jclass type, void *addr, jint value)
339
{
340
  if (type == JvPrimClass (int))
341
    * (jint *) addr = value;
342
  else if (type == JvPrimClass (long))
343
    * (jlong *) addr = value;
344
  else if (type == JvPrimClass (float))
345
    * (jfloat *) addr = value;
346
  else if (type == JvPrimClass (double))
347
    * (jdouble *) addr = value;
348
  else
349
    throw new java::lang::IllegalArgumentException;
350
}
351
 
352
static void
353
setLong (jclass type, void *addr, jlong value)
354
{
355
  if (type == JvPrimClass (long))
356
    * (jlong *) addr = value;
357
  else if (type == JvPrimClass (float))
358
    * (jfloat *) addr = value;
359
  else if (type == JvPrimClass (double))
360
    * (jdouble *) addr = value;
361
  else
362
    throw new java::lang::IllegalArgumentException;
363
}
364
 
365
static void
366
setFloat (jclass type, void *addr, jfloat value)
367
{
368
  if (type == JvPrimClass (float))
369
    * (jfloat *) addr = value;
370
  else if (type == JvPrimClass (double))
371
    * (jdouble *) addr = value;
372
  else
373
    throw new java::lang::IllegalArgumentException;
374
}
375
 
376
static void
377
setDouble (jclass type, void *addr, jdouble value)
378
{
379
  if (type == JvPrimClass (double))
380
    * (jdouble *) addr = value;
381
  else
382
    throw new java::lang::IllegalArgumentException;
383
}
384
 
385
void
386
java::lang::reflect::Field::setBoolean (jclass caller, jobject obj, jboolean b,
387
                                        jboolean checkFinal)
388
{
389
  ::setBoolean (this->getType(), getAddr (this, caller, obj, checkFinal), b);
390
}
391
 
392
void
393
java::lang::reflect::Field::setChar (jclass caller, jobject obj, jchar c,
394
                                     jboolean checkFinal)
395
{
396
  ::setChar (this->getType(), getAddr (this, caller, obj, checkFinal), c);
397
}
398
 
399
void
400
java::lang::reflect::Field::setByte (jclass caller, jobject obj, jbyte b,
401
                                     jboolean checkFinal)
402
{
403
  ::setByte (this->getType(), getAddr (this, caller, obj, checkFinal), b);
404
}
405
 
406
void
407
java::lang::reflect::Field::setShort (jclass caller, jobject obj, jshort s,
408
                                      jboolean checkFinal)
409
{
410
  ::setShort (this->getType(), getAddr (this, caller, obj, checkFinal), s);
411
}
412
 
413
void
414
java::lang::reflect::Field::setInt (jclass caller, jobject obj, jint i,
415
                                    jboolean checkFinal)
416
{
417
  ::setInt (this->getType(), getAddr (this, caller, obj, checkFinal), i);
418
}
419
 
420
void
421
java::lang::reflect::Field::setLong (jclass caller, jobject obj, jlong l,
422
                                     jboolean checkFinal)
423
{
424
  ::setLong (this->getType(), getAddr (this, caller, obj, checkFinal), l);
425
}
426
 
427
void
428
java::lang::reflect::Field::setFloat (jclass caller, jobject obj, jfloat f,
429
                                      jboolean checkFinal)
430
{
431
  ::setFloat (this->getType(), getAddr (this, caller, obj, checkFinal), f);
432
}
433
 
434
void
435
java::lang::reflect::Field::setDouble (jclass caller, jobject obj, jdouble d,
436
                                       jboolean checkFinal)
437
{
438
  ::setDouble (this->getType(), getAddr (this, caller, obj, checkFinal), d);
439
}
440
 
441
void
442
java::lang::reflect::Field::set (jclass caller, jobject object, jobject value,
443
                                 jclass type, jboolean checkFinal)
444
{
445
  void* addr = getAddr (this, caller, object, checkFinal);
446
  if (value != NULL && ! _Jv_IsInstanceOf (value, type))
447
    throw new java::lang::IllegalArgumentException;
448
  * (jobject*) addr = value;
449
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.