$53 GRAYBYTE WORDPRESS FILE MANAGER $27

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/lib/golang/src/go/types/

HOME
Current File : /lib/golang/src/go/types//scope.go
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
// Source: ../../cmd/compile/internal/types2/scope.go

// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This file implements Scopes.

package types

import (
	"fmt"
	"go/token"
	"io"
	"slices"
	"strings"
	"sync"
)

// A Scope maintains a set of objects and links to its containing
// (parent) and contained (children) scopes. Objects may be inserted
// and looked up by name. The zero value for Scope is a ready-to-use
// empty scope.
type Scope struct {
	parent   *Scope
	children []*Scope
	number   int               // parent.children[number-1] is this scope; 0 if there is no parent
	elems    map[string]Object // lazily allocated
	pos, end token.Pos         // scope extent; may be invalid
	comment  string            // for debugging only
	isFunc   bool              // set if this is a function scope (internal use only)
}

// NewScope returns a new, empty scope contained in the given parent
// scope, if any. The comment is for debugging only.
func NewScope(parent *Scope, pos, end token.Pos, comment string) *Scope {
	s := &Scope{parent, nil, 0, nil, pos, end, comment, false}
	// don't add children to Universe scope!
	if parent != nil && parent != Universe {
		parent.children = append(parent.children, s)
		s.number = len(parent.children)
	}
	return s
}

// Parent returns the scope's containing (parent) scope.
func (s *Scope) Parent() *Scope { return s.parent }

// Len returns the number of scope elements.
func (s *Scope) Len() int { return len(s.elems) }

// Names returns the scope's element names in sorted order.
func (s *Scope) Names() []string {
	names := make([]string, len(s.elems))
	i := 0
	for name := range s.elems {
		names[i] = name
		i++
	}
	slices.Sort(names)
	return names
}

// NumChildren returns the number of scopes nested in s.
func (s *Scope) NumChildren() int { return len(s.children) }

// Child returns the i'th child scope for 0 <= i < NumChildren().
func (s *Scope) Child(i int) *Scope { return s.children[i] }

// Lookup returns the object in scope s with the given name if such an
// object exists; otherwise the result is nil.
func (s *Scope) Lookup(name string) Object {
	obj := resolve(name, s.elems[name])
	// Hijack Lookup for "any": with gotypesalias=1, we want the Universe to
	// return an Alias for "any", and with gotypesalias=0 we want to return
	// the legacy representation of aliases.
	//
	// This is rather tricky, but works out after auditing of the usage of
	// s.elems. The only external API to access scope elements is Lookup.
	//
	// TODO: remove this once gotypesalias=0 is no longer supported.
	if obj == universeAnyAlias && !aliasAny() {
		return universeAnyNoAlias
	}
	return obj
}

// lookupIgnoringCase returns the objects in scope s whose names match
// the given name ignoring case. If exported is set, only exported names
// are returned.
func (s *Scope) lookupIgnoringCase(name string, exported bool) []Object {
	var matches []Object
	for _, n := range s.Names() {
		if (!exported || isExported(n)) && strings.EqualFold(n, name) {
			matches = append(matches, s.Lookup(n))
		}
	}
	return matches
}

// Insert attempts to insert an object obj into scope s.
// If s already contains an alternative object alt with
// the same name, Insert leaves s unchanged and returns alt.
// Otherwise it inserts obj, sets the object's parent scope
// if not already set, and returns nil.
func (s *Scope) Insert(obj Object) Object {
	name := obj.Name()
	if alt := s.Lookup(name); alt != nil {
		return alt
	}
	s.insert(name, obj)
	// TODO(gri) Can we always set the parent to s (or is there
	// a need to keep the original parent or some race condition)?
	// If we can, than we may not need environment.lookupScope
	// which is only there so that we get the correct scope for
	// marking "used" dot-imported packages.
	if obj.Parent() == nil {
		obj.setParent(s)
	}
	return nil
}

// InsertLazy is like Insert, but allows deferring construction of the
// inserted object until it's accessed with Lookup. The Object
// returned by resolve must have the same name as given to InsertLazy.
// If s already contains an alternative object with the same name,
// InsertLazy leaves s unchanged and returns false. Otherwise it
// records the binding and returns true. The object's parent scope
// will be set to s after resolve is called.
func (s *Scope) _InsertLazy(name string, resolve func() Object) bool {
	if s.elems[name] != nil {
		return false
	}
	s.insert(name, &lazyObject{parent: s, resolve: resolve})
	return true
}

func (s *Scope) insert(name string, obj Object) {
	if s.elems == nil {
		s.elems = make(map[string]Object)
	}
	s.elems[name] = obj
}

