]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: inline typedcl0 and typedcl1
authorMatthew Dempsky <mdempsky@google.com>
Wed, 1 Feb 2017 20:35:53 +0000 (12:35 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 1 Feb 2017 22:52:32 +0000 (22:52 +0000)
It's easier to understand what's happening after inlining these into
noder.typeDecl.

Change-Id: I7beed5a1e18047bf09f2d4ddf64b9646c324d8d6
Reviewed-on: https://go-review.googlesource.com/36111
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/noder.go
test/notinheap.go

index 6d8e609186b9f22acffaf5ff80670799cca1e782..b6c9bfb1509f4aa2094663f3e5ac2b476c1eed2d 100644 (file)
@@ -5,7 +5,6 @@
 package gc
 
 import (
-       "cmd/compile/internal/syntax"
        "cmd/internal/obj"
        "cmd/internal/src"
        "fmt"
@@ -638,33 +637,6 @@ func funcbody(n *Node) {
        }
 }
 
-// new type being defined with name s.
-func typedcl0(s *Sym) *Node {
-       n := newname(s)
-       n.Op = OTYPE
-       declare(n, dclcontext)
-       return n
-}
-
-// node n, which was returned by typedcl0
-// is being declared to have uncompiled type t.
-// returns the ODCLTYPE node to use.
-func typedcl1(n *Node, t *Node, pragma syntax.Pragma, alias bool) *Node {
-       if pragma != 0 && alias {
-               yyerror("cannot specify directive with type alias")
-               pragma = 0
-       }
-
-       n.Local = true
-
-       p := n.Name.Param
-       p.Ntype = t
-       p.Pragma = pragma
-       p.Alias = alias
-
-       return nod(ODCLTYPE, n, nil)
-}
-
 // structs, functions, and methods.
 // they don't belong here, but where do they belong?
 func checkembeddedtype(t *Type) {
index 14dc1a1d8726796394bac4fbbb23488fdae84c88..912652110cb86ab5e6ebd3a020655d47a2090a0a 100644 (file)
@@ -263,12 +263,25 @@ func (p *noder) constDecl(decl *syntax.ConstDecl, cs *constState) []*Node {
 }
 
 func (p *noder) typeDecl(decl *syntax.TypeDecl) *Node {
-       name := typedcl0(p.name(decl.Name))
+       n := p.declName(decl.Name)
+       n.Op = OTYPE
+       declare(n, dclcontext)
+       n.Local = true
 
        // decl.Type may be nil but in that case we got a syntax error during parsing
        typ := p.typeExprOrNil(decl.Type)
 
-       return typedcl1(name, typ, syntax.Pragma(decl.Pragma), decl.Alias)
+       param := n.Name.Param
+       param.Ntype = typ
+       param.Pragma = decl.Pragma
+       param.Alias = decl.Alias
+       if param.Alias && param.Pragma != 0 {
+               yyerror("cannot specify directive with type alias")
+               param.Pragma = 0
+       }
+
+       return p.nod(decl, ODCLTYPE, n, nil)
+
 }
 
 func (p *noder) declNames(names []*syntax.Name) []*Node {
index c3fdfd6daa338f8360749b4243c41fd4aaee3df9..44b79646ef70ca62093fbffbc3072374e971e488 100644 (file)
@@ -13,15 +13,15 @@ type nih struct{}
 
 // Types embedding notinheap types must be notinheap.
 
-type embed1 struct {
+type embed1 struct { // ERROR "must be go:notinheap"
        x nih
-} // ERROR "must be go:notinheap"
+}
 
 type embed2 [1]nih // ERROR "must be go:notinheap"
 
-type embed3 struct {
+type embed3 struct { // ERROR "must be go:notinheap"
        x [1]nih
-} // ERROR "must be go:notinheap"
+}
 
 type embed4 map[nih]int // ERROR "go:notinheap map key not allowed"