01: package gnu.expr;
02:
03: import gnu.bytecode.*;
04:
05: public class BindingInitializer extends Initializer {
06: Declaration decl;
07: Expression value;
08:
09: static final Method makeBindingMethod = Compilation.typeBinding
10: .getDeclaredMethod("make", Compilation.string1Arg);
11:
12: public BindingInitializer(Declaration decl, Field field,
13: Expression value) {
14: this .decl = decl;
15: this .value = value;
16: this .field = field;
17: }
18:
19: boolean createNewBinding = false;
20:
21: public void emit(Compilation comp) {
22: CodeAttr code = comp.getCode();
23:
24: if (value instanceof QuoteExp) {
25: Object val = ((QuoteExp) value).getValue();
26: if (val == null || val instanceof String)
27: return;
28: Literal lit = comp.findLiteral(val);
29: if (lit.field == this .field)
30: return;
31: }
32:
33: if (!field.getStaticFlag())
34: code.emitPushThis();
35:
36: if (value == null) {
37: // FIXME - this should be cached in a local Variable:
38: if (!createNewBinding)
39: code.emitInvokeStatic(comp.getCurrentEnvironmentMethod);
40:
41: String name = decl.getName();
42: if (name == null)
43: code.emitPushNull();
44: else
45: code.emitPushString(name);
46: if (createNewBinding)
47: code.emitInvokeStatic(makeBindingMethod);
48: else
49: code
50: .emitInvokeVirtual(comp.getBindingEnvironmentMethod);
51: } else {
52: value.compile(comp, field.getType());
53: }
54:
55: if (field.getStaticFlag())
56: code.emitPutStatic(field);
57: else
58: code.emitPutField(field);
59: }
60: }
|