2007-12-24 16:19:51 +08:00
|
|
|
package net.loveruby.cflat.ast;
|
2009-04-26 21:08:40 +08:00
|
|
|
import net.loveruby.cflat.type.Type;
|
|
|
|
import net.loveruby.cflat.type.CompositeType;
|
|
|
|
import net.loveruby.cflat.type.PointerType;
|
2008-01-03 22:31:26 +08:00
|
|
|
import net.loveruby.cflat.exception.*;
|
2007-12-24 16:19:51 +08:00
|
|
|
|
2009-05-18 02:35:02 +08:00
|
|
|
public class PtrMemberNode extends LHSNode {
|
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
|
|
|
}
|
|
|
|
|
2008-09-20 18:30:54 +08:00
|
|
|
public CompositeType dereferedCompositeType() {
|
2008-01-03 22:31:26 +08:00
|
|
|
try {
|
|
|
|
PointerType pt = expr.type().getPointerType();
|
2008-09-20 18:30:54 +08:00
|
|
|
return pt.baseType().getCompositeType();
|
2008-01-03 22:31:26 +08:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-05-18 02:35:02 +08:00
|
|
|
public long offset() {
|
|
|
|
return dereferedCompositeType().memberOffset(member);
|
2008-01-02 18:46:28 +08:00
|
|
|
}
|
|
|
|
|
2009-05-18 02:35:02 +08:00
|
|
|
protected Type origType() {
|
|
|
|
return dereferedCompositeType().memberType(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) {
|
2009-05-24 19:23:29 +08:00
|
|
|
if (type != null) {
|
|
|
|
d.printMember("type", type);
|
|
|
|
}
|
2008-01-04 07:01:49 +08:00
|
|
|
d.printMember("expr", expr);
|
2008-01-05 12:24:00 +08:00
|
|
|
d.printMember("member", member);
|
2008-01-04 07:01:49 +08:00
|
|
|
}
|
|
|
|
|
2009-04-12 14:31:12 +08:00
|
|
|
public <S,E> E accept(ASTVisitor<S,E> visitor) {
|
2009-04-04 22:47:11 +08:00
|
|
|
return visitor.visit(this);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
}
|