History

Fixed Class class, completely refactored it's native module

Dmitry Kabak (userdima committed 13 years ago

Commit 267b7a01 parent 3e3e9834 files · +359 −446Browse files

Showing the changes to java (4 of 4 files). Show all

Unified · Split

4 files
  1. java/pkg/java/lang/Class.class +0 −0
  2. java/pkg/java/lang/Class.java +4 −1
  3. java/pkg/java/lang/Class_L.b +337 −432
  4. java/pkg/java/lang/Class_L.m +19 −14
java/pkg/java/lang/Class.class+0−0

Binary file not shown.

java/pkg/java/lang/Class.java+4−1
@@ -183,7 +183,10 @@ public final · 182 unmodified lines
183183 */
184184 public static Class<?> forName(String className)
185185 throws ClassNotFoundException {
186− return forName0(className, true, ClassLoader.getCallerClassLoader());
186+ // [Inferno] No need to getCallerClassLoader here, it's not currently implemented <
187+ //return forName0(className, true, ClassLoader.getCallerClassLoader());
188+ return forName0(className, true, null);
189+ // [Inferno] >
187190 }
188191
189192
java/pkg/java/lang/Class_L.b+337−432
@@ -1,7 +1,5 @@
11 implement Class_L;
22
3−# javal v1.2 generated file: edit with care
4−
53 include "jni.m";
64 jni : JNI;
75 ClassModule,
@@ -50,195 +48,212 @@ init( jni_p : JNI ) · 42 unmodified lines
5048 #<<
5149 }
5250
53−forName0_rString_Z_rClassLoader_rClass( p0 : JString, p1 : int, p2 : JObject ) : JClass
51+forName0_rString_Z_rClassLoader_rClass( p0 : JString,p1 : int,p2 : JObject) : JClass
5452 {#>>
55− {
56− jni->sys->print("forName called for class %s\n", p0.str);
57− if ( p0.str != nil && p0.str[0] == '[' )
58− return( jni->LookupArrayClass(p0.str) );
59− else
60− return( jni->GetClassObject( jni->FindClass(p0.str) ) );
61− }
62− exception e {
63− "JLD:e0*" =>
64− jni->ThrowException( "java.lang.ClassNotFoundException", p0.str );
65− }
66−
67− return(nil);
53+ {
54+ if (p0.str != nil && p0.str[0] == '[')
55+ return jni->LookupArrayClass(p0.str);
56+ else
57+ return jni->GetClassObject(jni->FindClass(p0.str));
58+ }
59+ exception e {
60+ "JLD:e0*" =>
61+ jni->ThrowException("java.lang.ClassNotFoundException", p0.str);
62+ }
63+
64+ return nil;
6865 }#<<
6966
70−newInstance_rObject( this : JClass) : JObject
67+isAssignableFrom_rClass_Z( this : JClass, p0 : JClass) : int
7168 {#>>
72− if ( this.class.flags & (JNI->ACC_INTERFACE | JNI->ACC_ABSTRACT) ) {
73− s : string;
74− if ( isPrimitive_Z(this) == JNI->TRUE )
75− s = this.class.name[len "inferno/vm/":len this.class.name - 2];
76− else if ( this.aryname != nil )
77− s = this.aryname;
78− else
79− s = this.class.name;
80− jni->ThrowException( "java.lang.InstantiationException", s );
81− }
82− # create new object for the given class
83− return( jni->NewObject(this.class) );
69+ return jni->IsAssignable(p0, this);
8470 }#<<
8571
8672 isInstance_rObject_Z( this : JClass, p0 : JObject) : int
8773 {#>>
88− return( jni->IsInstanceOf( p0, this.class ) );
74+ return jni->IsInstanceOf(p0, this.class);
8975 }#<<
9076
91−isAssignableFrom_rClass_Z( this : JClass, p0 : JClass) : int
77+getModifiers_I( this : JClass) : int
9278 {#>>
93− return( jni->IsAssignable( p0, this ) );
79+ return (this.class.flags & (~ JNI->ACC_SYNCHRONIZED));
9480 }#<<
9581
9682 isInterface_Z( this : JClass) : int
9783 {#>>
98− return( this.class.flags & JNI->ACC_INTERFACE );
84+ return (this.class.flags & JNI->ACC_INTERFACE);
9985 }#<<
10086
10187 isArray_Z( this : JClass) : int
10288 {#>>
103− return( this.class.name == "inferno/vm/Array" );
89+ return (this.class.name == "inferno/vm/Array");
10490 }#<<
10591
10692 isPrimitive_Z( this : JClass) : int
10793 {#>>
108− ret : int;
109− if ( jni->PrimitiveIndex(this, 0) > 0 )
110− ret = JNI->TRUE;
111− else
112− ret = JNI->FALSE;
113− return ret;
94+ ret: int;
95+ if (jni->PrimitiveIndex(this, 0) > 0)
96+ ret = JNI->TRUE;
97+ else
98+ ret = JNI->FALSE;
99+ return ret;
114100 }#<<
115101
116−getName0_rString( this : JClass) : JString
102+getSuperclass_rClass( this : JClass) : JClass
117103 {#>>
118− name : string;
119− if ( isPrimitive_Z(this) == JNI->TRUE )
120− {
121− # mk primitive name from a slice
122− name = this.class.name[len "inferno/vm/":len this.class.name - 2];
123− }
124− else
125− {
126− if ( this.aryname != nil )
127− {
128− name = this.aryname;
129− }
130− else
131− {
132− name = this.class.name;
133− }
134− # change slashes to dots
135− for ( i := 0; i < len name; i++ )
136− if ( name[i] == '/' )
137− name[i] = '.';
138− }
139− return( jni->NewString( name ) );
104+ if (isPrimitive_Z(this) == JNI->TRUE || this.class.flags & JNI->ACC_INTERFACE)
105+ return nil;
106+ if ((superclass := jni->GetSuperclass(this.class)) == nil)
107+ return nil;
108+ return jni->GetClassObject(superclass);
140109 }#<<
141110
142−getClassLoader0_rClassLoader( this : JClass) : JObject
111+getComponentType_rClass( this : JClass) : JClass
143112 {#>>
144− junk := (this);
145− jni->FatalError( "getClassLoader() not implemented" );
146− return(nil);
113+ if(this == nil || this.aryname == nil)
114+ return nil;
115+
116+ name: string;
117+ c := this.aryname[1];
118+ if(c == '[') {
119+ return jni->LookupArrayClass(this.aryname[1:]);
120+ } else {
121+ if(c == 'L') {
122+ name = this.aryname[2:len this.aryname - 1];
123+ } else {
124+ getReflect();
125+ name = "inferno/vm/" + refl->TypeCharToName(c) + "_p";
126+ }
127+ return jni->GetClassObject(jni->FindClass(name));
128+ }
147129 }#<<
148130
149−getSuperclass_rClass( this : JClass) : JClass
131+registerNatives_V( )
150132 {#>>
151− if ( isPrimitive_Z(this) == JNI->TRUE
152− || this.class.flags & JNI->ACC_INTERFACE )
153− return nil;
154− if ( (superclass := jni->GetSuperclass(this.class)) == nil )
155− return nil;
156− return( jni->GetClassObject( superclass ) );
157133 }#<<
158134
159−getInterfaces_aClass( this : JClass) : JArrayJClass
135+getName0_rString( this : JClass) : JString
160136 {#>>
161− n : int;
162− # kludge for arrays to be consistent with JavaSoft's VM
163− if ( isArray_Z(this) )
164− n = 0;
165− else
166− n = len this.class.interdirect;
167− interface := array [n] of JObject;
168− il := this.class.interdirect;
169− for (i := n-1; i >= 0; i--) {
170− interface[i] = cast->FromJClass(jni->GetClassObject(hd il));
171− il = tl il;
172− }
173− classarray := cast->JArrayToClass(cast->ObjectToJArray(jni->MkAObject(interface)));
174− classarray.class = jni->FindClass("java/lang/Class");
175− return classarray;
137+ name: string;
138+ if (isPrimitive_Z(this) == JNI->TRUE) {
139+ name = this.class.name[len "inferno/vm/":len this.class.name - 2];
140+ } else {
141+ if ( this.aryname != nil )
142+ name = this.aryname;
143+ else
144+ name = this.class.name;
145+
146+ # change slashes to dots
147+ for (i := 0; i < len name; i++)
148+ if (name[i] == '/')
149+ name[i] = '.';
150+ }
151+ return jni->NewString(name);
176152 }#<<
177153
178−getComponentType_rClass(this : JClass) : JClass
154+getClassLoader0_rClassLoader( this : JClass) : JObject
179155 {#>>
180− if(this == nil || this.aryname == nil)
181− return nil;
182−
183− name : string;
184− c := this.aryname[1];
185− if(c == '[') {
186− return jni->LookupArrayClass(this.aryname[1:]);
187− } else {
188− if(c == 'L') {
189− name = this.aryname[2:len this.aryname - 1];
190− } else {
191− getReflect();
192− name = "inferno/vm/" + refl->TypeCharToName(c) + "_p";
193− }
194− return jni->GetClassObject(jni->FindClass(name));
195− }
156+ #jni->FatalError("getClassLoader() not implemented");
157+ return nil;
196158 }#<<
197159
198−getModifiers_I( this : JClass) : int
160+getInterfaces_aClass( this : JClass) : JArrayJClass
199161 {#>>
200− return( this.class.flags & (~ JNI->ACC_SYNCHRONIZED));
162+ n: int;
163+ # kludge for arrays to be consistent with JavaSoft's VM
164+ if (isArray_Z(this))
165+ n = 0;
166+ else
167+ n = len this.class.interdirect;
168+ interface := array [n] of JObject;
169+ il := this.class.interdirect;
170+ for (i := n-1; i >= 0; i--) {
171+ interface[i] = cast->FromJClass(jni->GetClassObject(hd il));
172+ il = tl il;
173+ }
174+ classarray := cast->JArrayToClass(cast->ObjectToJArray(jni->MkAObject(interface)));
175+ classarray.class = jni->FindClass("java/lang/Class");
176+ return classarray;
201177 }#<<
202178
203179 getSigners_aObject( this : JClass) : JArrayJObject
204180 {#>>
205− junk := (this);
206− jni->FatalError( "getSigners() not implemented" );
207− return(nil);
181+ #jni->FatalError("getSigners() not implemented");
182+ return nil;
208183 }#<<
209184
210185 setSigners_aObject_V( this : JClass, p0 : JArrayJObject)
211186 {#>>
212− junk := (this,p0);
213− jni->FatalError( "setSigners() not implemented" );
187+ #jni->FatalError("setSigners() not implemented");
188+}#<<
189+
190+getEnclosingMethod0_aObject( this : JClass) : JArrayJObject
191+{#>>
192+ #jni->FatalError("getEnclosingMethod0 is not implemented");
193+ return nil;
194+}#<<
195+
196+getDeclaringClass_rClass( this : JClass) : JClass
197+{#>>
198+ #jni->FatalError("getDeclaringClass is not implemented");
199+ return nil;
200+}#<<
201+
202+getProtectionDomain0_rProtectionDomain( this : JClass) : JObject
203+{#>>
204+ #jni->FatalError("getProtectionDomain is not implemented");
205+ return nil;
206+}#<<
207+
208+setProtectionDomain0_rProtectionDomain_V( this : JClass, p0 : JObject)
209+{#>>
210+ #jni->FatalError("setProtectionDomain is not implemented");
214211 }#<<
215212
216213 getPrimitiveClass_rString_rClass( p0 : JString) : JClass
217214 {#>>
218− {
219− return( jni->GetClassObject(jni->FindClass("inferno/vm/"+ p0.str +"_p")) );
220− }
221− exception e {
222− "JLD:e0*" =>
223− ; # do nothing
224− }
225− return(nil);
215+ {
216+ return jni->GetClassObject(jni->FindClass("inferno/vm/"+ p0.str +"_p"));
217+ }
218+ exception e {
219+ "JLD:e0*" =>
220+ ; # do nothing
221+ }
222+ return nil;
223+}#<<
224+
225+getGenericSignature_rString( this : JClass) : JString
226+{#>>
227+ #jni->FatalError("getGenericSignature is not implemented");
228+ return nil;
229+}#<<
230+
231+getRawAnnotations_aB( this : JClass) : JArrayB
232+{#>>
233+ #jni->FatalError("getRawAnnotations is not implemented");
234+ return nil;
235+}#<<
236+
237+getConstantPool_rConstantPool( this : JClass) : JObject
238+{#>>
239+ # TODO: our j2d does not save the constant pool
240+ jni->FatalError("getConstantPool is not implemented");
241+ return nil;
226242 }#<<
227243
228−getFields0_I_aField( this : JClass, p0 : int) : JArrayJObject
244+getDeclaredFields0_Z_aField( this : JClass, p0 : int) : JArrayJObject
229245 {#>>
230−# 'this' represents the class whose fields are wanted.
231246 # p0 == 0 for PUBLIC members (includes inherited members)
232247 # p0 == 1 for DECLARED members (All members but not inherited members)
233248
234− objs : list of JObject;
235− if ( !isArray_Z(this) )
236− objs = getFields(this, p0);
249+ objs: list of JObject;
250+ if (!isArray_Z(this))
251+ objs = getFields(this, p0);
237252
238253 obj_array := array[len objs] of JObject;
239− for ( i := 0; objs != nil ; i++ ) {
240− obj_array[i] = hd objs;
241− objs = tl objs;
254+ for (i := 0; objs != nil ; i++) {
255+ obj_array[i] = hd objs;
256+ objs = tl objs;
242257 }
243258
244259 fieldarray := jni->MkAObject(obj_array);
@@ -246,24 +261,22 @@ getFields0_I_aField( this : JClass, p0 : int) : JArrayJObject · 1 unmodified line
246261 return fieldarray;
247262 }#<<
248263
249−getMethods0_I_aMethod( this : JClass, p0 : int) : JArrayJObject
264+getDeclaredMethods0_Z_aMethod( this : JClass, p0 : int) : JArrayJObject
250265 {#>>
251−# 'this' represents the class whose methods are wanted.
252266 # p0 == 0 for PUBLIC members (includes inherited members)
253267 # p0 == 1 for DECLARED members (All members but not inherited members)
254268
255− objs : list of JObject;
269+ objs: list of JObject;
256270
257271 # if primitive or interface, filter out java.lang.Object methods
258− if ( isPrimitive_Z(this) == JNI->TRUE
259− || this.class.flags & JNI->ACC_INTERFACE )
260− p0 = 1;
272+ if (isPrimitive_Z(this) == JNI->TRUE || this.class.flags & JNI->ACC_INTERFACE)
273+ p0 = 1;
261274 objs = getMethods(this, p0);
262275
263276 obj_array := array[len objs] of JObject;
264277 for ( i := 0; objs != nil ; i++ ) {
265− obj_array[i] = hd objs;
266− objs = tl objs;
278+ obj_array[i] = hd objs;
279+ objs = tl objs;
267280 }
268281
269282 methodarray := jni->MkAObject(obj_array);
@@ -271,20 +284,19 @@ getMethods0_I_aMethod( this : JClass, p0 : int) : JArrayJObject · 1 unmodified line
271284 return methodarray;
272285 }#<<
273286
274−getConstructors0_I_aConstructor( this : JClass, p0 : int) : JArrayJObject
287+getDeclaredConstructors0_Z_aConstructor( this : JClass, p0 : int) : JArrayJObject
275288 {#>>
276−# 'this' represents the class whose constructors are wanted.
277289 # p0 == 0 for PUBLIC members (includes inherited members)
278290 # p0 == 1 for DECLARED members (All members but not inherited members)
279291
280− objs : list of JObject;
281− if ( isPrimitive_Z(this) == JNI->FALSE && !isArray_Z(this) )
282− objs = getConstructors(this, p0);
292+ objs: list of JObject;
293+ if (isPrimitive_Z(this) == JNI->FALSE && !isArray_Z(this))
294+ objs = getConstructors(this, p0);
283295
284296 obj_array := array[len objs] of JObject;
285297 for ( i := 0; objs != nil ; i++ ) {
286− obj_array[i] = hd objs;
287− objs = tl objs;
298+ obj_array[i] = hd objs;
299+ objs = tl objs;
288300 }
289301
290302 constructorarray := jni->MkAObject(obj_array);
@@ -292,118 +304,16 @@ getConstructors0_I_aConstructor( this : JClass, p0 : int) : JArrayJObject · 1 unmodified line
292304 return constructorarray;
293305 }#<<
294306
295−getField0_rString_I_rField( this : JClass, p0 : JString,p1 : int) : JObject
307+getDeclaredClasses0_aClass( this : JClass) : JArrayJClass
296308 {#>>
297−# 'this' represents the class for which a Field is desired.
298−# p0 is the name of the field.
299−# p1 == 0 for PUBLIC members (includes inherited members)
300−# p1 == 1 for DECLARED members (All members but not inherited members)
301−
302− staticfields := this.class.staticdata;
303− flg : int;
304− fld : ref jldr->Field;
305− for ( i := 0; i < len staticfields; i++ ) {
306− fld = staticfields[i];
307− flg = fld.flags;
308− if ( fld.field == p0.str &&
309− (p1 != 0 || (flg & JNI->ACC_PUBLIC) != 0) )
310− break;
311− }
312− if ( i >= len staticfields ) { # Not a public static field
313− super : list of ref jldr->Field = nil;
314− if ( (superclass := jni->GetSuperclass(this.class)) != nil &&
315− superclass != this.class )
316− super = superclass.objectdata;
317− objfields := this.class.objectdata;
318− for ( i = 0; objfields != nil; i++ ) {
319− if ( p1 == 1 && objfields == super ) # exclude inherited
320− break;
321− fld = hd objfields;
322− flg = fld.flags;
323− if ( fld.field == p0.str &&
324− (p1 != 0 || (flg & JNI->ACC_PUBLIC) != 0) )
325− break;
326− objfields = tl objfields;
327− }
328− if ( objfields == super || objfields == nil )
329− i = len staticfields + len this.class.objectdata;
330− }
331− if ( i >= len staticfields + len this.class.objectdata ) {
332− jni->ThrowException("java/lang/NoSuchFieldException", "");
333− return nil;
334− }
335− return makeField(this, fld, i);
336−}#<<
337−
338−getMethod0_rString_aClass_I_rMethod( this : JClass, p0 : JString,p1 : JArrayJClass,p2 : int) : JObject
339−{#>>
340−# 'this' represents the class for which a Method is desired.
341−# p0 is the name of the method.
342−# p1 is a Java array of Class objects, corresponding to the formal parameters
343−# of the method for which a Method object is desired. The array
344−# is used to construct a signature string which can be matched against
345−# data compiled by the classloader.
346−# p2 == 0 for PUBLIC members (includes inherited members)
347−# p2 == 1 for DECLARED members (All members but not inherited members)
348−
349− signatur := "(" + MakeSignature(p1) + ")";
350−
351− methods := this.class.staticmethods;
352− for ( i := 0; i < len methods; i++ ) {
353− fld := methods[i];
354− if ( fld.field == p0.str && jni->str->prefix(signatur, fld.signature) &&
355− (p2 != 0 || (fld.flags & JNI->ACC_PUBLIC) != 0) )
356− return makeMethod(this, fld, i, p1, fld.signature[len signatur:]);
357− }
358− methods = this.class.privatemethods;
359− for ( i = 0; i < len methods; i++ ) {
360− fld := methods[i];
361− if ( fld.field == p0.str && jni->str->prefix(signatur, fld.signature) &&
362− (p2 != 0 || (fld.flags & JNI->ACC_PUBLIC) != 0) )
363− return makeMethod(this, fld, i, p1, fld.signature[len signatur:]);
364− }
365− vmethods := this.class.virtualmethods;
366− for ( i = 0; i < len vmethods; i++ ) {
367− fld := vmethods[i].field;
368− if ( fld.field == p0.str && jni->str->prefix(signatur, fld.signature) &&
369− ((p2 != 0 && this.class == vmethods[i].class)
370− || (fld.flags & JNI->ACC_PUBLIC) != 0) ) {
371− if ( vmethods[i].class != this.class )
372− this = jni->GetClassObject(vmethods[i].class);
373− return makeMethod(this, fld, i, p1, fld.signature[len signatur:]);
374− }
375− }
376− jni->ThrowException("java/lang/NoSuchMethodException", "");
309+ # TODO: implement
377310 return nil;
378311 }#<<
379312
380−getConstructor0_aClass_I_rConstructor( this : JClass, p0 : JArrayJClass,p1 : int) : JObject
313+desiredAssertionStatus0_rClass_Z( p0 : JClass) : int
381314 {#>>
382−# 'this' represents the class for which a Constructor is desired.
383−# p0 is a Java array of Class objects, corresponding to the formal parameters
384−# of the constructor for which a Constructor object is desired. The array
385−# is used to construct a signature string which can be matched against
386−# data compiled by the classloader.
387−# p1 == 0 for PUBLIC members (includes inherited members)
388−# p1 == 1 for DECLARED members (All members but not inherited members)
389−
390− signatur := "(" + MakeSignature(p0) + ")";
391−
392− initmethods := this.class.initmethods;
393− flg : int;
394− fld : ref jldr->Field;
395− for ( i := 0; i < len initmethods; i++ ) {
396− fld = initmethods[i];
397− flg = fld.flags;
398− if ( jni->str->prefix(signatur, fld.signature) &&
399− (p1 != 0 || (flg & JNI->ACC_PUBLIC) != 0) )
400− break;
401− }
402− if ( i >= len initmethods ) {
403− jni->ThrowException("java/lang/NoSuchMethodException", "");
404− return nil;
405− }
406− return makeMethod(this, fld, i, p0, nil);
315+ #jni->FatalError("desiredAssertionStatus0 is not implemented");
316+ return int 0;
407317 }#<<
408318
409319 #
@@ -417,11 +327,11 @@ getConstructor0_aClass_I_rConstructor( this : JClass, p0 : JArrayJClass,p1 : int · 7 unmodified lines
417327
418328 getPublicStaticFields(this : JClass, objs : list of JObject) : list of JObject
419329 {
420− flds := this.class.staticdata;
421− for ( i := len flds - 1; i >= 0; i-- )
422− if ( (flds[i].flags & JNI->ACC_PUBLIC) != 0 )
423− objs = makeField(this, flds[i], i) :: objs;
424− return objs;
330+ flds := this.class.staticdata;
331+ for ( i := len flds - 1; i >= 0; i-- )
332+ if ( (flds[i].flags & JNI->ACC_PUBLIC) != 0 )
333+ objs = makeField(this, flds[i], i) :: objs;
334+ return objs;
425335 }
426336
427337 #
@@ -433,142 +343,142 @@ ifacelist: list of JClass; · 5 unmodified lines
433343
434344 doInterfaces(this : JClass, objs : list of JObject) : list of JObject
435345 {
436− ifaces := this.class.interfaces;
437−outer: for ( i := 0; i < len ifaces; i++ ) {
438− iface := jni->GetClassObject(ifaces[i].class);
439− for ( l := ifacelist; l != nil; l = tl l )
440− if ( hd l == iface )
441− continue outer;
442− ifacelist = iface :: ifacelist;
443− objs = getPublicStaticFields(iface, objs);
444− objs = doInterfaces(iface, objs);
445− }
446− return objs;
346+ ifaces := this.class.interfaces;
347+outer: for ( i := 0; i < len ifaces; i++ ) {
348+ iface := jni->GetClassObject(ifaces[i].class);
349+ for ( l := ifacelist; l != nil; l = tl l )
350+ if ( hd l == iface )
351+ continue outer;
352+ ifacelist = iface :: ifacelist;
353+ objs = getPublicStaticFields(iface, objs);
354+ objs = doInterfaces(iface, objs);
355+ }
356+ return objs;
447357 }
448358
449359 #
450−# A helper function that gets fields for the class represented
451−# by this. p0 == 0 => PUBLIC fields, p0 == 1 => DECLARED fields.
452−# Candidate fields are found in the loader array staticdata (for
453−# static fields) and list objectdata (for instance fields).
360+# A helper function that gets fields for the class represented
361+# by this. p0 == 0 => PUBLIC fields, p0 == 1 => DECLARED fields.
362+# Candidate fields are found in the loader array staticdata (for
363+# static fields) and list objectdata (for instance fields).
454364 #
455365
456366 getFields(this : JClass, p0 : int) : list of JObject
457367 {
458− objs : list of JObject;
368+ objs: list of JObject;
459369
460370 # get instance fields
461371 objdata := this.class.objectdata;
462372 flds := array[len objdata] of ref jldr->Field;
463373 super : list of ref jldr->Field = nil;
464− if ( (superclass := jni->GetSuperclass(this.class)) != nil )
465− super = superclass.objectdata;
466− for ( i := 0; objdata != nil; i++ ) {
467− if ( p0 == 1 && objdata == super )
468− break;
469− flds[i] = hd objdata;
470− objdata = tl objdata;
374+ if ((superclass := jni->GetSuperclass(this.class)) != nil)
375+ super = superclass.objectdata;
376+ for (i := 0; objdata != nil; i++) {
377+ if (p0 == 1 && objdata == super)
378+ break;
379+ flds[i] = hd objdata;
380+ objdata = tl objdata;
471381 }
472382 # need to associate declaring class with each instance field ???
473− for ( i--; i >= 0; i-- )
474− if ( p0 != 0 || (flds[i].flags & JNI->ACC_PUBLIC) != 0 )
475− objs = makeField(this, flds[i], i) :: objs;
383+ for (i--; i >= 0; i--)
384+ if (p0 != 0 || (flds[i].flags & JNI->ACC_PUBLIC) != 0)
385+ objs = makeField(this, flds[i], i) :: objs;
476386
477387 # get class fields of this class
478388 flds = this.class.staticdata;
479− for ( i = len flds - 1; i >= 0; i-- )
480− if ( p0 != 0 || (flds[i].flags & JNI->ACC_PUBLIC) != 0 )
481− objs = makeField(this, flds[i], i) :: objs;
389+ for (i = len flds - 1; i >= 0; i--)
390+ if (p0 != 0 || (flds[i].flags & JNI->ACC_PUBLIC) != 0)
391+ objs = makeField(this, flds[i], i) :: objs;
482392
483393 # get class fields of super classes and interfaces
484− if ( p0 == 0 ) {
485− ifacelist = nil;
486− objs = doInterfaces(this, objs);
487− curclass := this;
488− while ( ( curclass = getSuperclass_rClass(curclass) ) != nil ) {
489− objs = getPublicStaticFields(curclass, objs);
490− objs = doInterfaces(curclass, objs);
491− }
394+ if (p0 == 0) {
395+ ifacelist = nil;
396+ objs = doInterfaces(this, objs);
397+ curclass := this;
398+ while ((curclass = getSuperclass_rClass(curclass) ) != nil) {
399+ objs = getPublicStaticFields(curclass, objs);
400+ objs = doInterfaces(curclass, objs);
401+ }
492402 }
493403
494404 return objs;
495405 }
496406 #
497−# A helper function that gets methods for the class represented
498−# by this. p0 == 0 => PUBLIC methods, p0 == 1 => DECLARED methods.
499−# Candidate methods are found in the loader arrays staticmethods (for
500−# class methods), privatemethods (for methods private to this
501−# particular class), and virtualmethods (public instance methods of
502−# this class and all its superclasses).
407+# A helper function that gets methods for the class represented
408+# by this. p0 == 0 => PUBLIC methods, p0 == 1 => DECLARED methods.
409+# Candidate methods are found in the loader arrays staticmethods (for
410+# class methods), privatemethods (for methods private to this
411+# particular class), and virtualmethods (public instance methods of
412+# this class and all its superclasses).
503413 #
504414 getMethods(this : JClass, p0 : int) : list of JObject
505415 {
506− objs : list of JObject;
416+ objs: list of JObject;
507417
508418 getReflect();
509419
510420 flds := this.class.staticmethods;
511− for ( i := 0; i < len flds; i++ )
512− if ( p0 != 0 || (flds[i].flags & JNI->ACC_PUBLIC) != 0 )
513− objs = makeAMethod(this, flds[i], i) :: objs;
514−
515− if ( p0 != 0 ) {
516− flds = this.class.privatemethods;
517− for ( i = len flds - 1; i >= 0; i-- )
518− objs = makeAMethod(this, flds[i], i) :: objs;
421+ for (i := 0; i < len flds; i++)
422+ if (p0 != 0 || (flds[i].flags & JNI->ACC_PUBLIC) != 0)
423+ objs = makeAMethod(this, flds[i], i) :: objs;
424+
425+ if (p0 != 0) {
426+ flds = this.class.privatemethods;
427+ for (i = len flds - 1; i >= 0; i--)
428+ objs = makeAMethod(this, flds[i], i) :: objs;
519429 }
520430
521431 vflds := this.class.virtualmethods;
522432 for ( i = len vflds - 1; i >= 0; i-- )
523− if ( (p0 == 1 && vflds[i].class == this.class) # declared, this class
524− || ( p0 == 0 && (vflds[i].field.flags & JNI->ACC_PUBLIC) != 0 ) ) {
525− if ( vflds[i].class != this.class )
526− this = jni->GetClassObject(vflds[i].class);
527− objs = makeAMethod(this, vflds[i].field, i) :: objs;
528− }
433+ if ((p0 == 1 && vflds[i].class == this.class) # declared, this class
434+ || (p0 == 0 && (vflds[i].field.flags & JNI->ACC_PUBLIC) != 0)) {
435+ if (vflds[i].class != this.class)
436+ this = jni->GetClassObject(vflds[i].class);
437+ objs = makeAMethod(this, vflds[i].field, i) :: objs;
438+ }
529439
530440 return objs;
531441 }
532442 #
533−# A helper function that gets constructors for the class represented
534−# by this. p0 == 0 => PUBLIC constructors, p0 == 1 => DECLARED
535−# constructors. Candidate constructors are found in the loader
536−# array initmethods.
443+# A helper function that gets constructors for the class represented
444+# by this. p0 == 0 => PUBLIC constructors, p0 == 1 => DECLARED
445+# constructors. Candidate constructors are found in the loader
446+# array initmethods.
537447 #
538448 getConstructors(this : JClass, p0 : int) : list of JObject
539449 {
540− objs : list of JObject;
450+ objs: list of JObject;
541451
542452 getReflect();
543453
544454 flds := this.class.initmethods;
545− for ( i := len flds - 1; i >= 0; i-- )
546− if ( p0 != 0 || (flds[i].flags & JNI->ACC_PUBLIC) != 0 )
547− objs = makeAMethod(this, flds[i], i) :: objs;
455+ for (i := len flds - 1; i >= 0; i--)
456+ if (p0 != 0 || (flds[i].flags & JNI->ACC_PUBLIC) != 0)
457+ objs = makeAMethod(this, flds[i], i) :: objs;
548458
549459 return objs;
550460 }
551461 #
552−# Make sure Reflect module is loaded.
462+# Make sure Reflect module is loaded.
553463 #
554464 getReflect()
555465 {
556− if ( refl == nil ) {
557− refl = load Reflect Reflect->PATH;
558− if ( refl == nil )
559− jni->InitError( jni->sys->sprint( "java.lang.Class: could not load %s: %r", Reflect->PATH ) );
560− else
561− refl->init(jni);
466+ if (refl == nil) {
467+ refl = load Reflect Reflect->PATH;
468+ if (refl == nil)
469+ jni->InitError(jni->sys->sprint( "java.lang.Class: could not load %s: %r", Reflect->PATH));
470+ else
471+ refl->init(jni);
562472 }
563473 }
564474 #
565−# Construct a Field Object. The field is a member of the class
566−# represented by this, and the loader data for the field is in fld,
567−# which is at offset ix in the appropriate array or list. The 'slot'
568−# elements of a Field_obj adt is used only by native methods, and has
569−# the fields modifier flags in the low-order 16 bits, and the index
570−# into the array/list in the upper 16 bits. (The index into what
571−# depends on the modifier flags.)
475+# Construct a Field Object. The field is a member of the class
476+# represented by this, and the loader data for the field is in fld,
477+# which is at offset ix in the appropriate array or list. The 'slot'
478+# elements of a Field_obj adt is used only by native methods, and has
479+# the fields modifier flags in the low-order 16 bits, and the index
480+# into the array/list in the upper 16 bits. (The index into what
481+# depends on the modifier flags.)
572482 #
573483 makeField(this : JClass, fld : ref jldr->Field, ix : int) : JObject
574484 {
@@ -581,13 +491,13 @@ makeField(this : JClass, fld : ref jldr->Field, ix : int) : JObject · 6 unmodified lines
581491 name := ref Value.TObject(cast->FromJString(jni->NewString(fld.field)));
582492 jni->SetObjField(fldobj, "name", name);
583493
584− class : ref Value;
585− if ( (typ := refl->SigToType(fld.signature)) > 0 )
586− class = refl->GetPrimitiveClass(typ);
494+ class: ref Value;
495+ if ((typ := refl->SigToType(fld.signature)) > 0)
496+ class = refl->GetPrimitiveClass(typ);
587497 else {
588− classname := fld.signature[1:len fld.signature - 1];
589− class = ref Value.TObject(cast->FromJClass(
590− jni->GetClassObject(jni->FindClass(classname))));
498+ classname := fld.signature[1:len fld.signature - 1];
499+ class = ref Value.TObject(cast->FromJClass(
500+ jni->GetClassObject(jni->FindClass(classname))));
591501 }
592502 jni->SetObjField(fldobj, "type", class);
593503
@@ -597,12 +507,12 @@ makeField(this : JClass, fld : ref jldr->Field, ix : int) : JObject · 3 unmodified lines
597507 return fldobj;
598508 }
599509 #
600−# Make a new Method/Constructor object for a method or constructor in
601−# the class this. The loader information for the method/constructor is
602−# found in the loader Field adt fld, which is at offset ix in its
603−# array or list. The signature for the arguments is converted into
604−# a corresponding array of Class objects by makeParamClassArray, then
605−# makeMethod is called to generate the new object.
510+# Make a new Method/Constructor object for a method or constructor in
511+# the class this. The loader information for the method/constructor is
512+# found in the loader Field adt fld, which is at offset ix in its
513+# array or list. The signature for the arguments is converted into
514+# a corresponding array of Class objects by makeParamClassArray, then
515+# makeMethod is called to generate the new object.
606516 #
607517 makeAMethod(this: JClass, fld : ref jldr->Field, ix : int) : JObject
608518 {
@@ -613,68 +523,68 @@ makeAMethod(this: JClass, fld : ref jldr->Field, ix : int) : JObject · 4 unmodified lines
613523 return makeMethod(this, fld, ix, classarray, retsig);
614524 }
615525 #
616−# Construct a Method Object. Also used to make Constructor Objects,
617−# share several elements with Methods. The two can be distinguished
618−# because constructors have the name "<init>" (however, Constructor
619−# Objects do not have a 'name' field, nor do they have a 'returnType'
620−# field. The 'slot' field, which is only used by native methods,
621−# is filled with modifier flags in the lower 16 bits and an index (ix)
622−# into an appropriate loader array/list in the upper 16 bits (which
623−# array can be determined by the modifier flags. ). The arguments
624−# types required by the method are specified by the cl array of
625−# Class ofjects. The return value, if any, is specified by the
626−# signature given in retsig.
526+# Construct a Method Object. Also used to make Constructor Objects,
527+# share several elements with Methods. The two can be distinguished
528+# because constructors have the name "<init>" (however, Constructor
529+# Objects do not have a 'name' field, nor do they have a 'returnType'
530+# field. The 'slot' field, which is only used by native methods,
531+# is filled with modifier flags in the lower 16 bits and an index (ix)
532+# into an appropriate loader array/list in the upper 16 bits (which
533+# array can be determined by the modifier flags. ). The arguments
534+# types required by the method are specified by the cl array of
535+# Class ofjects. The return value, if any, is specified by the
536+# signature given in retsig.
627537 #
628538 makeMethod(this: JClass, fld : ref jldr->Field, ix : int, cl : JArrayJClass,
629− retsig : string) : JObject
539+ retsig : string) : JObject
630540 {
631541 mcl : ClassData;
632542 isConstructor := 0;
633− if ( fld.field == "<init>" )
634− isConstructor = 1;
635− if ( isConstructor )
636− mcl = jni->FindClass("java/lang/reflect/Constructor");
543+ if (fld.field == "<init>")
544+ isConstructor = 1;
545+ if (isConstructor)
546+ mcl = jni->FindClass("java/lang/reflect/Constructor");
637547 else
638− mcl = jni->FindClass("java/lang/reflect/Method");
548+ mcl = jni->FindClass("java/lang/reflect/Method");
639549 methobj := jni->AllocObject(mcl);
640550
641551 clazz := ref Value.TObject(cast->FromJClass(this));
642552 jni->SetObjField(methobj, "clazz", clazz);
643553
644− if ( ! isConstructor ) {
645− name := ref Value.TObject(cast->FromJString(jni->NewString(fld.field)));
646− jni->SetObjField(methobj, "name", name);
554+ if (!isConstructor) {
555+ name := ref Value.TObject(cast->FromJString(jni->NewString(fld.field)));
556+ jni->SetObjField(methobj, "name", name);
647557 }
648558
649559 slot := ref Value.TInt((fld.flags & 16rffff) | (ix << 16));
650560 jni->SetObjField(methobj, "slot", slot);
651561
652− if ( ! isConstructor ) {
653− getReflect();
654− ret : ref Value;
655− if ( (typ := refl->SigToType(retsig)) > 0 )
656− ret = refl->GetPrimitiveClass(typ);
657− else {
658− rclass: JClass;
659− case retsig[0] {
660− 'L' =>
661− rcdata := jni->FindClass(retsig[1:len retsig -1]);
662− rclass = jni->GetClassObject(rcdata);
663− '[' =>
664− rclass = jni->LookupArrayClass(retsig);
665− 'V' =>
666− rcdata := jni->FindClass("inferno/vm/void_p");
667− rclass = jni->GetClassObject(rcdata);
668− }
669− ret = ref Value.TObject(cast->FromJClass(rclass));
670− }
671− jni->SetObjField(methobj, "returnType", ret);
562+ if (!isConstructor) {
563+ getReflect();
564+ ret: ref Value;
565+ if ((typ := refl->SigToType(retsig)) > 0)
566+ ret = refl->GetPrimitiveClass(typ);
567+ else {
568+ rclass: JClass;
569+ case retsig[0] {
570+ 'L' =>
571+ rcdata := jni->FindClass(retsig[1:len retsig -1]);
572+ rclass = jni->GetClassObject(rcdata);
573+ '[' =>
574+ rclass = jni->LookupArrayClass(retsig);
575+ 'V' =>
576+ rcdata := jni->FindClass("inferno/vm/void_p");
577+ rclass = jni->GetClassObject(rcdata);
578+ }
579+ ret = ref Value.TObject(cast->FromJClass(rclass));
580+ }
581+ jni->SetObjField(methobj, "returnType", ret);
672582 }
673583
674584 args := ref Value.TObject(cast->FromJArray(cast->ClassToJArray(cl)));
675585 jni->SetObjField(methobj, "parameterTypes", args);
676586
677− # Don't know how to get the list of exceptions thrown.
587+ # Don't know how to get the list of exceptions thrown.
678588 # jni->SetObjField(methobj, "exceptionTypes", excs);
679589 # Set to a sensible default for now.
680590 foo := cast->JArrayToClass(cast->ObjectToJArray(makeParamClassArray("()")));
@@ -683,104 +593,99 @@ makeMethod(this: JClass, fld : ref jldr->Field, ix : int, cl : JArrayJClass, · 2 unmodified lines
683593 return methobj;
684594 }
685595 #
686−# Turn a signature into an array of Class Objects.
596+# Turn a signature into an array of Class Objects.
687597 #
688598 makeParamClassArray(sig : string) : JArrayJObject
689599 {
690− if ( sig[0] != '(' || sig[len sig -1] != ')' )
691− return nil;
600+ if (sig[0] != '(' || sig[len sig -1] != ')')
601+ return nil;
692602 clist := makeParamClass(sig[1:len sig -1]);
693603 jajcl := array[len clist] of JObject;
694− for ( i := 0; i < len jajcl; i++ ) {
695− jajcl[i] = hd clist;
696− clist = tl clist;
604+ for (i := 0; i < len jajcl; i++) {
605+ jajcl[i] = hd clist;
606+ clist = tl clist;
697607 }
698608 paramclassarray := jni->MkAObject(jajcl);
699609 paramclassarray.class = jni->FindClass("java/lang/Class");
700610 return paramclassarray;
701611 }
702612 #
703−# Recursively turn a signature into a list of JClass
613+# Recursively turn a signature into a list of JClass
704614 #
705615 makeParamClass(sig : string) : list of JObject
706616 {
707− if ( sig == "" )
708− return nil;
617+ if (sig == "")
618+ return nil;
709619
710620 (first, rest) := splitSignature(sig);
711621 jobj: JObject;
712622 case first[0] {
713623 'L' =>
714− first = first[1:len first - 1];
715− newcl := jni->GetClassObject(jni->FindClass(first));
716− jobj = cast->FromJClass(newcl);
624+ first = first[1:len first - 1];
625+ newcl := jni->GetClassObject(jni->FindClass(first));
626+ jobj = cast->FromJClass(newcl);
717627 '[' =>
718− newcl := jni->LookupArrayClass(first);
719− jobj = cast->FromJClass(newcl);
628+ newcl := jni->LookupArrayClass(first);
629+ jobj = cast->FromJClass(newcl);
720630 'Z' or 'B' or 'S' or 'C' or 'I' or 'J' or 'F' or 'D' =>
721− typ := refl->SigToType(first);
722− jobj = refl->GetPrimitiveClass(typ).Object();
631+ typ := refl->SigToType(first);
632+ jobj = refl->GetPrimitiveClass(typ).Object();
723633 * =>
724− return nil;
634+ return nil;
725635 }
726636
727637 return jobj :: makeParamClass(rest);
728638 }
729639 #
730−# Convert an array of JClass to the corresponding signature string.
640+# Convert an array of JClass to the corresponding signature string.
731641 #
732642 MakeSignature(jcl : JArrayJClass) : string
733643 {
734644 clarray: array of JClass;
735− if ( jcl != nil )
736− clarray = jcl.ary;
645+ if (jcl != nil)
646+ clarray = jcl.ary;
737647 sig := "";
738− for ( i := 0; i < len clarray; i++)
739− sig += MakeSingleSignature(clarray[i]);
648+ for (i := 0; i < len clarray; i++)
649+ sig += MakeSingleSignature(clarray[i]);
740650 return sig;
741651 }
742652 #
743−# Convert a Jclass to the corresponding signature.
653+# Convert a Jclass to the corresponding signature.
744654 #
745655 MakeSingleSignature(this : JClass) : string
746656 {
747− if ( (typ := jni->PrimitiveIndex(this, 1)) > 0 ) {
748− getReflect();
749− return refl->TypeToSig(typ);
657+ if ((typ := jni->PrimitiveIndex(this, 1)) > 0) {
658+ getReflect();
659+ return refl->TypeToSig(typ);
750660 }
751661
752− if ( this.aryname != nil )
753− return this.aryname;
662+ if (this.aryname != nil)
663+ return this.aryname;
754664
755665 #
756− # Must be a class type
666+ # Must be a class type
757667 #
758668 return "L" + this.class.name + ";";
759669 }
760670 #
761−# Break a signature into an initial type plus the remainder.
671+# Break a signature into an initial type plus the remainder.
762672 #
763673 splitSignature(sig : string) : (string, string)
764674 {
765675 case sig[0] {
766676 'L' =>
767− for ( i := 1; sig[i] != ';'; i++ ) ;
768− i++;
769− return (sig[0:i], sig[i:]);
677+ for (i := 1; sig[i] != ';'; i++) ;
678+ i++;
679+ return (sig[0:i], sig[i:]);
770680
771− '[' => # recurse to get element type
772− (first, rest) := splitSignature(sig[1:]);
773− return ("[" + first, rest);
681+ '[' => # recurse to get element type
682+ (first, rest) := splitSignature(sig[1:]);
683+ return ("[" + first, rest);
774684
775685 'Z' or 'B' or 'S' or 'C' or 'I' or 'J' or 'F' or 'D' =>
776− return (sig[0:1], sig[1:]);
686+ return (sig[0:1], sig[1:]);
777687 }
778688 return (nil, nil);
779689 }
780690
781691
782−registerNatives_V( )
783−{#>>
784− # currently empty...
785−}#<<
786−
java/pkg/java/lang/Class_L.m+19−14
@@ -1,31 +1,36 @@
1−# javal v1.2 generated file: edit with care
1+# generated file edit with care
22
33 Class_L : module
44 {
55
66 init : fn( jni_p : JNI );
7− forName0_rString_Z_rClassLoader_rClass : fn( p0 : JString, p1 : int, p2 : JObject ) : JClass;
8− newInstance_rObject : fn( this : JClass) : JObject;
9− isInstance_rObject_Z : fn( this : JClass, p0 : JObject) : int;
7+ forName0_rString_Z_rClassLoader_rClass : fn( p0 : JString,p1 : int,p2 : JObject) : JClass;
108 isAssignableFrom_rClass_Z : fn( this : JClass, p0 : JClass) : int;
9+ isInstance_rObject_Z : fn( this : JClass, p0 : JObject) : int;
10+ getModifiers_I : fn( this : JClass) : int;
1111 isInterface_Z : fn( this : JClass) : int;
1212 isArray_Z : fn( this : JClass) : int;
1313 isPrimitive_Z : fn( this : JClass) : int;
14+ getSuperclass_rClass : fn( this : JClass) : JClass;
15+ getComponentType_rClass : fn( this : JClass) : JClass;
16+ registerNatives_V : fn( );
1417 getName0_rString : fn( this : JClass) : JString;
1518 getClassLoader0_rClassLoader : fn( this : JClass) : JObject;
16− getSuperclass_rClass : fn( this : JClass) : JClass;
1719 getInterfaces_aClass : fn( this : JClass) : JArrayJClass;
18− getComponentType_rClass : fn( this : JClass) : JClass;
19− getModifiers_I : fn( this : JClass) : int;
2020 getSigners_aObject : fn( this : JClass) : JArrayJObject;
2121 setSigners_aObject_V : fn( this : JClass, p0 : JArrayJObject);
22+ getEnclosingMethod0_aObject : fn( this : JClass) : JArrayJObject;
23+ getDeclaringClass_rClass : fn( this : JClass) : JClass;
24+ getProtectionDomain0_rProtectionDomain : fn( this : JClass) : JObject;
25+ setProtectionDomain0_rProtectionDomain_V : fn( this : JClass, p0 : JObject);
2226 getPrimitiveClass_rString_rClass : fn( p0 : JString) : JClass;
23− getFields0_I_aField : fn( this : JClass, p0 : int) : JArrayJObject;
24− getMethods0_I_aMethod : fn( this : JClass, p0 : int) : JArrayJObject;
25− getConstructors0_I_aConstructor : fn( this : JClass, p0 : int) : JArrayJObject;
26− getField0_rString_I_rField : fn( this : JClass, p0 : JString,p1 : int) : JObject;
27− getMethod0_rString_aClass_I_rMethod : fn( this : JClass, p0 : JString,p1 : JArrayJClass,p2 : int) : JObject;
28− getConstructor0_aClass_I_rConstructor : fn( this : JClass, p0 : JArrayJClass,p1 : int) : JObject;
29− registerNatives_V : fn( );
27+ getGenericSignature_rString : fn( this : JClass) : JString;
28+ getRawAnnotations_aB : fn( this : JClass) : JArrayB;
29+ getConstantPool_rConstantPool : fn( this : JClass) : JObject;
30+ getDeclaredFields0_Z_aField : fn( this : JClass, p0 : int) : JArrayJObject;
31+ getDeclaredMethods0_Z_aMethod : fn( this : JClass, p0 : int) : JArrayJObject;
32+ getDeclaredConstructors0_Z_aConstructor : fn( this : JClass, p0 : int) : JArrayJObject;
33+ getDeclaredClasses0_aClass : fn( this : JClass) : JArrayJClass;
34+ desiredAssertionStatus0_rClass_Z : fn( p0 : JClass) : int;
3035
3136 };