Add forgotten test case for r203059.
[official-gcc.git] / libjava / gcj / field.h
blob2f483eb38ebfb3b2e2adabe74823e936a432f217
1 // field.h - Header file for fieldID instances. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #ifndef __GCJ_FIELD_H__
12 #define __GCJ_FIELD_H__
14 #include <java/lang/Class.h>
15 #include <java/lang/reflect/Field.h>
16 #include <java/lang/reflect/Modifier.h>
17 #include <gnu/gcj/RawData.h>
19 #define _Jv_FIELD_UNRESOLVED_FLAG 0x8000
21 struct _Jv_Field
23 struct _Jv_Utf8Const* name;
25 /* The type of the field, if isResolved().
26 If !isResolved(): The fields's signature as a (Utf8Const*). */
27 jclass type;
29 _Jv_ushort flags;
31 _Jv_ushort bsize; /* not really needed ... */
33 union {
34 jint boffset; /* offset in bytes for instance field */
35 char* addr; /* address of static field */
37 jobject* object_addr; /* address of static object field... etc */
38 jbyte* byte_addr;
39 jshort* short_addr;
40 jchar* char_addr;
41 jint* int_addr;
42 jlong* long_addr;
43 jfloat* float_addr;
44 jdouble* double_addr;
45 } u;
47 #ifdef __cplusplus
48 jboolean isResolved ()
49 { return ! (flags & _Jv_FIELD_UNRESOLVED_FLAG); }
51 public:
53 int getOffset () { return u.boffset; }
55 jobject getObjectField (jobject obj)
56 { return *(jobject *)((char *)obj + getOffset ()); }
58 jfieldID getNextField () { return this + 1; }
60 jboolean isRef ()
62 if (!isResolved ())
64 char first = ((_Jv_Utf8Const*)type)->first();
65 return first == '[' || first == 'L';
67 else
69 return ! type->isPrimitive ();
73 jclass getClass ()
75 // We can't use JvAssert here because it is not in a public
76 // header.
77 // JvAssert (isResolved ());
78 return type;
81 // Need to mask off all unknown/internal flags before returning.
82 int getModifiers()
84 return flags & java::lang::reflect::Modifier::ALL_FLAGS;
87 _Jv_Utf8Const * getNameUtf8Const (jclass) { return name; }
88 #endif
91 #ifdef __cplusplus
93 inline jbyte
94 _Jv_GetStaticByteField (jclass, _Jv_Field* field)
96 return * (jbyte *) field->u.addr;
99 inline jshort
100 _Jv_GetStaticShortField (jclass, _Jv_Field* field)
102 return * (jshort *) field->u.addr;
105 inline jint
106 _Jv_GetStaticIntField (jclass, _Jv_Field* field)
108 return * (jint *) field->u.addr;
111 inline jlong
112 _Jv_GetStaticLongField (jclass, _Jv_Field* field)
114 return * (jlong *) field->u.addr;
117 inline jobject
118 _Jv_GetObjectField (jobject obj, _Jv_Field* field)
120 return field->getObjectField (obj);
123 inline jbyte
124 _Jv_GetByteField (jobject obj, _Jv_Field* field)
126 return * (jbyte *) ((char*) obj + field->getOffset ());
129 inline jshort
130 _Jv_GetShortField (jobject obj, _Jv_Field* field)
132 return * (jshort *) ((char*) obj + field->getOffset ());
134 inline jint
135 _Jv_GetIntField (jobject obj, _Jv_Field* field)
137 return * (jint *) ((char*) obj + field->getOffset ());
139 inline jlong
140 _Jv_GetLongField (jobject obj, _Jv_Field* field)
142 return * (jlong *) ((char*) obj + field->getOffset ());
145 extern inline jfieldID
146 _Jv_FromReflectedField (java::lang::reflect::Field *field)
148 return (jfieldID) ((char *) field->declaringClass->fields + field->offset);
152 #ifdef __GCJ_CNI_H__
153 extern inline jfieldID
154 JvGetFirstInstanceField (jclass klass)
156 return &(klass->fields[klass->static_field_count]);
159 extern inline jint
160 JvNumInstanceFields (jclass klass)
162 return klass->field_count - klass->static_field_count;
165 extern inline jfieldID
166 JvGetFirstStaticField (jclass klass)
168 return &(klass->fields[0]);
171 extern inline jint
172 JvNumStaticFields (jclass klass)
174 return klass->static_field_count;
177 extern inline jboolean
178 JvFieldIsRef (jfieldID field)
180 return field->isRef () && field->type != &gnu::gcj::RawData::class$;
183 extern inline jobject
184 JvGetObjectField (jobject obj, _Jv_Field* field)
186 return _Jv_GetObjectField (obj, field);
188 #endif /* defined (__GCJ_CNI_H__) */
190 #endif /* __cplusplus */
192 #endif /* __GCJ_FIELD_H */