Commit 649f341e authored by Bryan C. Mills's avatar Bryan C. Mills

cmd: update x/mod to CL 205497

Also revert an incidental 'gofmt' of a vendored file from CL 205240.

Updates #34822

Change-Id: I82a015d865db4d865b4776a8013312f25dbb9181
Reviewed-on: https://go-review.googlesource.com/c/go/+/205539
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 14a133fe
...@@ -7,7 +7,7 @@ require ( ...@@ -7,7 +7,7 @@ require (
github.com/ianlancetaylor/demangle v0.0.0-20180524225900-fc6590592b44 // indirect github.com/ianlancetaylor/demangle v0.0.0-20180524225900-fc6590592b44 // indirect
golang.org/x/arch v0.0.0-20190815191158-8a70ba74b3a1 golang.org/x/arch v0.0.0-20190815191158-8a70ba74b3a1
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630 golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee
golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 // indirect golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 // indirect
golang.org/x/tools v0.0.0-20191104222624-6b7b8b79ae80 golang.org/x/tools v0.0.0-20191104222624-6b7b8b79ae80
) )
...@@ -9,6 +9,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq ...@@ -9,6 +9,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630 h1:QsMqsRXZFQT+jRZnwpEDIwGHWg0UY9ZrpWiplCOEK5I= golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630 h1:QsMqsRXZFQT+jRZnwpEDIwGHWg0UY9ZrpWiplCOEK5I=
golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
......
...@@ -90,6 +90,19 @@ func (x *FileSyntax) Span() (start, end Position) { ...@@ -90,6 +90,19 @@ func (x *FileSyntax) Span() (start, end Position) {
return start, end return start, end
} }
// addLine adds a line containing the given tokens to the file.
//
// If the first token of the hint matches the first token of the
// line, the new line is added at the end of the block containing hint,
// extracting hint into a new block if it is not yet in one.
//
// If the hint is non-nil buts its first token does not match,
// the new line is added after the block containing hint
// (or hint itself, if not in a block).
//
// If no hint is provided, addLine appends the line to the end of
// the last block with a matching first token,
// or to the end of the file if no such block exists.
func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line { func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line {
if hint == nil { if hint == nil {
// If no hint given, add to the last statement of the given type. // If no hint given, add to the last statement of the given type.
...@@ -111,11 +124,27 @@ func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line { ...@@ -111,11 +124,27 @@ func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line {
} }
} }
newLineAfter := func(i int) *Line {
new := &Line{Token: tokens}
if i == len(x.Stmt) {
x.Stmt = append(x.Stmt, new)
} else {
x.Stmt = append(x.Stmt, nil)
copy(x.Stmt[i+2:], x.Stmt[i+1:])
x.Stmt[i+1] = new
}
return new
}
if hint != nil { if hint != nil {
for i, stmt := range x.Stmt { for i, stmt := range x.Stmt {
switch stmt := stmt.(type) { switch stmt := stmt.(type) {
case *Line: case *Line:
if stmt == hint { if stmt == hint {
if stmt.Token == nil || stmt.Token[0] != tokens[0] {
return newLineAfter(i)
}
// Convert line to line block. // Convert line to line block.
stmt.InBlock = true stmt.InBlock = true
block := &LineBlock{Token: stmt.Token[:1], Line: []*Line{stmt}} block := &LineBlock{Token: stmt.Token[:1], Line: []*Line{stmt}}
...@@ -125,15 +154,25 @@ func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line { ...@@ -125,15 +154,25 @@ func (x *FileSyntax) addLine(hint Expr, tokens ...string) *Line {
block.Line = append(block.Line, new) block.Line = append(block.Line, new)
return new return new
} }
case *LineBlock: case *LineBlock:
if stmt == hint { if stmt == hint {
if stmt.Token[0] != tokens[0] {
return newLineAfter(i)
}
new := &Line{Token: tokens[1:], InBlock: true} new := &Line{Token: tokens[1:], InBlock: true}
stmt.Line = append(stmt.Line, new) stmt.Line = append(stmt.Line, new)
return new return new
} }
for j, line := range stmt.Line { for j, line := range stmt.Line {
if line == hint { if line == hint {
// Add new line after hint. if stmt.Token[0] != tokens[0] {
return newLineAfter(i)
}
// Add new line after hint within the block.
stmt.Line = append(stmt.Line, nil) stmt.Line = append(stmt.Line, nil)
copy(stmt.Line[j+2:], stmt.Line[j+1:]) copy(stmt.Line[j+2:], stmt.Line[j+1:])
new := &Line{Token: tokens[1:], InBlock: true} new := &Line{Token: tokens[1:], InBlock: true}
......
...@@ -505,9 +505,13 @@ func (f *File) AddGoStmt(version string) error { ...@@ -505,9 +505,13 @@ func (f *File) AddGoStmt(version string) error {
return fmt.Errorf("invalid language version string %q", version) return fmt.Errorf("invalid language version string %q", version)
} }
if f.Go == nil { if f.Go == nil {
var hint Expr
if f.Module != nil && f.Module.Syntax != nil {
hint = f.Module.Syntax
}
f.Go = &Go{ f.Go = &Go{
Version: version, Version: version,
Syntax: f.Syntax.addLine(nil, "go", version), Syntax: f.Syntax.addLine(hint, "go", version),
} }
} else { } else {
f.Go.Version = version f.Go.Version = version
......
...@@ -231,6 +231,7 @@ func Decode(pkg *types.Package, read func(packagePath string) ([]byte, error)) ( ...@@ -231,6 +231,7 @@ func Decode(pkg *types.Package, read func(packagePath string) ([]byte, error)) (
// It may fail if one of the Facts could not be gob-encoded, but this is // It may fail if one of the Facts could not be gob-encoded, but this is
// a sign of a bug in an Analyzer. // a sign of a bug in an Analyzer.
func (s *Set) Encode() []byte { func (s *Set) Encode() []byte {
// TODO(adonovan): opt: use a more efficient encoding // TODO(adonovan): opt: use a more efficient encoding
// that avoids repeating PkgPath for each fact. // that avoids repeating PkgPath for each fact.
......
...@@ -29,7 +29,7 @@ golang.org/x/arch/x86/x86asm ...@@ -29,7 +29,7 @@ golang.org/x/arch/x86/x86asm
golang.org/x/crypto/ed25519 golang.org/x/crypto/ed25519
golang.org/x/crypto/ed25519/internal/edwards25519 golang.org/x/crypto/ed25519/internal/edwards25519
golang.org/x/crypto/ssh/terminal golang.org/x/crypto/ssh/terminal
# golang.org/x/mod v0.1.1-0.20191101203923-a222b9651630 # golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee
## explicit ## explicit
golang.org/x/mod/internal/lazyregexp golang.org/x/mod/internal/lazyregexp
golang.org/x/mod/modfile golang.org/x/mod/modfile
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment