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
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
23 struct _Jv_Utf8Const
* name
;
25 /* The type of the field, if isResolved().
26 If !isResolved(): The fields's signature as a (Utf8Const*). */
31 _Jv_ushort bsize
; /* not really needed ... */
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 */
48 jboolean
isResolved ()
49 { return ! (flags
& _Jv_FIELD_UNRESOLVED_FLAG
); }
53 int getOffset () { return u
.boffset
; }
55 jobject
getObjectField (jobject obj
)
56 { return *(jobject
*)((char *)obj
+ getOffset ()); }
58 jfieldID
getNextField () { return this + 1; }
64 char first
= ((_Jv_Utf8Const
*)type
)->first();
65 return first
== '[' || first
== 'L';
69 return ! type
->isPrimitive ();
75 // We can't use JvAssert here because it is not in a public
77 // JvAssert (isResolved ());
81 // Need to mask off all unknown/internal flags before returning.
84 return flags
& java::lang::reflect::Modifier::ALL_FLAGS
;
87 _Jv_Utf8Const
* getNameUtf8Const (jclass
) { return name
; }
94 _Jv_GetStaticByteField (jclass
, _Jv_Field
* field
)
96 return * (jbyte
*) field
->u
.addr
;
100 _Jv_GetStaticShortField (jclass
, _Jv_Field
* field
)
102 return * (jshort
*) field
->u
.addr
;
106 _Jv_GetStaticIntField (jclass
, _Jv_Field
* field
)
108 return * (jint
*) field
->u
.addr
;
112 _Jv_GetStaticLongField (jclass
, _Jv_Field
* field
)
114 return * (jlong
*) field
->u
.addr
;
118 _Jv_GetObjectField (jobject obj
, _Jv_Field
* field
)
120 return field
->getObjectField (obj
);
124 _Jv_GetByteField (jobject obj
, _Jv_Field
* field
)
126 return * (jbyte
*) ((char*) obj
+ field
->getOffset ());
130 _Jv_GetShortField (jobject obj
, _Jv_Field
* field
)
132 return * (jshort
*) ((char*) obj
+ field
->getOffset ());
135 _Jv_GetIntField (jobject obj
, _Jv_Field
* field
)
137 return * (jint
*) ((char*) obj
+ field
->getOffset ());
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
);
153 extern inline jfieldID
154 JvGetFirstInstanceField (jclass klass
)
156 return &(klass
->fields
[klass
->static_field_count
]);
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]);
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 */