diff options
author | Ian Lance Taylor <iant@golang.org> | 2022-02-11 14:53:56 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2022-02-11 15:01:19 -0800 |
commit | 8dc2499aa62f768c6395c9754b8cabc1ce25c494 (patch) | |
tree | 43d7fd2bbfd7ad8c9625a718a5e8718889351994 /libgo/go/fmt | |
parent | 9a56779dbc4e2d9c15be8d31e36f2f59be7331a8 (diff) | |
download | gcc-8dc2499aa62f768c6395c9754b8cabc1ce25c494.zip gcc-8dc2499aa62f768c6395c9754b8cabc1ce25c494.tar.gz gcc-8dc2499aa62f768c6395c9754b8cabc1ce25c494.tar.bz2 |
libgo: update to Go1.18beta2
gotools/
* Makefile.am (go_cmd_cgo_files): Add ast_go118.go
(check-go-tool): Copy golang.org/x/tools directories.
* Makefile.in: Regenerate.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/384695
Diffstat (limited to 'libgo/go/fmt')
-rw-r--r-- | libgo/go/fmt/errors.go | 2 | ||||
-rw-r--r-- | libgo/go/fmt/fmt_test.go | 50 | ||||
-rw-r--r-- | libgo/go/fmt/print.go | 40 | ||||
-rw-r--r-- | libgo/go/fmt/scan.go | 28 | ||||
-rw-r--r-- | libgo/go/fmt/scan_test.go | 24 |
5 files changed, 72 insertions, 72 deletions
diff --git a/libgo/go/fmt/errors.go b/libgo/go/fmt/errors.go index 466a620..4f4daf1 100644 --- a/libgo/go/fmt/errors.go +++ b/libgo/go/fmt/errors.go @@ -14,7 +14,7 @@ import "errors" // invalid to include more than one %w verb or to supply it with an operand // that does not implement the error interface. The %w verb is otherwise // a synonym for %v. -func Errorf(format string, a ...interface{}) error { +func Errorf(format string, a ...any) error { p := newPrinter() p.wrapErrs = true p.doPrintf(format, a) diff --git a/libgo/go/fmt/fmt_test.go b/libgo/go/fmt/fmt_test.go index e52e5db..951d5bf 100644 --- a/libgo/go/fmt/fmt_test.go +++ b/libgo/go/fmt/fmt_test.go @@ -40,7 +40,7 @@ type ( ) func TestFmtInterface(t *testing.T) { - var i1 interface{} + var i1 any i1 = "abc" s := Sprintf("%s", i1) if s != "abc" { @@ -56,7 +56,7 @@ var ( intVar = 0 array = [5]int{1, 2, 3, 4, 5} - iarray = [4]interface{}{1, "hello", 2.5, nil} + iarray = [4]any{1, "hello", 2.5, nil} slice = array[:] islice = iarray[:] ) @@ -100,7 +100,7 @@ type S struct { } type SI struct { - I interface{} + I any } // P is a type with a String method with pointer receiver for testing %p. @@ -141,7 +141,7 @@ func (sf writeStringFormatter) Format(f State, c rune) { var fmtTests = []struct { fmt string - val interface{} + val any out string }{ {"%d", 12345, "12345"}, @@ -993,14 +993,14 @@ var fmtTests = []struct { // float and complex formatting should not change the padding width // for other elements. See issue 14642. - {"%06v", []interface{}{+10.0, 10}, "[000010 000010]"}, - {"%06v", []interface{}{-10.0, 10}, "[-00010 000010]"}, - {"%06v", []interface{}{+10.0 + 10i, 10}, "[(000010+00010i) 000010]"}, - {"%06v", []interface{}{-10.0 + 10i, 10}, "[(-00010+00010i) 000010]"}, + {"%06v", []any{+10.0, 10}, "[000010 000010]"}, + {"%06v", []any{-10.0, 10}, "[-00010 000010]"}, + {"%06v", []any{+10.0 + 10i, 10}, "[(000010+00010i) 000010]"}, + {"%06v", []any{-10.0 + 10i, 10}, "[(-00010+00010i) 000010]"}, // integer formatting should not alter padding for other elements. - {"%03.6v", []interface{}{1, 2.0, "x"}, "[000001 002 00x]"}, - {"%03.0v", []interface{}{0, 2.0, "x"}, "[ 002 000]"}, + {"%03.6v", []any{1, 2.0, "x"}, "[000001 002 00x]"}, + {"%03.0v", []any{0, 2.0, "x"}, "[ 002 000]"}, // Complex fmt used to leave the plus flag set for future entries in the array // causing +2+0i and +3+0i instead of 2+0i and 3+0i. @@ -1060,7 +1060,7 @@ var fmtTests = []struct { // Tests to check that not supported verbs generate an error string. {"%☠", nil, "%!☠(<nil>)"}, - {"%☠", interface{}(nil), "%!☠(<nil>)"}, + {"%☠", any(nil), "%!☠(<nil>)"}, {"%☠", int(0), "%!☠(int=0)"}, {"%☠", uint(0), "%!☠(uint=0)"}, {"%☠", []byte{0, 1}, "[%!☠(uint8=0) %!☠(uint8=1)]"}, @@ -1077,8 +1077,8 @@ var fmtTests = []struct { {"%☠", func() {}, "%!☠(func()=0xPTR)"}, {"%☠", reflect.ValueOf(renamedInt(0)), "%!☠(fmt_test.renamedInt=0)"}, {"%☠", SI{renamedInt(0)}, "{%!☠(fmt_test.renamedInt=0)}"}, - {"%☠", &[]interface{}{I(1), G(2)}, "&[%!☠(fmt_test.I=1) %!☠(fmt_test.G=2)]"}, - {"%☠", SI{&[]interface{}{I(1), G(2)}}, "{%!☠(*[]interface {}=&[1 2])}"}, + {"%☠", &[]any{I(1), G(2)}, "&[%!☠(fmt_test.I=1) %!☠(fmt_test.G=2)]"}, + {"%☠", SI{&[]any{I(1), G(2)}}, "{%!☠(*[]interface {}=&[1 2])}"}, {"%☠", reflect.Value{}, "<invalid reflect.Value>"}, {"%☠", map[float64]int{NaN: 1}, "map[%!☠(float64=NaN):%!☠(int=1)]"}, } @@ -1180,7 +1180,7 @@ func TestComplexFormatting(t *testing.T) { } } -type SE []interface{} // slice of empty; notational compactness. +type SE []any // slice of empty; notational compactness. var reorderTests = []struct { fmt string @@ -1267,7 +1267,7 @@ func BenchmarkSprintfTruncateString(b *testing.B) { } func BenchmarkSprintfTruncateBytes(b *testing.B) { - var bytes interface{} = []byte("日本語日本語日本語日本語") + var bytes any = []byte("日本語日本語日本語日本語") b.RunParallel(func(pb *testing.PB) { for pb.Next() { Sprintf("%.3s", bytes) @@ -1375,7 +1375,7 @@ func BenchmarkSprintfStringer(b *testing.B) { } func BenchmarkSprintfStructure(b *testing.B) { - s := &[]interface{}{SI{12345}, map[int]string{0: "hello"}} + s := &[]any{SI{12345}, map[int]string{0: "hello"}} b.RunParallel(func(pb *testing.PB) { for pb.Next() { Sprintf("%#v", s) @@ -1411,7 +1411,7 @@ func BenchmarkFprintfBytes(b *testing.B) { } func BenchmarkFprintIntNoAlloc(b *testing.B) { - var x interface{} = 123456 + var x any = 123456 var buf bytes.Buffer for i := 0; i < b.N; i++ { buf.Reset() @@ -1643,11 +1643,11 @@ func TestFormatterPrintln(t *testing.T) { } } -func args(a ...interface{}) []interface{} { return a } +func args(a ...any) []any { return a } var startests = []struct { fmt string - in []interface{} + in []any out string }{ {"%*d", args(4, 42), " 42"}, @@ -1689,7 +1689,7 @@ func TestWidthAndPrecision(t *testing.T) { // PanicS is a type that panics in String. type PanicS struct { - message interface{} + message any } // Value receiver. @@ -1699,7 +1699,7 @@ func (p PanicS) String() string { // PanicGo is a type that panics in GoString. type PanicGo struct { - message interface{} + message any } // Value receiver. @@ -1709,7 +1709,7 @@ func (p PanicGo) GoString() string { // PanicF is a type that panics in Format. type PanicF struct { - message interface{} + message any } // Value receiver. @@ -1719,7 +1719,7 @@ func (p PanicF) Format(f State, c rune) { var panictests = []struct { fmt string - in interface{} + in any out string }{ // String @@ -1731,7 +1731,7 @@ var panictests = []struct { {"%#v", PanicGo{io.ErrUnexpectedEOF}, "%!v(PANIC=GoString method: unexpected EOF)"}, {"%#v", PanicGo{3}, "%!v(PANIC=GoString method: 3)"}, // Issue 18282. catchPanic should not clear fmtFlags permanently. - {"%#v", []interface{}{PanicGo{3}, PanicGo{3}}, "[]interface {}{%!v(PANIC=GoString method: 3), %!v(PANIC=GoString method: 3)}"}, + {"%#v", []any{PanicGo{3}, PanicGo{3}}, "[]interface {}{%!v(PANIC=GoString method: 3), %!v(PANIC=GoString method: 3)}"}, // Format {"%s", (*PanicF)(nil), "<nil>"}, // nil pointer special case {"%s", PanicF{io.ErrUnexpectedEOF}, "%!s(PANIC=Format method: unexpected EOF)"}, @@ -1807,7 +1807,7 @@ func TestNilDoesNotBecomeTyped(t *testing.T) { var formatterFlagTests = []struct { in string - val interface{} + val any out string }{ // scalar values with the (unused by fmt) 'a' verb. diff --git a/libgo/go/fmt/print.go b/libgo/go/fmt/print.go index 8bc225f..1c37c3c 100644 --- a/libgo/go/fmt/print.go +++ b/libgo/go/fmt/print.go @@ -106,7 +106,7 @@ type pp struct { buf buffer // arg holds the current item, as an interface{}. - arg interface{} + arg any // value is used instead of arg for reflect values. value reflect.Value @@ -129,7 +129,7 @@ type pp struct { } var ppFree = sync.Pool{ - New: func() interface{} { return new(pp) }, + New: func() any { return new(pp) }, } // newPrinter allocates a new pp struct or grabs a cached one. @@ -199,7 +199,7 @@ func (p *pp) WriteString(s string) (ret int, err error) { // Fprintf formats according to a format specifier and writes to w. // It returns the number of bytes written and any write error encountered. -func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { +func Fprintf(w io.Writer, format string, a ...any) (n int, err error) { p := newPrinter() p.doPrintf(format, a) n, err = w.Write(p.buf) @@ -209,12 +209,12 @@ func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { // Printf formats according to a format specifier and writes to standard output. // It returns the number of bytes written and any write error encountered. -func Printf(format string, a ...interface{}) (n int, err error) { +func Printf(format string, a ...any) (n int, err error) { return Fprintf(os.Stdout, format, a...) } // Sprintf formats according to a format specifier and returns the resulting string. -func Sprintf(format string, a ...interface{}) string { +func Sprintf(format string, a ...any) string { p := newPrinter() p.doPrintf(format, a) s := string(p.buf) @@ -227,7 +227,7 @@ func Sprintf(format string, a ...interface{}) string { // Fprint formats using the default formats for its operands and writes to w. // Spaces are added between operands when neither is a string. // It returns the number of bytes written and any write error encountered. -func Fprint(w io.Writer, a ...interface{}) (n int, err error) { +func Fprint(w io.Writer, a ...any) (n int, err error) { p := newPrinter() p.doPrint(a) n, err = w.Write(p.buf) @@ -238,13 +238,13 @@ func Fprint(w io.Writer, a ...interface{}) (n int, err error) { // Print formats using the default formats for its operands and writes to standard output. // Spaces are added between operands when neither is a string. // It returns the number of bytes written and any write error encountered. -func Print(a ...interface{}) (n int, err error) { +func Print(a ...any) (n int, err error) { return Fprint(os.Stdout, a...) } // Sprint formats using the default formats for its operands and returns the resulting string. // Spaces are added between operands when neither is a string. -func Sprint(a ...interface{}) string { +func Sprint(a ...any) string { p := newPrinter() p.doPrint(a) s := string(p.buf) @@ -259,7 +259,7 @@ func Sprint(a ...interface{}) string { // Fprintln formats using the default formats for its operands and writes to w. // Spaces are always added between operands and a newline is appended. // It returns the number of bytes written and any write error encountered. -func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { +func Fprintln(w io.Writer, a ...any) (n int, err error) { p := newPrinter() p.doPrintln(a) n, err = w.Write(p.buf) @@ -270,13 +270,13 @@ func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { // Println formats using the default formats for its operands and writes to standard output. // Spaces are always added between operands and a newline is appended. // It returns the number of bytes written and any write error encountered. -func Println(a ...interface{}) (n int, err error) { +func Println(a ...any) (n int, err error) { return Fprintln(os.Stdout, a...) } // Sprintln formats using the default formats for its operands and returns the resulting string. // Spaces are always added between operands and a newline is appended. -func Sprintln(a ...interface{}) string { +func Sprintln(a ...any) string { p := newPrinter() p.doPrintln(a) s := string(p.buf) @@ -498,7 +498,7 @@ func (p *pp) fmtBytes(v []byte, verb rune, typeString string) { func (p *pp) fmtPointer(value reflect.Value, verb rune) { var u uintptr switch value.Kind() { - case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Slice, reflect.UnsafePointer: + case reflect.Chan, reflect.Func, reflect.Map, reflect.Pointer, reflect.Slice, reflect.UnsafePointer: u = value.Pointer() default: p.badVerb(verb) @@ -533,12 +533,12 @@ func (p *pp) fmtPointer(value reflect.Value, verb rune) { } } -func (p *pp) catchPanic(arg interface{}, verb rune, method string) { +func (p *pp) catchPanic(arg any, verb rune, method string) { if err := recover(); err != nil { // If it's a nil pointer, just say "<nil>". The likeliest causes are a // Stringer that fails to guard against nil or a nil pointer for a // value receiver, and in either case, "<nil>" is a nice result. - if v := reflect.ValueOf(arg); v.Kind() == reflect.Ptr && v.IsNil() { + if v := reflect.ValueOf(arg); v.Kind() == reflect.Pointer && v.IsNil() { p.buf.writeString(nilAngleString) return } @@ -631,7 +631,7 @@ func (p *pp) handleMethods(verb rune) (handled bool) { return false } -func (p *pp) printArg(arg interface{}, verb rune) { +func (p *pp) printArg(arg any, verb rune) { p.arg = arg p.value = reflect.Value{} @@ -866,7 +866,7 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { } p.buf.writeByte(']') } - case reflect.Ptr: + case reflect.Pointer: // pointer to array or slice or struct? ok at top level // but not embedded (avoid loops) if depth == 0 && f.Pointer() != 0 { @@ -886,7 +886,7 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { } // intFromArg gets the argNumth element of a. On return, isInt reports whether the argument has integer type. -func intFromArg(a []interface{}, argNum int) (num int, isInt bool, newArgNum int) { +func intFromArg(a []any, argNum int) (num int, isInt bool, newArgNum int) { newArgNum = argNum if argNum < len(a) { num, isInt = a[argNum].(int) // Almost always OK. @@ -971,7 +971,7 @@ func (p *pp) missingArg(verb rune) { p.buf.writeString(missingString) } -func (p *pp) doPrintf(format string, a []interface{}) { +func (p *pp) doPrintf(format string, a []any) { end := len(format) argNum := 0 // we process one argument per non-trivial format afterIndex := false // previous item in format was an index like [3]. @@ -1146,7 +1146,7 @@ formatLoop: } } -func (p *pp) doPrint(a []interface{}) { +func (p *pp) doPrint(a []any) { prevString := false for argNum, arg := range a { isString := arg != nil && reflect.TypeOf(arg).Kind() == reflect.String @@ -1161,7 +1161,7 @@ func (p *pp) doPrint(a []interface{}) { // doPrintln is like doPrint but always adds a space between arguments // and a newline after the last argument. -func (p *pp) doPrintln(a []interface{}) { +func (p *pp) doPrintln(a []any) { for argNum, arg := range a { if argNum > 0 { p.buf.writeByte(' ') diff --git a/libgo/go/fmt/scan.go b/libgo/go/fmt/scan.go index 3815770..d38610d 100644 --- a/libgo/go/fmt/scan.go +++ b/libgo/go/fmt/scan.go @@ -60,13 +60,13 @@ type Scanner interface { // space-separated values into successive arguments. Newlines count // as space. It returns the number of items successfully scanned. // If that is less than the number of arguments, err will report why. -func Scan(a ...interface{}) (n int, err error) { +func Scan(a ...any) (n int, err error) { return Fscan(os.Stdin, a...) } // Scanln is similar to Scan, but stops scanning at a newline and // after the final item there must be a newline or EOF. -func Scanln(a ...interface{}) (n int, err error) { +func Scanln(a ...any) (n int, err error) { return Fscanln(os.Stdin, a...) } @@ -77,7 +77,7 @@ func Scanln(a ...interface{}) (n int, err error) { // Newlines in the input must match newlines in the format. // The one exception: the verb %c always scans the next rune in the // input, even if it is a space (or tab etc.) or newline. -func Scanf(format string, a ...interface{}) (n int, err error) { +func Scanf(format string, a ...any) (n int, err error) { return Fscanf(os.Stdin, format, a...) } @@ -96,13 +96,13 @@ func (r *stringReader) Read(b []byte) (n int, err error) { // values into successive arguments. Newlines count as space. It // returns the number of items successfully scanned. If that is less // than the number of arguments, err will report why. -func Sscan(str string, a ...interface{}) (n int, err error) { +func Sscan(str string, a ...any) (n int, err error) { return Fscan((*stringReader)(&str), a...) } // Sscanln is similar to Sscan, but stops scanning at a newline and // after the final item there must be a newline or EOF. -func Sscanln(str string, a ...interface{}) (n int, err error) { +func Sscanln(str string, a ...any) (n int, err error) { return Fscanln((*stringReader)(&str), a...) } @@ -110,7 +110,7 @@ func Sscanln(str string, a ...interface{}) (n int, err error) { // values into successive arguments as determined by the format. It // returns the number of items successfully parsed. // Newlines in the input must match newlines in the format. -func Sscanf(str string, format string, a ...interface{}) (n int, err error) { +func Sscanf(str string, format string, a ...any) (n int, err error) { return Fscanf((*stringReader)(&str), format, a...) } @@ -118,7 +118,7 @@ func Sscanf(str string, format string, a ...interface{}) (n int, err error) { // values into successive arguments. Newlines count as space. It // returns the number of items successfully scanned. If that is less // than the number of arguments, err will report why. -func Fscan(r io.Reader, a ...interface{}) (n int, err error) { +func Fscan(r io.Reader, a ...any) (n int, err error) { s, old := newScanState(r, true, false) n, err = s.doScan(a) s.free(old) @@ -127,7 +127,7 @@ func Fscan(r io.Reader, a ...interface{}) (n int, err error) { // Fscanln is similar to Fscan, but stops scanning at a newline and // after the final item there must be a newline or EOF. -func Fscanln(r io.Reader, a ...interface{}) (n int, err error) { +func Fscanln(r io.Reader, a ...any) (n int, err error) { s, old := newScanState(r, false, true) n, err = s.doScan(a) s.free(old) @@ -138,7 +138,7 @@ func Fscanln(r io.Reader, a ...interface{}) (n int, err error) { // values into successive arguments as determined by the format. It // returns the number of items successfully parsed. // Newlines in the input must match newlines in the format. -func Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error) { +func Fscanf(r io.Reader, format string, a ...any) (n int, err error) { s, old := newScanState(r, false, false) n, err = s.doScanf(format, a) s.free(old) @@ -376,7 +376,7 @@ func (r *readRune) UnreadRune() error { } var ssFree = sync.Pool{ - New: func() interface{} { return new(ss) }, + New: func() any { return new(ss) }, } // newScanState allocates a new ss struct or grab a cached one. @@ -950,7 +950,7 @@ func (s *ss) scanPercent() { } // scanOne scans a single value, deriving the scanner from the type of the argument. -func (s *ss) scanOne(verb rune, arg interface{}) { +func (s *ss) scanOne(verb rune, arg any) { s.buf = s.buf[:0] var err error // If the parameter has its own Scan method, use that. @@ -1017,7 +1017,7 @@ func (s *ss) scanOne(verb rune, arg interface{}) { default: val := reflect.ValueOf(v) ptr := val - if ptr.Kind() != reflect.Ptr { + if ptr.Kind() != reflect.Pointer { s.errorString("type not a pointer: " + val.Type().String()) return } @@ -1067,7 +1067,7 @@ func errorHandler(errp *error) { } // doScan does the real work for scanning without a format string. -func (s *ss) doScan(a []interface{}) (numProcessed int, err error) { +func (s *ss) doScan(a []any) (numProcessed int, err error) { defer errorHandler(&err) for _, arg := range a { s.scanOne('v', arg) @@ -1178,7 +1178,7 @@ func (s *ss) advance(format string) (i int) { // doScanf does the real work when scanning with a format string. // At the moment, it handles only pointers to basic types. -func (s *ss) doScanf(format string, a []interface{}) (numProcessed int, err error) { +func (s *ss) doScanf(format string, a []any) (numProcessed int, err error) { defer errorHandler(&err) end := len(format) - 1 // We process one item per non-trivial format diff --git a/libgo/go/fmt/scan_test.go b/libgo/go/fmt/scan_test.go index 1cc469c..da0dfd1 100644 --- a/libgo/go/fmt/scan_test.go +++ b/libgo/go/fmt/scan_test.go @@ -21,22 +21,22 @@ import ( type ScanTest struct { text string - in interface{} - out interface{} + in any + out any } type ScanfTest struct { format string text string - in interface{} - out interface{} + in any + out any } type ScanfMultiTest struct { format string text string - in []interface{} - out []interface{} + in []any + out []any err string } @@ -444,7 +444,7 @@ var z IntString var r1, r2, r3 rune var multiTests = []ScanfMultiTest{ - {"", "", []interface{}{}, []interface{}{}, ""}, + {"", "", []any{}, []any{}, ""}, {"%d", "23", args(&i), args(23), ""}, {"%2s%3s", "22333", args(&s, &t), args("22", "333"), ""}, {"%2d%3d", "44555", args(&i, &j), args(44, 555), ""}, @@ -498,7 +498,7 @@ var readers = []struct { }}, } -func testScan(t *testing.T, f func(string) io.Reader, scan func(r io.Reader, a ...interface{}) (int, error)) { +func testScan(t *testing.T, f func(string) io.Reader, scan func(r io.Reader, a ...any) (int, error)) { for _, test := range scanTests { r := f(test.text) n, err := scan(r, test.in) @@ -516,7 +516,7 @@ func testScan(t *testing.T, f func(string) io.Reader, scan func(r io.Reader, a . } // The incoming value may be a pointer v := reflect.ValueOf(test.in) - if p := v; p.Kind() == reflect.Ptr { + if p := v; p.Kind() == reflect.Pointer { v = p.Elem() } val := v.Interface() @@ -561,7 +561,7 @@ func TestScanf(t *testing.T) { } // The incoming value may be a pointer v := reflect.ValueOf(test.in) - if p := v; p.Kind() == reflect.Ptr { + if p := v; p.Kind() == reflect.Pointer { v = p.Elem() } val := v.Interface() @@ -637,7 +637,7 @@ func TestInf(t *testing.T) { } func testScanfMulti(t *testing.T, f func(string) io.Reader) { - sliceType := reflect.TypeOf(make([]interface{}, 1)) + sliceType := reflect.TypeOf(make([]any, 1)) for _, test := range multiTests { r := f(test.text) n, err := Fscanf(r, test.format, test.in...) @@ -836,7 +836,7 @@ func TestEOFAtEndOfInput(t *testing.T) { var eofTests = []struct { format string - v interface{} + v any }{ {"%s", &stringVal}, {"%q", &stringVal}, |