aboutsummaryrefslogtreecommitdiffhomepage
path: root/cgo
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-09-22 21:51:19 +0200
committerRon Evans <[email protected]>2021-09-27 15:47:12 +0200
commit49dd2ce3933e9460c3dc04797b5f30134f48dd39 (patch)
treed0bda5814b1c0e28d9923ff65cbed3b38953f6fb /cgo
parent7df8e8db42c30be37c2b763b1ebc63dbfa751119 (diff)
downloadtinygo-49dd2ce3933e9460c3dc04797b5f30134f48dd39.tar.gz
tinygo-49dd2ce3933e9460c3dc04797b5f30134f48dd39.zip
all: fix staticcheck warnings
This is a loose collection of small fixes flagged by staticcheck: - dead code - regexp expressions not using backticks (`foobar` / "foobar") - redundant types of slice and map initializers - misc other fixes Not all of these seem very useful to me, but in particular dead code is nice to fix. I've fixed them all just so that if there are problems, they aren't hidden in the noise of less useful issues.
Diffstat (limited to 'cgo')
-rw-r--r--cgo/cgo.go58
-rw-r--r--cgo/cgo_test.go2
-rw-r--r--cgo/libclang.go12
3 files changed, 38 insertions, 34 deletions
diff --git a/cgo/cgo.go b/cgo/cgo.go
index 8581807fa..2718062d0 100644
--- a/cgo/cgo.go
+++ b/cgo/cgo.go
@@ -124,17 +124,17 @@ var cgoAliases = map[string]string{
// builtinAliases are handled specially because they only exist on the Go side
// of CGo, not on the CGo side (they're prefixed with "_Cgo_" there).
var builtinAliases = map[string]struct{}{
- "char": struct{}{},
- "schar": struct{}{},
- "uchar": struct{}{},
- "short": struct{}{},
- "ushort": struct{}{},
- "int": struct{}{},
- "uint": struct{}{},
- "long": struct{}{},
- "ulong": struct{}{},
- "longlong": struct{}{},
- "ulonglong": struct{}{},
+ "char": {},
+ "schar": {},
+ "uchar": {},
+ "short": {},
+ "ushort": {},
+ "int": {},
+ "uint": {},
+ "long": {},
+ "ulong": {},
+ "longlong": {},
+ "ulonglong": {},
}
// cgoTypes lists some C types with ambiguous sizes that must be retrieved
@@ -224,7 +224,7 @@ func Process(files []*ast.File, dir string, fset *token.FileSet, cflags []string
Specs: []ast.Spec{
&ast.ValueSpec{
Names: []*ast.Ident{
- &ast.Ident{
+ {
Name: "_",
Obj: &ast.Object{
Kind: ast.Var,
@@ -494,7 +494,7 @@ func (p *cgoPackage) addFuncDecls() {
if fn.variadic {
decl.Doc = &ast.CommentGroup{
List: []*ast.Comment{
- &ast.Comment{
+ {
Slash: fn.pos,
Text: "//go:variadic",
},
@@ -505,7 +505,7 @@ func (p *cgoPackage) addFuncDecls() {
for i, arg := range fn.args {
args[i] = &ast.Field{
Names: []*ast.Ident{
- &ast.Ident{
+ {
NamePos: fn.pos,
Name: arg.name,
Obj: &ast.Object{
@@ -553,7 +553,7 @@ func (p *cgoPackage) addFuncPtrDecls() {
Name: "C." + name + "$funcaddr",
}
valueSpec := &ast.ValueSpec{
- Names: []*ast.Ident{&ast.Ident{
+ Names: []*ast.Ident{{
NamePos: fn.pos,
Name: "C." + name + "$funcaddr",
Obj: obj,
@@ -603,7 +603,7 @@ func (p *cgoPackage) addConstDecls() {
Name: "C." + name,
}
valueSpec := &ast.ValueSpec{
- Names: []*ast.Ident{&ast.Ident{
+ Names: []*ast.Ident{{
NamePos: constVal.pos,
Name: "C." + name,
Obj: obj,
@@ -644,7 +644,7 @@ func (p *cgoPackage) addVarDecls() {
Name: "C." + name,
}
valueSpec := &ast.ValueSpec{
- Names: []*ast.Ident{&ast.Ident{
+ Names: []*ast.Ident{{
NamePos: global.pos,
Name: "C." + name,
Obj: obj,
@@ -845,9 +845,9 @@ func (p *cgoPackage) makeUnionField(typ *elaboratedTypeInfo) *ast.StructType {
Struct: typ.typeExpr.Struct,
Fields: &ast.FieldList{
Opening: typ.typeExpr.Fields.Opening,
- List: []*ast.Field{&ast.Field{
+ List: []*ast.Field{{
Names: []*ast.Ident{
- &ast.Ident{
+ {
NamePos: typ.typeExpr.Fields.Opening,
Name: "$union",
},
@@ -928,9 +928,9 @@ func (p *cgoPackage) createUnionAccessor(field *ast.Field, typeName string) {
Recv: &ast.FieldList{
Opening: pos,
List: []*ast.Field{
- &ast.Field{
+ {
Names: []*ast.Ident{
- &ast.Ident{
+ {
NamePos: pos,
Name: "union",
},
@@ -959,7 +959,7 @@ func (p *cgoPackage) createUnionAccessor(field *ast.Field, typeName string) {
},
Results: &ast.FieldList{
List: []*ast.Field{
- &ast.Field{
+ {
Type: &ast.StarExpr{
Star: pos,
X: field.Type,
@@ -1038,9 +1038,9 @@ func (p *cgoPackage) createBitfieldGetter(bitfield bitfieldInfo, typeName string
Recv: &ast.FieldList{
Opening: bitfield.pos,
List: []*ast.Field{
- &ast.Field{
+ {
Names: []*ast.Ident{
- &ast.Ident{
+ {
NamePos: bitfield.pos,
Name: "s",
Obj: &ast.Object{
@@ -1074,7 +1074,7 @@ func (p *cgoPackage) createBitfieldGetter(bitfield bitfieldInfo, typeName string
},
Results: &ast.FieldList{
List: []*ast.Field{
- &ast.Field{
+ {
Type: bitfield.field.Type,
},
},
@@ -1191,9 +1191,9 @@ func (p *cgoPackage) createBitfieldSetter(bitfield bitfieldInfo, typeName string
Recv: &ast.FieldList{
Opening: bitfield.pos,
List: []*ast.Field{
- &ast.Field{
+ {
Names: []*ast.Ident{
- &ast.Ident{
+ {
NamePos: bitfield.pos,
Name: "s",
Obj: &ast.Object{
@@ -1224,9 +1224,9 @@ func (p *cgoPackage) createBitfieldSetter(bitfield bitfieldInfo, typeName string
Params: &ast.FieldList{
Opening: bitfield.pos,
List: []*ast.Field{
- &ast.Field{
+ {
Names: []*ast.Ident{
- &ast.Ident{
+ {
NamePos: bitfield.pos,
Name: "value",
Obj: nil,
diff --git a/cgo/cgo_test.go b/cgo/cgo_test.go
index b18650606..6d5d55045 100644
--- a/cgo/cgo_test.go
+++ b/cgo/cgo_test.go
@@ -96,7 +96,7 @@ func TestCGo(t *testing.T) {
if err != nil {
t.Errorf("could not write out CGo AST: %v", err)
}
- actual := normalizeResult(string(buf.Bytes()))
+ actual := normalizeResult(buf.String())
// Read the file with the expected output, to compare against.
outfile := filepath.Join("testdata", name+".out.go")
diff --git a/cgo/libclang.go b/cgo/libclang.go
index 8e9af8a08..22ce68cdd 100644
--- a/cgo/libclang.go
+++ b/cgo/libclang.go
@@ -203,7 +203,7 @@ func tinygo_clang_globals_visitor(c, parent C.GoCXCursor, client_data C.CXClient
if resultType.kind != C.CXType_Void {
fn.results = &ast.FieldList{
List: []*ast.Field{
- &ast.Field{
+ {
Type: p.makeASTType(resultType, pos),
},
},
@@ -775,7 +775,7 @@ func tinygo_clang_struct_visitor(c, parent C.GoCXCursor, client_data C.CXClientD
}
*inBitfield = false
field.Names = []*ast.Ident{
- &ast.Ident{
+ {
NamePos: pos,
Name: name,
Obj: &ast.Object{
@@ -796,8 +796,12 @@ func tinygo_clang_enum_visitor(c, parent C.GoCXCursor, client_data C.CXClientDat
pos := p.getCursorPosition(c)
value := C.tinygo_clang_getEnumConstantDeclValue(c)
p.constants[name] = constantInfo{
- expr: &ast.BasicLit{pos, token.INT, strconv.FormatInt(int64(value), 10)},
- pos: pos,
+ expr: &ast.BasicLit{
+ ValuePos: pos,
+ Kind: token.INT,
+ Value: strconv.FormatInt(int64(value), 10),
+ },
+ pos: pos,
}
return C.CXChildVisit_Continue
}