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
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
24 struct _Jv_Utf8Const
* name
;
26 /* The type of the field, if isResolved().
27 If !isResolved(): The fields's signature as a (Utf8Const*). */
32 _Jv_ushort bsize
; /* not really needed ... */
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 */
49 jboolean
isResolved ()
50 { return ! (flags
& _Jv_FIELD_UNRESOLVED_FLAG
); }
54 int getOffset () { return u
.boffset
; }
56 jobject
getObjectField (jobject obj
)
57 { return *(jobject
*)((char *)obj
+ getOffset ()); }
59 jfieldID
getNextField () { return this + 1; }
65 char first
= ((_Jv_Utf8Const
*)type
)->first();
66 return first
== '[' || first
== 'L';
70 return ! type
->isPrimitive ();
76 // We can't use JvAssert here because it is not in a public
78 // JvAssert (isResolved ());
82 // Need to mask off all unknown/internal flags before returning.
85 return flags
& java::lang::reflect::Modifier::ALL_FLAGS
;
88 _Jv_Utf8Const
* getNameUtf8Const (jclass
) { return name
; }
95 _Jv_GetStaticByteField (jclass
, _Jv_Field
* field
)
97 return * (jbyte
*) field
->u
.addr
;
101 _Jv_GetStaticShortField (jclass
, _Jv_Field
* field
)
103 return * (jshort
*) field
->u
.addr
;
107 _Jv_GetStaticIntField (jclass
, _Jv_Field
* field
)
109 return * (jint
*) field
->u
.addr
;
113 _Jv_GetStaticLongField (jclass
, _Jv_Field
* field
)
115 return * (jlong
*) field
->u
.addr
;
119 _Jv_GetObjectField (jobject obj
, _Jv_Field
* field
)
121 return field
->getObjectField (obj
);
125 _Jv_GetByteField (jobject obj
, _Jv_Field
* field
)
127 return * (jbyte
*) ((char*) obj
+ field
->getOffset ());
131 _Jv_GetShortField (jobject obj
, _Jv_Field
* field
)
133 return * (jshort
*) ((char*) obj
+ field
->getOffset ());
136 _Jv_GetIntField (jobject obj
, _Jv_Field
* field
)
138 return * (jint
*) ((char*) obj
+ field
->getOffset ());
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
);
154 extern inline jfieldID
155 JvGetFirstInstanceField (jclass klass
)
157 return &(klass
->fields
[klass
->static_field_count
]);
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]);
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 */