mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typealias] cmd/compile: various minor cleanups
Also: Don't allow type pragmas with type alias declarations. For #18130. Change-Id: Ie54ea5fefcd677ad87ced03466bbfd783771e974 Reviewed-on: https://go-review.googlesource.com/35102 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
f011e0c6c3
commit
ac8421f9a5
2 changed files with 28 additions and 23 deletions
|
|
@ -344,8 +344,9 @@ func Main() {
|
||||||
// Don't use range--typecheck can add closures to xtop.
|
// Don't use range--typecheck can add closures to xtop.
|
||||||
timings.Start("fe", "typecheck", "top1")
|
timings.Start("fe", "typecheck", "top1")
|
||||||
for i := 0; i < len(xtop); i++ {
|
for i := 0; i < len(xtop); i++ {
|
||||||
if xtop[i].Op != ODCL && xtop[i].Op != OAS && xtop[i].Op != OAS2 {
|
n := xtop[i]
|
||||||
xtop[i] = typecheck(xtop[i], Etop)
|
if op := n.Op; op != ODCL && op != OAS && op != OAS2 {
|
||||||
|
xtop[i] = typecheck(n, Etop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -355,8 +356,9 @@ func Main() {
|
||||||
// Don't use range--typecheck can add closures to xtop.
|
// Don't use range--typecheck can add closures to xtop.
|
||||||
timings.Start("fe", "typecheck", "top2")
|
timings.Start("fe", "typecheck", "top2")
|
||||||
for i := 0; i < len(xtop); i++ {
|
for i := 0; i < len(xtop); i++ {
|
||||||
if xtop[i].Op == ODCL || xtop[i].Op == OAS || xtop[i].Op == OAS2 {
|
n := xtop[i]
|
||||||
xtop[i] = typecheck(xtop[i], Etop)
|
if op := n.Op; op == ODCL || op == OAS || op == OAS2 {
|
||||||
|
xtop[i] = typecheck(n, Etop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resumecheckwidth()
|
resumecheckwidth()
|
||||||
|
|
@ -366,8 +368,9 @@ func Main() {
|
||||||
timings.Start("fe", "typecheck", "func")
|
timings.Start("fe", "typecheck", "func")
|
||||||
var fcount int64
|
var fcount int64
|
||||||
for i := 0; i < len(xtop); i++ {
|
for i := 0; i < len(xtop); i++ {
|
||||||
if xtop[i].Op == ODCLFUNC || xtop[i].Op == OCLOSURE {
|
n := xtop[i]
|
||||||
Curfn = xtop[i]
|
if op := n.Op; op == ODCLFUNC || op == OCLOSURE {
|
||||||
|
Curfn = n
|
||||||
decldepth = 1
|
decldepth = 1
|
||||||
saveerrors()
|
saveerrors()
|
||||||
typecheckslice(Curfn.Nbody.Slice(), Etop)
|
typecheckslice(Curfn.Nbody.Slice(), Etop)
|
||||||
|
|
@ -459,8 +462,9 @@ func Main() {
|
||||||
timings.Start("be", "compilefuncs")
|
timings.Start("be", "compilefuncs")
|
||||||
fcount = 0
|
fcount = 0
|
||||||
for i := 0; i < len(xtop); i++ {
|
for i := 0; i < len(xtop); i++ {
|
||||||
if xtop[i].Op == ODCLFUNC {
|
n := xtop[i]
|
||||||
funccompile(xtop[i])
|
if n.Op == ODCLFUNC {
|
||||||
|
funccompile(n)
|
||||||
fcount++
|
fcount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,11 +153,7 @@ func (p *noder) importDecl(imp *syntax.ImportDecl) {
|
||||||
|
|
||||||
func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
|
func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
|
||||||
names := p.declNames(decl.NameList)
|
names := p.declNames(decl.NameList)
|
||||||
|
typ := p.typeExprOrNil(decl.Type)
|
||||||
var typ *Node
|
|
||||||
if decl.Type != nil {
|
|
||||||
typ = p.typeExpr(decl.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
var exprs []*Node
|
var exprs []*Node
|
||||||
if decl.Values != nil {
|
if decl.Values != nil {
|
||||||
|
|
@ -170,11 +166,7 @@ func (p *noder) varDecl(decl *syntax.VarDecl) []*Node {
|
||||||
|
|
||||||
func (p *noder) constDecl(decl *syntax.ConstDecl) []*Node {
|
func (p *noder) constDecl(decl *syntax.ConstDecl) []*Node {
|
||||||
names := p.declNames(decl.NameList)
|
names := p.declNames(decl.NameList)
|
||||||
|
typ := p.typeExprOrNil(decl.Type)
|
||||||
var typ *Node
|
|
||||||
if decl.Type != nil {
|
|
||||||
typ = p.typeExpr(decl.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
var exprs []*Node
|
var exprs []*Node
|
||||||
if decl.Values != nil {
|
if decl.Values != nil {
|
||||||
|
|
@ -190,12 +182,14 @@ func (p *noder) typeDecl(decl *syntax.TypeDecl) *Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
name := typedcl0(p.name(decl.Name))
|
name := typedcl0(p.name(decl.Name))
|
||||||
name.Name.Param.Pragma = Pragma(decl.Pragma)
|
pragma := Pragma(decl.Pragma)
|
||||||
|
if pragma != 0 && decl.Alias {
|
||||||
var typ *Node
|
yyerror("cannot specify directive with type alias")
|
||||||
if decl.Type != nil {
|
pragma = 0
|
||||||
typ = p.typeExpr(decl.Type)
|
|
||||||
}
|
}
|
||||||
|
name.Name.Param.Pragma = pragma
|
||||||
|
|
||||||
|
typ := p.typeExprOrNil(decl.Type)
|
||||||
|
|
||||||
return typedcl1(name, typ, true)
|
return typedcl1(name, typ, true)
|
||||||
}
|
}
|
||||||
|
|
@ -470,6 +464,13 @@ func (p *noder) typeExpr(typ syntax.Expr) *Node {
|
||||||
return p.expr(typ)
|
return p.expr(typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *noder) typeExprOrNil(typ syntax.Expr) *Node {
|
||||||
|
if typ != nil {
|
||||||
|
return p.expr(typ)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *noder) chanDir(dir syntax.ChanDir) ChanDir {
|
func (p *noder) chanDir(dir syntax.ChanDir) ChanDir {
|
||||||
switch dir {
|
switch dir {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue