Class CastExpr
- java.lang.Object
-
- com.tonic.analysis.source.ast.expr.CastExpr
-
- All Implemented Interfaces:
ASTNode,Expression
public final class CastExpr extends Object implements Expression
A cast expression: (Type) expression.
-
-
Constructor Summary
Constructors Constructor Description CastExpr(SourceType targetType, Expression expression)Creates a cast with an unknown source location.CastExpr(SourceType targetType, Expression expression, SourceLocation location)Creates a cast of the given expression to the target type and reparents the operand.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ExpressiongetExpression()SourceLocationgetLocation()Gets the source location of this node.ASTNodegetParent()Gets the parent node in the AST tree.SourceTypegetTargetType()SourceTypegetType()Gets the inferred type of this expression.booleanisRecordDeconstruction()voidsetExpression(Expression expression)Replaces the cast operand, reparenting the new child.voidsetParent(ASTNode parent)Sets the parent node in the AST tree.voidsetRecordDeconstruction(boolean recordDeconstruction)StringtoString()CastExprwithExpression(Expression expression)Replaces the cast operand, reparenting the new child and releasing the former one.-
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, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
-
-
-
Constructor Detail
-
CastExpr
public CastExpr(SourceType targetType, Expression expression, SourceLocation location)
Creates a cast of the given expression to the target type and reparents the operand.- Parameters:
targetType- the type cast toexpression- the expression being castlocation- the source location, or null for unknown- Throws:
NullPointerException- if targetType or expression is null
-
CastExpr
public CastExpr(SourceType targetType, Expression expression)
Creates a cast with an unknown source location.- Parameters:
targetType- the type cast toexpression- the expression being cast- Throws:
NullPointerException- if targetType or expression is null
-
-
Method Detail
-
getTargetType
public SourceType getTargetType()
- Returns:
- the target type
-
getExpression
public Expression getExpression()
- Returns:
- the expression
-
setExpression
public void setExpression(Expression expression)
Replaces the cast operand, reparenting the new child.- Parameters:
expression- the new operand
-
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)
Description copied from interface:ASTNodeSets the parent node in the AST tree.
-
isRecordDeconstruction
public boolean isRecordDeconstruction()
- Returns:
- whether record deconstruction
-
setRecordDeconstruction
public void setRecordDeconstruction(boolean recordDeconstruction)
- Parameters:
recordDeconstruction- true to mark this cast as a record deconstruction temp
-
getType
public SourceType getType()
Description copied from interface:ExpressionGets the inferred type of this expression.- Specified by:
getTypein interfaceExpression- Returns:
- the type of this expression
-
withExpression
public CastExpr withExpression(Expression expression)
Replaces the cast operand, reparenting the new child and releasing the former one.- Parameters:
expression- the new operand- Returns:
- this expression
-
getChildren
public List<ASTNode> getChildren()
Description copied from interface:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-