diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-10-04 16:20:57 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-10-07 18:02:14 +0000 |
commit | 019ad98b5337992625327ea07185ad06a9c19169 (patch) | |
tree | e33c8aa56383fead237747bf5f86ec805856d3a8 /src/cmd/cgo | |
parent | be571a36c7aa7198aef4712f8c6cde633e2f380b (diff) | |
download | go-019ad98b5337992625327ea07185ad06a9c19169.tar.gz go-019ad98b5337992625327ea07185ad06a9c19169.zip |
cmd/cgo: update to handle ast.IndexListExpr
Allows cgo to work with generics.
Updates #47781.
Change-Id: Id1a5d1a0a8193c5b157e3e671b1490d687d10384
Reviewed-on: https://go-review.googlesource.com/c/go/+/353882
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/cgo')
-rw-r--r-- | src/cmd/cgo/ast.go | 3 | ||||
-rw-r--r-- | src/cmd/cgo/ast_go1.go | 17 | ||||
-rw-r--r-- | src/cmd/cgo/ast_go118.go | 25 | ||||
-rw-r--r-- | src/cmd/cgo/gcc.go | 2 |
4 files changed, 44 insertions, 3 deletions
diff --git a/src/cmd/cgo/ast.go b/src/cmd/cgo/ast.go index a073407a96..28879e349c 100644 --- a/src/cmd/cgo/ast.go +++ b/src/cmd/cgo/ast.go @@ -338,8 +338,7 @@ func (f *File) walk(x interface{}, context astContext, visit func(*File, interfa // everything else just recurs default: - error_(token.NoPos, "unexpected type %T in walk", x) - panic("unexpected type") + f.walkUnexpected(x, context, visit) case nil: diff --git a/src/cmd/cgo/ast_go1.go b/src/cmd/cgo/ast_go1.go new file mode 100644 index 0000000000..cf6d99f64a --- /dev/null +++ b/src/cmd/cgo/ast_go1.go @@ -0,0 +1,17 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build !go1.18 +// +build !go1.18 + +package main + +import ( + "go/token" +) + +func (f *File) walkUnexpected(x interface{}, context astContext, visit func(*File, interface{}, astContext)) { + error_(token.NoPos, "unexpected type %T in walk", x) + panic("unexpected type") +} diff --git a/src/cmd/cgo/ast_go118.go b/src/cmd/cgo/ast_go118.go new file mode 100644 index 0000000000..2e3ce27521 --- /dev/null +++ b/src/cmd/cgo/ast_go118.go @@ -0,0 +1,25 @@ +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build go1.18 +// +build go1.18 + +package main + +import ( + "go/ast" + "go/token" +) + +func (f *File) walkUnexpected(x interface{}, context astContext, visit func(*File, interface{}, astContext)) { + switch n := x.(type) { + default: + error_(token.NoPos, "unexpected type %T in walk", x) + panic("unexpected type") + + case *ast.IndexListExpr: + f.walk(&n.X, ctxExpr, visit) + f.walk(n.Indices, ctxExpr, visit) + } +} diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index f5682c0997..c78197896c 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -1506,7 +1506,7 @@ func (p *Package) rewriteName(f *File, r *Ref, addPosition bool) ast.Expr { Args: []ast.Expr{getNewIdent(name.Mangle)}, } case "type": - // Okay - might be new(T) + // Okay - might be new(T), T(x), Generic[T], etc. if r.Name.Type == nil { error_(r.Pos(), "expression C.%s: undefined C type '%s'", fixGo(r.Name.Go), r.Name.C) } |