From 730fd707cb4ce48b21ccda2c881e0750d6475244 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 3 Nov 2008 15:50:11 -0800 Subject: [PATCH] support ... as a special type in the reflection library. R=rsc DELTA=17 (17 added, 0 deleted, 0 changed) OCL=18386 CL=18393 --- src/lib/reflect/test.go | 1 + src/lib/reflect/tostring.go | 2 ++ src/lib/reflect/type.go | 14 ++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/lib/reflect/test.go b/src/lib/reflect/test.go index e277f207b4..d057251905 100644 --- a/src/lib/reflect/test.go +++ b/src/lib/reflect/test.go @@ -124,6 +124,7 @@ func main() { typedump("struct {a int8; b int8; c int8; d int8; e int8; b int32}", "struct{a int8; b int8; c int8; d int8; e int8; b int32}"); typedump("struct {a int8 \"hi there\"; }", "struct{a int8 \"hi there\"}"); typedump("struct {a int8 \"hi \\x00there\\t\\n\\\"\\\\\"; }", "struct{a int8 \"hi \\x00there\\t\\n\\\"\\\\\"}"); + typedump("struct {f *(args ...)}", "struct{f *(args ...)}"); valuedump("int8", "8"); valuedump("int16", "16"); diff --git a/src/lib/reflect/tostring.go b/src/lib/reflect/tostring.go index f35caded97..e5c4588d83 100644 --- a/src/lib/reflect/tostring.go +++ b/src/lib/reflect/tostring.go @@ -67,6 +67,8 @@ func TypeToString(typ Type, expand bool) string { switch(typ.Kind()) { case MissingKind: return "$missing$"; + case DotDotDotKind: + return "..."; case IntKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, UintKind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, FloatKind, Float32Kind, Float64Kind, Float80Kind: diff --git a/src/lib/reflect/type.go b/src/lib/reflect/type.go index d4bc263870..8d5d2bde1a 100644 --- a/src/lib/reflect/type.go +++ b/src/lib/reflect/type.go @@ -18,6 +18,7 @@ export const ( ArrayKind; BoolKind; ChanKind; + DotDotDotKind; FloatKind; Float32Kind; Float64Kind; @@ -44,6 +45,7 @@ var ptrsize uint64 var interfacesize uint64 var MissingString = "$missing$" // syntactic name for undefined type names +var DotDotDotString = "..." export type Type interface { Kind() int; @@ -83,6 +85,7 @@ func NewBasicType(name string, kind int, size uint64) Type { // Prebuilt basic types export var ( Missing = NewBasicType(MissingString, MissingKind, 1); + DotDotDot = NewBasicType(DotDotDotString, DotDotDotKind, 16); // TODO(r): size of interface? Bool = NewBasicType("bool", BoolKind, 1); // TODO: need to know how big a bool is Int = NewBasicType("int", IntKind, 4); // TODO: need to know how big an int is Int8 = NewBasicType("int8", Int8Kind, 1); @@ -371,6 +374,7 @@ var initialized bool = false var basicstub *map[string] *StubType var MissingStub *StubType; +var DotDotDotStub *StubType; // The database stored in the maps is global; use locking to guarantee safety. var lockchan *chan bool // Channel with buffer of 1, used as a mutex @@ -396,6 +400,7 @@ func init() { // Basics go into types table types[MissingString] = &Missing; + types[DotDotDotString] = &DotDotDot; types["int"] = ∬ types["int8"] = &Int8; types["int16"] = &Int16; @@ -415,7 +420,9 @@ func init() { // Basics get prebuilt stubs MissingStub = NewStubType(MissingString, Missing); + DotDotDotStub = NewStubType(DotDotDotString, DotDotDot); basicstub[MissingString] = MissingStub; + basicstub[DotDotDotString] = DotDotDotStub; basicstub["int"] = NewStubType("int", Int); basicstub["int8"] = NewStubType("int8", Int8); basicstub["int16"] = NewStubType("int16", Int16); @@ -559,6 +566,13 @@ func (p *Parser) Next() { return; } fallthrough; // shouldn't happen but let the parser figure it out + case c == '.': + if p.index < len(p.str)+2 && p.str[p.index-1:p.index+2] == DotDotDotString { + p.index += 2; + p.token = DotDotDotString; + return; + } + fallthrough; // shouldn't happen but let the parser figure it out case special(uint8(c)): p.token = string(c); return; -- 2.50.0