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

org.qbicc.graph.Reachable 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;

/**
 *
 */
public final class Reachable extends AbstractNode implements Action, OrderedNode {
    private final Node dependency;
    private final Value reachableValue;

    Reachable(Node callSite, ExecutableElement element, int line, int bci, Node dependency, Value reachableValue) {
        super(callSite, element, line, bci);
        this.dependency = dependency;
        this.reachableValue = reachableValue;
    }

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

    @Override
    public Value getValueDependency(int index) throws IndexOutOfBoundsException {
        return switch (index) {
            case 0 -> reachableValue;
            default -> Util.throwIndexOutOfBounds(index);
        };
    }

    public Value getReachableValue() {
        return reachableValue;
    }

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

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

    @Override
    int calcHashCode() {
        return Objects.hash(Reachable.class, dependency, reachableValue);
    }

    @Override
    public StringBuilder toString(StringBuilder b) {
        return reachableValue.toReferenceString(super.toString(b).append('(')).append(')');
    }

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

    public boolean equals(Reachable other) {
        return this == other || other != null && dependency.equals(other.dependency) && reachableValue.equals(other.reachableValue);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy