01: /*
02: * $Id: ReferenceNode.java,v 1.9 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.codec.Code;
14: import anvil.script.compiler.ByteCompiler;
15: import anvil.script.Context;
16: import java.io.IOException;
17:
18: /**
19: * class ReferenceNode
20: *
21: * @author: Jani Lehtimäki
22: */
23: public class ReferenceNode extends BinaryParent {
24:
25: public ReferenceNode(Node self, Node index) {
26: super (self, index);
27: }
28:
29: public int typeOf() {
30: return EXPR_REFERENCE;
31: }
32:
33: public boolean isConstant() {
34: return false;
35: }
36:
37: public Node optimize() {
38: optimizeChilds();
39: return this ;
40: }
41:
42: public void compile(ByteCompiler context, int operation) {
43: Code code = context.getCode();
44: switch (operation) {
45: case GET:
46: _left.compile(context, GET);
47: code.aload_first();
48: _right.compile(context, GET);
49: code
50: .invokevirtual(code
51: .getPool()
52: .addMethodRef(context.TYPE_ANY,
53: "getReference",
54: "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;"));
55: break;
56:
57: case GET_BOOLEAN:
58: _left.compile(context, GET);
59: code.aload_first();
60: _right.compile(context, GET);
61: code
62: .invokevirtual(code
63: .getPool()
64: .addMethodRef(context.TYPE_ANY,
65: "getReference",
66: "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;"));
67: context.any2boolean();
68: break;
69:
70: case CHECK:
71: _left.compile(context, GET);
72: code.aload_first();
73: _right.compile(context, GET);
74: code
75: .invokevirtual(code
76: .getPool()
77: .addMethodRef(context.TYPE_ANY,
78: "checkReference",
79: "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;"));
80: break;
81:
82: case DELETE:
83: _left.compile(context, GET);
84: code.aload_first();
85: _right.compile(context, GET);
86: code.invokevirtual(code.getPool().addMethodRef(
87: context.TYPE_ANY, "deleteReference",
88: "(Lanvil/script/Context;Lanvil/core/Any;)Z"));
89: break;
90: }
91: }
92:
93: }
|