Class VarRefExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.VarRefExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class VarRefExpr extends Object implements Expression
Represents a local variable reference.
-
-
Constructor Summary
Constructors Constructor Description VarRefExpr(String name, SourceType type)Creates a variable reference with no backing IR value and an unknown source position.VarRefExpr(String name, SourceType type, SSAValue ssaValue)Creates a variable reference with an unknown source position.VarRefExpr(String name, SourceType type, SSAValue ssaValue, SourceLocation location)Creates a variable reference.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.SourceLocationgetLocation()Gets the source location of this node.StringgetName()ASTNodegetParent()Gets the parent node in the AST tree.SSAValuegetSsaValue()SourceTypegetType()Gets the inferred type of this expression.booleanhasSSAValue()voidsetName(String name)Renames the referenced variable.voidsetParent(ASTNode parent)Sets the enclosing node.StringtoString()VarRefExprwithName(String name)Renames the referenced variable in place, for chaining.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getChildren, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
Constructor Detail
-
VarRefExpr
public VarRefExpr(String name, SourceType type, SSAValue ssaValue, SourceLocation location)
Creates a variable reference.- Parameters:
name- the variable nametype- the variable's declared typessaValue- the IR value this reference maps back to, may be nulllocation- source position, null for unknown- Throws:
NullPointerException- if the name or type is null
-
VarRefExpr
public VarRefExpr(String name, SourceType type, SSAValue ssaValue)
Creates a variable reference with an unknown source position.- Parameters:
name- the variable nametype- the variable's declared typessaValue- the IR value this reference maps back to, may be null- Throws:
NullPointerException- if the name or type is null
-
VarRefExpr
public VarRefExpr(String name, SourceType type)
Creates a variable reference with no backing IR value and an unknown source position.- Parameters:
name- the variable nametype- the variable's declared type- Throws:
NullPointerException- if the name or type is null
-
-
Method Detail
-
getName
public String getName()
- Returns:
- the name
-
setName
public void setName(String name)
Renames the referenced variable.- Parameters:
name- the new name
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type
-
getSsaValue
public SSAValue getSsaValue()
- Returns:
- the ssa value
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Sets the enclosing node.
-
withName
public VarRefExpr withName(String name)
Renames the referenced variable in place, for chaining.- Parameters:
name- the new name- Returns:
- this reference
-
hasSSAValue
public boolean hasSSAValue()
- Returns:
- true when this reference carries a backing IR value
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-