2007-12-24 16:19:51 +08:00
|
|
|
package net.loveruby.cflat.ast;
|
|
|
|
import net.loveruby.cflat.type.*;
|
|
|
|
import net.loveruby.cflat.asm.*;
|
2008-01-03 22:31:26 +08:00
|
|
|
import net.loveruby.cflat.exception.*;
|
2007-12-24 16:19:51 +08:00
|
|
|
|
2008-01-02 19:53:41 +08:00
|
|
|
public class PtrMemberNode extends ExprNode implements LHSNode {
|
|
|
|
public ExprNode expr;
|
2007-12-24 16:19:51 +08:00
|
|
|
public String name;
|
|
|
|
|
2008-01-02 19:53:41 +08:00
|
|
|
public PtrMemberNode(ExprNode expr, String name) {
|
|
|
|
this.expr = expr;
|
|
|
|
this.name = name;
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public Type type() {
|
2008-01-03 19:26:07 +08:00
|
|
|
return dereferedType().memberType(name);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
2008-01-03 19:26:07 +08:00
|
|
|
public ComplexType dereferedType() {
|
2008-01-03 22:31:26 +08:00
|
|
|
try {
|
|
|
|
PointerType pt = expr.type().getPointerType();
|
|
|
|
return pt.baseType().getComplexType();
|
|
|
|
}
|
|
|
|
catch (ClassCastException err) {
|
|
|
|
throw new SemanticError(err.getMessage());
|
|
|
|
}
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
2008-01-02 19:53:41 +08:00
|
|
|
public ExprNode expr() {
|
2007-12-24 16:19:51 +08:00
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String name() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2008-01-02 18:46:28 +08:00
|
|
|
public boolean isAssignable() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LHS node requirement
|
2007-12-24 16:19:51 +08:00
|
|
|
public boolean isConstantAddress() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-02 18:46:28 +08:00
|
|
|
// LHS node requirement
|
2007-12-24 16:19:51 +08:00
|
|
|
public AsmEntity address() {
|
|
|
|
throw new Error("PtrMemberNode#address");
|
|
|
|
}
|
|
|
|
|
|
|
|
public long offset() {
|
2008-01-03 19:26:07 +08:00
|
|
|
return dereferedType().memberOffset(name);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
2008-01-04 07:01:49 +08:00
|
|
|
protected void _dump(Dumper d) {
|
|
|
|
d.printMember("expr", expr);
|
|
|
|
d.printMember("name", name);
|
|
|
|
}
|
|
|
|
|
2007-12-24 16:19:51 +08:00
|
|
|
public void accept(ASTVisitor visitor) {
|
|
|
|
visitor.visit(this);
|
|
|
|
}
|
|
|
|
}
|