1
0
mirror of https://github.com/golang/go synced 2024-11-19 03:44:40 -07:00

cmd/compile: add typMap

Also, add two uses of Key and Val that I missed earlier.
As before, direct writes to Down and Type remain in bimport.

Change-Id: I487aa975926b30092db1ad74ace17994697117c1
Reviewed-on: https://go-review.googlesource.com/21330
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Josh Bleecher Snyder 2016-03-30 10:52:13 -07:00
parent dc5a7682f0
commit 76e72691a0
3 changed files with 18 additions and 13 deletions

View File

@ -301,8 +301,8 @@ func dumpexporttype(t *Type) {
dumpexporttype(t.Results()) dumpexporttype(t.Results())
dumpexporttype(t.Params()) dumpexporttype(t.Params())
case TMAP: case TMAP:
dumpexporttype(t.Type) dumpexporttype(t.Val())
dumpexporttype(t.Down) // key dumpexporttype(t.Key())
case TARRAY, TCHAN, TPTR32, TPTR64: case TARRAY, TCHAN, TPTR32, TPTR64:
dumpexporttype(t.Type) dumpexporttype(t.Type)
} }

View File

@ -382,27 +382,24 @@ func maptype(key *Type, val *Type) *Type {
Yyerror("invalid map key type %v", key) Yyerror("invalid map key type %v", key)
} }
// will be resolved later.
case TANY: case TANY:
// will be resolved later.
break break
case TFORW:
// map[key] used during definition of key. // map[key] used during definition of key.
// postpone check until key is fully defined. // postpone check until key is fully defined.
// if there are multiple uses of map[key] // if there are multiple uses of map[key]
// before key is fully defined, the error // before key is fully defined, the error
// will only be printed for the first one. // will only be printed for the first one.
// good enough. // good enough.
case TFORW:
if key.Maplineno == 0 { if key.Maplineno == 0 {
key.Maplineno = lineno key.Maplineno = lineno
} }
} }
} }
t := typ(TMAP) return typMap(key, val)
t.Down = key
t.Type = val
return t
} }
// methcmp sorts by symbol, then by package path for unexported symbols. // methcmp sorts by symbol, then by package path for unexported symbols.

View File

@ -267,6 +267,14 @@ func typeChan(elem *Type, dir uint8) *Type {
return t return t
} }
// typMap returns a new map Type with key type k and element (aka value) type v.
func typMap(k, v *Type) *Type {
t := typ(TMAP)
t.Down = k
t.Type = v
return t
}
// typPtr returns a new pointer type pointing to t. // typPtr returns a new pointer type pointing to t.
func typPtr(elem *Type) *Type { func typPtr(elem *Type) *Type {
t := typ(Tptr) t := typ(Tptr)