* java/util/Properties.java (load): Only skip line if the first
[official-gcc.git] / libjava / gcj / field.h
blob9279c832964a166f3c9c4bff763bc794d6346a17
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
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 #ifndef COMPACT_FIELDS
25 struct _Jv_Utf8Const* name;
26 #endif
28 /* The type of the field, if isResolved().
29 If !isResolved(): The fields's signature as a (Utf8Const*). */
30 jclass type;
32 _Jv_ushort flags;
34 #ifdef COMPACT_FIELDS
35 jshort nameIndex; /* offset in class's name table */
36 #else
37 _Jv_ushort bsize; /* not really needed ... */
38 #endif
40 union {
41 jint boffset; /* offset in bytes for instance field */
42 void* addr; /* address of static field */
43 } u;
45 #ifdef __cplusplus
46 jboolean isResolved ()
47 { return ! (flags & _Jv_FIELD_UNRESOLVED_FLAG); }
49 public:
51 int getOffset () { return u.boffset; }
53 jobject getObjectField (jobject obj)
54 { return *(jobject *)((char *)obj + getOffset ()); }
56 jfieldID getNextField () { return this + 1; }
58 jboolean isRef ()
60 if (!isResolved ())
62 char first = ((_Jv_Utf8Const*)type)->data[0];
63 return first == '[' || first == 'L';
65 else
67 return ! type->isPrimitive ();
71 jclass getClass ()
73 // We can't use JvAssert here because it is not in a public
74 // header.
75 // JvAssert (isResolved ());
76 return type;
79 // Need to mask off all unknown/internal flags before returning.
80 int getModifiers()
82 return flags & java::lang::reflect::Modifier::ALL_FLAGS;
85 #ifdef COMPACT_FIELDS
86 _Jv_Utf8Const * getNameUtf8Const (jclass cls)
87 { return clas->fieldNames + nameIndex; }
88 #else
89 _Jv_Utf8Const * getNameUtf8Const (jclass) { return name; }
90 #endif
91 #endif
94 #ifdef __cplusplus
96 inline jbyte
97 _Jv_GetStaticByteField (jclass, _Jv_Field* field)
99 return * (jbyte *) field->u.addr;
102 inline jshort
103 _Jv_GetStaticShortField (jclass, _Jv_Field* field)
105 return * (jshort *) field->u.addr;
108 inline jint
109 _Jv_GetStaticIntField (jclass, _Jv_Field* field)
111 return * (jint *) field->u.addr;
114 inline jlong
115 _Jv_GetStaticLongField (jclass, _Jv_Field* field)
117 return * (jlong *) field->u.addr;
120 inline jobject
121 _Jv_GetObjectField (jobject obj, _Jv_Field* field)
123 return field->getObjectField (obj);
126 inline jbyte
127 _Jv_GetByteField (jobject obj, _Jv_Field* field)
129 return * (jbyte *) ((char*) obj + field->getOffset ());
132 inline jshort
133 _Jv_GetShortField (jobject obj, _Jv_Field* field)
135 return * (jshort *) ((char*) obj + field->getOffset ());
137 inline jint
138 _Jv_GetIntField (jobject obj, _Jv_Field* field)
140 return * (jint *) ((char*) obj + field->getOffset ());
142 inline jlong
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);
155 #ifdef __GCJ_CNI_H__
156 extern inline jfieldID
157 JvGetFirstInstanceField (jclass klass)
159 return &(klass->fields[klass->static_field_count]);
162 extern inline jint
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]);
174 extern inline jint
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 */