source: vendor/gcc/3.2.2/libjava/gcj/field.h

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.0 KB
Line 
1// field.h - Header file for fieldID instances. -*- c++ -*-
2
3/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11#ifndef __GCJ_FIELD_H__
12#define __GCJ_FIELD_H__
13
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>
18
19#define _Jv_FIELD_UNRESOLVED_FLAG 0x8000
20#define _Jv_FIELD_CONSTANT_VALUE 0x4000
21
22struct _Jv_Field
23{
24#ifndef COMPACT_FIELDS
25 struct _Jv_Utf8Const* name;
26#endif
27
28 /* The type of the field, if isResolved().
29 If !isResolved(): The fields's signature as a (Utf8Const*). */
30 jclass type;
31
32 _Jv_ushort flags;
33
34#ifdef COMPACT_FIELDS
35 jshort nameIndex; /* offset in class's name table */
36#else
37 _Jv_ushort bsize; /* not really needed ... */
38#endif
39
40 union {
41 jint boffset; /* offset in bytes for instance field */
42 void* addr; /* address of static field */
43 } u;
44
45#ifdef __cplusplus
46 jboolean isResolved ()
47 { return ! (flags & _Jv_FIELD_UNRESOLVED_FLAG); }
48
49 public:
50
51 int getOffset () { return u.boffset; }
52
53 jobject getObjectField (jobject obj)
54 { return *(jobject *)((char *)obj + getOffset ()); }
55
56 jfieldID getNextField () { return this + 1; }
57
58 jboolean isRef ()
59 {
60 if (!isResolved ())
61 {
62 char first = ((_Jv_Utf8Const*)type)->data[0];
63 return first == '[' || first == 'L';
64 }
65 else
66 {
67 return ! type->isPrimitive ();
68 }
69 }
70
71 jclass getClass ()
72 {
73 // We can't use JvAssert here because it is not in a public
74 // header.
75 // JvAssert (isResolved ());
76 return type;
77 }
78
79 // Need to mask off all unknown/internal flags before returning.
80 int getModifiers()
81 {
82 return flags & java::lang::reflect::Modifier::ALL_FLAGS;
83 }
84
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
92};
93
94#ifdef __cplusplus
95
96inline jbyte
97_Jv_GetStaticByteField (jclass, _Jv_Field* field)
98{
99 return * (jbyte *) field->u.addr;
100}
101
102inline jshort
103_Jv_GetStaticShortField (jclass, _Jv_Field* field)
104{
105 return * (jshort *) field->u.addr;
106}
107
108inline jint
109_Jv_GetStaticIntField (jclass, _Jv_Field* field)
110{
111 return * (jint *) field->u.addr;
112}
113
114inline jlong
115_Jv_GetStaticLongField (jclass, _Jv_Field* field)
116{
117 return * (jlong *) field->u.addr;
118}
119
120inline jobject
121_Jv_GetObjectField (jobject obj, _Jv_Field* field)
122{
123 return field->getObjectField (obj);
124}
125
126inline jbyte
127_Jv_GetByteField (jobject obj, _Jv_Field* field)
128{
129 return * (jbyte *) ((char*) obj + field->getOffset ());
130}
131
132inline jshort
133_Jv_GetShortField (jobject obj, _Jv_Field* field)
134{
135 return * (jshort *) ((char*) obj + field->getOffset ());
136}
137inline jint
138_Jv_GetIntField (jobject obj, _Jv_Field* field)
139{
140 return * (jint *) ((char*) obj + field->getOffset ());
141}
142inline jlong
143_Jv_GetLongField (jobject obj, _Jv_Field* field)
144{
145 return * (jlong *) ((char*) obj + field->getOffset ());
146}
147
148extern inline jfieldID
149_Jv_FromReflectedField (java::lang::reflect::Field *field)
150{
151 return (jfieldID) ((char *) field->declaringClass->fields + field->offset);
152}
153
154
155#ifdef __GCJ_CNI_H__
156extern inline jfieldID
157JvGetFirstInstanceField (jclass klass)
158{
159 return &(klass->fields[klass->static_field_count]);
160}
161
162extern inline jint
163JvNumInstanceFields (jclass klass)
164{
165 return klass->field_count - klass->static_field_count;
166}
167
168extern inline jfieldID
169JvGetFirstStaticField (jclass klass)
170{
171 return &(klass->fields[0]);
172}
173
174extern inline jint
175JvNumStaticFields (jclass klass)
176{
177 return klass->static_field_count;
178}
179
180extern inline jboolean
181JvFieldIsRef (jfieldID field)
182{
183 return field->isRef () && field->type != &gnu::gcj::RawData::class$;
184}
185
186extern inline jobject
187JvGetObjectField (jobject obj, _Jv_Field* field)
188{
189 return _Jv_GetObjectField (obj, field);
190}
191#endif /* defined (__GCJ_CNI_H__) */
192
193#endif /* __cplusplus */
194
195#endif /* __GCJ_FIELD_H */
Note: See TracBrowser for help on using the repository browser.