Class UnaryExpr

  • All Implemented Interfaces:
    ASTNode, Expression

    public final class UnaryExpr
    extends Object
    implements Expression
    Represents a unary expression: op operand (prefix) or operand op (postfix)
    • Constructor Detail

      • UnaryExpr

        public UnaryExpr​(UnaryOperator operator,
                         Expression operand,
                         SourceType type,
                         SourceLocation location)
        Creates a unary expression and adopts the operand as a child.
        Parameters:
        operator - the prefix or postfix operator
        operand - the operand expression
        type - the result type
        location - the source location, null for unknown
        Throws:
        NullPointerException - if the operator, operand or type is null
      • UnaryExpr

        public UnaryExpr​(UnaryOperator operator,
                         Expression operand,
                         SourceType type)
        Creates a unary expression with an unknown source location.
        Parameters:
        operator - the prefix or postfix operator
        operand - the operand expression
        type - the result type
        Throws:
        NullPointerException - if the operator, operand or type is null
    • Method Detail

      • getOperator

        public UnaryOperator getOperator()
        Returns:
        the operator
      • setOperator

        public void setOperator​(UnaryOperator operator)
        Sets the operator.
        Parameters:
        operator - the new operator
      • getOperand

        public Expression getOperand()
        Returns:
        the operand
      • setOperand

        public void setOperand​(Expression operand)
        Sets the operand, reparenting the new one and releasing the old one.
        Parameters:
        operand - the new operand
      • getType

        public SourceType getType()
        Description copied from interface: Expression
        Gets the inferred type of this expression.
        Specified by:
        getType in interface Expression
        Returns:
        the static type of this expression
      • getLocation

        public SourceLocation getLocation()
        Description copied from interface: ASTNode
        Gets the source location of this node.
        Specified by:
        getLocation in interface ASTNode
        Returns:
        the location
      • getParent

        public ASTNode getParent()
        Description copied from interface: ASTNode
        Gets the parent node in the AST tree.
        Specified by:
        getParent in interface ASTNode
        Returns:
        the parent
      • setParent

        public void setParent​(ASTNode parent)
        Sets the enclosing AST node.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the new parent
      • isPrefix

        public boolean isPrefix()
        Returns:
        true if the operator is written before the operand
      • isPostfix

        public boolean isPostfix()
        Returns:
        true if the operator is written after the operand
      • isIncDec

        public boolean isIncDec()
        Returns:
        true if the operator is an increment or decrement
      • withOperator

        public UnaryExpr withOperator​(UnaryOperator operator)
        Sets the operator.
        Parameters:
        operator - the new operator
        Returns:
        this expression
      • withOperand

        public UnaryExpr withOperand​(Expression operand)
        Sets the operand, reparenting the new one and releasing the old one.
        Parameters:
        operand - the new operand
        Returns:
        this expression
      • getChildren

        public List<ASTNode> getChildren()
        Description copied from interface: ASTNode
        Lists the direct children a node holds, in source order.
        Specified by:
        getChildren in interface ASTNode
        Returns:
        the direct children, empty for a leaf
      • accept

        public <T> T accept​(SourceVisitor<T> visitor)
        Description copied from interface: ASTNode
        Accepts a visitor for this node.
        Specified by:
        accept in interface ASTNode
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor