File: package.go

package info (click to toggle)
golang-github-go-restruct-restruct 1.2.0-alpha-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 344 kB
  • sloc: makefile: 2
file content (29 lines) | stat: -rw-r--r-- 660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package expr

// Package represents a package value.
type Package struct {
	types   map[string]Type
	symbols map[string]Value
}

// NewPackage creates a new package.
func NewPackage(symbols map[string]Value) Package {
	pkg := Package{symbols: symbols, types: map[string]Type{}}
	for key := range symbols {
		pkg.types[key] = pkg.symbols[key].Type()
	}
	return pkg
}

// Symbol returns a symbol, or nil if the symbol doesn't exist.
func (p Package) Symbol(ident string) Value {
	if symbol, ok := p.symbols[ident]; ok {
		return symbol
	}
	return nil
}

// Type returns the type for this package.
func (p Package) Type() Type {
	return NewPackageType(p.types)
}