]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add typMap
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 30 Mar 2016 17:52:13 +0000 (10:52 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 30 Mar 2016 21:05:29 +0000 (21:05 +0000)
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>
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/type.go

index 5c54edf12a74dd7e7d159e1847b2de0f04fa4fba..d17368a19a451a75153fc1d3199c2d737d75c22a 100644 (file)
@@ -301,8 +301,8 @@ func dumpexporttype(t *Type) {
                dumpexporttype(t.Results())
                dumpexporttype(t.Params())
        case TMAP:
-               dumpexporttype(t.Type)
-               dumpexporttype(t.Down) // key
+               dumpexporttype(t.Val())
+               dumpexporttype(t.Key())
        case TARRAY, TCHAN, TPTR32, TPTR64:
                dumpexporttype(t.Type)
        }
index 6262910634406cf72cc4d6d02846b73ea926e866..31c5ec876b22e0462ddc7a3cb81a0b1dd363c822 100644 (file)
@@ -382,27 +382,24 @@ func maptype(key *Type, val *Type) *Type {
                                Yyerror("invalid map key type %v", key)
                        }
 
-                       // will be resolved later.
                case TANY:
+                       // will be resolved later.
                        break
 
-                       // map[key] used during definition of key.
-               // postpone check until key is fully defined.
-               // if there are multiple uses of map[key]
-               // before key is fully defined, the error
-               // will only be printed for the first one.
-               // good enough.
                case TFORW:
+                       // map[key] used during definition of key.
+                       // postpone check until key is fully defined.
+                       // if there are multiple uses of map[key]
+                       // before key is fully defined, the error
+                       // will only be printed for the first one.
+                       // good enough.
                        if key.Maplineno == 0 {
                                key.Maplineno = lineno
                        }
                }
        }
 
-       t := typ(TMAP)
-       t.Down = key
-       t.Type = val
-       return t
+       return typMap(key, val)
 }
 
 // methcmp sorts by symbol, then by package path for unexported symbols.
index ca8e2a030b680cc1801653f3693206f3ff12824e..f7bd270e4018206c38e9be702c22602275977600 100644 (file)
@@ -267,6 +267,14 @@ func typeChan(elem *Type, dir uint8) *Type {
        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.
 func typPtr(elem *Type) *Type {
        t := typ(Tptr)