// WriteTo writes a string representation of the scope to w,
// with the scope elements sorted by name.
// The level of indentation is controlled by n >= 0, with
// n == 0 for no indentation.
// If recurse is set, it also writes nested (children) scopes.
func (s *Scope) WriteTo(w io.Writer, n int, recurse bool) {
	const ind = ".  "
	indn := strings.Repeat(ind, n)

	fmt.Fprintf(w, "%s%s scope %p {\n", indn, s.comment, s)

	indn1 := indn + ind
	for _, name := range s.Names() {
		fmt.Fprintf(w, "%s%s\n", indn1, s.Lookup(name))
	}

	if recurse {
		for _, s := range s.children {
			s.WriteTo(w, n+1, recurse)
		}
	}

	fmt.Fprintf(w, "%s}\n", indn)
}

// String returns a string representation of the scope, for debugging.
func (s *Scope) String() string {
	var buf strings.Builder
	s.WriteTo(&buf, 0, false)
	return buf.String()
}

// A lazyObject represents an imported Object that has not been fully
// resolved yet by its importer.
type lazyObject struct {
	parent  *Scope
	resolve func() Object
	obj     Object
	once    sync.Once
}

// resolve returns the Object represented by obj, resolving lazy
// objects as appropriate.
func resolve(name string, obj Object) Object {
	if lazy, ok := obj.(*lazyObject); ok {
		lazy.once.Do(func() {
			obj := lazy.resolve()

			if _, ok := obj.(*lazyObject); ok {
				panic("recursive lazy object")
			}
			if obj.Name() != name {
				panic("lazy object has unexpected name")
			}

			if obj.Parent() == nil {
				obj.setParent(lazy.parent)
			}
			lazy.obj = obj
		})

		obj = lazy.obj
	}
	return obj
}

// stub implementations so *lazyObject implements Object and we can
// store them directly into Scope.elems.
func (*lazyObject) Parent() *Scope                     { panic("unreachable") }
func (*lazyObject) Pos() token.Pos                     { panic("unreachable") }
func (*lazyObject) Pkg() *Package                      { panic("unreachable") }
func (*lazyObject) Name() string                       { panic("unreachable") }
func (*lazyObject) Type() Type                         { panic("unreachable") }
func (*lazyObject) Exported() bool                     { panic("unreachable") }
func (*lazyObject) Id() string                         { panic("unreachable") }
func (*lazyObject) String() string                     { panic("unreachable") }
func (*lazyObject) order() uint32                      { panic("unreachable") }
func (*lazyObject) color() color                       { panic("unreachable") }
func (*lazyObject) setType(Type)                       { panic("unreachable") }
func (*lazyObject) setOrder(uint32)                    { panic("unreachable") }
func (*lazyObject) setColor(color color)               { panic("unreachable") }
func (*lazyObject) setParent(*Scope)                   { panic("unreachable") }
func (*lazyObject) sameId(*Package, string, bool) bool { panic("unreachable") }
func (*lazyObject) scopePos() token.Pos                { panic("unreachable") }
func (*lazyObject) setScopePos(token.Pos)              { panic("unreachable") }

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
4 Dec 2025 6.06 PM
root / root
0755
README.md
0.133 KB
4 Dec 2025 6.06 PM
root / root
0644
alias.go
6.063 KB
4 Dec 2025 6.06 PM
root / root
0644
api.go
17.887 KB
4 Dec 2025 6.06 PM
root / root
0644
api_predicates.go
3.451 KB
4 Dec 2025 6.06 PM
root / root
0644
array.go
0.905 KB
4 Dec 2025 6.06 PM
root / root
0644
assignments.go
16.889 KB
4 Dec 2025 6.06 PM
root / root
0644
badlinkname.go
0.686 KB
4 Dec 2025 6.06 PM
root / root
0644
basic.go
1.605 KB
4 Dec 2025 6.06 PM
root / root
0644
builtins.go
29.413 KB
4 Dec 2025 6.06 PM
root / root
0644
call.go
33.833 KB
4 Dec 2025 6.06 PM
root / root
0644
chan.go
1.009 KB
4 Dec 2025 6.06 PM
root / root
0644
check.go
21.786 KB
4 Dec 2025 6.06 PM
root / root
0644
const.go
7.618 KB
4 Dec 2025 6.06 PM
root / root
0644
context.go
4.429 KB
4 Dec 2025 6.06 PM
root / root
0644
conversions.go
9.082 KB
4 Dec 2025 6.06 PM
root / root
0644
decl.go
31.035 KB
4 Dec 2025 6.06 PM
root / root
0644
errors.go
8.49 KB
4 Dec 2025 6.06 PM
root / root
0644
errsupport.go
4.528 KB
4 Dec 2025 6.06 PM
root / root
0644
eval.go
3.069 KB
4 Dec 2025 6.06 PM
root / root
0644
expr.go
39.407 KB
4 Dec 2025 6.06 PM
root / root
0644
exprstring.go
4.781 KB
4 Dec 2025 6.06 PM
root / root
0644
format.go
4.031 KB
4 Dec 2025 6.06 PM
root / root
0644
gccgosizes.go
1.143 KB
4 Dec 2025 6.06 PM
root / root
0644
gcsizes.go
4.357 KB
4 Dec 2025 6.06 PM
root / root
0644
generate.go
0.263 KB
4 Dec 2025 6.06 PM
root / root
0644
gotype.go
8.33 KB
4 Dec 2025 6.06 PM
root / root
0644
index.go
11.772 KB
4 Dec 2025 6.06 PM
root / root
0644
infer.go
27.142 KB
4 Dec 2025 6.06 PM
root / root
0644
initorder.go
10.131 KB
4 Dec 2025 6.06 PM
root / root
0644
instantiate.go
13.211 KB
4 Dec 2025 6.06 PM
root / root
0644
interface.go
8.155 KB
4 Dec 2025 6.06 PM
root / root
0644
iter.go
3.873 KB
4 Dec 2025 6.06 PM
root / root
0644
labels.go
7.295 KB
4 Dec 2025 6.06 PM
root / root
0644
literals.go
12.77 KB
4 Dec 2025 6.06 PM
root / root
0644
lookup.go
22.653 KB
4 Dec 2025 6.06 PM
root / root
0644
map.go
0.763 KB
4 Dec 2025 6.06 PM
root / root
0644
methodset.go
7.058 KB
4 Dec 2025 6.06 PM
root / root
0644
mono.go
9.194 KB
4 Dec 2025 6.06 PM
root / root
0644
named.go
24.34 KB
4 Dec 2025 6.06 PM
root / root
0644
object.go
22.06 KB
4 Dec 2025 6.06 PM
root / root
0644
objset.go
1.028 KB
4 Dec 2025 6.06 PM
root / root
0644
operand.go
12.16 KB
4 Dec 2025 6.06 PM
root / root
0644
package.go
3.05 KB
4 Dec 2025 6.06 PM
root / root
0644
pointer.go
0.743 KB
4 Dec 2025 6.06 PM
root / root
0644
predicates.go
17.609 KB
4 Dec 2025 6.06 PM
root / root
0644
range.go
9.338 KB
4 Dec 2025 6.06 PM
root / root
0644
recording.go
4.648 KB
4 Dec 2025 6.06 PM
root / root
0644
resolver.go
25.255 KB
4 Dec 2025 6.06 PM
root / root
0644
return.go
4.232 KB
4 Dec 2025 6.06 PM
root / root
0644
scope.go
7.632 KB
4 Dec 2025 6.06 PM
root / root
0644
scope2.go
2.554 KB
4 Dec 2025 6.06 PM
root / root
0644
selection.go
5.906 KB
4 Dec 2025 6.06 PM
root / root
0644
signature.go
17.81 KB
4 Dec 2025 6.06 PM
root / root
0644
sizes.go
8.939 KB
4 Dec 2025 6.06 PM
root / root
0644
slice.go
0.685 KB
4 Dec 2025 6.06 PM
root / root
0644
stmt.go
23.696 KB
4 Dec 2025 6.06 PM
root / root
0644
struct.go
6.149 KB
4 Dec 2025 6.06 PM
root / root
0644
subst.go
10.411 KB
4 Dec 2025 6.06 PM
root / root
0644
termlist.go
3.894 KB
4 Dec 2025 6.06 PM
root / root
0644
tuple.go
1.028 KB
4 Dec 2025 6.06 PM
root / root
0644
type.go
0.528 KB
4 Dec 2025 6.06 PM
root / root
0644
typelists.go
1.967 KB
4 Dec 2025 6.06 PM
root / root
0644
typeparam.go
5.224 KB
4 Dec 2025 6.06 PM
root / root
0644
typeset.go
13.31 KB
4 Dec 2025 6.06 PM
root / root
0644
typestring.go
12.479 KB
4 Dec 2025 6.06 PM
root / root
0644
typeterm.go
3.643 KB
4 Dec 2025 6.06 PM
root / root
0644
typexpr.go
16.179 KB
4 Dec 2025 6.06 PM
root / root
0644
under.go
4.331 KB
4 Dec 2025 6.06 PM
root / root
0644
unify.go
27.898 KB
4 Dec 2025 6.06 PM
root / root
0644
union.go
6.225 KB
4 Dec 2025 6.06 PM
root / root
0644
universe.go
9.354 KB
4 Dec 2025 6.06 PM
root / root
0644
util.go
1.9 KB
4 Dec 2025 6.06 PM
root / root
0644
validtype.go
10.345 KB
4 Dec 2025 6.06 PM
root / root
0644
version.go
2.036 KB
4 Dec 2025 6.06 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF