Commit 730fd707 authored by Rob Pike's avatar Rob Pike

support ... as a special type in the reflection library.

R=rsc
DELTA=17  (17 added, 0 deleted, 0 changed)
OCL=18386
CL=18393
parent c4969a3b
...@@ -124,6 +124,7 @@ func main() { ...@@ -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; 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 there\"; }", "struct{a int8 \"hi there\"}");
typedump("struct {a int8 \"hi \\x00there\\t\\n\\\"\\\\\"; }", "struct{a int8 \"hi \\x00there\\t\\n\\\"\\\\\"}"); 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("int8", "8");
valuedump("int16", "16"); valuedump("int16", "16");
......
...@@ -67,6 +67,8 @@ func TypeToString(typ Type, expand bool) string { ...@@ -67,6 +67,8 @@ func TypeToString(typ Type, expand bool) string {
switch(typ.Kind()) { switch(typ.Kind()) {
case MissingKind: case MissingKind:
return "$missing$"; return "$missing$";
case DotDotDotKind:
return "...";
case IntKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind, case IntKind, Int8Kind, Int16Kind, Int32Kind, Int64Kind,
UintKind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind, UintKind, Uint8Kind, Uint16Kind, Uint32Kind, Uint64Kind,
FloatKind, Float32Kind, Float64Kind, Float80Kind: FloatKind, Float32Kind, Float64Kind, Float80Kind:
......
...@@ -18,6 +18,7 @@ export const ( ...@@ -18,6 +18,7 @@ export const (
ArrayKind; ArrayKind;
BoolKind; BoolKind;
ChanKind; ChanKind;
DotDotDotKind;
FloatKind; FloatKind;
Float32Kind; Float32Kind;
Float64Kind; Float64Kind;
...@@ -44,6 +45,7 @@ var ptrsize uint64 ...@@ -44,6 +45,7 @@ var ptrsize uint64
var interfacesize uint64 var interfacesize uint64
var MissingString = "$missing$" // syntactic name for undefined type names var MissingString = "$missing$" // syntactic name for undefined type names
var DotDotDotString = "..."
export type Type interface { export type Type interface {
Kind() int; Kind() int;
...@@ -83,6 +85,7 @@ func NewBasicType(name string, kind int, size uint64) Type { ...@@ -83,6 +85,7 @@ func NewBasicType(name string, kind int, size uint64) Type {
// Prebuilt basic types // Prebuilt basic types
export var ( export var (
Missing = NewBasicType(MissingString, MissingKind, 1); 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 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 Int = NewBasicType("int", IntKind, 4); // TODO: need to know how big an int is
Int8 = NewBasicType("int8", Int8Kind, 1); Int8 = NewBasicType("int8", Int8Kind, 1);
...@@ -371,6 +374,7 @@ var initialized bool = false ...@@ -371,6 +374,7 @@ var initialized bool = false
var basicstub *map[string] *StubType var basicstub *map[string] *StubType
var MissingStub *StubType; var MissingStub *StubType;
var DotDotDotStub *StubType;
// The database stored in the maps is global; use locking to guarantee safety. // 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 var lockchan *chan bool // Channel with buffer of 1, used as a mutex
...@@ -396,6 +400,7 @@ func init() { ...@@ -396,6 +400,7 @@ func init() {
// Basics go into types table // Basics go into types table
types[MissingString] = &Missing; types[MissingString] = &Missing;
types[DotDotDotString] = &DotDotDot;
types["int"] = ∬ types["int"] = ∬
types["int8"] = &Int8; types["int8"] = &Int8;
types["int16"] = &Int16; types["int16"] = &Int16;
...@@ -415,7 +420,9 @@ func init() { ...@@ -415,7 +420,9 @@ func init() {
// Basics get prebuilt stubs // Basics get prebuilt stubs
MissingStub = NewStubType(MissingString, Missing); MissingStub = NewStubType(MissingString, Missing);
DotDotDotStub = NewStubType(DotDotDotString, DotDotDot);
basicstub[MissingString] = MissingStub; basicstub[MissingString] = MissingStub;
basicstub[DotDotDotString] = DotDotDotStub;
basicstub["int"] = NewStubType("int", Int); basicstub["int"] = NewStubType("int", Int);
basicstub["int8"] = NewStubType("int8", Int8); basicstub["int8"] = NewStubType("int8", Int8);
basicstub["int16"] = NewStubType("int16", Int16); basicstub["int16"] = NewStubType("int16", Int16);
...@@ -559,6 +566,13 @@ func (p *Parser) Next() { ...@@ -559,6 +566,13 @@ func (p *Parser) Next() {
return; return;
} }
fallthrough; // shouldn't happen but let the parser figure it out 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)): case special(uint8(c)):
p.token = string(c); p.token = string(c);
return; return;
......
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