public abstract class NNode
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Method and Description |
---|---|
void |
addChildren(java.util.List<? extends NNode> nodes) |
void |
addChildren(NNode... nodes) |
protected void |
addError(NNode loc,
java.lang.String msg) |
protected void |
addError(java.lang.String msg) |
NType |
addType(NType newType)
Adds a new type for the node, creating a union of the previous type
and the new type.
|
protected void |
addWarning(NNode loc,
java.lang.String msg) |
protected void |
addWarning(java.lang.String msg) |
protected void |
bindNames(Scope s)
Called by resolver to bind names into the passed scope.
|
boolean |
bindsName()
Returns
true if this is a name-binding node. |
int |
end() |
NNode |
getAstRoot() |
NNode |
getDeepestNodeAtOffset(int sourceOffset)
Searches the AST for the deepest node that overlaps the specified source
offset.
|
Scope |
getEnclosingNamespace()
Returns the innermost enclosing scope for doing (non-attribute) name
lookups.
|
java.lang.String |
getFile() |
NNode |
getParent() |
Scope |
getTable()
Utility alias for
getType().getTable() . |
NType |
getType()
Returns the type for this node.
|
boolean |
isCall() |
boolean |
isClassDef() |
boolean |
isFunctionDef() |
boolean |
isLambda() |
boolean |
isModule() |
boolean |
isName() |
int |
length() |
NType |
resolve(Scope s)
Node should set the resolved type in its
type field
and also return it. |
static NType |
resolveExpr(NNode n,
Scope s) |
protected void |
resolveList(java.util.List<? extends NNode> nodes,
Scope s)
Resolves each element of a node list in the passed scope.
|
protected NType |
resolveListAsUnion(java.util.List<? extends NNode> nodes,
Scope s)
Utility method to resolve every node in
nodes and
return the union of their types. |
void |
setEnd(int end) |
void |
setParent(NNode parent) |
void |
setStart(int start) |
NType |
setType(NType newType)
Sets the type for the node.
|
int |
start() |
abstract void |
visit(NNodeVisitor visitor)
Visits this node and optionally its children.
|
protected void |
visitNode(NNode n,
NNodeVisitor v) |
protected void |
visitNodeList(java.util.List<? extends NNode> nodes,
NNodeVisitor v) |
protected NNode parent
public void setParent(NNode parent)
public NNode getParent()
public NNode getAstRoot()
public void setStart(int start)
public void setEnd(int end)
public int start()
public int end()
public int length()
public Scope getTable()
getType().getTable()
.public NType getType()
null
.
If the node has not been resolved, the type will default to
Indexer.idx.builtins.None
.public NType setType(NType newType)
newType
- the new typenewType
java.lang.IllegalArgumentException
- if newType
is null
public NType addType(NType newType)
newType
- the new typejava.lang.IllegalArgumentException
- if newType
is null
public boolean bindsName()
true
if this is a name-binding node. Includes functions/lambdas,
function/lambda params, classes, assignments, imports, and implicit assignment via for
statements and except clauses.protected void bindNames(Scope s) throws java.lang.Exception
java.lang.Exception
public java.lang.String getFile()
public void addChildren(NNode... nodes)
public void addChildren(java.util.List<? extends NNode> nodes)
public NType resolve(Scope s) throws java.lang.Exception
type
field
and also return it.java.lang.Exception
public boolean isCall()
public boolean isModule()
public boolean isClassDef()
public boolean isFunctionDef()
public boolean isLambda()
public boolean isName()
protected void visitNode(NNode n, NNodeVisitor v)
protected void visitNodeList(java.util.List<? extends NNode> nodes, NNodeVisitor v)
public abstract void visit(NNodeVisitor visitor)
visitor
- the object to call with this node.
If the visitor returns true
, the node also
passes its children to the visitor.public Scope getEnclosingNamespace()
protected void addWarning(java.lang.String msg)
protected void addWarning(NNode loc, java.lang.String msg)
protected void addError(java.lang.String msg)
protected void addError(NNode loc, java.lang.String msg)
protected NType resolveListAsUnion(java.util.List<? extends NNode> nodes, Scope s)
nodes
and
return the union of their types. If nodes
is empty or
null
, returns a new NUnknownType
.protected void resolveList(java.util.List<? extends NNode> nodes, Scope s)
null
.public NNode getDeepestNodeAtOffset(int sourceOffset)
sourceOffset
- the spot at which to look for a nodenull
if no node overlaps sourceOffset
.