Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compileStringLitEx: use qiniu/x/stringutil #1779

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.