public class LexicalContext extends Object
Block
nodes. Has special methods to retrieve useful subsets of the context.
This is implemented with a primitive array and a stack pointer, because it really makes a
difference performance-wise. None of the collection classes were optimal.Constructor and Description |
---|
LexicalContext()
Creates a new empty lexical context.
|
Modifier and Type | Method and Description |
---|---|
boolean |
contains(LexicalContextNode node)
Check if a node is in the lexical context.
|
Iterator<LexicalContextNode> |
getAllNodes() |
Iterator<Block> |
getBlocks()
Returns an iterator over all blocks in the context, with the top block (innermost lexical
context) first.
|
Block |
getCurrentBlock() |
FunctionNode |
getCurrentFunction() |
FunctionNode |
getCurrentNonArrowFunction() |
Scope |
getCurrentScope()
Returns the innermost scope in the context.
|
Iterator<FunctionNode> |
getFunctions()
Returns an iterator over all functions in the context, with the top (innermost open) function
first.
|
boolean |
isEmpty()
Is the context empty?
|
<T extends LexicalContextNode> |
pop(T node)
Pops the innermost block off the context and all nodes that has been contributed since it was
put there.
|
<T extends LexicalContextNode> |
push(T node)
Pushes a new block on top of the context, making it the innermost open block.
|
LexicalContextNode |
replace(LexicalContextNode oldNode,
LexicalContextNode newNode)
Replace a node on the lexical context with a new one.
|
String |
toString() |
public Iterator<LexicalContextNode> getAllNodes()
public <T extends LexicalContextNode> T push(T node)
T
- the type of the new nodenode
- the new nodepublic boolean isEmpty()
true
if emptypublic <T extends LexicalContextNode> T pop(T node)
T
- the type of the node to be poppednode
- the node expected to be popped, used to detect unbalanced pushes/popspublic boolean contains(LexicalContextNode node)
node
- node to check fortrue
if in the contextpublic LexicalContextNode replace(LexicalContextNode oldNode, LexicalContextNode newNode)
oldNode
- old nodenewNode
- new nodepublic Iterator<Block> getBlocks()
public Iterator<FunctionNode> getFunctions()
public Block getCurrentBlock()
public FunctionNode getCurrentFunction()
public FunctionNode getCurrentNonArrowFunction()
public Scope getCurrentScope()