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-05 11:52:41 +08:00
|
|
|
public class PtrMemberNode extends ExprNode {
|
2008-01-02 19:53:41 +08:00
|
|
|
public ExprNode expr;
|
2008-01-05 12:24:00 +08:00
|
|
|
public String member;
|
2007-12-24 16:19:51 +08:00
|
|
|
|
2008-01-05 12:24:00 +08:00
|
|
|
public PtrMemberNode(ExprNode expr, String member) {
|
2008-01-02 19:53:41 +08:00
|
|
|
this.expr = expr;
|
2008-01-05 12:24:00 +08:00
|
|
|
this.member = member;
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public Type type() {
|
2008-09-07 06:37:39 +08:00
|
|
|
return dereferedComplexType().memberType(member);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
2008-09-07 06:37:39 +08:00
|
|
|
public ComplexType dereferedComplexType() {
|
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-09-07 06:37:39 +08:00
|
|
|
public Type dereferedType() {
|
|
|
|
try {
|
|
|
|
PointerType pt = expr.type().getPointerType();
|
|
|
|
return pt.baseType();
|
|
|
|
}
|
|
|
|
catch (ClassCastException err) {
|
|
|
|
throw new SemanticError(err.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-02 19:53:41 +08:00
|
|
|
public ExprNode expr() {
|
2007-12-24 16:19:51 +08:00
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
2008-01-05 12:24:00 +08:00
|
|
|
public String member() {
|
|
|
|
return member;
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
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 false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long offset() {
|
2008-09-07 06:37:39 +08:00
|
|
|
return dereferedComplexType().memberOffset(member);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
2008-01-05 09:34:27 +08:00
|
|
|
public Location location() {
|
|
|
|
return expr.location();
|
|
|
|
}
|
|
|
|
|
2008-01-04 07:01:49 +08:00
|
|
|
protected void _dump(Dumper d) {
|
|
|
|
d.printMember("expr", expr);
|
2008-01-05 12:24:00 +08:00
|
|
|
d.printMember("member", member);
|
2008-01-04 07:01:49 +08:00
|
|
|
}
|
|
|
|
|
2007-12-24 16:19:51 +08:00
|
|
|
public void accept(ASTVisitor visitor) {
|
|
|
|
visitor.visit(this);
|
|
|
|
}
|
2008-09-07 07:06:41 +08:00
|
|
|
|
|
|
|
public void acceptLHS(ASTLHSVisitor visitor) {
|
|
|
|
visitor.visitLHS(this);
|
|
|
|
}
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|