all: unnecessary use of fmt.Sprintf (#2691)

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
This commit is contained in:
guangwu 2023-07-05 15:36:29 +08:00 committed by GitHub
parent c908685e55
commit 54e1263565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 31 deletions

View File

@ -464,7 +464,7 @@ type disposeShaderCommand struct {
} }
func (c *disposeShaderCommand) String() string { func (c *disposeShaderCommand) String() string {
return fmt.Sprintf("dispose-shader: target") return "dispose-shader: target"
} }
// Exec executes the disposeShaderCommand. // Exec executes the disposeShaderCommand.
@ -503,7 +503,7 @@ type newShaderCommand struct {
} }
func (c *newShaderCommand) String() string { func (c *newShaderCommand) String() string {
return fmt.Sprintf("new-shader") return "new-shader"
} }
// Exec executes a newShaderCommand. // Exec executes a newShaderCommand.

View File

@ -870,7 +870,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
// In the context where a local variable is marked as used, any expressions must have its // In the context where a local variable is marked as used, any expressions must have its
// meaning. Then, a blank identifier is not available there. // meaning. Then, a blank identifier is not available there.
if markLocalVariableUsed { if markLocalVariableUsed {
cs.addError(e.Pos(), fmt.Sprintf("cannot use _ as value")) cs.addError(e.Pos(), "cannot use _ as value")
return nil, nil, nil, false return nil, nil, nil, false
} }
return []shaderir.Expr{ return []shaderir.Expr{
@ -1068,7 +1068,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
return nil, nil, nil, false return nil, nil, nil, false
} }
if len(exprs) != 1 { if len(exprs) != 1 {
cs.addError(e.Pos(), fmt.Sprintf("multiple-value context is not available at a composite literal")) cs.addError(e.Pos(), "multiple-value context is not available at a composite literal")
return nil, nil, nil, false return nil, nil, nil, false
} }
stmts = append(stmts, ss...) stmts = append(stmts, ss...)
@ -1112,7 +1112,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
stmts = append(stmts, ss...) stmts = append(stmts, ss...)
if len(exprs) != 1 { if len(exprs) != 1 {
cs.addError(e.Pos(), fmt.Sprintf("multiple-value context is not available at an index expression")) cs.addError(e.Pos(), "multiple-value context is not available at an index expression")
return nil, nil, nil, false return nil, nil, nil, false
} }
idx := exprs[0] idx := exprs[0]
@ -1130,7 +1130,7 @@ func (cs *compileState) parseExpr(block *block, fname string, expr ast.Expr, mar
} }
stmts = append(stmts, ss...) stmts = append(stmts, ss...)
if len(exprs) != 1 { if len(exprs) != 1 {
cs.addError(e.Pos(), fmt.Sprintf("multiple-value context is not available at an index expression")) cs.addError(e.Pos(), "multiple-value context is not available at an index expression")
return nil, nil, nil, false return nil, nil, nil, false
} }
x := exprs[0] x := exprs[0]

View File

