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

org.qbicc.graph.Dereference 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.ValueType;
import org.qbicc.type.definition.element.ExecutableElement;

/**
 * An opaque member selection.  The wrapped value is a pointer to any memory object.
 * Selected members may be unwrapped to be used as lvalues, or may be lazily transformed to plain loads.
 */
public final class Dereference extends AbstractValue {
    private final Value pointer;

    Dereference(Node callSite, ExecutableElement element, int line, int bci, Value pointer) {
        super(callSite, element, line, bci);
        this.pointer = pointer;
    }

    public Value getPointer() {
        return pointer;
    }

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

    @Override
    public Value getValueDependency(int index) throws IndexOutOfBoundsException {
        return switch (index) {
            case 0 -> pointer;
            default -> throw new IndexOutOfBoundsException(index);
        };
    }

    public ValueType getType() {
        return pointer.getPointeeType();
    }

    int calcHashCode() {
        return Objects.hash(Dereference.class, pointer);
    }

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

    @Override
    StringBuilder toRValueString(StringBuilder b) {
        return pointer.toReferenceString(b.append("deref "));
    }

    public boolean equals(final Object other) {
        return other instanceof Dereference && equals((Dereference) other);
    }

    public boolean equals(final Dereference other) {
        return this == other || other != null && pointer.equals(other.pointer);
    }

    public  R accept(final ValueVisitor visitor, final T param) {
        return visitor.visit(param, this);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy