Package anvil.script.expression

Source Code of anvil.script.expression.ConditionalNode

/*
* $Id: ConditionalNode.java,v 1.6 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.core.Any;
import anvil.codec.Code;
import anvil.codec.Source;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import java.io.IOException;

/**
* class ConditionalNode
*
* @author: Jani Lehtim�ki
*/
public class ConditionalNode extends MultiParent
{

  public ConditionalNode(Node left, Node middle, Node right)
  {
    super(3);
    setChild(0, left);
    setChild(1, middle);
    setChild(2, right);
  }


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


  public Any eval()
  {
    Any result = getChild(0).eval();
    if (result.toBoolean()) {
      return getChild(1).eval();
    } else {
      return getChild(2).eval();
    }
  }


  public void compile(ByteCompiler context, int operation)
  {
    getChild(0).compile(context, GET_BOOLEAN);
    Code code = context.getCode();
    Source isfalse = code.if_eq();
    getChild(1).compile(context, operation);
    Source out = code.go_to();
    code.popop();
    isfalse.bind();
    getChild(2).compile(context, operation);
    out.bind();
  }

}
TOP

Related Classes of anvil.script.expression.ConditionalNode

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.