mirror of https://github.com/aamine/cbc
* net/loveruby/cflat/compiler/TypeChecker.java (checkCond): cond expr might be an array.
* net/loveruby/cflat/compiler/TypeChecker.java (SwitchNode): cond expr should not be pointer. * net/loveruby/cflat/compiler/TypeChecker.java: <</>> expects same integer. * net/loveruby/cflat/compiler/TypeChecker.java: comparison operators accept arrays. * net/loveruby/cflat/compiler/TypeChecker.java: "!" accepts a pointer and an array. * net/loveruby/cflat/compiler/TypeChecker.java: new method #mustBeScalarAlike. * net/loveruby/cflat/compiler/TypeChecker.java (mustBeInteger, mustBeScalar, mustBeScalarAlike): takes operator name. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3914 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
parent
d27ddfebee
commit
d1d388ab0c
23
ChangeLog
23
ChangeLog
|
@ -1,3 +1,26 @@
|
|||
Mon Feb 18 05:35:14 2008 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* net/loveruby/cflat/compiler/TypeChecker.java (checkCond): cond
|
||||
expr might be an array.
|
||||
|
||||
* net/loveruby/cflat/compiler/TypeChecker.java (SwitchNode): cond
|
||||
expr should not be pointer.
|
||||
|
||||
* net/loveruby/cflat/compiler/TypeChecker.java: <</>> expects same
|
||||
integer.
|
||||
|
||||
* net/loveruby/cflat/compiler/TypeChecker.java: comparison
|
||||
operators accept arrays.
|
||||
|
||||
* net/loveruby/cflat/compiler/TypeChecker.java: "!" accepts a
|
||||
pointer and an array.
|
||||
|
||||
* net/loveruby/cflat/compiler/TypeChecker.java: new method
|
||||
#mustBeScalarAlike.
|
||||
|
||||
* net/loveruby/cflat/compiler/TypeChecker.java (mustBeInteger,
|
||||
mustBeScalar, mustBeScalarAlike): takes operator name.
|
||||
|
||||
Mon Feb 18 04:10:40 2008 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* net/loveruby/cflat/compiler/TypeChecker.java (mustBeScalar):
|
||||
|
|
|
@ -106,12 +106,12 @@ class TypeChecker extends Visitor {
|
|||
}
|
||||
|
||||
protected void checkCond(ExprNode cond) {
|
||||
mustBeScalar(cond);
|
||||
mustBeScalarAlike(cond, "condition expression");
|
||||
}
|
||||
|
||||
public void visit(SwitchNode node) {
|
||||
super.visit(node);
|
||||
mustBeScalar(node.cond());
|
||||
mustBeInteger(node.cond(), "condition expression");
|
||||
}
|
||||
|
||||
public void visit(ReturnNode node) {
|
||||
|
@ -250,13 +250,10 @@ class TypeChecker extends Visitor {
|
|||
|| node.operator().equals("%")
|
||||
|| node.operator().equals("&")
|
||||
|| node.operator().equals("|")
|
||||
|| node.operator().equals("^")) {
|
||||
expectsSameInteger(node);
|
||||
}
|
||||
else if (node.operator().equals("<<")
|
||||
|| node.operator().equals("^")
|
||||
|| node.operator().equals("<<")
|
||||
|| node.operator().equals(">>")) {
|
||||
expectsIntegers(node);
|
||||
expectsIntegers(node);
|
||||
expectsSameInteger(node);
|
||||
}
|
||||
else if (node.operator().equals("==")
|
||||
|| node.operator().equals("!=")
|
||||
|
@ -290,11 +287,11 @@ class TypeChecker extends Visitor {
|
|||
*/
|
||||
protected void expectsSameIntegerOrPointerDiff(BinaryOpNode node) {
|
||||
if (node.left().type().isPointer()) {
|
||||
mustBeInteger(node.right());
|
||||
mustBeInteger(node.right(), node.operator());
|
||||
node.setType(node.left().type());
|
||||
}
|
||||
else if (node.right().type().isPointer()) {
|
||||
mustBeInteger(node.left());
|
||||
mustBeInteger(node.left(), node.operator());
|
||||
node.setType(node.right().type());
|
||||
}
|
||||
else {
|
||||
|
@ -302,23 +299,17 @@ class TypeChecker extends Visitor {
|
|||
}
|
||||
}
|
||||
|
||||
// *, /, %, &, |, ^
|
||||
// +, -, *, /, %, &, |, ^, <<, >>
|
||||
protected void expectsSameInteger(BinaryOpNode node) {
|
||||
mustBeInteger(node.left());
|
||||
mustBeInteger(node.right());
|
||||
mustBeInteger(node.left(), node.operator());
|
||||
mustBeInteger(node.right(), node.operator());
|
||||
insertImplicitCast(node);
|
||||
}
|
||||
|
||||
// <<, >>
|
||||
protected void expectsIntegers(BinaryOpNode node) {
|
||||
mustBeInteger(node.left());
|
||||
mustBeInteger(node.right());
|
||||
}
|
||||
|
||||
// ==, !=, <, <=, >, >=, &&, ||
|
||||
protected void expectsComparableScalars(BinaryOpNode node) {
|
||||
mustBeScalar(node.left());
|
||||
mustBeScalar(node.right());
|
||||
mustBeScalarAlike(node.left(), node.operator());
|
||||
mustBeScalarAlike(node.right(), node.operator());
|
||||
insertImplicitCast(node);
|
||||
}
|
||||
|
||||
|
@ -344,19 +335,24 @@ class TypeChecker extends Visitor {
|
|||
// +, -, !, ~
|
||||
public void visit(UnaryOpNode node) {
|
||||
super.visit(node);
|
||||
mustBeInteger(node.expr());
|
||||
if (node.operator().equals("!")) {
|
||||
mustBeScalarAlike(node.expr(), node.operator());
|
||||
}
|
||||
else {
|
||||
mustBeInteger(node.expr(), node.operator());
|
||||
}
|
||||
}
|
||||
|
||||
// ++, --
|
||||
public void visit(PrefixOpNode node) {
|
||||
super.visit(node);
|
||||
mustBeScalar(node.expr());
|
||||
mustBeScalar(node.expr(), node.operator());
|
||||
}
|
||||
|
||||
// ++, --
|
||||
public void visit(SuffixOpNode node) {
|
||||
super.visit(node);
|
||||
mustBeScalar(node.expr());
|
||||
mustBeScalar(node.expr(), node.operator());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -393,7 +389,7 @@ class TypeChecker extends Visitor {
|
|||
|
||||
public void visit(ArefNode node) {
|
||||
super.visit(node);
|
||||
mustBeInteger(node.index());
|
||||
mustBeInteger(node.index(), "[]");
|
||||
}
|
||||
|
||||
public void visit(CastNode node) {
|
||||
|
@ -411,27 +407,29 @@ class TypeChecker extends Visitor {
|
|||
return new CastNode(new TypeNode(t), n);
|
||||
}
|
||||
|
||||
protected void mustBeInteger(ExprNode node) {
|
||||
protected void mustBeInteger(ExprNode node, String op) {
|
||||
if (node.type().isInteger()) return;
|
||||
notIntegerError(node, node.type());
|
||||
notIntegerError(node, node.type(), op);
|
||||
}
|
||||
|
||||
protected void mustBeScalar(ExprNode node) {
|
||||
protected void mustBeScalar(ExprNode node, String op) {
|
||||
if (node.type().isInteger()) return;
|
||||
if (node.type().isPointer()) return;
|
||||
notIntegerError(node, node.type(), op);
|
||||
}
|
||||
|
||||
protected void mustBeScalarAlike(ExprNode node, String op) {
|
||||
if (node.type().isInteger()) return;
|
||||
if (node.type().isPointerAlike()) return;
|
||||
notIntegerError(node, node.type());
|
||||
notIntegerError(node, node.type(), op);
|
||||
}
|
||||
|
||||
protected void incompatibleTypeError(Node n, Type l, Type r) {
|
||||
error(n, "incompatible type: " + l + " and " + r);
|
||||
}
|
||||
|
||||
protected void notIntegerError(Node n, Type type) {
|
||||
error(n, "non-integer argument for unary op: " + type);
|
||||
}
|
||||
|
||||
protected void undereferableError(Node n, Type type) {
|
||||
error(n, "dereferencing non-pointer expression: " + type);
|
||||
protected void notIntegerError(Node n, Type type, String op) {
|
||||
error(n, "wrong operand type for " + op + ": " + type);
|
||||
}
|
||||
|
||||
protected void warn(Node n, String msg) {
|
||||
|
|
Loading…
Reference in New Issue