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

43 lines
954 B
Java
Raw Permalink Normal View History

package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.Type;
public class AddressNode extends ExprNode {
final ExprNode expr;
Type type;
public AddressNode(ExprNode expr) {
this.expr = expr;
}
public ExprNode expr() {
return expr;
}
public Type type() {
if (type == null) throw new Error("type is null");
return 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
/** Decides type of this node.
* This method is called from DereferenceChecker. */
public void setType(Type type) {
if (this.type != null) throw new Error("type set twice");
this.type = type;
}
public Location location() {
return expr.location();
}
protected void _dump(Dumper d) {
if (type != null) {
d.printMember("type", type);
}
d.printMember("expr", expr);
}
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}