KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > reflect > ArrayLength


1 package gnu.kawa.reflect;
2 import gnu.bytecode.*;
3 import gnu.mapping.*;
4 import gnu.expr.*;
5 import java.io.*;
6
7 public class ArrayLength
8   extends Procedure1
9   implements Inlineable, Externalizable
10 {
11   Type element_type;
12
13   public ArrayLength (Type element_type)
14   {
15     this.element_type = element_type;
16   }
17
18   public Object JavaDoc apply1 (Object JavaDoc array)
19   {
20     return gnu.math.IntNum.make(java.lang.reflect.Array.getLength(array));
21   }
22
23   public void compile (ApplyExp exp, Compilation comp, Target target)
24   {
25     exp.getArgs()[0].compile(comp, ArrayType.make(element_type));
26     CodeAttr code = comp.getCode();
27     code.emitArrayLength();
28     target.compileFromStack(comp, gnu.kawa.lispexpr.LangPrimType.intType);
29   }
30
31   public gnu.bytecode.Type getReturnType (Expression[] args)
32   {
33     return gnu.kawa.lispexpr.LangPrimType.intType;
34   }
35
36   public void writeExternal(ObjectOutput out) throws IOException
37   {
38     out.writeObject(element_type);
39   }
40
41   public void readExternal(ObjectInput in)
42     throws IOException, ClassNotFoundException JavaDoc
43   {
44     element_type = (Type) in.readObject();
45   }
46 }
47
Popular Tags