XorNode.java :  » Web-Framework » anvil » anvil » script » expression » Java Open Source

Java Open Source » Web Framework » anvil 
anvil » anvil » script » expression » XorNode.java
/*
 * $Id: XorNode.java,v 1.5 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.codec.ConstantPool;
import anvil.codec.Source;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import java.io.IOException;

/**
 * class XorNode
 *
 * @author: Jani Lehtimki
 */
public class XorNode extends BinaryParent
{

  public XorNode(Node left, Node right) 
  {
    super(left,right);
  }


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


  public Any eval() 
  {
    boolean a = _left.eval().toBoolean();
    boolean b = _right.eval().toBoolean();
    return a != b ? Any.TRUE : Any.FALSE;
  }



  public void compile(ByteCompiler context, int operation)
  {
    super.compile(context, GET_BOOLEAN);
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    Source notequal = code.if_icmpne();
    if (operation == GET_BOOLEAN) {
      code.iconst(false);
    } else {
      code.getstatic(pool.addFieldRef(context.TYPE_ANY, "FALSE", "Lanvil/core/Any;"));
    }
    Source toend = code.go_to();
    notequal.bind();
    if (operation == GET_BOOLEAN) {
      code.iconst(true);
    } else {
      code.getstatic(pool.addFieldRef(context.TYPE_ANY, "TRUE", "Lanvil/core/Any;"));
    }
    toend.bind();
  }
  

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.