* net/loveruby/cflat/type/Type.java: #textize -> #toString.

* net/loveruby/cflat/type/IntegerType.java: ditto.
* net/loveruby/cflat/type/ComplexType.java: ditto.
* net/loveruby/cflat/type/StructType.java: ditto.
* net/loveruby/cflat/type/FunctionType.java: ditto.
* net/loveruby/cflat/type/VoidType.java: ditto.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/type/ArrayType.java: ditto.
* net/loveruby/cflat/type/PointerType.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: ditto.
* net/loveruby/cflat/type/UnionType.java: ditto.
* net/loveruby/cflat/ast/Dumper.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3791 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2008-01-04 18:43:45 +00:00
parent a023940537
commit bdaa4f96d1
14 changed files with 58 additions and 40 deletions

View File

@ -1,3 +1,31 @@
Sat Jan 5 03:43:42 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/type/Type.java: #textize -> #toString.
* net/loveruby/cflat/type/IntegerType.java: ditto.
* net/loveruby/cflat/type/ComplexType.java: ditto.
* net/loveruby/cflat/type/StructType.java: ditto.
* net/loveruby/cflat/type/FunctionType.java: ditto.
* net/loveruby/cflat/type/VoidType.java: ditto.
* net/loveruby/cflat/type/UserType.java: ditto.
* net/loveruby/cflat/type/ArrayType.java: ditto.
* net/loveruby/cflat/type/PointerType.java: ditto.
* net/loveruby/cflat/type/TypeTable.java: ditto.
* net/loveruby/cflat/type/UnionType.java: ditto.
* net/loveruby/cflat/ast/Dumper.java: ditto.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
Fri Jan 4 08:30:55 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/ast/Dumper.java: specialize TypeNode

View File

