Commit f5cfadde authored by Rob Pike's avatar Rob Pike

implement two TODOs in reflect:

- delete vestigial SetString method
- make type map use interface instead of *interface

R=rsc
DELTA=31  (0 added, 7 deleted, 24 changed)
OCL=20861
CL=20863
parent 3935610e
...@@ -54,7 +54,6 @@ export type Type interface { ...@@ -54,7 +54,6 @@ export type Type interface {
Kind() int; Kind() int;
Name() string; Name() string;
String() string; String() string;
SetString(string); // TODO: remove when no longer needed
Size() int; Size() int;
} }
...@@ -78,10 +77,6 @@ func (c *Common) String() string { ...@@ -78,10 +77,6 @@ func (c *Common) String() string {
return c.str return c.str
} }
func (c *Common) SetString(s string) {
c.str = s
}
func (c *Common) Size() int { func (c *Common) Size() int {
return c.size return c.size
} }
...@@ -379,7 +374,7 @@ func (t *FuncTypeStruct) Out() StructType { ...@@ -379,7 +374,7 @@ func (t *FuncTypeStruct) Out() StructType {
} }
// Cache of expanded types keyed by type name. // Cache of expanded types keyed by type name.
var types *map[string] *Type // BUG TODO: should be Type not *Type var types *map[string] Type
// List of typename, typestring pairs // List of typename, typestring pairs
var typestring *map[string] string var typestring *map[string] string
...@@ -408,29 +403,29 @@ func init() { ...@@ -408,29 +403,29 @@ func init() {
Lock(); // not necessary because of init ordering but be safe. Lock(); // not necessary because of init ordering but be safe.
types = new(map[string] *Type); types = new(map[string] Type);
typestring = new(map[string] string); typestring = new(map[string] string);
basicstub = new(map[string] *StubType); basicstub = new(map[string] *StubType);
// Basics go into types table // Basics go into types table
types[MissingString] = &Missing; types[MissingString] = Missing;
types[DotDotDotString] = &DotDotDot; types[DotDotDotString] = DotDotDot;
types["int"] = ∬ types["int"] = Int;
types["int8"] = &Int8; types["int8"] = Int8;
types["int16"] = &Int16; types["int16"] = Int16;
types["int32"] = &Int32; types["int32"] = Int32;
types["int64"] = &Int64; types["int64"] = Int64;
types["uint"] = &Uint; types["uint"] = Uint;
types["uint8"] = &Uint8; types["uint8"] = Uint8;
types["uint16"] = &Uint16; types["uint16"] = Uint16;
types["uint32"] = &Uint32; types["uint32"] = Uint32;
types["uint64"] = &Uint64; types["uint64"] = Uint64;
types["float"] = &Float; types["float"] = Float;
types["float32"] = &Float32; types["float32"] = Float32;
types["float64"] = &Float64; types["float64"] = Float64;
types["float80"] = &Float80; types["float80"] = Float80;
types["string"] = &String; types["string"] = String;
types["bool"] = &Bool; types["bool"] = Bool;
// Basics get prebuilt stubs // Basics get prebuilt stubs
MissingStub = NewStubType(MissingString, Missing); MissingStub = NewStubType(MissingString, Missing);
...@@ -899,13 +894,11 @@ func ExpandType(name string) Type { ...@@ -899,13 +894,11 @@ func ExpandType(name string) Type {
t, ok := types[name]; t, ok := types[name];
if ok { if ok {
Unlock(); Unlock();
return *t return t
} }
types[name] = &Missing; // prevent recursion; will overwrite types[name] = Missing; // prevent recursion; will overwrite
t1 := ParseTypeString(name, TypeNameToTypeString(name)); t1 := ParseTypeString(name, TypeNameToTypeString(name));
p := new(Type); types[name] = t1;
*p = t1;
types[name] = p;
Unlock(); Unlock();
return t1; return t1;
} }
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