/*
* $Id: LocalVariableStatement.java,v 1.5 2002/09/16 08:05:06 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.statements;
import anvil.Location;
import anvil.core.Any;
import anvil.codec.Code;
import anvil.codec.ConstantPool;
import anvil.doc.Doc;
import anvil.script.LocalVariableType;
import anvil.script.expression.Expression;
import anvil.script.compiler.ByteCompiler;
import java.io.IOException;
/**
* class LocalVariableStatement
*
* @author: Jani Lehtim�ki
*/
public class LocalVariableStatement extends VariableStatement implements LocalVariableType
{
protected int _slot = -1;
protected int _index;
protected boolean _escaped = false;
protected FunctionStatement _function;
public LocalVariableStatement(Location location, FunctionStatement function, String name)
{
super(location, function, name, Expression.UNDEFINED, (Doc)null);
_function = function;
}
public int getType()
{
return LOCAL_VARIABLE;
}
public int getSlot()
{
if (_slot == -1) {
_slot = _function.getNextLocalSlot();
}
return _slot;
}
public int getIndex()
{
return _index;
}
public int getFrameIndex()
{
return _function.getFrameIndex();
}
public boolean isEscaped()
{
return _escaped;
}
public void markEscaped()
{
_escaped = true;
_function.markEscaped();
getSlot();
}
public void compile(ByteCompiler context)
{
Code code = context.getCode();
_index = code.addLocal();
if (!_escaped) {
code.getstatic(code.getPool().addFieldRef(context.TYPE_ANY, "UNDEFINED", "Lanvil/core/Any;"));
code.astore(_index);
}
}
public int getTypeRef(ConstantPool pool)
{
return 0;
}
}