01: // Copyright (c) 2001 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.expr;
05:
06: import gnu.bytecode.*;
07:
08: /** Cause a class value from a ClassExp to be initialized. */
09:
10: public class ClassInitializer extends Initializer {
11: ClassExp cexp;
12:
13: public ClassInitializer(ClassExp cexp, Compilation comp) {
14: field = cexp.allocFieldFor(comp);
15: this .cexp = cexp;
16: if (field.getStaticFlag()) {
17: next = comp.clinitChain;
18: comp.clinitChain = this ;
19: } else {
20: LambdaExp heapLambda = cexp.getHeapLambda();
21: next = heapLambda.initChain;
22: heapLambda.initChain = this ;
23: }
24: }
25:
26: public void emit(Compilation comp) {
27: CodeAttr code = comp.getCode();
28: if (!field.getStaticFlag())
29: code.emitPushThis();
30: cexp.compile(comp, Target.pushValue(Compilation.typeClassType));
31: if (field.getStaticFlag())
32: code.emitPutStatic(field);
33: else
34: code.emitPutField(field);
35: }
36: }
|