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

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

/**
 * A pointer that is offset from the base pointer by a number of base-pointee-typed elements.
 */
public final class OffsetPointer extends AbstractValue {
    private final Value basePointer;
    private final Value offset;

    OffsetPointer(Node callSite, ExecutableElement element, int line, int bci, Value basePointer, Value offset) {
        super(callSite, element, line, bci);
        this.basePointer = basePointer;
        this.offset = offset;
    }

    @Override
    int calcHashCode() {
        return Objects.hash(OffsetPointer.class, basePointer, offset);
    }

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

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

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

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

    public boolean equals(OffsetPointer other) {
        return this == other || other != null && basePointer.equals(other.basePointer) && offset.equals(other.offset);
    }

    @Override
    StringBuilder toRValueString(StringBuilder b) {
        return offset.toReferenceString(basePointer.toReferenceString(b.append("offset ")).append(" by "));
    }

    @Override
    public PointerType getType() {
        return basePointer.getType(PointerType.class);
    }

    public Value getBasePointer() {
        return basePointer;
    }

    public Value getOffset() {
        return offset;
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy