From a250f37cbc93a0d625741b0d380154ed3a94ca09 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 8 Dec 2011 22:08:03 -0500 Subject: [PATCH] update tree for new default type rule R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5448091 --- src/cmd/cgo/gcc.go | 2 +- src/cmd/godoc/dirtrees.go | 2 +- src/pkg/bytes/bytes.go | 2 +- src/pkg/exp/types/gcimporter.go | 22 +++++++++++++++++----- src/pkg/fmt/scan_test.go | 12 +++++++----- src/pkg/go/build/dir.go | 6 +++--- src/pkg/html/escape.go | 2 +- src/pkg/html/template/css.go | 2 +- src/pkg/math/big/nat.go | 2 +- src/pkg/regexp/syntax/parse.go | 8 ++++---- src/pkg/strings/strings.go | 2 +- src/pkg/strings/strings_test.go | 2 +- src/pkg/unicode/letter.go | 8 ++++---- 13 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 646857419d..dc18abfcca 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -201,7 +201,7 @@ func splitQuoted(s string) (r []string, err error) { arg := make([]rune, len(s)) escaped := false quoted := false - quote := rune(0) + quote := '\x00' i := 0 for _, r := range s { switch { diff --git a/src/cmd/godoc/dirtrees.go b/src/cmd/godoc/dirtrees.go index 7f06348938..4be9107eb8 100644 --- a/src/cmd/godoc/dirtrees.go +++ b/src/cmd/godoc/dirtrees.go @@ -47,7 +47,7 @@ func isPkgDir(fi os.FileInfo) bool { func firstSentence(s string) string { i := -1 // index+1 of first terminator (punctuation ending a sentence) j := -1 // index+1 of first terminator followed by white space - prev := rune('A') + prev := 'A' for k, ch := range s { k1 := k + 1 if ch == '.' || ch == '!' || ch == '?' { diff --git a/src/pkg/bytes/bytes.go b/src/pkg/bytes/bytes.go index 307c89aa3d..e94a0ec5c4 100644 --- a/src/pkg/bytes/bytes.go +++ b/src/pkg/bytes/bytes.go @@ -470,7 +470,7 @@ func Title(s []byte) []byte { // Use a closure here to remember state. // Hackish but effective. Depends on Map scanning in order and calling // the closure once per rune. - prev := rune(' ') + prev := ' ' return Map( func(r rune) rune { if isSeparator(prev) { diff --git a/src/pkg/exp/types/gcimporter.go b/src/pkg/exp/types/gcimporter.go index 6adcc2a9ad..150c6edb3c 100644 --- a/src/pkg/exp/types/gcimporter.go +++ b/src/pkg/exp/types/gcimporter.go @@ -81,7 +81,7 @@ type gcParser struct { func (p *gcParser) init(filename, id string, src io.Reader, imports map[string]*ast.Object) { p.scanner.Init(src) p.scanner.Error = func(_ *scanner.Scanner, msg string) { p.error(msg) } - p.scanner.Mode = scanner.ScanIdents | scanner.ScanInts | scanner.ScanStrings | scanner.ScanComments | scanner.SkipComments + p.scanner.Mode = scanner.ScanIdents | scanner.ScanInts | scanner.ScanChars | scanner.ScanStrings | scanner.ScanComments | scanner.SkipComments p.scanner.Whitespace = 1<<'\t' | 1<<' ' p.scanner.Filename = filename // for good error messages p.next() @@ -206,7 +206,7 @@ func (p *gcParser) expect(tok rune) string { } func (p *gcParser) expectSpecial(tok string) { - sep := rune('x') // not white space + sep := 'x' // not white space i := 0 for i < len(tok) && p.tok == rune(tok[i]) && sep > ' ' { sep = p.scanner.Peek() // if sep <= ' ', there is white space before the next token @@ -261,7 +261,7 @@ func (p *gcParser) parsePkgId() *ast.Object { func (p *gcParser) parseDotIdent() string { ident := "" if p.tok != scanner.Int { - sep := rune('x') // not white space + sep := 'x' // not white space for (p.tok == scanner.Ident || p.tok == scanner.Int || p.tok == 'ยท') && sep > ' ' { ident += p.lit sep = p.scanner.Peek() // if sep <= ' ', there is white space before the next token @@ -645,6 +645,7 @@ func (p *gcParser) parseNumber() Const { // Literal = bool_lit | int_lit | float_lit | complex_lit | string_lit . // bool_lit = "true" | "false" . // complex_lit = "(" float_lit "+" float_lit ")" . +// rune_lit = "(" int_lit "+" int_lit ")" . // string_lit = `"` { unicode_char } `"` . // func (p *gcParser) parseConstDecl() { @@ -674,21 +675,32 @@ func (p *gcParser) parseConstDecl() { typ = Float64.Underlying } case '(': - // complex_lit + // complex_lit or rune_lit p.next() + if p.tok == scanner.Char { + p.next() + p.expect('+') + p.parseNumber() + // TODO: x = ... + break + } re := p.parseNumber() p.expect('+') im := p.parseNumber() p.expect(')') x = Const{cmplx{re.val.(*big.Rat), im.val.(*big.Rat)}} typ = Complex128.Underlying + case scanner.Char: + // TODO: x = ... + p.next() case scanner.String: // string_lit x = MakeConst(token.STRING, p.lit) p.next() typ = String.Underlying default: - p.error("expected literal") + println(p.tok) + p.errorf("expected literal got %s", scanner.TokenString(p.tok)) } if obj.Type == nil { obj.Type = typ diff --git a/src/pkg/fmt/scan_test.go b/src/pkg/fmt/scan_test.go index 0689bf3b6e..b26c828cbf 100644 --- a/src/pkg/fmt/scan_test.go +++ b/src/pkg/fmt/scan_test.go @@ -56,6 +56,7 @@ var ( stringVal string stringVal1 string bytesVal []byte + runeVal rune complex64Val complex64 complex128Val complex128 renamedBoolVal renamedBool @@ -225,9 +226,9 @@ var scanfTests = []ScanfTest{ {"%v", "0377\n", &intVal, 0377}, {"%v", "0x44\n", &intVal, 0x44}, {"%d", "72\n", &intVal, 72}, - {"%c", "a\n", &intVal, 'a'}, - {"%c", "\u5072\n", &intVal, 0x5072}, - {"%c", "\u1234\n", &intVal, '\u1234'}, + {"%c", "a\n", &runeVal, 'a'}, + {"%c", "\u5072\n", &runeVal, '\u5072'}, + {"%c", "\u1234\n", &runeVal, '\u1234'}, {"%d", "73\n", &int8Val, int8(73)}, {"%d", "+74\n", &int16Val, int16(74)}, {"%d", "75\n", &int32Val, int32(75)}, @@ -322,6 +323,7 @@ var s, t string var c complex128 var x, y Xs var z IntString +var r1, r2, r3 rune var multiTests = []ScanfMultiTest{ {"", "", []interface{}{}, []interface{}{}, ""}, @@ -333,7 +335,7 @@ var multiTests = []ScanfMultiTest{ {"%3d22%3d", "33322333", args(&i, &j), args(333, 333), ""}, {"%6vX=%3fY", "3+2iX=2.5Y", args(&c, &f), args((3 + 2i), 2.5), ""}, {"%d%s", "123abc", args(&i, &s), args(123, "abc"), ""}, - {"%c%c%c", "2\u50c2X", args(&i, &j, &k), args('2', '\u50c2', 'X'), ""}, + {"%c%c%c", "2\u50c2X", args(&r1, &r2, &r3), args('2', '\u50c2', 'X'), ""}, // Custom scanners. {"%e%f", "eefffff", args(&x, &y), args(Xs("ee"), Xs("fffff")), ""}, @@ -347,7 +349,7 @@ var multiTests = []ScanfMultiTest{ {"X%d", "10X", args(&intVal), nil, "input does not match format"}, // Bad UTF-8: should see every byte. - {"%c%c%c", "\xc2X\xc2", args(&i, &j, &k), args(utf8.RuneError, 'X', utf8.RuneError), ""}, + {"%c%c%c", "\xc2X\xc2", args(&r1, &r2, &r3), args(utf8.RuneError, 'X', utf8.RuneError), ""}, } func testScan(name string, t *testing.T, scan func(r io.Reader, a ...interface{}) (int, error)) { diff --git a/src/pkg/go/build/dir.go b/src/pkg/go/build/dir.go index 12dc99942a..2c89224fd4 100644 --- a/src/pkg/go/build/dir.go +++ b/src/pkg/go/build/dir.go @@ -466,7 +466,7 @@ func splitQuoted(s string) (r []string, err error) { arg := make([]rune, len(s)) escaped := false quoted := false - quote := rune(0) + quote := '\x00' i := 0 for _, rune := range s { switch { @@ -475,9 +475,9 @@ func splitQuoted(s string) (r []string, err error) { case rune == '\\': escaped = true continue - case quote != 0: + case quote != '\x00': if rune == quote { - quote = 0 + quote = '\x00' continue } case rune == '"' || rune == '\'': diff --git a/src/pkg/html/escape.go b/src/pkg/html/escape.go index ac9e100df0..42be865ef0 100644 --- a/src/pkg/html/escape.go +++ b/src/pkg/html/escape.go @@ -78,7 +78,7 @@ func unescapeEntity(b []byte, dst, src int, attribute bool) (dst1, src1 int) { i++ } - x := rune(0) + x := '\x00' for i < len(s) { c = s[i] i++ diff --git a/src/pkg/html/template/css.go b/src/pkg/html/template/css.go index b0a2f013d2..3bcd984983 100644 --- a/src/pkg/html/template/css.go +++ b/src/pkg/html/template/css.go @@ -106,7 +106,7 @@ func isHex(c byte) bool { // hexDecode decodes a short hex digit sequence: "10" -> 16. func hexDecode(s []byte) rune { - n := rune(0) + n := '\x00' for _, c := range s { n <<= 4 switch { diff --git a/src/pkg/math/big/nat.go b/src/pkg/math/big/nat.go index 680445dc9a..ead1a881a6 100644 --- a/src/pkg/math/big/nat.go +++ b/src/pkg/math/big/nat.go @@ -592,7 +592,7 @@ func (x nat) bitLen() int { const MaxBase = 'z' - 'a' + 10 + 1 // = hexValue('z') + 1 func hexValue(ch rune) Word { - d := MaxBase + 1 // illegal base + d := int(MaxBase + 1) // illegal base switch { case '0' <= ch && ch <= '9': d = int(ch - '0') diff --git a/src/pkg/regexp/syntax/parse.go b/src/pkg/regexp/syntax/parse.go index 6c37df9707..6f8acbbefb 100644 --- a/src/pkg/regexp/syntax/parse.go +++ b/src/pkg/regexp/syntax/parse.go @@ -1694,7 +1694,7 @@ func appendFoldedClass(r []rune, x []rune) []rune { // appendNegatedClass returns the result of appending the negation of the class x to the class r. // It assumes x is clean. func appendNegatedClass(r []rune, x []rune) []rune { - nextLo := rune('\u0000') + nextLo := '\u0000' for i := 0; i < len(x); i += 2 { lo, hi := x[i], x[i+1] if nextLo <= lo-1 { @@ -1735,7 +1735,7 @@ func appendTable(r []rune, x *unicode.RangeTable) []rune { // appendNegatedTable returns the result of appending the negation of x to the class r. func appendNegatedTable(r []rune, x *unicode.RangeTable) []rune { - nextLo := rune('\u0000') // lo end of next class to add + nextLo := '\u0000' // lo end of next class to add for _, xr := range x.R16 { lo, hi, stride := rune(xr.Lo), rune(xr.Hi), rune(xr.Stride) if stride == 1 { @@ -1777,8 +1777,8 @@ func appendNegatedTable(r []rune, x *unicode.RangeTable) []rune { // negateClass overwrites r and returns r's negation. // It assumes the class r is already clean. func negateClass(r []rune) []rune { - nextLo := rune('\u0000') // lo end of next class to add - w := 0 // write index + nextLo := '\u0000' // lo end of next class to add + w := 0 // write index for i := 0; i < len(r); i += 2 { lo, hi := r[i], r[i+1] if nextLo <= lo-1 { diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go index 53fdeadf97..b411ba5d8b 100644 --- a/src/pkg/strings/strings.go +++ b/src/pkg/strings/strings.go @@ -434,7 +434,7 @@ func Title(s string) string { // Use a closure here to remember state. // Hackish but effective. Depends on Map scanning in order and calling // the closure once per rune. - prev := rune(' ') + prev := ' ' return Map( func(r rune) rune { if isSeparator(prev) { diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go index 957af67b2b..8866d220c0 100644 --- a/src/pkg/strings/strings_test.go +++ b/src/pkg/strings/strings_test.go @@ -642,7 +642,7 @@ func equal(m string, s1, s2 string, t *testing.T) bool { func TestCaseConsistency(t *testing.T) { // Make a string of all the runes. - numRunes := unicode.MaxRune + 1 + numRunes := int(unicode.MaxRune + 1) if testing.Short() { numRunes = 1000 } diff --git a/src/pkg/unicode/letter.go b/src/pkg/unicode/letter.go index 01c485b693..dcc160a5b7 100644 --- a/src/pkg/unicode/letter.go +++ b/src/pkg/unicode/letter.go @@ -7,10 +7,10 @@ package unicode const ( - MaxRune = 0x10FFFF // Maximum valid Unicode code point. - ReplacementChar = 0xFFFD // Represents invalid code points. - MaxASCII = 0x7F // maximum ASCII value. - MaxLatin1 = 0xFF // maximum Latin-1 value. + MaxRune = '\U0010FFFF' // Maximum valid Unicode code point. + ReplacementChar = '\uFFFD' // Represents invalid code points. + MaxASCII = '\u007F' // maximum ASCII value. + MaxLatin1 = '\u00FF' // maximum Latin-1 value. ) // RangeTable defines a set of Unicode code points by listing the ranges of