~davewalker/etherpad/ubuntu-unlimited-max-users-and-revisions

« back to all changes in this revision

Viewing changes to infrastructure/rhino1_7R1/src/org/mozilla/javascript/ScriptOrFnNode.java

  • Committer: James Page
  • Date: 2011-04-13 08:00:43 UTC
  • Revision ID: james.page@canonical.com-20110413080043-eee2nq7y1v7cv2mp
* Refactoring to use native Ubuntu Java libraries. 
* debian/control:
  - use openjdk instead of sun's java
  - update maintainer
* debian/etherpad.init.orig, debian/etherpad.upstart:
  - move the init script out of the way
  - create a basic upstart script
  - note that the open office document conversion daemon was dropped
    from the upstart configuration; if this behavior is desired, please
    create a separate upstart job for it
* debian/rules:
  - just use basic dh_installinit, as it will pick up the new upstart job
* New release
* Changed maintainer to Packaging
* Fixed installation scripts
* Initial Release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * ***** BEGIN LICENSE BLOCK *****
 
4
 * Version: MPL 1.1/GPL 2.0
 
5
 *
 
6
 * The contents of this file are subject to the Mozilla Public License Version
 
7
 * 1.1 (the "License"); you may not use this file except in compliance with
 
8
 * the License. You may obtain a copy of the License at
 
9
 * http://www.mozilla.org/MPL/
 
10
 *
 
11
 * Software distributed under the License is distributed on an "AS IS" basis,
 
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
13
 * for the specific language governing rights and limitations under the
 
14
 * License.
 
15
 *
 
16
 * The Original Code is Rhino code, released
 
17
 * May 6, 1999.
 
18
 *
 
19
 * The Initial Developer of the Original Code is
 
20
 * Netscape Communications Corporation.
 
21
 * Portions created by the Initial Developer are Copyright (C) 1997-1999
 
22
 * the Initial Developer. All Rights Reserved.
 
23
 *
 
24
 * Contributor(s):
 
25
 *   Igor Bukanov
 
26
 *   Bob Jervis
 
27
 *   Norris Boyd
 
28
 *
 
29
 * Alternatively, the contents of this file may be used under the terms of
 
30
 * the GNU General Public License Version 2 or later (the "GPL"), in which
 
31
 * case the provisions of the GPL are applicable instead of those above. If
 
32
 * you wish to allow use of your version of this file only under the terms of
 
33
 * the GPL and not to allow others to use your version of this file under the
 
34
 * MPL, indicate your decision by deleting the provisions above and replacing
 
35
 * them with the notice and other provisions required by the GPL. If you do
 
36
 * not delete the provisions above, a recipient may use your version of this
 
37
 * file under either the MPL or the GPL.
 
38
 *
 
39
 * ***** END LICENSE BLOCK ***** */
 
40
 
 
41
package org.mozilla.javascript;
 
42
 
 
43
import java.util.ArrayList;
 
