01: /*
02: * $Id: DynamicHasNode.java,v 1.3 2002/09/16 08:05:04 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.codec.ConstantPool;
15: import anvil.script.compiler.ByteCompiler;
16: import anvil.script.Context;
17: import java.io.IOException;
18:
19: /**
20: * class HasNode
21: *
22: * @author: Jani Lehtimäki
23: */
24: public class DynamicHasNode extends BinaryParent {
25:
26: public DynamicHasNode(Node left, Node right) {
27: super (left, right);
28: }
29:
30: public int typeOf() {
31: return Node.EXPR_HAS;
32: }
33:
34: public Any eval() {
35: return _left.eval().has(_right.eval().toString()) ? Any.TRUE
36: : Any.FALSE;
37: }
38:
39: public void compile(ByteCompiler context, int operation) {
40: Code code = context.getCode();
41: ConstantPool pool = code.getPool();
42: _left.compile(context, GET);
43: _right.compile(context, GET);
44: code.invokevirtual(pool.addMethodRef(context.TYPE_OBJECT,
45: "toString", "()Ljava/lang/String;"));
46: code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "has",
47: "(Ljava/lang/String;)Z"));
48: if (operation != GET_BOOLEAN) {
49: context.boolean2any();
50: }
51: }
52:
53: }
|