Package anvil.script.expression

Source Code of anvil.script.expression.InstanceOfNode

/*
* $Id: InstanceOfNode.java,v 1.5 2002/09/16 08:05:04 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.script.expression;

import anvil.Location;
import anvil.core.Any;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.ErrorListener;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import anvil.script.Type;
import java.io.IOException;

/**
* class IsNode
*
* @author: Jani Lehtim�ki
*/
public class InstanceOfNode extends BinaryParent
{

  protected Location _location;

  public InstanceOfNode(Node left, Node right, Location location)
  {
    super(left, right);
    _location = location;
  }


  public int typeOf()
  {
    return Node.EXPR_IS;
  }
 

  public boolean isConstant()
  {
    return false;
  }
 

  public void check(ErrorListener context)
  {
    super.check(context);
    if (_right instanceof TypeNode) {
      int type = ((TypeNode)_right).getType().getType();
      if (type == Type.CLASS || type == Type.INTERFACE) {
        return;
      }
    }
    context.error(_location, "Right side of 'is' does not point into class or interface");
  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    _left.compile(context, GET);
    _right.compile(context, GET_TYPE);
    code.invokevirtual(pool.addMethodRef(context.TYPE_ANY,
      "isInstanceOf", "(Lanvil/script/Type;)Z"));
    if (operation != GET_BOOLEAN) {
      context.boolean2any();
    }
  }

}
TOP

Related Classes of anvil.script.expression.InstanceOfNode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.