Skip to content

Commit 2cf8044

Browse files
committed
all: merge master (adcfb65) into gopls-release-branch.0.8
Also add a replace directive to gopls/go.mod. Merge List: + 2022-02-17 adcfb65 internal/lsp/source: use the object as the hover source for type params + 2022-02-17 411d040 internal/lsp/source: clean up the interface to hover information + 2022-02-17 45aeaf7 internal/lsp/source: improve the heuristics for linkable identifiers + 2022-02-17 a317113 internal/lsp/source: fix hover on generic type declarations + 2022-02-17 1f3875c internal/lsp/source: begin to refactor hovering with a HoverContext type + 2022-02-17 fd59bdf internal/lsp/source: adjust object position when formatting full AST + 2022-02-17 cda4201 internal/lsp/source: simplify Identifier.enclosing + 2022-02-16 59f1f2c cmd/goyacc: reduce array sizes using smaller base types + 2022-02-16 c677677 internal/lsp/cache: let Session.getGoEnv query GOWORK + 2022-02-16 9095d10 go/analysis/passes/tests: fix a missed rename from CL 374495 + 2022-02-16 70c3ea2 gopls,internal/lsp: Implement method stubbing via CodeAction + 2022-02-16 2ff4db7 go/analysis/passes/tests: Check malformed fuzz target. + 2022-02-15 11109f6 go/ssa/ssautil: Initialize Instances field. + 2022-02-15 33002ea go/loader: Initialize (types/Info).Instances field + 2022-02-15 be40034 internal/lsp: add support for formatting go.work files + 2022-02-15 2405dce internal/lsp: use placeholders with prepare rename + 2022-02-14 c6fca02 godoc: handle type parameters correctly in LinkifyText + 2022-02-09 c0b9fb5 internal/lsp/analysis/undeclaredname: suppress impossible quick fixes Change-Id: I43b1dbcd9aff3c05f0a4884f3ee593d1906de326
2 parents 9466be7 + adcfb65 commit 2cf8044

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2166
-343
lines changed

cmd/goyacc/yacc.go

Lines changed: 92 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import (
5151
"fmt"
5252
"go/format"
5353
"io/ioutil"
54+
"math"
5455
"os"
5556
"strconv"
5657
"strings"
@@ -2157,7 +2158,7 @@ func output() {
21572158
if !lflag {
21582159
fmt.Fprintf(ftable, "\n//line yacctab:1")
21592160
}
2160-
fmt.Fprintf(ftable, "\nvar %sExca = [...]int{\n", prefix)
2161+
var actions []int
21612162

21622163
if len(errors) > 0 {
21632164
stateTable = make([]Row, nstate)
@@ -2230,10 +2231,11 @@ func output() {
22302231
}
22312232
}
22322233
}
2233-
wract(i)
2234+
actions = addActions(actions, i)
22342235
}
22352236

2236-
fmt.Fprintf(ftable, "}\n")
2237+
arrayOutColumns("Exca", actions, 2, false)
2238+
fmt.Fprintf(ftable, "\n")
22372239
ftable.WriteRune('\n')
22382240
fmt.Fprintf(ftable, "const %sPrivate = %v\n", prefix, PRIVATE)
22392241
}
@@ -2278,7 +2280,7 @@ func precftn(r, t, s int) {
22782280
// output state i
22792281
// temp1 has the actions, lastred the default
22802282
//
2281-
func wract(i int) {
2283+
func addActions(act []int, i int) []int {
22822284
var p, p1 int
22832285

22842286
// find the best choice for lastred
@@ -2351,18 +2353,19 @@ func wract(i int) {
23512353
continue
23522354
}
23532355
if flag == 0 {
2354-
fmt.Fprintf(ftable, "\t-1, %v,\n", i)
2356+
act = append(act, -1, i)
23552357
}
23562358
flag++
2357-
fmt.Fprintf(ftable, "\t%v, %v,\n", p, p1)
2359+
act = append(act, p, p1)
23582360
zzexcp++
23592361
}
23602362
}
23612363
if flag != 0 {
23622364
defact[i] = -2
2363-
fmt.Fprintf(ftable, "\t-2, %v,\n", lastred)
2365+
act = append(act, -2, lastred)
23642366
}
23652367
optst[i] = os
2368+
return act
23662369
}
23672370

23682371
//
@@ -2855,7 +2858,7 @@ func others() {
28552858
}
28562859
}
28572860
arout("Chk", temp1, nstate)
2858-
arout("Def", defact, nstate)
2861+
arrayOutColumns("Def", defact[:nstate], 10, false)
28592862

28602863
// put out token translation tables
28612864
// table 1 has 0-256
@@ -2903,8 +2906,7 @@ func others() {
29032906

29042907
// table 3 has everything else
29052908
ftable.WriteRune('\n')
2906-
fmt.Fprintf(ftable, "var %sTok3 = [...]int{\n\t", prefix)
2907-
c = 0
2909+
var v []int
29082910
for i = 1; i <= ntokens; i++ {
29092911
j = tokset[i].value
29102912
if j >= 0 && j < 256 {
@@ -2914,19 +2916,11 @@ func others() {
29142916
continue
29152917
}
29162918

2917-
if c%5 != 0 {
2918-
ftable.WriteRune(' ')
2919-
}
2920-
fmt.Fprintf(ftable, "%d, %d,", j, i)
2921-
c++
2922-
if c%5 == 0 {
2923-
fmt.Fprint(ftable, "\n\t")
2924-
}
2919+
v = append(v, j, i)
29252920
}
2926-
if c%5 != 0 {
2927-
ftable.WriteRune(' ')
2928-
}
2929-
fmt.Fprintf(ftable, "%d,\n}\n", 0)
2921+
v = append(v, 0)
2922+
arout("Tok3", v, len(v))
2923+
fmt.Fprintf(ftable, "\n")
29302924

29312925
// Custom error messages.
29322926
fmt.Fprintf(ftable, "\n")
@@ -3013,21 +3007,65 @@ Loop:
30133007
}
30143008
}
30153009

