001: /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
002: *
003: * ***** BEGIN LICENSE BLOCK *****
004: * Version: MPL 1.1/GPL 2.0
005: *
006: * The contents of this file are subject to the Mozilla Public License Version
007: * 1.1 (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: * http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the
014: * License.
015: *
016: * The Original Code is Rhino code, released
017: * May 6, 1999.
018: *
019: * The Initial Developer of the Original Code is
020: * Netscape Communications Corporation.
021: * Portions created by the Initial Developer are Copyright (C) 1997-2000
022: * the Initial Developer. All Rights Reserved.
023: *
024: * Contributor(s):
025: * Norris Boyd
026: * Bob Jervis
027: * Roger Lawrence
028: *
029: * Alternatively, the contents of this file may be used under the terms of
030: * the GNU General Public License Version 2 or later (the "GPL"), in which
031: * case the provisions of the GPL are applicable instead of those above. If
032: * you wish to allow use of your version of this file only under the terms of
033: * the GPL and not to allow others to use your version of this file under the
034: * MPL, indicate your decision by deleting the provisions above and replacing
035: * them with the notice and other provisions required by the GPL. If you do
036: * not delete the provisions above, a recipient may use your version of this
037: * file under either the MPL or the GPL.
038: *
039: * ***** END LICENSE BLOCK ***** */
040:
041: package org.mozilla.javascript;
042:
043: import java.io.Serializable;
044:
045: import org.mozilla.javascript.debug.DebuggableScript;
046:
047: final class InterpreterData implements Serializable, DebuggableScript {
048: static final long serialVersionUID = 5067677351589230234L;
049:
050: static final int INITIAL_MAX_ICODE_LENGTH = 1024;
051: static final int INITIAL_STRINGTABLE_SIZE = 64;
052: static final int INITIAL_NUMBERTABLE_SIZE = 64;
053:
054: InterpreterData(int languageVersion, String sourceFile,
055: String encodedSource) {
056: this .languageVersion = languageVersion;
057: this .itsSourceFile = sourceFile;
058: this .encodedSource = encodedSource;
059:
060: init();
061: }
062:
063: InterpreterData(InterpreterData parent) {
064: this .parentData = parent;
065: this .languageVersion = parent.languageVersion;
066: this .itsSourceFile = parent.itsSourceFile;
067: this .encodedSource = parent.encodedSource;
068:
069: init();
070: }
071:
072: private void init() {
073: itsICode = new byte[INITIAL_MAX_ICODE_LENGTH];
074: itsStringTable = new String[INITIAL_STRINGTABLE_SIZE];
075: }
076:
077: String itsName;
078: String itsSourceFile;
079: boolean itsNeedsActivation;
080: int itsFunctionType;
081:
082: String[] itsStringTable;
083: double[] itsDoubleTable;
084: InterpreterData[] itsNestedFunctions;
085: Object[] itsRegExpLiterals;
086:
087: byte[] itsICode;
088:
089: int[] itsExceptionTable;
090:
091: int itsMaxVars;
092: int itsMaxLocals;
093: int itsMaxStack;
094: int itsMaxFrameArray;
095:
096: // see comments in NativeFuncion for definition of argNames and argCount
097: String[] argNames;
098: boolean[] argIsConst;
099: int argCount;
100:
101: int itsMaxCalleeArgs;
102:
103: String encodedSource;
104: int encodedSourceStart;
105: int encodedSourceEnd;
106:
107: int languageVersion;
108:
109: boolean useDynamicScope;
110:
111: boolean topLevel;
112:
113: Object[] literalIds;
114:
115: UintMap longJumps;
116:
117: int firstLinePC = -1; // PC for the first LINE icode
118:
119: InterpreterData parentData;
120:
121: boolean evalScriptFlag; // true if script corresponds to eval() code
122:
123: public boolean isTopLevel() {
124: return topLevel;
125: }
126:
127: public boolean isFunction() {
128: return itsFunctionType != 0;
129: }
130:
131: public String getFunctionName() {
132: return itsName;
133: }
134:
135: public int getParamCount() {
136: return argCount;
137: }
138:
139: public int getParamAndVarCount() {
140: return argNames.length;
141: }
142:
143: public String getParamOrVarName(int index) {
144: return argNames[index];
145: }
146:
147: public boolean getParamOrVarConst(int index) {
148: return argIsConst[index];
149: }
150:
151: public String getSourceName() {
152: return itsSourceFile;
153: }
154:
155: public boolean isGeneratedScript() {
156: return ScriptRuntime.isGeneratedScript(itsSourceFile);
157: }
158:
159: public int[] getLineNumbers() {
160: return Interpreter.getLineNumbers(this );
161: }
162:
163: public int getFunctionCount() {
164: return (itsNestedFunctions == null) ? 0
165: : itsNestedFunctions.length;
166: }
167:
168: public DebuggableScript getFunction(int index) {
169: return itsNestedFunctions[index];
170: }
171:
172: public DebuggableScript getParent() {
173: return parentData;
174: }
175:
176: }
|