mirror of https://github.com/aamine/cbc
95 lines
2.0 KiB
Java
95 lines
2.0 KiB
Java
package net.loveruby.cflat.ast;
|
|
import net.loveruby.cflat.type.*;
|
|
import net.loveruby.cflat.asm.Symbol;
|
|
import net.loveruby.cflat.asm.AsmOperand;
|
|
import net.loveruby.cflat.asm.MemoryReference;
|
|
|
|
abstract public class Entity extends Node {
|
|
protected String name;
|
|
protected boolean isPrivate;
|
|
protected TypeNode typeNode;
|
|
protected long nRefered;
|
|
protected MemoryReference memref;
|
|
protected MemoryReference address;
|
|
|
|
public Entity(boolean priv, TypeNode type, String name) {
|
|
this.name = name;
|
|
this.isPrivate = priv;
|
|
this.typeNode = type;
|
|
this.nRefered = 0;
|
|
}
|
|
|
|
public String name() {
|
|
return name;
|
|
}
|
|
|
|
public String symbolString() {
|
|
return name();
|
|
}
|
|
|
|
abstract public boolean isDefined();
|
|
abstract public boolean isInitialized();
|
|
|
|
public boolean isParameter() { return false; }
|
|
|
|
public boolean isPrivate() {
|
|
return isPrivate;
|
|
}
|
|
|
|
public TypeNode typeNode() {
|
|
return typeNode;
|
|
}
|
|
|
|
public Type type() {
|
|
return typeNode.type();
|
|
}
|
|
|
|
public long allocSize() {
|
|
return type().allocSize();
|
|
}
|
|
|
|
public long alignment() {
|
|
return type().alignment();
|
|
}
|
|
|
|
public void refered() {
|
|
nRefered++;
|
|
}
|
|
|
|
public boolean isRefered() {
|
|
return (nRefered > 0);
|
|
}
|
|
|
|
abstract public boolean cannotLoad();
|
|
|
|
public void setMemref(MemoryReference mem) {
|
|
this.memref = mem;
|
|
}
|
|
|
|
public MemoryReference memref() {
|
|
checkAddress();
|
|
return memref;
|
|
}
|
|
|
|
public void setAddress(MemoryReference mem) {
|
|
this.address = mem;
|
|
}
|
|
|
|
public AsmOperand address() {
|
|
checkAddress();
|
|
return address;
|
|
}
|
|
|
|
protected void checkAddress() {
|
|
if (memref == null && address == null) {
|
|
throw new Error("address did not resolved: " + name);
|
|
}
|
|
}
|
|
|
|
public Location location() {
|
|
return typeNode.location();
|
|
}
|
|
|
|
abstract public <S,E> S accept(ASTVisitor<S,E> visitor);
|
|
}
|