| 1 | // Copyright 2013 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Except for this comment, this file is a verbatim copy of the file |
| 6 | // with the same name in $GOROOT/src/go/internal/gccgoimporter. |
| 7 | |
| 8 | package gccgoimporterscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/ |
| 9 | |
| 10 | import ( |
| 11 | "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/" |
| 12 | "go/typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/" |
| 13 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 14 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 15 | "text/scannerscip-go gomod github.com/golang/go/src go1.25.0 `text/scanner`/" |
| 16 | ) |
| 17 | |
| 18 | var typeParserTestsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests. = []struct { |
| 19 | idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id., typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ., wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want., underlyingscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:underlying., methodsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:methods. string |
| 20 | }{ |
| 21 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type -1>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "int8"}, |
| 22 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 *<type -19>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "*error"}, |
| 23 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 *any>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "unsafe.Pointer"}, |
| 24 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 \"Bar\" <type 2 *<type 1>>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "foo.Bar", underlyingscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:underlying.: "*foo.Bar"}, |
| 25 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 \"bar.Foo\" \"bar\" <type -1>\nfunc (? <type 1>) M ();\n>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "bar.Foo", underlyingscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:underlying.: "int8", methodsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:methods.: "func (bar.Foo).M()"}, |
| 26 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 \".bar.foo\" \"bar\" <type -1>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "bar.foo", underlyingscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:underlying.: "int8"}, |
| 27 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 []<type -1>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "[]int8"}, |
| 28 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 [42]<type -1>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "[42]int8"}, |
| 29 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 map [<type -1>] <type -2>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "map[int8]int16"}, |
| 30 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 chan <type -1>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "chan int8"}, |
| 31 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 chan <- <type -1>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "<-chan int8"}, |
| 32 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 chan -< <type -1>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "chan<- int8"}, |
| 33 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 struct { I8 <type -1>; I16 <type -2> \"i16\"; }>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "struct{I8 int8; I16 int16 \"i16\"}"}, |
| 34 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 interface { Foo (a <type -1>, b <type -2>) <type -1>; Bar (? <type -2>, ? ...<type -1>) (? <type -2>, ? <type -1>); Baz (); }>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "interface{Bar(int16, ...int8) (int16, int8); Baz(); Foo(a int8, b int16) int8}"}, |
| 35 | {idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id.: "foo", typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.: "<type 1 (? <type -1>) <type -2>>", wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.: "func(int8) int16"}, |
| 36 | } |
| 37 | |
| 38 | func TestTypeParserscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/TestTypeParser().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 39 | for _, test := range typeParserTestsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests. { |
| 40 | var p parserscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser# |
| 41 | p.initscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#init().("test.gox", stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(test.typscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:typ.), make(map[string]*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Packagescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Package#)) |
| 42 | p.versionscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#version. = "v2" |
| 43 | p.pkgnamescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#pkgname. = test.idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id. |
| 44 | p.pkgpathscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#pkgpath. = test.idscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:id. |
| 45 | p.maybeCreatePackagescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#maybeCreatePackage().() |
| 46 | typ := p.parseTypescip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#parseType().(p.pkgscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#pkg.) |
| 47 | |
| 48 | if p.tokscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#tok. != scannerscip-go gomod github.com/golang/go/src go1.25.0 `text/scanner`/.EOFscip-go gomod github.com/golang/go/src go1.25.0 `text/scanner`/EOF. { |
| 49 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected full parse, stopped at %q", p.litscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/parser#lit.) |
| 50 | } |
| 51 | |
| 52 | // interfaces must be explicitly completed |
| 53 | if ityp, _ := typ.(*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Interfacescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Interface#); ityp != nil { |
| 54 | ityp.Completescip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Interface#Complete().() |
| 55 | } |
| 56 | |
| 57 | got := typ.Stringscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Type#String().() |
| 58 | if got != test.wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want. { |
| 59 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("got type %q, expected %q", got, test.wantscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:want.) |
| 60 | } |
| 61 | |
| 62 | if test.underlyingscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:underlying. != "" { |
| 63 | underlying := typ.Underlyingscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Type#Underlying().().Stringscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Type#String().() |
| 64 | if underlying != test.underlyingscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:underlying. { |
| 65 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("got underlying type %q, expected %q", underlying, test.underlyingscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:underlying.) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if test.methodsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:methods. != "" { |
| 70 | nt := typ.(*typesscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/.Namedscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Named#) |
| 71 | var buf bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer# |
| 72 | for i := 0; i != nt.NumMethodsscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Named#NumMethods().(); i++ { |
| 73 | buf.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#WriteString().(nt.Methodscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Named#Method().(i).Stringscip-go gomod github.com/golang/go/src go1.25.0 `go/types`/Func#String().()) |
| 74 | } |
| 75 | methods := buf.Stringscip-go gomod github.com/golang/go/src go1.25.0 bytes/Buffer#String().() |
| 76 | if methods != test.methodsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:methods. { |
| 77 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("got methods %q, expected %q", methods, test.methodsscip-go gomod golang.org/x/tools . `golang.org/x/tools/go/internal/gccgoimporter`/typeParserTests:methods.) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |