From a0239405377e9c98dd45508046a5571d02d189aa Mon Sep 17 00:00:00 2001 From: Minero Aoki Date: Thu, 3 Jan 2008 23:30:58 +0000 Subject: [PATCH] * net/loveruby/cflat/ast/Dumper.java: specialize TypeNode printing. * net/loveruby/cflat/ast/Params.java: show parameter list. * net/loveruby/cflat/type/*TypeRef.java: define #toString. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3788 1b9489fe-b721-0410-924e-b54b9192deb8 --- ChangeLog | 9 +++++++++ net/loveruby/cflat/ast/Dumper.java | 5 +++++ net/loveruby/cflat/ast/Params.java | 3 +-- net/loveruby/cflat/type/ArrayTypeRef.java | 7 +++++++ net/loveruby/cflat/type/FunctionTypeRef.java | 16 ++++++++++++++++ net/loveruby/cflat/type/PointerTypeRef.java | 4 ++++ net/loveruby/cflat/type/SignedCharRef.java | 4 ++++ net/loveruby/cflat/type/SignedIntRef.java | 4 ++++ net/loveruby/cflat/type/SignedLongRef.java | 4 ++++ net/loveruby/cflat/type/SignedShortRef.java | 4 ++++ net/loveruby/cflat/type/StructTypeRef.java | 4 ++++ net/loveruby/cflat/type/UnionTypeRef.java | 4 ++++ net/loveruby/cflat/type/UnsignedCharRef.java | 4 ++++ net/loveruby/cflat/type/UnsignedIntRef.java | 4 ++++ net/loveruby/cflat/type/UnsignedLongRef.java | 4 ++++ net/loveruby/cflat/type/UnsignedShortRef.java | 4 ++++ net/loveruby/cflat/type/UserTypeRef.java | 4 ++++ net/loveruby/cflat/type/VoidTypeRef.java | 4 ++++ 18 files changed, 90 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd8b7f6..308cfe4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Jan 4 08:30:55 2008 Minero Aoki + + * net/loveruby/cflat/ast/Dumper.java: specialize TypeNode + printing. + + * net/loveruby/cflat/ast/Params.java: show parameter list. + + * net/loveruby/cflat/type/*TypeRef.java: define #toString. + Fri Jan 4 08:01:31 2008 Minero Aoki * net/loveruby/cflat/compiler/Compiler.java: implement command diff --git a/net/loveruby/cflat/ast/Dumper.java b/net/loveruby/cflat/ast/Dumper.java index e86e9bb..66d6280 100644 --- a/net/loveruby/cflat/ast/Dumper.java +++ b/net/loveruby/cflat/ast/Dumper.java @@ -67,6 +67,11 @@ public class Dumper { stream.println(name + ": " + value); } + public void printMember(String name, TypeNode n) { + printIndent(); + stream.println(name + ": " + n.typeRef()); + } + public void printMember(String name, Node n) { printIndent(); if (n == null) { diff --git a/net/loveruby/cflat/ast/Params.java b/net/loveruby/cflat/ast/Params.java index 0262b40..e3e2fd8 100644 --- a/net/loveruby/cflat/ast/Params.java +++ b/net/loveruby/cflat/ast/Params.java @@ -16,7 +16,6 @@ abstract public class Params extends Node { abstract public Params typeRefs(); protected void _dump(Dumper d) { - // FIXME - d.printMember("parameters", "FIXME"); + d.printNodeList("parameters", parameters()); } } diff --git a/net/loveruby/cflat/type/ArrayTypeRef.java b/net/loveruby/cflat/type/ArrayTypeRef.java index 5550b19..3601e16 100644 --- a/net/loveruby/cflat/type/ArrayTypeRef.java +++ b/net/loveruby/cflat/type/ArrayTypeRef.java @@ -40,4 +40,11 @@ public class ArrayTypeRef extends TypeRef { public boolean isLengthUndefined() { return (length == undefined); } + + public String toString() { + return baseType.toString() + + "[" + + (length == undefined ? "" : "" + length) + + "]"; + } } diff --git a/net/loveruby/cflat/type/FunctionTypeRef.java b/net/loveruby/cflat/type/FunctionTypeRef.java index 28b3a28..46403c9 100644 --- a/net/loveruby/cflat/type/FunctionTypeRef.java +++ b/net/loveruby/cflat/type/FunctionTypeRef.java @@ -33,4 +33,20 @@ public class FunctionTypeRef extends TypeRef { public Params params() { return params; } + + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append(returnType.toString()); + buf.append(" ("); + Iterator params = this.params.parameters(); + String sep = ""; + while (params.hasNext()) { + TypeRef ref = (TypeRef)params.next(); + buf.append(sep); + buf.append(ref.toString()); + sep = ", "; + } + buf.append(")"); + return buf.toString(); + } } diff --git a/net/loveruby/cflat/type/PointerTypeRef.java b/net/loveruby/cflat/type/PointerTypeRef.java index 595509f..97badc5 100644 --- a/net/loveruby/cflat/type/PointerTypeRef.java +++ b/net/loveruby/cflat/type/PointerTypeRef.java @@ -23,4 +23,8 @@ public class PointerTypeRef extends TypeRef { public int hashCode() { return (1 << 11) & baseType.hashCode(); } + + public String toString() { + return baseType.toString() + "*"; + } } diff --git a/net/loveruby/cflat/type/SignedCharRef.java b/net/loveruby/cflat/type/SignedCharRef.java index bd3a4b1..55fef27 100644 --- a/net/loveruby/cflat/type/SignedCharRef.java +++ b/net/loveruby/cflat/type/SignedCharRef.java @@ -15,4 +15,8 @@ public class SignedCharRef extends TypeRef { public int hashCode() { return 0; } + + public String toString() { + return "char"; + } } diff --git a/net/loveruby/cflat/type/SignedIntRef.java b/net/loveruby/cflat/type/SignedIntRef.java index f4a80ab..373582f 100644 --- a/net/loveruby/cflat/type/SignedIntRef.java +++ b/net/loveruby/cflat/type/SignedIntRef.java @@ -15,4 +15,8 @@ public class SignedIntRef extends TypeRef { public int hashCode() { return 2; } + + public String toString() { + return "int"; + } } diff --git a/net/loveruby/cflat/type/SignedLongRef.java b/net/loveruby/cflat/type/SignedLongRef.java index 0e767ac..3070176 100644 --- a/net/loveruby/cflat/type/SignedLongRef.java +++ b/net/loveruby/cflat/type/SignedLongRef.java @@ -15,4 +15,8 @@ public class SignedLongRef extends TypeRef { public int hashCode() { return 3; } + + public String toString() { + return "long"; + } } diff --git a/net/loveruby/cflat/type/SignedShortRef.java b/net/loveruby/cflat/type/SignedShortRef.java index 99e5a1e..0db9bcf 100644 --- a/net/loveruby/cflat/type/SignedShortRef.java +++ b/net/loveruby/cflat/type/SignedShortRef.java @@ -15,4 +15,8 @@ public class SignedShortRef extends TypeRef { public int hashCode() { return 1; } + + public String toString() { + return "short"; + } } diff --git a/net/loveruby/cflat/type/StructTypeRef.java b/net/loveruby/cflat/type/StructTypeRef.java index 8826e10..1d5237f 100644 --- a/net/loveruby/cflat/type/StructTypeRef.java +++ b/net/loveruby/cflat/type/StructTypeRef.java @@ -23,4 +23,8 @@ public class StructTypeRef extends TypeRef { public String name() { return name; } + + public String toString() { + return "struct " + name; + } } diff --git a/net/loveruby/cflat/type/UnionTypeRef.java b/net/loveruby/cflat/type/UnionTypeRef.java index d01ebf1..722b6f2 100644 --- a/net/loveruby/cflat/type/UnionTypeRef.java +++ b/net/loveruby/cflat/type/UnionTypeRef.java @@ -23,4 +23,8 @@ public class UnionTypeRef extends TypeRef { public String name() { return name; } + + public String toString() { + return "union " + name; + } } diff --git a/net/loveruby/cflat/type/UnsignedCharRef.java b/net/loveruby/cflat/type/UnsignedCharRef.java index 53e6ce1..d42427c 100644 --- a/net/loveruby/cflat/type/UnsignedCharRef.java +++ b/net/loveruby/cflat/type/UnsignedCharRef.java @@ -15,4 +15,8 @@ public class UnsignedCharRef extends TypeRef { public int hashCode() { return 4; } + + public String toString() { + return "unsigned char"; + } } diff --git a/net/loveruby/cflat/type/UnsignedIntRef.java b/net/loveruby/cflat/type/UnsignedIntRef.java index dd722dd..fddcbe8 100644 --- a/net/loveruby/cflat/type/UnsignedIntRef.java +++ b/net/loveruby/cflat/type/UnsignedIntRef.java @@ -15,4 +15,8 @@ public class UnsignedIntRef extends TypeRef { public int hashCode() { return 6; } + + public String toString() { + return "unsigned int"; + } } diff --git a/net/loveruby/cflat/type/UnsignedLongRef.java b/net/loveruby/cflat/type/UnsignedLongRef.java index 2a0dc59..35168d0 100644 --- a/net/loveruby/cflat/type/UnsignedLongRef.java +++ b/net/loveruby/cflat/type/UnsignedLongRef.java @@ -15,4 +15,8 @@ public class UnsignedLongRef extends TypeRef { public int hashCode() { return 7; } + + public String toString() { + return "unsigned long"; + } } diff --git a/net/loveruby/cflat/type/UnsignedShortRef.java b/net/loveruby/cflat/type/UnsignedShortRef.java index d5cbd14..bd62969 100644 --- a/net/loveruby/cflat/type/UnsignedShortRef.java +++ b/net/loveruby/cflat/type/UnsignedShortRef.java @@ -15,4 +15,8 @@ public class UnsignedShortRef extends TypeRef { public int hashCode() { return 5; } + + public String toString() { + return "unsigned short"; + } } diff --git a/net/loveruby/cflat/type/UserTypeRef.java b/net/loveruby/cflat/type/UserTypeRef.java index 3e3abd4..00868e7 100644 --- a/net/loveruby/cflat/type/UserTypeRef.java +++ b/net/loveruby/cflat/type/UserTypeRef.java @@ -23,4 +23,8 @@ public class UserTypeRef extends TypeRef { public int hashCode() { return (1 << 12) & name.hashCode(); } + + public String toString() { + return name; + } } diff --git a/net/loveruby/cflat/type/VoidTypeRef.java b/net/loveruby/cflat/type/VoidTypeRef.java index ef3ea96..f46071c 100644 --- a/net/loveruby/cflat/type/VoidTypeRef.java +++ b/net/loveruby/cflat/type/VoidTypeRef.java @@ -15,4 +15,8 @@ public class VoidTypeRef extends TypeRef { public int hashCode() { return -1; } + + public String toString() { + return "void"; + } }