01: /*
02: * $Id: LocalVariableStatement.java,v 1.5 2002/09/16 08:05:06 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.script.statements;
11:
12: import anvil.Location;
13: import anvil.core.Any;
14: import anvil.codec.Code;
15: import anvil.codec.ConstantPool;
16: import anvil.doc.Doc;
17: import anvil.script.LocalVariableType;
18: import anvil.script.expression.Expression;
19: import anvil.script.compiler.ByteCompiler;
20: import java.io.IOException;
21:
22: /**
23: * class LocalVariableStatement
24: *
25: * @author: Jani Lehtimäki
26: */
27: public class LocalVariableStatement extends VariableStatement implements
28: LocalVariableType {
29:
30: protected int _slot = -1;
31: protected int _index;
32: protected boolean _escaped = false;
33: protected FunctionStatement _function;
34:
35: public LocalVariableStatement(Location location,
36: FunctionStatement function, String name) {
37: super (location, function, name, Expression.UNDEFINED,
38: (Doc) null);
39: _function = function;
40: }
41:
42: public int getType() {
43: return LOCAL_VARIABLE;
44: }
45:
46: public int getSlot() {
47: if (_slot == -1) {
48: _slot = _function.getNextLocalSlot();
49: }
50: return _slot;
51: }
52:
53: public int getIndex() {
54: return _index;
55: }
56:
57: public int getFrameIndex() {
58: return _function.getFrameIndex();
59: }
60:
61: public boolean isEscaped() {
62: return _escaped;
63: }
64:
65: public void markEscaped() {
66: _escaped = true;
67: _function.markEscaped();
68: getSlot();
69: }
70:
71: public void compile(ByteCompiler context) {
72: Code code = context.getCode();
73: _index = code.addLocal();
74: if (!_escaped) {
75: code.getstatic(code.getPool().addFieldRef(context.TYPE_ANY,
76: "UNDEFINED", "Lanvil/core/Any;"));
77: code.astore(_index);
78: }
79: }
80:
81: public int getTypeRef(ConstantPool pool) {
82: return 0;
83: }
84:
85: }
|