]> Cypherpunks repositories - gostls13.git/commitdiff
support ... as a special type in the reflection library.
authorRob Pike <r@golang.org>
Mon, 3 Nov 2008 23:50:11 +0000 (15:50 -0800)
committerRob Pike <r@golang.org>
Mon, 3 Nov 2008 23:50:11 +0000 (15:50 -0800)
R=rsc
DELTA=17  (17 added, 0 deleted, 0 changed)
OCL=18386
CL=18393

src/lib/reflect/test.go
src/lib/reflect/tostring.go
src/lib/reflect/type.go

index e277f207b46e24366eaa27e1eaae12b5c10feefc..d057251905cd83c1ee786fa5c4ed020fc1bcec41 100644 (file)
@@ -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");
index f35caded97d0a164d48455c650dd5bfabe0592a0..e5c4588d83b554c00d45eab43959a90d9d3d3e91 100644 (file)
@@ -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:
index d4bc263870804a4a815b8dddc4e93f943162bfcd..8d5d2bde1ae1c68ca7838a111697d4374cfa0ca3 100644 (file)
@@ -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"] = &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;