01: package gnu.expr;
02:
03: import gnu.bytecode.*;
04:
05: /** Evaluates to the "this" implicit variable.
06: * This is currently neither robust nor general. FIXME!
07: */
08:
09: public class ThisExp extends ReferenceExp {
10: /** The class which this refers to. */
11: Expression context;
12:
13: public ThisExp() {
14: super ("$this$");
15: }
16:
17: public ThisExp(Expression context) {
18: super ("$this$");
19: this .context = context;
20: }
21:
22: public ThisExp(Declaration binding) {
23: super ("$this", binding);
24: }
25:
26: public ThisExp(ClassType type) {
27: this (new Declaration("this", type));
28: }
29:
30: public void compile(Compilation comp, Target target) {
31: // If we have been captured, load ourselve the hard way.
32: if (binding != null && binding.field != null)
33: binding.load(comp);
34: else
35: comp.getCode().emitPushThis();
36: target.compileFromStack(comp, comp.getCode().topType());
37: }
38:
39: protected Expression walk(ExpWalker walker) {
40: return walker.walkThisExp(this );
41: }
42:
43: public final gnu.bytecode.Type getType() {
44: if (binding != null)
45: return binding.getType();
46: if (context != null && context instanceof ClassExp)
47: return ((ClassExp) context).getType();
48: return Type.pointer_type;
49: }
50: }
|