44
 
 
45
public class ScriptOrFnNode extends Node.Scope {
 
46
 
 
47
    public ScriptOrFnNode(int nodeType) {
 
48
        super(nodeType);
 
49
        symbols = new ArrayList(4);
 
50
        setParent(null);
 
51
    }
 
52
 
 
53
    public final String getSourceName() { return sourceName; }
 
54
 
 
55
    public final void setSourceName(String sourceName) {
 
56
        this.sourceName = sourceName;
 
57
    }
 
58
 
 
59
    public final int getEncodedSourceStart() { return encodedSourceStart; }
 
60
 
 
61
    public final int getEncodedSourceEnd() { return encodedSourceEnd; }
 
62
 
 
63
    public final void setEncodedSourceBounds(int start, int end) {
 
64
        this.encodedSourceStart = start;
 
65
        this.encodedSourceEnd = end;
 
66
    }
 
67
 
 
68
    public final int getBaseLineno() { return this.lineno; }
 
69
 
 
70
    public final void setBaseLineno(int lineno) {
 
71
        // One time action
 
72
        if (lineno < 0 || this.lineno >= 0) Kit.codeBug();
 
73
        this.lineno = lineno;
 
74
    }
 
75
 
 
76
    public final int getEndLineno() { return endLineno; }
 
77
 
 
78
    public final void setEndLineno(int lineno) {
 
79
        // One time action
 
80
        if (lineno < 0 || endLineno >= 0) Kit.codeBug();
 
81
        endLineno = lineno;
 
82
    }
 
83
 
 
84
    public final int getFunctionCount() {
 
85
        if (functions == null) { return 0; }
 
86
        return functions.size();
 
87
    }
 
88
 
 
89
    public final FunctionNode getFunctionNode(int i) {
 
90
        return (FunctionNode)functions.get(i);
 
91
    }
 
92
 
 
93
    public final int addFunction(FunctionNode fnNode) {
 
94
        if (fnNode == null) Kit.codeBug();
 
95
        if (functions == null) { functions = new ObjArray(); }
 
96
        functions.add(fnNode);
 
97
        return functions.size() - 1;
 
98
    }
 
99
 
 
100
    public final int getRegexpCount() {
 
101
        if (regexps == null) { return 0; }
 
102
        return regexps.size() / 2;
 
103
    }
 
104
 
 
105
    public final String getRegexpString(int index) {
 
106
        return (String)regexps.get(index * 2);
 
107
    }
 
108
 
 
109
    public final String getRegexpFlags(int index) {
 
110
        return (String)regexps.get(index * 2 + 1);
 
111
    }
 
112
 
 
113
    /*APPJET*/public final int getRegexpLineno(int index) {
 
114
        return (Integer)regexpLinenos.get(index);
 
115
    }
 
116
 
 
117
    public final int addRegexp(String string, String flags, /*APPJET*/
 
118
                               int lineno) {
 
119
        if (string == null) Kit.codeBug();
 
120
        if (regexps == null) {
 
121
            /*APPJET*/
 
122
            regexps = new ObjArray();
 
123
            regexpLinenos = new ObjArray();
 
124
        }
 
125
        regexps.add(string);
 
126
        regexps.add(flags);
 
127
        /*APPJET*/regexpLinenos.add(lineno);
 
128
        return regexps.size() / 2 - 1;
 
129
    }
 
130
 
 
131
    public int getIndexForNameNode(Node nameNode) {
 
132
        if (variableNames == null) throw Kit.codeBug();
 
133
        Node.Scope node = nameNode.getScope();
 
134
        Symbol symbol = node == null ? null 
 
135
                                     : node.getSymbol(nameNode.getString());
 
136
        if (symbol == null)
 
137
            return -1;
 
138
        return symbol.index;
 
139
    }
 
140
 
 
141
    public final String getParamOrVarName(int index) {
 
142
        if (variableNames == null) throw Kit.codeBug();
 
143
        return variableNames[index];
 
144
    }
 
145
 
 
146
    public final int getParamCount() {
 
147
        return paramCount;
 
148
    }
 
149
 
 
150
    public final int getParamAndVarCount() {
 
151
        if (variableNames == null) throw Kit.codeBug();
 
152
        return symbols.size();
 
153
    }
 
154
 
 
155
    public final String[] getParamAndVarNames() {
 
156
        if (variableNames == null) throw Kit.codeBug();
 
157
        return variableNames;
 
158
    }
 
159
 
 
160
    public final boolean[] getParamAndVarConst() {
 
161
        if (variableNames == null) throw Kit.codeBug();
 
162
        return isConsts;
 
163
    }
 
164
 
 
165
    void addSymbol(Symbol symbol) {
 
166
        if (variableNames != null) throw Kit.codeBug();
 
167
        if (symbol.declType == Token.LP) {
 
168
            paramCount++;
 
169
        }
 
170
        symbols.add(symbol);
 
171
    }
 
172
 
 
173
    /**
 
174
     * Assign every symbol a unique integer index. Generate arrays of variable 
 
175
     * names and constness that can be indexed by those indices.
 
176
     * 
 
177
     * @param flattenAllTables if true, flatten all symbol tables, included
 
178
     * nested block scope symbol tables. If false, just flatten the script's
 
179
     * or function's symbol table.
 
180
     */
 
181
    void flattenSymbolTable(boolean flattenAllTables) {
 
182
        if (!flattenAllTables) {
 
183
            ArrayList newSymbols = new ArrayList();
 
184
            if (this.symbolTable != null) {
 
185
                // Just replace "symbols" with the symbols in this object's
 
186
                // symbol table. Can't just work from symbolTable map since
 
187
                // we need to retain duplicate parameters.
 
188
                for (int i=0; i < symbols.size(); i++) {
 
189
                    Symbol symbol = (Symbol) symbols.get(i);
 
190
                    if (symbol.containingTable == this) {
 
191
                        newSymbols.add(symbol);
 
192
                    }
 
193
                }
 
194
            }
 
195
            symbols = newSymbols;
 
196
        }
 
197
        variableNames = new String[symbols.size()];
 
198
        isConsts = new boolean[symbols.size()];
 
199
        for (int i=0; i < symbols.size(); i++) {
 
200
            Symbol symbol = (Symbol) symbols.get(i);
 
201
            variableNames[i] = symbol.name;
 
202
            isConsts[i] = symbol.declType == Token.CONST;
 
203
            symbol.index = i;
 
204
        }
 
205
    }
 
206
 
 
207
    public final Object getCompilerData()
 
208
    {
 
209
        return compilerData;
 
210
    }
 
211
 
 
212
    public final void setCompilerData(Object data)
 
213
    {
 
214
        if (data == null) throw new IllegalArgumentException();
 
215
        // Can only call once
 
216
        if (compilerData != null) throw new IllegalStateException();
 
217
        compilerData = data;
 
218
    }
 
219
    
 
220
    public String getNextTempName()
 
221
    {
 
222
        return "$" + tempNumber++;
 
223
    }
 
224
 
 
225
    private int encodedSourceStart;
 
226
    private int encodedSourceEnd;
 
227
    private String sourceName;
 
228
    private int endLineno = -1;
 
229
 
 
230
    private ObjArray functions;
 
231
    private ObjArray regexps;
 
232
    /*APPJET*/ private ObjArray regexpLinenos;
 
233
    
 
234
    private ArrayList symbols;
 
235
    private int paramCount = 0;
 
236
    private String[] variableNames;
 
237
    private boolean[] isConsts;
 
238
 
 
239
    private Object compilerData;
 
240
    private int tempNumber = 0;
 
241
}