package gc
import (
- "cmd/compile/internal/syntax"
"cmd/internal/obj"
"cmd/internal/src"
"fmt"
}
}
-// 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) {
}
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 {
// 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"