01: /*
02: * $Id: MemberVariableNode.java,v 1.19 2002/09/16 08:05:05 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.script.expression;
11:
12: import anvil.core.Any;
13: import anvil.core.AnyClass;
14: import anvil.ErrorListener;
15: import anvil.script.ClassType;
16: import anvil.codec.Code;
17: import anvil.codec.ConstantPool;
18: import anvil.script.compiler.ByteCompiler;
19: import anvil.script.Context;
20: import anvil.script.Type;
21: import anvil.script.MemberVariableType;
22: import java.io.IOException;
23:
24: /**
25: * class MemberVariableNode
26: *
27: * @author: Jani Lehtimäki
28: */
29: public class MemberVariableNode extends Node {
30:
31: protected ClassType _target;
32: protected ClassType _context;
33: protected MemberVariableType _member;
34:
35: public MemberVariableNode(ClassType context,
36: MemberVariableType member) {
37: this (member.getClassType(), context, member);
38: }
39:
40: public MemberVariableNode(ClassType target, ClassType context,
41: MemberVariableType member) {
42: super ();
43: _target = target;
44: _context = context;
45: _member = member;
46: }
47:
48: public int typeOf() {
49: return Node.EXPR_VARIABLE;
50: }
51:
52: public boolean isConstant() {
53: return false;
54: }
55:
56: public Node optimize() {
57: return this ;
58: }
59:
60: public void compile(ByteCompiler context, Node child) {
61: Code code = context.getCode();
62: ConstantPool pool = code.getPool();
63: context.accessInstance(_context, _target);
64: child.compile(context, GET);
65: code.dup_x1();
66: code.putfield(_member.getTypeRef(pool));
67: }
68:
69: public void compile(ByteCompiler context, int operation) {
70: Code code = context.getCode();
71: ConstantPool pool = code.getPool();
72: switch (operation) {
73: case GET:
74: context.accessInstance(_context, _target);
75: code.getfield(_member.getTypeRef(pool));
76: break;
77:
78: case GET_BOOLEAN:
79: context.accessInstance(_context, _target);
80: code.getfield(_member.getTypeRef(pool));
81: context.any2boolean();
82: break;
83:
84: case CHECK:
85: context.accessInstance(_context, _target);
86: code.getfield(_member.getTypeRef(pool));
87: break;
88:
89: case DELETE:
90: code.iconst(false);
91: break;
92: }
93:
94: }
95:
96: }
|