01: /*
02: * $Id: InstanceOfNode.java,v 1.5 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.Location;
13: import anvil.core.Any;
14: import anvil.codec.Code;
15: import anvil.codec.ConstantPool;
16: import anvil.ErrorListener;
17: import anvil.script.compiler.ByteCompiler;
18: import anvil.script.Context;
19: import anvil.script.Type;
20: import java.io.IOException;
21:
22: /**
23: * class IsNode
24: *
25: * @author: Jani Lehtimäki
26: */
27: public class InstanceOfNode extends BinaryParent {
28:
29: protected Location _location;
30:
31: public InstanceOfNode(Node left, Node right, Location location) {
32: super (left, right);
33: _location = location;
34: }
35:
36: public int typeOf() {
37: return Node.EXPR_IS;
38: }
39:
40: public boolean isConstant() {
41: return false;
42: }
43:
44: public void check(ErrorListener context) {
45: super .check(context);
46: if (_right instanceof TypeNode) {
47: int type = ((TypeNode) _right).getType().getType();
48: if (type == Type.CLASS || type == Type.INTERFACE) {
49: return;
50: }
51: }
52: context
53: .error(_location,
54: "Right side of 'is' does not point into class or interface");
55: }
56:
57: public void compile(ByteCompiler context, int operation) {
58: Code code = context.getCode();
59: ConstantPool pool = code.getPool();
60: _left.compile(context, GET);
61: _right.compile(context, GET_TYPE);
62: code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
63: "isInstanceOf", "(Lanvil/script/Type;)Z"));
64: if (operation != GET_BOOLEAN) {
65: context.boolean2any();
66: }
67: }
68:
69: }
|