3016-
func arout(s string, v []int, n int) {
3010+
func minMax(v []int) (min, max int) {
3011+
if len(v) == 0 {
3012+
return
3013+
}
3014+
min = v[0]
3015+
max = v[0]
3016+
for _, i := range v {
3017+
if i < min {
3018+
min = i
3019+
}
3020+
if i > max {
3021+
max = i
3022+
}
3023+
}
3024+
return
3025+
}
3026+
3027+
// return the smaller integral base type to store the values in v
3028+
func minType(v []int, allowUnsigned bool) (typ string) {
3029+
typ = "int"
3030+
typeLen := 8
3031+
min, max := minMax(v)
3032+
checkType := func(name string, size, minType, maxType int) {
3033+
if min >= minType && max <= maxType && typeLen > size {
3034+
typ = name
3035+
typeLen = size
3036+
}
3037+
}
3038+
checkType("int32", 4, math.MinInt32, math.MaxInt32)
3039+
checkType("int16", 2, math.MinInt16, math.MaxInt16)
3040+
checkType("int8", 1, math.MinInt8, math.MaxInt8)
3041+
if allowUnsigned {
3042+
// Do not check for uint32, not worth and won't compile on 32 bit systems
3043+
checkType("uint16", 2, 0, math.MaxUint16)
3044+
checkType("uint8", 1, 0, math.MaxUint8)
3045+
}
3046+
return
3047+
}
3048+
3049+
func arrayOutColumns(s string, v []int, columns int, allowUnsigned bool) {
30173050
s = prefix + s
30183051
ftable.WriteRune('\n')
3019-
fmt.Fprintf(ftable, "var %v = [...]int{", s)
3020-
for i := 0; i < n; i++ {
3021-
if i%10 == 0 {
3052+
minType := minType(v, allowUnsigned)
3053+
fmt.Fprintf(ftable, "var %v = [...]%s{", s, minType)
3054+
for i, val := range v {
3055+
if i%columns == 0 {
30223056
fmt.Fprintf(ftable, "\n\t")
30233057
} else {
30243058
ftable.WriteRune(' ')
30253059
}
3026-
fmt.Fprintf(ftable, "%d,", v[i])
3060+
fmt.Fprintf(ftable, "%d,", val)
30273061
}
30283062
fmt.Fprintf(ftable, "\n}\n")
30293063
}
30303064

3065+
func arout(s string, v []int, n int) {
3066+
arrayOutColumns(s, v[:n], 10, true)
3067+
}
3068+
30313069
//
30323070
// output the summary on y.output
30333071
//
@@ -3332,9 +3370,9 @@ func $$ErrorMessage(state, lookAhead int) string {
33323370
expected := make([]int, 0, 4)
33333371
33343372
// Look for shiftable tokens.
3335-
base := $$Pact[state]
3373+
base := int($$Pact[state])
33363374
for tok := TOKSTART; tok-1 < len($$Toknames); tok++ {
3337-
if n := base + tok; n >= 0 && n < $$Last && $$Chk[$$Act[n]] == tok {
3375+
if n := base + tok; n >= 0 && n < $$Last && int($$Chk[int($$Act[n])]) == tok {
33383376
if len(expected) == cap(expected) {
33393377
return res
33403378
}
@@ -3344,13 +3382,13 @@ func $$ErrorMessage(state, lookAhead int) string {
33443382
33453383
if $$Def[state] == -2 {
33463384
i := 0
3347-
for $$Exca[i] != -1 || $$Exca[i+1] != state {
3385+
for $$Exca[i] != -1 || int($$Exca[i+1]) != state {
33483386
i += 2
33493387
}
33503388
33513389
// Look for tokens that we accept or reduce.
33523390
for i += 2; $$Exca[i] >= 0; i += 2 {
3353-
tok := $$Exca[i]
3391+
tok := int($$Exca[i])
33543392
if tok < TOKSTART || $$Exca[i+1] == 0 {
33553393
continue
33563394
}
@@ -3381,30 +3419,30 @@ func $$lex1(lex $$Lexer, lval *$$SymType) (char, token int) {
33813419
token = 0
33823420
char = lex.Lex(lval)
33833421
if char <= 0 {
3384-
token = $$Tok1[0]
3422+
token = int($$Tok1[0])
33853423
goto out
33863424
}
33873425
if char < len($$Tok1) {
3388-
token = $$Tok1[char]
3426+
token = int($$Tok1[char])
33893427
goto out
33903428
}
33913429
if char >= $$Private {
33923430
if char < $$Private+len($$Tok2) {
3393-
token = $$Tok2[char-$$Private]
3431+
token = int($$Tok2[char-$$Private])
33943432
goto out
33953433
}
33963434
}
33973435
for i := 0; i < len($$Tok3); i += 2 {
3398-
token = $$Tok3[i+0]
3436+
token = int($$Tok3[i+0])
33993437
if token == char {
3400-
token = $$Tok3[i+1]
3438+
token = int($$Tok3[i+1])
34013439
goto out
34023440
}
34033441
}
34043442
34053443
out:
34063444
if token == 0 {
3407-
token = $$Tok2[1] /* unknown char */
3445+
token = int($$Tok2[1]) /* unknown char */
34083446
}
34093447
if $$Debug >= 3 {
34103448
__yyfmt__.Printf("lex %s(%d)\n", $$Tokname(token), uint(char))
@@ -3459,7 +3497,7 @@ $$stack:
34593497
$$S[$$p].yys = $$state
34603498
34613499
$$newstate:
3462-
$$n = $$Pact[$$state]
3500+
$$n = int($$Pact[$$state])
34633501
if $$n <= $$Flag {
34643502
goto $$default /* simple state */
34653503
}
@@ -3470,8 +3508,8 @@ $$newstate:
34703508
if $$n < 0 || $$n >= $$Last {
34713509
goto $$default
34723510
}
3473-
$$n = $$Act[$$n]
3474-
if $$Chk[$$n] == $$token { /* valid shift */
3511+
$$n = int($$Act[$$n])
3512+
if int($$Chk[$$n]) == $$token { /* valid shift */
34753513
$$rcvr.char = -1
34763514
$$token = -1
34773515
$$VAL = $$rcvr.lval
@@ -3484,7 +3522,7 @@ $$newstate:
34843522
34853523
$$default:
34863524
/* default state action */
3487-
$$n = $$Def[$$state]
3525+
$$n = int($$Def[$$state])
34883526
if $$n == -2 {
34893527
if $$rcvr.char < 0 {
34903528
$$rcvr.char, $$token = $$lex1($$lex, &$$rcvr.lval)
@@ -3493,18 +3531,18 @@ $$default:
34933531
/* look through exception table */
34943532
xi := 0
34953533
for {
3496-
if $$Exca[xi+0] == -1 && $$Exca[xi+1] == $$state {
3534+
if $$Exca[xi+0] == -1 && int($$Exca[xi+1]) == $$state {
34973535
break
34983536
}
34993537
xi += 2
35003538
}
35013539
for xi += 2; ; xi += 2 {
3502-
$$n = $$Exca[xi+0]
3540+
$$n = int($$Exca[xi+0])
35033541
if $$n < 0 || $$n == $$token {
35043542
break
35053543
}
35063544
}
3507-
$$n = $$Exca[xi+1]
3545+
$$n = int($$Exca[xi+1])
35083546
if $$n < 0 {
35093547
goto ret0
35103548
}
@@ -3526,10 +3564,10 @@ $$default:
35263564
35273565
/* find a state where "error" is a legal shift action */
35283566
for $$p >= 0 {
3529-
$$n = $$Pact[$$S[$$p].yys] + $$ErrCode
3567+
$$n = int($$Pact[$$S[$$p].yys]) + $$ErrCode
35303568
if $$n >= 0 && $$n < $$Last {
3531-
$$state = $$Act[$$n] /* simulate a shift of "error" */
3532-
if $$Chk[$$state] == $$ErrCode {
3569+
$$state = int($$Act[$$n]) /* simulate a shift of "error" */
3570+
if int($$Chk[$$state]) == $$ErrCode {
35333571
goto $$stack
35343572
}
35353573
}
@@ -3565,7 +3603,7 @@ $$default:
35653603
$$pt := $$p
35663604
_ = $$pt // guard against "declared and not used"
35673605
3568-
$$p -= $$R2[$$n]
3606+
$$p -= int($$R2[$$n])
35693607
// $$p is now the index of $0. Perform the default action. Iff the
35703608
// reduced production is ε, $1 is possibly out of range.
35713609
if $$p+1 >= len($$S) {
@@ -3576,16 +3614,16 @@ $$default:
35763614
$$VAL = $$S[$$p+1]
35773615
35783616
/* consult goto table to find next state */
3579-
$$n = $$R1[$$n]
3580-
$$g := $$Pgo[$$n]
3617+
$$n = int($$R1[$$n])
3618+
$$g := int($$Pgo[$$n])
35813619
$$j := $$g + $$S[$$p].yys + 1
35823620
35833621
if $$j >= $$Last {
3584-
$$state = $$Act[$$g]
3622+
$$state = int($$Act[$$g])
35853623
} else {
3586-
$$state = $$Act[$$j]
3587-
if $$Chk[$$state] != -$$n {
3588-
$$state = $$Act[$$g]
3624+
$$state = int($$Act[$$j])
3625+
if int($$Chk[$$state]) != -$$n {
3626+
$$state = int($$Act[$$g])
35893627
}
35903628
}
35913629
// dummy call; replaced with literal code

0 commit comments

Comments
 (0)