mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
compiler: process index expresstions in a generic way
All type errors such as string index in slice will be catched during parse phase.
This commit is contained in:
parent
aeaa4a8210
commit
87f6ba34db
1 changed files with 4 additions and 26 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"go/types"
|
||||
"math"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
|
@ -446,23 +445,9 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
ast.Walk(c, n.Rhs[i])
|
||||
name := t.X.(*ast.Ident).Name
|
||||
c.emitLoadVar(name)
|
||||
switch ind := t.Index.(type) {
|
||||
case *ast.BasicLit:
|
||||
indexStr := ind.Value
|
||||
index, err := strconv.Atoi(indexStr)
|
||||
if err != nil {
|
||||
c.prog.Err = fmt.Errorf("failed to convert slice index to integer")
|
||||
return nil
|
||||
}
|
||||
c.emitStoreStructField(index)
|
||||
case *ast.Ident:
|
||||
c.emitLoadVar(ind.Name)
|
||||
ast.Walk(c, t.Index)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.ROT)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.SETITEM)
|
||||
default:
|
||||
c.prog.Err = fmt.Errorf("unsupported index expression")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -832,14 +817,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
// Walk the expression, this could be either an Ident or SelectorExpr.
|
||||
// This will load local whatever X is.
|
||||
ast.Walk(c, n.X)
|
||||
|
||||
switch n.Index.(type) {
|
||||
case *ast.BasicLit:
|
||||
c.emitLoadConst(c.typeAndValueOf(n.Index))
|
||||
default:
|
||||
ast.Walk(c, n.Index)
|
||||
}
|
||||
|
||||
emit.Opcode(c.prog.BinWriter, opcode.PICKITEM) // just pickitem here
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue