Skip to content

Commit

Permalink
compileStringLitEx: use qiniu/x/stringutil (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei authored Feb 25, 2024
1 parent 8e3e9c7 commit 3664c8e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 182 deletions.
3 changes: 2 additions & 1 deletion cl/compile_gop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,13 @@ println "Hi, " + "a${x}b"`, `package main
import (
"fmt"
"github.com/qiniu/x/stringutil"
"strconv"
)
func main() {
x := 1
fmt.Println("Hi, " + ("a" + strconv.Itoa(x) + "b"))
fmt.Println("Hi, " + stringutil.Concat("a", strconv.Itoa(x), "b"))
}
`)
}
Expand Down
26 changes: 17 additions & 9 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ const (
objGopExec = objGopExecOrEnv
)

const errorPkgPath = "github.com/qiniu/x/errors"

func compileIdent(ctx *blockCtx, ident *ast.Ident, flags int) (pkg gox.PkgRef, kind int) {
fvalue := (flags&clIdentSelectorExpr) != 0 || (flags&clIdentLHS) == 0
cb := ctx.cb
Expand Down Expand Up @@ -944,11 +942,19 @@ func basicLit(cb *gox.CodeBuilder, v *ast.BasicLit) {
cb.Val(&goast.BasicLit{Kind: gotoken.Token(v.Kind), Value: v.Value}, v)
}

const (
stringutilPkgPath = "github.com/qiniu/x/stringutil"
)

func compileStringLitEx(ctx *blockCtx, cb *gox.CodeBuilder, lit *ast.BasicLit) {
pos := lit.ValuePos + 1
quote := lit.Value[:1]
notFirst := false
for _, part := range lit.Extra.Parts {
parts := lit.Extra.Parts
n := len(parts)
if n != 1 {
cb.Val(ctx.pkg.Import(stringutilPkgPath).Ref("Concat"))
}
for _, part := range parts {
switch v := part.(type) {
case string: // normal string literal or end with "$$"
next := pos + token.Pos(len(v))
Expand All @@ -971,11 +977,9 @@ func compileStringLitEx(ctx *blockCtx, cb *gox.CodeBuilder, lit *ast.BasicLit) {
default:
panic("compileStringLitEx TODO: unexpected part")
}
if notFirst {
cb.BinaryOp(gotoken.ADD)
} else {
notFirst = true
}
}
if n != 1 {
cb.CallWith(n, 0, lit)
}
}

Expand Down Expand Up @@ -1328,6 +1332,10 @@ func compileComprehensionExpr(ctx *blockCtx, v *ast.ComprehensionExpr, twoValue
cb.Return(0).End().Call(0)
}

const (
errorPkgPath = "github.com/qiniu/x/errors"
)

var (
tyError = types.Universe.Lookup("error").Type()
)
Expand Down
48 changes: 0 additions & 48 deletions strx/build.go

This file was deleted.

30 changes: 0 additions & 30 deletions strx/concat.go

This file was deleted.

34 changes: 0 additions & 34 deletions strx/string_go121.go

This file was deleted.

24 changes: 0 additions & 24 deletions strx/string_mock.go

This file was deleted.

36 changes: 0 additions & 36 deletions strx/string_test.go

This file was deleted.

0 comments on commit 3664c8e

Please sign in to comment.