Package anvil.script.expression

Source Code of anvil.script.expression.ConstantVariableNode

/*
* $Id: ConstantVariableNode.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 anvil.ErrorListener;
import anvil.script.ConstantVariableType;
import anvil.script.Type;
import anvil.script.statements.ModuleStatement;
import java.io.IOException;

/**
* class ConstantVariableNode
*
* @author: Jani Lehtim�ki
*/
public class ConstantVariableNode extends Node
{

  protected ConstantVariableType _constant;


  public ConstantVariableNode(ConstantVariableType constant)
  {
    super();
    _constant = constant;
  }

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


  public boolean isConstant()
  {
    return _constant.hasConstantInitializer();
  }

 
  public Node optimize()
  {
    return this;
  }


  public Any eval()
  {
    return _constant.getValue();
  }


  public void compile(ByteCompiler context, Node child)
  {
    child.compile(context, GET);
    Code code = context.getCode();
    code.dup();
    code.putstatic(_constant.getTypeRef(code.getPool()));
  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    int field = _constant.getTypeRef(context.getPool());
    switch(operation) {
    case GET:
    case CHECK:
      if (isConstant()) {
        context.constant(_constant.getValue(), false);
      } else {
        code.getstatic(field);
      }
      break;

    case GET_BOOLEAN:
      if (isConstant()) {
        code.iconst(_constant.getValue().toBoolean());
      } else {
        code.getstatic(field);
        context.any2boolean();
      }
      break;

    case DELETE:
      code.iconst(false);
      break;
   
  }

}
TOP

Related Classes of anvil.script.expression.ConstantVariableNode

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.