@ -497,7 +497,7 @@ func (cs *compileState) functionReturnTypes(block *block, expr ast.Expr) ([]shad
func (s *compileState) parseVariable(block *block, fname string, vs *ast.ValueSpec) ([]variable, []shaderir.Expr, []shaderir.Stmt, bool) { func (s *compileState) parseVariable(block *block, fname string, vs *ast.ValueSpec) ([]variable, []shaderir.Expr, []shaderir.Stmt, bool) {
if len(vs.Names) != len(vs.Values) && len(vs.Values) != 1 && len(vs.Values) != 0 { if len(vs.Names) != len(vs.Values) && len(vs.Values) != 1 && len(vs.Values) != 0 {
s.addError(vs.Pos(), fmt.Sprintf("the numbers of lhs and rhs don't match")) s.addError(vs.Pos(), "the numbers of lhs and rhs don't match")
return nil, nil, nil, false return nil, nil, nil, false
} }
@ -542,7 +542,7 @@ func (s *compileState) parseVariable(block *block, fname string, vs *ast.ValueSp
ts = rts ts = rts
} }
if len(ts) > 1 { if len(ts) > 1 {
s.addError(vs.Pos(), fmt.Sprintf("the numbers of lhs and rhs don't match")) s.addError(vs.Pos(), "the numbers of lhs and rhs don't match")
} }
t = ts[0] t = ts[0]
} }
@ -585,7 +585,7 @@ func (s *compileState) parseVariable(block *block, fname string, vs *ast.ValueSp
inittypes = ts inittypes = ts
} }
if len(ts) != len(vs.Names) { if len(ts) != len(vs.Names) {
s.addError(vs.Pos(), fmt.Sprintf("the numbers of lhs and rhs don't match")) s.addError(vs.Pos(), "the numbers of lhs and rhs don't match")
continue continue
} }
} }
@ -760,12 +760,12 @@ func (cs *compileState) parseFunc(block *block, d *ast.FuncDecl) (function, bool
checkVaryings := func(vs []variable) { checkVaryings := func(vs []variable) {
if len(cs.ir.Varyings) != len(vs) { if len(cs.ir.Varyings) != len(vs) {
cs.addError(d.Pos(), fmt.Sprintf("the number of vertex entry point's returning values and the number of fragment entry point's params must be the same")) cs.addError(d.Pos(), "the number of vertex entry point's returning values and the number of fragment entry point's params must be the same")
return return
} }
for i, t := range cs.ir.Varyings { for i, t := range cs.ir.Varyings {
if t.Main != vs[i].typ.Main { if t.Main != vs[i].typ.Main {
cs.addError(d.Pos(), fmt.Sprintf("vertex entry point's returning value types and fragment entry point's param types must match")) cs.addError(d.Pos(), "vertex entry point's returning value types and fragment entry point's param types must match")
} }
} }
} }
@ -789,7 +789,7 @@ func (cs *compileState) parseFunc(block *block, d *ast.FuncDecl) (function, bool
// The first out-param is treated as gl_Position in GLSL. // The first out-param is treated as gl_Position in GLSL.
if outParams[0].typ.Main != shaderir.Vec4 { if outParams[0].typ.Main != shaderir.Vec4 {
cs.addError(d.Pos(), fmt.Sprintf("vertex entry point must have at least one returning vec4 value for a position")) cs.addError(d.Pos(), "vertex entry point must have at least one returning vec4 value for a position")
return function{}, false return function{}, false
} }
@ -804,16 +804,16 @@ func (cs *compileState) parseFunc(block *block, d *ast.FuncDecl) (function, bool
cs.varyingParsed = true cs.varyingParsed = true
case cs.fragmentEntry: case cs.fragmentEntry:
if len(inParams) == 0 { if len(inParams) == 0 {
cs.addError(d.Pos(), fmt.Sprintf("fragment entry point must have at least one vec4 parameter for a position")) cs.addError(d.Pos(), "fragment entry point must have at least one vec4 parameter for a position")
return function{}, false return function{}, false
} }
if inParams[0].typ.Main != shaderir.Vec4 { if inParams[0].typ.Main != shaderir.Vec4 {
cs.addError(d.Pos(), fmt.Sprintf("fragment entry point must have at least one vec4 parameter for a position")) cs.addError(d.Pos(), "fragment entry point must have at least one vec4 parameter for a position")
return function{}, false return function{}, false
} }
if len(outParams) != 0 || returnType.Main != shaderir.Vec4 { if len(outParams) != 0 || returnType.Main != shaderir.Vec4 {
cs.addError(d.Pos(), fmt.Sprintf("fragment entry point must have one returning vec4 value for a color")) cs.addError(d.Pos(), "fragment entry point must have one returning vec4 value for a color")
return function{}, false return function{}, false
} }

View File

@ -42,7 +42,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
switch stmt.Tok { switch stmt.Tok {
case token.DEFINE: case token.DEFINE:
if len(stmt.Lhs) != len(stmt.Rhs) && len(stmt.Rhs) != 1 { if len(stmt.Lhs) != len(stmt.Rhs) && len(stmt.Rhs) != 1 {
cs.addError(stmt.Pos(), fmt.Sprintf("single-value context and multiple-value context cannot be mixed")) cs.addError(stmt.Pos(), "single-value context and multiple-value context cannot be mixed")
return nil, false return nil, false
} }
@ -53,7 +53,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
stmts = append(stmts, ss...) stmts = append(stmts, ss...)
case token.ASSIGN: case token.ASSIGN:
if len(stmt.Lhs) != len(stmt.Rhs) && len(stmt.Rhs) != 1 { if len(stmt.Lhs) != len(stmt.Rhs) && len(stmt.Rhs) != 1 {
cs.addError(stmt.Pos(), fmt.Sprintf("single-value context and multiple-value context cannot be mixed")) cs.addError(stmt.Pos(), "single-value context and multiple-value context cannot be mixed")
return nil, false return nil, false
} }
ss, ok := cs.assign(block, fname, stmt.Pos(), stmt.Lhs, stmt.Rhs, inParams, false) ss, ok := cs.assign(block, fname, stmt.Pos(), stmt.Lhs, stmt.Rhs, inParams, false)
@ -75,7 +75,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
stmts = append(stmts, ss...) stmts = append(stmts, ss...)
if lhs[0].Type == shaderir.UniformVariable { if lhs[0].Type == shaderir.UniformVariable {
cs.addError(stmt.Pos(), fmt.Sprintf("a uniform variable cannot be assigned")) cs.addError(stmt.Pos(), "a uniform variable cannot be assigned")
return nil, false return nil, false
} }
@ -559,7 +559,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
case *ast.ExprStmt: case *ast.ExprStmt:
if _, ok := stmt.X.(*ast.CallExpr); !ok { if _, ok := stmt.X.(*ast.CallExpr); !ok {
cs.addError(stmt.Pos(), fmt.Sprintf("the statement is evaluated but not used")) cs.addError(stmt.Pos(), "the statement is evaluated but not used")
return nil, false return nil, false
} }
@ -576,7 +576,7 @@ func (cs *compileState) parseStmt(block *block, fname string, stmt ast.Stmt, inP
continue continue
} }
if expr.Exprs[0].Type == shaderir.BuiltinFuncExpr { if expr.Exprs[0].Type == shaderir.BuiltinFuncExpr {
cs.addError(stmt.Pos(), fmt.Sprintf("the statement is evaluated but not used")) cs.addError(stmt.Pos(), "the statement is evaluated but not used")
return nil, false return nil, false
} }
stmts = append(stmts, shaderir.Stmt{ stmts = append(stmts, shaderir.Stmt{
@ -622,7 +622,7 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
ts = rts ts = rts
} }
if len(ts) > 1 { if len(ts) > 1 {
cs.addError(pos, fmt.Sprintf("single-value context and multiple-value context cannot be mixed")) cs.addError(pos, "single-value context and multiple-value context cannot be mixed")
return nil, false return nil, false
} }
@ -634,7 +634,7 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
} }
if len(r) > 1 { if len(r) > 1 {
cs.addError(pos, fmt.Sprintf("single-value context and multiple-value context cannot be mixed")) cs.addError(pos, "single-value context and multiple-value context cannot be mixed")
return nil, false return nil, false
} }
@ -646,7 +646,7 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
if len(l) != len(r) { if len(l) != len(r) {
if len(r) == 0 { if len(r) == 0 {
cs.addError(pos, fmt.Sprintf("right-hand side (no value) used as value")) cs.addError(pos, "right-hand side (no value) used as value")
} else { } else {
cs.addError(pos, fmt.Sprintf("assignment mismatch: %d variables but the right-hand side has %d values", len(l), len(r))) cs.addError(pos, fmt.Sprintf("assignment mismatch: %d variables but the right-hand side has %d values", len(l), len(r)))
} }
@ -675,7 +675,7 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
} }
if isAssignmentForbidden(&l[0]) { if isAssignmentForbidden(&l[0]) {
cs.addError(pos, fmt.Sprintf("a uniform variable cannot be assigned")) cs.addError(pos, "a uniform variable cannot be assigned")
return nil, false return nil, false
} }
allblank = false allblank = false
@ -747,7 +747,7 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
return nil, false return nil, false
} }
if len(rhsExprs) != len(lhs) { if len(rhsExprs) != len(lhs) {
cs.addError(pos, fmt.Sprintf("single-value context and multiple-value context cannot be mixed")) cs.addError(pos, "single-value context and multiple-value context cannot be mixed")
} }
stmts = append(stmts, ss...) stmts = append(stmts, ss...)
} }
@ -797,7 +797,7 @@ func (cs *compileState) assign(block *block, fname string, pos token.Pos, lhs, r
} }
if define && allblank { if define && allblank {
cs.addError(pos, fmt.Sprintf("no new variables on left side of :=")) cs.addError(pos, "no new variables on left side of :=")
return nil, false return nil, false
} }

