cbc/net/loveruby/cflat/ast/PtrMemberNode.java

68 lines
1.6 KiB
Java
Raw Normal View History

package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.Type;
import net.loveruby.cflat.type.CompositeType;
import net.loveruby.cflat.type.PointerType;
import net.loveruby.cflat.exception.*;
r4865@macbookpro: aamine | 2009-05-18 03:02:28 +0900 * net/loveruby/cflat/parser/Parser.jj: change function pointer syntax: int(*)(int,int) -> int(int,int)*. Function type is int(int,int). * net/loveruby/cflat/parser/Parser.jj: function returns function type, not pointer to function. * net/loveruby/cflat/compiler/TypeResolver.java: resolve all function headers first, then resolve bodies. * net/loveruby/cflat/compiler/TypeResolver.java: generate a pointer for array-type expression. * net/loveruby/cflat/compiler/TypeResolver.java: isDereferable -> isPointer. * net/loveruby/cflat/compiler/TypeChecker.java: ditto. * net/loveruby/cflat/compiler/DereferenceChecker.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: shouldEvaluatedToAddress -> isLoadable (check arrays and functions, not only arrays). * net/loveruby/cflat/type/Type.java: remove #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: is not a scalar. * net/loveruby/cflat/type/ArrayType.java: is not dereferable itself. * net/loveruby/cflat/type/PointerType.java: is incompatible with arrays. * net/loveruby/cflat/type/IntegerType.java: ditto. * net/loveruby/cflat/type/FunctionType.java: is callable. * net/loveruby/cflat/type/ParamTypeRefs.java: x[] -> x* for param types. * net/loveruby/cflat/type/TypeTable.java: new method #getParamType. * net/loveruby/cflat/ast/ExprNode.java: new method #isLvalue. * net/loveruby/cflat/ast/ExprNode.java: new method #isAssignable. * net/loveruby/cflat/ast/ExprNode.java: new method #isLoadable. * net/loveruby/cflat/ast/CastNode.java: delegate them. * net/loveruby/cflat/ast/LHSNode.java: new super class of LHS nodes. * net/loveruby/cflat/ast/VariableNode.java: ditto. * net/loveruby/cflat/ast/DereferenceNode.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ditto. * net/loveruby/cflat/ast/MemberNode.java: ditto. * net/loveruby/cflat/ast/PtrMemberNode.java: ditto. * net/loveruby/cflat/entity/Entity.java: remove #cannotLoad. * net/loveruby/cflat/entity/Function.java: ditto. * net/loveruby/cflat/entity/Variable.java: ditto. * net/loveruby/cflat/entity/Constant.java: ditto. * net/loveruby/cflat/ir/Addr.java: is not LHS node now. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4220 1b9489fe-b721-0410-924e-b54b9192deb8
2009-05-18 02:35:02 +08:00
public class PtrMemberNode extends LHSNode {
public ExprNode expr;
public String member;
public PtrMemberNode(ExprNode expr, String member) {
this.expr = expr;
this.member = member;
}
public CompositeType dereferedCompositeType() {
try {
PointerType pt = expr.type().getPointerType();
return pt.baseType().getCompositeType();
}
catch (ClassCastException err) {
throw new SemanticError(err.getMessage());
}
}
public Type dereferedType() {
try {
PointerType pt = expr.type().getPointerType();
return pt.baseType();
}
catch (ClassCastException err) {
throw new SemanticError(err.getMessage());
}
}
public ExprNode expr() {
return expr;
}
public String member() {
return member;
}
r4865@macbookpro: aamine | 2009-05-18 03:02:28 +0900 * net/loveruby/cflat/parser/Parser.jj: change function pointer syntax: int(*)(int,int) -> int(int,int)*. Function type is int(int,int). * net/loveruby/cflat/parser/Parser.jj: function returns function type, not pointer to function. * net/loveruby/cflat/compiler/TypeResolver.java: resolve all function headers first, then resolve bodies. * net/loveruby/cflat/compiler/TypeResolver.java: generate a pointer for array-type expression. * net/loveruby/cflat/compiler/TypeResolver.java: isDereferable -> isPointer. * net/loveruby/cflat/compiler/TypeChecker.java: ditto. * net/loveruby/cflat/compiler/DereferenceChecker.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: shouldEvaluatedToAddress -> isLoadable (check arrays and functions, not only arrays). * net/loveruby/cflat/type/Type.java: remove #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: is not a scalar. * net/loveruby/cflat/type/ArrayType.java: is not dereferable itself. * net/loveruby/cflat/type/PointerType.java: is incompatible with arrays. * net/loveruby/cflat/type/IntegerType.java: ditto. * net/loveruby/cflat/type/FunctionType.java: is callable. * net/loveruby/cflat/type/ParamTypeRefs.java: x[] -> x* for param types. * net/loveruby/cflat/type/TypeTable.java: new method #getParamType. * net/loveruby/cflat/ast/ExprNode.java: new method #isLvalue. * net/loveruby/cflat/ast/ExprNode.java: new method #isAssignable. * net/loveruby/cflat/ast/ExprNode.java: new method #isLoadable. * net/loveruby/cflat/ast/CastNode.java: delegate them. * net/loveruby/cflat/ast/LHSNode.java: new super class of LHS nodes. * net/loveruby/cflat/ast/VariableNode.java: ditto. * net/loveruby/cflat/ast/DereferenceNode.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ditto. * net/loveruby/cflat/ast/MemberNode.java: ditto. * net/loveruby/cflat/ast/PtrMemberNode.java: ditto. * net/loveruby/cflat/entity/Entity.java: remove #cannotLoad. * net/loveruby/cflat/entity/Function.java: ditto. * net/loveruby/cflat/entity/Variable.java: ditto. * net/loveruby/cflat/entity/Constant.java: ditto. * net/loveruby/cflat/ir/Addr.java: is not LHS node now. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4220 1b9489fe-b721-0410-924e-b54b9192deb8
2009-05-18 02:35:02 +08:00
public long offset() {
return dereferedCompositeType().memberOffset(member);
}
r4865@macbookpro: aamine | 2009-05-18 03:02:28 +0900 * net/loveruby/cflat/parser/Parser.jj: change function pointer syntax: int(*)(int,int) -> int(int,int)*. Function type is int(int,int). * net/loveruby/cflat/parser/Parser.jj: function returns function type, not pointer to function. * net/loveruby/cflat/compiler/TypeResolver.java: resolve all function headers first, then resolve bodies. * net/loveruby/cflat/compiler/TypeResolver.java: generate a pointer for array-type expression. * net/loveruby/cflat/compiler/TypeResolver.java: isDereferable -> isPointer. * net/loveruby/cflat/compiler/TypeChecker.java: ditto. * net/loveruby/cflat/compiler/DereferenceChecker.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: shouldEvaluatedToAddress -> isLoadable (check arrays and functions, not only arrays). * net/loveruby/cflat/type/Type.java: remove #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: is not a scalar. * net/loveruby/cflat/type/ArrayType.java: is not dereferable itself. * net/loveruby/cflat/type/PointerType.java: is incompatible with arrays. * net/loveruby/cflat/type/IntegerType.java: ditto. * net/loveruby/cflat/type/FunctionType.java: is callable. * net/loveruby/cflat/type/ParamTypeRefs.java: x[] -> x* for param types. * net/loveruby/cflat/type/TypeTable.java: new method #getParamType. * net/loveruby/cflat/ast/ExprNode.java: new method #isLvalue. * net/loveruby/cflat/ast/ExprNode.java: new method #isAssignable. * net/loveruby/cflat/ast/ExprNode.java: new method #isLoadable. * net/loveruby/cflat/ast/CastNode.java: delegate them. * net/loveruby/cflat/ast/LHSNode.java: new super class of LHS nodes. * net/loveruby/cflat/ast/VariableNode.java: ditto. * net/loveruby/cflat/ast/DereferenceNode.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ditto. * net/loveruby/cflat/ast/MemberNode.java: ditto. * net/loveruby/cflat/ast/PtrMemberNode.java: ditto. * net/loveruby/cflat/entity/Entity.java: remove #cannotLoad. * net/loveruby/cflat/entity/Function.java: ditto. * net/loveruby/cflat/entity/Variable.java: ditto. * net/loveruby/cflat/entity/Constant.java: ditto. * net/loveruby/cflat/ir/Addr.java: is not LHS node now. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4220 1b9489fe-b721-0410-924e-b54b9192deb8
2009-05-18 02:35:02 +08:00
protected Type origType() {
return dereferedCompositeType().memberType(member);
}
public Location location() {
return expr.location();
}
protected void _dump(Dumper d) {
if (type != null) {
d.printMember("type", type);
}
d.printMember("expr", expr);
d.printMember("member", member);
}
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}