@ -55,7 +55,7 @@ public class Dumper {
}
public void printMember(String name, Type t) {
printPair(name, (t == null ? "null" : t.textize()));
printPair(name, (t == null ? "null" : t.toString()));
}
public void printMember(String name, String str) {

View File

@ -55,8 +55,7 @@ class TypeChecker extends Visitor {
while (params.hasNext()) {
Parameter param = (Parameter)params.next();
if (isInvalidArgType(param.type())) {
errorHandler.error("invalid parameter type: "
+ param.type().textize());
errorHandler.error("invalid parameter type: " + param.type());
}
}
}
@ -150,8 +149,7 @@ class TypeChecker extends Visitor {
node.setExpr(newCastNode(retType, node.expr()));
}
else {
errorHandler.error("returning incompatible value: "
+ exprType.textize());
errorHandler.error("returning incompatible value: " + exprType);
}
}
@ -228,8 +226,7 @@ class TypeChecker extends Visitor {
}
else if (r.isCastableTo(l)) { // insert cast on RHS
if (! r.isCompatible(l)) {
errorHandler.warn("implicit cast from " +
r.textize() + " to " + l.textize());
errorHandler.warn("implicit cast from " + r + " to " + l);
}
return newCastNode(l, rhs);
}
@ -482,8 +479,7 @@ class TypeChecker extends Visitor {
/** Checks argument type and insert implicit cast if needed. */
protected ExprNode checkArgType(ExprNode arg, Type param) {
if (isInvalidArgType(arg.type())) {
errorHandler.error("invalid argument type: "
+ arg.type().textize());
errorHandler.error("invalid argument type: " + arg.type());
return arg;
}
if (arg.type().isSameType(param)) {
@ -512,8 +508,7 @@ class TypeChecker extends Visitor {
public void visit(ArefNode node) {
resolve(node.expr());
if (! node.expr().isDereferable()) {
errorHandler.error("is not indexable: " +
node.expr().type().textize());
errorHandler.error("is not indexable: " + node.expr().type());
return;
}
resolve(node.index());
@ -536,13 +531,13 @@ class TypeChecker extends Visitor {
protected void checkMemberRef(Type t, String memb) {
if (! t.isComplexType()) {
errorHandler.error("is not struct/union: " + t.textize());
errorHandler.error("is not struct/union: " + t);
return;
}
ComplexType type = t.getComplexType();
if (! type.hasMember(memb)) {
errorHandler.error(type.textize() +
" does not have member " + memb);
errorHandler.error(type.toString()
+ " does not have member " + memb);
return;
}
}
@ -571,8 +566,8 @@ class TypeChecker extends Visitor {
}
else if (! node.expr().type().isCompatible(node.type())) {
errorHandler.warn("incompatible cast from "
+ node.expr().type().textize()
+ " to " + node.type().textize());
+ node.expr().type()
+ " to " + node.type());
}
}
@ -596,17 +591,14 @@ class TypeChecker extends Visitor {
}
protected void incompatibleTypeError(Type l, Type r) {
errorHandler.error("incompatible type: "
+ l.textize() + " and " + r.textize());
errorHandler.error("incompatible type: " + l + " and " + r);
}
protected void notIntegerError(Type type) {
errorHandler.error("non-integer argument for unary op: "
+ type.textize());
errorHandler.error("non-integer argument for unary op: " + type);
}
protected void undereferableError(Type type) {
errorHandler.error("dereferencing non-pointer expression: "
+ type.textize());
errorHandler.error("dereferencing non-pointer expression: " + type);
}
}

View File

@ -49,12 +49,12 @@ public class ArrayType extends Type {
return baseType.isSameType(other.baseType());
}
public String textize() {
public String toString() {
if (length < 0) {
return baseType.textize() + "[]";
return baseType.toString() + "[]";
}
else {
return baseType.textize() + "[" + length + "]";
return baseType.toString() + "[" + length + "]";
}
}
}

View File

@ -63,7 +63,7 @@ abstract public class ComplexType extends Type {
Slot s = get(name);
if (s == null) {
throw new SemanticError("no such member in "
+ textize() + ": " + name);
+ toString() + ": " + name);
}
return s;
}

View File

@ -51,14 +51,14 @@ public class FunctionType extends Type {
throw new Error("FunctionType#size called");
}
public String textize() {
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append(returnType.textize());
buf.append(returnType.toString());
buf.append(" (*)(");
Iterator params = paramTypes.parameters();
while (params.hasNext()) {
Type t = (Type)params.next();
buf.append(t.textize());
buf.append(t.toString());
}
buf.append(")");
return buf.toString();

View File

@ -31,7 +31,7 @@ public class IntegerType extends Type {
return size;
}
public String textize() {
public String toString() {
return name;
}
}

View File

@ -33,7 +33,7 @@ public class PointerType extends Type {
return baseType.isSameType(other.baseType());
}
public String textize() {
return baseType.textize() + "*";
public String toString() {
return baseType.toString() + "*";
}
}

View File

@ -33,7 +33,7 @@ public class StructType extends ComplexType {
size = offset;
}
public String textize() {
public String toString() {
return "struct " + name;
}
}

View File

@ -8,8 +8,6 @@ public abstract class Type {
return size();
}
abstract public String textize();
abstract public long size();
public long allocSize() { return size(); }

View File

@ -184,7 +184,7 @@ public class TypeTable {
while (membs.hasNext()) {
Slot memb = (Slot)membs.next();
if (seen.containsKey(memb.name())) {
h.error(t.textize() + " has duplicated member: "
h.error(t.toString() + " has duplicated member: "
+ memb.name());
}
seen.put(memb.name(), memb);
@ -201,7 +201,7 @@ public class TypeTable {
protected void _checkRecursiveDefinition(Type t, Map seen,
ErrorHandler h) {
if (seen.get(t) == checking) {
h.error("recursive type definition: " + t.textize());
h.error("recursive type definition: " + t);
return;
}
else if (seen.get(t) == checked) {

View File

@ -32,7 +32,7 @@ public class UnionType extends ComplexType {
size = max;
}
public String textize() {
public String toString() {
return "union " + name;
}
}

View File

@ -22,7 +22,7 @@ public class UserType extends Type {
return real;
}
public String textize() {
public String toString() {
return name;
}

View File

@ -11,7 +11,7 @@ public class VoidType extends Type {
throw new Error("VoidType#size called");
}
public String textize() {
public String toString() {
return "void";
}
}