01: /*
02: * $Id: RefNode.java,v 1.5 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.Location;
13: import anvil.ErrorListener;
14: import anvil.core.Any;
15: import anvil.codec.Code;
16: import anvil.codec.ConstantPool;
17: import anvil.script.compiler.ByteCompiler;
18: import anvil.script.Context;
19: import anvil.script.statements.LocalVariableStatement;
20: import java.io.IOException;
21:
22: /**
23: * class RefNode
24: *
25: * @author: Jani Lehtimäki
26: */
27: public class RefNode extends UnaryParent {
28:
29: protected Location _location;
30: protected boolean _isassignment;
31:
32: public RefNode(Location location, Node child, boolean isassignment) {
33: super (child);
34: _location = location;
35: _isassignment = isassignment;
36: }
37:
38: public int typeOf() {
39: return Node.EXPR_VARIABLE;
40: }
41:
42: public boolean isConstant() {
43: return false;
44: }
45:
46: public void check(ErrorListener listener) {
47: super .check(listener);
48: if (!_isassignment) {
49: Node child = _child;
50: if (child instanceof VariableNode) {
51: ((VariableNode) child).getVariable().markEscaped();
52:
53: } else if (child instanceof EscapedVariableNode) {
54: // pass
55:
56: } else {
57: listener
58: .error(_location,
59: "Right side of '&' does not point to local variable");
60: }
61: }
62: }
63:
64: public void compile(ByteCompiler context, Node child) {
65: Code code = context.getCode();
66: ConstantPool pool = code.getPool();
67: _child.compile(context, GET);
68: child.compile(context, GET);
69: code.dup_x1();
70: code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
71: "setRef", "(Lanvil/core/Any;)V"));
72: }
73:
74: public void compile(ByteCompiler context, int operation) {
75: Code code = context.getCode();
76: ConstantPool pool = code.getPool();
77: switch (operation) {
78: case GET:
79: case CHECK:
80: _child.compile(context, GET_REF);
81: break;
82:
83: case GET_BOOLEAN:
84: _child.compile(context, GET_BOOLEAN);
85: break;
86:
87: case DELETE:
88: code.iconst(false);
89: break;
90: }
91: }
92:
93: }
|