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

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

/**
 * class ConstantNode
 *
 * @author: Jani Lehtimki
 */
public class ConstantNode extends Node 
{

  public static final ConstantNode NULL = new ConstantNode(Any.NULL);
  public static final ConstantNode UNDEFINED = new ConstantNode(Any.UNDEFINED);
  public static final ConstantNode TRUE = new ConstantNode(Any.TRUE);
  public static final ConstantNode FALSE = new ConstantNode(Any.FALSE);
  public static final ConstantNode INF = new ConstantNode(Any.INF);
  public static final ConstantNode NEG_INF = new ConstantNode(Any.NEG_INF);
  public static final ConstantNode SPACE = new ConstantNode(Any.create(" "));

  private Any _const;
  private String _image = null;


  public ConstantNode() 
  {
    _const = Any.NULL;
  }


  public ConstantNode(Any constant) 
  {
    super();
    _const = constant;
  }  


  public ConstantNode(String image, long number) 
  {
    super();
    _const = Any.create(number);
    _image = image;
  }  


  public ConstantNode(String string) 
  {
    super();
    _const = Any.create(string);
  }


  public ConstantNode(boolean bool) 
  {
    super();
    _const = Any.create(bool);
  }
  

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

  
  public boolean isConstant() 
  {
    return true;
  }


  public String getImage()
  {
    return _image;
  }

  
  public Node optimize() 
  {
    return this;
  }  
  
  
  public String toString()
  {
    return super.toString()+ '(' + _const.toAnvil() + ')';
  }
   
   
  public Any eval() 
  {
    return (Any)_const.copy();
  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    if (operation == GET_BOOLEAN) { 
      code.iconst(_const.toBoolean());
    } else {
      context.constant(_const, true);
    }
  }

}
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.