All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.qbicc.graph.DebugValueDeclaration Maven / Gradle / Ivy

There is a newer version: 0.77.0
Show newest version
package org.qbicc.graph;

import java.util.Objects;

import org.qbicc.type.definition.element.ExecutableElement;
import org.qbicc.type.definition.element.LocalVariableElement;

/**
 * A node which establishes that, at this point of the program, the given variable has the given value.
 */
public final class DebugValueDeclaration extends AbstractNode implements Action, OrderedNode {
    private final Node dependency;
    private final LocalVariableElement variable;
    private final Value value;

    DebugValueDeclaration(Node callSite, ExecutableElement element, int line, int bci, Node dependency, LocalVariableElement variable, Value value) {
        super(callSite, element, line, bci);
        this.dependency = dependency;
        this.variable = variable;
        this.value = value;
    }

    @Override
    public Node getDependency() {
        return dependency;
    }

    public LocalVariableElement getVariable() {
        return variable;
    }

    public Value getValue() {
        return value;
    }

    @Override
    int calcHashCode() {
        return Objects.hash(dependency, variable, value);
    }

    @Override
    String getNodeName() {
        return "DebugValue";
    }

    @Override
    public int getValueDependencyCount() {
        return 1;
    }

    @Override
    public Value getValueDependency(int index) throws IndexOutOfBoundsException {
        return index == 0 ? value : Util.throwIndexOutOfBounds(index);
    }

    @Override
    public boolean equals(Object other) {
        return other instanceof DebugValueDeclaration && equals((DebugValueDeclaration) other);
    }

    @Override
    public StringBuilder toString(StringBuilder b) {
        super.toString(b);
        b.append('(');
        variable.getType().toString(b);
        b.append(' ');
        b.append(variable.getName());
        b.append(')');
        b.append('@');
        value.toReferenceString(b);
        return b;
    }

    public boolean equals(DebugValueDeclaration other) {
        return this == other || other != null && dependency.equals(other.dependency) && variable.equals(other.variable) && value.equals(other.value);
    }

    @Override
    public  R accept(ActionVisitor visitor, T param) {
        return visitor.visit(param, this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy