16147
|
1 |
/*
|
16151
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
|
16147
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.nashorn.internal.ir;
|
|
27 |
|
|
28 |
import java.io.PrintWriter;
|
|
29 |
import jdk.nashorn.internal.codegen.types.Type;
|
|
30 |
import jdk.nashorn.internal.runtime.options.Options;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Maps a name to specific data.
|
|
34 |
*/
|
|
35 |
|
|
36 |
public final class Symbol implements Comparable<Symbol> {
|
|
37 |
/** Symbol flags. Kind ordered by precedence. */
|
|
38 |
public static final int IS_TEMP = 0b0000_0001;
|
|
39 |
/** Is this Global */
|
|
40 |
public static final int IS_GLOBAL = 0b0000_0010;
|
|
41 |
/** Is this a variable */
|
|
42 |
public static final int IS_VAR = 0b0000_0011;
|
|
43 |
/** Is this a parameter */
|
|
44 |
public static final int IS_PARAM = 0b0000_0100;
|
|
45 |
/** Is this a constant */
|
|
46 |
public static final int IS_CONSTANT = 0b0000_0101;
|
|
47 |
|
|
48 |
static final int KINDMASK = 0b0000_1111;
|
|
49 |
|
|
50 |
/** Is this scope */
|
|
51 |
public static final int IS_SCOPE = 0b0000_0001_0000;
|
|
52 |
/** Is this a this symbol */
|
|
53 |
public static final int IS_THIS = 0b0000_0010_0000;
|
|
54 |
/** Can this symbol ever be undefined */
|
|
55 |
public static final int CAN_BE_UNDEFINED = 0b0000_0100_0000;
|
|
56 |
/** Can this symbol ever have primitive types */
|
|
57 |
public static final int CAN_BE_PRIMITIVE = 0b0000_1000_0000;
|
|
58 |
/** Is this a let */
|
|
59 |
public static final int IS_LET = 0b0001_0000_0000;
|
|
60 |
/** Is this an internal symbol, never represented explicitly in source code */
|
|
61 |
public static final int IS_INTERNAL = 0b0010_0000_0000;
|
|
62 |
|
|
63 |
/** Null or name identifying symbol. */
|
|
64 |
private final String name;
|
|
65 |
|
|
66 |
/** Symbol flags. */
|
|
67 |
private int flags;
|
|
68 |
|
|
69 |
/** Defining node. */
|
|
70 |
private Node node;
|
|
71 |
|
|
72 |
/** Definition block. */
|
|
73 |
private final Block block;
|
|
74 |
|
|
75 |
/** Type of symbol. */
|
|
76 |
private Type type;
|
|
77 |
|
|
78 |
/** Local variable slot. -1 indicates external property. */
|
|
79 |
private int slot;
|
|
80 |
|
|
81 |
/** Field number in scope or property. */
|
|
82 |
private int fieldIndex;
|
|
83 |
|
|
84 |
/** Number of times this symbol is used in code */
|
|
85 |
private int useCount;
|
|
86 |
|
|
87 |
/** Debugging option - dump info and stack trace when a symbol with a given name is manipulated */
|
|
88 |
private static final String TRACE_SYMBOL = Options.getStringProperty("nashorn.compiler.symbol.trace", null);
|
|
89 |
|
|
90 |
/**
|
|
91 |
* Constructor
|
|
92 |
*
|
|
93 |
* @param name name of symbol
|
|
94 |
* @param flags symbol flags
|
|
95 |
* @param node node this symbol is in
|
|
96 |
* @param block block this symbol is in
|
|
97 |
* @param type type of this symbol
|
|
98 |
* @param slot bytecode slot for this symbol
|
|
99 |
*/
|
|
100 |
protected Symbol(final String name, final int flags, final Node node, final Block block, final Type type, final int slot) {
|
|
101 |
this.name = name;
|
|
102 |
this.flags = flags;
|
|
103 |
this.node = node;
|
|
104 |
this.block = block;
|
|
105 |
this.type = type;
|
|
106 |
this.slot = slot;
|
|
107 |
this.fieldIndex = -1;
|
|
108 |
}
|
|
109 |
|
|
110 |
/**
|
|
111 |
* Constructor
|
|
112 |
*
|
|
113 |
* @param name name of symbol
|
|
114 |
* @param flags symbol flags
|
|
115 |
* @param node node this symbol is in
|
|
116 |
* @param block block this symbol is in
|
|
117 |
*/
|
|
118 |
public Symbol(final String name, final int flags, final Node node, final Block block) {
|
|
119 |
this(name, flags, node, block, Type.UNKNOWN, -1);
|
|
120 |
}
|
|
121 |
|
|
122 |
/**
|
|
123 |
* Constructor
|
|
124 |
*
|
|
125 |
* @param name name of symbol
|
|
126 |
* @param flags symbol flags
|
|
127 |
* @param type type of this symbol
|
|
128 |
*/
|
|
129 |
public Symbol(final String name, final int flags, final Type type) {
|
|
130 |
this(name, flags, null, null, type, -1);
|
|
131 |
}
|
|
132 |
|
|
133 |
private static String align(final String string, final int max) {
|
|
134 |
final StringBuilder sb = new StringBuilder();
|
|
135 |
sb.append(string.substring(0, Math.min(string.length(), max)));
|
|
136 |
|
|
137 |
while (sb.length () < max) {
|
|
138 |
sb.append(' ');
|
|
139 |
}
|
|
140 |
return sb.toString();
|
|
141 |
}
|
|
142 |
|
|
143 |
/**
|
|
144 |
* Return the type for this symbol. Normally, if there is no type override,
|
|
145 |
* this is where any type for any node is stored. If the node has a TypeOverride,
|
|
146 |
* it may override this, e.g. when asking for a scoped field as a double
|
|
147 |
*
|
|
148 |
* @return symbol type
|
|
149 |
*/
|
|
150 |
public final Type getSymbolType() {
|
|
151 |
return type;
|
|
152 |
}
|
|
153 |
|
|
154 |
/**
|
|
155 |
* Debugging .
|
|
156 |
*
|
|
157 |
* @param stream Stream to print to.
|
|
158 |
*/
|
|
159 |
|
|
160 |
void print(final PrintWriter stream) {
|
|
161 |
final String printName = align(name, 20);
|
|
162 |
final String printType = align(type.toString(), 10);
|
|
163 |
final String printSlot = align(slot == -1 ? "none" : "" + slot, 10);
|
|
164 |
String printFlags = "";
|
|
165 |
|
|
166 |
switch (flags & KINDMASK) {
|
|
167 |
case IS_TEMP:
|
|
168 |
printFlags = "temp " + printFlags;
|
|
169 |
break;
|
|
170 |
case IS_GLOBAL:
|
|
171 |
printFlags = "global " + printFlags;
|
|
172 |
break;
|
|
173 |
case IS_VAR:
|
|
174 |
printFlags = "var " + printFlags;
|
|
175 |
break;
|
|
176 |
case IS_PARAM:
|
|
177 |
printFlags = "param " + printFlags;
|
|
178 |
break;
|
|
179 |
case IS_CONSTANT:
|
|
180 |
printFlags = "CONSTANT " + printFlags;
|
|
181 |
break;
|
|
182 |
default:
|
|
183 |
break;
|
|
184 |
}
|
|
185 |
|
|
186 |
if (isScope()) {
|
|
187 |
printFlags += "scope ";
|
|
188 |
}
|
|
189 |
|
|
190 |
if (isInternal()) {
|
|
191 |
printFlags += "internal ";
|
|
192 |
}
|
|
193 |
|
|
194 |
if (isLet()) {
|
|
195 |
printFlags += "let ";
|
|
196 |
}
|
|
197 |
|
|
198 |
if (isThis()) {
|
|
199 |
printFlags += "this ";
|
|
200 |
}
|
|
201 |
|
|
202 |
if (!canBeUndefined()) {
|
|
203 |
printFlags += "always_def ";
|
|
204 |
}
|
|
205 |
|
|
206 |
if (canBePrimitive()) {
|
|
207 |
printFlags += "can_be_prim ";
|
|
208 |
}
|
|
209 |
|
|
210 |
stream.print(printName + ": " + printType + ", " + printSlot + ", " + printFlags);
|
|
211 |
stream.println();
|
|
212 |
}
|
|
213 |
|
|
214 |
/**
|
|
215 |
* Compare the the symbol kind with another.
|
|
216 |
*
|
|
217 |
* @param other Other symbol's flags.
|
|
218 |
* @return True if symbol has less kind.
|
|
219 |
*/
|
|
220 |
public boolean less(final int other) {
|
|
221 |
return (flags & KINDMASK) < (other & KINDMASK);
|
|
222 |
}
|
|
223 |
|
|
224 |
/**
|
|
225 |
* Allocate a slot for this symbol.
|
|
226 |
*
|
|
227 |
* @param needsSlot True if symbol needs a slot.
|
|
228 |
*/
|
|
229 |
public void setNeedsSlot(final boolean needsSlot) {
|
|
230 |
setSlot(needsSlot ? 0 : -1);
|
|
231 |
}
|
|
232 |
|
|
233 |
/**
|
|
234 |
* Return the number of slots required for the symbol.
|
|
235 |
*
|
|
236 |
* @return Number of slots.
|
|
237 |
*/
|
|
238 |
public int slotCount() {
|
|
239 |
return type.isCategory2() ? 2 : 1;
|
|
240 |
}
|
|
241 |
|
|
242 |
/**
|
|
243 |
* Return the defining function (scope.)
|
|
244 |
*
|
|
245 |
* @return Defining function.
|
|
246 |
*/
|
|
247 |
public FunctionNode findFunction() {
|
|
248 |
return block != null ? block.getFunction() : null;
|
|
249 |
}
|
|
250 |
|
|
251 |
@Override
|
|
252 |
public boolean equals(final Object other) {
|
|
253 |
if (!(other instanceof Symbol)) {
|
|
254 |
return false;
|
|
255 |
}
|
|
256 |
final Symbol symbol = (Symbol) other;
|
|
257 |
return name.equals(symbol.name) && block.equals(symbol.block);
|
|
258 |
}
|
|
259 |
|
|
260 |
@Override
|
|
261 |
public int hashCode() {
|
|
262 |
return name.hashCode() ^ block.hashCode();
|
|
263 |
}
|
|
264 |
|
|
265 |
@Override
|
|
266 |
public String toString() {
|
|
267 |
final StringBuilder sb = new StringBuilder();
|
|
268 |
final String desc = getSymbolType().getDescriptor();
|
|
269 |
|
|
270 |
sb.append(name).
|
|
271 |
append(' ').
|
|
272 |
append("(type=").
|
|
273 |
append(desc.charAt(desc.length() - 1) == ';' ? 'O' : desc).
|
|
274 |
append(')');
|
|
275 |
|
|
276 |
if (hasSlot()) {
|
|
277 |
sb.append(' ').
|
|
278 |
append('(').
|
|
279 |
append("slot=").
|
|
280 |
append(slot).
|
|
281 |
append(')');
|
|
282 |
}
|
|
283 |
|
|
284 |
if (isScope()) {
|
|
285 |
sb.append(" S");
|
|
286 |
}
|
|
287 |
|
|
288 |
if (canBePrimitive()) {
|
|
289 |
sb.append(" P?");
|
|
290 |
}
|
|
291 |
|
|
292 |
return sb.toString();
|
|
293 |
}
|
|
294 |
|
|
295 |
@Override
|
|
296 |
public int compareTo(final Symbol other) {
|
|
297 |
return name.compareTo(other.name);
|
|
298 |
}
|
|
299 |
|
|
300 |
/**
|
|
301 |
* Does this symbol have an allocated bytecode slot. If not, it is scope
|
|
302 |
* and must be loaded from memory upon access
|
|
303 |
*
|
|
304 |
* @return true if this symbol has a local bytecode slot
|
|
305 |
*/
|
|
306 |
public boolean hasSlot() {
|
|
307 |
return slot >= 0;
|
|
308 |
}
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Check if this is a temporary symbol
|
|
312 |
* @return true if temporary
|
|
313 |
*/
|
|
314 |
public boolean isTemp() {
|
|
315 |
return (flags & KINDMASK) == IS_TEMP;
|
|
316 |
}
|
|
317 |
|
|
318 |
/**
|
|
319 |
* Check if this is a symbol in scope. Scope symbols cannot, for obvious reasons
|
|
320 |
* be stored in byte code slots on the local frame
|
|
321 |
*
|
|
322 |
* @return true if this is scoped
|
|
323 |
*/
|
|
324 |
public boolean isScope() {
|
|
325 |
assert ((flags & KINDMASK) != IS_GLOBAL) || ((flags & IS_SCOPE) == IS_SCOPE) : "global without scope flag";
|
|
326 |
return (flags & IS_SCOPE) == IS_SCOPE;
|
|
327 |
}
|
|
328 |
|
|
329 |
/**
|
|
330 |
* Flag this symbol as scope as described in {@link Symbol#isScope()}
|
|
331 |
*/
|
|
332 |
public void setIsScope() {
|
|
333 |
flags |= IS_SCOPE;
|
|
334 |
getBlock().setNeedsScope(true);
|
|
335 |
}
|
|
336 |
|
|
337 |
/**
|
|
338 |
* Check if this symbol is a variable
|
|
339 |
* @return true if variable
|
|
340 |
*/
|
|
341 |
public boolean isVar() {
|
|
342 |
return (flags & KINDMASK) == IS_VAR;
|
|
343 |
}
|
|
344 |
|
|
345 |
/**
|
|
346 |
* Check if this symbol is a global (undeclared) variable
|
|
347 |
* @return true if global
|
|
348 |
*/
|
|
349 |
public boolean isGlobal() {
|
|
350 |
return (flags & KINDMASK) == IS_GLOBAL;
|
|
351 |
}
|
|
352 |
|
|
353 |
/**
|
|
354 |
* Check if this symbol is a function parameter
|
|
355 |
* @return true if parameter
|
|
356 |
*/
|
|
357 |
public boolean isParam() {
|
|
358 |
return (flags & KINDMASK) == IS_PARAM;
|
|
359 |
}
|
|
360 |
|
|
361 |
/**
|
|
362 |
* Check whether this symbol ever has primitive assignments. Conservative
|
|
363 |
* @return true if primitive assignments exist
|
|
364 |
*/
|
|
365 |
public boolean canBePrimitive() {
|
|
366 |
return (flags & CAN_BE_PRIMITIVE) == CAN_BE_PRIMITIVE;
|
|
367 |
}
|
|
368 |
|
|
369 |
/**
|
|
370 |
* Check if this symbol can ever be undefined
|
|
371 |
* @return true if can be undefined
|
|
372 |
*/
|
|
373 |
public boolean canBeUndefined() {
|
|
374 |
return (flags & CAN_BE_UNDEFINED) == CAN_BE_UNDEFINED;
|
|
375 |
}
|
|
376 |
|
|
377 |
/**
|
|
378 |
* Flag this symbol as potentially undefined in parts of the program
|
|
379 |
*/
|
|
380 |
public void setCanBeUndefined() {
|
|
381 |
assert type.isObject() : type;
|
|
382 |
flags |= CAN_BE_UNDEFINED;
|
|
383 |
}
|
|
384 |
|
|
385 |
/**
|
|
386 |
* Flag this symbol as potentially primitive
|
|
387 |
* @param type the primitive type it occurs with, currently unused but can be used for width guesses
|
|
388 |
*/
|
|
389 |
public void setCanBePrimitive(final Type type) {
|
|
390 |
flags |= CAN_BE_PRIMITIVE;
|
|
391 |
}
|
|
392 |
|
|
393 |
/**
|
|
394 |
* Check if this symbol is a constant
|
|
395 |
* @return true if a constant
|
|
396 |
*/
|
|
397 |
public boolean isConstant() {
|
|
398 |
return (flags & KINDMASK) == IS_CONSTANT;
|
|
399 |
}
|
|
400 |
|
|
401 |
/**
|
|
402 |
* Check if this is an internal symbol, without an explicit JavaScript source
|
|
403 |
* code equivalent
|
|
404 |
* @return true if internal
|
|
405 |
*/
|
|
406 |
public boolean isInternal() {
|
|
407 |
return (flags & IS_INTERNAL) != 0;
|
|
408 |
}
|
|
409 |
|
|
410 |
/**
|
|
411 |
* Check if this symbol represents {@code this}
|
|
412 |
* @return true if this
|
|
413 |
*/
|
|
414 |
public boolean isThis() {
|
|
415 |
return (flags & IS_THIS) != 0;
|
|
416 |
}
|
|
417 |
|
|
418 |
/**
|
|
419 |
* Check if this symbol is a let
|
|
420 |
* @return true if let
|
|
421 |
*/
|
|
422 |
public boolean isLet() {
|
|
423 |
return (flags & IS_LET) == IS_LET;
|
|
424 |
}
|
|
425 |
|
|
426 |
/**
|
|
427 |
* Flag this symbol as a let
|
|
428 |
*/
|
|
429 |
public void setIsLet() {
|
|
430 |
flags |= IS_LET;
|
|
431 |
}
|
|
432 |
|
|
433 |
/**
|
|
434 |
* Check if this symbol can be accessed directly with a putfield or getfield or dynamic load
|
|
435 |
*
|
|
436 |
* @param currentFunction function to check for fast scope
|
|
437 |
* @return true if fast scope
|
|
438 |
*/
|
|
439 |
public boolean isFastScope(final FunctionNode currentFunction) {
|
|
440 |
if (!isScope() || !block.needsScope()) {
|
|
441 |
return false;
|
|
442 |
}
|
|
443 |
// Allow fast scope access if no parent function contains with or eval
|
|
444 |
FunctionNode func = currentFunction;
|
|
445 |
while (func != null) {
|
|
446 |
if (func.hasWith() || func.hasEval()) {
|
|
447 |
return false;
|
|
448 |
}
|
|
449 |
func = func.findParentFunction();
|
|
450 |
}
|
|
451 |
return true;
|
|
452 |
}
|
|
453 |
|
|
454 |
/**
|
|
455 |
* Get the block in which the symbol is defined
|
|
456 |
* @return a block
|
|
457 |
*/
|
|
458 |
public Block getBlock() {
|
|
459 |
return block;
|
|
460 |
}
|
|
461 |
|
|
462 |
/**
|
|
463 |
* Get the index of the field used to store this symbol, should it be an AccessorProperty
|
|
464 |
* and get allocated in a JO$-prefixed ScriptObject subclass.
|
|
465 |
*
|
|
466 |
* @return field index
|
|
467 |
*/
|
|
468 |
public int getFieldIndex() {
|
|
469 |
assert fieldIndex != -1 : "fieldIndex must be initialized";
|
|
470 |
return fieldIndex;
|
|
471 |
}
|
|
472 |
|
|
473 |
/**
|
|
474 |
* Set the index of the field used to store this symbol, should it be an AccessorProperty
|
|
475 |
* and get allocated in a JO$-prefixed ScriptObject subclass.
|
|
476 |
*
|
|
477 |
* @param fieldIndex field index - a positive integer
|
|
478 |
*/
|
|
479 |
public void setFieldIndex(final int fieldIndex) {
|
|
480 |
assert this.fieldIndex == -1 : "fieldIndex must be initialized only once";
|
|
481 |
this.fieldIndex = fieldIndex;
|
|
482 |
}
|
|
483 |
|
|
484 |
/**
|
|
485 |
* Get the symbol flags
|
|
486 |
* @return flags
|
|
487 |
*/
|
|
488 |
public int getFlags() {
|
|
489 |
return flags;
|
|
490 |
}
|
|
491 |
|
|
492 |
/**
|
|
493 |
* Set the symbol flags
|
|
494 |
* @param flags flags
|
|
495 |
*/
|
|
496 |
public void setFlags(final int flags) {
|
|
497 |
this.flags = flags;
|
|
498 |
}
|
|
499 |
|
|
500 |
/**
|
|
501 |
* Get the node this symbol stores the result for
|
|
502 |
* @return node
|
|
503 |
*/
|
|
504 |
public Node getNode() {
|
|
505 |
return node;
|
|
506 |
}
|
|
507 |
|
|
508 |
/**
|
|
509 |
* Set the node this symbol stores the result for
|
|
510 |
* @param node node
|
|
511 |
*/
|
|
512 |
public void setNode(final Node node) {
|
|
513 |
this.node = node;
|
|
514 |
}
|
|
515 |
|
|
516 |
/**
|
|
517 |
* Get the name of this symbol
|
|
518 |
* @return symbol name
|
|
519 |
*/
|
|
520 |
public String getName() {
|
|
521 |
return name;
|
|
522 |
}
|
|
523 |
|
|
524 |
/**
|
|
525 |
* Get the byte code slot for this symbol
|
|
526 |
* @return byte code slot, or -1 if no slot allocated/possible
|
|
527 |
*/
|
|
528 |
public int getSlot() {
|
|
529 |
return slot;
|
|
530 |
}
|
|
531 |
|
|
532 |
/**
|
|
533 |
* Increase the symbol's use count by one.
|
|
534 |
*/
|
|
535 |
public void increaseUseCount() {
|
|
536 |
useCount++;
|
|
537 |
}
|
|
538 |
|
|
539 |
/**
|
|
540 |
* Get the symbol's use count
|
|
541 |
* @return the number of times the symbol is used in code.
|
|
542 |
*/
|
|
543 |
public int getUseCount() {
|
|
544 |
return useCount;
|
|
545 |
}
|
|
546 |
|
|
547 |
/**
|
|
548 |
* Set the bytecode slot for this symbol
|
|
549 |
* @param slot valid bytecode slot, or -1 if not available
|
|
550 |
*/
|
|
551 |
public void setSlot(final int slot) {
|
|
552 |
if (TRACE_SYMBOL != null) {
|
|
553 |
if (TRACE_SYMBOL.equals(name)) {
|
|
554 |
System.err.println(name + " gets slot " + slot);
|
|
555 |
new Throwable().printStackTrace();
|
|
556 |
}
|
|
557 |
}
|
|
558 |
this.slot = slot;
|
|
559 |
}
|
|
560 |
|
|
561 |
/**
|
|
562 |
* Assign a specific subclass of Object to the symbol
|
|
563 |
*
|
|
564 |
* @param type the type
|
|
565 |
*/
|
|
566 |
public void setType(final Class<?> type) {
|
|
567 |
assert !type.isPrimitive() && !Number.class.isAssignableFrom(type) : "Class<?> types can only be subclasses of object";
|
|
568 |
setType(Type.typeFor(type));
|
|
569 |
}
|
|
570 |
|
|
571 |
/**
|
|
572 |
* Assign a type to the symbol
|
|
573 |
*
|
|
574 |
* @param type the type
|
|
575 |
*/
|
|
576 |
public void setType(final Type type) {
|
|
577 |
if (TRACE_SYMBOL == null) {
|
|
578 |
setTypeOverride(Type.widest(this.type, type));
|
|
579 |
} else {
|
|
580 |
final boolean check = TRACE_SYMBOL.equals(getName());
|
|
581 |
final Type from = this.type;
|
|
582 |
setTypeOverride(Type.widest(this.type, type));
|
|
583 |
|
|
584 |
if (check) {
|
|
585 |
System.err.println(getName() + " " + from + "=>" + type + " == " + this.type);
|
|
586 |
new Throwable().printStackTrace();
|
|
587 |
}
|
|
588 |
}
|
|
589 |
}
|
|
590 |
|
|
591 |
/**
|
|
592 |
* Only use this if you know about an existing type
|
|
593 |
* constraint - otherwise a type can only be
|
|
594 |
* widened
|
|
595 |
*
|
|
596 |
* @param type the type
|
|
597 |
*/
|
|
598 |
public void setTypeOverride(final Type type) {
|
|
599 |
this.type = type;
|
|
600 |
}
|
|
601 |
|
|
602 |
/**
|
|
603 |
* Check if this symbol is in the global scope, i.e. it is on the outermost level
|
|
604 |
* in the script
|
|
605 |
* @return true if this this is a global scope symbol
|
|
606 |
*/
|
|
607 |
public boolean isTopLevel() {
|
|
608 |
return block instanceof FunctionNode && ((FunctionNode) block).isScript();
|
|
609 |
}
|
|
610 |
}
|