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

org.qbicc.pointer.GlobalPointer Maven / Gradle / Ivy

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

import org.qbicc.type.definition.element.GlobalVariableElement;

/**
 * A pointer to a global variable.
 */
public final class GlobalPointer extends RootPointer {
    private final GlobalVariableElement globalVariable;

    GlobalPointer(GlobalVariableElement globalVariable) {
        super(globalVariable.getType().getPointer());
        this.globalVariable = globalVariable;
    }

    public static GlobalPointer of(final GlobalVariableElement fieldElement) {
        return fieldElement.getOrCreatePointer(GlobalPointer::new);
    }

    public GlobalVariableElement getGlobalVariable() {
        return globalVariable;
    }

    @Override
    public long getRootByteOffset() {
        return globalVariable.getOffset();
    }

    @Override
    public int hashCode() {
        return super.hashCode() * 19 + globalVariable.hashCode();
    }

    @Override
    public boolean equals(final RootPointer other) {
        return other instanceof GlobalPointer gp && equals(gp);
    }

    public boolean equals(final GlobalPointer other) {
        return super.equals(other) && globalVariable == other.globalVariable;
    }

    @Override
    public StringBuilder toString(StringBuilder b) {
        return b.append('&').append(globalVariable.getName());
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy