1
0
mirror of https://github.com/golang/go synced 2024-11-15 10:10:22 -07:00
The Go programming language
Go to file
Robert Griesemer 41ff51ae00 [dev.typeparams] cmd/compile/internal/types2: review of scopes.go
This file has a few changes compared to the go/types version:
1) syntax.Pos is used instead of token.Pos.
2) The cmpPos helper function (defined elsewhere) is used to
   compare positions (syntax.Pos positions cannot be compared
   directly with <=).
3) A new method Scope.Squash was added (primary difference).

f=scope.go; diff $f ../../../../go/types/$f
7c7
< package types2
---
> package types
11d10
< 	"cmd/compile/internal/syntax"
12a12
> 	"go/token"
26c26
< 	pos, end syntax.Pos        // scope extent; may be invalid
---
> 	pos, end token.Pos         // scope extent; may be invalid
33c33
< func NewScope(parent *Scope, pos, end syntax.Pos, comment string) *Scope {
---
> func NewScope(parent *Scope, pos, end token.Pos, comment string) *Scope {
82c82
< func (s *Scope) LookupParent(name string, pos syntax.Pos) (*Scope, Object) {
---
> func (s *Scope) LookupParent(name string, pos token.Pos) (*Scope, Object) {
84c84
< 		if obj := s.elems[name]; obj != nil && (!pos.IsKnown() || cmpPos(obj.scopePos(), pos) <= 0) {
---
> 		if obj := s.elems[name]; obj != nil && (!pos.IsValid() || obj.scopePos() <= pos) {
111,144d110
< // Squash merges s with its parent scope p by adding all
< // objects of s to p, adding all children of s to the
< // children of p, and removing s from p's children.
< // The function f is called for each object obj in s which
< // has an object alt in p. s should be discarded after
< // having been squashed.
< func (s *Scope) Squash(err func(obj, alt Object)) {
< 	p := s.parent
< 	assert(p != nil)
< 	for _, obj := range s.elems {
< 		obj.setParent(nil)
< 		if alt := p.Insert(obj); alt != nil {
< 			err(obj, alt)
< 		}
< 	}
<
< 	j := -1 // index of s in p.children
< 	for i, ch := range p.children {
< 		if ch == s {
< 			j = i
< 			break
< 		}
< 	}
< 	assert(j >= 0)
< 	k := len(p.children) - 1
< 	p.children[j] = p.children[k]
< 	p.children = p.children[:k]
<
< 	p.children = append(p.children, s.children...)
<
< 	s.children = nil
< 	s.elems = nil
< }
<
149,150c115,116
< func (s *Scope) Pos() syntax.Pos { return s.pos }
< func (s *Scope) End() syntax.Pos { return s.end }
---
> func (s *Scope) Pos() token.Pos { return s.pos }
> func (s *Scope) End() token.Pos { return s.end }
155,156c121,122
< func (s *Scope) Contains(pos syntax.Pos) bool {
< 	return cmpPos(s.pos, pos) <= 0 && cmpPos(pos, s.end) < 0
---
> func (s *Scope) Contains(pos token.Pos) bool {
> 	return s.pos <= pos && pos < s.end
164c130
< func (s *Scope) Innermost(pos syntax.Pos) *Scope {
---
> func (s *Scope) Innermost(pos token.Pos) *Scope {

Change-Id: If6c459f45dae8980ffb3a902a46b1700e9b55dc7
Reviewed-on: https://go-review.googlesource.com/c/go/+/265700
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-10-28 04:14:01 +00:00
.github .github: add link to questions in ISSUE_TEMPLATE 2020-01-06 17:05:31 +00:00
api io/fs: move FileInfo, FileMode, PathError, ErrInvalid, ... from os to io/fs 2020-10-20 02:32:41 +00:00
doc cmd/go: set TOOLEXEC_IMPORTPATH for -toolexec tools 2020-10-22 15:10:01 +00:00
lib/time lib/time, time, time/tzdata: use slim tz data format 2020-10-14 09:00:41 +00:00
misc misc/wasm: improve error message if javascript polyfills are required 2020-10-21 13:19:35 +00:00
src [dev.typeparams] cmd/compile/internal/types2: review of scopes.go 2020-10-28 04:14:01 +00:00
test [dev.typeparams] cmd/compile: enable type-checking of generic code 2020-10-27 03:37:05 +00:00
.gitattributes all: treat all files as binary, but check in .bat with CRLF 2020-06-08 15:31:43 +00:00
.gitignore
AUTHORS A+C: add Kush Patel (corporate CLA for Hootsuite Inc) 2020-07-08 00:10:44 +00:00
CONTRIBUTING.md
CONTRIBUTORS CONTRIBUTORS: update for the Go 1.15 release 2020-08-10 21:51:48 +00:00
favicon.ico
LICENSE
PATENTS
README.md README: linkify some paths 2018-06-06 18:07:01 +00:00
robots.txt
SECURITY.md SECURITY.md: update go versions 2019-09-26 15:34:57 +00:00

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Download and Install

Binary Distributions

Official binary distributions are available at https://golang.org/dl/.

After downloading a binary release, visit https://golang.org/doc/install or load doc/install.html in your web browser for installation instructions.

Install From Source

If a binary distribution is not available for your combination of operating system and architecture, visit https://golang.org/doc/install/source or load doc/install-source.html in your web browser for source installation instructions.

Contributing

Go is the work of thousands of contributors. We appreciate your help!

To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html

Note that the Go project uses the issue tracker for bug reports and proposals only. See https://golang.org/wiki/Questions for a list of places to ask questions about the Go language.