mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: replace calls to typecheck with transform functions
For additions, compares, and slices, create transform functions that do just the transformations for those nodes by the typecheck package (given that the code has been fully typechecked by types2). For nodes that have no args with typeparams, we call these transform functions directly in noder2. But for nodes that have args with typeparams, we have to delay and call the tranform functions during stenciling, since we don't know the specific types involved. We indicate that a node still needs transformation by setting Typecheck to a new value 3. This value means the current type of the node has been set (via types2), but the node may still need transformation. Had to export typcheck.IsCmp and typecheck.Assignop from the typecheck package. Added new tests list2.go (required delaying compare typecheck/transform because of != compare in checkList) and adder.go (requires delaying add typecheck/transform, since it can do addition for numbers or strings). There are several more transformation functions needed for expressions (indexing, calls, etc.) and several more complicated ones needed for statements (mainly various kinds of assignments). Change-Id: I7d89d13a4108308ea0304a4b815ab60b40c59b0a Reviewed-on: https://go-review.googlesource.com/c/go/+/303091 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
b8371d495b
commit
0265b6475f
10 changed files with 785 additions and 24 deletions
|
|
@ -64,7 +64,7 @@ func (g *irgen) expr(expr syntax.Expr) ir.Node {
|
|||
}
|
||||
|
||||
n := g.expr0(typ, expr)
|
||||
if n.Typecheck() != 1 {
|
||||
if n.Typecheck() != 1 && n.Typecheck() != 3 {
|
||||
base.FatalfAt(g.pos(expr), "missed typecheck: %+v", n)
|
||||
}
|
||||
if !g.match(n.Type(), typ, tv.HasOk()) {
|
||||
|
|
@ -161,7 +161,7 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
|
|||
return g.selectorExpr(pos, typ, expr)
|
||||
|
||||
case *syntax.SliceExpr:
|
||||
return Slice(pos, g.expr(expr.X), g.expr(expr.Index[0]), g.expr(expr.Index[1]), g.expr(expr.Index[2]))
|
||||
return Slice(pos, g.typ(typ), g.expr(expr.X), g.expr(expr.Index[0]), g.expr(expr.Index[1]), g.expr(expr.Index[2]))
|
||||
|
||||
case *syntax.Operation:
|
||||
if expr.Y == nil {
|
||||
|
|
@ -171,7 +171,7 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node {
|
|||
case ir.OEQ, ir.ONE, ir.OLT, ir.OLE, ir.OGT, ir.OGE:
|
||||
return Compare(pos, g.typ(typ), op, g.expr(expr.X), g.expr(expr.Y))
|
||||
default:
|
||||
return Binary(pos, op, g.expr(expr.X), g.expr(expr.Y))
|
||||
return Binary(pos, op, g.typ(typ), g.expr(expr.X), g.expr(expr.Y))
|
||||
}
|
||||
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue