1 // field.h - Header file for fieldID instances. -*- c++ -*-
3 /* Copyright (C) 1998, 1999, 2000 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 #ifndef COMPACT_FIELDS
25 struct _Jv_Utf8Const
* name
;
28 /* The type of the field, if isResolved().
29 If !isResolved(): The fields's signature as a (Utf8Const*). */
35 jshort nameIndex
; /* offset in class's name table */
37 _Jv_ushort bsize
; /* not really needed ... */
41 jint boffset
; /* offset in bytes for instance field */
42 void* addr
; /* address of static field */
46 jboolean
isResolved ()
47 { return ! (flags
& _Jv_FIELD_UNRESOLVED_FLAG
); }
51 int getOffset () { return u
.boffset
; }
53 jobject
getObjectField (jobject obj
)
54 { return *(jobject
*)((char *)obj
+ getOffset ()); }
56 jfieldID
getNextField () { return this + 1; }
62 char first
= ((_Jv_Utf8Const
*)type
)->data
[0];
63 return first
== '[' || first
== 'L';
67 return ! type
->isPrimitive ();
73 // We can't use JvAssert here because it is not in a public
75 // JvAssert (isResolved ());
79 // Need to mask off all unknown/internal flags before returning.
82 return flags
& java::lang::reflect::Modifier::ALL_FLAGS
;
86 _Jv_Utf8Const
* getNameUtf8Const (jclass cls
)
87 { return clas
->fieldNames
+ nameIndex
; }
89 _Jv_Utf8Const
* getNameUtf8Const (jclass
) { return name
; }
97 _Jv_GetStaticByteField (jclass
, _Jv_Field
* field
)
99 return * (jbyte
*) field
->u
.addr
;
103 _Jv_GetStaticShortField (jclass
, _Jv_Field
* field
)
105 return * (jshort
*) field
->u
.addr
;
109 _Jv_GetStaticIntField (jclass
, _Jv_Field
* field
)
111 return * (jint
*) field
->u
.addr
;
115 _Jv_GetStaticLongField (jclass
, _Jv_Field
* field
)
117 return * (jlong
*) field
->u
.addr
;
121 _Jv_GetObjectField (jobject obj
, _Jv_Field
* field
)
123 return field
->getObjectField (obj
);
127 _Jv_GetByteField (jobject obj
, _Jv_Field
* field
)
129 return * (jbyte
*) ((char*) obj
+ field
->getOffset ());
133 _Jv_GetShortField (jobject obj
, _Jv_Field
* field
)
135 return * (jshort
*) ((char*) obj
+ field
->getOffset ());
138 _Jv_GetIntField (jobject obj
, _Jv_Field
* field
)
140 return * (jint
*) ((char*) obj
+ field
->getOffset ());
143 _Jv_GetLongField (jobject obj
, _Jv_Field
* field
)
145 return * (jlong
*) ((char*) obj
+ field
->getOffset ());
148 extern inline jfieldID
149 _Jv_FromReflectedField (java::lang::reflect::Field
*field
)
151 return (jfieldID
) ((char *) field
->declaringClass
->fields
+ field
->offset
);
156 extern inline jfieldID
157 JvGetFirstInstanceField (jclass klass
)
159 return &(klass
->fields
[klass
->static_field_count
]);
163 JvNumInstanceFields (jclass klass
)
165 return klass
->field_count
- klass
->static_field_count
;
168 extern inline jfieldID
169 JvGetFirstStaticField (jclass klass
)
171 return &(klass
->fields
[0]);
175 JvNumStaticFields (jclass klass
)
177 return klass
->static_field_count
;
180 extern inline jboolean
181 JvFieldIsRef (jfieldID field
)
183 return field
->isRef () && field
->type
!= &gnu::gcj::RawData::class$
;
186 extern inline jobject
187 JvGetObjectField (jobject obj
, _Jv_Field
* field
)
189 return _Jv_GetObjectField (obj
, field
);
191 #endif /* defined (__GCJ_CNI_H__) */
193 #endif /* __cplusplus */
195 #endif /* __GCJ_FIELD_H */