KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > expr > ClassInitializer


1 // Copyright (c) 2001 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.expr;
5 import gnu.bytecode.*;
6
7 /** Cause a class value from a ClassExp to be initialized. */
8
9 public class ClassInitializer extends Initializer
10 {
11   ClassExp cexp;
12
13   public ClassInitializer(ClassExp cexp, Compilation comp)
14   {
15     field = cexp.allocFieldFor(comp);
16     cexp.compile (comp);
17     this.cexp = cexp;
18     if (field.getStaticFlag())
19       {
20     next = comp.clinitChain;
21     comp.clinitChain = this;
22       }
23     else
24       {
25     LambdaExp heapLambda = cexp.getOwningLambda();
26     next = heapLambda.initChain;
27     heapLambda.initChain = this;
28       }
29   }
30
31   public void emit(Compilation comp)
32   {
33     CodeAttr code = comp.getCode();
34     if (! field.getStaticFlag())
35       code.emitPushThis();
36     cexp.compilePushClass(comp, Target.pushValue(Compilation.typeClassType));
37     if (field.getStaticFlag())
38       code.emitPutStatic(field);
39     else
40       code.emitPutField(field);
41   }
42 }
43
Popular Tags