View File

@ -57,7 +57,7 @@ func (cs *compileState) parseType(block *block, fname string, expr ast.Expr) (sh
} }
case *ast.ArrayType: case *ast.ArrayType:
if t.Len == nil { if t.Len == nil {
cs.addError(t.Pos(), fmt.Sprintf("array length must be specified")) cs.addError(t.Pos(), "array length must be specified")
return shaderir.Type{}, false return shaderir.Type{}, false
} }
var length int var length int
@ -69,16 +69,16 @@ func (cs *compileState) parseType(block *block, fname string, expr ast.Expr) (sh
return shaderir.Type{}, false return shaderir.Type{}, false
} }
if len(exprs) != 1 { if len(exprs) != 1 {
cs.addError(t.Pos(), fmt.Sprintf("invalid length of array")) cs.addError(t.Pos(), "invalid length of array")
return shaderir.Type{}, false return shaderir.Type{}, false
} }
if exprs[0].Type != shaderir.NumberExpr { if exprs[0].Type != shaderir.NumberExpr {
cs.addError(t.Pos(), fmt.Sprintf("length of array must be a constant number")) cs.addError(t.Pos(), "length of array must be a constant number")
return shaderir.Type{}, false return shaderir.Type{}, false
} }
l, ok := gconstant.Int64Val(exprs[0].Const) l, ok := gconstant.Int64Val(exprs[0].Const)
if !ok { if !ok {
cs.addError(t.Pos(), fmt.Sprintf("length of array must be an integer")) cs.addError(t.Pos(), "length of array must be an integer")
return shaderir.Type{}, false return shaderir.Type{}, false
} }
length = int(l) length = int(l)
@ -89,7 +89,7 @@ func (cs *compileState) parseType(block *block, fname string, expr ast.Expr) (sh
return shaderir.Type{}, false return shaderir.Type{}, false
} }
if elm.Main == shaderir.Array { if elm.Main == shaderir.Array {
cs.addError(t.Pos(), fmt.Sprintf("array of array is forbidden")) cs.addError(t.Pos(), "array of array is forbidden")
return shaderir.Type{}, false return shaderir.Type{}, false
} }
return shaderir.Type{ return shaderir.Type{