/*
* $Id: UnaryMinusNode.java,v 1.6 2002/09/16 08:05:05 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.core.Any;
import anvil.codec.Code;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import java.io.IOException;
/**
* class UnaryMinusNode
*
* @author: Jani Lehtim�ki
*/
public class UnaryMinusNode extends UnaryParent
{
public UnaryMinusNode(Node child)
{
super(child);
}
public int typeOf()
{
return Node.EXPR_UNARY_MINUS;
}
public Node optimize()
{
int count = 1;
Node child = _child;
while(child.typeOf() == EXPR_UNARY_MINUS) {
count++;
child = ((UnaryMinusNode)child).getChild();
}
if (count % 2 == 0) {
return child;
} else {
_child = child;
return this;
}
}
public Any eval()
{
return _child.eval().minus();
}
public void compile(ByteCompiler context, int operation)
{
_child.compile(context, GET);
Code code = context.getCode();
code.invokevirtual(code.getPool().addMethodRef(context.TYPE_ANY,
"minus", "()Lanvil/core/Any;"));
if (operation == GET_BOOLEAN) {
context.any2boolean();
}
}
}