Class LexicalContext
java.lang.Object
com.oracle.js.parser.ir.LexicalContext
A class that tracks the current lexical context of node visitation as a stack of
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(LexicalContextNode node) Check if a node is in the lexical context.copy()Returns an iterator over all blocks in the context, with the top block (innermost lexical context) first.Returns the innermost scope in the context.Returns an iterator over all functions in the context, with the top (innermost open) function first.booleaninModule()booleanisEmpty()Is the context empty?<T extends LexicalContextNode>
Tpop(T node) Pops the innermost block off the context and all nodes that has been contributed since it was put there.<T extends LexicalContextNode>
Tpush(T node) Pushes a new block on top of the context, making it the innermost open block.replace(LexicalContextNode oldNode, LexicalContextNode newNode) Replace a node on the lexical context with a new one.toString()
-
Constructor Details
-
LexicalContext
public LexicalContext()Creates a new empty lexical context.
-
-
Method Details
-
getAllNodes
- Returns:
- all nodes in the LexicalContext.
-
push
Pushes a new block on top of the context, making it the innermost open block.- Type Parameters:
T- the type of the new node- Parameters:
node- the new node- Returns:
- the node that was pushed
-
isEmpty
public boolean isEmpty()Is the context empty?- Returns:
trueif empty
-
pop
Pops the innermost block off the context and all nodes that has been contributed since it was put there.- Type Parameters:
T- the type of the node to be popped- Parameters:
node- the node expected to be popped, used to detect unbalanced pushes/pops- Returns:
- the node that was popped
-
contains
Check if a node is in the lexical context.- Parameters:
node- node to check for- Returns:
trueif in the context
-
replace
Replace a node on the lexical context with a new one. Normally you should try to engineer IR traversals so this isn't needed- Parameters:
oldNode- old nodenewNode- new node- Returns:
- the new node
-
getBlocks
-
getFunctions
Returns an iterator over all functions in the context, with the top (innermost open) function first.- Returns:
- an iterator over all functions in the context.
-
getCurrentBlock
- Returns:
- the innermost block in the context.
-
getCurrentFunction
- Returns:
- the innermost function in the context.
-
getCurrentNonArrowFunction
-
getCurrentScope
Returns the innermost scope in the context. -
getCurrentClass
- Returns:
- the innermost class in the context.
-
inModule
public boolean inModule() -
copy
-
toString
-