Package anvil.script.expression

Source Code of anvil.script.expression.RefNode

/*
* $Id: RefNode.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.Location;
import anvil.ErrorListener;
import anvil.core.Any;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.script.compiler.ByteCompiler;
import anvil.script.Context;
import anvil.script.statements.LocalVariableStatement;
import java.io.IOException;

/**
* class RefNode
*
* @author: Jani Lehtim�ki
*/
public class RefNode extends UnaryParent
{

  protected Location _location;
  protected boolean  _isassignment;

  public RefNode(Location location, Node child, boolean isassignment)
  {
    super(child);
    _location = location;
    _isassignment = isassignment;
  }


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

  public boolean isConstant()
  {
    return false;
  }


  public void check(ErrorListener listener)
  {
    super.check(listener);
    if (!_isassignment) {
      Node child = _child;
      if (child instanceof VariableNode) {
        ((VariableNode)child).getVariable().markEscaped();
       
      } else if (child instanceof EscapedVariableNode) {
        // pass
       
      } else {
        listener.error(_location, "Right side of '&' does not point to local variable");
      }
    }
  }


  public void compile(ByteCompiler context, Node child)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    _child.compile(context, GET);
    child.compile(context, GET);
    code.dup_x1();
    code.invokevirtual(pool.addMethodRef(context.TYPE_ANY, "setRef",
      "(Lanvil/core/Any;)V"));
  }


  public void compile(ByteCompiler context, int operation)
  {
    Code code = context.getCode();
    ConstantPool pool = code.getPool();
    switch(operation) {
    case GET:
    case CHECK:
      _child.compile(context, GET_REF);
      break;
     
    case GET_BOOLEAN:
      _child.compile(context, GET_BOOLEAN);
      break;
 
    case DELETE:
      code.iconst(false);
      break;
    }
  }

}
TOP

Related Classes of anvil.script.expression.RefNode

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.