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

64 lines
1.4 KiB
Java
Raw Normal View History

package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.*;
import net.loveruby.cflat.asm.*;
import net.loveruby.cflat.exception.*;
public class PtrMemberNode extends ExprNode implements LHSNode {
public ExprNode expr;
public String name;
public PtrMemberNode(ExprNode expr, String name) {
this.expr = expr;
this.name = name;
}
public Type type() {
* net/loveruby/cflat/compiler/TypeChecker.java: <<, >> does not require same type of integers. 2 types of integers are OK. * net/loveruby/cflat/compiler/TypeChecker.java: arrays and pointers are both dereferable (== indexable). We can dereference both. * net/loveruby/cflat/type/Type.java: #isIndexable -> #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: ditto. * net/loveruby/cflat/ast/ExprNode.java: ditto. * net/loveruby/cflat/type/Type.java: #isReferable -> #isDereferable. * net/loveruby/cflat/type/ArrayType.java: ditto. * net/loveruby/cflat/type/PointerType.java: ditto. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ptr[0] should be allowed. Use #isDereferable instead of explict pointer check. * net/loveruby/cflat/ast/DereferenceNode.java: override #type. * net/loveruby/cflat/ast/ArefNode.java: remove cast for Type. * net/loveruby/cflat/ast/FuncallNode.java: #functionType should be called after checking isCallable, type check is not needed in #functionType. * net/loveruby/cflat/ast/PtrMemberNode.java: #baseType -> #dereferedType. * net/loveruby/cflat/ast/MemberNode.java: reduce cast for Type. * net/loveruby/cflat/type/Type.java: define #baseType here. * net/loveruby/cflat/type/ArrayType.java: override #baseType (#base -> #baseType). * net/loveruby/cflat/type/PointerType.java: ditto. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/ast/Function.java: ditto. * net/loveruby/cflat/type/PointerType.java: is not an integer. #isInteger removed. * net/loveruby/cflat/type/ArrayTypeRef.java: #base -> #baseType. * net/loveruby/cflat/type/PointerTypeRef.java: ditto. * net/loveruby/cflat/type/TypeTable.java: do not use cast methods, use true cast, since the real type is required here. * test/usertype.cb: test user type. * test/Makefile: build it. * test/test.sh: run it. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3776 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 19:26:07 +08:00
return dereferedType().memberType(name);
}
* net/loveruby/cflat/compiler/TypeChecker.java: <<, >> does not require same type of integers. 2 types of integers are OK. * net/loveruby/cflat/compiler/TypeChecker.java: arrays and pointers are both dereferable (== indexable). We can dereference both. * net/loveruby/cflat/type/Type.java: #isIndexable -> #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: ditto. * net/loveruby/cflat/ast/ExprNode.java: ditto. * net/loveruby/cflat/type/Type.java: #isReferable -> #isDereferable. * net/loveruby/cflat/type/ArrayType.java: ditto. * net/loveruby/cflat/type/PointerType.java: ditto. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ptr[0] should be allowed. Use #isDereferable instead of explict pointer check. * net/loveruby/cflat/ast/DereferenceNode.java: override #type. * net/loveruby/cflat/ast/ArefNode.java: remove cast for Type. * net/loveruby/cflat/ast/FuncallNode.java: #functionType should be called after checking isCallable, type check is not needed in #functionType. * net/loveruby/cflat/ast/PtrMemberNode.java: #baseType -> #dereferedType. * net/loveruby/cflat/ast/MemberNode.java: reduce cast for Type. * net/loveruby/cflat/type/Type.java: define #baseType here. * net/loveruby/cflat/type/ArrayType.java: override #baseType (#base -> #baseType). * net/loveruby/cflat/type/PointerType.java: ditto. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/ast/Function.java: ditto. * net/loveruby/cflat/type/PointerType.java: is not an integer. #isInteger removed. * net/loveruby/cflat/type/ArrayTypeRef.java: #base -> #baseType. * net/loveruby/cflat/type/PointerTypeRef.java: ditto. * net/loveruby/cflat/type/TypeTable.java: do not use cast methods, use true cast, since the real type is required here. * test/usertype.cb: test user type. * test/Makefile: build it. * test/test.sh: run it. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3776 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 19:26:07 +08:00
public ComplexType dereferedType() {
try {
PointerType pt = expr.type().getPointerType();
return pt.baseType().getComplexType();
}
catch (ClassCastException err) {
throw new SemanticError(err.getMessage());
}
}
public ExprNode expr() {
return expr;
}
public String name() {
return name;
}
public boolean isAssignable() {
return true;
}
// LHS node requirement
public boolean isConstantAddress() {
return false;
}
// LHS node requirement
public AsmEntity address() {
throw new Error("PtrMemberNode#address");
}
public long offset() {
* net/loveruby/cflat/compiler/TypeChecker.java: <<, >> does not require same type of integers. 2 types of integers are OK. * net/loveruby/cflat/compiler/TypeChecker.java: arrays and pointers are both dereferable (== indexable). We can dereference both. * net/loveruby/cflat/type/Type.java: #isIndexable -> #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: ditto. * net/loveruby/cflat/ast/ExprNode.java: ditto. * net/loveruby/cflat/type/Type.java: #isReferable -> #isDereferable. * net/loveruby/cflat/type/ArrayType.java: ditto. * net/loveruby/cflat/type/PointerType.java: ditto. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ptr[0] should be allowed. Use #isDereferable instead of explict pointer check. * net/loveruby/cflat/ast/DereferenceNode.java: override #type. * net/loveruby/cflat/ast/ArefNode.java: remove cast for Type. * net/loveruby/cflat/ast/FuncallNode.java: #functionType should be called after checking isCallable, type check is not needed in #functionType. * net/loveruby/cflat/ast/PtrMemberNode.java: #baseType -> #dereferedType. * net/loveruby/cflat/ast/MemberNode.java: reduce cast for Type. * net/loveruby/cflat/type/Type.java: define #baseType here. * net/loveruby/cflat/type/ArrayType.java: override #baseType (#base -> #baseType). * net/loveruby/cflat/type/PointerType.java: ditto. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/ast/Function.java: ditto. * net/loveruby/cflat/type/PointerType.java: is not an integer. #isInteger removed. * net/loveruby/cflat/type/ArrayTypeRef.java: #base -> #baseType. * net/loveruby/cflat/type/PointerTypeRef.java: ditto. * net/loveruby/cflat/type/TypeTable.java: do not use cast methods, use true cast, since the real type is required here. * test/usertype.cb: test user type. * test/Makefile: build it. * test/test.sh: run it. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3776 1b9489fe-b721-0410-924e-b54b9192deb8
2008-01-03 19:26:07 +08:00
return dereferedType().memberOffset(name);
}
protected void _dump(Dumper d) {
d.printMember("expr", expr);
d.printMember("name", name);
}
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}