| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package org.mozilla.javascript.ast; |
| 8 |
|
| 9 |
import org.mozilla.javascript.Node; |
| 10 |
import org.mozilla.javascript.Token; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
public class Symbol { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
private int declType; |
| 20 |
private int index = -1; |
| 21 |
private String name; |
| 22 |
private Node node; |
| 23 |
private Scope containingTable; |
| 24 |
|
| 25 |
public Symbol() { |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public Symbol(int declType, String name) { |
| 34 |
setName(name); |
| 35 |
setDeclType(declType); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public int getDeclType() { |
| 42 |
return declType; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public void setDeclType(int declType) { |
| 49 |
if (!(declType == Token.FUNCTION |
| 50 |
|| declType == Token.LP |
| 51 |
|| declType == Token.VAR |
| 52 |
|| declType == Token.LET |
| 53 |
|| declType == Token.CONST)) |
| 54 |
throw new IllegalArgumentException("Invalid declType: " + declType); |
| 55 |
this.declType = declType; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public String getName() { |
| 62 |
return name; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public void setName(String name) { |
| 69 |
this.name = name; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public Node getNode() { |
| 76 |
return node; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public int getIndex() { |
| 83 |
return index; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public void setIndex(int index) { |
| 90 |
this.index = index; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
public void setNode(Node node) { |
| 97 |
this.node = node; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public Scope getContainingTable() { |
| 104 |
return containingTable; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public void setContainingTable(Scope containingTable) { |
| 111 |
this.containingTable = containingTable; |
| 112 |
} |
| 113 |
|
| 114 |
public String getDeclTypeName() { |
| 115 |
return Token.typeToName(declType); |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
public String toString() { |
| 120 |
StringBuilder result = new StringBuilder(); |
| 121 |
result.append("Symbol ("); |
| 122 |
result.append(getDeclTypeName()); |
| 123 |
result.append(") name="); |
| 124 |
result.append(name); |
| 125 |
if (node != null) { |
| 126 |
result.append(" line="); |
| 127 |
result.append(node.getLineno()); |
| 128 |
} |
| 129 |
return result.toString(); |
| 130 |
} |
| 131 |
} |