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: cexp.compile(comp);
16: this .cexp = cexp;
17: if (field.getStaticFlag()) {
18: next = comp.clinitChain;
19: comp.clinitChain = this ;
20: } else {
21: LambdaExp heapLambda = cexp.getOwningLambda();
22: next = heapLambda.initChain;
23: heapLambda.initChain = this ;
24: }
25: }
26:
27: public void emit(Compilation comp) {
28: CodeAttr code = comp.getCode();
29: if (!field.getStaticFlag())
30: code.emitPushThis();
31: cexp.compilePushClass(comp, Target
32: .pushValue(Compilation.typeClassType));
33: if (field.getStaticFlag())
34: code.emitPutStatic(field);
35: else
36: code.emitPutField(field);
37: }
38: }
|