PR target/18973
[official-gcc.git] / libjava / gcj / field.h
blob8421bc7e04644d1839ab96a50f5739c3114996be
1 // field.h - Header file for fieldID instances. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000, 2004 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
20 #define _Jv_FIELD_CONSTANT_VALUE 0x4000
22 struct _Jv_Field
24 struct _Jv_Utf8Const* name;
26 /* The type of the field, if isResolved().
27 If !isResolved(): The fields's signature as a (Utf8Const*). */
28 jclass type;
30 _Jv_ushort flags;
32 _Jv_ushort bsize; /* not really needed ... */
34 union {
35 jint boffset; /* offset in bytes for instance field */
36 char* addr; /* address of static field */
38 jobject* object_addr; /* address of static object field... etc */
39 jbyte* byte_addr;
40 jshort* short_addr;
41 jchar* char_addr;
42 jint* int_addr;
43 jlong* long_addr;
44 jfloat* float_addr;
45 jdouble* double_addr;
46 } u;
48 #ifdef __cplusplus
49 jboolean isResolved ()
50 { return ! (flags & _Jv_FIELD_UNRESOLVED_FLAG); }
52 public:
54 int getOffset () { return u.boffset; }
56 jobject getObjectField (jobject obj)
57 { return *(jobject *)((char *)obj + getOffset ()); }
59 jfieldID getNextField () { return this + 1; }
61 jboolean isRef ()
63 if (!isResolved ())
65 char first = ((_Jv_Utf8Const*)type)->first();
66 return first == '[' || first == 'L';
68 else
70 return ! type->isPrimitive ();
74 jclass getClass ()
76 // We can't use JvAssert here because it is not in a public
77 // header.
78 // JvAssert (isResolved ());
79 return type;
82 // Need to mask off all unknown/internal flags before returning.
83 int getModifiers()
85 return flags & java::lang::reflect::Modifier::ALL_FLAGS;
88 _Jv_Utf8Const * getNameUtf8Const (jclass) { return name; }
89 #endif
92 #ifdef __cplusplus
94 inline jbyte
95 _Jv_GetStaticByteField (jclass, _Jv_Field* field)
97 return * (jbyte *) field->u.addr;
100 inline jshort
101 _Jv_GetStaticShortField (jclass, _Jv_Field* field)
103 return * (jshort *) field->u.addr;
106 inline jint
107 _Jv_GetStaticIntField (jclass, _Jv_Field* field)
109 return * (jint *) field->u.addr;
112 inline jlong
113 _Jv_GetStaticLongField (jclass, _Jv_Field* field)
115 return * (jlong *) field->u.addr;
118 inline jobject
119 _Jv_GetObjectField (jobject obj, _Jv_Field* field)
121 return field->getObjectField (obj);
124 inline jbyte
125 _Jv_GetByteField (jobject obj, _Jv_Field* field)
127 return * (jbyte *) ((char*) obj + field->getOffset ());
130 inline jshort
131 _Jv_GetShortField (jobject obj, _Jv_Field* field)
133 return * (jshort *) ((char*) obj + field->getOffset ());
135 inline jint
136 _Jv_GetIntField (jobject obj, _Jv_Field* field)
138 return * (jint *) ((char*) obj + field->getOffset ());
140 inline jlong
141 _Jv_GetLongField (jobject obj, _Jv_Field* field)
143 return * (jlong *) ((char*) obj + field->getOffset ());
146 extern inline jfieldID
147 _Jv_FromReflectedField (java::lang::reflect::Field *field)
149 return (jfieldID) ((char *) field->declaringClass->fields + field->offset);
153 #ifdef __GCJ_CNI_H__
154 extern inline jfieldID
155 JvGetFirstInstanceField (jclass klass)
157 return &(klass->fields[klass->static_field_count]);
160 extern inline jint
161 JvNumInstanceFields (jclass klass)
163 return klass->field_count - klass->static_field_count;
166 extern inline jfieldID
167 JvGetFirstStaticField (jclass klass)
169 return &(klass->fields[0]);
172 extern inline jint
173 JvNumStaticFields (jclass klass)
175 return klass->static_field_count;
178 extern inline jboolean
179 JvFieldIsRef (jfieldID field)
181 return field->isRef () && field->type != &gnu::gcj::RawData::class$;
184 extern inline jobject
185 JvGetObjectField (jobject obj, _Jv_Field* field)
187 return _Jv_GetObjectField (obj, field);
189 #endif /* defined (__GCJ_CNI_H__) */
191 #endif /* __cplusplus */
193 #endif /* __GCJ_FIELD_H */