2007-12-24 16:19:51 +08:00
|
|
|
package net.loveruby.cflat.ast;
|
|
|
|
import net.loveruby.cflat.type.Type;
|
|
|
|
import net.loveruby.cflat.asm.*;
|
|
|
|
|
2008-01-05 11:52:41 +08:00
|
|
|
public class VariableNode extends ExprNode {
|
2008-01-05 09:34:27 +08:00
|
|
|
protected Location location;
|
2007-12-24 16:19:51 +08:00
|
|
|
protected String name;
|
|
|
|
protected Entity entity;
|
|
|
|
|
2008-01-05 09:34:27 +08:00
|
|
|
public VariableNode(Location loc, String name) {
|
2007-12-24 16:19:51 +08:00
|
|
|
super();
|
2008-01-05 09:34:27 +08:00
|
|
|
this.location = loc;
|
|
|
|
this.name = name;
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public String name() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2008-01-13 03:48:31 +08:00
|
|
|
public boolean isResolved() {
|
|
|
|
return (entity != null);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public Entity entity() {
|
|
|
|
if (entity == null) {
|
|
|
|
throw new Error("VariableNode.entity == null");
|
|
|
|
}
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
2008-01-13 03:48:31 +08:00
|
|
|
public void setEntity(Entity ent) {
|
|
|
|
entity = ent;
|
|
|
|
}
|
|
|
|
|
2007-12-24 16:19:51 +08:00
|
|
|
public Type type() {
|
|
|
|
return entity().type();
|
|
|
|
}
|
|
|
|
|
|
|
|
public TypeNode typeNode() {
|
|
|
|
return entity().typeNode();
|
|
|
|
}
|
|
|
|
|
2008-01-02 18:46:28 +08:00
|
|
|
public boolean isAssignable() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-12-24 16:19:51 +08:00
|
|
|
public boolean isConstantAddress() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public AsmEntity address() {
|
|
|
|
return entity.address();
|
|
|
|
}
|
2008-01-04 07:01:49 +08:00
|
|
|
|
2008-01-05 09:34:27 +08:00
|
|
|
public Location location() {
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
|
2008-01-04 07:01:49 +08:00
|
|
|
protected void _dump(Dumper d) {
|
2008-01-13 03:48:31 +08:00
|
|
|
d.printMember("name", name, isResolved());
|
2008-01-04 07:01:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void accept(ASTVisitor visitor) {
|
|
|
|
visitor.visit(this);
|
|
|
|
}
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|