Commit ed2ac9b8 authored by Rob Pike's avatar Rob Pike

casify reflect.

R=rsc
DELTA=513  (0 added, 2 deleted, 511 changed)
OCL=22954
CL=22956
parent aedfb397
......@@ -87,8 +87,6 @@ func valuedump(s, t string) {
assert(reflect.ValueToString(v), t);
}
export type empty interface {}
export type T struct { a int; b float64; c string; d *int }
export func TestAll(tt *testing.T) { // TODO(r): wrap up better
......@@ -342,14 +340,14 @@ export func TestBigUnnamedStruct(t *testing.T) {
}
}
type Big struct {
type big struct {
a, b, c, d, e int64
}
export func TestBigStruct(t *testing.T) {
b := Big{1, 2, 3, 4, 5};
b := big{1, 2, 3, 4, 5};
v := NewValue(b);
b1 := v.Interface().(Big);
b1 := v.Interface().(big);
if b1.a != b.a || b1.b != b.b || b1.c != b.c || b1.d != b.d || b1.e != b.e {
t.Errorf("NewValue(%v).Interface().(Big) = %v", b, b1);
t.Errorf("NewValue(%v).Interface().(big) = %v", b, b1);
}
}
......@@ -15,7 +15,7 @@ import (
export func TypeToString(typ Type, expand bool) string
export func ValueToString(val Value) string
func DoubleQuote(s string) string {
func doubleQuote(s string) string {
out := "\"";
for i := 0; i < len(s); i++ {
c := s[i];
......@@ -38,12 +38,12 @@ func DoubleQuote(s string) string {
return out;
}
type HasFields interface {
type hasFields interface {
Field(i int) (name string, typ Type, tag string, offset int);
Len() int;
}
func TypeFieldsToString(t HasFields, sep string) string {
func typeFieldsToString(t hasFields, sep string) string {
var str string;
for i := 0; i < t.Len(); i++ {
str1, typ, tag, offset := t.Field(i);
......@@ -52,7 +52,7 @@ func TypeFieldsToString(t HasFields, sep string) string {
}
str1 += TypeToString(typ, false);
if tag != "" {
str1 += " " + DoubleQuote(tag);
str1 += " " + doubleQuote(tag);
}
if i < t.Len() - 1 {
str1 += sep + " ";
......@@ -62,7 +62,7 @@ func TypeFieldsToString(t HasFields, sep string) string {
return str;
}
func TypeToString(typ Type, expand bool) string {
export func TypeToString(typ Type, expand bool) string {
var str string;
if name := typ.Name(); !expand && name != "" {
return name
......@@ -105,14 +105,14 @@ func TypeToString(typ Type, expand bool) string {
}
return str + TypeToString(c.Elem(), false);
case StructKind:
return "struct{" + TypeFieldsToString(typ, ";") + "}";
return "struct{" + typeFieldsToString(typ, ";") + "}";
case InterfaceKind:
return "interface{" + TypeFieldsToString(typ, ";") + "}";
return "interface{" + typeFieldsToString(typ, ";") + "}";
case FuncKind:
f := typ.(FuncType);
str = "(" + TypeFieldsToString(f.In(), ",") + ")";
str = "(" + typeFieldsToString(f.In(), ",") + ")";
if f.Out() != nil {
str += "(" + TypeFieldsToString(f.Out(), ",") + ")";
str += "(" + typeFieldsToString(f.Out(), ",") + ")";
}
return str;
default:
......@@ -126,7 +126,7 @@ func integer(v int64) string {
return strconv.Itoa64(v);
}
func ValueToString(val Value) string {
export func ValueToString(val Value) string {
var str string;
typ := val.Type();
switch(val.Kind()) {
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment