mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-21 16:55:38 +03:00
[chore] bump modernc.org/sqlite v1.28.0 -> v1.29.4 (#2749)
This commit is contained in:
parent
1bcdf1da3b
commit
c27049ad15
125 changed files with 2480136 additions and 1870210 deletions
9
go.mod
9
go.mod
|
@ -76,7 +76,7 @@ require (
|
|||
golang.org/x/text v0.14.0
|
||||
gopkg.in/mcuadros/go-syslog.v2 v2.3.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
modernc.org/sqlite v1.28.0
|
||||
modernc.org/sqlite v1.29.4
|
||||
mvdan.cc/xurls/v2 v2.5.0
|
||||
)
|
||||
|
||||
|
@ -143,6 +143,7 @@ require (
|
|||
github.com/gorilla/securecookie v1.1.1 // indirect
|
||||
github.com/gorilla/sessions v1.2.1 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/huandu/xstrings v1.3.3 // indirect
|
||||
github.com/imdario/mergo v0.3.12 // indirect
|
||||
|
@ -154,7 +155,6 @@ require (
|
|||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/klauspost/compress v1.17.6 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
|
@ -220,13 +220,10 @@ require (
|
|||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
lukechampine.com/uint128 v1.2.0 // indirect
|
||||
modernc.org/cc/v3 v3.41.0 // indirect
|
||||
modernc.org/ccgo/v3 v3.16.15 // indirect
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
|
||||
modernc.org/libc v1.41.0 // indirect
|
||||
modernc.org/mathutil v1.6.0 // indirect
|
||||
modernc.org/memory v1.7.2 // indirect
|
||||
modernc.org/opt v0.1.3 // indirect
|
||||
modernc.org/strutil v1.2.0 // indirect
|
||||
modernc.org/token v1.1.0 // indirect
|
||||
)
|
||||
|
|
28
go.sum
28
go.sum
|
@ -402,6 +402,8 @@ github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
|
|||
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
|
@ -441,8 +443,6 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
|
|||
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
|
||||
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
|
||||
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
|
@ -1131,34 +1131,22 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
|
||||
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
modernc.org/cc/v3 v3.41.0 h1:QoR1Sn3YWlmA1T4vLaKZfawdVtSiGx8H+cEojbC7v1Q=
|
||||
modernc.org/cc/v3 v3.41.0/go.mod h1:Ni4zjJYJ04CDOhG7dn640WGfwBzfE0ecX8TyMB0Fv0Y=
|
||||
modernc.org/ccgo/v3 v3.16.15 h1:KbDR3ZAVU+wiLyMESPtbtE/Add4elztFyfsWoNTgxS0=
|
||||
modernc.org/ccgo/v3 v3.16.15/go.mod h1:yT7B+/E2m43tmMOT51GMoM98/MtHIcQQSleGnddkUNI=
|
||||
modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
|
||||
modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
|
||||
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
|
||||
modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
|
||||
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
|
||||
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI=
|
||||
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4=
|
||||
modernc.org/libc v1.41.0 h1:g9YAc6BkKlgORsUWj+JwqoB1wU3o4DE3bM3yvA3k+Gk=
|
||||
modernc.org/libc v1.41.0/go.mod h1:w0eszPsiXoOnoMJgrXjglgLuDy/bt5RR4y3QzUUeodY=
|
||||
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
|
||||
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
|
||||
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
|
||||
modernc.org/memory v1.7.2/go.mod h1:NO4NVCQy0N7ln+T9ngWqOQfi7ley4vpwvARR+Hjw95E=
|
||||
modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4=
|
||||
modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
|
||||
modernc.org/sqlite v1.28.0 h1:Zx+LyDDmXczNnEQdvPuEfcFVA2ZPyaD7UCZDjef3BHQ=
|
||||
modernc.org/sqlite v1.28.0/go.mod h1:Qxpazz0zH8Z1xCFyi5GSL3FzbtZ3fvbjmywNogldEW0=
|
||||
modernc.org/sqlite v1.29.4 h1:mbvQTJ3Tl5Vz+wLA6z8hdBFSeNQ0XXQ+KVwn8NkUliw=
|
||||
modernc.org/sqlite v1.29.4/go.mod h1:MjUIBKZ+tU/lqjNLbVAAMjsQPdWdA/ciwdhsT9kBwk8=
|
||||
modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA=
|
||||
modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0=
|
||||
modernc.org/tcl v1.15.2 h1:C4ybAYCGJw968e+Me18oW55kD/FexcHbqH2xak1ROSY=
|
||||
modernc.org/tcl v1.15.2/go.mod h1:3+k/ZaEbKrC8ePv8zJWPtBSW0V7Gg9g8rkmhI1Kfs3c=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
|
||||
modernc.org/z v1.7.3 h1:zDJf6iHjrnB+WRD88stbXokugjyc0/pB91ri1gO6LZY=
|
||||
modernc.org/z v1.7.3/go.mod h1:Ipv4tsdxZRbQyLq9Q1M6gdbkxYzdlrciF2Hi/lS7nWE=
|
||||
mvdan.cc/xurls/v2 v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
|
||||
mvdan.cc/xurls/v2 v2.5.0/go.mod h1:yQgaGQ1rFtJUzkmKiHYSSfuQxqfYmd//X6PxvholpeE=
|
||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||
|
|
23
vendor/github.com/hashicorp/golang-lru/v2/.gitignore
generated
vendored
Normal file
23
vendor/github.com/hashicorp/golang-lru/v2/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
46
vendor/github.com/hashicorp/golang-lru/v2/.golangci.yml
generated
vendored
Normal file
46
vendor/github.com/hashicorp/golang-lru/v2/.golangci.yml
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
# Copyright (c) HashiCorp, Inc.
|
||||
# SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
linters:
|
||||
fast: false
|
||||
disable-all: true
|
||||
enable:
|
||||
- revive
|
||||
- megacheck
|
||||
- govet
|
||||
- unconvert
|
||||
- gas
|
||||
- gocyclo
|
||||
- dupl
|
||||
- misspell
|
||||
- unparam
|
||||
- unused
|
||||
- typecheck
|
||||
- ineffassign
|
||||
# - stylecheck
|
||||
- exportloopref
|
||||
- gocritic
|
||||
- nakedret
|
||||
- gosimple
|
||||
- prealloc
|
||||
|
||||
# golangci-lint configuration file
|
||||
linters-settings:
|
||||
revive:
|
||||
ignore-generated-header: true
|
||||
severity: warning
|
||||
rules:
|
||||
- name: package-comments
|
||||
severity: warning
|
||||
disabled: true
|
||||
- name: exported
|
||||
severity: warning
|
||||
disabled: false
|
||||
arguments: ["checkPrivateReceivers", "disableStutteringCheck"]
|
||||
|
||||
issues:
|
||||
exclude-use-default: false
|
||||
exclude-rules:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- dupl
|
267
vendor/github.com/hashicorp/golang-lru/v2/2q.go
generated
vendored
Normal file
267
vendor/github.com/hashicorp/golang-lru/v2/2q.go
generated
vendored
Normal file
|
@ -0,0 +1,267 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package lru
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/golang-lru/v2/simplelru"
|
||||
)
|
||||
|
||||
const (
|
||||
// Default2QRecentRatio is the ratio of the 2Q cache dedicated
|
||||
// to recently added entries that have only been accessed once.
|
||||
Default2QRecentRatio = 0.25
|
||||
|
||||
// Default2QGhostEntries is the default ratio of ghost
|
||||
// entries kept to track entries recently evicted
|
||||
Default2QGhostEntries = 0.50
|
||||
)
|
||||
|
||||
// TwoQueueCache is a thread-safe fixed size 2Q cache.
|
||||
// 2Q is an enhancement over the standard LRU cache
|
||||
// in that it tracks both frequently and recently used
|
||||
// entries separately. This avoids a burst in access to new
|
||||
// entries from evicting frequently used entries. It adds some
|
||||
// additional tracking overhead to the standard LRU cache, and is
|
||||
// computationally about 2x the cost, and adds some metadata over
|
||||
// head. The ARCCache is similar, but does not require setting any
|
||||
// parameters.
|
||||
type TwoQueueCache[K comparable, V any] struct {
|
||||
size int
|
||||
recentSize int
|
||||
recentRatio float64
|
||||
ghostRatio float64
|
||||
|
||||
recent simplelru.LRUCache[K, V]
|
||||
frequent simplelru.LRUCache[K, V]
|
||||
recentEvict simplelru.LRUCache[K, struct{}]
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// New2Q creates a new TwoQueueCache using the default
|
||||
// values for the parameters.
|
||||
func New2Q[K comparable, V any](size int) (*TwoQueueCache[K, V], error) {
|
||||
return New2QParams[K, V](size, Default2QRecentRatio, Default2QGhostEntries)
|
||||
}
|
||||
|
||||
// New2QParams creates a new TwoQueueCache using the provided
|
||||
// parameter values.
|
||||
func New2QParams[K comparable, V any](size int, recentRatio, ghostRatio float64) (*TwoQueueCache[K, V], error) {
|
||||
if size <= 0 {
|
||||
return nil, errors.New("invalid size")
|
||||
}
|
||||
if recentRatio < 0.0 || recentRatio > 1.0 {
|
||||
return nil, errors.New("invalid recent ratio")
|
||||
}
|
||||
if ghostRatio < 0.0 || ghostRatio > 1.0 {
|
||||
return nil, errors.New("invalid ghost ratio")
|
||||
}
|
||||
|
||||
// Determine the sub-sizes
|
||||
recentSize := int(float64(size) * recentRatio)
|
||||
evictSize := int(float64(size) * ghostRatio)
|
||||
|
||||
// Allocate the LRUs
|
||||
recent, err := simplelru.NewLRU[K, V](size, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
frequent, err := simplelru.NewLRU[K, V](size, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
recentEvict, err := simplelru.NewLRU[K, struct{}](evictSize, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Initialize the cache
|
||||
c := &TwoQueueCache[K, V]{
|
||||
size: size,
|
||||
recentSize: recentSize,
|
||||
recentRatio: recentRatio,
|
||||
ghostRatio: ghostRatio,
|
||||
recent: recent,
|
||||
frequent: frequent,
|
||||
recentEvict: recentEvict,
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Get looks up a key's value from the cache.
|
||||
func (c *TwoQueueCache[K, V]) Get(key K) (value V, ok bool) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
// Check if this is a frequent value
|
||||
if val, ok := c.frequent.Get(key); ok {
|
||||
return val, ok
|
||||
}
|
||||
|
||||
// If the value is contained in recent, then we
|
||||
// promote it to frequent
|
||||
if val, ok := c.recent.Peek(key); ok {
|
||||
c.recent.Remove(key)
|
||||
c.frequent.Add(key, val)
|
||||
return val, ok
|
||||
}
|
||||
|
||||
// No hit
|
||||
return
|
||||
}
|
||||
|
||||
// Add adds a value to the cache.
|
||||
func (c *TwoQueueCache[K, V]) Add(key K, value V) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
// Check if the value is frequently used already,
|
||||
// and just update the value
|
||||
if c.frequent.Contains(key) {
|
||||
c.frequent.Add(key, value)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the value is recently used, and promote
|
||||
// the value into the frequent list
|
||||
if c.recent.Contains(key) {
|
||||
c.recent.Remove(key)
|
||||
c.frequent.Add(key, value)
|
||||
return
|
||||
}
|
||||
|
||||
// If the value was recently evicted, add it to the
|
||||
// frequently used list
|
||||
if c.recentEvict.Contains(key) {
|
||||
c.ensureSpace(true)
|
||||
c.recentEvict.Remove(key)
|
||||
c.frequent.Add(key, value)
|
||||
return
|
||||
}
|
||||
|
||||
// Add to the recently seen list
|
||||
c.ensureSpace(false)
|
||||
c.recent.Add(key, value)
|
||||
}
|
||||
|
||||
// ensureSpace is used to ensure we have space in the cache
|
||||
func (c *TwoQueueCache[K, V]) ensureSpace(recentEvict bool) {
|
||||
// If we have space, nothing to do
|
||||
recentLen := c.recent.Len()
|
||||
freqLen := c.frequent.Len()
|
||||
if recentLen+freqLen < c.size {
|
||||
return
|
||||
}
|
||||
|
||||
// If the recent buffer is larger than
|
||||
// the target, evict from there
|
||||
if recentLen > 0 && (recentLen > c.recentSize || (recentLen == c.recentSize && !recentEvict)) {
|
||||
k, _, _ := c.recent.RemoveOldest()
|
||||
c.recentEvict.Add(k, struct{}{})
|
||||
return
|
||||
}
|
||||
|
||||
// Remove from the frequent list otherwise
|
||||
c.frequent.RemoveOldest()
|
||||
}
|
||||
|
||||
// Len returns the number of items in the cache.
|
||||
func (c *TwoQueueCache[K, V]) Len() int {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
return c.recent.Len() + c.frequent.Len()
|
||||
}
|
||||
|
||||
// Resize changes the cache size.
|
||||
func (c *TwoQueueCache[K, V]) Resize(size int) (evicted int) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
|
||||
// Recalculate the sub-sizes
|
||||
recentSize := int(float64(size) * c.recentRatio)
|
||||
evictSize := int(float64(size) * c.ghostRatio)
|
||||
c.size = size
|
||||
c.recentSize = recentSize
|
||||
|
||||
// ensureSpace
|
||||
diff := c.recent.Len() + c.frequent.Len() - size
|
||||
if diff < 0 {
|
||||
diff = 0
|
||||
}
|
||||
for i := 0; i < diff; i++ {
|
||||
c.ensureSpace(true)
|
||||
}
|
||||
|
||||
// Reallocate the LRUs
|
||||
c.recent.Resize(size)
|
||||
c.frequent.Resize(size)
|
||||
c.recentEvict.Resize(evictSize)
|
||||
|
||||
return diff
|
||||
}
|
||||
|
||||
// Keys returns a slice of the keys in the cache.
|
||||
// The frequently used keys are first in the returned slice.
|
||||
func (c *TwoQueueCache[K, V]) Keys() []K {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
k1 := c.frequent.Keys()
|
||||
k2 := c.recent.Keys()
|
||||
return append(k1, k2...)
|
||||
}
|
||||
|
||||
// Values returns a slice of the values in the cache.
|
||||
// The frequently used values are first in the returned slice.
|
||||
func (c *TwoQueueCache[K, V]) Values() []V {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
v1 := c.frequent.Values()
|
||||
v2 := c.recent.Values()
|
||||
return append(v1, v2...)
|
||||
}
|
||||
|
||||
// Remove removes the provided key from the cache.
|
||||
func (c *TwoQueueCache[K, V]) Remove(key K) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
if c.frequent.Remove(key) {
|
||||
return
|
||||
}
|
||||
if c.recent.Remove(key) {
|
||||
return
|
||||
}
|
||||
if c.recentEvict.Remove(key) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Purge is used to completely clear the cache.
|
||||
func (c *TwoQueueCache[K, V]) Purge() {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
c.recent.Purge()
|
||||
c.frequent.Purge()
|
||||
c.recentEvict.Purge()
|
||||
}
|
||||
|
||||
// Contains is used to check if the cache contains a key
|
||||
// without updating recency or frequency.
|
||||
func (c *TwoQueueCache[K, V]) Contains(key K) bool {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
return c.frequent.Contains(key) || c.recent.Contains(key)
|
||||
}
|
||||
|
||||
// Peek is used to inspect the cache value of a key
|
||||
// without updating recency or frequency.
|
||||
func (c *TwoQueueCache[K, V]) Peek(key K) (value V, ok bool) {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
if val, ok := c.frequent.Peek(key); ok {
|
||||
return val, ok
|
||||
}
|
||||
return c.recent.Peek(key)
|
||||
}
|
364
vendor/github.com/hashicorp/golang-lru/v2/LICENSE
generated
vendored
Normal file
364
vendor/github.com/hashicorp/golang-lru/v2/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,364 @@
|
|||
Copyright (c) 2014 HashiCorp, Inc.
|
||||
|
||||
Mozilla Public License, version 2.0
|
||||
|
||||
1. Definitions
|
||||
|
||||
1.1. "Contributor"
|
||||
|
||||
means each individual or legal entity that creates, contributes to the
|
||||
creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
|
||||
means the combination of the Contributions of others (if any) used by a
|
||||
Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
|
||||
means Source Code Form to which the initial Contributor has attached the
|
||||
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
||||
Modifications of such Source Code Form, in each case including portions
|
||||
thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
a. that the initial Contributor has attached the notice described in
|
||||
Exhibit B to the Covered Software; or
|
||||
|
||||
b. that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the terms of
|
||||
a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
|
||||
means a work that combines Covered Software with other material, in a
|
||||
separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
|
||||
means having the right to grant, to the maximum extent possible, whether
|
||||
at the time of the initial grant or subsequently, any and all of the
|
||||
rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
|
||||
means any of the following:
|
||||
|
||||
a. any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered Software; or
|
||||
|
||||
b. any new file in Source Code Form that contains any Covered Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the License,
|
||||
by the making, using, selling, offering for sale, having made, import,
|
||||
or transfer of either its Contributions or its Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
|
||||
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
||||
General Public License, Version 2.1, the GNU Affero General Public
|
||||
License, Version 3.0, or any later versions of those licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that controls, is
|
||||
controlled by, or is under common control with You. For purposes of this
|
||||
definition, "control" means (a) the power, direct or indirect, to cause
|
||||
the direction or management of such entity, whether by contract or
|
||||
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
||||
outstanding shares or beneficial ownership of such entity.
|
||||
|
||||
|
||||
2. License Grants and Conditions
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
a. under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
||||
sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
a. for any code that a Contributor has removed from Covered Software; or
|
||||
|
||||
b. for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
c. under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights to
|
||||
grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
||||
Section 2.1.
|
||||
|
||||
|
||||
3. Responsibilities
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
a. such Covered Software must also be made available in Source Code Form,
|
||||
as described in Section 3.1, and You must inform recipients of the
|
||||
Executable Form how they can obtain a copy of such Source Code Form by
|
||||
reasonable means in a timely manner, at a charge no more than the cost
|
||||
of distribution to the recipient; and
|
||||
|
||||
b. You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter the
|
||||
recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty, or
|
||||
limitations of liability) contained within the Source Code Form of the
|
||||
Covered Software, except that You may alter any license notices to the
|
||||
extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this License
|
||||
with respect to some or all of the Covered Software due to statute,
|
||||
judicial order, or regulation then You must: (a) comply with the terms of
|
||||
this License to the maximum extent possible; and (b) describe the
|
||||
limitations and the code they affect. Such description must be placed in a
|
||||
text file included with all distributions of the Covered Software under
|
||||
this License. Except to the extent prohibited by statute or regulation,
|
||||
such description must be sufficiently detailed for a recipient of ordinary
|
||||
skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically if You
|
||||
fail to comply with any of its terms. However, if You become compliant,
|
||||
then the rights granted under this License from a particular Contributor
|
||||
are reinstated (a) provisionally, unless and until such Contributor
|
||||
explicitly and finally terminates Your grants, and (b) on an ongoing
|
||||
basis, if such Contributor fails to notify You of the non-compliance by
|
||||
some reasonable means prior to 60 days after You have come back into
|
||||
compliance. Moreover, Your grants from a particular Contributor are
|
||||
reinstated on an ongoing basis if such Contributor notifies You of the
|
||||
non-compliance by some reasonable means, this is the first time You have
|
||||
received notice of non-compliance with this License from such
|
||||
Contributor, and You become compliant prior to 30 days after Your receipt
|
||||
of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
||||
license agreements (excluding distributors and resellers) which have been
|
||||
validly granted by You or Your distributors under this License prior to
|
||||
termination shall survive termination.
|
||||
|
||||
6. Disclaimer of Warranty
|
||||
|
||||
Covered Software is provided under this License on an "as is" basis,
|
||||
without warranty of any kind, either expressed, implied, or statutory,
|
||||
including, without limitation, warranties that the Covered Software is free
|
||||
of defects, merchantable, fit for a particular purpose or non-infringing.
|
||||
The entire risk as to the quality and performance of the Covered Software
|
||||
is with You. Should any Covered Software prove defective in any respect,
|
||||
You (not any Contributor) assume the cost of any necessary servicing,
|
||||
repair, or correction. This disclaimer of warranty constitutes an essential
|
||||
part of this License. No use of any Covered Software is authorized under
|
||||
this License except under this disclaimer.
|
||||
|
||||
7. Limitation of Liability
|
||||
|
||||
Under no circumstances and under no legal theory, whether tort (including
|
||||
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
||||
distributes Covered Software as permitted above, be liable to You for any
|
||||
direct, indirect, special, incidental, or consequential damages of any
|
||||
character including, without limitation, damages for lost profits, loss of
|
||||
goodwill, work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses, even if such party shall have been
|
||||
informed of the possibility of such damages. This limitation of liability
|
||||
shall not apply to liability for death or personal injury resulting from
|
||||
such party's negligence to the extent applicable law prohibits such
|
||||
limitation. Some jurisdictions do not allow the exclusion or limitation of
|
||||
incidental or consequential damages, so this exclusion and limitation may
|
||||
not apply to You.
|
||||
|
||||
8. Litigation
|
||||
|
||||
Any litigation relating to this License may be brought only in the courts
|
||||
of a jurisdiction where the defendant maintains its principal place of
|
||||
business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions. Nothing
|
||||
in this Section shall prevent a party's ability to bring cross-claims or
|
||||
counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides that
|
||||
the language of a contract shall be construed against the drafter shall not
|
||||
be used to construe this License against a Contributor.
|
||||
|
||||
|
||||
10. Versions of the License
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses If You choose to distribute Source Code Form that is
|
||||
Incompatible With Secondary Licenses under the terms of this version of
|
||||
the License, the notice described in Exhibit B of this License must be
|
||||
attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file,
|
||||
then You may include the notice in a location (such as a LICENSE file in a
|
||||
relevant directory) where a recipient would be likely to look for such a
|
||||
notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
|
||||
This Source Code Form is "Incompatible
|
||||
With Secondary Licenses", as defined by
|
||||
the Mozilla Public License, v. 2.0.
|
79
vendor/github.com/hashicorp/golang-lru/v2/README.md
generated
vendored
Normal file
79
vendor/github.com/hashicorp/golang-lru/v2/README.md
generated
vendored
Normal file
|
@ -0,0 +1,79 @@
|
|||
golang-lru
|
||||
==========
|
||||
|
||||
This provides the `lru` package which implements a fixed-size
|
||||
thread safe LRU cache. It is based on the cache in Groupcache.
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
Full docs are available on [Go Packages](https://pkg.go.dev/github.com/hashicorp/golang-lru/v2)
|
||||
|
||||
LRU cache example
|
||||
=================
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
l, _ := lru.New[int, any](128)
|
||||
for i := 0; i < 256; i++ {
|
||||
l.Add(i, nil)
|
||||
}
|
||||
if l.Len() != 128 {
|
||||
panic(fmt.Sprintf("bad len: %v", l.Len()))
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Expirable LRU cache example
|
||||
===========================
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/golang-lru/v2/expirable"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// make cache with 10ms TTL and 5 max keys
|
||||
cache := expirable.NewLRU[string, string](5, nil, time.Millisecond*10)
|
||||
|
||||
|
||||
// set value under key1.
|
||||
cache.Add("key1", "val1")
|
||||
|
||||
// get value under key1
|
||||
r, ok := cache.Get("key1")
|
||||
|
||||
// check for OK value
|
||||
if ok {
|
||||
fmt.Printf("value before expiration is found: %v, value: %q\n", ok, r)
|
||||
}
|
||||
|
||||
// wait for cache to expire
|
||||
time.Sleep(time.Millisecond * 12)
|
||||
|
||||
// get value under key1 after key expiration
|
||||
r, ok = cache.Get("key1")
|
||||
fmt.Printf("value after expiration is found: %v, value: %q\n", ok, r)
|
||||
|
||||
// set value under key2, would evict old entry because it is already expired.
|
||||
cache.Add("key2", "val2")
|
||||
|
||||
fmt.Printf("Cache len: %d\n", cache.Len())
|
||||
// Output:
|
||||
// value before expiration is found: true, value: "val1"
|
||||
// value after expiration is found: false, value: ""
|
||||
// Cache len: 1
|
||||
}
|
||||
```
|
24
vendor/github.com/hashicorp/golang-lru/v2/doc.go
generated
vendored
Normal file
24
vendor/github.com/hashicorp/golang-lru/v2/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
// Package lru provides three different LRU caches of varying sophistication.
|
||||
//
|
||||
// Cache is a simple LRU cache. It is based on the LRU implementation in
|
||||
// groupcache: https://github.com/golang/groupcache/tree/master/lru
|
||||
//
|
||||
// TwoQueueCache tracks frequently used and recently used entries separately.
|
||||
// This avoids a burst of accesses from taking out frequently used entries, at
|
||||
// the cost of about 2x computational overhead and some extra bookkeeping.
|
||||
//
|
||||
// ARCCache is an adaptive replacement cache. It tracks recent evictions as well
|
||||
// as recent usage in both the frequent and recent caches. Its computational
|
||||
// overhead is comparable to TwoQueueCache, but the memory overhead is linear
|
||||
// with the size of the cache.
|
||||
//
|
||||
// ARC has been patented by IBM, so do not use it if that is problematic for
|
||||
// your program. For this reason, it is in a separate go module contained within
|
||||
// this repository.
|
||||
//
|
||||
// All caches in this package take locks while operating, and are therefore
|
||||
// thread-safe for consumers.
|
||||
package lru
|
142
vendor/github.com/hashicorp/golang-lru/v2/internal/list.go
generated
vendored
Normal file
142
vendor/github.com/hashicorp/golang-lru/v2/internal/list.go
generated
vendored
Normal file
|
@ -0,0 +1,142 @@
|
|||
// Copyright 2009 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_list file.
|
||||
|
||||
package internal
|
||||
|
||||
import "time"
|
||||
|
||||
// Entry is an LRU Entry
|
||||
type Entry[K comparable, V any] struct {
|
||||
// Next and previous pointers in the doubly-linked list of elements.
|
||||
// To simplify the implementation, internally a list l is implemented
|
||||
// as a ring, such that &l.root is both the next element of the last
|
||||
// list element (l.Back()) and the previous element of the first list
|
||||
// element (l.Front()).
|
||||
next, prev *Entry[K, V]
|
||||
|
||||
// The list to which this element belongs.
|
||||
list *LruList[K, V]
|
||||
|
||||
// The LRU Key of this element.
|
||||
Key K
|
||||
|
||||
// The Value stored with this element.
|
||||
Value V
|
||||
|
||||
// The time this element would be cleaned up, optional
|
||||
ExpiresAt time.Time
|
||||
|
||||
// The expiry bucket item was put in, optional
|
||||
ExpireBucket uint8
|
||||
}
|
||||
|
||||
// PrevEntry returns the previous list element or nil.
|
||||
func (e *Entry[K, V]) PrevEntry() *Entry[K, V] {
|
||||
if p := e.prev; e.list != nil && p != &e.list.root {
|
||||
return p
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LruList represents a doubly linked list.
|
||||
// The zero Value for LruList is an empty list ready to use.
|
||||
type LruList[K comparable, V any] struct {
|
||||
root Entry[K, V] // sentinel list element, only &root, root.prev, and root.next are used
|
||||
len int // current list Length excluding (this) sentinel element
|
||||
}
|
||||
|
||||
// Init initializes or clears list l.
|
||||
func (l *LruList[K, V]) Init() *LruList[K, V] {
|
||||
l.root.next = &l.root
|
||||
l.root.prev = &l.root
|
||||
l.len = 0
|
||||
return l
|
||||
}
|
||||
|
||||
// NewList returns an initialized list.
|
||||
func NewList[K comparable, V any]() *LruList[K, V] { return new(LruList[K, V]).Init() }
|
||||
|
||||
// Length returns the number of elements of list l.
|
||||
// The complexity is O(1).
|
||||
func (l *LruList[K, V]) Length() int { return l.len }
|
||||
|
||||
// Back returns the last element of list l or nil if the list is empty.
|
||||
func (l *LruList[K, V]) Back() *Entry[K, V] {
|
||||
if l.len == 0 {
|
||||
return nil
|
||||
}
|
||||
return l.root.prev
|
||||
}
|
||||
|
||||
// lazyInit lazily initializes a zero List Value.
|
||||
func (l *LruList[K, V]) lazyInit() {
|
||||
if l.root.next == nil {
|
||||
l.Init()
|
||||
}
|
||||
}
|
||||
|
||||
// insert inserts e after at, increments l.len, and returns e.
|
||||
func (l *LruList[K, V]) insert(e, at *Entry[K, V]) *Entry[K, V] {
|
||||
e.prev = at
|
||||
e.next = at.next
|
||||
e.prev.next = e
|
||||
e.next.prev = e
|
||||
e.list = l
|
||||
l.len++
|
||||
return e
|
||||
}
|
||||
|
||||
// insertValue is a convenience wrapper for insert(&Entry{Value: v, ExpiresAt: ExpiresAt}, at).
|
||||
func (l *LruList[K, V]) insertValue(k K, v V, expiresAt time.Time, at *Entry[K, V]) *Entry[K, V] {
|
||||
return l.insert(&Entry[K, V]{Value: v, Key: k, ExpiresAt: expiresAt}, at)
|
||||
}
|
||||
|
||||
// Remove removes e from its list, decrements l.len
|
||||
func (l *LruList[K, V]) Remove(e *Entry[K, V]) V {
|
||||
e.prev.next = e.next
|
||||
e.next.prev = e.prev
|
||||
e.next = nil // avoid memory leaks
|
||||
e.prev = nil // avoid memory leaks
|
||||
e.list = nil
|
||||
l.len--
|
||||
|
||||
return e.Value
|
||||
}
|
||||
|
||||
// move moves e to next to at.
|
||||
func (l *LruList[K, V]) move(e, at *Entry[K, V]) {
|
||||
if e == at {
|
||||
return
|
||||
}
|
||||
e.prev.next = e.next
|
||||
e.next.prev = e.prev
|
||||
|
||||
e.prev = at
|
||||
e.next = at.next
|
||||
e.prev.next = e
|
||||
e.next.prev = e
|
||||
}
|
||||
|
||||
// PushFront inserts a new element e with value v at the front of list l and returns e.
|
||||
func (l *LruList[K, V]) PushFront(k K, v V) *Entry[K, V] {
|
||||
l.lazyInit()
|
||||
return l.insertValue(k, v, time.Time{}, &l.root)
|
||||
}
|
||||
|
||||
// PushFrontExpirable inserts a new expirable element e with Value v at the front of list l and returns e.
|
||||
func (l *LruList[K, V]) PushFrontExpirable(k K, v V, expiresAt time.Time) *Entry[K, V] {
|
||||
l.lazyInit()
|
||||
return l.insertValue(k, v, expiresAt, &l.root)
|
||||
}
|
||||
|
||||
// MoveToFront moves element e to the front of list l.
|
||||
// If e is not an element of l, the list is not modified.
|
||||
// The element must not be nil.
|
||||
func (l *LruList[K, V]) MoveToFront(e *Entry[K, V]) {
|
||||
if e.list != l || l.root.next == e {
|
||||
return
|
||||
}
|
||||
// see comment in List.Remove about initialization of l
|
||||
l.move(e, &l.root)
|
||||
}
|
250
vendor/github.com/hashicorp/golang-lru/v2/lru.go
generated
vendored
Normal file
250
vendor/github.com/hashicorp/golang-lru/v2/lru.go
generated
vendored
Normal file
|
@ -0,0 +1,250 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package lru
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/golang-lru/v2/simplelru"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultEvictedBufferSize defines the default buffer size to store evicted key/val
|
||||
DefaultEvictedBufferSize = 16
|
||||
)
|
||||
|
||||
// Cache is a thread-safe fixed size LRU cache.
|
||||
type Cache[K comparable, V any] struct {
|
||||
lru *simplelru.LRU[K, V]
|
||||
evictedKeys []K
|
||||
evictedVals []V
|
||||
onEvictedCB func(k K, v V)
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
// New creates an LRU of the given size.
|
||||
func New[K comparable, V any](size int) (*Cache[K, V], error) {
|
||||
return NewWithEvict[K, V](size, nil)
|
||||
}
|
||||
|
||||
// NewWithEvict constructs a fixed size cache with the given eviction
|
||||
// callback.
|
||||
func NewWithEvict[K comparable, V any](size int, onEvicted func(key K, value V)) (c *Cache[K, V], err error) {
|
||||
// create a cache with default settings
|
||||
c = &Cache[K, V]{
|
||||
onEvictedCB: onEvicted,
|
||||
}
|
||||
if onEvicted != nil {
|
||||
c.initEvictBuffers()
|
||||
onEvicted = c.onEvicted
|
||||
}
|
||||
c.lru, err = simplelru.NewLRU(size, onEvicted)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Cache[K, V]) initEvictBuffers() {
|
||||
c.evictedKeys = make([]K, 0, DefaultEvictedBufferSize)
|
||||
c.evictedVals = make([]V, 0, DefaultEvictedBufferSize)
|
||||
}
|
||||
|
||||
// onEvicted save evicted key/val and sent in externally registered callback
|
||||
// outside of critical section
|
||||
func (c *Cache[K, V]) onEvicted(k K, v V) {
|
||||
c.evictedKeys = append(c.evictedKeys, k)
|
||||
c.evictedVals = append(c.evictedVals, v)
|
||||
}
|
||||
|
||||
// Purge is used to completely clear the cache.
|
||||
func (c *Cache[K, V]) Purge() {
|
||||
var ks []K
|
||||
var vs []V
|
||||
c.lock.Lock()
|
||||
c.lru.Purge()
|
||||
if c.onEvictedCB != nil && len(c.evictedKeys) > 0 {
|
||||
ks, vs = c.evictedKeys, c.evictedVals
|
||||
c.initEvictBuffers()
|
||||
}
|
||||
c.lock.Unlock()
|
||||
// invoke callback outside of critical section
|
||||
if c.onEvictedCB != nil {
|
||||
for i := 0; i < len(ks); i++ {
|
||||
c.onEvictedCB(ks[i], vs[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds a value to the cache. Returns true if an eviction occurred.
|
||||
func (c *Cache[K, V]) Add(key K, value V) (evicted bool) {
|
||||
var k K
|
||||
var v V
|
||||
c.lock.Lock()
|
||||
evicted = c.lru.Add(key, value)
|
||||
if c.onEvictedCB != nil && evicted {
|
||||
k, v = c.evictedKeys[0], c.evictedVals[0]
|
||||
c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0]
|
||||
}
|
||||
c.lock.Unlock()
|
||||
if c.onEvictedCB != nil && evicted {
|
||||
c.onEvictedCB(k, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Get looks up a key's value from the cache.
|
||||
func (c *Cache[K, V]) Get(key K) (value V, ok bool) {
|
||||
c.lock.Lock()
|
||||
value, ok = c.lru.Get(key)
|
||||
c.lock.Unlock()
|
||||
return value, ok
|
||||
}
|
||||
|
||||
// Contains checks if a key is in the cache, without updating the
|
||||
// recent-ness or deleting it for being stale.
|
||||
func (c *Cache[K, V]) Contains(key K) bool {
|
||||
c.lock.RLock()
|
||||
containKey := c.lru.Contains(key)
|
||||
c.lock.RUnlock()
|
||||
return containKey
|
||||
}
|
||||
|
||||
// Peek returns the key value (or undefined if not found) without updating
|
||||
// the "recently used"-ness of the key.
|
||||
func (c *Cache[K, V]) Peek(key K) (value V, ok bool) {
|
||||
c.lock.RLock()
|
||||
value, ok = c.lru.Peek(key)
|
||||
c.lock.RUnlock()
|
||||
return value, ok
|
||||
}
|
||||
|
||||
// ContainsOrAdd checks if a key is in the cache without updating the
|
||||
// recent-ness or deleting it for being stale, and if not, adds the value.
|
||||
// Returns whether found and whether an eviction occurred.
|
||||
func (c *Cache[K, V]) ContainsOrAdd(key K, value V) (ok, evicted bool) {
|
||||
var k K
|
||||
var v V
|
||||
c.lock.Lock()
|
||||
if c.lru.Contains(key) {
|
||||
c.lock.Unlock()
|
||||
return true, false
|
||||
}
|
||||
evicted = c.lru.Add(key, value)
|
||||
if c.onEvictedCB != nil && evicted {
|
||||
k, v = c.evictedKeys[0], c.evictedVals[0]
|
||||
c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0]
|
||||
}
|
||||
c.lock.Unlock()
|
||||
if c.onEvictedCB != nil && evicted {
|
||||
c.onEvictedCB(k, v)
|
||||
}
|
||||
return false, evicted
|
||||
}
|
||||
|
||||
// PeekOrAdd checks if a key is in the cache without updating the
|
||||
// recent-ness or deleting it for being stale, and if not, adds the value.
|
||||
// Returns whether found and whether an eviction occurred.
|
||||
func (c *Cache[K, V]) PeekOrAdd(key K, value V) (previous V, ok, evicted bool) {
|
||||
var k K
|
||||
var v V
|
||||
c.lock.Lock()
|
||||
previous, ok = c.lru.Peek(key)
|
||||
if ok {
|
||||
c.lock.Unlock()
|
||||
return previous, true, false
|
||||
}
|
||||
evicted = c.lru.Add(key, value)
|
||||
if c.onEvictedCB != nil && evicted {
|
||||
k, v = c.evictedKeys[0], c.evictedVals[0]
|
||||
c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0]
|
||||
}
|
||||
c.lock.Unlock()
|
||||
if c.onEvictedCB != nil && evicted {
|
||||
c.onEvictedCB(k, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Remove removes the provided key from the cache.
|
||||
func (c *Cache[K, V]) Remove(key K) (present bool) {
|
||||
var k K
|
||||
var v V
|
||||
c.lock.Lock()
|
||||
present = c.lru.Remove(key)
|
||||
if c.onEvictedCB != nil && present {
|
||||
k, v = c.evictedKeys[0], c.evictedVals[0]
|
||||
c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0]
|
||||
}
|
||||
c.lock.Unlock()
|
||||
if c.onEvictedCB != nil && present {
|
||||
c.onEvictedCB(k, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Resize changes the cache size.
|
||||
func (c *Cache[K, V]) Resize(size int) (evicted int) {
|
||||
var ks []K
|
||||
var vs []V
|
||||
c.lock.Lock()
|
||||
evicted = c.lru.Resize(size)
|
||||
if c.onEvictedCB != nil && evicted > 0 {
|
||||
ks, vs = c.evictedKeys, c.evictedVals
|
||||
c.initEvictBuffers()
|
||||
}
|
||||
c.lock.Unlock()
|
||||
if c.onEvictedCB != nil && evicted > 0 {
|
||||
for i := 0; i < len(ks); i++ {
|
||||
c.onEvictedCB(ks[i], vs[i])
|
||||
}
|
||||
}
|
||||
return evicted
|
||||
}
|
||||
|
||||
// RemoveOldest removes the oldest item from the cache.
|
||||
func (c *Cache[K, V]) RemoveOldest() (key K, value V, ok bool) {
|
||||
var k K
|
||||
var v V
|
||||
c.lock.Lock()
|
||||
key, value, ok = c.lru.RemoveOldest()
|
||||
if c.onEvictedCB != nil && ok {
|
||||
k, v = c.evictedKeys[0], c.evictedVals[0]
|
||||
c.evictedKeys, c.evictedVals = c.evictedKeys[:0], c.evictedVals[:0]
|
||||
}
|
||||
c.lock.Unlock()
|
||||
if c.onEvictedCB != nil && ok {
|
||||
c.onEvictedCB(k, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetOldest returns the oldest entry
|
||||
func (c *Cache[K, V]) GetOldest() (key K, value V, ok bool) {
|
||||
c.lock.RLock()
|
||||
key, value, ok = c.lru.GetOldest()
|
||||
c.lock.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// Keys returns a slice of the keys in the cache, from oldest to newest.
|
||||
func (c *Cache[K, V]) Keys() []K {
|
||||
c.lock.RLock()
|
||||
keys := c.lru.Keys()
|
||||
c.lock.RUnlock()
|
||||
return keys
|
||||
}
|
||||
|
||||
// Values returns a slice of the values in the cache, from oldest to newest.
|
||||
func (c *Cache[K, V]) Values() []V {
|
||||
c.lock.RLock()
|
||||
values := c.lru.Values()
|
||||
c.lock.RUnlock()
|
||||
return values
|
||||
}
|
||||
|
||||
// Len returns the number of items in the cache.
|
||||
func (c *Cache[K, V]) Len() int {
|
||||
c.lock.RLock()
|
||||
length := c.lru.Len()
|
||||
c.lock.RUnlock()
|
||||
return length
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
Copyright (c) 2017 The CC Authors. All rights reserved.
|
||||
This license applies to simplelru/list.go
|
||||
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
|
@ -10,7 +12,7 @@ notice, this list of conditions and the following disclaimer.
|
|||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the names of the authors nor the names of the
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
177
vendor/github.com/hashicorp/golang-lru/v2/simplelru/lru.go
generated
vendored
Normal file
177
vendor/github.com/hashicorp/golang-lru/v2/simplelru/lru.go
generated
vendored
Normal file
|
@ -0,0 +1,177 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
package simplelru
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/hashicorp/golang-lru/v2/internal"
|
||||
)
|
||||
|
||||
// EvictCallback is used to get a callback when a cache entry is evicted
|
||||
type EvictCallback[K comparable, V any] func(key K, value V)
|
||||
|
||||
// LRU implements a non-thread safe fixed size LRU cache
|
||||
type LRU[K comparable, V any] struct {
|
||||
size int
|
||||
evictList *internal.LruList[K, V]
|
||||
items map[K]*internal.Entry[K, V]
|
||||
onEvict EvictCallback[K, V]
|
||||
}
|
||||
|
||||
// NewLRU constructs an LRU of the given size
|
||||
func NewLRU[K comparable, V any](size int, onEvict EvictCallback[K, V]) (*LRU[K, V], error) {
|
||||
if size <= 0 {
|
||||
return nil, errors.New("must provide a positive size")
|
||||
}
|
||||
|
||||
c := &LRU[K, V]{
|
||||
size: size,
|
||||
evictList: internal.NewList[K, V](),
|
||||
items: make(map[K]*internal.Entry[K, V]),
|
||||
onEvict: onEvict,
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Purge is used to completely clear the cache.
|
||||
func (c *LRU[K, V]) Purge() {
|
||||
for k, v := range c.items {
|
||||
if c.onEvict != nil {
|
||||
c.onEvict(k, v.Value)
|
||||
}
|
||||
delete(c.items, k)
|
||||
}
|
||||
c.evictList.Init()
|
||||
}
|
||||
|
||||
// Add adds a value to the cache. Returns true if an eviction occurred.
|
||||
func (c *LRU[K, V]) Add(key K, value V) (evicted bool) {
|
||||
// Check for existing item
|
||||
if ent, ok := c.items[key]; ok {
|
||||
c.evictList.MoveToFront(ent)
|
||||
ent.Value = value
|
||||
return false
|
||||
}
|
||||
|
||||
// Add new item
|
||||
ent := c.evictList.PushFront(key, value)
|
||||
c.items[key] = ent
|
||||
|
||||
evict := c.evictList.Length() > c.size
|
||||
// Verify size not exceeded
|
||||
if evict {
|
||||
c.removeOldest()
|
||||
}
|
||||
return evict
|
||||
}
|
||||
|
||||
// Get looks up a key's value from the cache.
|
||||
func (c *LRU[K, V]) Get(key K) (value V, ok bool) {
|
||||
if ent, ok := c.items[key]; ok {
|
||||
c.evictList.MoveToFront(ent)
|
||||
return ent.Value, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Contains checks if a key is in the cache, without updating the recent-ness
|
||||
// or deleting it for being stale.
|
||||
func (c *LRU[K, V]) Contains(key K) (ok bool) {
|
||||
_, ok = c.items[key]
|
||||
return ok
|
||||
}
|
||||
|
||||
// Peek returns the key value (or undefined if not found) without updating
|
||||
// the "recently used"-ness of the key.
|
||||
func (c *LRU[K, V]) Peek(key K) (value V, ok bool) {
|
||||
var ent *internal.Entry[K, V]
|
||||
if ent, ok = c.items[key]; ok {
|
||||
return ent.Value, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Remove removes the provided key from the cache, returning if the
|
||||
// key was contained.
|
||||
func (c *LRU[K, V]) Remove(key K) (present bool) {
|
||||
if ent, ok := c.items[key]; ok {
|
||||
c.removeElement(ent)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RemoveOldest removes the oldest item from the cache.
|
||||
func (c *LRU[K, V]) RemoveOldest() (key K, value V, ok bool) {
|
||||
if ent := c.evictList.Back(); ent != nil {
|
||||
c.removeElement(ent)
|
||||
return ent.Key, ent.Value, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetOldest returns the oldest entry
|
||||
func (c *LRU[K, V]) GetOldest() (key K, value V, ok bool) {
|
||||
if ent := c.evictList.Back(); ent != nil {
|
||||
return ent.Key, ent.Value, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Keys returns a slice of the keys in the cache, from oldest to newest.
|
||||
func (c *LRU[K, V]) Keys() []K {
|
||||
keys := make([]K, c.evictList.Length())
|
||||
i := 0
|
||||
for ent := c.evictList.Back(); ent != nil; ent = ent.PrevEntry() {
|
||||
keys[i] = ent.Key
|
||||
i++
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
// Values returns a slice of the values in the cache, from oldest to newest.
|
||||
func (c *LRU[K, V]) Values() []V {
|
||||
values := make([]V, len(c.items))
|
||||
i := 0
|
||||
for ent := c.evictList.Back(); ent != nil; ent = ent.PrevEntry() {
|
||||
values[i] = ent.Value
|
||||
i++
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
// Len returns the number of items in the cache.
|
||||
func (c *LRU[K, V]) Len() int {
|
||||
return c.evictList.Length()
|
||||
}
|
||||
|
||||
// Resize changes the cache size.
|
||||
func (c *LRU[K, V]) Resize(size int) (evicted int) {
|
||||
diff := c.Len() - size
|
||||
if diff < 0 {
|
||||
diff = 0
|
||||
}
|
||||
for i := 0; i < diff; i++ {
|
||||
c.removeOldest()
|
||||
}
|
||||
c.size = size
|
||||
return diff
|
||||
}
|
||||
|
||||
// removeOldest removes the oldest item from the cache.
|
||||
func (c *LRU[K, V]) removeOldest() {
|
||||
if ent := c.evictList.Back(); ent != nil {
|
||||
c.removeElement(ent)
|
||||
}
|
||||
}
|
||||
|
||||
// removeElement is used to remove a given list element from the cache
|
||||
func (c *LRU[K, V]) removeElement(e *internal.Entry[K, V]) {
|
||||
c.evictList.Remove(e)
|
||||
delete(c.items, e.Key)
|
||||
if c.onEvict != nil {
|
||||
c.onEvict(e.Key, e.Value)
|
||||
}
|
||||
}
|
46
vendor/github.com/hashicorp/golang-lru/v2/simplelru/lru_interface.go
generated
vendored
Normal file
46
vendor/github.com/hashicorp/golang-lru/v2/simplelru/lru_interface.go
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
// Package simplelru provides simple LRU implementation based on build-in container/list.
|
||||
package simplelru
|
||||
|
||||
// LRUCache is the interface for simple LRU cache.
|
||||
type LRUCache[K comparable, V any] interface {
|
||||
// Adds a value to the cache, returns true if an eviction occurred and
|
||||
// updates the "recently used"-ness of the key.
|
||||
Add(key K, value V) bool
|
||||
|
||||
// Returns key's value from the cache and
|
||||
// updates the "recently used"-ness of the key. #value, isFound
|
||||
Get(key K) (value V, ok bool)
|
||||
|
||||
// Checks if a key exists in cache without updating the recent-ness.
|
||||
Contains(key K) (ok bool)
|
||||
|
||||
// Returns key's value without updating the "recently used"-ness of the key.
|
||||
Peek(key K) (value V, ok bool)
|
||||
|
||||
// Removes a key from the cache.
|
||||
Remove(key K) bool
|
||||
|
||||
// Removes the oldest entry from cache.
|
||||
RemoveOldest() (K, V, bool)
|
||||
|
||||
// Returns the oldest entry from the cache. #key, value, isFound
|
||||
GetOldest() (K, V, bool)
|
||||
|
||||
// Returns a slice of the keys in the cache, from oldest to newest.
|
||||
Keys() []K
|
||||
|
||||
// Values returns a slice of the values in the cache, from oldest to newest.
|
||||
Values() []V
|
||||
|
||||
// Returns the number of items in the cache.
|
||||
Len() int
|
||||
|
||||
// Clears all cache entries.
|
||||
Purge()
|
||||
|
||||
// Resizes cache, returning number evicted
|
||||
Resize(int) int
|
||||
}
|
19
vendor/github.com/kballard/go-shellquote/LICENSE
generated
vendored
19
vendor/github.com/kballard/go-shellquote/LICENSE
generated
vendored
|
@ -1,19 +0,0 @@
|
|||
Copyright (C) 2014 Kevin Ballard
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
36
vendor/github.com/kballard/go-shellquote/README
generated
vendored
36
vendor/github.com/kballard/go-shellquote/README
generated
vendored
|
@ -1,36 +0,0 @@
|
|||
PACKAGE
|
||||
|
||||
package shellquote
|
||||
import "github.com/kballard/go-shellquote"
|
||||
|
||||
Shellquote provides utilities for joining/splitting strings using sh's
|
||||
word-splitting rules.
|
||||
|
||||
VARIABLES
|
||||
|
||||
var (
|
||||
UnterminatedSingleQuoteError = errors.New("Unterminated single-quoted string")
|
||||
UnterminatedDoubleQuoteError = errors.New("Unterminated double-quoted string")
|
||||
UnterminatedEscapeError = errors.New("Unterminated backslash-escape")
|
||||
)
|
||||
|
||||
|
||||
FUNCTIONS
|
||||
|
||||
func Join(args ...string) string
|
||||
Join quotes each argument and joins them with a space. If passed to
|
||||
/bin/sh, the resulting string will be split back into the original
|
||||
arguments.
|
||||
|
||||
func Split(input string) (words []string, err error)
|
||||
Split splits a string according to /bin/sh's word-splitting rules. It
|
||||
supports backslash-escapes, single-quotes, and double-quotes. Notably it
|
||||
does not support the $'' style of quoting. It also doesn't attempt to
|
||||
perform any other sort of expansion, including brace expansion, shell
|
||||
expansion, or pathname expansion.
|
||||
|
||||
If the given input has an unterminated quoted string or ends in a
|
||||
backslash-escape, one of UnterminatedSingleQuoteError,
|
||||
UnterminatedDoubleQuoteError, or UnterminatedEscapeError is returned.
|
||||
|
||||
|
3
vendor/github.com/kballard/go-shellquote/doc.go
generated
vendored
3
vendor/github.com/kballard/go-shellquote/doc.go
generated
vendored
|
@ -1,3 +0,0 @@
|
|||
// Shellquote provides utilities for joining/splitting strings using sh's
|
||||
// word-splitting rules.
|
||||
package shellquote
|
102
vendor/github.com/kballard/go-shellquote/quote.go
generated
vendored
102
vendor/github.com/kballard/go-shellquote/quote.go
generated
vendored
|
@ -1,102 +0,0 @@
|
|||
package shellquote
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Join quotes each argument and joins them with a space.
|
||||
// If passed to /bin/sh, the resulting string will be split back into the
|
||||
// original arguments.
|
||||
func Join(args ...string) string {
|
||||
var buf bytes.Buffer
|
||||
for i, arg := range args {
|
||||
if i != 0 {
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
quote(arg, &buf)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
const (
|
||||
specialChars = "\\'\"`${[|&;<>()*?!"
|
||||
extraSpecialChars = " \t\n"
|
||||
prefixChars = "~"
|
||||
)
|
||||
|
||||
func quote(word string, buf *bytes.Buffer) {
|
||||
// We want to try to produce a "nice" output. As such, we will
|
||||
// backslash-escape most characters, but if we encounter a space, or if we
|
||||
// encounter an extra-special char (which doesn't work with
|
||||
// backslash-escaping) we switch over to quoting the whole word. We do this
|
||||
// with a space because it's typically easier for people to read multi-word
|
||||
// arguments when quoted with a space rather than with ugly backslashes
|
||||
// everywhere.
|
||||
origLen := buf.Len()
|
||||
|
||||
if len(word) == 0 {
|
||||
// oops, no content
|
||||
buf.WriteString("''")
|
||||
return
|
||||
}
|
||||
|
||||
cur, prev := word, word
|
||||
atStart := true
|
||||
for len(cur) > 0 {
|
||||
c, l := utf8.DecodeRuneInString(cur)
|
||||
cur = cur[l:]
|
||||
if strings.ContainsRune(specialChars, c) || (atStart && strings.ContainsRune(prefixChars, c)) {
|
||||
// copy the non-special chars up to this point
|
||||
if len(cur) < len(prev) {
|
||||
buf.WriteString(prev[0 : len(prev)-len(cur)-l])
|
||||
}
|
||||
buf.WriteByte('\\')
|
||||
buf.WriteRune(c)
|
||||
prev = cur
|
||||
} else if strings.ContainsRune(extraSpecialChars, c) {
|
||||
// start over in quote mode
|
||||
buf.Truncate(origLen)
|
||||
goto quote
|
||||
}
|
||||
atStart = false
|
||||
}
|
||||
if len(prev) > 0 {
|
||||
buf.WriteString(prev)
|
||||
}
|
||||
return
|
||||
|
||||
quote:
|
||||
// quote mode
|
||||
// Use single-quotes, but if we find a single-quote in the word, we need
|
||||
// to terminate the string, emit an escaped quote, and start the string up
|
||||
// again
|
||||
inQuote := false
|
||||
for len(word) > 0 {
|
||||
i := strings.IndexRune(word, '\'')
|
||||
if i == -1 {
|
||||
break
|
||||
}
|
||||
if i > 0 {
|
||||
if !inQuote {
|
||||
buf.WriteByte('\'')
|
||||
inQuote = true
|
||||
}
|
||||
buf.WriteString(word[0:i])
|
||||
}
|
||||
word = word[i+1:]
|
||||
if inQuote {
|
||||
buf.WriteByte('\'')
|
||||
inQuote = false
|
||||
}
|
||||
buf.WriteString("\\'")
|
||||
}
|
||||
if len(word) > 0 {
|
||||
if !inQuote {
|
||||
buf.WriteByte('\'')
|
||||
}
|
||||
buf.WriteString(word)
|
||||
buf.WriteByte('\'')
|
||||
}
|
||||
}
|
156
vendor/github.com/kballard/go-shellquote/unquote.go
generated
vendored
156
vendor/github.com/kballard/go-shellquote/unquote.go
generated
vendored
|
@ -1,156 +0,0 @@
|
|||
package shellquote
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
var (
|
||||
UnterminatedSingleQuoteError = errors.New("Unterminated single-quoted string")
|
||||
UnterminatedDoubleQuoteError = errors.New("Unterminated double-quoted string")
|
||||
UnterminatedEscapeError = errors.New("Unterminated backslash-escape")
|
||||
)
|
||||
|
||||
var (
|
||||
splitChars = " \n\t"
|
||||
singleChar = '\''
|
||||
doubleChar = '"'
|
||||
escapeChar = '\\'
|
||||
doubleEscapeChars = "$`\"\n\\"
|
||||
)
|
||||
|
||||
// Split splits a string according to /bin/sh's word-splitting rules. It
|
||||
// supports backslash-escapes, single-quotes, and double-quotes. Notably it does
|
||||
// not support the $'' style of quoting. It also doesn't attempt to perform any
|
||||
// other sort of expansion, including brace expansion, shell expansion, or
|
||||
// pathname expansion.
|
||||
//
|
||||
// If the given input has an unterminated quoted string or ends in a
|
||||
// backslash-escape, one of UnterminatedSingleQuoteError,
|
||||
// UnterminatedDoubleQuoteError, or UnterminatedEscapeError is returned.
|
||||
func Split(input string) (words []string, err error) {
|
||||
var buf bytes.Buffer
|
||||
words = make([]string, 0)
|
||||
|
||||
for len(input) > 0 {
|
||||
// skip any splitChars at the start
|
||||
c, l := utf8.DecodeRuneInString(input)
|
||||
if strings.ContainsRune(splitChars, c) {
|
||||
input = input[l:]
|
||||
continue
|
||||
} else if c == escapeChar {
|
||||
// Look ahead for escaped newline so we can skip over it
|
||||
next := input[l:]
|
||||
if len(next) == 0 {
|
||||
err = UnterminatedEscapeError
|
||||
return
|
||||
}
|
||||
c2, l2 := utf8.DecodeRuneInString(next)
|
||||
if c2 == '\n' {
|
||||
input = next[l2:]
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
var word string
|
||||
word, input, err = splitWord(input, &buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
words = append(words, word)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func splitWord(input string, buf *bytes.Buffer) (word string, remainder string, err error) {
|
||||
buf.Reset()
|
||||
|
||||
raw:
|
||||
{
|
||||
cur := input
|
||||
for len(cur) > 0 {
|
||||
c, l := utf8.DecodeRuneInString(cur)
|
||||
cur = cur[l:]
|
||||
if c == singleChar {
|
||||
buf.WriteString(input[0 : len(input)-len(cur)-l])
|
||||
input = cur
|
||||
goto single
|
||||
} else if c == doubleChar {
|
||||
buf.WriteString(input[0 : len(input)-len(cur)-l])
|
||||
input = cur
|
||||
goto double
|
||||
} else if c == escapeChar {
|
||||
buf.WriteString(input[0 : len(input)-len(cur)-l])
|
||||
input = cur
|
||||
goto escape
|
||||
} else if strings.ContainsRune(splitChars, c) {
|
||||
buf.WriteString(input[0 : len(input)-len(cur)-l])
|
||||
return buf.String(), cur, nil
|
||||
}
|
||||
}
|
||||
if len(input) > 0 {
|
||||
buf.WriteString(input)
|
||||
input = ""
|
||||
}
|
||||
goto done
|
||||
}
|
||||
|
||||
escape:
|
||||
{
|
||||
if len(input) == 0 {
|
||||
return "", "", UnterminatedEscapeError
|
||||
}
|
||||
c, l := utf8.DecodeRuneInString(input)
|
||||
if c == '\n' {
|
||||
// a backslash-escaped newline is elided from the output entirely
|
||||
} else {
|
||||
buf.WriteString(input[:l])
|
||||
}
|
||||
input = input[l:]
|
||||
}
|
||||
goto raw
|
||||
|
||||
single:
|
||||
{
|
||||
i := strings.IndexRune(input, singleChar)
|
||||
if i == -1 {
|
||||
return "", "", UnterminatedSingleQuoteError
|
||||
}
|
||||
buf.WriteString(input[0:i])
|
||||
input = input[i+1:]
|
||||
goto raw
|
||||
}
|
||||
|
||||
double:
|
||||
{
|
||||
cur := input
|
||||
for len(cur) > 0 {
|
||||
c, l := utf8.DecodeRuneInString(cur)
|
||||
cur = cur[l:]
|
||||
if c == doubleChar {
|
||||
buf.WriteString(input[0 : len(input)-len(cur)-l])
|
||||
input = cur
|
||||
goto raw
|
||||
} else if c == escapeChar {
|
||||
// bash only supports certain escapes in double-quoted strings
|
||||
c2, l2 := utf8.DecodeRuneInString(cur)
|
||||
cur = cur[l2:]
|
||||
if strings.ContainsRune(doubleEscapeChars, c2) {
|
||||
buf.WriteString(input[0 : len(input)-len(cur)-l-l2])
|
||||
if c2 == '\n' {
|
||||
// newline is special, skip the backslash entirely
|
||||
} else {
|
||||
buf.WriteRune(c2)
|
||||
}
|
||||
input = cur
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", "", UnterminatedDoubleQuoteError
|
||||
}
|
||||
|
||||
done:
|
||||
return buf.String(), input, nil
|
||||
}
|
1877
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/attribute_group.go
generated
vendored
1877
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/attribute_group.go
generated
vendored
File diff suppressed because it is too large
Load diff
20
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/doc.go
generated
vendored
20
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/doc.go
generated
vendored
|
@ -1,20 +0,0 @@
|
|||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package semconv implements OpenTelemetry semantic conventions.
|
||||
//
|
||||
// OpenTelemetry semantic conventions are agreed standardized naming
|
||||
// patterns for OpenTelemetry things. This package represents the v1.21.0
|
||||
// version of the OpenTelemetry semantic conventions.
|
||||
package semconv // import "go.opentelemetry.io/otel/semconv/v1.21.0"
|
199
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/event.go
generated
vendored
199
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/event.go
generated
vendored
|
@ -1,199 +0,0 @@
|
|||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Code generated from semantic convention specification. DO NOT EDIT.
|
||||
|
||||
package semconv // import "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
|
||||
import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
// This semantic convention defines the attributes used to represent a feature
|
||||
// flag evaluation as an event.
|
||||
const (
|
||||
// FeatureFlagKeyKey is the attribute Key conforming to the
|
||||
// "feature_flag.key" semantic conventions. It represents the unique
|
||||
// identifier of the feature flag.
|
||||
//
|
||||
// Type: string
|
||||
// RequirementLevel: Required
|
||||
// Stability: stable
|
||||
// Examples: 'logo-color'
|
||||
FeatureFlagKeyKey = attribute.Key("feature_flag.key")
|
||||
|
||||
// FeatureFlagProviderNameKey is the attribute Key conforming to the
|
||||
// "feature_flag.provider_name" semantic conventions. It represents the
|
||||
// name of the service provider that performs the flag evaluation.
|
||||
//
|
||||
// Type: string
|
||||
// RequirementLevel: Recommended
|
||||
// Stability: stable
|
||||
// Examples: 'Flag Manager'
|
||||
FeatureFlagProviderNameKey = attribute.Key("feature_flag.provider_name")
|
||||
|
||||
// FeatureFlagVariantKey is the attribute Key conforming to the
|
||||
// "feature_flag.variant" semantic conventions. It represents the sHOULD be
|
||||
// a semantic identifier for a value. If one is unavailable, a stringified
|
||||
// version of the value can be used.
|
||||
//
|
||||
// Type: string
|
||||
// RequirementLevel: Recommended
|
||||
// Stability: stable
|
||||
// Examples: 'red', 'true', 'on'
|
||||
// Note: A semantic identifier, commonly referred to as a variant, provides
|
||||
// a means
|
||||
// for referring to a value without including the value itself. This can
|
||||
// provide additional context for understanding the meaning behind a value.
|
||||
// For example, the variant `red` maybe be used for the value `#c05543`.
|
||||
//
|
||||
// A stringified version of the value can be used in situations where a
|
||||
// semantic identifier is unavailable. String representation of the value
|
||||
// should be determined by the implementer.
|
||||
FeatureFlagVariantKey = attribute.Key("feature_flag.variant")
|
||||
)
|
||||
|
||||
// FeatureFlagKey returns an attribute KeyValue conforming to the
|
||||
// "feature_flag.key" semantic conventions. It represents the unique identifier
|
||||
// of the feature flag.
|
||||
func FeatureFlagKey(val string) attribute.KeyValue {
|
||||
return FeatureFlagKeyKey.String(val)
|
||||
}
|
||||
|
||||
// FeatureFlagProviderName returns an attribute KeyValue conforming to the
|
||||
// "feature_flag.provider_name" semantic conventions. It represents the name of
|
||||
// the service provider that performs the flag evaluation.
|
||||
func FeatureFlagProviderName(val string) attribute.KeyValue {
|
||||
return FeatureFlagProviderNameKey.String(val)
|
||||
}
|
||||
|
||||
// FeatureFlagVariant returns an attribute KeyValue conforming to the
|
||||
// "feature_flag.variant" semantic conventions. It represents the sHOULD be a
|
||||
// semantic identifier for a value. If one is unavailable, a stringified
|
||||
// version of the value can be used.
|
||||
func FeatureFlagVariant(val string) attribute.KeyValue {
|
||||
return FeatureFlagVariantKey.String(val)
|
||||
}
|
||||
|
||||
// RPC received/sent message.
|
||||
const (
|
||||
// MessageTypeKey is the attribute Key conforming to the "message.type"
|
||||
// semantic conventions. It represents the whether this is a received or
|
||||
// sent message.
|
||||
//
|
||||
// Type: Enum
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
MessageTypeKey = attribute.Key("message.type")
|
||||
|
||||
// MessageIDKey is the attribute Key conforming to the "message.id"
|
||||
// semantic conventions. It represents the mUST be calculated as two
|
||||
// different counters starting from `1` one for sent messages and one for
|
||||
// received message.
|
||||
//
|
||||
// Type: int
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
// Note: This way we guarantee that the values will be consistent between
|
||||
// different implementations.
|
||||
MessageIDKey = attribute.Key("message.id")
|
||||
|
||||
// MessageCompressedSizeKey is the attribute Key conforming to the
|
||||
// "message.compressed_size" semantic conventions. It represents the
|
||||
// compressed size of the message in bytes.
|
||||
//
|
||||
// Type: int
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
MessageCompressedSizeKey = attribute.Key("message.compressed_size")
|
||||
|
||||
// MessageUncompressedSizeKey is the attribute Key conforming to the
|
||||
// "message.uncompressed_size" semantic conventions. It represents the
|
||||
// uncompressed size of the message in bytes.
|
||||
//
|
||||
// Type: int
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
MessageUncompressedSizeKey = attribute.Key("message.uncompressed_size")
|
||||
)
|
||||
|
||||
var (
|
||||
// sent
|
||||
MessageTypeSent = MessageTypeKey.String("SENT")
|
||||
// received
|
||||
MessageTypeReceived = MessageTypeKey.String("RECEIVED")
|
||||
)
|
||||
|
||||
// MessageID returns an attribute KeyValue conforming to the "message.id"
|
||||
// semantic conventions. It represents the mUST be calculated as two different
|
||||
// counters starting from `1` one for sent messages and one for received
|
||||
// message.
|
||||
func MessageID(val int) attribute.KeyValue {
|
||||
return MessageIDKey.Int(val)
|
||||
}
|
||||
|
||||
// MessageCompressedSize returns an attribute KeyValue conforming to the
|
||||
// "message.compressed_size" semantic conventions. It represents the compressed
|
||||
// size of the message in bytes.
|
||||
func MessageCompressedSize(val int) attribute.KeyValue {
|
||||
return MessageCompressedSizeKey.Int(val)
|
||||
}
|
||||
|
||||
// MessageUncompressedSize returns an attribute KeyValue conforming to the
|
||||
// "message.uncompressed_size" semantic conventions. It represents the
|
||||
// uncompressed size of the message in bytes.
|
||||
func MessageUncompressedSize(val int) attribute.KeyValue {
|
||||
return MessageUncompressedSizeKey.Int(val)
|
||||
}
|
||||
|
||||
// The attributes used to report a single exception associated with a span.
|
||||
const (
|
||||
// ExceptionEscapedKey is the attribute Key conforming to the
|
||||
// "exception.escaped" semantic conventions. It represents the sHOULD be
|
||||
// set to true if the exception event is recorded at a point where it is
|
||||
// known that the exception is escaping the scope of the span.
|
||||
//
|
||||
// Type: boolean
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
// Note: An exception is considered to have escaped (or left) the scope of
|
||||
// a span,
|
||||
// if that span is ended while the exception is still logically "in
|
||||
// flight".
|
||||
// This may be actually "in flight" in some languages (e.g. if the
|
||||
// exception
|
||||
// is passed to a Context manager's `__exit__` method in Python) but will
|
||||
// usually be caught at the point of recording the exception in most
|
||||
// languages.
|
||||
//
|
||||
// It is usually not possible to determine at the point where an exception
|
||||
// is thrown
|
||||
// whether it will escape the scope of a span.
|
||||
// However, it is trivial to know that an exception
|
||||
// will escape, if one checks for an active exception just before ending
|
||||
// the span,
|
||||
// as done in the [example above](#recording-an-exception).
|
||||
//
|
||||
// It follows that an exception may still escape the scope of the span
|
||||
// even if the `exception.escaped` attribute was not set or set to false,
|
||||
// since the event might have been recorded at a time where it was not
|
||||
// clear whether the exception will escape.
|
||||
ExceptionEscapedKey = attribute.Key("exception.escaped")
|
||||
)
|
||||
|
||||
// ExceptionEscaped returns an attribute KeyValue conforming to the
|
||||
// "exception.escaped" semantic conventions. It represents the sHOULD be set to
|
||||
// true if the exception event is recorded at a point where it is known that
|
||||
// the exception is escaping the scope of the span.
|
||||
func ExceptionEscaped(val bool) attribute.KeyValue {
|
||||
return ExceptionEscapedKey.Bool(val)
|
||||
}
|
20
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/exception.go
generated
vendored
20
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/exception.go
generated
vendored
|
@ -1,20 +0,0 @@
|
|||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package semconv // import "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
|
||||
const (
|
||||
// ExceptionEventName is the name of the Span event representing an exception.
|
||||
ExceptionEventName = "exception"
|
||||
)
|
2310
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/resource.go
generated
vendored
2310
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/resource.go
generated
vendored
File diff suppressed because it is too large
Load diff
20
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/schema.go
generated
vendored
20
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/schema.go
generated
vendored
|
@ -1,20 +0,0 @@
|
|||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package semconv // import "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
|
||||
// SchemaURL is the schema URL that matches the version of the semantic conventions
|
||||
// that this package defines. Semconv packages starting from v1.4.0 must declare
|
||||
// non-empty schema URL in the form https://opentelemetry.io/schemas/<version>
|
||||
const SchemaURL = "https://opentelemetry.io/schemas/1.21.0"
|
2495
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/trace.go
generated
vendored
2495
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/trace.go
generated
vendored
File diff suppressed because it is too large
Load diff
21
vendor/lukechampine.com/uint128/LICENSE
generated
vendored
21
vendor/lukechampine.com/uint128/LICENSE
generated
vendored
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019 Luke Champine
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
46
vendor/lukechampine.com/uint128/README.md
generated
vendored
46
vendor/lukechampine.com/uint128/README.md
generated
vendored
|
@ -1,46 +0,0 @@
|
|||
uint128
|
||||
-------
|
||||
|
||||
[![GoDoc](https://godoc.org/github.com/lukechampine/uint128?status.svg)](https://godoc.org/github.com/lukechampine/uint128)
|
||||
[![Go Report Card](http://goreportcard.com/badge/github.com/lukechampine/uint128)](https://goreportcard.com/report/github.com/lukechampine/uint128)
|
||||
|
||||
```
|
||||
go get lukechampine.com/uint128
|
||||
```
|
||||
|
||||
`uint128` provides a high-performance `Uint128` type that supports standard arithmetic
|
||||
operations. Unlike `math/big`, operations on `Uint128` values always produce new values
|
||||
instead of modifying a pointer receiver. A `Uint128` value is therefore immutable, just
|
||||
like `uint64` and friends.
|
||||
|
||||
The name `uint128.Uint128` stutters, so I recommend either using a "dot import"
|
||||
or aliasing `uint128.Uint128` to give it a project-specific name. Embedding the type
|
||||
is not recommended, because methods will still return `uint128.Uint128`; this means that,
|
||||
if you want to extend the type with new methods, your best bet is probably to copy the
|
||||
source code wholesale and rename the identifier. ¯\\\_(ツ)\_/¯
|
||||
|
||||
|
||||
# Benchmarks
|
||||
|
||||
Addition, multiplication, and subtraction are on par with their native 64-bit
|
||||
equivalents. Division is slower: ~20x slower when dividing a `Uint128` by a
|
||||
`uint64`, and ~100x slower when dividing by a `Uint128`. However, division is
|
||||
still faster than with `big.Int` (for the same operands), especially when
|
||||
dividing by a `uint64`.
|
||||
|
||||
```
|
||||
BenchmarkArithmetic/Add-4 2000000000 0.45 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkArithmetic/Sub-4 2000000000 0.67 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkArithmetic/Mul-4 2000000000 0.42 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkArithmetic/Lsh-4 2000000000 1.06 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkArithmetic/Rsh-4 2000000000 1.06 ns/op 0 B/op 0 allocs/op
|
||||
|
||||
BenchmarkDivision/native_64/64-4 2000000000 0.39 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkDivision/Div_128/64-4 2000000000 6.28 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkDivision/Div_128/128-4 30000000 45.2 ns/op 0 B/op 0 allocs/op
|
||||
BenchmarkDivision/big.Int_128/64-4 20000000 98.2 ns/op 8 B/op 1 allocs/op
|
||||
BenchmarkDivision/big.Int_128/128-4 30000000 53.4 ns/op 48 B/op 1 allocs/op
|
||||
|
||||
BenchmarkString/Uint128-4 10000000 173 ns/op 48 B/op 1 allocs/op
|
||||
BenchmarkString/big.Int-4 5000000 350 ns/op 144 B/op 3 allocs/op
|
||||
```
|
440
vendor/lukechampine.com/uint128/uint128.go
generated
vendored
440
vendor/lukechampine.com/uint128/uint128.go
generated
vendored
|
@ -1,440 +0,0 @@
|
|||
package uint128 // import "lukechampine.com/uint128"
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"math/bits"
|
||||
)
|
||||
|
||||
// Zero is a zero-valued uint128.
|
||||
var Zero Uint128
|
||||
|
||||
// Max is the largest possible uint128 value.
|
||||
var Max = New(math.MaxUint64, math.MaxUint64)
|
||||
|
||||
// A Uint128 is an unsigned 128-bit number.
|
||||
type Uint128 struct {
|
||||
Lo, Hi uint64
|
||||
}
|
||||
|
||||
// IsZero returns true if u == 0.
|
||||
func (u Uint128) IsZero() bool {
|
||||
// NOTE: we do not compare against Zero, because that is a global variable
|
||||
// that could be modified.
|
||||
return u == Uint128{}
|
||||
}
|
||||
|
||||
// Equals returns true if u == v.
|
||||
//
|
||||
// Uint128 values can be compared directly with ==, but use of the Equals method
|
||||
// is preferred for consistency.
|
||||
func (u Uint128) Equals(v Uint128) bool {
|
||||
return u == v
|
||||
}
|
||||
|
||||
// Equals64 returns true if u == v.
|
||||
func (u Uint128) Equals64(v uint64) bool {
|
||||
return u.Lo == v && u.Hi == 0
|
||||
}
|
||||
|
||||
// Cmp compares u and v and returns:
|
||||
//
|
||||
// -1 if u < v
|
||||
// 0 if u == v
|
||||
// +1 if u > v
|
||||
//
|
||||
func (u Uint128) Cmp(v Uint128) int {
|
||||
if u == v {
|
||||
return 0
|
||||
} else if u.Hi < v.Hi || (u.Hi == v.Hi && u.Lo < v.Lo) {
|
||||
return -1
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
// Cmp64 compares u and v and returns:
|
||||
//
|
||||
// -1 if u < v
|
||||
// 0 if u == v
|
||||
// +1 if u > v
|
||||
//
|
||||
func (u Uint128) Cmp64(v uint64) int {
|
||||
if u.Hi == 0 && u.Lo == v {
|
||||
return 0
|
||||
} else if u.Hi == 0 && u.Lo < v {
|
||||
return -1
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
// And returns u&v.
|
||||
func (u Uint128) And(v Uint128) Uint128 {
|
||||
return Uint128{u.Lo & v.Lo, u.Hi & v.Hi}
|
||||
}
|
||||
|
||||
// And64 returns u&v.
|
||||
func (u Uint128) And64(v uint64) Uint128 {
|
||||
return Uint128{u.Lo & v, u.Hi & 0}
|
||||
}
|
||||
|
||||
// Or returns u|v.
|
||||
func (u Uint128) Or(v Uint128) Uint128 {
|
||||
return Uint128{u.Lo | v.Lo, u.Hi | v.Hi}
|
||||
}
|
||||
|
||||
// Or64 returns u|v.
|
||||
func (u Uint128) Or64(v uint64) Uint128 {
|
||||
return Uint128{u.Lo | v, u.Hi | 0}
|
||||
}
|
||||
|
||||
// Xor returns u^v.
|
||||
func (u Uint128) Xor(v Uint128) Uint128 {
|
||||
return Uint128{u.Lo ^ v.Lo, u.Hi ^ v.Hi}
|
||||
}
|
||||
|
||||
// Xor64 returns u^v.
|
||||
func (u Uint128) Xor64(v uint64) Uint128 {
|
||||
return Uint128{u.Lo ^ v, u.Hi ^ 0}
|
||||
}
|
||||
|
||||
// Add returns u+v.
|
||||
func (u Uint128) Add(v Uint128) Uint128 {
|
||||
lo, carry := bits.Add64(u.Lo, v.Lo, 0)
|
||||
hi, carry := bits.Add64(u.Hi, v.Hi, carry)
|
||||
if carry != 0 {
|
||||
panic("overflow")
|
||||
}
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// AddWrap returns u+v with wraparound semantics; for example,
|
||||
// Max.AddWrap(From64(1)) == Zero.
|
||||
func (u Uint128) AddWrap(v Uint128) Uint128 {
|
||||
lo, carry := bits.Add64(u.Lo, v.Lo, 0)
|
||||
hi, _ := bits.Add64(u.Hi, v.Hi, carry)
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// Add64 returns u+v.
|
||||
func (u Uint128) Add64(v uint64) Uint128 {
|
||||
lo, carry := bits.Add64(u.Lo, v, 0)
|
||||
hi, carry := bits.Add64(u.Hi, 0, carry)
|
||||
if carry != 0 {
|
||||
panic("overflow")
|
||||
}
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// AddWrap64 returns u+v with wraparound semantics; for example,
|
||||
// Max.AddWrap64(1) == Zero.
|
||||
func (u Uint128) AddWrap64(v uint64) Uint128 {
|
||||
lo, carry := bits.Add64(u.Lo, v, 0)
|
||||
hi := u.Hi + carry
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// Sub returns u-v.
|
||||
func (u Uint128) Sub(v Uint128) Uint128 {
|
||||
lo, borrow := bits.Sub64(u.Lo, v.Lo, 0)
|
||||
hi, borrow := bits.Sub64(u.Hi, v.Hi, borrow)
|
||||
if borrow != 0 {
|
||||
panic("underflow")
|
||||
}
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// SubWrap returns u-v with wraparound semantics; for example,
|
||||
// Zero.SubWrap(From64(1)) == Max.
|
||||
func (u Uint128) SubWrap(v Uint128) Uint128 {
|
||||
lo, borrow := bits.Sub64(u.Lo, v.Lo, 0)
|
||||
hi, _ := bits.Sub64(u.Hi, v.Hi, borrow)
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// Sub64 returns u-v.
|
||||
func (u Uint128) Sub64(v uint64) Uint128 {
|
||||
lo, borrow := bits.Sub64(u.Lo, v, 0)
|
||||
hi, borrow := bits.Sub64(u.Hi, 0, borrow)
|
||||
if borrow != 0 {
|
||||
panic("underflow")
|
||||
}
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// SubWrap64 returns u-v with wraparound semantics; for example,
|
||||
// Zero.SubWrap64(1) == Max.
|
||||
func (u Uint128) SubWrap64(v uint64) Uint128 {
|
||||
lo, borrow := bits.Sub64(u.Lo, v, 0)
|
||||
hi := u.Hi - borrow
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// Mul returns u*v, panicking on overflow.
|
||||
func (u Uint128) Mul(v Uint128) Uint128 {
|
||||
hi, lo := bits.Mul64(u.Lo, v.Lo)
|
||||
p0, p1 := bits.Mul64(u.Hi, v.Lo)
|
||||
p2, p3 := bits.Mul64(u.Lo, v.Hi)
|
||||
hi, c0 := bits.Add64(hi, p1, 0)
|
||||
hi, c1 := bits.Add64(hi, p3, c0)
|
||||
if (u.Hi != 0 && v.Hi != 0) || p0 != 0 || p2 != 0 || c1 != 0 {
|
||||
panic("overflow")
|
||||
}
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// MulWrap returns u*v with wraparound semantics; for example,
|
||||
// Max.MulWrap(Max) == 1.
|
||||
func (u Uint128) MulWrap(v Uint128) Uint128 {
|
||||
hi, lo := bits.Mul64(u.Lo, v.Lo)
|
||||
hi += u.Hi*v.Lo + u.Lo*v.Hi
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// Mul64 returns u*v, panicking on overflow.
|
||||
func (u Uint128) Mul64(v uint64) Uint128 {
|
||||
hi, lo := bits.Mul64(u.Lo, v)
|
||||
p0, p1 := bits.Mul64(u.Hi, v)
|
||||
hi, c0 := bits.Add64(hi, p1, 0)
|
||||
if p0 != 0 || c0 != 0 {
|
||||
panic("overflow")
|
||||
}
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// MulWrap64 returns u*v with wraparound semantics; for example,
|
||||
// Max.MulWrap64(2) == Max.Sub64(1).
|
||||
func (u Uint128) MulWrap64(v uint64) Uint128 {
|
||||
hi, lo := bits.Mul64(u.Lo, v)
|
||||
hi += u.Hi * v
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// Div returns u/v.
|
||||
func (u Uint128) Div(v Uint128) Uint128 {
|
||||
q, _ := u.QuoRem(v)
|
||||
return q
|
||||
}
|
||||
|
||||
// Div64 returns u/v.
|
||||
func (u Uint128) Div64(v uint64) Uint128 {
|
||||
q, _ := u.QuoRem64(v)
|
||||
return q
|
||||
}
|
||||
|
||||
// QuoRem returns q = u/v and r = u%v.
|
||||
func (u Uint128) QuoRem(v Uint128) (q, r Uint128) {
|
||||
if v.Hi == 0 {
|
||||
var r64 uint64
|
||||
q, r64 = u.QuoRem64(v.Lo)
|
||||
r = From64(r64)
|
||||
} else {
|
||||
// generate a "trial quotient," guaranteed to be within 1 of the actual
|
||||
// quotient, then adjust.
|
||||
n := uint(bits.LeadingZeros64(v.Hi))
|
||||
v1 := v.Lsh(n)
|
||||
u1 := u.Rsh(1)
|
||||
tq, _ := bits.Div64(u1.Hi, u1.Lo, v1.Hi)
|
||||
tq >>= 63 - n
|
||||
if tq != 0 {
|
||||
tq--
|
||||
}
|
||||
q = From64(tq)
|
||||
// calculate remainder using trial quotient, then adjust if remainder is
|
||||
// greater than divisor
|
||||
r = u.Sub(v.Mul64(tq))
|
||||
if r.Cmp(v) >= 0 {
|
||||
q = q.Add64(1)
|
||||
r = r.Sub(v)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// QuoRem64 returns q = u/v and r = u%v.
|
||||
func (u Uint128) QuoRem64(v uint64) (q Uint128, r uint64) {
|
||||
if u.Hi < v {
|
||||
q.Lo, r = bits.Div64(u.Hi, u.Lo, v)
|
||||
} else {
|
||||
q.Hi, r = bits.Div64(0, u.Hi, v)
|
||||
q.Lo, r = bits.Div64(r, u.Lo, v)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Mod returns r = u%v.
|
||||
func (u Uint128) Mod(v Uint128) (r Uint128) {
|
||||
_, r = u.QuoRem(v)
|
||||
return
|
||||
}
|
||||
|
||||
// Mod64 returns r = u%v.
|
||||
func (u Uint128) Mod64(v uint64) (r uint64) {
|
||||
_, r = u.QuoRem64(v)
|
||||
return
|
||||
}
|
||||
|
||||
// Lsh returns u<<n.
|
||||
func (u Uint128) Lsh(n uint) (s Uint128) {
|
||||
if n > 64 {
|
||||
s.Lo = 0
|
||||
s.Hi = u.Lo << (n - 64)
|
||||
} else {
|
||||
s.Lo = u.Lo << n
|
||||
s.Hi = u.Hi<<n | u.Lo>>(64-n)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Rsh returns u>>n.
|
||||
func (u Uint128) Rsh(n uint) (s Uint128) {
|
||||
if n > 64 {
|
||||
s.Lo = u.Hi >> (n - 64)
|
||||
s.Hi = 0
|
||||
} else {
|
||||
s.Lo = u.Lo>>n | u.Hi<<(64-n)
|
||||
s.Hi = u.Hi >> n
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LeadingZeros returns the number of leading zero bits in u; the result is 128
|
||||
// for u == 0.
|
||||
func (u Uint128) LeadingZeros() int {
|
||||
if u.Hi > 0 {
|
||||
return bits.LeadingZeros64(u.Hi)
|
||||
}
|
||||
return 64 + bits.LeadingZeros64(u.Lo)
|
||||
}
|
||||
|
||||
// TrailingZeros returns the number of trailing zero bits in u; the result is
|
||||
// 128 for u == 0.
|
||||
func (u Uint128) TrailingZeros() int {
|
||||
if u.Lo > 0 {
|
||||
return bits.TrailingZeros64(u.Lo)
|
||||
}
|
||||
return 64 + bits.TrailingZeros64(u.Hi)
|
||||
}
|
||||
|
||||
// OnesCount returns the number of one bits ("population count") in u.
|
||||
func (u Uint128) OnesCount() int {
|
||||
return bits.OnesCount64(u.Hi) + bits.OnesCount64(u.Lo)
|
||||
}
|
||||
|
||||
// RotateLeft returns the value of u rotated left by (k mod 128) bits.
|
||||
func (u Uint128) RotateLeft(k int) Uint128 {
|
||||
const n = 128
|
||||
s := uint(k) & (n - 1)
|
||||
return u.Lsh(s).Or(u.Rsh(n - s))
|
||||
}
|
||||
|
||||
// RotateRight returns the value of u rotated left by (k mod 128) bits.
|
||||
func (u Uint128) RotateRight(k int) Uint128 {
|
||||
return u.RotateLeft(-k)
|
||||
}
|
||||
|
||||
// Reverse returns the value of u with its bits in reversed order.
|
||||
func (u Uint128) Reverse() Uint128 {
|
||||
return Uint128{bits.Reverse64(u.Hi), bits.Reverse64(u.Lo)}
|
||||
}
|
||||
|
||||
// ReverseBytes returns the value of u with its bytes in reversed order.
|
||||
func (u Uint128) ReverseBytes() Uint128 {
|
||||
return Uint128{bits.ReverseBytes64(u.Hi), bits.ReverseBytes64(u.Lo)}
|
||||
}
|
||||
|
||||
// Len returns the minimum number of bits required to represent u; the result is
|
||||
// 0 for u == 0.
|
||||
func (u Uint128) Len() int {
|
||||
return 128 - u.LeadingZeros()
|
||||
}
|
||||
|
||||
// String returns the base-10 representation of u as a string.
|
||||
func (u Uint128) String() string {
|
||||
if u.IsZero() {
|
||||
return "0"
|
||||
}
|
||||
buf := []byte("0000000000000000000000000000000000000000") // log10(2^128) < 40
|
||||
for i := len(buf); ; i -= 19 {
|
||||
q, r := u.QuoRem64(1e19) // largest power of 10 that fits in a uint64
|
||||
var n int
|
||||
for ; r != 0; r /= 10 {
|
||||
n++
|
||||
buf[i-n] += byte(r % 10)
|
||||
}
|
||||
if q.IsZero() {
|
||||
return string(buf[i-n:])
|
||||
}
|
||||
u = q
|
||||
}
|
||||
}
|
||||
|
||||
// PutBytes stores u in b in little-endian order. It panics if len(b) < 16.
|
||||
func (u Uint128) PutBytes(b []byte) {
|
||||
binary.LittleEndian.PutUint64(b[:8], u.Lo)
|
||||
binary.LittleEndian.PutUint64(b[8:], u.Hi)
|
||||
}
|
||||
|
||||
// Big returns u as a *big.Int.
|
||||
func (u Uint128) Big() *big.Int {
|
||||
i := new(big.Int).SetUint64(u.Hi)
|
||||
i = i.Lsh(i, 64)
|
||||
i = i.Xor(i, new(big.Int).SetUint64(u.Lo))
|
||||
return i
|
||||
}
|
||||
|
||||
// Scan implements fmt.Scanner.
|
||||
func (u *Uint128) Scan(s fmt.ScanState, ch rune) error {
|
||||
i := new(big.Int)
|
||||
if err := i.Scan(s, ch); err != nil {
|
||||
return err
|
||||
} else if i.Sign() < 0 {
|
||||
return errors.New("value cannot be negative")
|
||||
} else if i.BitLen() > 128 {
|
||||
return errors.New("value overflows Uint128")
|
||||
}
|
||||
u.Lo = i.Uint64()
|
||||
u.Hi = i.Rsh(i, 64).Uint64()
|
||||
return nil
|
||||
}
|
||||
|
||||
// New returns the Uint128 value (lo,hi).
|
||||
func New(lo, hi uint64) Uint128 {
|
||||
return Uint128{lo, hi}
|
||||
}
|
||||
|
||||
// From64 converts v to a Uint128 value.
|
||||
func From64(v uint64) Uint128 {
|
||||
return New(v, 0)
|
||||
}
|
||||
|
||||
// FromBytes converts b to a Uint128 value.
|
||||
func FromBytes(b []byte) Uint128 {
|
||||
return New(
|
||||
binary.LittleEndian.Uint64(b[:8]),
|
||||
binary.LittleEndian.Uint64(b[8:]),
|
||||
)
|
||||
}
|
||||
|
||||
// FromBig converts i to a Uint128 value. It panics if i is negative or
|
||||
// overflows 128 bits.
|
||||
func FromBig(i *big.Int) (u Uint128) {
|
||||
if i.Sign() < 0 {
|
||||
panic("value cannot be negative")
|
||||
} else if i.BitLen() > 128 {
|
||||
panic("value overflows Uint128")
|
||||
}
|
||||
u.Lo = i.Uint64()
|
||||
u.Hi = i.Rsh(i, 64).Uint64()
|
||||
return u
|
||||
}
|
||||
|
||||
// FromString parses s as a Uint128 value.
|
||||
func FromString(s string) (u Uint128, err error) {
|
||||
_, err = fmt.Sscan(s, &u)
|
||||
return
|
||||
}
|
20
vendor/modernc.org/cc/v3/AUTHORS
generated
vendored
20
vendor/modernc.org/cc/v3/AUTHORS
generated
vendored
|
@ -1,20 +0,0 @@
|
|||
# This file lists authors for copyright purposes. This file is distinct from
|
||||
# the CONTRIBUTORS files. See the latter for an explanation.
|
||||
#
|
||||
# Names should be added to this file as:
|
||||
# Name or Organization <email address>
|
||||
#
|
||||
# The email address is not required for organizations.
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Dan Kortschak <dan.kortschak@adelaide.edu.au>
|
||||
Dan Peterson <danp@danp.net>
|
||||
Denys Smirnov <denis.smirnov.91@gmail.com>
|
||||
Huang Qiqi <huangqiqi@loongson.cn>
|
||||
Jan Mercl <0xjnml@gmail.com>
|
||||
Maxim Kupriianov <max@kc.vc>
|
||||
Peter Waller <p@pwaller.net>
|
||||
Steffen Butzer <steffen(dot)butzer@outlook.com>
|
||||
Tommi Virtanen <tv@eagain.net>
|
||||
Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
20
vendor/modernc.org/cc/v3/CONTRIBUTORS
generated
vendored
20
vendor/modernc.org/cc/v3/CONTRIBUTORS
generated
vendored
|
@ -1,20 +0,0 @@
|
|||
# This file lists people who contributed code to this repository. The AUTHORS
|
||||
# file lists the copyright holders; this file lists people.
|
||||
#
|
||||
# Names should be added to this file like so:
|
||||
# Name <email address>
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Dan Kortschak <dan.kortschak@adelaide.edu.au>
|
||||
Dan Peterson <danp@danp.net>
|
||||
Denys Smirnov <denis.smirnov.91@gmail.com>
|
||||
Huang Qiqi <huangqiqi@loongson.cn>
|
||||
Jan Mercl <0xjnml@gmail.com>
|
||||
Maxim Kupriianov <max@kc.vc>
|
||||
Peter Waller <p@pwaller.net>
|
||||
Steffen Butzer <steffen(dot)butzer@outlook.com>
|
||||
Tommi Virtanen <tv@eagain.net>
|
||||
Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||
Zvi Effron <zeffron@cs.hmc.edu>
|
||||
Lucas Raab <tuftedocelot@fastmail.fm>
|
141
vendor/modernc.org/cc/v3/Makefile
generated
vendored
141
vendor/modernc.org/cc/v3/Makefile
generated
vendored
|
@ -1,141 +0,0 @@
|
|||
# Copyright 2019 The CC Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
.PHONY: all bench clean cover cpu editor internalError later mem nuke todo edit devbench
|
||||
|
||||
grep=--include=*.go --include=*.l --include=*.y --include=*.yy
|
||||
ngrep='internalError\|TODOOK\|lexer\.go\|ast.go\|trigraphs\.go\|.*_string\.go\|stringer\.go\|testdata\/gcc'
|
||||
testlog=testdata/testlog-$(shell echo $$GOOS)-$(shell echo $$GOARCH)-on-$(shell go env GOOS)-$(shell go env GOARCH)
|
||||
|
||||
all: lexer.go
|
||||
LC_ALL=C make all_log 2>&1 | tee log
|
||||
|
||||
all_log:
|
||||
date
|
||||
go version
|
||||
uname -a
|
||||
./unconvert.sh
|
||||
gofmt -l -s -w *.go
|
||||
GOOS=darwin GOARCH=amd64 go build
|
||||
GOOS=darwin GOARCH=arm64 go build
|
||||
GOOS=linux GOARCH=386 go build
|
||||
GOOS=linux GOARCH=amd64 go build
|
||||
GOOS=linux GOARCH=arm go build
|
||||
GOOS=linux GOARCH=loong64 go build
|
||||
GOOS=windows GOARCH=386 go build
|
||||
GOOS=windows GOARCH=amd64 go build
|
||||
go vet | grep -v $(ngrep) || true
|
||||
golint | grep -v $(ngrep) || true
|
||||
misspell *.go
|
||||
staticcheck | grep -v 'lexer\.go' || true
|
||||
pcregrep -nM 'FAIL|false|<nil>|:\n}' ast_test.go || true
|
||||
|
||||
test:
|
||||
go version | tee $(testlog)
|
||||
uname -a | tee -a $(testlog)
|
||||
go test -v -timeout 24h | tee -a $(testlog)
|
||||
grep -ni fail $(testlog) | tee -a $(testlog) || true
|
||||
LC_ALL=C date | tee -a $(testlog)
|
||||
grep -ni --color=always fail $(testlog) || true
|
||||
|
||||
test_linux_amd64:
|
||||
GOOS=linux GOARCH=amd64 make test
|
||||
|
||||
test_linux_386:
|
||||
GOOS=linux GOARCH=386 make test
|
||||
|
||||
test_linux_arm:
|
||||
GOOS=linux GOARCH=arm make test
|
||||
|
||||
test_linux_arm64:
|
||||
GOOS=linux GOARCH=arm64 make test
|
||||
|
||||
test_windows_amd64:
|
||||
go version
|
||||
go test -v -timeout 24h
|
||||
|
||||
test_linux_loong64:
|
||||
GOOS=linux GOARCH=loong64 make test
|
||||
|
||||
test_windows386:
|
||||
go version
|
||||
go test -v -timeout 24h
|
||||
|
||||
build_all_targets:
|
||||
GOOS=darwin GOARCH=amd64 go build -v ./...
|
||||
GOOS=darwin GOARCH=arm64 go build -v ./...
|
||||
GOOS=freebsd GOARCH=386 go build -v ./...
|
||||
GOOS=freebsd GOARCH=amd64 go build -v ./...
|
||||
GOOS=freebsd GOARCH=arm go build -v ./...
|
||||
GOOS=freebsd GOARCH=arm64 go build -v ./...
|
||||
GOOS=illumos GOARCH=amd64 go build -v ./...
|
||||
GOOS=linux GOARCH=386 go build -v ./...
|
||||
GOOS=linux GOARCH=amd64 go build -v ./...
|
||||
GOOS=linux GOARCH=arm go build -v ./...
|
||||
GOOS=linux GOARCH=arm64 go build -v ./...
|
||||
GOOS=linux GOARCH=loong64 go build -v ./...
|
||||
GOOS=linux GOARCH=ppc64le go build -v ./...
|
||||
GOOS=linux GOARCH=riscv64 go build -v ./...
|
||||
GOOS=linux GOARCH=s390x go build -v ./...
|
||||
GOOS=netbsd GOARCH=386 go build -v ./...
|
||||
GOOS=netbsd GOARCH=amd64 go build -v ./...
|
||||
GOOS=netbsd GOARCH=arm go build -v ./...
|
||||
GOOS=openbsd GOARCH=386 go build -v ./...
|
||||
GOOS=openbsd GOARCH=amd64 go build -v ./...
|
||||
GOOS=openbsd GOARCH=arm64 go build -v ./...
|
||||
GOOS=windows GOARCH=386 go build -v ./...
|
||||
GOOS=windows GOARCH=amd64 go build -v ./...
|
||||
GOOS=windows GOARCH=arm64 go build -v ./...
|
||||
|
||||
devbench:
|
||||
date 2>&1 | tee log-devbench
|
||||
go test -timeout 24h -dev -run @ -bench . 2>&1 | tee -a log-devbench
|
||||
grep -n 'FAIL\|SKIP' log-devbench || true
|
||||
|
||||
bench:
|
||||
date 2>&1 | tee log-bench
|
||||
go test -timeout 24h -v -run '^[^E]' -bench . 2>&1 | tee -a log-bench
|
||||
grep -n 'FAIL\|SKIP' log-bench || true
|
||||
|
||||
clean:
|
||||
go clean
|
||||
rm -f *~ *.test *.out
|
||||
|
||||
cover:
|
||||
t=$(shell mktemp) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t
|
||||
|
||||
cpu: clean
|
||||
go test -run @ -bench . -cpuprofile cpu.out
|
||||
go tool pprof -lines *.test cpu.out
|
||||
|
||||
edit:
|
||||
@touch log
|
||||
@if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile *.go & fi
|
||||
|
||||
editor: lexer.go
|
||||
gofmt -l -s -w *.go
|
||||
go test -o /dev/null -c
|
||||
go install 2>&1 | tee log
|
||||
|
||||
ast.go lexer.go stringer.go: lexer.l parser.yy enum.go
|
||||
go generate
|
||||
|
||||
later:
|
||||
@grep -n $(grep) LATER * || true
|
||||
@grep -n $(grep) MAYBE * || true
|
||||
|
||||
mem: clean
|
||||
# go test -v -run ParserCS -csmith 2m -memprofile mem.out -timeout 24h
|
||||
# go test -v -run @ -bench BenchmarkScanner -memprofile mem.out -timeout 24h
|
||||
go test -v -run TestTranslateSQLite -memprofile mem.out -timeout 24h
|
||||
go tool pprof -lines -web -alloc_space *.test mem.out
|
||||
|
||||
nuke: clean
|
||||
go clean -i
|
||||
|
||||
todo:
|
||||
@grep -nr $(grep) ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) 'TODO\|panic' * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) BUG * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) [^[:alpha:]]println * | grep -v $(ngrep) || true
|
11
vendor/modernc.org/cc/v3/README.md
generated
vendored
11
vendor/modernc.org/cc/v3/README.md
generated
vendored
|
@ -1,11 +0,0 @@
|
|||
# cc/v3
|
||||
|
||||
Package CC is a C99 compiler front end.
|
||||
|
||||
Most of the functionality is now working.
|
||||
|
||||
Installation
|
||||
|
||||
$ go get -u modernc.org/cc/v3
|
||||
|
||||
Documentation: [godoc.org/modernc.org/cc/v3](http://godoc.org/modernc.org/cc/v3)
|
1026
vendor/modernc.org/cc/v3/abi.go
generated
vendored
1026
vendor/modernc.org/cc/v3/abi.go
generated
vendored
File diff suppressed because it is too large
Load diff
870
vendor/modernc.org/cc/v3/abi_platforms.go
generated
vendored
870
vendor/modernc.org/cc/v3/abi_platforms.go
generated
vendored
|
@ -1,870 +0,0 @@
|
|||
package cc
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
// abiByteOrders contains byte order information for known architectures.
|
||||
var (
|
||||
abiByteOrders = map[string]binary.ByteOrder{
|
||||
"386": binary.LittleEndian,
|
||||
"amd64": binary.LittleEndian,
|
||||
"arm": binary.LittleEndian,
|
||||
"arm64": binary.LittleEndian,
|
||||
"loong64": binary.LittleEndian,
|
||||
"ppc64le": binary.LittleEndian,
|
||||
"riscv64": binary.LittleEndian,
|
||||
"s390x": binary.BigEndian,
|
||||
}
|
||||
|
||||
abiSignedChar = map[[2]string]bool{
|
||||
{"freebsd", "arm"}: false,
|
||||
{"freebsd", "arm64"}: false,
|
||||
{"linux", "arm"}: false,
|
||||
{"linux", "arm64"}: false,
|
||||
{"linux", "ppc64le"}: false,
|
||||
{"linux", "riscv64"}: false,
|
||||
{"linux", "s390x"}: false,
|
||||
{"netbsd", "arm"}: false,
|
||||
{"openbsd", "arm64"}: false,
|
||||
|
||||
{"darwin", "amd64"}: true,
|
||||
{"darwin", "arm64"}: true,
|
||||
{"freebsd", "386"}: true,
|
||||
{"freebsd", "amd64"}: true,
|
||||
{"illumos", "amd64"}: true,
|
||||
{"linux", "386"}: true,
|
||||
{"linux", "amd64"}: true,
|
||||
{"linux", "loong64"}: true,
|
||||
{"netbsd", "386"}: true,
|
||||
{"netbsd", "amd64"}: true,
|
||||
{"openbsd", "386"}: true,
|
||||
{"openbsd", "amd64"}: true,
|
||||
{"windows", "386"}: true,
|
||||
{"windows", "amd64"}: true,
|
||||
{"windows", "arm64"}: true,
|
||||
}
|
||||
)
|
||||
|
||||
// abiTypes contains size and alignment information for known OS/arch pairs.
|
||||
//
|
||||
// The content is generated by ./cmd/cabi/main.c.
|
||||
var abiTypes = map[[2]string]map[Kind]ABIType{
|
||||
// Linux, generated by GCC 8.3.0
|
||||
{"linux", "amd64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {16, 16, 16},
|
||||
Float128: {16, 16, 16},
|
||||
Decimal32: {4, 4, 4},
|
||||
Decimal64: {8, 8, 8},
|
||||
Decimal128: {16, 16, 16},
|
||||
},
|
||||
{"linux", "386"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 4, 4},
|
||||
ULongLong: {8, 4, 4},
|
||||
Ptr: {4, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 4, 4},
|
||||
LongDouble: {12, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
UInt64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Float64x: {12, 4, 4},
|
||||
Float128: {16, 16, 16},
|
||||
Decimal32: {4, 4, 4},
|
||||
Decimal64: {8, 8, 8},
|
||||
Decimal128: {16, 16, 16},
|
||||
},
|
||||
{"linux", "arm"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {4, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
},
|
||||
{"linux", "arm64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
},
|
||||
// $ x86_64-w64-mingw32-gcc main.c && wine a.exe
|
||||
{"windows", "amd64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {16, 16, 16},
|
||||
Float128: {16, 16, 16},
|
||||
Decimal32: {4, 4, 4},
|
||||
Decimal64: {8, 8, 8},
|
||||
Decimal128: {16, 16, 16},
|
||||
},
|
||||
// clang version 14.0.0 (https://github.com/llvm/llvm-project.git 329fda39c507e8740978d10458451dcdb21563be)
|
||||
// Target: aarch64-w64-windows-gnu
|
||||
{"windows", "arm64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {8, 8, 8},
|
||||
},
|
||||
// $ i686-w64-mingw32-gcc main.c && wine a.exe
|
||||
{"windows", "386"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {4, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {12, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {12, 4, 4},
|
||||
Float128: {16, 16, 16},
|
||||
Decimal32: {4, 4, 4},
|
||||
Decimal64: {8, 8, 8},
|
||||
Decimal128: {16, 16, 16},
|
||||
},
|
||||
{"darwin", "amd64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
},
|
||||
{"darwin", "arm64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
},
|
||||
// gcc (SUSE Linux) 7.5.0
|
||||
{"linux", "s390x"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 8, 8},
|
||||
UInt128: {16, 8, 8},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {16, 8, 8},
|
||||
Float128: {16, 8, 8},
|
||||
Decimal32: {4, 4, 4},
|
||||
Decimal64: {8, 8, 8},
|
||||
Decimal128: {16, 8, 8},
|
||||
},
|
||||
// gcc (FreeBSD Ports Collection) 10.3.0
|
||||
{"freebsd", "amd64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
},
|
||||
// gcc (FreeBSD Ports Collection) 11.3.0
|
||||
{"freebsd", "arm64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
},
|
||||
// gcc (FreeBSD Ports Collection) 10.3.0
|
||||
{"freebsd", "386"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 4, 4},
|
||||
ULongLong: {8, 4, 4},
|
||||
Ptr: {4, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 4, 4},
|
||||
LongDouble: {12, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
UInt64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Float64x: {16, 16, 16},
|
||||
Float128: {16, 16, 16},
|
||||
},
|
||||
// gcc (FreeBSD Ports Collection) 11.3.0
|
||||
{"freebsd", "arm"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {4, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
},
|
||||
// gcc (GCC) 8.4.0
|
||||
{"openbsd", "amd64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {16, 16, 16},
|
||||
Float128: {16, 16, 16},
|
||||
},
|
||||
// OpenBSD clang version 13.0.0
|
||||
{"openbsd", "arm64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
},
|
||||
// OpenBSD clang version 13.0.0
|
||||
{"openbsd", "386"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 4, 4},
|
||||
ULongLong: {8, 4, 4},
|
||||
Ptr: {4, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 4, 4},
|
||||
LongDouble: {12, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
UInt64: {8, 4, 4},
|
||||
},
|
||||
// gcc (GCC) 10.3.0
|
||||
{"netbsd", "amd64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
},
|
||||
// gcc (nb4 20200810) 7.5.0
|
||||
{"netbsd", "arm"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {4, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
},
|
||||
// gcc (nb4 20200810) 7.5.0
|
||||
{"netbsd", "386"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {4, 4, 4},
|
||||
ULong: {4, 4, 4},
|
||||
LongLong: {8, 4, 4},
|
||||
ULongLong: {8, 4, 4},
|
||||
Ptr: {4, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 4, 4},
|
||||
LongDouble: {12, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
UInt64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Float64x: {12, 4, 4},
|
||||
Float128: {16, 16, 16},
|
||||
},
|
||||
// gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0
|
||||
{"linux", "riscv64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {16, 16, 16},
|
||||
Float128: {16, 16, 16},
|
||||
},
|
||||
// gcc (Debian 10.2.1-6) 10.2.1 20210110
|
||||
{"linux", "ppc64le"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {16, 16, 16},
|
||||
Float128: {16, 16, 16},
|
||||
Decimal32: {4, 4, 4},
|
||||
Decimal64: {8, 8, 8},
|
||||
Decimal128: {16, 16, 16},
|
||||
},
|
||||
// gcc (Loongnix 8.3.0-6.lnd.vec.33) 8.3.0
|
||||
{"linux", "loong64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {16, 16, 16},
|
||||
Float128: {16, 16, 16},
|
||||
Decimal32: {4, 4, 4},
|
||||
Decimal64: {8, 8, 8},
|
||||
Decimal128: {16, 16, 16},
|
||||
},
|
||||
// gcc (OmniOS 151044/12.2.0-il-0) 12.2.0
|
||||
{"illumos", "amd64"}: {
|
||||
Void: {1, 1, 1},
|
||||
Bool: {1, 1, 1},
|
||||
Char: {1, 1, 1},
|
||||
SChar: {1, 1, 1},
|
||||
UChar: {1, 1, 1},
|
||||
Short: {2, 2, 2},
|
||||
UShort: {2, 2, 2},
|
||||
Enum: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
UInt: {4, 4, 4},
|
||||
Long: {8, 8, 8},
|
||||
ULong: {8, 8, 8},
|
||||
LongLong: {8, 8, 8},
|
||||
ULongLong: {8, 8, 8},
|
||||
Ptr: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Float: {4, 4, 4},
|
||||
Double: {8, 8, 8},
|
||||
LongDouble: {16, 16, 16},
|
||||
Int8: {1, 1, 1},
|
||||
UInt8: {1, 1, 1},
|
||||
Int16: {2, 2, 2},
|
||||
UInt16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
UInt32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
UInt64: {8, 8, 8},
|
||||
Int128: {16, 16, 16},
|
||||
UInt128: {16, 16, 16},
|
||||
Float32: {4, 4, 4},
|
||||
Float32x: {8, 8, 8},
|
||||
Float64: {8, 8, 8},
|
||||
Float64x: {16, 16, 16},
|
||||
Float128: {16, 16, 16},
|
||||
},
|
||||
}
|
5232
vendor/modernc.org/cc/v3/ast.go
generated
vendored
5232
vendor/modernc.org/cc/v3/ast.go
generated
vendored
File diff suppressed because it is too large
Load diff
1187
vendor/modernc.org/cc/v3/ast2.go
generated
vendored
1187
vendor/modernc.org/cc/v3/ast2.go
generated
vendored
File diff suppressed because it is too large
Load diff
1057
vendor/modernc.org/cc/v3/cc.go
generated
vendored
1057
vendor/modernc.org/cc/v3/cc.go
generated
vendored
File diff suppressed because it is too large
Load diff
5276
vendor/modernc.org/cc/v3/check.go
generated
vendored
5276
vendor/modernc.org/cc/v3/check.go
generated
vendored
File diff suppressed because it is too large
Load diff
3101
vendor/modernc.org/cc/v3/cpp.go
generated
vendored
3101
vendor/modernc.org/cc/v3/cpp.go
generated
vendored
File diff suppressed because it is too large
Load diff
84
vendor/modernc.org/cc/v3/enum.go
generated
vendored
84
vendor/modernc.org/cc/v3/enum.go
generated
vendored
|
@ -1,84 +0,0 @@
|
|||
// Copyright 2019 The CC Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cc // import "modernc.org/cc/v3"
|
||||
|
||||
// Values of Kind
|
||||
const (
|
||||
Invalid Kind = iota
|
||||
|
||||
Array // T[]
|
||||
Bool // _Bool
|
||||
Char // char
|
||||
ComplexChar // complex char
|
||||
ComplexDouble // complex double
|
||||
ComplexFloat // complex float
|
||||
ComplexInt // complex int
|
||||
ComplexLong // complex long
|
||||
ComplexLongDouble // complex long double
|
||||
ComplexLongLong // complex long long
|
||||
ComplexShort // complex short
|
||||
ComplexUInt // complex unsigned
|
||||
ComplexULong // complex unsigned long
|
||||
ComplexULongLong // complex unsigned long long
|
||||
ComplexUShort // complex shor
|
||||
Decimal128 // _Decimal128
|
||||
Decimal32 // _Decimal32
|
||||
Decimal64 // _Decimal64
|
||||
Double // double
|
||||
Enum // enum
|
||||
Float // float
|
||||
Float128 // _Float128
|
||||
Float32 // _Float32
|
||||
Float32x // _Float32x
|
||||
Float64 // _Float64
|
||||
Float64x // _Float64x
|
||||
Function // function
|
||||
Int // int
|
||||
Int8 // __int8
|
||||
Int16 // __int16
|
||||
Int32 // __int32
|
||||
Int64 // __int64
|
||||
Int128 // __int128
|
||||
Long // long
|
||||
LongDouble // long double
|
||||
LongLong // long long
|
||||
Ptr // pointer
|
||||
SChar // signed char
|
||||
Short // short
|
||||
Struct // struct
|
||||
TypedefName // typedefname
|
||||
UChar // unsigned char
|
||||
UInt // unsigned
|
||||
UInt8 // unsigned __int8
|
||||
UInt16 // unsigned __int16
|
||||
UInt32 // unsigned __int32
|
||||
UInt64 // unsigned __int64
|
||||
UInt128 // unsigned __int128
|
||||
ULong // unsigned long
|
||||
ULongLong // unsigned long long
|
||||
UShort // unsigned short
|
||||
Union // union
|
||||
Void // void
|
||||
Vector // vector
|
||||
|
||||
typeofExpr
|
||||
typeofType
|
||||
|
||||
maxKind
|
||||
)
|
||||
|
||||
// Values of Linkage
|
||||
const (
|
||||
None Linkage = iota
|
||||
Internal
|
||||
External
|
||||
)
|
||||
|
||||
// Values of StorageClass
|
||||
const (
|
||||
Static StorageClass = iota
|
||||
Automatic
|
||||
Allocated
|
||||
)
|
156
vendor/modernc.org/cc/v3/filesystem.go
generated
vendored
156
vendor/modernc.org/cc/v3/filesystem.go
generated
vendored
|
@ -1,156 +0,0 @@
|
|||
// Copyright 2019 The CC Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cc
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Filesystem abstraction used in CC. The underlying value must be comparable (e.g. pointer) to be used in map keys.
|
||||
type Filesystem interface {
|
||||
// Stat is an analog of os.Stat, but also accepts a flag to indicate a system include (<file.h>).
|
||||
Stat(path string, sys bool) (os.FileInfo, error)
|
||||
// Open is an analog of os.Open, but also accepts a flag to indicate a system include (<file.h>).
|
||||
Open(path string, sys bool) (io.ReadCloser, error)
|
||||
}
|
||||
|
||||
// LocalFS returns a local filesystem implementation.
|
||||
func LocalFS() Filesystem {
|
||||
return localFS{}
|
||||
}
|
||||
|
||||
type localFS struct{}
|
||||
|
||||
// Stat implements Filesystem.
|
||||
func (localFS) Stat(path string, sys bool) (os.FileInfo, error) {
|
||||
return os.Stat(path)
|
||||
}
|
||||
|
||||
// Open implements Filesystem.
|
||||
func (localFS) Open(path string, sys bool) (io.ReadCloser, error) {
|
||||
return os.Open(path)
|
||||
}
|
||||
|
||||
// WorkingDir is a filesystem implementation that resolves paths relative to a given directory.
|
||||
// If filesystem is not specified, the local one will be used.
|
||||
func WorkingDir(wd string, fs Filesystem) Filesystem {
|
||||
if fs == nil {
|
||||
fs = LocalFS()
|
||||
}
|
||||
return workDir{fs: fs, wd: wd}
|
||||
}
|
||||
|
||||
type workDir struct {
|
||||
fs Filesystem
|
||||
wd string
|
||||
}
|
||||
|
||||
// Stat implements Filesystem.
|
||||
func (fs workDir) Stat(fname string, sys bool) (os.FileInfo, error) {
|
||||
if !path.IsAbs(fname) {
|
||||
fname = path.Join(fs.wd, fname)
|
||||
}
|
||||
return fs.fs.Stat(fname, sys)
|
||||
}
|
||||
|
||||
// Open implements Filesystem.
|
||||
func (fs workDir) Open(fname string, sys bool) (io.ReadCloser, error) {
|
||||
if !path.IsAbs(fname) {
|
||||
fname = path.Join(fs.wd, fname)
|
||||
}
|
||||
return fs.fs.Open(fname, sys)
|
||||
}
|
||||
|
||||
// Overlay is a filesystem implementation that first check if the file is available in the primary FS
|
||||
// and if not, falls back to a secondary FS.
|
||||
func Overlay(pri, sec Filesystem) Filesystem {
|
||||
return overlayFS{pri: pri, sec: sec}
|
||||
}
|
||||
|
||||
type overlayFS struct {
|
||||
pri, sec Filesystem
|
||||
}
|
||||
|
||||
// Stat implements Filesystem.
|
||||
func (fs overlayFS) Stat(path string, sys bool) (os.FileInfo, error) {
|
||||
st, err := fs.pri.Stat(path, sys)
|
||||
if err == nil || !os.IsNotExist(err) {
|
||||
return st, err
|
||||
}
|
||||
return fs.sec.Stat(path, sys)
|
||||
}
|
||||
|
||||
// Open implements Filesystem.
|
||||
func (fs overlayFS) Open(path string, sys bool) (io.ReadCloser, error) {
|
||||
f, err := fs.pri.Open(path, sys)
|
||||
if err == nil || !os.IsNotExist(err) {
|
||||
return f, err
|
||||
}
|
||||
return fs.sec.Open(path, sys)
|
||||
}
|
||||
|
||||
// StaticFS implements filesystem interface by serving string values form the provided map.
|
||||
func StaticFS(files map[string]string) Filesystem {
|
||||
return &staticFS{m: files, ts: time.Now()}
|
||||
}
|
||||
|
||||
type staticFS struct {
|
||||
ts time.Time
|
||||
m map[string]string
|
||||
}
|
||||
|
||||
// Stat implements Filesystem.
|
||||
func (fs *staticFS) Stat(path string, sys bool) (os.FileInfo, error) {
|
||||
v, ok := fs.m[path]
|
||||
if !ok {
|
||||
return nil, &os.PathError{"stat", path, os.ErrNotExist}
|
||||
}
|
||||
return staticFileInfo{name: path, size: int64(len(v)), mode: 0, mod: fs.ts}, nil
|
||||
}
|
||||
|
||||
// Open implements Filesystem.
|
||||
func (fs *staticFS) Open(path string, sys bool) (io.ReadCloser, error) {
|
||||
v, ok := fs.m[path]
|
||||
if !ok {
|
||||
return nil, &os.PathError{"open", path, os.ErrNotExist}
|
||||
}
|
||||
return ioutil.NopCloser(strings.NewReader(v)), nil
|
||||
}
|
||||
|
||||
type staticFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
mod time.Time
|
||||
}
|
||||
|
||||
func (fi staticFileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
|
||||
func (fi staticFileInfo) Size() int64 {
|
||||
return fi.size
|
||||
}
|
||||
|
||||
func (fi staticFileInfo) Mode() os.FileMode {
|
||||
return fi.mode
|
||||
}
|
||||
|
||||
func (fi staticFileInfo) ModTime() time.Time {
|
||||
return fi.mod
|
||||
}
|
||||
|
||||
func (fi staticFileInfo) IsDir() bool {
|
||||
return fi.mode.IsDir()
|
||||
}
|
||||
|
||||
func (fi staticFileInfo) Sys() interface{} {
|
||||
return fi
|
||||
}
|
632
vendor/modernc.org/cc/v3/inspect.go
generated
vendored
632
vendor/modernc.org/cc/v3/inspect.go
generated
vendored
|
@ -1,632 +0,0 @@
|
|||
// Copyright 2020 The CC Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cc // import "modernc.org/cc/v3"
|
||||
|
||||
// Inspect inspects AST node trees.
|
||||
//
|
||||
// If n is a non-terminal node, f(n, true) is called first. Next, f is called
|
||||
// recursively for each of n's non-nil non-terminal children nodes, if any, in
|
||||
// alphabetical order. Next, all n's terminal nodes, if any, are visited in
|
||||
// the numeric order of their suffixes (Token, Token2, Token3, ...). Finally,
|
||||
// f(n, false) is invoked.
|
||||
//
|
||||
// If n a terminal node, of type *Token, f(n, <unspecified boolean value> is
|
||||
// called once.
|
||||
//
|
||||
// Inspect stops when any invocation of f returns false.
|
||||
func Inspect(n Node, f func(Node, bool) bool) {
|
||||
see(n, f)
|
||||
}
|
||||
|
||||
func see(n Node, f func(Node, bool) bool) bool {
|
||||
switch x := n.(type) {
|
||||
case *AbstractDeclarator:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.DirectAbstractDeclarator, f) &&
|
||||
see(x.Pointer, f) &&
|
||||
f(x, false)
|
||||
case *AdditiveExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AdditiveExpression, f) &&
|
||||
see(x.MultiplicativeExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *AlignmentSpecifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ConstantExpression, f) &&
|
||||
see(x.TypeName, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *AndExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AndExpression, f) &&
|
||||
see(x.EqualityExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *ArgumentExpressionList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ArgumentExpressionList, f) &&
|
||||
see(x.AssignmentExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *Asm:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AsmArgList, f) &&
|
||||
see(x.AsmQualifierList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
see(&x.Token4, f) &&
|
||||
f(x, false)
|
||||
case *AsmArgList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AsmArgList, f) &&
|
||||
see(x.AsmExpressionList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *AsmExpressionList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AsmExpressionList, f) &&
|
||||
see(x.AsmIndex, f) &&
|
||||
see(x.AssignmentExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *AsmFunctionDefinition:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AsmStatement, f) &&
|
||||
see(x.DeclarationSpecifiers, f) &&
|
||||
see(x.Declarator, f) &&
|
||||
f(x, false)
|
||||
case *AsmIndex:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Expression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *AsmQualifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *AsmQualifierList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AsmQualifier, f) &&
|
||||
see(x.AsmQualifierList, f) &&
|
||||
f(x, false)
|
||||
case *AsmStatement:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Asm, f) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *AssignmentExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AssignmentExpression, f) &&
|
||||
see(x.ConditionalExpression, f) &&
|
||||
see(x.UnaryExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *AtomicTypeSpecifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.TypeName, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *AttributeSpecifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeValueList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
see(&x.Token4, f) &&
|
||||
see(&x.Token5, f) &&
|
||||
f(x, false)
|
||||
case *AttributeSpecifierList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifier, f) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
f(x, false)
|
||||
case *AttributeValue:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ExpressionList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *AttributeValueList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeValue, f) &&
|
||||
see(x.AttributeValueList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *BlockItem:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.CompoundStatement, f) &&
|
||||
see(x.Declaration, f) &&
|
||||
see(x.DeclarationSpecifiers, f) &&
|
||||
see(x.Declarator, f) &&
|
||||
see(x.LabelDeclaration, f) &&
|
||||
see(x.PragmaSTDC, f) &&
|
||||
see(x.Statement, f) &&
|
||||
f(x, false)
|
||||
case *BlockItemList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.BlockItem, f) &&
|
||||
see(x.BlockItemList, f) &&
|
||||
f(x, false)
|
||||
case *CastExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.CastExpression, f) &&
|
||||
see(x.TypeName, f) &&
|
||||
see(x.UnaryExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *CompoundStatement:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.BlockItemList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *ConditionalExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ConditionalExpression, f) &&
|
||||
see(x.Expression, f) &&
|
||||
see(x.LogicalOrExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *ConstantExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ConditionalExpression, f) &&
|
||||
f(x, false)
|
||||
case *Declaration:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.DeclarationSpecifiers, f) &&
|
||||
see(x.InitDeclaratorList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *DeclarationList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Declaration, f) &&
|
||||
see(x.DeclarationList, f) &&
|
||||
f(x, false)
|
||||
case *DeclarationSpecifiers:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AlignmentSpecifier, f) &&
|
||||
see(x.AttributeSpecifier, f) &&
|
||||
see(x.DeclarationSpecifiers, f) &&
|
||||
see(x.FunctionSpecifier, f) &&
|
||||
see(x.StorageClassSpecifier, f) &&
|
||||
see(x.TypeQualifier, f) &&
|
||||
see(x.TypeSpecifier, f) &&
|
||||
f(x, false)
|
||||
case *Declarator:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.DirectDeclarator, f) &&
|
||||
see(x.Pointer, f) &&
|
||||
f(x, false)
|
||||
case *Designation:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.DesignatorList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *Designator:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ConstantExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *DesignatorList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Designator, f) &&
|
||||
see(x.DesignatorList, f) &&
|
||||
f(x, false)
|
||||
case *DirectAbstractDeclarator:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AbstractDeclarator, f) &&
|
||||
see(x.AssignmentExpression, f) &&
|
||||
see(x.DirectAbstractDeclarator, f) &&
|
||||
see(x.ParameterTypeList, f) &&
|
||||
see(x.TypeQualifiers, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *DirectDeclarator:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Asm, f) &&
|
||||
see(x.AssignmentExpression, f) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.Declarator, f) &&
|
||||
see(x.DirectDeclarator, f) &&
|
||||
see(x.IdentifierList, f) &&
|
||||
see(x.ParameterTypeList, f) &&
|
||||
see(x.TypeQualifiers, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *EnumSpecifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.EnumeratorList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
see(&x.Token4, f) &&
|
||||
see(&x.Token5, f) &&
|
||||
f(x, false)
|
||||
case *Enumerator:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.ConstantExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *EnumeratorList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Enumerator, f) &&
|
||||
see(x.EnumeratorList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *EqualityExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.EqualityExpression, f) &&
|
||||
see(x.RelationalExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *ExclusiveOrExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AndExpression, f) &&
|
||||
see(x.ExclusiveOrExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *Expression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AssignmentExpression, f) &&
|
||||
see(x.Expression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *ExpressionList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AssignmentExpression, f) &&
|
||||
see(x.ExpressionList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *ExpressionStatement:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.Expression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *ExternalDeclaration:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AsmFunctionDefinition, f) &&
|
||||
see(x.AsmStatement, f) &&
|
||||
see(x.Declaration, f) &&
|
||||
see(x.FunctionDefinition, f) &&
|
||||
see(x.PragmaSTDC, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *FunctionDefinition:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.CompoundStatement, f) &&
|
||||
see(x.DeclarationList, f) &&
|
||||
see(x.DeclarationSpecifiers, f) &&
|
||||
see(x.Declarator, f) &&
|
||||
f(x, false)
|
||||
case *FunctionSpecifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *IdentifierList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.IdentifierList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *InclusiveOrExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ExclusiveOrExpression, f) &&
|
||||
see(x.InclusiveOrExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *InitDeclarator:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.Declarator, f) &&
|
||||
see(x.Initializer, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *InitDeclaratorList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.InitDeclarator, f) &&
|
||||
see(x.InitDeclaratorList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *Initializer:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AssignmentExpression, f) &&
|
||||
see(x.InitializerList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *InitializerList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Designation, f) &&
|
||||
see(x.Initializer, f) &&
|
||||
see(x.InitializerList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *IterationStatement:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Declaration, f) &&
|
||||
see(x.Expression, f) &&
|
||||
see(x.Expression2, f) &&
|
||||
see(x.Expression3, f) &&
|
||||
see(x.Statement, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
see(&x.Token4, f) &&
|
||||
see(&x.Token5, f) &&
|
||||
f(x, false)
|
||||
case *JumpStatement:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Expression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *LabelDeclaration:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.IdentifierList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *LabeledStatement:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.ConstantExpression, f) &&
|
||||
see(x.ConstantExpression2, f) &&
|
||||
see(x.Statement, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *LogicalAndExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.InclusiveOrExpression, f) &&
|
||||
see(x.LogicalAndExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *LogicalOrExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.LogicalAndExpression, f) &&
|
||||
see(x.LogicalOrExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *MultiplicativeExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.CastExpression, f) &&
|
||||
see(x.MultiplicativeExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *ParameterDeclaration:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AbstractDeclarator, f) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.DeclarationSpecifiers, f) &&
|
||||
see(x.Declarator, f) &&
|
||||
f(x, false)
|
||||
case *ParameterList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ParameterDeclaration, f) &&
|
||||
see(x.ParameterList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *ParameterTypeList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ParameterList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *Pointer:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Pointer, f) &&
|
||||
see(x.TypeQualifiers, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *PostfixExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ArgumentExpressionList, f) &&
|
||||
see(x.Expression, f) &&
|
||||
see(x.InitializerList, f) &&
|
||||
see(x.PostfixExpression, f) &&
|
||||
see(x.PrimaryExpression, f) &&
|
||||
see(x.TypeName, f) &&
|
||||
see(x.TypeName2, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
see(&x.Token4, f) &&
|
||||
see(&x.Token5, f) &&
|
||||
f(x, false)
|
||||
case *PragmaSTDC:
|
||||
return x == nil || f(x, true) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
see(&x.Token4, f) &&
|
||||
f(x, false)
|
||||
case *PrimaryExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.CompoundStatement, f) &&
|
||||
see(x.Expression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
f(x, false)
|
||||
case *RelationalExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.RelationalExpression, f) &&
|
||||
see(x.ShiftExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *SelectionStatement:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.Expression, f) &&
|
||||
see(x.Statement, f) &&
|
||||
see(x.Statement2, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
see(&x.Token4, f) &&
|
||||
f(x, false)
|
||||
case *ShiftExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AdditiveExpression, f) &&
|
||||
see(x.ShiftExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *SpecifierQualifierList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AlignmentSpecifier, f) &&
|
||||
see(x.AttributeSpecifier, f) &&
|
||||
see(x.SpecifierQualifierList, f) &&
|
||||
see(x.TypeQualifier, f) &&
|
||||
see(x.TypeSpecifier, f) &&
|
||||
f(x, false)
|
||||
case *Statement:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AsmStatement, f) &&
|
||||
see(x.CompoundStatement, f) &&
|
||||
see(x.ExpressionStatement, f) &&
|
||||
see(x.IterationStatement, f) &&
|
||||
see(x.JumpStatement, f) &&
|
||||
see(x.LabeledStatement, f) &&
|
||||
see(x.SelectionStatement, f) &&
|
||||
f(x, false)
|
||||
case *StorageClassSpecifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *StructDeclaration:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.SpecifierQualifierList, f) &&
|
||||
see(x.StructDeclaratorList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *StructDeclarationList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.StructDeclaration, f) &&
|
||||
see(x.StructDeclarationList, f) &&
|
||||
f(x, false)
|
||||
case *StructDeclarator:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.ConstantExpression, f) &&
|
||||
see(x.Declarator, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *StructDeclaratorList:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.StructDeclarator, f) &&
|
||||
see(x.StructDeclaratorList, f) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *StructOrUnion:
|
||||
return x == nil || f(x, true) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *StructOrUnionSpecifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifierList, f) &&
|
||||
see(x.StructDeclarationList, f) &&
|
||||
see(x.StructOrUnion, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *TranslationUnit:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.ExternalDeclaration, f) &&
|
||||
see(x.TranslationUnit, f) &&
|
||||
f(x, false)
|
||||
case *TypeName:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AbstractDeclarator, f) &&
|
||||
see(x.SpecifierQualifierList, f) &&
|
||||
f(x, false)
|
||||
case *TypeQualifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(&x.Token, f) &&
|
||||
f(x, false)
|
||||
case *TypeQualifiers:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AttributeSpecifier, f) &&
|
||||
see(x.TypeQualifier, f) &&
|
||||
see(x.TypeQualifiers, f) &&
|
||||
f(x, false)
|
||||
case *TypeSpecifier:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.AtomicTypeSpecifier, f) &&
|
||||
see(x.EnumSpecifier, f) &&
|
||||
see(x.Expression, f) &&
|
||||
see(x.StructOrUnionSpecifier, f) &&
|
||||
see(x.TypeName, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *UnaryExpression:
|
||||
return x == nil || f(x, true) &&
|
||||
see(x.CastExpression, f) &&
|
||||
see(x.PostfixExpression, f) &&
|
||||
see(x.TypeName, f) &&
|
||||
see(x.UnaryExpression, f) &&
|
||||
see(&x.Token, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token2, f) &&
|
||||
see(&x.Token3, f) &&
|
||||
f(x, false)
|
||||
case *Token:
|
||||
return f(x, true)
|
||||
default:
|
||||
panic(todo("internal error: %T", x))
|
||||
}
|
||||
}
|
1555
vendor/modernc.org/cc/v3/lexer.go
generated
vendored
1555
vendor/modernc.org/cc/v3/lexer.go
generated
vendored
File diff suppressed because it is too large
Load diff
97
vendor/modernc.org/cc/v3/lexer.l
generated
vendored
97
vendor/modernc.org/cc/v3/lexer.l
generated
vendored
|
@ -1,97 +0,0 @@
|
|||
%{
|
||||
// Copyright 2019 The CC Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
%}
|
||||
|
||||
%yyc c
|
||||
%yyn c = s.next()
|
||||
%yym s.mark = len(s.charBuf)
|
||||
|
||||
%{
|
||||
package cc // import "modernc.org/cc/v3"
|
||||
|
||||
func (s *scanner) scan() (r rune) {
|
||||
%}
|
||||
|
||||
c-char [^'\n\x80\\]|{escape-sequence}
|
||||
c-char-sequence {c-char}+
|
||||
character-constant '{c-char-sequence}'
|
||||
comment "/*"([^*\x80]|\*+[^*/\x80])*\*+\/
|
||||
comment-not-terminated "/*"([^*\x80]|\*+[^*/\x80])*(\*+)?\n\x80
|
||||
digit [0-9]
|
||||
escape-sequence {simple-sequence}|{octal-escape-sequence}|{hexadecimal-escape-sequence}|{universal-character-name}
|
||||
hex-quad {hexadecimal-digit}{hexadecimal-digit}{hexadecimal-digit}{hexadecimal-digit}
|
||||
hexadecimal-digit [0-9a-fA-F]
|
||||
hexadecimal-escape-sequence \\x{hexadecimal-digit}+
|
||||
identifier {identifier-nondigit}({identifier-nondigit}|{digit}|"$")*
|
||||
identifier-nondigit {nondigit}|"$"|{universal-character-name}
|
||||
line-comment "//"[^\n\x80]*
|
||||
nondigit [_a-zA-Z\x81]
|
||||
octal-digit [0-7]
|
||||
octal-escape-sequence \\{octal-digit}{octal-digit}?{octal-digit}?
|
||||
pp-number ({digit}|\.{digit})({digit}|{identifier-nondigit}|[eEpP]{sign}|\.)*
|
||||
s-char [^\x22\n\x80\\]|{escape-sequence}
|
||||
s-char-sequence {s-char}+
|
||||
sign [-+]
|
||||
simple-sequence \\['\x22?\\abefnrtv]
|
||||
string-literal \x22{s-char-sequence}?\x22
|
||||
universal-character-name \\u{hex-quad}|\\U{hex-quad}{hex-quad}
|
||||
white-space [ \t\f\v]
|
||||
|
||||
%%
|
||||
c := s.initScan()
|
||||
|
||||
({white-space}|{comment})*{line-comment} |
|
||||
({white-space}|{comment})+{line-comment}?
|
||||
return ' '
|
||||
|
||||
(({white-space}|{comment})*{comment-not-terminated})+
|
||||
return s.unterminatedComment()
|
||||
|
||||
"!=" return NEQ
|
||||
"##" return PPPASTE
|
||||
"%:" return '#'
|
||||
"%:%:" return PPPASTE
|
||||
"%=" return MODASSIGN
|
||||
"%>" return '}'
|
||||
"&&" return ANDAND
|
||||
"&=" return ANDASSIGN
|
||||
"*=" return MULASSIGN
|
||||
"++" return INC
|
||||
"+=" return ADDASSIGN
|
||||
"--" return DEC
|
||||
"-=" return SUBASSIGN
|
||||
"->" return ARROW
|
||||
"..." return DDD
|
||||
"/=" return DIVASSIGN
|
||||
":>" return ']'
|
||||
"<%" return '{'
|
||||
"<:" return '['
|
||||
"<<" return LSH
|
||||
"<<=" return LSHASSIGN
|
||||
"<=" return LEQ
|
||||
"==" return EQ
|
||||
">=" return GEQ
|
||||
">>" return RSH
|
||||
">>=" return RSHASSIGN
|
||||
"^=" return XORASSIGN
|
||||
"|=" return ORASSIGN
|
||||
"||" return OROR
|
||||
|
||||
L{string-literal} return LONGSTRINGLITERAL
|
||||
L{character-constant} return LONGCHARCONST
|
||||
{character-constant} return CHARCONST
|
||||
{identifier} return IDENTIFIER
|
||||
{pp-number} return PPNUMBER
|
||||
{string-literal} return STRINGLITERAL
|
||||
|
||||
\r?\n return '\n'
|
||||
|
||||
%%
|
||||
if c, ok := s.abort(); ok {
|
||||
return rune(c)
|
||||
}
|
||||
|
||||
goto yyAction
|
||||
}
|
1337
vendor/modernc.org/cc/v3/operand.go
generated
vendored
1337
vendor/modernc.org/cc/v3/operand.go
generated
vendored
File diff suppressed because it is too large
Load diff
4311
vendor/modernc.org/cc/v3/parser.go
generated
vendored
4311
vendor/modernc.org/cc/v3/parser.go
generated
vendored
File diff suppressed because it is too large
Load diff
1033
vendor/modernc.org/cc/v3/parser.yy
generated
vendored
1033
vendor/modernc.org/cc/v3/parser.yy
generated
vendored
File diff suppressed because it is too large
Load diff
1266
vendor/modernc.org/cc/v3/scanner.go
generated
vendored
1266
vendor/modernc.org/cc/v3/scanner.go
generated
vendored
File diff suppressed because it is too large
Load diff
99
vendor/modernc.org/cc/v3/stringer.go
generated
vendored
99
vendor/modernc.org/cc/v3/stringer.go
generated
vendored
|
@ -1,99 +0,0 @@
|
|||
// Code generated by "stringer -output stringer.go -linecomment -type=Kind,Linkage"; DO NOT EDIT.
|
||||
|
||||
package cc
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[Invalid-0]
|
||||
_ = x[Array-1]
|
||||
_ = x[Bool-2]
|
||||
_ = x[Char-3]
|
||||
_ = x[ComplexChar-4]
|
||||
_ = x[ComplexDouble-5]
|
||||
_ = x[ComplexFloat-6]
|
||||
_ = x[ComplexInt-7]
|
||||
_ = x[ComplexLong-8]
|
||||
_ = x[ComplexLongDouble-9]
|
||||
_ = x[ComplexLongLong-10]
|
||||
_ = x[ComplexShort-11]
|
||||
_ = x[ComplexUInt-12]
|
||||
_ = x[ComplexULong-13]
|
||||
_ = x[ComplexULongLong-14]
|
||||
_ = x[ComplexUShort-15]
|
||||
_ = x[Decimal128-16]
|
||||
_ = x[Decimal32-17]
|
||||
_ = x[Decimal64-18]
|
||||
_ = x[Double-19]
|
||||
_ = x[Enum-20]
|
||||
_ = x[Float-21]
|
||||
_ = x[Float128-22]
|
||||
_ = x[Float32-23]
|
||||
_ = x[Float32x-24]
|
||||
_ = x[Float64-25]
|
||||
_ = x[Float64x-26]
|
||||
_ = x[Function-27]
|
||||
_ = x[Int-28]
|
||||
_ = x[Int8-29]
|
||||
_ = x[Int16-30]
|
||||
_ = x[Int32-31]
|
||||
_ = x[Int64-32]
|
||||
_ = x[Int128-33]
|
||||
_ = x[Long-34]
|
||||
_ = x[LongDouble-35]
|
||||
_ = x[LongLong-36]
|
||||
_ = x[Ptr-37]
|
||||
_ = x[SChar-38]
|
||||
_ = x[Short-39]
|
||||
_ = x[Struct-40]
|
||||
_ = x[TypedefName-41]
|
||||
_ = x[UChar-42]
|
||||
_ = x[UInt-43]
|
||||
_ = x[UInt8-44]
|
||||
_ = x[UInt16-45]
|
||||
_ = x[UInt32-46]
|
||||
_ = x[UInt64-47]
|
||||
_ = x[UInt128-48]
|
||||
_ = x[ULong-49]
|
||||
_ = x[ULongLong-50]
|
||||
_ = x[UShort-51]
|
||||
_ = x[Union-52]
|
||||
_ = x[Void-53]
|
||||
_ = x[Vector-54]
|
||||
_ = x[typeofExpr-55]
|
||||
_ = x[typeofType-56]
|
||||
_ = x[maxKind-57]
|
||||
}
|
||||
|
||||
const _Kind_name = "InvalidT[]_Boolcharcomplex charcomplex doublecomplex floatcomplex intcomplex longcomplex long doublecomplex long longcomplex shortcomplex unsignedcomplex unsigned longcomplex unsigned long longcomplex shor_Decimal128_Decimal32_Decimal64doubleenumfloat_Float128_Float32_Float32x_Float64_Float64xfunctionint__int8__int16__int32__int64__int128longlong doublelong longpointersigned charshortstructtypedefnameunsigned charunsignedunsigned __int8unsigned __int16unsigned __int32unsigned __int64unsigned __int128unsigned longunsigned long longunsigned shortunionvoidvectortypeofExprtypeofTypemaxKind"
|
||||
|
||||
var _Kind_index = [...]uint16{0, 7, 10, 15, 19, 31, 45, 58, 69, 81, 100, 117, 130, 146, 167, 193, 205, 216, 226, 236, 242, 246, 251, 260, 268, 277, 285, 294, 302, 305, 311, 318, 325, 332, 340, 344, 355, 364, 371, 382, 387, 393, 404, 417, 425, 440, 456, 472, 488, 505, 518, 536, 550, 555, 559, 565, 575, 585, 592}
|
||||
|
||||
func (i Kind) String() string {
|
||||
if i >= Kind(len(_Kind_index)-1) {
|
||||
return "Kind(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Kind_name[_Kind_index[i]:_Kind_index[i+1]]
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[None-0]
|
||||
_ = x[Internal-1]
|
||||
_ = x[External-2]
|
||||
}
|
||||
|
||||
const _Linkage_name = "NoneInternalExternal"
|
||||
|
||||
var _Linkage_index = [...]uint8{0, 4, 12, 20}
|
||||
|
||||
func (i Linkage) String() string {
|
||||
if i < 0 || i >= Linkage(len(_Linkage_index)-1) {
|
||||
return "Linkage(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Linkage_name[_Linkage_index[i]:_Linkage_index[i+1]]
|
||||
}
|
3266
vendor/modernc.org/cc/v3/type.go
generated
vendored
3266
vendor/modernc.org/cc/v3/type.go
generated
vendored
File diff suppressed because it is too large
Load diff
4
vendor/modernc.org/cc/v3/unconvert.sh
generated
vendored
4
vendor/modernc.org/cc/v3/unconvert.sh
generated
vendored
|
@ -1,4 +0,0 @@
|
|||
until unconvert -fastmath . &> /dev/null
|
||||
do
|
||||
unconvert -fastmath -apply . &> /dev/null
|
||||
done
|
27
vendor/modernc.org/ccgo/v3/LICENSE
generated
vendored
27
vendor/modernc.org/ccgo/v3/LICENSE
generated
vendored
|
@ -1,27 +0,0 @@
|
|||
Copyright (c) 2017 The CCGO Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the names of the authors nor the names of the
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
141
vendor/modernc.org/ccgo/v3/lib/Makefile
generated
vendored
141
vendor/modernc.org/ccgo/v3/lib/Makefile
generated
vendored
|
@ -1,141 +0,0 @@
|
|||
# Copyright 2019 The CCGO Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
.PHONY: all bench clean cover cpu editor internalError later mem nuke todo edit devbench
|
||||
|
||||
grep=--include=*.go
|
||||
ngrep='TODOOK\|internalError\|testdata'
|
||||
testlog=testdata/testlog-$(shell echo $$GOOS)-$(shell echo $$GOARCH)-on-$(shell go env GOOS)-$(shell go env GOARCH)
|
||||
|
||||
all:
|
||||
LC_ALL=C make all_log 2>&1 | tee log
|
||||
|
||||
all_log:
|
||||
date
|
||||
go version
|
||||
uname -a
|
||||
./unconvert.sh
|
||||
gofmt -l -s -w *.go
|
||||
GOOS=darwin GOARCH=amd64 go build -o /dev/null
|
||||
GOOS=linux GOARCH=386 go build -o /dev/null
|
||||
GOOS=linux GOARCH=amd64 go build -o /dev/null
|
||||
GOOS=linux GOARCH=arm go build -o /dev/null
|
||||
GOOS=windows GOARCH=386 go build -o /dev/null
|
||||
GOOS=windows GOARCH=amd64 go build -o /dev/null
|
||||
go vet 2>&1 | grep -v $(ngrep) || true
|
||||
golint 2>&1 | grep -v $(ngrep) || true
|
||||
make todo
|
||||
misspell *.go
|
||||
staticcheck | grep -v 'lexer\.go' || true
|
||||
maligned || true
|
||||
grep -n 'files.*, ok' log
|
||||
@grep -n --color=never 'FAIL\|PASS' log
|
||||
@grep -n --color=always 'FAIL' log
|
||||
grep -n --color=always 'nil pointer' log
|
||||
grep -c 'exit status 1' log || true
|
||||
grep -c 'exit status 2' log || true
|
||||
LC_ALL=C date 2>&1 | tee -a log
|
||||
|
||||
test:
|
||||
LC_ALL=C make test_log 2>&1 | tee $(testlog)
|
||||
grep -ni --color=always fail $(testlog) || true
|
||||
|
||||
test_log:
|
||||
go version
|
||||
uname -a
|
||||
go test -v -timeout 24h
|
||||
date | tee -a $(testlog)
|
||||
|
||||
test_linux_amd64:
|
||||
GOOS=linux GOARCH=amd64 make test
|
||||
|
||||
test_linux_386:
|
||||
GOOS=linux GOARCH=386 make test
|
||||
|
||||
test_linux_arm:
|
||||
GOOS=linux GOARCH=arm make test
|
||||
|
||||
test_linux_arm64:
|
||||
GOOS=linux GOARCH=arm64 make test
|
||||
|
||||
test_windows_386:
|
||||
go version | tee %TEMP%\testlog-windows-386
|
||||
go test -v -timeout 24h | tee -a %TEMP%\testlog-windows-386
|
||||
date /T | tee -a %TEMP%\testlog-windows-386
|
||||
time /T | tee -a %TEMP%\testlog-windows-386
|
||||
|
||||
test_windows_amd64:
|
||||
go version | tee %TEMP%\testlog-windows-amd64
|
||||
go test -v -timeout 24h | tee -a %TEMP%\testlog-windows-amd64
|
||||
date /T | tee -a %TEMP%\testlog-windows-amd64
|
||||
time /T | tee -a %TEMP%\testlog-windows-amd64
|
||||
|
||||
build_all_targets:
|
||||
GOOS=darwin GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=darwin GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=arm go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=arm go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=riscv64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=s390x go test -c -o /dev/null
|
||||
GOOS=netbsd GOARCH=amd64 go test -c -o /dev/null
|
||||
#TODO GOOS=netbsd GOARCH=arm go test -c -o /dev/null
|
||||
GOOS=openbsd GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=openbsd GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=windows GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=windows GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=windows GOARCH=arm64 go test -c -o /dev/null
|
||||
|
||||
devbench:
|
||||
date 2>&1 | tee log-devbench
|
||||
go test -timeout 24h -dev -run @ -bench . 2>&1 | tee -a log-devbench
|
||||
grep -n 'FAIL\|SKIP' log-devbench || true
|
||||
|
||||
bench:
|
||||
date 2>&1 | tee log-bench
|
||||
go test -timeout 24h -v -run '^[^E]' -bench . 2>&1 | tee -a log-bench
|
||||
grep -n 'FAIL\|SKIP' log-bench || true
|
||||
|
||||
clean:
|
||||
go clean
|
||||
rm -f *~ *.test *.out
|
||||
|
||||
cover:
|
||||
t=$(shell mktemp) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t
|
||||
|
||||
cpu: clean
|
||||
go test -run @ -bench . -cpuprofile cpu.out
|
||||
go tool pprof -lines *.test cpu.out
|
||||
|
||||
edit:
|
||||
@touch log
|
||||
@if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile *.go & fi
|
||||
|
||||
|
||||
editor:
|
||||
gofmt -l -s -w *.go
|
||||
go build -v -o $(GOPATH)/bin/ccgo3 modernc.org/ccgo/v3
|
||||
go test -c -o /dev/null
|
||||
|
||||
later:
|
||||
@grep -n $(grep) LATER * || true
|
||||
@grep -n $(grep) MAYBE * || true
|
||||
|
||||
mem: clean
|
||||
go test -run Mem -mem -memprofile mem.out -timeout 24h
|
||||
go tool pprof -lines -web -alloc_space *.test mem.out
|
||||
|
||||
nuke: clean
|
||||
go clean -i
|
||||
|
||||
todo:
|
||||
@grep -nr $(grep) ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) 'TODO\|panic' * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) BUG * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) [^[:alpha:]]println * | grep -v $(ngrep) || true
|
||||
@grep -nir $(grep) 'work.*progress' || true
|
2148
vendor/modernc.org/ccgo/v3/lib/ccgo.go
generated
vendored
2148
vendor/modernc.org/ccgo/v3/lib/ccgo.go
generated
vendored
File diff suppressed because it is too large
Load diff
39
vendor/modernc.org/ccgo/v3/lib/cover.go
generated
vendored
39
vendor/modernc.org/ccgo/v3/lib/cover.go
generated
vendored
|
@ -1,39 +0,0 @@
|
|||
// Copyright 2020 The CCGO Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ccgo // import "modernc.org/ccgo/v3/lib"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
coverMap = map[uintptr]struct{}{}
|
||||
)
|
||||
|
||||
func pc2origin(pc uintptr) string {
|
||||
f := runtime.FuncForPC(pc)
|
||||
var fn, fns string
|
||||
var fl int
|
||||
if f != nil {
|
||||
fn, fl = f.FileLine(pc)
|
||||
fns = f.Name()
|
||||
if x := strings.LastIndex(fns, "."); x > 0 {
|
||||
fns = fns[x+1:]
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s:%d:%s", fn, fl, fns)
|
||||
}
|
||||
|
||||
func coverReport() string {
|
||||
var a []string
|
||||
for pc := range coverMap {
|
||||
a = append(a, pc2origin(pc))
|
||||
}
|
||||
sort.Strings(a)
|
||||
return strings.Join(a, "\n")
|
||||
}
|
91
vendor/modernc.org/ccgo/v3/lib/design-notes.adoc
generated
vendored
91
vendor/modernc.org/ccgo/v3/lib/design-notes.adoc
generated
vendored
|
@ -1,91 +0,0 @@
|
|||
= Design Notes
|
||||
|
||||
== Problems:
|
||||
|
||||
Translating C to Go is harder than it looks.
|
||||
|
||||
Jan says: It's impossible in the general case to turn C char* into Go
|
||||
[]byte. It's possible to do it probably often for concrete C code
|
||||
cases - based also on author's C coding style. The first problem this
|
||||
runs into is that Go does not guarantee that the backing array will
|
||||
keep its address stable due to Go movable stacks. C expects the
|
||||
opposite, a pointer never magically modifies itself, so some code will
|
||||
fail.
|
||||
|
||||
INSERT CODE EXAMPLES ILLUSTRATING THE PROBLEM HERE
|
||||
|
||||
== How the parser works
|
||||
|
||||
There are no comment nodes in the C AST. Instead every cc.Token has a
|
||||
Sep field: https://godoc.org/modernc.org/cc/v3#Token
|
||||
|
||||
It captures, when configured to do so, all white space preceding the
|
||||
token, combined, including comments, if any. So we have all white
|
||||
space/comments information for every token in the AST. A final white
|
||||
space/comment, preceding EOF, is available as field TrailingSeperator
|
||||
in the AST: https://godoc.org/modernc.org/cc/v3#AST.
|
||||
|
||||
To get the lexically first white space/comment for any node, use
|
||||
tokenSeparator():
|
||||
https://gitlab.com/cznic/ccgo/-/blob/6551e2544a758fdc265c8fac71fb2587fb3e1042/v3/go.go#L1476
|
||||
|
||||
The same with a default value is comment():
|
||||
https://gitlab.com/cznic/ccgo/-/blob/6551e2544a758fdc265c8fac71fb2587fb3e1042/v3/go.go#L1467
|
||||
|
||||
== Looking forward
|
||||
|
||||
Eric says: In my visualization of how the translator would work, the
|
||||
output of a ccgo translation of a module at any given time is a file
|
||||
of pseudo-Go code in which some sections may be enclosed by a Unicode
|
||||
bracketing character (presently using the guillemot quotes U+ab and
|
||||
U+bb) meaning "this is not Go yet" that intentionally makes the Go
|
||||
compiler barf. This expresses a color on the AST nodes.
|
||||
|
||||
So, for example, if I'm translating hello.c with a ruleset that does not
|
||||
include print -> fmt.Printf, this:
|
||||
|
||||
---------------------------------------------------------
|
||||
#include <stdio>
|
||||
|
||||
/* an example comment */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("Hello, World")
|
||||
}
|
||||
---------------------------------------------------------
|
||||
|
||||
becomes this without any explicit rules at all:
|
||||
|
||||
---------------------------------------------------------
|
||||
«#include <stdio>»
|
||||
|
||||
/* an example comment */
|
||||
|
||||
func main
|
||||
{
|
||||
«printf(»"Hello, World"!\n"«)»
|
||||
}
|
||||
---------------------------------------------------------
|
||||
|
||||
Then, when the rule print -> fmt.Printf is added, it becomes
|
||||
|
||||
---------------------------------------------------------
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
/* an example comment */
|
||||
|
||||
func main
|
||||
{
|
||||
fmt.Printf("Hello, World"!\n")
|
||||
}
|
||||
---------------------------------------------------------
|
||||
|
||||
because with that rule the AST node corresponding to the printf
|
||||
call can be translated and colored "Go". This implies an import
|
||||
of fmt. We observe that there are no longer C-colored spans
|
||||
and drop the #includes.
|
||||
|
||||
// end
|
43
vendor/modernc.org/ccgo/v3/lib/dmesg.go
generated
vendored
43
vendor/modernc.org/ccgo/v3/lib/dmesg.go
generated
vendored
|
@ -1,43 +0,0 @@
|
|||
// Copyright 2021 The CCGO Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build ccgo.dmesg
|
||||
// +build ccgo.dmesg
|
||||
|
||||
package ccgo // import "modernc.org/ccgo/v3/lib"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const dmesgs = true
|
||||
|
||||
var (
|
||||
pid = fmt.Sprintf("[%v %v] ", os.Getpid(), filepath.Base(os.Args[0]))
|
||||
logf *os.File
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
if logf, err = os.OpenFile("/tmp/ccgo.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY|os.O_SYNC, 0644); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func dmesg(s string, args ...interface{}) {
|
||||
if s == "" {
|
||||
s = strings.Repeat("%v ", len(args))
|
||||
}
|
||||
s = fmt.Sprintf(s, args...)
|
||||
s = pid + s
|
||||
switch {
|
||||
case len(s) != 0 && s[len(s)-1] == '\n':
|
||||
fmt.Fprint(logf, s)
|
||||
default:
|
||||
fmt.Fprintln(logf, s)
|
||||
}
|
||||
}
|
110
vendor/modernc.org/ccgo/v3/lib/etc.go
generated
vendored
110
vendor/modernc.org/ccgo/v3/lib/etc.go
generated
vendored
|
@ -1,110 +0,0 @@
|
|||
// Copyright 2020 The CCGO Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ccgo // import "modernc.org/ccgo/v3/lib"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
|
||||
"modernc.org/cc/v3"
|
||||
)
|
||||
|
||||
var (
|
||||
reservedNames = map[string]bool{
|
||||
"bool": false, // ccgo can use
|
||||
"break": true, // keyword
|
||||
"case": true, // keyword
|
||||
"chan": true, // keyword
|
||||
"const": true, // keyword
|
||||
"continue": true, // keyword
|
||||
"default": true, // keyword
|
||||
"defer": true, // keyword
|
||||
"else": true, // keyword
|
||||
"fallthrough": true, // keyword
|
||||
"false": false, // ccgo can use
|
||||
"float32": false, // ccgo can use
|
||||
"float64": false, // ccgo can use
|
||||
"for": true, // keyword
|
||||
"func": true, // keyword
|
||||
"go": true, // keyword
|
||||
"goto": true, // keyword
|
||||
"if": true, // keyword
|
||||
"import": true, // keyword
|
||||
"init": false, // special name
|
||||
"int16": false, // ccgo can use
|
||||
"int32": false, // ccgo can use
|
||||
"int64": false, // ccgo can use
|
||||
"int8": false, // ccgo can use
|
||||
"interface": true, // keyword
|
||||
"map": true, // keyword
|
||||
"math": false, // package name
|
||||
"nil": false, // ccgo can use
|
||||
"package": true, // keyword
|
||||
"range": true, // keyword
|
||||
"return": true, // keyword
|
||||
"select": true, // keyword
|
||||
"struct": true, // keyword
|
||||
"switch": true, // keyword
|
||||
"true": false, // ccgo can use
|
||||
"type": true, // keyword
|
||||
"types": false, // package name
|
||||
"uint16": false, // ccgo can use
|
||||
"uint32": false, // ccgo can use
|
||||
"uint64": false, // ccgo can use
|
||||
"uint8": false, // ccgo can use
|
||||
"uintptr": false, // ccgo can use
|
||||
"unsafe": false, // package name
|
||||
"var": true, // keyword
|
||||
}
|
||||
|
||||
reservedIds []cc.StringID
|
||||
|
||||
maxInt32 = big.NewInt(math.MaxInt32)
|
||||
maxInt64 = big.NewInt(math.MaxInt64)
|
||||
maxUint32 = big.NewInt(math.MaxUint32)
|
||||
maxUint64 = big.NewInt(0).SetUint64(math.MaxUint64)
|
||||
minInt32 = big.NewInt(math.MinInt32)
|
||||
minInt64 = big.NewInt(math.MinInt64)
|
||||
)
|
||||
|
||||
func init() {
|
||||
for k := range reservedNames {
|
||||
reservedIds = append(reservedIds, cc.String(k))
|
||||
}
|
||||
}
|
||||
|
||||
type scope map[cc.StringID]int32
|
||||
|
||||
func newScope() scope {
|
||||
s := scope{}
|
||||
for _, k := range reservedIds {
|
||||
s[k] = 0
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s scope) take(t cc.StringID) string {
|
||||
if t == 0 {
|
||||
panic(todo("internal error"))
|
||||
}
|
||||
|
||||
n, ok := s[t]
|
||||
if !ok {
|
||||
s[t] = 0
|
||||
return t.String()
|
||||
}
|
||||
|
||||
for {
|
||||
n++
|
||||
s[t] = n
|
||||
r := fmt.Sprintf("%s%d", t, n)
|
||||
id := cc.String(r)
|
||||
if _, ok := s[id]; !ok {
|
||||
s[id] = 0
|
||||
return r
|
||||
}
|
||||
}
|
||||
}
|
13228
vendor/modernc.org/ccgo/v3/lib/go.go
generated
vendored
13228
vendor/modernc.org/ccgo/v3/lib/go.go
generated
vendored
File diff suppressed because it is too large
Load diff
553
vendor/modernc.org/ccgo/v3/lib/init.go
generated
vendored
553
vendor/modernc.org/ccgo/v3/lib/init.go
generated
vendored
|
@ -1,553 +0,0 @@
|
|||
// Copyright 2020 The CCGO Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ccgo // import "modernc.org/ccgo/v3/lib"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"modernc.org/cc/v3"
|
||||
)
|
||||
|
||||
func isAggregateTypeOrUnion(t cc.Type) bool {
|
||||
switch t.Kind() {
|
||||
case cc.Struct, cc.Union, cc.Array:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// 6.7.8 Initialization
|
||||
func (p *project) initializer(f *function, n *cc.Initializer, t cc.Type, sc cc.StorageClass, tld *tld) {
|
||||
lm := map[*cc.Initializer][]cc.StringID{}
|
||||
tm := map[*cc.Initializer][]cc.StringID{}
|
||||
s := p.initializerFlatten(n, lm, tm)
|
||||
sort.Slice(s, func(i, j int) bool {
|
||||
a := s[i]
|
||||
b := s[j]
|
||||
if a.Offset < b.Offset {
|
||||
return true
|
||||
}
|
||||
|
||||
if a.Offset > b.Offset {
|
||||
return false
|
||||
}
|
||||
|
||||
if a.Field == nil || b.Field == nil || !a.Field.IsBitField() || !b.Field.IsBitField() {
|
||||
panic(todo("%v: internal error: off %#x, %v: off %#x, t %v", a.Position(), a.Offset, b.Position(), b.Offset, t))
|
||||
}
|
||||
|
||||
return a.Field.BitFieldOffset() < b.Field.BitFieldOffset()
|
||||
})
|
||||
p.initializerInner("", 0, f, s, t, sc, tld, nil, lm, tm)
|
||||
}
|
||||
|
||||
func (p *project) initializerInner(tag string, off uintptr, f *function, s []*cc.Initializer, t cc.Type, sc cc.StorageClass, tld *tld, patchField cc.Field, lm, tm map[*cc.Initializer][]cc.StringID) {
|
||||
// 11: The initializer for a scalar shall be a single expression, optionally
|
||||
// enclosed in braces. The initial value of the object is that of the
|
||||
// expression (after conversion); the same type constraints and conversions as
|
||||
// for simple assignment apply, taking the type of the scalar to be the
|
||||
// unqualified version of its declared type.
|
||||
if t.IsScalarType() && len(s) == 1 {
|
||||
p.w("%s%s", tidyComment("", s[0]), tag)
|
||||
switch {
|
||||
case tld != nil && t.Kind() == cc.Ptr && s[0].AssignmentExpression.Operand.Value() == nil:
|
||||
tld.patches = append(tld.patches, initPatch{t, s[0], patchField})
|
||||
p.w(" 0 ")
|
||||
default:
|
||||
p.assignmentExpression(f, s[0].AssignmentExpression, t, exprValue, 0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 12: The rest of this subclause deals with initializers for objects that have
|
||||
// aggregate or union type.
|
||||
|
||||
k := t.Kind()
|
||||
|
||||
// 13: The initializer for a structure or union object that has automatic
|
||||
// storage duration shall be either an initializer list as described below, or
|
||||
// a single expression that has compatible structure or union type. In the
|
||||
// latter case, the initial value of the object, including unnamed members, is
|
||||
// that of the expression.
|
||||
if sc == cc.Automatic && len(s) == 1 {
|
||||
switch k {
|
||||
case cc.Struct, cc.Union:
|
||||
if compatibleStructOrUnion(t, s[0].AssignmentExpression.Operand.Type()) {
|
||||
p.w("%s%s", tidyComment("", s[0]), tag)
|
||||
p.assignmentExpression(f, s[0].AssignmentExpression, t, exprValue, 0)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if k == cc.Array && len(s) == 1 {
|
||||
et := t.Elem()
|
||||
switch {
|
||||
case isCharType(et):
|
||||
// 14: An array of character type may be initialized by a character string
|
||||
// literal, optionally enclosed in braces. Successive characters of the
|
||||
// character string literal (including the terminating null character if there
|
||||
// is room or if the array is of unknown size) initialize the elements of the
|
||||
// array.
|
||||
if x, ok := s[0].AssignmentExpression.Operand.Value().(cc.StringValue); ok {
|
||||
p.w("%s%s", tidyComment("", s[0]), tag)
|
||||
str := cc.StringID(x).String()
|
||||
slen := uintptr(len(str)) + 1
|
||||
alen := t.Len()
|
||||
switch {
|
||||
case alen < slen-1:
|
||||
p.w("*(*%s)(unsafe.Pointer(%s))", p.typ(s[0], t), p.stringLiteralString(str[:alen]))
|
||||
case alen < slen:
|
||||
p.w("*(*%s)(unsafe.Pointer(%s))", p.typ(s[0], t), p.stringLiteralString(str))
|
||||
default: // alen >= slen
|
||||
p.w("*(*%s)(unsafe.Pointer(%s))", p.typ(s[0], t), p.stringLiteralString(str+strings.Repeat("\x00", int(alen-slen))))
|
||||
}
|
||||
return
|
||||
}
|
||||
case p.isWCharType(et):
|
||||
// 15: An array with element type compatible with wchar_t may be initialized by
|
||||
// a wide string literal, optionally enclosed in braces. Successive wide
|
||||
// characters of the wide string literal (including the terminating null wide
|
||||
// character if there is room or if the array is of unknown size) initialize
|
||||
// the elements of the array.
|
||||
if x, ok := s[0].AssignmentExpression.Operand.Value().(cc.WideStringValue); ok {
|
||||
p.w("%s%s", tidyComment("", s[0]), tag)
|
||||
str := []rune(cc.StringID(x).String())
|
||||
slen := uintptr(len(str)) + 1
|
||||
alen := t.Len()
|
||||
switch {
|
||||
case alen < slen-1:
|
||||
panic(todo("", p.pos(s[0])))
|
||||
case alen < slen:
|
||||
p.w("*(*%s)(unsafe.Pointer(%s))", p.typ(s[0], t), p.wideStringLiteral(x, 0))
|
||||
default: // alen >= slen
|
||||
p.w("*(*%s)(unsafe.Pointer(%s))", p.typ(s[0], t), p.wideStringLiteral(x, int(alen-slen)))
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 16: Otherwise, the initializer for an object that has aggregate or union
|
||||
// type shall be a brace-enclosed list of initializers for the elements or
|
||||
// named members.
|
||||
switch k {
|
||||
case cc.Array:
|
||||
p.initializerArray(tag, off, f, s, t, sc, tld, lm, tm)
|
||||
case cc.Struct:
|
||||
p.initializerStruct(tag, off, f, s, t, sc, tld, lm, tm)
|
||||
case cc.Union:
|
||||
p.initializerUnion(tag, off, f, s, t, sc, tld, lm, tm)
|
||||
default:
|
||||
panic(todo("%v: internal error: %v alias %v %v", s[0].Position(), t, t.Alias(), len(s)))
|
||||
}
|
||||
}
|
||||
|
||||
func (p *project) initializerArray(tag string, off uintptr, f *function, s []*cc.Initializer, t cc.Type, sc cc.StorageClass, tld *tld, lm, tm map[*cc.Initializer][]cc.StringID) {
|
||||
if len(s) == 0 {
|
||||
p.w("%s%s{}", tag, p.typ(nil, t))
|
||||
return
|
||||
}
|
||||
|
||||
et := t.Elem()
|
||||
esz := et.Size()
|
||||
s0 := s[0]
|
||||
p.w("%s%s%s{", initComment(s0, lm), tag, p.typ(s0, t))
|
||||
var a [][]*cc.Initializer
|
||||
for len(s) != 0 {
|
||||
s2, parts, _ := p.initializerArrayElement(off, s, esz)
|
||||
s = s2
|
||||
a = append(a, parts)
|
||||
}
|
||||
mustIndex := uintptr(len(a)) != t.Len()
|
||||
var parts []*cc.Initializer
|
||||
for _, parts = range a {
|
||||
var comma *cc.Token
|
||||
comma = parts[len(parts)-1].TrailingComma()
|
||||
elemOff := (parts[0].Offset - off) / esz * esz
|
||||
tag = ""
|
||||
if mustIndex {
|
||||
tag = fmt.Sprintf("%d:", elemOff/esz)
|
||||
}
|
||||
p.initializerInner(tag, off+elemOff, f, parts, et, sc, tld, nil, lm, tm)
|
||||
p.preCommaSep(comma)
|
||||
p.w(",")
|
||||
}
|
||||
p.w("%s}", initComment(parts[len(parts)-1], tm))
|
||||
}
|
||||
|
||||
func initComment(n *cc.Initializer, m map[*cc.Initializer][]cc.StringID) string {
|
||||
a := m[n]
|
||||
if len(a) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
m[n] = a[1:]
|
||||
return tidyCommentString(a[0].String())
|
||||
}
|
||||
|
||||
func (p *project) initializerArrayElement(off uintptr, s []*cc.Initializer, elemSize uintptr) (r []*cc.Initializer, parts []*cc.Initializer, isZero bool) {
|
||||
r = s
|
||||
isZero = true
|
||||
valueOff := s[0].Offset - off
|
||||
elemOff := valueOff - valueOff%elemSize
|
||||
nextOff := elemOff + elemSize
|
||||
for len(s) != 0 {
|
||||
if v := s[0]; v.Offset-off < nextOff {
|
||||
s = s[1:]
|
||||
parts = append(parts, v)
|
||||
if !v.AssignmentExpression.Operand.IsZero() {
|
||||
isZero = false
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
return r[len(parts):], parts, isZero
|
||||
}
|
||||
|
||||
func (p *project) initializerStruct(tag string, off uintptr, f *function, s []*cc.Initializer, t cc.Type, sc cc.StorageClass, tld *tld, lm, tm map[*cc.Initializer][]cc.StringID) {
|
||||
if len(s) == 0 {
|
||||
p.w("%s%s{}", tag, p.typ(nil, t))
|
||||
return
|
||||
}
|
||||
|
||||
if t.HasFlexibleMember() {
|
||||
p.err(s[0], "flexible array members not supported")
|
||||
return
|
||||
}
|
||||
|
||||
p.w("%s%s%s{", initComment(s[0], lm), tag, p.typ(s[0], t))
|
||||
var parts []*cc.Initializer
|
||||
var isZero bool
|
||||
var fld cc.Field
|
||||
for len(s) != 0 {
|
||||
var comma *cc.Token
|
||||
s, fld, parts, isZero = p.structInitializerParts(off, s, t)
|
||||
if isZero {
|
||||
continue
|
||||
}
|
||||
|
||||
if fld.Type().IsIncomplete() {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
comma = parts[len(parts)-1].TrailingComma()
|
||||
tag = fmt.Sprintf("%s:", p.fieldName2(parts[0], fld))
|
||||
ft := fld.Type()
|
||||
switch {
|
||||
case fld.IsBitField():
|
||||
bft := p.bitFileType(parts[0], fld.BitFieldBlockWidth())
|
||||
off0 := fld.Offset()
|
||||
first := true
|
||||
for _, v := range parts {
|
||||
if v.AssignmentExpression.Operand.IsZero() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !first {
|
||||
p.w("|")
|
||||
}
|
||||
first = false
|
||||
bitFld := v.Field
|
||||
p.w("%s%s", tidyComment("", v.AssignmentExpression), tag)
|
||||
tag = ""
|
||||
p.assignmentExpression(f, v.AssignmentExpression, bft, exprValue, 0)
|
||||
p.w("&%#x", uint64(1)<<uint64(bitFld.BitFieldWidth())-1)
|
||||
if o := bitFld.BitFieldOffset() + 8*int((bitFld.Offset()-off0)); o != 0 {
|
||||
p.w("<<%d", o)
|
||||
}
|
||||
}
|
||||
default:
|
||||
p.initializerInner(tag, off+fld.Offset(), f, parts, ft, sc, tld, fld, lm, tm)
|
||||
}
|
||||
p.preCommaSep(comma)
|
||||
p.w(",")
|
||||
}
|
||||
p.w("%s}", initComment(parts[len(parts)-1], tm))
|
||||
}
|
||||
|
||||
func (p *project) preCommaSep(comma *cc.Token) {
|
||||
if comma == nil {
|
||||
return
|
||||
}
|
||||
|
||||
p.w("%s", strings.TrimSpace(comma.Sep.String()))
|
||||
}
|
||||
|
||||
func (p *project) structInitializerParts(off uintptr, s []*cc.Initializer, t cc.Type) (r []*cc.Initializer, fld cc.Field, parts []*cc.Initializer, isZero bool) {
|
||||
if len(s) == 0 {
|
||||
return nil, nil, nil, true
|
||||
}
|
||||
|
||||
part := s[0]
|
||||
isZero = part.AssignmentExpression.Operand.IsZero()
|
||||
parts = append(parts, part)
|
||||
s = s[1:]
|
||||
fld, _, fNext := p.containingStructField(part, off, t)
|
||||
for len(s) != 0 {
|
||||
part = s[0]
|
||||
vOff := part.Offset
|
||||
if vOff >= fNext {
|
||||
break
|
||||
}
|
||||
|
||||
isZero = isZero && part.AssignmentExpression.Operand.IsZero()
|
||||
parts = append(parts, part)
|
||||
s = s[1:]
|
||||
}
|
||||
return s, fld, parts, isZero
|
||||
}
|
||||
|
||||
func (p *project) containingStructField(part *cc.Initializer, off uintptr, t cc.Type) (f cc.Field, fOff, fNext uintptr) {
|
||||
nf := t.NumField()
|
||||
vOff := part.Offset
|
||||
for i := []int{0}; i[0] < nf; i[0]++ {
|
||||
f = t.FieldByIndex(i)
|
||||
if f.IsBitField() && f.Name() == 0 { // Anonymous bit fields cannot be initialized.
|
||||
continue
|
||||
}
|
||||
|
||||
fOff = off + f.Offset()
|
||||
switch {
|
||||
case f.IsBitField():
|
||||
fNext = fOff + uintptr(f.BitFieldBlockWidth())>>3
|
||||
default:
|
||||
fNext = fOff + f.Type().Size()
|
||||
}
|
||||
if vOff >= fOff && vOff < fNext {
|
||||
return f, fOff, fNext
|
||||
}
|
||||
}
|
||||
|
||||
panic(todo("%v: internal error", p.pos(part)))
|
||||
}
|
||||
|
||||
func (p *project) initializerUnion(tag string, off uintptr, f *function, s []*cc.Initializer, t cc.Type, sc cc.StorageClass, tld *tld, lm, tm map[*cc.Initializer][]cc.StringID) {
|
||||
if len(s) == 0 {
|
||||
p.w("%s%s{}", tag, p.typ(nil, t))
|
||||
return
|
||||
}
|
||||
|
||||
if t.HasFlexibleMember() {
|
||||
p.err(s[0], "flexible array members not supported")
|
||||
return
|
||||
}
|
||||
|
||||
parts, isZero := p.initializerUnionField(off, s, t)
|
||||
if len(parts) == 0 || isZero {
|
||||
p.w("%s%s%s{", initComment(s[0], lm), tag, p.typ(s[0], t))
|
||||
p.w("%s}", initComment(parts[len(parts)-1], tm))
|
||||
return
|
||||
}
|
||||
|
||||
p.w("%sfunc() (r %s) {", tag, p.typ(parts[0], t))
|
||||
for _, part := range parts {
|
||||
var ft cc.Type
|
||||
fld := part.Field
|
||||
if fld != nil && fld.IsBitField() {
|
||||
}
|
||||
|
||||
if ft == nil {
|
||||
ft = part.Type()
|
||||
}
|
||||
if ft.Kind() == cc.Array {
|
||||
et := ft.Elem()
|
||||
switch {
|
||||
case isCharType(et):
|
||||
switch x := part.AssignmentExpression.Operand.Value().(type) {
|
||||
case cc.StringValue:
|
||||
str := cc.StringID(x).String()
|
||||
slen := uintptr(len(str)) + 1
|
||||
alen := ft.Len()
|
||||
switch {
|
||||
case alen < slen-1:
|
||||
p.w("copy(((*[%d]byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&r))+%d)))[:], (*[%d]byte)(unsafe.Pointer(%s))[:])\n", alen, part.Offset-off, alen, p.stringLiteralString(str[:alen]))
|
||||
case alen < slen:
|
||||
p.w("copy(((*[%d]byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&r))+%d)))[:], (*[%d]byte)(unsafe.Pointer(%s))[:])\n", alen, part.Offset-off, alen, p.stringLiteralString(str))
|
||||
default: // alen >= slen
|
||||
p.w("copy(((*[%d]byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&r))+%d)))[:], (*[%d]byte)(unsafe.Pointer(%s))[:])\n", alen, part.Offset-off, alen, p.stringLiteralString(str+strings.Repeat("\x00", int(alen-slen))))
|
||||
}
|
||||
continue
|
||||
default:
|
||||
panic(todo("%v: %v <- %T", p.pos(part), et, x))
|
||||
}
|
||||
case p.isWCharType(et):
|
||||
panic(todo(""))
|
||||
}
|
||||
ft = et
|
||||
}
|
||||
switch {
|
||||
case fld != nil && fld.IsBitField():
|
||||
bft := p.bitFileType(part, fld.BitFieldBlockWidth())
|
||||
p.w("*(*%s)(unsafe.Pointer(uintptr(unsafe.Pointer(&r))+%d)) |= ", p.typ(part, bft), part.Offset-off)
|
||||
p.assignmentExpression(f, part.AssignmentExpression, bft, exprValue, 0)
|
||||
p.w("&%#x", uint64(1)<<uint64(fld.BitFieldWidth())-1)
|
||||
if o := fld.BitFieldOffset(); o != 0 {
|
||||
p.w("<<%d", o)
|
||||
}
|
||||
default:
|
||||
p.w("*(*%s)(unsafe.Pointer(uintptr(unsafe.Pointer(&r))+%d)) = ", p.typ(part, ft), part.Offset-off)
|
||||
p.assignmentExpression(f, part.AssignmentExpression, ft, exprValue, 0)
|
||||
}
|
||||
p.w("\n")
|
||||
}
|
||||
p.w("return r\n")
|
||||
p.w("}()")
|
||||
}
|
||||
|
||||
func (p *project) initializerUnionField(off uintptr, s []*cc.Initializer, t cc.Type) (parts []*cc.Initializer, isZero bool) {
|
||||
isZero = true
|
||||
nextOff := off + t.Size()
|
||||
for len(s) != 0 {
|
||||
if v := s[0]; v.Offset < nextOff {
|
||||
s = s[1:]
|
||||
parts = append(parts, v)
|
||||
isZero = isZero && v.AssignmentExpression.Operand.IsZero()
|
||||
continue
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
return parts, isZero
|
||||
}
|
||||
|
||||
func compatibleStructOrUnion(t1, t2 cc.Type) bool {
|
||||
switch t1.Kind() {
|
||||
case cc.Struct:
|
||||
if t2.Kind() != cc.Struct {
|
||||
return false
|
||||
}
|
||||
case cc.Union:
|
||||
if t2.Kind() != cc.Union {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
if tag := t1.Tag(); tag != 0 && t2.Tag() != tag {
|
||||
return false
|
||||
}
|
||||
|
||||
nf := t1.NumField()
|
||||
if t2.NumField() != nf {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := []int{0}; i[0] < nf; i[0]++ {
|
||||
f1 := t1.FieldByIndex(i)
|
||||
f2 := t2.FieldByIndex(i)
|
||||
nm := f1.Name()
|
||||
if f2.Name() != nm {
|
||||
return false
|
||||
}
|
||||
|
||||
ft1 := f1.Type()
|
||||
ft2 := f2.Type()
|
||||
if ft1.Size() != ft2.Size() ||
|
||||
f1.IsBitField() != f2.IsBitField() ||
|
||||
f1.BitFieldOffset() != f2.BitFieldOffset() ||
|
||||
f1.BitFieldWidth() != f2.BitFieldWidth() {
|
||||
return false
|
||||
}
|
||||
|
||||
if !compatibleType(ft1, ft2) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func compatibleType(t1, t2 cc.Type) bool {
|
||||
if t1.Kind() != t2.Kind() {
|
||||
return false
|
||||
}
|
||||
|
||||
switch t1.Kind() {
|
||||
case cc.Array:
|
||||
if t1.Len() != t2.Len() || !compatibleType(t1.Elem(), t2.Elem()) {
|
||||
return false
|
||||
}
|
||||
case cc.Struct, cc.Union:
|
||||
if !compatibleStructOrUnion(t1, t2) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *project) bitFileType(n cc.Node, bits int) cc.Type {
|
||||
switch bits {
|
||||
case 8:
|
||||
return p.task.cfg.ABI.Type(cc.UChar)
|
||||
case 16:
|
||||
return p.task.cfg.ABI.Type(cc.UShort)
|
||||
case 32:
|
||||
return p.task.cfg.ABI.Type(cc.UInt)
|
||||
case 64:
|
||||
return p.task.cfg.ABI.Type(cc.ULongLong)
|
||||
default:
|
||||
panic(todo("%v: internal error: %v", n.Position(), bits))
|
||||
}
|
||||
}
|
||||
|
||||
func (p *project) isWCharType(t cc.Type) bool {
|
||||
if t.IsAliasType() {
|
||||
if id := t.AliasDeclarator().Name(); id == idWcharT ||
|
||||
p.task.goos == "windows" && id == idWinWchar {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func isCharType(t cc.Type) bool {
|
||||
switch t.Kind() {
|
||||
case cc.Char, cc.SChar, cc.UChar:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *project) initializerFlatten(n *cc.Initializer, lm, tm map[*cc.Initializer][]cc.StringID) (s []*cc.Initializer) {
|
||||
switch n.Case {
|
||||
case cc.InitializerExpr: // AssignmentExpression
|
||||
return append(s, n)
|
||||
case cc.InitializerInitList: // '{' InitializerList ',' '}'
|
||||
first := true
|
||||
for list := n.InitializerList; list != nil; list = list.InitializerList {
|
||||
in := list.Initializer
|
||||
k := in
|
||||
if in.Case != cc.InitializerExpr {
|
||||
k = nil
|
||||
}
|
||||
if first {
|
||||
lm[k] = append(lm[k], append(lm[nil], n.Token.Sep)...)
|
||||
if k != nil {
|
||||
delete(lm, nil)
|
||||
}
|
||||
first = false
|
||||
}
|
||||
if list.InitializerList == nil {
|
||||
tm[k] = append([]cc.StringID{n.Token3.Sep}, append(tm[nil], tm[k]...)...)
|
||||
tm[k] = append(tm[k], append(tm[nil], n.Token3.Sep)...)
|
||||
if k != nil {
|
||||
delete(tm, nil)
|
||||
}
|
||||
}
|
||||
s = append(s, p.initializerFlatten(in, lm, tm)...)
|
||||
}
|
||||
return s
|
||||
default:
|
||||
panic(todo("%v: internal error: %v", n.Position(), n.Case))
|
||||
}
|
||||
}
|
10
vendor/modernc.org/ccgo/v3/lib/mem.go
generated
vendored
10
vendor/modernc.org/ccgo/v3/lib/mem.go
generated
vendored
|
@ -1,10 +0,0 @@
|
|||
// Copyright 2020 The CCGO Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
package ccgo // import "modernc.org/ccgo/v3/lib"
|
||||
|
||||
var totalRam uint64
|
20
vendor/modernc.org/ccgo/v3/lib/mem_linux.go
generated
vendored
20
vendor/modernc.org/ccgo/v3/lib/mem_linux.go
generated
vendored
|
@ -1,20 +0,0 @@
|
|||
// Copyright 2020 The CCGO Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ccgo // import "modernc.org/ccgo/v3/lib"
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
var totalRam uint64
|
||||
|
||||
func init() {
|
||||
var si unix.Sysinfo_t
|
||||
if unix.Sysinfo(&si) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
totalRam = uint64(si.Totalram)
|
||||
}
|
12
vendor/modernc.org/ccgo/v3/lib/nodmesg.go
generated
vendored
12
vendor/modernc.org/ccgo/v3/lib/nodmesg.go
generated
vendored
|
@ -1,12 +0,0 @@
|
|||
// Copyright 2020 The Libc Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !ccgo.dmesg
|
||||
// +build !ccgo.dmesg
|
||||
|
||||
package ccgo // import "modernc.org/ccgo/v3/lib"
|
||||
|
||||
const dmesgs = false
|
||||
|
||||
func dmesg(s string, args ...interface{}) {}
|
58
vendor/modernc.org/ccgo/v3/lib/stringer.go
generated
vendored
58
vendor/modernc.org/ccgo/v3/lib/stringer.go
generated
vendored
|
@ -1,58 +0,0 @@
|
|||
// Code generated by "stringer -output stringer.go -type=exprMode,opKind"; DO NOT EDIT.
|
||||
|
||||
package ccgo
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[exprAddrOf-1]
|
||||
_ = x[exprBool-2]
|
||||
_ = x[exprCondInit-3]
|
||||
_ = x[exprCondReturn-4]
|
||||
_ = x[exprDecay-5]
|
||||
_ = x[exprFunc-6]
|
||||
_ = x[exprLValue-7]
|
||||
_ = x[exprPSelect-8]
|
||||
_ = x[exprSelect-9]
|
||||
_ = x[exprValue-10]
|
||||
_ = x[exprVoid-11]
|
||||
_ = x[exprGoPtr-12]
|
||||
}
|
||||
|
||||
const _exprMode_name = "exprAddrOfexprBoolexprCondInitexprCondReturnexprDecayexprFuncexprLValueexprPSelectexprSelectexprValueexprVoidexprGoPtr"
|
||||
|
||||
var _exprMode_index = [...]uint8{0, 10, 18, 30, 44, 53, 61, 71, 82, 92, 101, 109, 118}
|
||||
|
||||
func (i exprMode) String() string {
|
||||
i -= 1
|
||||
if i < 0 || i >= exprMode(len(_exprMode_index)-1) {
|
||||
return "exprMode(" + strconv.FormatInt(int64(i+1), 10) + ")"
|
||||
}
|
||||
return _exprMode_name[_exprMode_index[i]:_exprMode_index[i+1]]
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[opNormal-0]
|
||||
_ = x[opArray-1]
|
||||
_ = x[opArrayParameter-2]
|
||||
_ = x[opFunction-3]
|
||||
_ = x[opUnion-4]
|
||||
_ = x[opBitfield-5]
|
||||
_ = x[opStruct-6]
|
||||
}
|
||||
|
||||
const _opKind_name = "opNormalopArrayopArrayParameteropFunctionopUnionopBitfieldopStruct"
|
||||
|
||||
var _opKind_index = [...]uint8{0, 8, 15, 31, 41, 48, 58, 66}
|
||||
|
||||
func (i opKind) String() string {
|
||||
if i < 0 || i >= opKind(len(_opKind_index)-1) {
|
||||
return "opKind(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _opKind_name[_opKind_index[i]:_opKind_index[i+1]]
|
||||
}
|
4
vendor/modernc.org/ccgo/v3/lib/unconvert.sh
generated
vendored
4
vendor/modernc.org/ccgo/v3/lib/unconvert.sh
generated
vendored
|
@ -1,4 +0,0 @@
|
|||
until unconvert -fastmath . &> /dev/null
|
||||
do
|
||||
unconvert -fastmath -apply . &> /dev/null
|
||||
done
|
488
vendor/modernc.org/ccgo/v3/lib/util.go
generated
vendored
488
vendor/modernc.org/ccgo/v3/lib/util.go
generated
vendored
|
@ -1,488 +0,0 @@
|
|||
// Copyright 2020 The CCGO Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// generator.go helpers
|
||||
|
||||
package ccgo // import "modernc.org/ccgo/v3/lib"
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CopyFile copies src to dest, preserving permissions and times where/when
|
||||
// possible. If canOverwrite is not nil, it is consulted whether a destination
|
||||
// file can be overwritten. If canOverwrite is nil then destination is
|
||||
// overwritten if permissions allow that, otherwise the function fails.
|
||||
//
|
||||
// Src and dst must be in the slash form.
|
||||
func CopyFile(dst, src string, canOverwrite func(fn string, fi os.FileInfo) bool) (n int64, rerr error) {
|
||||
dst = filepath.FromSlash(dst)
|
||||
dstDir := filepath.Dir(dst)
|
||||
di, err := os.Stat(dstDir)
|
||||
switch {
|
||||
case err != nil:
|
||||
if !os.IsNotExist(err) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(dstDir, 0770); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
case err == nil:
|
||||
if !di.IsDir() {
|
||||
return 0, fmt.Errorf("cannot create directory, file exists: %s", dst)
|
||||
}
|
||||
}
|
||||
|
||||
src = filepath.FromSlash(src)
|
||||
si, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if si.IsDir() {
|
||||
return 0, fmt.Errorf("cannot copy a directory: %s", src)
|
||||
}
|
||||
|
||||
di, err = os.Stat(dst)
|
||||
switch {
|
||||
case err != nil && !os.IsNotExist(err):
|
||||
return 0, err
|
||||
case err == nil:
|
||||
if di.IsDir() {
|
||||
return 0, fmt.Errorf("cannot overwite a directory: %s", dst)
|
||||
}
|
||||
|
||||
if canOverwrite != nil && !canOverwrite(dst, di) {
|
||||
return 0, fmt.Errorf("cannot overwite: %s", dst)
|
||||
}
|
||||
}
|
||||
|
||||
s, err := os.Open(src)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
defer s.Close()
|
||||
r := bufio.NewReader(s)
|
||||
|
||||
d, err := os.Create(dst)
|
||||
|
||||
defer func() {
|
||||
if err := d.Close(); err != nil && rerr == nil {
|
||||
rerr = err
|
||||
return
|
||||
}
|
||||
|
||||
if err := os.Chmod(dst, si.Mode()); err != nil && rerr == nil {
|
||||
rerr = err
|
||||
return
|
||||
}
|
||||
|
||||
if err := os.Chtimes(dst, si.ModTime(), si.ModTime()); err != nil && rerr == nil {
|
||||
rerr = err
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
w := bufio.NewWriter(d)
|
||||
|
||||
defer func() {
|
||||
if err := w.Flush(); err != nil && rerr == nil {
|
||||
rerr = err
|
||||
}
|
||||
}()
|
||||
|
||||
return io.Copy(w, r)
|
||||
}
|
||||
|
||||
// MustCopyFile is like CopyFile but it executes Fatal(stackTrace, err) if it fails.
|
||||
func MustCopyFile(stackTrace bool, dst, src string, canOverwrite func(fn string, fi os.FileInfo) bool) int64 {
|
||||
n, err := CopyFile(dst, src, canOverwrite)
|
||||
if err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// CopyDir recursively copies src to dest, preserving permissions and times
|
||||
// where/when possible. If canOverwrite is not nil, it is consulted whether a
|
||||
// destination file can be overwritten. If canOverwrite is nil then destination
|
||||
// is overwritten if permissions allow that, otherwise the function fails.
|
||||
//
|
||||
// Src and dst must be in the slash form.
|
||||
func CopyDir(dst, src string, canOverwrite func(fn string, fi os.FileInfo) bool) (files int, bytes int64, rerr error) {
|
||||
dst = filepath.FromSlash(dst)
|
||||
src = filepath.FromSlash(src)
|
||||
si, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
if !si.IsDir() {
|
||||
return 0, 0, fmt.Errorf("cannot copy a file: %s", src)
|
||||
}
|
||||
|
||||
return files, bytes, filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
target, err := filepath.EvalSymlinks(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot evaluate symlink %s: %v", path, err)
|
||||
}
|
||||
|
||||
if info, err = os.Stat(target); err != nil {
|
||||
return fmt.Errorf("cannot stat %s: %v", target, err)
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
rel, err := filepath.Rel(src, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dst2 := filepath.Join(dst, rel)
|
||||
if err := os.MkdirAll(dst2, 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f, b, err := CopyDir(dst2, target, canOverwrite)
|
||||
files += f
|
||||
bytes += b
|
||||
return err
|
||||
}
|
||||
|
||||
path = target
|
||||
}
|
||||
|
||||
rel, err := filepath.Rel(src, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return os.MkdirAll(filepath.Join(dst, rel), 0770)
|
||||
}
|
||||
|
||||
n, err := CopyFile(filepath.Join(dst, rel), path, canOverwrite)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
files++
|
||||
bytes += n
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// MustCopyDir is like CopyDir, but it executes Fatal(stackTrace, errú if it fails.
|
||||
func MustCopyDir(stackTrace bool, dst, src string, canOverwrite func(fn string, fi os.FileInfo) bool) (files int, bytes int64) {
|
||||
file, bytes, err := CopyDir(dst, src, canOverwrite)
|
||||
if err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
|
||||
return file, bytes
|
||||
}
|
||||
|
||||
// UntarFile extracts a named tar.gz archive into dst. If canOverwrite is not
|
||||
// nil, it is consulted whether a destination file can be overwritten. If
|
||||
// canOverwrite is nil then destination is overwritten if permissions allow
|
||||
// that, otherwise the function fails.
|
||||
//
|
||||
// Src and dst must be in the slash form.
|
||||
func UntarFile(dst, src string, canOverwrite func(fn string, fi os.FileInfo) bool) error {
|
||||
f, err := os.Open(filepath.FromSlash(src))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
return Untar(dst, bufio.NewReader(f), canOverwrite)
|
||||
}
|
||||
|
||||
// MustUntarFile is like UntarFile but it executes Fatal(stackTrace, err) if it fails.
|
||||
func MustUntarFile(stackTrace bool, dst, src string, canOverwrite func(fn string, fi os.FileInfo) bool) {
|
||||
if err := UntarFile(dst, src, canOverwrite); err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Untar extracts a tar.gz archive into dst. If canOverwrite is not nil, it is
|
||||
// consulted whether a destination file can be overwritten. If canOverwrite is
|
||||
// nil then destination is overwritten if permissions allow that, otherwise the
|
||||
// function fails.
|
||||
//
|
||||
// Dst must be in the slash form.
|
||||
func Untar(dst string, r io.Reader, canOverwrite func(fn string, fi os.FileInfo) bool) error {
|
||||
dst = filepath.FromSlash(dst)
|
||||
gr, err := gzip.NewReader(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tr := tar.NewReader(gr)
|
||||
for {
|
||||
hdr, err := tr.Next()
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
switch hdr.Typeflag {
|
||||
case tar.TypeDir:
|
||||
dir := filepath.Join(dst, hdr.Name)
|
||||
if err = os.MkdirAll(dir, 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
case tar.TypeSymlink, tar.TypeXGlobalHeader:
|
||||
// skip
|
||||
case tar.TypeReg, tar.TypeRegA:
|
||||
dir := filepath.Dir(filepath.Join(dst, hdr.Name))
|
||||
if _, err := os.Stat(dir); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = os.MkdirAll(dir, 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
fn := filepath.Join(dst, hdr.Name)
|
||||
f, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY, os.FileMode(hdr.Mode))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w := bufio.NewWriter(f)
|
||||
if _, err = io.Copy(w, tr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := w.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Chtimes(fn, hdr.AccessTime, hdr.ModTime); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unexpected tar header typeflag %#02x", hdr.Typeflag)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MustUntar is like Untar but it executes Fatal(stackTrace, err) if it fails.
|
||||
func MustUntar(stackTrace bool, dst string, r io.Reader, canOverwrite func(fn string, fi os.FileInfo) bool) {
|
||||
if err := Untar(dst, r, canOverwrite); err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Fatalf prints a formatted message to os.Stderr and performs os.Exit(1). A
|
||||
// stack trace is added if stackTrace is true.
|
||||
func Fatalf(stackTrace bool, s string, args ...interface{}) {
|
||||
if stackTrace {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", debug.Stack())
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, strings.TrimSpace(fmt.Sprintf(s, args...)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Fatal prints its argumenst to os.Stderr and performs os.Exit(1). A
|
||||
// stack trace is added if stackTrace is true.
|
||||
func Fatal(stackTrace bool, args ...interface{}) {
|
||||
if stackTrace {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", debug.Stack())
|
||||
}
|
||||
fmt.Fprintln(os.Stderr, strings.TrimSpace(fmt.Sprint(args...)))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Mkdirs will create all paths. Paths must be in slash form.
|
||||
func Mkdirs(paths ...string) error {
|
||||
for _, path := range paths {
|
||||
path = filepath.FromSlash(path)
|
||||
if err := os.MkdirAll(path, 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MustMkdirs is like Mkdir but if executes Fatal(stackTrace, err) if it fails.
|
||||
func MustMkdirs(stackTrace bool, paths ...string) {
|
||||
if err := Mkdirs(paths...); err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
}
|
||||
|
||||
// InDir executes f in dir. Dir must be in slash form.
|
||||
func InDir(dir string, f func() error) (err error) {
|
||||
var cwd string
|
||||
if cwd, err = os.Getwd(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err2 := os.Chdir(cwd); err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
}()
|
||||
|
||||
if err = os.Chdir(filepath.FromSlash(dir)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return f()
|
||||
}
|
||||
|
||||
// MustInDir is like InDir but it executes Fatal(stackTrace, err) if it fails.
|
||||
func MustInDir(stackTrace bool, dir string, f func() error) {
|
||||
if err := InDir(dir, f); err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
}
|
||||
|
||||
type echoWriter struct {
|
||||
w bytes.Buffer
|
||||
}
|
||||
|
||||
func (w *echoWriter) Write(b []byte) (int, error) {
|
||||
os.Stdout.Write(b)
|
||||
return w.w.Write(b)
|
||||
}
|
||||
|
||||
// Shell echoes and executes cmd with args and returns the combined output if the command.
|
||||
func Shell(cmd string, args ...string) ([]byte, error) {
|
||||
cmd, err := exec.LookPath(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wd, err := AbsCwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmt.Printf("execute %s %q in %s\n", cmd, args, wd)
|
||||
var b echoWriter
|
||||
c := exec.Command(cmd, args...)
|
||||
c.Stdout = &b
|
||||
c.Stderr = &b
|
||||
err = c.Run()
|
||||
return b.w.Bytes(), err
|
||||
}
|
||||
|
||||
// MustShell is like Shell but it executes Fatal(stackTrace, err) if it fails.
|
||||
func MustShell(stackTrace bool, cmd string, args ...string) []byte {
|
||||
b, err := Shell(cmd, args...)
|
||||
if err != nil {
|
||||
Fatalf(stackTrace, "%v %s\noutput: %s\nerr: %s", cmd, args, b, err)
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// Compile executes Shell with cmd set to "ccgo".
|
||||
func Compile(args ...string) ([]byte, error) { return Shell("ccgo", args...) }
|
||||
|
||||
// MustCompile is like Compile but if executes Fatal(stackTrace, err) if it fails.
|
||||
func MustCompile(stackTrace bool, args ...string) []byte {
|
||||
return MustShell(stackTrace, "ccgo", args...)
|
||||
}
|
||||
|
||||
// Run is like Compile, but executes in-process.
|
||||
func Run(args ...string) ([]byte, error) {
|
||||
var b bytes.Buffer
|
||||
t := NewTask(append([]string{"ccgo"}, args...), &b, &b)
|
||||
err := t.Main()
|
||||
return b.Bytes(), err
|
||||
}
|
||||
|
||||
// MustRun is like Run but if executes Fatal(stackTrace, err) if it fails.
|
||||
func MustRun(stackTrace bool, args ...string) []byte {
|
||||
var b bytes.Buffer
|
||||
args = append([]string{"ccgo"}, args...)
|
||||
t := NewTask(args, &b, &b)
|
||||
if err := t.Main(); err != nil {
|
||||
Fatalf(stackTrace, "%v\noutput: %s\nerr: %s", args, b.Bytes(), err)
|
||||
}
|
||||
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
// AbsCwd returns the absolute working directory.
|
||||
func AbsCwd() (string, error) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if wd, err = filepath.Abs(wd); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return wd, nil
|
||||
}
|
||||
|
||||
// MustAbsCwd is like AbsCwd but executes Fatal(stackTrace, err) if it fails.
|
||||
func MustAbsCwd(stackTrace bool) string {
|
||||
s, err := AbsCwd()
|
||||
if err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Env returns the value of environmental variable key of dflt otherwise.
|
||||
func Env(key, dflt string) string {
|
||||
if s := os.Getenv(key); s != "" {
|
||||
return s
|
||||
}
|
||||
|
||||
return dflt
|
||||
}
|
||||
|
||||
// MustTempDir is like ioutil.TempDir but executes Fatal(stackTrace, err) if it
|
||||
// fails. The returned path is absolute.
|
||||
func MustTempDir(stackTrace bool, dir, name string) string {
|
||||
s, err := ioutil.TempDir(dir, name)
|
||||
if err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
|
||||
if s, err = filepath.Abs(s); err != nil {
|
||||
Fatal(stackTrace, err)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
0
vendor/modernc.org/cc/v3/GO-LICENSE → vendor/modernc.org/gc/v3/GO-LICENSE
generated
vendored
0
vendor/modernc.org/cc/v3/GO-LICENSE → vendor/modernc.org/gc/v3/GO-LICENSE
generated
vendored
69
vendor/modernc.org/gc/v3/LICENSE
generated
vendored
Normal file
69
vendor/modernc.org/gc/v3/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
-------------------------------------------------------------------------------
|
||||
Copyright (c) 2016 The GC Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the names of the authors nor the names of the
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Code in this repository contains or may contain
|
||||
|
||||
- copied original code from
|
||||
- code based on original code from
|
||||
- code inspired by original code in
|
||||
|
||||
"The Go Programming Language" project at https://go.googlesource.com/go/.
|
||||
|
||||
Copy of the license of the original code follows below
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
-------------------------------------------------------------------------------
|
113
vendor/modernc.org/gc/v3/Makefile
generated
vendored
Normal file
113
vendor/modernc.org/gc/v3/Makefile
generated
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
.PHONY: all clean edit editor test test2 back report report2 parser2 benchmarks benchmarks2 mem memgo race nreport build_all_targets
|
||||
|
||||
all:
|
||||
|
||||
build_all_targets:
|
||||
GOOS=darwin GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=darwin GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=arm go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=illumos GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=arm go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=ppc64le go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=riscv64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=s390x go test -c -o /dev/null
|
||||
GOOS=netbsd GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=netbsd GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=netbsd GOARCH=arm go test -c -o /dev/null
|
||||
GOOS=openbsd GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=openbsd GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=openbsd GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=windows GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=windows GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=windows GOARCH=arm64 go test -c -o /dev/null
|
||||
|
||||
clean:
|
||||
rm -f cpu.test mem.test *.out
|
||||
go clean
|
||||
|
||||
edit:
|
||||
@touch log
|
||||
@if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile all_test.go gc.go & fi
|
||||
|
||||
editor:
|
||||
gofmt -l -s -w *.go
|
||||
go test -c -o /dev/null 2>&1 | tee log-editor
|
||||
|
||||
race:
|
||||
go test -v -failfast -heap -race 2>&1 | tee log-test
|
||||
@git diff testdata/ || true
|
||||
@git status
|
||||
@grep TOTAL log-test || true
|
||||
grep 'FAIL\|TODO' log-test || true
|
||||
|
||||
test:
|
||||
go test -v -failfast -trctodo -exterr -heap 2>&1 | tee log-test
|
||||
@git diff testdata/ || true
|
||||
@git status
|
||||
@grep TOTAL log-test || true
|
||||
grep 'FAIL\|TODO' log-test || true
|
||||
|
||||
test2:
|
||||
go test -v -failfast -trctodo -exterr -src $$HOME/src 2>&1 | tee log-test2
|
||||
@git diff testdata/ || true
|
||||
@git status
|
||||
@grep TOTAL log-test2 || true
|
||||
grep 'FAIL\|TODO' log-test2 || true
|
||||
|
||||
parser2:
|
||||
go test -v -failfast -run TestParser -src $$HOME/src 2>&1 | tee log-parser2
|
||||
@git diff testdata/ || true
|
||||
@git status
|
||||
@grep TOTAL log-parser2 || true
|
||||
grep 'FAIL\|TODO' log-parser2 || true
|
||||
|
||||
back:
|
||||
go test -v -failfast -noback 2>&1 | tee log-back
|
||||
@git diff testdata/ || true
|
||||
@git status
|
||||
@grep TOTAL log-back || true
|
||||
grep 'FAIL\|TODO' log-back || true
|
||||
|
||||
nreport:
|
||||
touch log-nreport
|
||||
cp log-nreport log-nreport0
|
||||
go test -v -failfast -run TestParser -heap -nreport 2>&1 | tee log-nreport
|
||||
@git diff testdata/ || true
|
||||
@git status
|
||||
@grep TOTAL log-report || true
|
||||
grep 'FAIL\|TODO' log-report || true
|
||||
|
||||
report:
|
||||
go test -v -failfast -run TestParser -report 2>&1 | tee log-report
|
||||
@git diff testdata/ || true
|
||||
@git status
|
||||
@grep TOTAL log-report || true
|
||||
grep 'FAIL\|TODO' log-report || true
|
||||
|
||||
report2:
|
||||
go test -v -failfast -run TestParser -src $$HOME/src -report 2>&1 | tee log-report2
|
||||
@git diff testdata/ || true
|
||||
@git status
|
||||
@grep TOTAL log-report2 || true
|
||||
grep 'FAIL\|TODO' log-report2 || true
|
||||
|
||||
|
||||
benchmarks:
|
||||
go test -v -run @ -bench . 2>&1 | tee log-benchmarks
|
||||
|
||||
benchmarks2:
|
||||
go test -v -run @ -bench . -bsrc $$HOME/src 2>&1 | tee log-benchmarks2
|
||||
|
||||
mem:
|
||||
go test -run @ -bench BenchmarkParser -memprofile mem.out
|
||||
go tool pprof --lines --alloc_space *.test mem.out
|
||||
|
||||
memgo:
|
||||
go test -run @ -bench BenchmarkGoParser -memprofile mem.out
|
||||
go tool pprof --lines --alloc_space *.test mem.out
|
682
vendor/modernc.org/gc/v3/abi.go
generated
vendored
Normal file
682
vendor/modernc.org/gc/v3/abi.go
generated
vendored
Normal file
|
@ -0,0 +1,682 @@
|
|||
// Copyright 2022 The Gc Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gc // import "modernc.org/gc/v3"
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
byteOrders = map[string]binary.ByteOrder{
|
||||
"386": binary.LittleEndian,
|
||||
"amd64": binary.LittleEndian,
|
||||
"arm": binary.LittleEndian,
|
||||
"arm64": binary.LittleEndian,
|
||||
"ppc64le": binary.LittleEndian,
|
||||
"riscv64": binary.LittleEndian,
|
||||
"s390x": binary.BigEndian,
|
||||
}
|
||||
|
||||
abiTypes = map[[2]string]map[Kind]ABIType{
|
||||
// go1.19.1
|
||||
{"freebsd", "386"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {4, 4, 4},
|
||||
Complex128: {16, 4, 4},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {8, 4, 4},
|
||||
Map: {4, 4, 4},
|
||||
Pointer: {4, 4, 4},
|
||||
Slice: {12, 4, 4},
|
||||
String: {8, 4, 4},
|
||||
Uint: {4, 4, 4},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 4, 4},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {4, 4, 4},
|
||||
UnsafePointer: {4, 4, 4},
|
||||
},
|
||||
// go1.19.1
|
||||
{"freebsd", "amd64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.18.5
|
||||
{"freebsd", "arm"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {4, 4, 4},
|
||||
Complex128: {16, 4, 4},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {8, 4, 4},
|
||||
Map: {4, 4, 4},
|
||||
Pointer: {4, 4, 4},
|
||||
Slice: {12, 4, 4},
|
||||
String: {8, 4, 4},
|
||||
Uint: {4, 4, 4},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 4, 4},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {4, 4, 4},
|
||||
UnsafePointer: {4, 4, 4},
|
||||
},
|
||||
// go1.19
|
||||
{"freebsd", "arm64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.1
|
||||
{"darwin", "amd64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.1
|
||||
{"darwin", "arm64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.1
|
||||
{"linux", "386"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {4, 4, 4},
|
||||
Complex128: {16, 4, 4},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {8, 4, 4},
|
||||
Map: {4, 4, 4},
|
||||
Pointer: {4, 4, 4},
|
||||
Slice: {12, 4, 4},
|
||||
String: {8, 4, 4},
|
||||
Uint: {4, 4, 4},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 4, 4},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {4, 4, 4},
|
||||
UnsafePointer: {4, 4, 4},
|
||||
},
|
||||
// go1.19.1
|
||||
{"linux", "amd64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.1
|
||||
{"linux", "arm"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {4, 4, 4},
|
||||
Complex128: {16, 4, 4},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {8, 4, 4},
|
||||
Map: {4, 4, 4},
|
||||
Pointer: {4, 4, 4},
|
||||
Slice: {12, 4, 4},
|
||||
String: {8, 4, 4},
|
||||
Uint: {4, 4, 4},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 4, 4},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {4, 4, 4},
|
||||
UnsafePointer: {4, 4, 4},
|
||||
},
|
||||
// go1.19.1
|
||||
{"linux", "arm64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.1
|
||||
{"linux", "s390x"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.1
|
||||
{"linux", "ppc64le"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.1
|
||||
{"linux", "riscv64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.18.3
|
||||
{"netbsd", "386"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {4, 4, 4},
|
||||
Complex128: {16, 4, 4},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {8, 4, 4},
|
||||
Map: {4, 4, 4},
|
||||
Pointer: {4, 4, 4},
|
||||
Slice: {12, 4, 4},
|
||||
String: {8, 4, 4},
|
||||
Uint: {4, 4, 4},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 4, 4},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {4, 4, 4},
|
||||
UnsafePointer: {4, 4, 4},
|
||||
},
|
||||
// go1.18.3
|
||||
{"netbsd", "amd64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.18.3
|
||||
{"netbsd", "arm"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {4, 4, 4},
|
||||
Complex128: {16, 4, 4},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {8, 4, 4},
|
||||
Map: {4, 4, 4},
|
||||
Pointer: {4, 4, 4},
|
||||
Slice: {12, 4, 4},
|
||||
String: {8, 4, 4},
|
||||
Uint: {4, 4, 4},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 4, 4},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {4, 4, 4},
|
||||
UnsafePointer: {4, 4, 4},
|
||||
},
|
||||
// go1.19
|
||||
{"openbsd", "amd64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19
|
||||
{"openbsd", "arm64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19
|
||||
{"openbsd", "386"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {4, 4, 4},
|
||||
Complex128: {16, 4, 4},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {8, 4, 4},
|
||||
Map: {4, 4, 4},
|
||||
Pointer: {4, 4, 4},
|
||||
Slice: {12, 4, 4},
|
||||
String: {8, 4, 4},
|
||||
Uint: {4, 4, 4},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 4, 4},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {4, 4, 4},
|
||||
UnsafePointer: {4, 4, 4},
|
||||
},
|
||||
// go1.19.1
|
||||
{"windows", "386"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {4, 4, 4},
|
||||
Complex128: {16, 4, 4},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 4, 4},
|
||||
Function: {4, 4, 4},
|
||||
Int: {4, 4, 4},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 4, 4},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {8, 4, 4},
|
||||
Map: {4, 4, 4},
|
||||
Pointer: {4, 4, 4},
|
||||
Slice: {12, 4, 4},
|
||||
String: {8, 4, 4},
|
||||
Uint: {4, 4, 4},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 4, 4},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {4, 4, 4},
|
||||
UnsafePointer: {4, 4, 4},
|
||||
},
|
||||
// go1.19.1
|
||||
{"windows", "amd64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.1
|
||||
{"windows", "arm64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
// go1.19.3
|
||||
{"illumos", "amd64"}: {
|
||||
Bool: {1, 1, 1},
|
||||
Chan: {8, 8, 8},
|
||||
Complex128: {16, 8, 8},
|
||||
Complex64: {8, 4, 4},
|
||||
Float32: {4, 4, 4},
|
||||
Float64: {8, 8, 8},
|
||||
Function: {8, 8, 8},
|
||||
Int: {8, 8, 8},
|
||||
Int16: {2, 2, 2},
|
||||
Int32: {4, 4, 4},
|
||||
Int64: {8, 8, 8},
|
||||
Int8: {1, 1, 1},
|
||||
Interface: {16, 8, 8},
|
||||
Map: {8, 8, 8},
|
||||
Pointer: {8, 8, 8},
|
||||
Slice: {24, 8, 8},
|
||||
String: {16, 8, 8},
|
||||
Uint: {8, 8, 8},
|
||||
Uint16: {2, 2, 2},
|
||||
Uint32: {4, 4, 4},
|
||||
Uint64: {8, 8, 8},
|
||||
Uint8: {1, 1, 1},
|
||||
Uintptr: {8, 8, 8},
|
||||
UnsafePointer: {8, 8, 8},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// ABI describes selected parts of the Application Binary Interface.
|
||||
type ABI struct {
|
||||
ByteOrder binary.ByteOrder
|
||||
goarch string
|
||||
goos string
|
||||
Types map[Kind]ABIType
|
||||
}
|
||||
|
||||
type ABIType struct {
|
||||
Size int64
|
||||
Align int64
|
||||
FieldAlign int64
|
||||
}
|
||||
|
||||
// NewABI creates an ABI based on the os+arch pair.
|
||||
func NewABI(os, arch string) (*ABI, error) {
|
||||
byteOrder, ok := byteOrders[arch]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unsupported arch: %s", arch)
|
||||
}
|
||||
|
||||
types0, ok := abiTypes[[2]string{os, arch}]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unsupported os/arch: %s/%s", os, arch)
|
||||
}
|
||||
|
||||
types := make(map[Kind]ABIType, len(types0))
|
||||
for k, v := range types0 {
|
||||
types[k] = v
|
||||
}
|
||||
return &ABI{
|
||||
ByteOrder: byteOrder,
|
||||
Types: types,
|
||||
}, nil
|
||||
}
|
598
vendor/modernc.org/gc/v3/check.go
generated
vendored
Normal file
598
vendor/modernc.org/gc/v3/check.go
generated
vendored
Normal file
|
@ -0,0 +1,598 @@
|
|||
// Copyright 2022 The Gc Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gc // modernc.org/gc/v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type ctx struct {
|
||||
ast *AST
|
||||
cfg *Config
|
||||
errs errList
|
||||
iota int64
|
||||
pkg *Package
|
||||
|
||||
int32 Type // Set by newCtx
|
||||
untypedFloat Type // Set by newCtx
|
||||
untypedInt Type // Set by newCtx
|
||||
untypedString Type // Set by newCtx
|
||||
}
|
||||
|
||||
func newCtx(cfg *Config) (r *ctx) {
|
||||
r = &ctx{
|
||||
cfg: cfg,
|
||||
iota: -1, // -> Invalid
|
||||
}
|
||||
r.int32 = r.newPredeclaredType(znode, Int32)
|
||||
r.untypedFloat = r.newPredeclaredType(znode, UntypedFloat)
|
||||
r.untypedInt = r.newPredeclaredType(znode, UntypedInt)
|
||||
r.untypedString = r.newPredeclaredType(znode, UntypedString)
|
||||
return r
|
||||
}
|
||||
|
||||
func (c *ctx) err(n Node, msg string, args ...interface{}) {
|
||||
var pos token.Position
|
||||
if n != nil {
|
||||
pos = n.Position()
|
||||
}
|
||||
s := fmt.Sprintf(msg, args...)
|
||||
if trcTODOs && strings.HasPrefix(s, "TODO") {
|
||||
fmt.Fprintf(os.Stderr, "%v: %s (%v)\n", pos, s, origin(2))
|
||||
os.Stderr.Sync()
|
||||
}
|
||||
switch {
|
||||
case extendedErrors:
|
||||
c.errs.err(pos, "%s (%v: %v: %v)", s, origin(4), origin(3), origin(2))
|
||||
default:
|
||||
c.errs.err(pos, s)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ctx) isBuiltin() bool { return c.pkg.Scope.kind == UniverseScope }
|
||||
func (c *ctx) isUnsafe() bool { return c.pkg.isUnsafe }
|
||||
|
||||
func (c *ctx) lookup(sc *Scope, id Token) (pkg *Package, in *Scope, r named) {
|
||||
sc0 := sc
|
||||
pkg = c.pkg
|
||||
for {
|
||||
switch in, nm := sc.lookup(id); x := nm.n.(type) {
|
||||
case *TypeDefNode:
|
||||
if sc.kind == UniverseScope {
|
||||
if sc0.kind != UniverseScope && token.IsExported(id.Src()) {
|
||||
// trc("%v: %q %v %v", id.Position(), id.Src(), sc0.kind, sc.kind)
|
||||
return nil, nil, r
|
||||
}
|
||||
}
|
||||
|
||||
return x.pkg, in, nm
|
||||
default:
|
||||
panic(todo("%v: %q %T", id.Position(), id.Src(), x))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (n *Package) check(c *ctx) (err error) {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
c.pkg = n
|
||||
// trc("PKG %q", n.ImportPath)
|
||||
// defer func() { trc("PKG %q -> err: %v", n.ImportPath, err) }()
|
||||
for _, v := range n.GoFiles {
|
||||
path := filepath.Join(n.FSPath, v.Name())
|
||||
n.AST[path].check(c)
|
||||
}
|
||||
return c.errs.Err()
|
||||
}
|
||||
|
||||
func (n *AST) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.ast = n
|
||||
n.SourceFile.check(c)
|
||||
}
|
||||
|
||||
func (n *SourceFileNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
n.PackageClause.check(c)
|
||||
for l := n.ImportDeclList; l != nil; l = l.List {
|
||||
l.ImportDecl.check(c)
|
||||
}
|
||||
for l := n.TopLevelDeclList; l != nil; l = l.List {
|
||||
switch x := l.TopLevelDecl.(type) {
|
||||
case *TypeDeclNode:
|
||||
x.check(c)
|
||||
case *ConstDeclNode:
|
||||
x.check(c)
|
||||
case *VarDeclNode:
|
||||
x.check(c)
|
||||
case *FunctionDeclNode:
|
||||
x.check(c)
|
||||
case *MethodDeclNode:
|
||||
x.check(c)
|
||||
default:
|
||||
panic(todo("%v: %T %s", x.Position(), x, x.Source(false)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (n *MethodDeclNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
n.Receiver.check(c)
|
||||
n.Signature.check(c)
|
||||
}
|
||||
|
||||
func (n *FunctionDeclNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if c.isBuiltin() {
|
||||
switch nm := n.FunctionName.IDENT.Src(); nm {
|
||||
case
|
||||
"append",
|
||||
"cap",
|
||||
"close",
|
||||
"complex",
|
||||
"copy",
|
||||
"delete",
|
||||
"imag",
|
||||
"len",
|
||||
"make",
|
||||
"new",
|
||||
"panic",
|
||||
"print",
|
||||
"println",
|
||||
"real",
|
||||
"recover",
|
||||
|
||||
// Go 1.21
|
||||
"max",
|
||||
"min",
|
||||
"clear":
|
||||
|
||||
n.Signature.t = c.newPredeclaredType(n, Function)
|
||||
default:
|
||||
panic(todo("%v: %q %s", n.Position(), nm, n.Source(false)))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
n.Signature.check(c)
|
||||
if n.TypeParameters != nil {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *SignatureNode) check(c *ctx) Type {
|
||||
if n == nil {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
if !n.enter(c, n) {
|
||||
return n.Type()
|
||||
}
|
||||
|
||||
in := n.Parameters.check(c)
|
||||
out := n.Result.check(c)
|
||||
return n.setType(newTupleType(n.Parameters, []Type{in, out}))
|
||||
}
|
||||
|
||||
func (n *ResultNode) check(c *ctx) Type {
|
||||
if n == nil {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
switch {
|
||||
case n.Parameters != nil:
|
||||
return n.Parameters.check(c)
|
||||
case n.TypeNode != nil:
|
||||
return n.TypeNode.check(c)
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *ParametersNode) check(c *ctx) Type {
|
||||
if n == nil {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
r := newTupleType(n, nil)
|
||||
for l := n.ParameterDeclList; l != nil; l = l.List {
|
||||
r.Types = append(r.Types, l.ParameterDecl.check(c)...)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (n *ParameterDeclNode) check(c *ctx) (r []Type) {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
t := n.TypeNode.check(c)
|
||||
for l := n.IdentifierList; l != nil; l = l.List {
|
||||
r = append(r, t)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (n *VarDeclNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch x := n.VarSpec.(type) {
|
||||
case *VarSpecNode:
|
||||
x.check(c)
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *VarSpecNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if c.isBuiltin() {
|
||||
switch nm := n.IDENT.Src(); nm {
|
||||
case "nil":
|
||||
n.TypeNode = c.newPredeclaredType(n, UntypedNil)
|
||||
default:
|
||||
panic(todo("%v: %q", n.IDENT.Position(), nm))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if n.TypeNode != nil {
|
||||
c.err(n, "TODO %v", n.TypeNode.Source(false))
|
||||
}
|
||||
var e []Expression
|
||||
for l := n.ExpressionList; l != nil; l = l.List {
|
||||
e = append(e, l.Expression.checkExpr(c))
|
||||
}
|
||||
switch len(e) {
|
||||
default:
|
||||
panic(todo("", len(e)))
|
||||
c.err(n, "TODO %v", len(e))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *ConstDeclNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch x := n.ConstSpec.(type) {
|
||||
case *ConstSpecListNode:
|
||||
var prev Node
|
||||
for l := x; l != nil; l = l.List {
|
||||
switch y := l.ConstSpec.(type) {
|
||||
case *ConstSpecNode:
|
||||
y.check(c, prev)
|
||||
if y.Expression != nil || y.TypeNode != nil {
|
||||
prev = y
|
||||
}
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), y, n.Source(false)))
|
||||
}
|
||||
}
|
||||
case *ConstSpecNode:
|
||||
x.check(c, nil)
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (n *ConstSpecNode) check(c *ctx, prev Node) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if !n.enter(c, n) {
|
||||
if n.guard == guardChecking {
|
||||
panic(todo("")) // report recursive
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
defer func() { n.guard = guardChecked }()
|
||||
|
||||
if c.isBuiltin() {
|
||||
switch n.IDENT.Src() {
|
||||
case "true":
|
||||
switch x := n.Expression.(type) {
|
||||
case *BinaryExpressionNode:
|
||||
x.setValue(trueVal)
|
||||
x.setType(c.newPredeclaredType(x, UntypedBool))
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
case "false":
|
||||
switch x := n.Expression.(type) {
|
||||
case *BinaryExpressionNode:
|
||||
x.setValue(falseVal)
|
||||
x.setType(c.newPredeclaredType(x, UntypedBool))
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
case "iota":
|
||||
switch x := n.Expression.(type) {
|
||||
case *BasicLitNode:
|
||||
// ok
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
default:
|
||||
panic(todo("", n.Position(), n.Source(false)))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
save := c.iota
|
||||
c.iota = n.iota
|
||||
|
||||
defer func() { c.iota = save }()
|
||||
|
||||
switch {
|
||||
case n.Expression != nil:
|
||||
n.Expression = n.Expression.checkExpr(c)
|
||||
if n.TypeNode == nil {
|
||||
n.TypeNode = n.Expression.Type()
|
||||
return
|
||||
}
|
||||
|
||||
t := n.TypeNode.check(c)
|
||||
trc("", t)
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
default:
|
||||
// var e Expression
|
||||
// var pe *Expression
|
||||
// switch {
|
||||
// case n.Expression != nil:
|
||||
// e = n.Expression
|
||||
// pe = &n.Expression
|
||||
// default:
|
||||
// switch x := prev.(type) {
|
||||
// case *ConstSpecNode:
|
||||
// e = x.Expression.clone()
|
||||
// pe = &e
|
||||
// default:
|
||||
// panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
// }
|
||||
// }
|
||||
// ev, et := e.checkExpr(c, pe)
|
||||
// e = *pe
|
||||
// if ev.Kind() == constant.Unknown {
|
||||
// c.err(e, "%s is not a constant", e.Source(false))
|
||||
// n.t = Invalid
|
||||
// n.setValue(unknown)
|
||||
// return Invalid
|
||||
// }
|
||||
// switch {
|
||||
// case n.t == nil:
|
||||
// n.t = et
|
||||
// default:
|
||||
|
||||
// c.err(n.Expression, "cannot assign %v (type %v) to type %v", ev, et, n.Type())
|
||||
// return Invalid
|
||||
// } else {
|
||||
// n.setValue(convertValue(c, e, ev, n.Type()))
|
||||
// }
|
||||
// }
|
||||
// return n.Type()
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (n *TypeDeclNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for l := n.TypeSpecList; l != nil; l = l.List {
|
||||
switch x := l.TypeSpec.(type) {
|
||||
case *TypeDefNode:
|
||||
switch {
|
||||
case c.isBuiltin():
|
||||
x.pkg = c.pkg
|
||||
switch nm := x.IDENT.Src(); nm {
|
||||
case "bool":
|
||||
x.TypeNode = c.newPredeclaredType(x, Bool)
|
||||
case "int":
|
||||
x.TypeNode = c.newPredeclaredType(x, Int)
|
||||
c.cfg.int = x.TypeNode
|
||||
case "int8":
|
||||
x.TypeNode = c.newPredeclaredType(x, Int8)
|
||||
case "int16":
|
||||
x.TypeNode = c.newPredeclaredType(x, Int16)
|
||||
case "int32":
|
||||
x.TypeNode = c.newPredeclaredType(x, Int32)
|
||||
case "int64":
|
||||
x.TypeNode = c.newPredeclaredType(x, Int64)
|
||||
case "uint":
|
||||
x.TypeNode = c.newPredeclaredType(x, Uint)
|
||||
c.cfg.uint = x.TypeNode
|
||||
case "uint8":
|
||||
x.TypeNode = c.newPredeclaredType(x, Uint8)
|
||||
case "uint16":
|
||||
x.TypeNode = c.newPredeclaredType(x, Uint16)
|
||||
case "uint32":
|
||||
x.TypeNode = c.newPredeclaredType(x, Uint32)
|
||||
case "uint64":
|
||||
x.TypeNode = c.newPredeclaredType(x, Uint64)
|
||||
case "uintptr":
|
||||
x.TypeNode = c.newPredeclaredType(x, Uintptr)
|
||||
case "string":
|
||||
x.TypeNode = c.newPredeclaredType(x, String)
|
||||
case "float32":
|
||||
x.TypeNode = c.newPredeclaredType(x, Float32)
|
||||
case "float64":
|
||||
x.TypeNode = c.newPredeclaredType(x, Float64)
|
||||
case "complex64":
|
||||
x.TypeNode = c.newPredeclaredType(x, Complex64)
|
||||
case "complex128":
|
||||
x.TypeNode = c.newPredeclaredType(x, Complex128)
|
||||
case "comparable":
|
||||
x.TypeNode = c.newPredeclaredType(x, Interface)
|
||||
case "error":
|
||||
x.check(c)
|
||||
default:
|
||||
if token.IsExported(nm) {
|
||||
delete(c.pkg.Scope.nodes, nm)
|
||||
return
|
||||
}
|
||||
|
||||
panic(todo("%v: %T %s", x.Position(), x, x.Source(false)))
|
||||
}
|
||||
case c.isUnsafe():
|
||||
switch nm := x.IDENT.Src(); nm {
|
||||
case "ArbitraryType", "IntegerType", "Pointer":
|
||||
x.TypeNode.check(c)
|
||||
default:
|
||||
panic(todo("%v: %T %s", x.Position(), x, x.Source(false)))
|
||||
}
|
||||
default:
|
||||
switch {
|
||||
case x.TypeParameters != nil:
|
||||
panic(todo("%v: %T %s", x.Position(), x, x.Source(false)))
|
||||
default:
|
||||
x.check(c)
|
||||
}
|
||||
}
|
||||
case *AliasDeclNode:
|
||||
x.check(c)
|
||||
default:
|
||||
panic(todo("%v: %T %s", x.Position(), x, x.Source(false)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (n *AliasDeclNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
n.TypeNode.check(c)
|
||||
}
|
||||
|
||||
func (n *ImportDeclNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
type result struct {
|
||||
spec *ImportSpecNode
|
||||
pkg *Package
|
||||
err error
|
||||
}
|
||||
var a []*result
|
||||
var wg sync.WaitGroup
|
||||
for l := n.ImportSpecList; l != nil; l = l.List {
|
||||
r := &result{}
|
||||
a = append(a, r)
|
||||
wg.Add(1)
|
||||
go func(isln *ImportSpecListNode, r *result) {
|
||||
|
||||
defer wg.Done()
|
||||
|
||||
r.spec = isln.ImportSpec
|
||||
r.pkg, r.err = r.spec.check(c)
|
||||
r.spec.pkg = r.pkg
|
||||
}(l, r)
|
||||
}
|
||||
wg.Wait()
|
||||
fileScope := c.ast.FileScope
|
||||
pkgScope := c.pkg.Scope
|
||||
for _, v := range a {
|
||||
switch x := v.err.(type) {
|
||||
case nil:
|
||||
// ok
|
||||
default:
|
||||
panic(todo("%v: %T: %s", v.spec.Position(), x, x))
|
||||
}
|
||||
if c.pkg.ImportPath == "builtin" && v.spec.ImportPath.Src() == `"cmp"` {
|
||||
continue
|
||||
}
|
||||
|
||||
switch ex := fileScope.declare(v.pkg.Name, v.spec, 0, nil, true); {
|
||||
case ex.declTok.IsValid():
|
||||
c.err(n, "%s redeclared, previous declaration at %v:", v.pkg.Name.Src(), ex.declTok.Position())
|
||||
continue
|
||||
}
|
||||
|
||||
switch ex := pkgScope.declare(v.pkg.Name, v.spec, 0, nil, true); {
|
||||
case ex.declTok.IsValid():
|
||||
c.err(n, "%s redeclared, previous declaration at %v:", v.pkg.Name.Src(), ex.declTok.Position())
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (n *ImportSpecNode) check(c *ctx) (*Package, error) {
|
||||
if n == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
switch {
|
||||
case n.PERIOD.IsValid():
|
||||
panic(todo("", n.Position(), n.Source(false)))
|
||||
case n.PackageName.IsValid():
|
||||
//TODO version
|
||||
check := c.pkg.typeCheck
|
||||
switch check {
|
||||
case TypeCheckAll:
|
||||
// nop
|
||||
default:
|
||||
panic(todo("", check))
|
||||
}
|
||||
return c.cfg.newPackage(c.pkg.FSPath, constant.StringVal(n.ImportPath.Value()), "", nil, false, check, c.pkg.guard)
|
||||
default:
|
||||
//TODO version
|
||||
check := c.pkg.typeCheck
|
||||
switch check {
|
||||
case TypeCheckAll:
|
||||
// nop
|
||||
default:
|
||||
if c.pkg.ImportPath == "builtin" && n.ImportPath.Src() == `"cmp"` {
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
return c.cfg.newPackage(c.pkg.FSPath, constant.StringVal(n.ImportPath.Value()), "", nil, false, check, c.pkg.guard)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *PackageClauseNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
nm := n.PackageName.Src()
|
||||
if ex := c.pkg.Name; ex.IsValid() && ex.Src() != nm {
|
||||
c.err(n.PackageName, "found different packages %q and %q", ex.Src(), nm)
|
||||
return
|
||||
}
|
||||
|
||||
c.pkg.Name = n.PackageName
|
||||
}
|
559
vendor/modernc.org/gc/v3/etc.go
generated
vendored
Normal file
559
vendor/modernc.org/gc/v3/etc.go
generated
vendored
Normal file
|
@ -0,0 +1,559 @@
|
|||
// Copyright 2022 The Gc Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gc // modernc.org/gc/v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/token"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
// The list of tokens.
|
||||
const (
|
||||
// Special tokens
|
||||
ILLEGAL = token.ILLEGAL
|
||||
EOF = token.EOF
|
||||
COMMENT = token.COMMENT
|
||||
|
||||
// Identifiers and basic type literals
|
||||
// (these tokens stand for classes of literals)
|
||||
IDENT = token.IDENT // main
|
||||
INT = token.INT // 12345
|
||||
FLOAT = token.FLOAT // 123.45
|
||||
IMAG = token.IMAG // 123.45i
|
||||
CHAR = token.CHAR // 'a'
|
||||
STRING = token.STRING // "abc"
|
||||
|
||||
// Operators and delimiters
|
||||
ADD = token.ADD // +
|
||||
SUB = token.SUB // -
|
||||
MUL = token.MUL // *
|
||||
QUO = token.QUO // /
|
||||
REM = token.REM // %
|
||||
|
||||
AND = token.AND // &
|
||||
OR = token.OR // |
|
||||
XOR = token.XOR // ^
|
||||
SHL = token.SHL // <<
|
||||
SHR = token.SHR // >>
|
||||
AND_NOT = token.AND_NOT // &^
|
||||
|
||||
ADD_ASSIGN = token.ADD_ASSIGN // +=
|
||||
SUB_ASSIGN = token.SUB_ASSIGN // -=
|
||||
MUL_ASSIGN = token.MUL_ASSIGN // *=
|
||||
QUO_ASSIGN = token.QUO_ASSIGN // /=
|
||||
REM_ASSIGN = token.REM_ASSIGN // %=
|
||||
|
||||
AND_ASSIGN = token.AND_ASSIGN // &=
|
||||
OR_ASSIGN = token.OR_ASSIGN // |=
|
||||
XOR_ASSIGN = token.XOR_ASSIGN // ^=
|
||||
SHL_ASSIGN = token.SHL_ASSIGN // <<=
|
||||
SHR_ASSIGN = token.SHR_ASSIGN // >>=
|
||||
AND_NOT_ASSIGN = token.AND_NOT_ASSIGN // &^=
|
||||
|
||||
LAND = token.LAND // &&
|
||||
LOR = token.LOR // ||
|
||||
ARROW = token.ARROW // <-
|
||||
INC = token.INC // ++
|
||||
DEC = token.DEC // --
|
||||
|
||||
EQL = token.EQL // ==
|
||||
LSS = token.LSS // <
|
||||
GTR = token.GTR // >
|
||||
ASSIGN = token.ASSIGN // =
|
||||
NOT = token.NOT // !
|
||||
|
||||
NEQ = token.NEQ // !=
|
||||
LEQ = token.LEQ // <=
|
||||
GEQ = token.GEQ // >=
|
||||
DEFINE = token.DEFINE // :=
|
||||
ELLIPSIS = token.ELLIPSIS // ...
|
||||
|
||||
LPAREN = token.LPAREN // (
|
||||
LBRACK = token.LBRACK // [
|
||||
LBRACE = token.LBRACE // {
|
||||
COMMA = token.COMMA // ,
|
||||
PERIOD = token.PERIOD // .
|
||||
|
||||
RPAREN = token.RPAREN // )
|
||||
RBRACK = token.RBRACK // ]
|
||||
RBRACE = token.RBRACE // }
|
||||
SEMICOLON = token.SEMICOLON // ;
|
||||
COLON = token.COLON // :
|
||||
|
||||
// Keywords
|
||||
BREAK = token.BREAK
|
||||
CASE = token.CASE
|
||||
CHAN = token.CHAN
|
||||
CONST = token.CONST
|
||||
CONTINUE = token.CONTINUE
|
||||
|
||||
DEFAULT = token.DEFAULT
|
||||
DEFER = token.DEFER
|
||||
ELSE = token.ELSE
|
||||
FALLTHROUGH = token.FALLTHROUGH
|
||||
FOR = token.FOR
|
||||
|
||||
FUNC = token.FUNC
|
||||
GO = token.GO
|
||||
GOTO = token.GOTO
|
||||
IF = token.IF
|
||||
IMPORT = token.IMPORT
|
||||
|
||||
INTERFACE = token.INTERFACE
|
||||
MAP = token.MAP
|
||||
PACKAGE = token.PACKAGE
|
||||
RANGE = token.RANGE
|
||||
RETURN = token.RETURN
|
||||
|
||||
SELECT = token.SELECT
|
||||
STRUCT = token.STRUCT
|
||||
SWITCH = token.SWITCH
|
||||
TYPE = token.TYPE
|
||||
VAR = token.VAR
|
||||
|
||||
// additional tokens, handled in an ad-hoc manner
|
||||
TILDE = token.TILDE
|
||||
)
|
||||
|
||||
var (
|
||||
trcTODOs bool
|
||||
extendedErrors bool
|
||||
)
|
||||
|
||||
// origin returns caller's short position, skipping skip frames.
|
||||
func origin(skip int) string {
|
||||
pc, fn, fl, _ := runtime.Caller(skip)
|
||||
f := runtime.FuncForPC(pc)
|
||||
var fns string
|
||||
if f != nil {
|
||||
fns = f.Name()
|
||||
if x := strings.LastIndex(fns, "."); x > 0 {
|
||||
fns = fns[x+1:]
|
||||
}
|
||||
if strings.HasPrefix(fns, "func") {
|
||||
num := true
|
||||
for _, c := range fns[len("func"):] {
|
||||
if c < '0' || c > '9' {
|
||||
num = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if num {
|
||||
return origin(skip + 2)
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s:%d:%s", filepath.Base(fn), fl, fns)
|
||||
}
|
||||
|
||||
// todo prints and returns caller's position and an optional message tagged with TODO. Output goes to stderr.
|
||||
//
|
||||
//lint:ignore U1000 whatever
|
||||
func todo(s string, args ...interface{}) string {
|
||||
switch {
|
||||
case s == "":
|
||||
s = fmt.Sprintf(strings.Repeat("%v ", len(args)), args...)
|
||||
default:
|
||||
s = fmt.Sprintf(s, args...)
|
||||
}
|
||||
r := fmt.Sprintf("%s\n\tTODO (%s)", origin(2), s)
|
||||
// fmt.Fprintf(os.Stderr, "%s\n", r)
|
||||
// os.Stdout.Sync()
|
||||
return r
|
||||
}
|
||||
|
||||
// trc prints and returns caller's position and an optional message tagged with TRC. Output goes to stderr.
|
||||
//
|
||||
//lint:ignore U1000 whatever
|
||||
func trc(s string, args ...interface{}) string {
|
||||
switch {
|
||||
case s == "":
|
||||
s = fmt.Sprintf(strings.Repeat("%v ", len(args)), args...)
|
||||
default:
|
||||
s = fmt.Sprintf(s, args...)
|
||||
}
|
||||
r := fmt.Sprintf("%s: TRC (%s)", origin(2), s)
|
||||
fmt.Fprintf(os.Stderr, "%s\n", r)
|
||||
os.Stderr.Sync()
|
||||
return r
|
||||
}
|
||||
|
||||
func extractPos(s string) (p token.Position, ok bool) {
|
||||
var prefix string
|
||||
if len(s) > 1 && s[1] == ':' { // c:\foo
|
||||
prefix = s[:2]
|
||||
s = s[2:]
|
||||
}
|
||||
// "testdata/parser/bug/001.c:1193: ..."
|
||||
a := strings.Split(s, ":")
|
||||
// ["testdata/parser/bug/001.c" "1193" "..."]
|
||||
if len(a) < 2 {
|
||||
return p, false
|
||||
}
|
||||
|
||||
line, err := strconv.Atoi(a[1])
|
||||
if err != nil {
|
||||
return p, false
|
||||
}
|
||||
|
||||
col, err := strconv.Atoi(a[2])
|
||||
if err != nil {
|
||||
col = 1
|
||||
}
|
||||
|
||||
return token.Position{Filename: prefix + a[0], Line: line, Column: col}, true
|
||||
}
|
||||
|
||||
// errorf constructs an error value. If extendedErrors is true, the error will
|
||||
// contain its origin.
|
||||
func errorf(s string, args ...interface{}) error {
|
||||
switch {
|
||||
case s == "":
|
||||
s = fmt.Sprintf(strings.Repeat("%v ", len(args)), args...)
|
||||
default:
|
||||
s = fmt.Sprintf(s, args...)
|
||||
}
|
||||
if trcTODOs && strings.HasPrefix(s, "TODO") {
|
||||
fmt.Fprintf(os.Stderr, "%s (%v)\n", s, origin(2))
|
||||
os.Stderr.Sync()
|
||||
}
|
||||
switch {
|
||||
case extendedErrors:
|
||||
return fmt.Errorf("%s (%v: %v: %v)", s, origin(4), origin(3), origin(2))
|
||||
default:
|
||||
return fmt.Errorf("%s", s)
|
||||
}
|
||||
}
|
||||
|
||||
func tokSource(t token.Token) string {
|
||||
switch t {
|
||||
case ILLEGAL:
|
||||
return "ILLEGAL"
|
||||
case EOF:
|
||||
return "EOF"
|
||||
case COMMENT:
|
||||
return "COMMENT"
|
||||
case IDENT:
|
||||
return "IDENT"
|
||||
case INT:
|
||||
return "INT"
|
||||
case FLOAT:
|
||||
return "FLOAT"
|
||||
case IMAG:
|
||||
return "IMAG"
|
||||
case CHAR:
|
||||
return "CHAR"
|
||||
case STRING:
|
||||
return "STRING"
|
||||
case ADD:
|
||||
return "ADD"
|
||||
case SUB:
|
||||
return "SUB"
|
||||
case MUL:
|
||||
return "MUL"
|
||||
case QUO:
|
||||
return "QUO"
|
||||
case REM:
|
||||
return "REM"
|
||||
case AND:
|
||||
return "AND"
|
||||
case OR:
|
||||
return "OR"
|
||||
case XOR:
|
||||
return "XOR"
|
||||
case SHL:
|
||||
return "SHL"
|
||||
case SHR:
|
||||
return "SHR"
|
||||
case AND_NOT:
|
||||
return "AND_NOT"
|
||||
case ADD_ASSIGN:
|
||||
return "ADD_ASSIGN"
|
||||
case SUB_ASSIGN:
|
||||
return "SUB_ASSIGN"
|
||||
case MUL_ASSIGN:
|
||||
return "MUL_ASSIGN"
|
||||
case QUO_ASSIGN:
|
||||
return "QUO_ASSIGN"
|
||||
case REM_ASSIGN:
|
||||
return "REM_ASSIGN"
|
||||
case AND_ASSIGN:
|
||||
return "AND_ASSIGN"
|
||||
case OR_ASSIGN:
|
||||
return "OR_ASSIGN"
|
||||
case XOR_ASSIGN:
|
||||
return "XOR_ASSIGN"
|
||||
case SHL_ASSIGN:
|
||||
return "SHL_ASSIGN"
|
||||
case SHR_ASSIGN:
|
||||
return "SHR_ASSIGN"
|
||||
case AND_NOT_ASSIGN:
|
||||
return "AND_NOT_ASSIGN"
|
||||
case LAND:
|
||||
return "LAND"
|
||||
case LOR:
|
||||
return "LOR"
|
||||
case ARROW:
|
||||
return "ARROW"
|
||||
case INC:
|
||||
return "INC"
|
||||
case DEC:
|
||||
return "DEC"
|
||||
case EQL:
|
||||
return "EQL"
|
||||
case LSS:
|
||||
return "LSS"
|
||||
case GTR:
|
||||
return "GTR"
|
||||
case ASSIGN:
|
||||
return "ASSIGN"
|
||||
case NOT:
|
||||
return "NOT"
|
||||
case NEQ:
|
||||
return "NEQ"
|
||||
case LEQ:
|
||||
return "LEQ"
|
||||
case GEQ:
|
||||
return "GEQ"
|
||||
case DEFINE:
|
||||
return "DEFINE"
|
||||
case ELLIPSIS:
|
||||
return "ELLIPSIS"
|
||||
case LPAREN:
|
||||
return "LPAREN"
|
||||
case LBRACK:
|
||||
return "LBRACK"
|
||||
case LBRACE:
|
||||
return "LBRACE"
|
||||
case COMMA:
|
||||
return "COMMA"
|
||||
case PERIOD:
|
||||
return "PERIOD"
|
||||
case RPAREN:
|
||||
return "RPAREN"
|
||||
case RBRACK:
|
||||
return "RBRACK"
|
||||
case RBRACE:
|
||||
return "RBRACE"
|
||||
case SEMICOLON:
|
||||
return "SEMICOLON"
|
||||
case COLON:
|
||||
return "COLON"
|
||||
case BREAK:
|
||||
return "BREAK"
|
||||
case CASE:
|
||||
return "CASE"
|
||||
case CHAN:
|
||||
return "CHAN"
|
||||
case CONST:
|
||||
return "CONST"
|
||||
case CONTINUE:
|
||||
return "CONTINUE"
|
||||
case DEFAULT:
|
||||
return "DEFAULT"
|
||||
case DEFER:
|
||||
return "DEFER"
|
||||
case ELSE:
|
||||
return "ELSE"
|
||||
case FALLTHROUGH:
|
||||
return "FALLTHROUGH"
|
||||
case FOR:
|
||||
return "FOR"
|
||||
case FUNC:
|
||||
return "FUNC"
|
||||
case GO:
|
||||
return "GO"
|
||||
case GOTO:
|
||||
return "GOTO"
|
||||
case IF:
|
||||
return "IF"
|
||||
case IMPORT:
|
||||
return "IMPORT"
|
||||
case INTERFACE:
|
||||
return "INTERFACE"
|
||||
case MAP:
|
||||
return "MAP"
|
||||
case PACKAGE:
|
||||
return "PACKAGE"
|
||||
case RANGE:
|
||||
return "RANGE"
|
||||
case RETURN:
|
||||
return "RETURN"
|
||||
case SELECT:
|
||||
return "SELECT"
|
||||
case STRUCT:
|
||||
return "STRUCT"
|
||||
case SWITCH:
|
||||
return "SWITCH"
|
||||
case TYPE:
|
||||
return "TYPE"
|
||||
case VAR:
|
||||
return "VAR"
|
||||
case TILDE:
|
||||
return "TILDE"
|
||||
default:
|
||||
panic(todo("", int(t), t))
|
||||
}
|
||||
}
|
||||
|
||||
type data struct {
|
||||
line int
|
||||
cases int
|
||||
cnt int
|
||||
}
|
||||
|
||||
type analyzer struct {
|
||||
sync.Mutex
|
||||
m map[int]*data // line: data
|
||||
}
|
||||
|
||||
func newAnalyzer() *analyzer {
|
||||
return &analyzer{m: map[int]*data{}}
|
||||
}
|
||||
|
||||
func (a *analyzer) record(line, cnt int) {
|
||||
d := a.m[line]
|
||||
if d == nil {
|
||||
d = &data{line: line}
|
||||
a.m[line] = d
|
||||
}
|
||||
d.cases++
|
||||
d.cnt += cnt
|
||||
}
|
||||
|
||||
func (a *analyzer) merge(b *analyzer) {
|
||||
a.Lock()
|
||||
defer a.Unlock()
|
||||
|
||||
for k, v := range b.m {
|
||||
d := a.m[k]
|
||||
if d == nil {
|
||||
d = &data{line: k}
|
||||
a.m[k] = d
|
||||
}
|
||||
d.cases += v.cases
|
||||
d.cnt += v.cnt
|
||||
}
|
||||
}
|
||||
|
||||
func (a *analyzer) report() string {
|
||||
var rows []*data
|
||||
for _, v := range a.m {
|
||||
rows = append(rows, v)
|
||||
}
|
||||
sort.Slice(rows, func(i, j int) bool {
|
||||
a := rows[i]
|
||||
b := rows[j]
|
||||
if a.cases < b.cases {
|
||||
return true
|
||||
}
|
||||
|
||||
if a.cases > b.cases {
|
||||
return false
|
||||
}
|
||||
|
||||
// a.cases == b.cases
|
||||
if a.cnt < b.cnt {
|
||||
return true
|
||||
}
|
||||
|
||||
if a.cnt > b.cnt {
|
||||
return false
|
||||
}
|
||||
|
||||
// a.cnt == b.cnt
|
||||
return a.line < b.line
|
||||
})
|
||||
var b strings.Builder
|
||||
var cases, cnt int
|
||||
for _, row := range rows {
|
||||
cases += row.cases
|
||||
cnt += row.cnt
|
||||
avg := float64(row.cnt) / float64(row.cases)
|
||||
fmt.Fprintf(&b, "parser.go:%d:\t%16s %16s %8.1f\n", row.line, h(row.cases), h(row.cnt), avg)
|
||||
}
|
||||
avg := float64(cnt) / float64(cases)
|
||||
fmt.Fprintf(&b, "<total>\t\t%16s %16s %8.1f\n", h(cases), h(cnt), avg)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func h(v interface{}) string {
|
||||
switch x := v.(type) {
|
||||
case int:
|
||||
return humanize.Comma(int64(x))
|
||||
case int32:
|
||||
return humanize.Comma(int64(x))
|
||||
case int64:
|
||||
return humanize.Comma(x)
|
||||
case uint32:
|
||||
return humanize.Comma(int64(x))
|
||||
case uint64:
|
||||
if x <= math.MaxInt64 {
|
||||
return humanize.Comma(int64(x))
|
||||
}
|
||||
|
||||
return "-" + humanize.Comma(-int64(x))
|
||||
}
|
||||
return fmt.Sprint(v)
|
||||
}
|
||||
|
||||
type parallel struct {
|
||||
limiter chan struct{}
|
||||
}
|
||||
|
||||
func newParallel() *parallel {
|
||||
return ¶llel{
|
||||
limiter: make(chan struct{}, runtime.GOMAXPROCS(0)),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parallel) throttle(f func()) {
|
||||
p.limiter <- struct{}{}
|
||||
|
||||
defer func() {
|
||||
<-p.limiter
|
||||
}()
|
||||
|
||||
f()
|
||||
}
|
||||
|
||||
func extraTags(verMajor, verMinor int, goos, goarch string) (r []string) {
|
||||
// https://github.com/golang/go/commit/eeb7899137cda1c2cd60dab65ff41f627436db5b
|
||||
//
|
||||
// In Go 1.17 we added register ABI on AMD64 on Linux/macOS/Windows
|
||||
// as a GOEXPERIMENT, on by default. In Go 1.18, we commit to always
|
||||
// enabling register ABI on AMD64.
|
||||
//
|
||||
// Now "go build" for AMD64 always have goexperiment.regabi* tags
|
||||
// set. However, at bootstrapping cmd/dist does not set the tags
|
||||
// when building go_bootstrap. For this to work, unfortunately, we
|
||||
// need to hard-code AMD64 to use register ABI in runtime code.
|
||||
if verMajor == 1 {
|
||||
switch {
|
||||
case verMinor == 17:
|
||||
switch goos {
|
||||
case "linux", "darwin", "windows":
|
||||
if goarch == "amd64" {
|
||||
r = append(r, "goexperiment.regabiargs", "goexperiment.regabiwrappers")
|
||||
}
|
||||
}
|
||||
case verMinor >= 18:
|
||||
if goarch == "amd64" {
|
||||
r = append(r, "goexperiment.regabiargs", "goexperiment.regabiwrappers")
|
||||
}
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
761
vendor/modernc.org/gc/v3/gc.go
generated
vendored
Normal file
761
vendor/modernc.org/gc/v3/gc.go
generated
vendored
Normal file
|
@ -0,0 +1,761 @@
|
|||
// Copyright 2022 The Gc Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:generate stringer -output stringer.go -linecomment -type=Kind,ScopeKind,ChanDir,TypeCheck
|
||||
|
||||
package gc // modernc.org/gc/v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/build"
|
||||
"go/build/constraint"
|
||||
"go/token"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"unicode"
|
||||
|
||||
"github.com/hashicorp/golang-lru/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
trcErrors bool
|
||||
)
|
||||
|
||||
type FileFilter func(cfg *Config, importPath string, matchedFSPaths []string, withTestFiles bool) (pkgFiles []string, err error)
|
||||
|
||||
type TypeCheck int
|
||||
|
||||
const (
|
||||
TypeCheckNone TypeCheck = iota
|
||||
TypeCheckAll
|
||||
)
|
||||
|
||||
type cacheKey struct {
|
||||
buildTagsKey string
|
||||
cfg *Config
|
||||
fsPath string
|
||||
goarch string
|
||||
goos string
|
||||
gopathKey string
|
||||
goroot string
|
||||
importPath string
|
||||
typeCheck TypeCheck
|
||||
|
||||
withTestFiles bool
|
||||
}
|
||||
|
||||
type cacheItem struct {
|
||||
pkg *Package
|
||||
ch chan struct{}
|
||||
}
|
||||
|
||||
func newCacheItem() *cacheItem { return &cacheItem{ch: make(chan struct{})} }
|
||||
|
||||
func (c *cacheItem) set(pkg *Package) {
|
||||
c.pkg = pkg
|
||||
close(c.ch)
|
||||
}
|
||||
|
||||
func (c *cacheItem) wait() *Package {
|
||||
<-c.ch
|
||||
return c.pkg
|
||||
}
|
||||
|
||||
type Cache struct {
|
||||
sync.Mutex
|
||||
lru *lru.TwoQueueCache[cacheKey, *cacheItem]
|
||||
}
|
||||
|
||||
func NewCache(size int) (*Cache, error) {
|
||||
c, err := lru.New2Q[cacheKey, *cacheItem](size)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Cache{lru: c}, nil
|
||||
}
|
||||
|
||||
func MustNewCache(size int) *Cache {
|
||||
c, err := NewCache(size)
|
||||
if err != nil {
|
||||
panic(todo("", err))
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
type ConfigOption func(*Config) error
|
||||
|
||||
// Config configures NewPackage
|
||||
//
|
||||
// Config instances can be shared, they are not mutated once created and
|
||||
// configured.
|
||||
type Config struct {
|
||||
abi *ABI
|
||||
buildTagMap map[string]bool
|
||||
buildTags []string
|
||||
buildTagsKey string // Zero byte separated
|
||||
builtin *Package
|
||||
cache *Cache
|
||||
cmp *Package // Go 1.21
|
||||
env map[string]string
|
||||
fs fs.FS
|
||||
goarch string
|
||||
gocompiler string // "gc", "gccgo"
|
||||
goos string
|
||||
gopath string
|
||||
gopathKey string // Zero byte separated
|
||||
goroot string
|
||||
goversion string
|
||||
lookup func(rel, importPath, version string) (fsPath string, err error)
|
||||
parallel *parallel
|
||||
searchGoPaths []string
|
||||
searchGoroot []string
|
||||
|
||||
int Type // Set by NewConfig
|
||||
uint Type // Set by NewConfig
|
||||
|
||||
arch32bit bool
|
||||
configured bool
|
||||
}
|
||||
|
||||
// NewConfig returns a newly created config or an error, if any.
|
||||
func NewConfig(opts ...ConfigOption) (r *Config, err error) {
|
||||
r = &Config{
|
||||
buildTagMap: map[string]bool{},
|
||||
env: map[string]string{},
|
||||
parallel: newParallel(),
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r != nil {
|
||||
r.configured = true
|
||||
}
|
||||
}()
|
||||
|
||||
r.lookup = r.DefaultLookup
|
||||
ctx := build.Default
|
||||
r.goos = r.getenv("GOOS", ctx.GOOS)
|
||||
r.goarch = r.getenv("GOARCH", ctx.GOARCH)
|
||||
r.goroot = r.getenv("GOROOT", ctx.GOROOT)
|
||||
r.gopath = r.getenv("GOPATH", ctx.GOPATH)
|
||||
r.buildTags = append(r.buildTags, r.goos, r.goarch)
|
||||
r.gocompiler = runtime.Compiler
|
||||
for _, opt := range opts {
|
||||
if err := opt(r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if r.abi, err = NewABI(r.goos, r.goarch); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch r.goarch {
|
||||
case "386", "arm":
|
||||
r.arch32bit = true
|
||||
}
|
||||
|
||||
// During a particular build, the following build tags are satisfied:
|
||||
//
|
||||
// the target operating system, as spelled by runtime.GOOS, set with the GOOS environment variable.
|
||||
// the target architecture, as spelled by runtime.GOARCH, set with the GOARCH environment variable.
|
||||
// "unix", if GOOS is a Unix or Unix-like system.
|
||||
// the compiler being used, either "gc" or "gccgo"
|
||||
// "cgo", if the cgo command is supported (see CGO_ENABLED in 'go help environment').
|
||||
// a term for each Go major release, through the current version: "go1.1" from Go version 1.1 onward, "go1.12" from Go 1.12, and so on.
|
||||
// any additional tags given by the -tags flag (see 'go help build').
|
||||
// There are no separate build tags for beta or minor releases.
|
||||
if r.goversion == "" {
|
||||
r.goversion = runtime.Version()
|
||||
}
|
||||
if !strings.HasPrefix(r.goversion, "go") || !strings.Contains(r.goversion, ".") {
|
||||
return nil, fmt.Errorf("cannot parse Go version: %s", r.goversion)
|
||||
}
|
||||
|
||||
ver := strings.SplitN(r.goversion[len("go"):], ".", 2)
|
||||
verMajor, err := strconv.Atoi(ver[0])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse Go version %s: %v", r.goversion, err)
|
||||
}
|
||||
|
||||
if verMajor != 1 {
|
||||
return nil, fmt.Errorf("unsupported Go version: %s", r.goversion)
|
||||
}
|
||||
|
||||
switch x, x2 := strings.IndexByte(ver[1], '.'), strings.Index(ver[1], "rc"); {
|
||||
case x >= 0:
|
||||
ver[1] = ver[1][:x]
|
||||
case x2 >= 0:
|
||||
ver[1] = ver[1][:x2]
|
||||
}
|
||||
verMinor, err := strconv.Atoi(ver[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse Go version %s: %v", r.goversion, err)
|
||||
}
|
||||
|
||||
for i := 1; i <= verMinor; i++ {
|
||||
r.buildTags = append(r.buildTags, fmt.Sprintf("go%d.%d", verMajor, i))
|
||||
}
|
||||
r.buildTags = append(r.buildTags, r.gocompiler)
|
||||
r.buildTags = append(r.buildTags, extraTags(verMajor, verMinor, r.goos, r.goarch)...)
|
||||
if r.getenv("CGO_ENABLED", "1") == "1" {
|
||||
r.buildTags = append(r.buildTags, "cgo")
|
||||
}
|
||||
for i, v := range r.buildTags {
|
||||
tag := strings.TrimSpace(v)
|
||||
r.buildTags[i] = tag
|
||||
r.buildTagMap[tag] = true
|
||||
}
|
||||
sort.Strings(r.buildTags)
|
||||
r.buildTagsKey = strings.Join(r.buildTags, "\x00")
|
||||
r.searchGoroot = []string{filepath.Join(r.goroot, "src")}
|
||||
r.searchGoPaths = filepath.SplitList(r.gopath)
|
||||
r.gopathKey = strings.Join(r.searchGoPaths, "\x00")
|
||||
for i, v := range r.searchGoPaths {
|
||||
r.searchGoPaths[i] = filepath.Join(v, "src")
|
||||
}
|
||||
|
||||
switch r.cmp, err = r.NewPackage("", "cmp", "", nil, false, TypeCheckNone); {
|
||||
case err != nil:
|
||||
r.cmp = nil
|
||||
default:
|
||||
//TODO r.cmp.Scope.kind = UniverseScope
|
||||
}
|
||||
if r.builtin, err = r.NewPackage("", "builtin", "", nil, false, TypeCheckNone); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.builtin.Scope.kind = UniverseScope
|
||||
if err := r.builtin.check(newCtx(r)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (c *Config) universe() *Scope {
|
||||
if c.builtin != nil {
|
||||
return c.builtin.Scope
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) stat(name string) (fs.FileInfo, error) {
|
||||
if c.fs == nil {
|
||||
return os.Stat(name)
|
||||
}
|
||||
|
||||
name = filepath.ToSlash(name)
|
||||
if x, ok := c.fs.(fs.StatFS); ok {
|
||||
return x.Stat(name)
|
||||
}
|
||||
|
||||
f, err := c.fs.Open(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
return f.Stat()
|
||||
}
|
||||
|
||||
func (c *Config) open(name string) (fs.File, error) {
|
||||
if c.fs == nil {
|
||||
return os.Open(name)
|
||||
}
|
||||
|
||||
name = filepath.ToSlash(name)
|
||||
return c.fs.Open(name)
|
||||
}
|
||||
|
||||
func (c *Config) glob(pattern string) (matches []string, err error) {
|
||||
if c.fs == nil {
|
||||
return filepath.Glob(pattern)
|
||||
}
|
||||
|
||||
pattern = filepath.ToSlash(pattern)
|
||||
return fs.Glob(c.fs, pattern)
|
||||
}
|
||||
|
||||
func (c *Config) checkConstraints(pos token.Position, sep string) (r bool) {
|
||||
if !strings.Contains(sep, "//go:build") && !strings.Contains(sep, "+build") {
|
||||
return true
|
||||
}
|
||||
|
||||
// defer func() { trc("", r) }()
|
||||
|
||||
lines := strings.Split(sep, "\n")
|
||||
var build, plusBuild []string
|
||||
for i, line := range lines {
|
||||
if constraint.IsGoBuild(line) && i < len(lines)-1 && lines[i+1] == "" {
|
||||
build = append(build, line)
|
||||
}
|
||||
if constraint.IsPlusBuild(line) {
|
||||
plusBuild = append(plusBuild, line)
|
||||
}
|
||||
}
|
||||
switch len(build) {
|
||||
case 0:
|
||||
// ok
|
||||
case 1:
|
||||
expr, err := constraint.Parse(build[0])
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return expr.Eval(func(tag string) (r bool) {
|
||||
// defer func() { trc("%q: %v", tag, r) }()
|
||||
switch tag {
|
||||
case "unix":
|
||||
return unixOS[c.goos]
|
||||
default:
|
||||
return c.buildTagMap[tag]
|
||||
}
|
||||
})
|
||||
default:
|
||||
panic(todo("%v: %q", pos, build))
|
||||
}
|
||||
|
||||
for _, line := range plusBuild {
|
||||
expr, err := constraint.Parse(line)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if !expr.Eval(func(tag string) (r bool) {
|
||||
// defer func() { trc("%q: %v", tag, r) }()
|
||||
switch tag {
|
||||
case "unix":
|
||||
return unixOS[c.goos]
|
||||
default:
|
||||
return c.buildTagMap[tag]
|
||||
}
|
||||
}) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Default lookup translates import paths, possibly relative to rel, to file system paths.
|
||||
func (c *Config) DefaultLookup(rel, importPath, version string) (fsPath string, err error) {
|
||||
if importPath == "" {
|
||||
return "", fmt.Errorf("import path cannot be emtpy")
|
||||
}
|
||||
|
||||
// Implementation restriction: A compiler may restrict ImportPaths to non-empty
|
||||
// strings using only characters belonging to Unicode's L, M, N, P, and S
|
||||
// general categories (the Graphic characters without spaces) and may also
|
||||
// exclude the characters !"#$%&'()*,:;<=>?[\]^`{|} and the Unicode replacement
|
||||
// character U+FFFD.
|
||||
if strings.ContainsAny(importPath, "!\"#$%&'()*,:;<=>?[\\]^`{|}\ufffd") {
|
||||
return "", fmt.Errorf("invalid import path: %s", importPath)
|
||||
}
|
||||
|
||||
for _, r := range importPath {
|
||||
if !unicode.Is(unicode.L, r) &&
|
||||
!unicode.Is(unicode.M, r) &&
|
||||
!unicode.Is(unicode.N, r) &&
|
||||
!unicode.Is(unicode.P, r) &&
|
||||
!unicode.Is(unicode.S, r) {
|
||||
return "", fmt.Errorf("invalid import path: %s", importPath)
|
||||
}
|
||||
}
|
||||
var search []string
|
||||
ip0 := importPath
|
||||
switch slash := strings.IndexByte(importPath, '/'); {
|
||||
case strings.HasPrefix(importPath, "./"):
|
||||
if rel != "" {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("invalid import path: %s", importPath)
|
||||
case strings.HasPrefix(importPath, "/"):
|
||||
return importPath, nil
|
||||
case slash > 0:
|
||||
ip0 = importPath[:slash]
|
||||
default:
|
||||
ip0 = importPath
|
||||
}
|
||||
if ip0 != "" {
|
||||
switch {
|
||||
case strings.Contains(ip0, "."):
|
||||
search = c.searchGoPaths
|
||||
default:
|
||||
search = c.searchGoroot
|
||||
}
|
||||
}
|
||||
for _, v := range search {
|
||||
fsPath = filepath.Join(v, importPath)
|
||||
dir, err := c.open(fsPath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
fi, err := dir.Stat()
|
||||
dir.Close()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if fi.IsDir() {
|
||||
return fsPath, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("cannot find package %s, searched %v", importPath, search)
|
||||
}
|
||||
|
||||
func (c *Config) getenv(nm, deflt string) (r string) {
|
||||
if r = c.env[nm]; r != "" {
|
||||
return r
|
||||
}
|
||||
|
||||
if r = os.Getenv(nm); r != "" {
|
||||
return r
|
||||
}
|
||||
|
||||
return deflt
|
||||
}
|
||||
|
||||
func DefaultFileFilter(cfg *Config, importPath string, matchedFSPaths []string, withTestFiles bool) (pkgFiles []string, err error) {
|
||||
w := 0
|
||||
for _, v := range matchedFSPaths {
|
||||
base := filepath.Base(v)
|
||||
base = base[:len(base)-len(filepath.Ext(base))]
|
||||
const testSuffix = "_test"
|
||||
if strings.HasSuffix(base, testSuffix) {
|
||||
if !withTestFiles {
|
||||
continue
|
||||
}
|
||||
|
||||
base = base[:len(base)-len(testSuffix)]
|
||||
}
|
||||
if x := strings.LastIndexByte(base, '_'); x > 0 {
|
||||
last := base[x+1:]
|
||||
base = base[:x]
|
||||
var prevLast string
|
||||
if x := strings.LastIndexByte(base, '_'); x > 0 {
|
||||
prevLast = base[x+1:]
|
||||
}
|
||||
if last != "" && prevLast != "" {
|
||||
// *_GOOS_GOARCH
|
||||
if knownOS[prevLast] && prevLast != cfg.goos {
|
||||
continue
|
||||
}
|
||||
|
||||
if knownArch[last] && last != cfg.goarch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if last != "" {
|
||||
// *_GOOS or *_GOARCH
|
||||
if knownOS[last] && last != cfg.goos {
|
||||
continue
|
||||
}
|
||||
|
||||
if knownArch[last] && last != cfg.goarch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matchedFSPaths[w] = v
|
||||
w++
|
||||
}
|
||||
return matchedFSPaths[:w], nil
|
||||
}
|
||||
|
||||
// ConfigBuildTags configures build tags.
|
||||
func ConfigBuildTags(tags []string) ConfigOption {
|
||||
return func(cfg *Config) error {
|
||||
if cfg.configured {
|
||||
return fmt.Errorf("ConfigBuildTags: Config instance already configured")
|
||||
}
|
||||
|
||||
cfg.buildTags = append(cfg.buildTags, tags...)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigEnviron configures environment variables.
|
||||
func ConfigEnviron(env []string) ConfigOption {
|
||||
return func(cfg *Config) error {
|
||||
if cfg.configured {
|
||||
return fmt.Errorf("ConfigEnviron: Config instance already configured")
|
||||
}
|
||||
|
||||
for _, v := range env {
|
||||
switch x := strings.IndexByte(v, '='); {
|
||||
case x < 0:
|
||||
cfg.env[v] = ""
|
||||
default:
|
||||
cfg.env[v[:x]] = v[x+1:]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigFS configures a file system used for opening Go source files. If not
|
||||
// explicitly configured, a default os.DirFS("/") is used on Unix-like
|
||||
// operating systems. On Windows it will be rooted on the volume where
|
||||
// runtime.GOROOT() is.
|
||||
func ConfigFS(fs fs.FS) ConfigOption {
|
||||
return func(cfg *Config) error {
|
||||
if cfg.configured {
|
||||
return fmt.Errorf("ConfigFS: Config instance already configured")
|
||||
}
|
||||
|
||||
cfg.fs = fs
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigLookup configures a lookup function.
|
||||
func ConfigLookup(f func(dir, importPath, version string) (fsPath string, err error)) ConfigOption {
|
||||
return func(cfg *Config) error {
|
||||
if cfg.configured {
|
||||
return fmt.Errorf("ConfigLookup: Config instance already configured")
|
||||
}
|
||||
|
||||
cfg.lookup = f
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigCache configures a cache.
|
||||
func ConfigCache(c *Cache) ConfigOption {
|
||||
return func(cfg *Config) error {
|
||||
if cfg.configured {
|
||||
return fmt.Errorf("ConfigCache: Config instance already configured")
|
||||
}
|
||||
|
||||
cfg.cache = c
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
type importGuard struct {
|
||||
m map[string]struct{}
|
||||
stack []string
|
||||
}
|
||||
|
||||
func newImportGuard() *importGuard { return &importGuard{m: map[string]struct{}{}} }
|
||||
|
||||
// Package represents a Go package. The instance must not be mutated.
|
||||
type Package struct {
|
||||
AST map[string]*AST // AST maps fsPaths of individual files to their respective ASTs
|
||||
FSPath string
|
||||
GoFiles []fs.FileInfo
|
||||
ImportPath string
|
||||
InvalidGoFiles map[string]error // errors for particular files, if any
|
||||
Name Token
|
||||
Scope *Scope // Package scope.
|
||||
Version string
|
||||
cfg *Config
|
||||
guard *importGuard
|
||||
mu sync.Mutex
|
||||
typeCheck TypeCheck
|
||||
|
||||
isUnsafe bool // ImportPath == "usnafe"
|
||||
// isChecked bool
|
||||
}
|
||||
|
||||
// NewPackage returns a Package, possibly cached, for importPath@version or an
|
||||
// error, if any. The fileFilter argument can be nil, in such case
|
||||
// DefaultFileFilter is used, which ignores Files with suffix _test.go unless
|
||||
// withTestFiles is true.
|
||||
//
|
||||
// NewPackage is safe for concurrent use by multiple goroutines.
|
||||
func (c *Config) NewPackage(dir, importPath, version string, fileFilter FileFilter, withTestFiles bool, typeCheck TypeCheck) (pkg *Package, err error) {
|
||||
return c.newPackage(dir, importPath, version, fileFilter, withTestFiles, typeCheck, newImportGuard())
|
||||
}
|
||||
|
||||
func (c *Config) newPackage(dir, importPath, version string, fileFilter FileFilter, withTestFiles bool, typeCheck TypeCheck, guard *importGuard) (pkg *Package, err error) {
|
||||
if _, ok := guard.m[importPath]; ok {
|
||||
return nil, fmt.Errorf("import cycle %v", guard.stack)
|
||||
}
|
||||
|
||||
guard.stack = append(guard.stack, importPath)
|
||||
fsPath, err := c.lookup(dir, importPath, version)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("lookup %s: %v", importPath, err)
|
||||
}
|
||||
|
||||
pat := filepath.Join(fsPath, "*.go")
|
||||
matches, err := c.glob(pat)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("glob %s: %v", pat, err)
|
||||
}
|
||||
|
||||
if len(matches) == 0 {
|
||||
return nil, fmt.Errorf("no Go files in %s", fsPath)
|
||||
}
|
||||
|
||||
if fileFilter == nil {
|
||||
fileFilter = DefaultFileFilter
|
||||
}
|
||||
if matches, err = fileFilter(c, importPath, matches, withTestFiles); err != nil {
|
||||
return nil, fmt.Errorf("matching Go files in %s: %v", fsPath, err)
|
||||
}
|
||||
|
||||
var k cacheKey
|
||||
if c.cache != nil {
|
||||
k = cacheKey{
|
||||
buildTagsKey: c.buildTagsKey,
|
||||
cfg: c,
|
||||
fsPath: fsPath,
|
||||
goarch: c.goarch,
|
||||
goos: c.goos,
|
||||
gopathKey: c.gopathKey,
|
||||
goroot: c.goroot,
|
||||
importPath: importPath,
|
||||
typeCheck: typeCheck,
|
||||
withTestFiles: withTestFiles,
|
||||
}
|
||||
|
||||
c.cache.Lock() // ---------------------------------------- lock
|
||||
item, ok := c.cache.lru.Get(k)
|
||||
if ok {
|
||||
c.cache.Unlock() // ---------------------------- unlock
|
||||
if pkg = item.wait(); pkg != nil && pkg.matches(&k, matches) {
|
||||
return pkg, nil
|
||||
}
|
||||
}
|
||||
|
||||
item = newCacheItem()
|
||||
c.cache.lru.Add(k, item)
|
||||
c.cache.Unlock() // ------------------------------------ unlock
|
||||
|
||||
defer func() {
|
||||
if pkg != nil && err == nil {
|
||||
item.set(pkg)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
r := &Package{
|
||||
AST: map[string]*AST{},
|
||||
FSPath: fsPath,
|
||||
ImportPath: importPath,
|
||||
Scope: newScope(c.universe(), PackageScope),
|
||||
Version: version,
|
||||
cfg: c,
|
||||
guard: guard,
|
||||
isUnsafe: importPath == "unsafe",
|
||||
typeCheck: typeCheck,
|
||||
}
|
||||
|
||||
defer func() { r.guard = nil }()
|
||||
|
||||
sort.Strings(matches)
|
||||
|
||||
defer func() {
|
||||
sort.Slice(r.GoFiles, func(i, j int) bool { return r.GoFiles[i].Name() < r.GoFiles[j].Name() })
|
||||
if err != nil || len(r.InvalidGoFiles) != 0 || typeCheck == TypeCheckNone {
|
||||
return
|
||||
}
|
||||
|
||||
//TODO err = r.check(newCtx(c))
|
||||
}()
|
||||
|
||||
c.parallel.throttle(func() {
|
||||
for _, path := range matches {
|
||||
if err = c.newPackageFile(r, path); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
return r, err
|
||||
}
|
||||
|
||||
func (c *Config) newPackageFile(pkg *Package, path string) (err error) {
|
||||
f, err := c.open(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening file %q: %v", path, err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
f.Close()
|
||||
if err != nil {
|
||||
if pkg.InvalidGoFiles == nil {
|
||||
pkg.InvalidGoFiles = map[string]error{}
|
||||
}
|
||||
pkg.InvalidGoFiles[path] = err
|
||||
}
|
||||
}()
|
||||
|
||||
var fi fs.FileInfo
|
||||
if fi, err = f.Stat(); err != nil {
|
||||
return fmt.Errorf("stat %s: %v", path, err)
|
||||
}
|
||||
|
||||
if !fi.Mode().IsRegular() {
|
||||
return nil
|
||||
}
|
||||
|
||||
var b []byte
|
||||
if b, err = io.ReadAll(f); err != nil {
|
||||
return fmt.Errorf("reading %s: %v", path, err)
|
||||
}
|
||||
|
||||
p := newParser(pkg.Scope, path, b, false)
|
||||
if p.peek(0) == PACKAGE {
|
||||
tok := Token{p.s.source, p.s.toks[p.ix].ch, int32(p.ix)}
|
||||
if !c.checkConstraints(tok.Position(), tok.Sep()) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
pkg.GoFiles = append(pkg.GoFiles, fi)
|
||||
var ast *AST
|
||||
if ast, err = p.parse(); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
pkg.AST[path] = ast
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Package) matches(k *cacheKey, matches []string) bool {
|
||||
matched := map[string]struct{}{}
|
||||
for _, match := range matches {
|
||||
matched[match] = struct{}{}
|
||||
}
|
||||
for _, cachedInfo := range p.GoFiles {
|
||||
name := cachedInfo.Name()
|
||||
path := filepath.Join(p.FSPath, name)
|
||||
if _, ok := matched[path]; !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
info, err := k.cfg.stat(path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if info.IsDir() ||
|
||||
info.Size() != cachedInfo.Size() ||
|
||||
info.ModTime().After(cachedInfo.ModTime()) ||
|
||||
info.Mode() != cachedInfo.Mode() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ParseFile parses 'b', assuming it comes from 'path' and returns an AST or error, if any.
|
||||
func ParseFile(path string, b []byte) (*AST, error) {
|
||||
return newParser(newScope(nil, PackageScope), path, b, false).parse()
|
||||
}
|
9415
vendor/modernc.org/gc/v3/parser.go
generated
vendored
Normal file
9415
vendor/modernc.org/gc/v3/parser.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
1446
vendor/modernc.org/gc/v3/scanner.go
generated
vendored
Normal file
1446
vendor/modernc.org/gc/v3/scanner.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
115
vendor/modernc.org/gc/v3/stringer.go
generated
vendored
Normal file
115
vendor/modernc.org/gc/v3/stringer.go
generated
vendored
Normal file
|
@ -0,0 +1,115 @@
|
|||
// Code generated by "stringer -output stringer.go -linecomment -type=Kind,ScopeKind,ChanDir,TypeCheck"; DO NOT EDIT.
|
||||
|
||||
package gc
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[InvalidKind-0]
|
||||
_ = x[Array-1]
|
||||
_ = x[Bool-2]
|
||||
_ = x[Chan-3]
|
||||
_ = x[Complex128-4]
|
||||
_ = x[Complex64-5]
|
||||
_ = x[Float32-6]
|
||||
_ = x[Float64-7]
|
||||
_ = x[Function-8]
|
||||
_ = x[Int-9]
|
||||
_ = x[Int16-10]
|
||||
_ = x[Int32-11]
|
||||
_ = x[Int64-12]
|
||||
_ = x[Int8-13]
|
||||
_ = x[Interface-14]
|
||||
_ = x[Map-15]
|
||||
_ = x[Pointer-16]
|
||||
_ = x[Slice-17]
|
||||
_ = x[String-18]
|
||||
_ = x[Struct-19]
|
||||
_ = x[Tuple-20]
|
||||
_ = x[Uint-21]
|
||||
_ = x[Uint16-22]
|
||||
_ = x[Uint32-23]
|
||||
_ = x[Uint64-24]
|
||||
_ = x[Uint8-25]
|
||||
_ = x[Uintptr-26]
|
||||
_ = x[UnsafePointer-27]
|
||||
_ = x[UntypedBool-28]
|
||||
_ = x[UntypedComplex-29]
|
||||
_ = x[UntypedFloat-30]
|
||||
_ = x[UntypedInt-31]
|
||||
_ = x[UntypedNil-32]
|
||||
_ = x[UntypedRune-33]
|
||||
_ = x[UntypedString-34]
|
||||
}
|
||||
|
||||
const _Kind_name = "<invalid type>arrayboolchancomplex128complex64float32float64functionintint16int32int64int8interfacemappointerslicestringstructtupleuintuint16uint32uint64uint8uintptrunsafe.Pointeruntyped booluntyped complexuntyped floatuntyped intuntyped niluntyped runeuntyped string"
|
||||
|
||||
var _Kind_index = [...]uint16{0, 14, 19, 23, 27, 37, 46, 53, 60, 68, 71, 76, 81, 86, 90, 99, 102, 109, 114, 120, 126, 131, 135, 141, 147, 153, 158, 165, 179, 191, 206, 219, 230, 241, 253, 267}
|
||||
|
||||
func (i Kind) String() string {
|
||||
if i >= Kind(len(_Kind_index)-1) {
|
||||
return "Kind(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Kind_name[_Kind_index[i]:_Kind_index[i+1]]
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[scZero-0]
|
||||
_ = x[UniverseScope-1]
|
||||
_ = x[PackageScope-2]
|
||||
_ = x[FileScope-3]
|
||||
_ = x[OtherScope-4]
|
||||
}
|
||||
|
||||
const _ScopeKind_name = "scZeroUniverseScopePackageScopeFileScopeOtherScope"
|
||||
|
||||
var _ScopeKind_index = [...]uint8{0, 6, 19, 31, 40, 50}
|
||||
|
||||
func (i ScopeKind) String() string {
|
||||
if i < 0 || i >= ScopeKind(len(_ScopeKind_index)-1) {
|
||||
return "ScopeKind(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _ScopeKind_name[_ScopeKind_index[i]:_ScopeKind_index[i+1]]
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[SendRecv-0]
|
||||
_ = x[SendOnly-1]
|
||||
_ = x[RecvOnly-2]
|
||||
}
|
||||
|
||||
const _ChanDir_name = "SendRecvSendOnlyRecvOnly"
|
||||
|
||||
var _ChanDir_index = [...]uint8{0, 8, 16, 24}
|
||||
|
||||
func (i ChanDir) String() string {
|
||||
if i < 0 || i >= ChanDir(len(_ChanDir_index)-1) {
|
||||
return "ChanDir(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _ChanDir_name[_ChanDir_index[i]:_ChanDir_index[i+1]]
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[TypeCheckNone-0]
|
||||
_ = x[TypeCheckAll-1]
|
||||
}
|
||||
|
||||
const _TypeCheck_name = "TypeCheckNoneTypeCheckAll"
|
||||
|
||||
var _TypeCheck_index = [...]uint8{0, 13, 25}
|
||||
|
||||
func (i TypeCheck) String() string {
|
||||
if i < 0 || i >= TypeCheck(len(_TypeCheck_index)-1) {
|
||||
return "TypeCheck(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _TypeCheck_name[_TypeCheck_index[i]:_TypeCheck_index[i+1]]
|
||||
}
|
90
vendor/modernc.org/gc/v3/syslist.go
generated
vendored
Normal file
90
vendor/modernc.org/gc/v3/syslist.go
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the GO-LICENSE file.
|
||||
|
||||
// Modifications
|
||||
//
|
||||
// Copyright 2022 The Gc Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// package build // /usr/local/go/src/go/build/syslist.go
|
||||
|
||||
package gc // import "modernc.org/gc/v3"
|
||||
|
||||
// Go 1.19.3
|
||||
|
||||
// Note that this file is read by internal/goarch/gengoarch.go and by
|
||||
// internal/goos/gengoos.go. If you change this file, look at those
|
||||
// files as well.
|
||||
|
||||
// knownOS is the list of past, present, and future known GOOS values.
|
||||
// Do not remove from this list, as it is used for filename matching.
|
||||
// If you add an entry to this list, look at unixOS, below.
|
||||
var knownOS = map[string]bool{
|
||||
"aix": true,
|
||||
"android": true,
|
||||
"darwin": true,
|
||||
"dragonfly": true,
|
||||
"freebsd": true,
|
||||
"hurd": true,
|
||||
"illumos": true,
|
||||
"ios": true,
|
||||
"js": true,
|
||||
"linux": true,
|
||||
"nacl": true,
|
||||
"netbsd": true,
|
||||
"openbsd": true,
|
||||
"plan9": true,
|
||||
"solaris": true,
|
||||
"windows": true,
|
||||
"zos": true,
|
||||
}
|
||||
|
||||
// unixOS is the set of GOOS values matched by the "unix" build tag.
|
||||
// This is not used for filename matching.
|
||||
// This list also appears in cmd/dist/build.go and
|
||||
// cmd/go/internal/imports/build.go.
|
||||
var unixOS = map[string]bool{
|
||||
"aix": true,
|
||||
"android": true,
|
||||
"darwin": true,
|
||||
"dragonfly": true,
|
||||
"freebsd": true,
|
||||
"hurd": true,
|
||||
"illumos": true,
|
||||
"ios": true,
|
||||
"linux": true,
|
||||
"netbsd": true,
|
||||
"openbsd": true,
|
||||
"solaris": true,
|
||||
}
|
||||
|
||||
// knownArch is the list of past, present, and future known GOARCH values.
|
||||
// Do not remove from this list, as it is used for filename matching.
|
||||
var knownArch = map[string]bool{
|
||||
"386": true,
|
||||
"amd64": true,
|
||||
"amd64p32": true,
|
||||
"arm": true,
|
||||
"armbe": true,
|
||||
"arm64": true,
|
||||
"arm64be": true,
|
||||
"loong64": true,
|
||||
"mips": true,
|
||||
"mipsle": true,
|
||||
"mips64": true,
|
||||
"mips64le": true,
|
||||
"mips64p32": true,
|
||||
"mips64p32le": true,
|
||||
"ppc": true,
|
||||
"ppc64": true,
|
||||
"ppc64le": true,
|
||||
"riscv": true,
|
||||
"riscv64": true,
|
||||
"s390": true,
|
||||
"s390x": true,
|
||||
"sparc": true,
|
||||
"sparc64": true,
|
||||
"wasm": true,
|
||||
}
|
813
vendor/modernc.org/gc/v3/type.go
generated
vendored
Normal file
813
vendor/modernc.org/gc/v3/type.go
generated
vendored
Normal file
|
@ -0,0 +1,813 @@
|
|||
// Copyright 2022 The Gc Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gc // modernc.org/gc/v3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/token"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
Invalid = &InvalidType{}
|
||||
)
|
||||
|
||||
var (
|
||||
_ Type = (*ArrayTypeNode)(nil)
|
||||
_ Type = (*ChannelTypeNode)(nil)
|
||||
_ Type = (*FunctionTypeNode)(nil)
|
||||
_ Type = (*InterfaceTypeNode)(nil)
|
||||
_ Type = (*InvalidType)(nil)
|
||||
_ Type = (*MapTypeNode)(nil)
|
||||
_ Type = (*ParenthesizedTypeNode)(nil)
|
||||
_ Type = (*PointerTypeNode)(nil)
|
||||
_ Type = (*PredeclaredType)(nil)
|
||||
_ Type = (*SliceTypeNode)(nil)
|
||||
_ Type = (*StructTypeNode)(nil)
|
||||
_ Type = (*TupleType)(nil)
|
||||
_ Type = (*TypeDefNode)(nil)
|
||||
_ Type = (*TypeNameNode)(nil)
|
||||
_ Type = (*TypeNode)(nil)
|
||||
|
||||
invalidRecursiveType = &InvalidType{}
|
||||
)
|
||||
|
||||
// A Kind represents the specific kind of type that a Type represents. The zero
|
||||
// Kind is not a valid kind.
|
||||
type Kind byte
|
||||
|
||||
// Values of type Kind
|
||||
const (
|
||||
InvalidKind Kind = iota // <invalid type>
|
||||
|
||||
Array // array
|
||||
Bool // bool
|
||||
Chan // chan
|
||||
Complex128 // complex128
|
||||
Complex64 // complex64
|
||||
Float32 // float32
|
||||
Float64 // float64
|
||||
Function // function
|
||||
Int // int
|
||||
Int16 // int16
|
||||
Int32 // int32
|
||||
Int64 // int64
|
||||
Int8 // int8
|
||||
Interface // interface
|
||||
Map // map
|
||||
Pointer // pointer
|
||||
Slice // slice
|
||||
String // string
|
||||
Struct // struct
|
||||
Tuple // tuple
|
||||
Uint // uint
|
||||
Uint16 // uint16
|
||||
Uint32 // uint32
|
||||
Uint64 // uint64
|
||||
Uint8 // uint8
|
||||
Uintptr // uintptr
|
||||
UnsafePointer // unsafe.Pointer
|
||||
UntypedBool // untyped bool
|
||||
UntypedComplex // untyped complex
|
||||
UntypedFloat // untyped float
|
||||
UntypedInt // untyped int
|
||||
UntypedNil // untyped nil
|
||||
UntypedRune // untyped rune
|
||||
UntypedString // untyped string
|
||||
)
|
||||
|
||||
type typeSetter interface {
|
||||
setType(t Type) Type
|
||||
}
|
||||
|
||||
type typeCache struct {
|
||||
t Type
|
||||
}
|
||||
|
||||
func (n *typeCache) Type() Type {
|
||||
if n.t != nil {
|
||||
return n.t
|
||||
}
|
||||
|
||||
n.t = Invalid
|
||||
return Invalid
|
||||
}
|
||||
|
||||
func (n *typeCache) setType(t Type) Type {
|
||||
n.t = t
|
||||
return t
|
||||
}
|
||||
|
||||
func (n *typeCache) enter(c *ctx, nd Node) bool {
|
||||
switch {
|
||||
case n.t == nil:
|
||||
n.t = invalidRecursiveType
|
||||
return true
|
||||
case n.t == invalidRecursiveType:
|
||||
n.t = Invalid
|
||||
c.err(nd, "invalid recursive type")
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type typer interface {
|
||||
Type() Type
|
||||
}
|
||||
|
||||
type Type interface {
|
||||
Node
|
||||
|
||||
// Align returns the alignment in bytes of a value of this type when allocated
|
||||
// in memory.
|
||||
Align() int
|
||||
|
||||
// FieldAlign returns the alignment in bytes of a value of this type when used
|
||||
// as a field in a struct.
|
||||
FieldAlign() int
|
||||
|
||||
// Kind returns the specific kind of this type.
|
||||
Kind() Kind
|
||||
|
||||
// Size returns the number of bytes needed to store a value of the given type;
|
||||
// it is analogous to unsafe.Sizeof.
|
||||
Size() int64
|
||||
|
||||
// String returns a string representation of the type. The string
|
||||
// representation is not guaranteed to be unique among types.
|
||||
String() string
|
||||
|
||||
check(c *ctx) Type
|
||||
}
|
||||
|
||||
func (n *ArrayTypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *ArrayTypeNode) FieldAlign() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *ArrayTypeNode) Kind() Kind { return Array }
|
||||
func (n *ArrayTypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *ArrayTypeNode) String() string {
|
||||
return fmt.Sprintf("[%v]%v", n.ArrayLength.Value(), n.ElementType)
|
||||
}
|
||||
|
||||
func (n *ArrayTypeNode) check(c *ctx) Type {
|
||||
if n == nil {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
n.ArrayLength = n.ArrayLength.checkExpr(c)
|
||||
v := c.convertValue(n.ArrayLength, n.ArrayLength.Value(), c.cfg.int)
|
||||
if !known(v) {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
n.ElementType.check(c)
|
||||
return n
|
||||
}
|
||||
|
||||
// ChanDir represents a channel direction.
|
||||
type ChanDir int
|
||||
|
||||
// Values of type ChanDir.
|
||||
const (
|
||||
SendRecv ChanDir = iota
|
||||
SendOnly
|
||||
RecvOnly
|
||||
)
|
||||
|
||||
func (n *ChannelTypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *ChannelTypeNode) FieldAlign() int {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ChannelTypeNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *ChannelTypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *ChannelTypeNode) String() string { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *ChannelTypeNode) check(c *ctx) Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *FunctionTypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *FunctionTypeNode) FieldAlign() int {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *FunctionTypeNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *FunctionTypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *FunctionTypeNode) String() string {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
func (n *FunctionTypeNode) check(c *ctx) Type {
|
||||
if !n.enter(c, n) {
|
||||
if n.guard == guardChecking {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
defer func() { n.guard = guardChecked }()
|
||||
|
||||
n.Signature.check(c)
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *InterfaceTypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *InterfaceTypeNode) FieldAlign() int {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *InterfaceTypeNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *InterfaceTypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *InterfaceTypeNode) String() string {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
func (n *InterfaceTypeNode) check(c *ctx) Type {
|
||||
if !n.enter(c, n) {
|
||||
if n.guard == guardChecking {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
defer func() { n.guard = guardChecked }()
|
||||
|
||||
n.InterfaceElemList.check(c, n)
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *InterfaceElemListNode) check(c *ctx, t *InterfaceTypeNode) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
for l := n; l != nil; l = l.List {
|
||||
l.InterfaceElem.check(c, t)
|
||||
}
|
||||
}
|
||||
|
||||
func (n *InterfaceElemNode) check(c *ctx, t *InterfaceTypeNode) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
n.MethodElem.check(c, t)
|
||||
n.TypeElem.check(c)
|
||||
}
|
||||
|
||||
func (n *MethodElemNode) check(c *ctx, t *InterfaceTypeNode) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
nm := n.MethodName.Src()
|
||||
if ex := t.methods[nm]; ex != nil {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
if t.methods == nil {
|
||||
t.methods = map[string]*MethodElemNode{}
|
||||
}
|
||||
t.methods[nm] = n
|
||||
n.typ = n.Signature.check(c)
|
||||
}
|
||||
|
||||
func (n *TypeElemListNode) check(c *ctx) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
type InvalidType struct{}
|
||||
|
||||
func (n *InvalidType) Align() int { return 1 }
|
||||
func (n *InvalidType) FieldAlign() int { return 1 }
|
||||
func (n *InvalidType) Kind() Kind { return InvalidKind }
|
||||
func (n *InvalidType) Position() (r token.Position) { return r }
|
||||
func (n *InvalidType) Size() int64 { return 1 }
|
||||
func (n *InvalidType) Source(full bool) string { return "<invalid type>" }
|
||||
func (n *InvalidType) String() string { return "<invalid type>" }
|
||||
func (n *InvalidType) check(c *ctx) Type { return n }
|
||||
|
||||
func (n *MapTypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *MapTypeNode) FieldAlign() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *MapTypeNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *MapTypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *MapTypeNode) String() string { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *MapTypeNode) check(c *ctx) Type { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *ParenthesizedTypeNode) Align() int {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ParenthesizedTypeNode) FieldAlign() int {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ParenthesizedTypeNode) Kind() Kind {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ParenthesizedTypeNode) Size() int64 {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ParenthesizedTypeNode) String() string {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ParenthesizedTypeNode) check(c *ctx) Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *PointerTypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *PointerTypeNode) FieldAlign() int {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *PointerTypeNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *PointerTypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *PointerTypeNode) String() string { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *PointerTypeNode) check(c *ctx) Type {
|
||||
if !n.enter(c, n) {
|
||||
if n.guard == guardChecking {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
defer func() { n.guard = guardChecked }()
|
||||
|
||||
switch x := n.BaseType.(type) {
|
||||
case *TypeNameNode:
|
||||
x.checkDefined(c)
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
type PredeclaredType struct {
|
||||
Node
|
||||
kind Kind
|
||||
t ABIType
|
||||
}
|
||||
|
||||
func (c *ctx) newPredeclaredType(n Node, kind Kind) *PredeclaredType {
|
||||
t, ok := c.cfg.abi.Types[kind]
|
||||
if !ok && !isAnyUntypedKind(kind) {
|
||||
panic(todo("%v: internal error %s: %s", n.Position(), n.Source(false), kind))
|
||||
}
|
||||
|
||||
return &PredeclaredType{
|
||||
Node: n,
|
||||
kind: kind,
|
||||
t: t,
|
||||
}
|
||||
}
|
||||
|
||||
func (n *PredeclaredType) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *PredeclaredType) FieldAlign() int {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *PredeclaredType) Kind() Kind { return n.kind }
|
||||
func (n *PredeclaredType) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *PredeclaredType) String() string {
|
||||
switch n.Kind() {
|
||||
case
|
||||
String,
|
||||
UntypedInt:
|
||||
|
||||
return n.Kind().String()
|
||||
default:
|
||||
panic(todo("%v: %s %s", n.Position(), n.Kind(), n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *PredeclaredType) check(c *ctx) Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *SliceTypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *SliceTypeNode) FieldAlign() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *SliceTypeNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *SliceTypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *SliceTypeNode) String() string { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *SliceTypeNode) check(c *ctx) Type {
|
||||
if !n.enter(c, n) {
|
||||
if n.guard == guardChecking {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
defer func() { n.guard = guardChecked }()
|
||||
|
||||
switch x := n.ElementType.(type) {
|
||||
case *TypeNameNode:
|
||||
x.checkDefined(c)
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
type Field struct {
|
||||
Declaration *FieldDeclNode
|
||||
Name string
|
||||
}
|
||||
|
||||
func (n *StructTypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *StructTypeNode) FieldAlign() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *StructTypeNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *StructTypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *StructTypeNode) String() string { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *StructTypeNode) check(c *ctx) Type {
|
||||
if !n.enter(c, n) {
|
||||
if n.guard == guardChecking {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
defer func() { n.guard = guardChecked }()
|
||||
|
||||
for l := n.FieldDeclList; l != nil; l = l.List {
|
||||
n.fields = append(n.fields, l.check(c)...)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *FieldDeclListNode) check(c *ctx) []Field {
|
||||
return n.FieldDecl.check(c)
|
||||
}
|
||||
|
||||
func (n *FieldDeclNode) check(c *ctx) (r []Field) {
|
||||
switch {
|
||||
case n.EmbeddedField != nil:
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
default:
|
||||
n.TypeNode.check(c)
|
||||
for l := n.IdentifierList; l != nil; l = l.List {
|
||||
r = append(r, Field{n, l.IDENT.Src()})
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
type TupleType struct {
|
||||
Node
|
||||
Types []Type
|
||||
}
|
||||
|
||||
func newTupleType(n Node, types []Type) *TupleType { return &TupleType{n, types} }
|
||||
|
||||
func (n *TupleType) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TupleType) FieldAlign() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TupleType) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *TupleType) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func (n *TupleType) Source(full bool) (r string) {
|
||||
if n.Node != nil {
|
||||
r = n.Node.Source(full)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (n *TupleType) String() string {
|
||||
var a []string
|
||||
for _, v := range n.Types {
|
||||
a = append(a, v.String())
|
||||
}
|
||||
return fmt.Sprintf("(%s)", strings.Join(a, ", "))
|
||||
}
|
||||
|
||||
func (n *TupleType) check(c *ctx) Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *TypeDefNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeDefNode) FieldAlign() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeDefNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeDefNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeDefNode) String() string { return fmt.Sprintf("%s.%s", n.pkg.ImportPath, n.IDENT.Src()) }
|
||||
|
||||
func (n *TypeDefNode) check(c *ctx) Type {
|
||||
if n == nil {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
if n.pkg != nil {
|
||||
return n
|
||||
}
|
||||
|
||||
n.pkg = c.pkg
|
||||
if n.TypeParameters != nil {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
switch x := n.TypeNode.check(c).(type) {
|
||||
case *PredeclaredType:
|
||||
n.TypeNode = x
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *TypeNameNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNameNode) FieldAlign() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNameNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNameNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNameNode) String() string { return n.Name.Source(false) }
|
||||
|
||||
func (n *TypeNameNode) checkDefined(c *ctx) bool {
|
||||
switch x := n.Name.(type) {
|
||||
case Token:
|
||||
switch _, nmd := n.LexicalScope().lookup(x); y := nmd.n.(type) {
|
||||
case *TypeDefNode, *AliasDeclNode:
|
||||
return true
|
||||
default:
|
||||
panic(todo("%v: type=%T %s", y.Position(), y, y.Source(false)))
|
||||
}
|
||||
case *QualifiedIdentNode:
|
||||
if !token.IsExported(x.IDENT.Src()) {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
switch _, nmd := n.LexicalScope().lookup(x.PackageName); y := nmd.n.(type) {
|
||||
case *ImportSpecNode:
|
||||
if y.pkg == nil {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
switch _, nmd := y.pkg.Scope.lookup(x.IDENT); z := nmd.n.(type) {
|
||||
case *TypeDefNode, *AliasDeclNode:
|
||||
return true
|
||||
default:
|
||||
panic(todo("%v: type=%T %s", z.Position(), z, z.Source(false)))
|
||||
}
|
||||
default:
|
||||
panic(todo("%v: type=%T %s", y.Position(), y, y.Source(false)))
|
||||
}
|
||||
default:
|
||||
panic(todo("%v: type=%T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *TypeNameNode) check(c *ctx) Type {
|
||||
if n == nil {
|
||||
return Invalid
|
||||
}
|
||||
|
||||
switch x := n.Name.(type) {
|
||||
case Token:
|
||||
nm := x.Src()
|
||||
if c.isBuiltin() {
|
||||
switch nm {
|
||||
case "bool":
|
||||
return c.newPredeclaredType(n, Bool)
|
||||
case "uint8":
|
||||
return c.newPredeclaredType(n, Uint8)
|
||||
case "uint16":
|
||||
return c.newPredeclaredType(n, Uint16)
|
||||
case "uint32":
|
||||
return c.newPredeclaredType(n, Uint32)
|
||||
case "uint64":
|
||||
return c.newPredeclaredType(n, Uint64)
|
||||
case "int8":
|
||||
return c.newPredeclaredType(n, Int8)
|
||||
case "int16":
|
||||
return c.newPredeclaredType(n, Int16)
|
||||
case "int32":
|
||||
return c.newPredeclaredType(n, Int32)
|
||||
case "int64":
|
||||
return c.newPredeclaredType(n, Int64)
|
||||
case "float32":
|
||||
return c.newPredeclaredType(n, Float32)
|
||||
case "float64":
|
||||
return c.newPredeclaredType(n, Float64)
|
||||
case "complex64":
|
||||
return c.newPredeclaredType(n, Complex64)
|
||||
case "complex128":
|
||||
return c.newPredeclaredType(n, Complex128)
|
||||
case "string":
|
||||
return c.newPredeclaredType(n, String)
|
||||
case "int":
|
||||
return c.newPredeclaredType(n, Int)
|
||||
case "uint":
|
||||
return c.newPredeclaredType(n, Uint)
|
||||
case "uintptr":
|
||||
return c.newPredeclaredType(n, Uintptr)
|
||||
case "Type":
|
||||
// ok
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
pkg, _, nmd := c.lookup(n.LexicalScope(), x)
|
||||
switch y := nmd.n.(type) {
|
||||
case *TypeDefNode:
|
||||
if pkg != c.pkg {
|
||||
return y
|
||||
}
|
||||
|
||||
return y.check(c)
|
||||
case nil:
|
||||
panic(todo("%v: %T %s", x.Position(), y, x.Source(false)))
|
||||
default:
|
||||
panic(todo("%v: %T %s", y.Position(), y, y.Source(false)))
|
||||
}
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *TypeNode) Align() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNode) FieldAlign() int { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNode) Kind() Kind { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNode) Size() int64 { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNode) String() string { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
func (n *TypeNode) check(c *ctx) Type { panic(todo("%v: %T %s", n.Position(), n, n.Source(false))) }
|
||||
|
||||
func isAnyUntypedType(t Type) bool { return isAnyUntypedKind(t.Kind()) }
|
||||
|
||||
func isAnyUntypedKind(k Kind) bool {
|
||||
switch k {
|
||||
case UntypedBool, UntypedComplex, UntypedFloat, UntypedInt, UntypedNil, UntypedRune, UntypedString:
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
guardUnchecked guard = iota
|
||||
guardChecking
|
||||
guardChecked
|
||||
)
|
||||
|
||||
type guard byte
|
||||
|
||||
func (n *guard) enter(c *ctx, nd Node) bool {
|
||||
switch *n {
|
||||
case guardUnchecked:
|
||||
*n = guardChecking
|
||||
return true
|
||||
case guardChecking:
|
||||
c.err(nd, "invalid recursive type")
|
||||
return false
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isAnyArithmeticType(t Type) bool { return isArithmeticType(t) || isUntypedArithmeticType(t) }
|
||||
|
||||
func isUntypedArithmeticType(t Type) bool {
|
||||
switch t.Kind() {
|
||||
case UntypedInt, UntypedFloat, UntypedComplex:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isArithmeticType(t Type) bool {
|
||||
return isIntegerType(t) || isFloatType(t) || isComplexType(t)
|
||||
}
|
||||
|
||||
func isComplexType(t Type) bool {
|
||||
switch t.Kind() {
|
||||
case Complex64, Complex128:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isFloatType(t Type) bool {
|
||||
switch t.Kind() {
|
||||
case Float32, Float64:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isIntegerType(t Type) bool {
|
||||
switch t.Kind() {
|
||||
case Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ctx) isIdentical(n Node, t, u Type) bool {
|
||||
tk := t.Kind()
|
||||
uk := u.Kind()
|
||||
if tk != uk {
|
||||
return false
|
||||
}
|
||||
|
||||
if t == u {
|
||||
return true
|
||||
}
|
||||
|
||||
if isAnyUntypedKind(tk) && isAnyUntypedKind(uk) && tk == uk {
|
||||
return true
|
||||
}
|
||||
|
||||
switch x := t.(type) {
|
||||
// case *ArrayTypeNode:
|
||||
// switch y := u.(type) {
|
||||
// case *ArrayTypeNode:
|
||||
// return x.Len == y.Len && c.isIdentical(n, x.Elem, y.Elem)
|
||||
// }
|
||||
// case *StructType:
|
||||
// switch y := u.(type) {
|
||||
// case *StructType:
|
||||
// if len(x.Fields) != len(y.Fields) {
|
||||
// return false
|
||||
// }
|
||||
|
||||
// for i, v := range x.Fields {
|
||||
// w := y.Fields[i]
|
||||
// if v.Name != w.Name || !c.isIdentical(n, v.Type(), w.Type()) {
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
|
||||
// return true
|
||||
// }
|
||||
// case *FunctionType:
|
||||
// switch y := u.(type) {
|
||||
// case *FunctionType:
|
||||
// in, out := x.Parameters.Types, x.Result.Types
|
||||
// in2, out2 := y.Parameters.Types, y.Result.Types
|
||||
// if len(in) != len(in2) || len(out) != len(out2) {
|
||||
// return false
|
||||
// }
|
||||
|
||||
// for i, v := range in {
|
||||
// if !c.isIdentical(n, v, in2[i]) {
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
|
||||
// for i, v := range out {
|
||||
// if !c.isIdentical(n, v, out2[i]) {
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
|
||||
// return true
|
||||
// }
|
||||
// case *PointerType:
|
||||
// switch y := u.(type) {
|
||||
// case *PointerType:
|
||||
// return c.isIdentical(n, x.Elem, y.Elem)
|
||||
// }
|
||||
default:
|
||||
c.err(n, "TODO %v %v", x, u)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *ctx) mustIdentical(n Node, t, u Type) bool {
|
||||
if !c.isIdentical(n, t, u) {
|
||||
c.err(n, "incompatible types: %v and %v", t, u)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *ctx) checkType(n Node) Type {
|
||||
switch x := n.(type) {
|
||||
case *ArrayTypeNode:
|
||||
return x.check(c)
|
||||
default:
|
||||
c.err(n, "TODO %T", x)
|
||||
return Invalid
|
||||
}
|
||||
}
|
716
vendor/modernc.org/gc/v3/value.go
generated
vendored
Normal file
716
vendor/modernc.org/gc/v3/value.go
generated
vendored
Normal file
|
@ -0,0 +1,716 @@
|
|||
// Copyright 2022 The Gc Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package gc // modernc.org/gc/v3
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"math"
|
||||
)
|
||||
|
||||
var (
|
||||
_ Expression = (*BasicLitNode)(nil)
|
||||
_ Expression = (*BinaryExpressionNode)(nil)
|
||||
_ Expression = (*CompositeLitNode)(nil)
|
||||
_ Expression = (*ConversionNode)(nil)
|
||||
_ Expression = (*FunctionLitNode)(nil)
|
||||
_ Expression = (*KeyedElementNode)(nil)
|
||||
_ Expression = (*LiteralValueNode)(nil)
|
||||
_ Expression = (*MethodExprNode)(nil)
|
||||
_ Expression = (*OperandNameNode)(nil)
|
||||
_ Expression = (*OperandNode)(nil)
|
||||
_ Expression = (*OperandQualifiedNameNode)(nil)
|
||||
_ Expression = (*ParenthesizedExpressionNode)(nil)
|
||||
_ Expression = (*PrimaryExprNode)(nil)
|
||||
_ Expression = (*UnaryExprNode)(nil)
|
||||
_ Expression = (*ValueExpression)(nil)
|
||||
|
||||
falseVal = constant.MakeBool(false)
|
||||
trueVal = constant.MakeBool(true)
|
||||
unknown = constant.MakeUnknown()
|
||||
)
|
||||
|
||||
func known(v constant.Value) bool { return v != nil && v.Kind() != constant.Unknown }
|
||||
|
||||
type valueCache struct {
|
||||
v constant.Value
|
||||
}
|
||||
|
||||
func (n *valueCache) Value() constant.Value {
|
||||
if n.v != nil {
|
||||
return n.v
|
||||
}
|
||||
|
||||
return unknown
|
||||
}
|
||||
|
||||
func (n *valueCache) setValue(v constant.Value) constant.Value {
|
||||
n.v = v
|
||||
return v
|
||||
}
|
||||
|
||||
type valuer interface {
|
||||
Value() constant.Value
|
||||
}
|
||||
|
||||
type Expression interface {
|
||||
Node
|
||||
checkExpr(c *ctx) Expression
|
||||
clone() Expression
|
||||
typer
|
||||
valuer
|
||||
}
|
||||
|
||||
type ValueExpression struct {
|
||||
Node
|
||||
typeCache
|
||||
valueCache
|
||||
}
|
||||
|
||||
func (n *ValueExpression) checkExpr(c *ctx) Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ValueExpression) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *BasicLitNode) Type() Type {
|
||||
switch n.Ch() {
|
||||
case CHAR:
|
||||
return n.ctx.int32
|
||||
case INT:
|
||||
return n.ctx.untypedInt
|
||||
case FLOAT:
|
||||
return n.ctx.untypedFloat
|
||||
case STRING:
|
||||
return n.ctx.untypedString
|
||||
default:
|
||||
panic(todo("%v: %T %s %v", n.Position(), n, n.Source(false), n.Ch()))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *BasicLitNode) Value() constant.Value {
|
||||
return constant.MakeFromLiteral(n.Src(), n.Ch(), 0)
|
||||
}
|
||||
|
||||
func (n *BasicLitNode) checkExpr(c *ctx) Expression {
|
||||
n.ctx = c
|
||||
if !known(n.Value()) {
|
||||
c.err(n, "invalid literal: %s", n.Source(false))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *BasicLitNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandNameNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandNameNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandNameNode) checkExpr(c *ctx) Expression {
|
||||
in, named := n.LexicalScope().lookup(n.Name)
|
||||
switch x := named.n.(type) {
|
||||
case *ConstSpecNode:
|
||||
switch in.kind {
|
||||
case UniverseScope:
|
||||
switch n.Name.Src() {
|
||||
case "iota":
|
||||
if c.iota < 0 {
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
|
||||
r := &ValueExpression{Node: x}
|
||||
r.t = c.untypedInt
|
||||
r.v = constant.MakeInt64(c.iota)
|
||||
return r
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
default:
|
||||
return x.Expression
|
||||
}
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *OperandNameNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ParenthesizedExpressionNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ParenthesizedExpressionNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ParenthesizedExpressionNode) checkExpr(c *ctx) Expression {
|
||||
return n.Expression.checkExpr(c)
|
||||
}
|
||||
|
||||
func (n *ParenthesizedExpressionNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *LiteralValueNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *LiteralValueNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *LiteralValueNode) checkExpr(c *ctx) Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *LiteralValueNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *KeyedElementNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *KeyedElementNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *KeyedElementNode) checkExpr(c *ctx) Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *KeyedElementNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *CompositeLitNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *CompositeLitNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *CompositeLitNode) checkExpr(c *ctx) Expression {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !n.enter(c, n) {
|
||||
return n
|
||||
}
|
||||
|
||||
t := n.setType(c.checkType(n.LiteralType))
|
||||
n.LiteralValue.check(c, t)
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *CompositeLitNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *LiteralValueNode) check(c *ctx, t Type) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch t.Kind() {
|
||||
case Array:
|
||||
n.checkArray(c, t.(*ArrayTypeNode))
|
||||
default:
|
||||
panic(todo("%v: %T %s %v", n.Position(), n, n.Source(false), t.Kind()))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *LiteralValueNode) checkArray(c *ctx, t *ArrayTypeNode) {
|
||||
panic(todo("%v: %T %s %s", n.Position(), n, t, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *FunctionLitNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *FunctionLitNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *FunctionLitNode) checkExpr(c *ctx) Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *FunctionLitNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandNode) checkExpr(c *ctx) Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandQualifiedNameNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandQualifiedNameNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandQualifiedNameNode) checkExpr(c *ctx) Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *OperandQualifiedNameNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *ConversionNode) Type() Type {
|
||||
return n.TypeNode
|
||||
}
|
||||
|
||||
func (n *ConversionNode) checkExpr(c *ctx) Expression {
|
||||
t := n.TypeNode.check(c)
|
||||
n.Expression = n.Expression.checkExpr(c)
|
||||
v := n.Expression.Value()
|
||||
n.v = c.convertValue(n.Expression, v, t)
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *ConversionNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *MethodExprNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *MethodExprNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *MethodExprNode) checkExpr(c *ctx) Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *MethodExprNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *PrimaryExprNode) Type() Type {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *PrimaryExprNode) Value() constant.Value {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *PrimaryExprNode) checkExpr(c *ctx) Expression {
|
||||
switch x := n.PrimaryExpr.(type) {
|
||||
case *OperandNameNode:
|
||||
_, named := x.LexicalScope().lookup(x.Name)
|
||||
switch y := named.n.(type) {
|
||||
case *TypeDefNode:
|
||||
switch z := n.Postfix.(type) {
|
||||
case *ArgumentsNode:
|
||||
cnv := &ConversionNode{
|
||||
TypeNode: &TypeNameNode{
|
||||
Name: x.Name,
|
||||
lexicalScoper: x.lexicalScoper,
|
||||
},
|
||||
LPAREN: z.LPAREN,
|
||||
Expression: z.Expression,
|
||||
RPAREN: z.RPAREN,
|
||||
}
|
||||
return cnv.checkExpr(c)
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), z, n.Source(false)))
|
||||
}
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), y, n.Source(false)))
|
||||
}
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
|
||||
n.PrimaryExpr = n.PrimaryExpr.checkExpr(c)
|
||||
switch x := n.Postfix.(type) {
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), x, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *PrimaryExprNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *BinaryExpressionNode) checkExpr(c *ctx) (r Expression) {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n.typeCache.Type() != Invalid {
|
||||
return n
|
||||
}
|
||||
|
||||
n.LHS = n.LHS.checkExpr(c)
|
||||
n.RHS = n.RHS.checkExpr(c)
|
||||
lv := n.LHS.Value()
|
||||
lt := n.LHS.Type()
|
||||
rv := n.RHS.Value()
|
||||
rt := n.RHS.Type()
|
||||
|
||||
defer func() {
|
||||
if known(lv) && known(rv) && r != nil && !known(r.Value()) {
|
||||
c.err(n.Op, "operation value not determined: %v %s %v", lv, n.Op.Src(), rv)
|
||||
}
|
||||
}()
|
||||
|
||||
switch n.Op.Ch() {
|
||||
case SHL, SHR:
|
||||
var u uint64
|
||||
var uOk bool
|
||||
n.t = lt
|
||||
// The right operand in a shift expression must have integer type or be an
|
||||
// untyped constant representable by a value of type uint.
|
||||
switch {
|
||||
case isIntegerType(rt):
|
||||
// ok
|
||||
case known(rv):
|
||||
if isAnyArithmeticType(rt) {
|
||||
rv = c.convertValue(n.RHS, rv, c.cfg.uint)
|
||||
if known(rv) {
|
||||
u, uOk = constant.Uint64Val(rv)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
c.err(n.Op, "TODO %v", n.Op.Src())
|
||||
return n
|
||||
default:
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
return n
|
||||
}
|
||||
|
||||
// If the left operand of a non-constant shift expression is an untyped
|
||||
// constant, it is first implicitly converted to the type it would assume if
|
||||
// the shift expression were replaced by its left operand alone.
|
||||
switch {
|
||||
case known(lv) && !known(rv):
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
// c.err(n.Op, "TODO %v", n.Op.Ch.str())
|
||||
// return n
|
||||
case known(lv) && known(rv):
|
||||
if !uOk {
|
||||
panic(todo(""))
|
||||
}
|
||||
|
||||
n.t = lt
|
||||
n.v = constant.Shift(lv, n.Op.Ch(), uint(u))
|
||||
default:
|
||||
trc("", known(lv), known(rv), u, uOk)
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
// n.t = lt
|
||||
// n.v = constant.BinaryOp(lv, n.Op.Ch(), rv)
|
||||
}
|
||||
case ADD, SUB, MUL, QUO, REM:
|
||||
if !isAnyArithmeticType(lt) || !isAnyArithmeticType(rt) {
|
||||
c.err(n.Op, "TODO %v %v", lt, rt)
|
||||
break
|
||||
}
|
||||
|
||||
// For other binary operators, the operand types must be identical unless the
|
||||
// operation involves shifts or untyped constants.
|
||||
//
|
||||
// Except for shift operations, if one operand is an untyped constant and the
|
||||
// other operand is not, the constant is implicitly converted to the type of
|
||||
// the other operand.
|
||||
switch {
|
||||
case isAnyUntypedType(lt) && isAnyUntypedType(rt):
|
||||
n.v = constant.BinaryOp(lv, n.Op.Ch(), rv)
|
||||
switch n.v.Kind() {
|
||||
case constant.Int:
|
||||
n.t = c.untypedInt
|
||||
case constant.Float:
|
||||
n.t = c.untypedFloat
|
||||
default:
|
||||
c.err(n.Op, "TODO %v %v %q %v %v -> %v %v", lv, lt, n.Op.Src(), rv, rt, n.v, n.v.Kind())
|
||||
}
|
||||
case isAnyUntypedType(lt) && !isAnyUntypedType(rt):
|
||||
c.err(n.Op, "TODO %v %v %q %v %v", lv, lt, n.Op.Src(), rv, rt)
|
||||
case !isAnyUntypedType(lt) && isAnyUntypedType(rt):
|
||||
c.err(n.Op, "TODO %v %v %q %v %v", lv, lt, n.Op.Src(), rv, rt)
|
||||
default: // case !isAnyUntypedType(lt) && !isAnyUntypedType(rt):
|
||||
c.err(n.Op, "TODO %v %v %q %v %v", lv, lt, n.Op.Src(), rv, rt)
|
||||
}
|
||||
default:
|
||||
c.err(n.Op, "TODO %v %v %q %v %v", lv, lt, n.Op.Src(), rv, rt)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *BinaryExpressionNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (n *UnaryExprNode) checkExpr(c *ctx) Expression {
|
||||
if n == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if n.typeCache.Type() != Invalid {
|
||||
return n
|
||||
}
|
||||
|
||||
n.UnaryExpr = n.UnaryExpr.checkExpr(c)
|
||||
v := n.UnaryExpr.Value()
|
||||
t := n.UnaryExpr.Type()
|
||||
switch n.Op.Ch() {
|
||||
default:
|
||||
trc("", v, t)
|
||||
panic(todo("%v: %T %s", n.Op.Position(), n, n.Source(false)))
|
||||
}
|
||||
}
|
||||
|
||||
func (n *UnaryExprNode) clone() Expression {
|
||||
panic(todo("%v: %T %s", n.Position(), n, n.Source(false)))
|
||||
}
|
||||
|
||||
func (c *ctx) convertValue(n Node, v constant.Value, to Type) (r constant.Value) {
|
||||
if !known(v) {
|
||||
return unknown
|
||||
}
|
||||
|
||||
switch to.Kind() {
|
||||
case
|
||||
Complex128,
|
||||
Complex64,
|
||||
Function,
|
||||
Interface,
|
||||
Map,
|
||||
Pointer,
|
||||
Slice,
|
||||
String,
|
||||
Struct,
|
||||
Tuple,
|
||||
UnsafePointer,
|
||||
UntypedBool,
|
||||
UntypedComplex,
|
||||
UntypedFloat,
|
||||
UntypedInt,
|
||||
UntypedNil,
|
||||
UntypedRune,
|
||||
UntypedString:
|
||||
|
||||
c.err(n, "TODO %v -> %v", v, to)
|
||||
case Int:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
i64, ok := constant.Int64Val(w)
|
||||
if !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
switch c.cfg.goarch {
|
||||
case "386", "arm":
|
||||
if i64 < math.MinInt32 || i64 > math.MaxInt32 {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
}
|
||||
return w
|
||||
case Int8:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
i64, ok := constant.Int64Val(w)
|
||||
if !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
if i64 < math.MinInt8 || i64 > math.MaxInt8 {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
return w
|
||||
case Int16:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
i64, ok := constant.Int64Val(w)
|
||||
if !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
if i64 < math.MinInt16 || i64 > math.MaxInt16 {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
return w
|
||||
case Int32:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
i64, ok := constant.Int64Val(w)
|
||||
if !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
if i64 < math.MinInt32 || i64 > math.MaxInt32 {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
return w
|
||||
case Int64:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
if _, ok := constant.Int64Val(w); !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
return w
|
||||
case Uint, Uintptr:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
u64, ok := constant.Uint64Val(w)
|
||||
if !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
switch c.cfg.goarch {
|
||||
case "386", "arm":
|
||||
if u64 > math.MaxUint32 {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
}
|
||||
return w
|
||||
case Uint8:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
u64, ok := constant.Uint64Val(w)
|
||||
if !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
if u64 > math.MaxUint8 {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
return w
|
||||
case Uint16:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
u64, ok := constant.Uint64Val(w)
|
||||
if !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
if u64 > math.MaxUint16 {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
return w
|
||||
case Uint32:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
u64, ok := constant.Uint64Val(w)
|
||||
if !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
if u64 > math.MaxUint32 {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
return w
|
||||
case Uint64:
|
||||
w := constant.ToInt(v)
|
||||
if !known(w) {
|
||||
c.err(n, "cannot convert %s to %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
if _, ok := constant.Uint64Val(w); !ok {
|
||||
c.err(n, "value %s overflows %s", v, to)
|
||||
return unknown
|
||||
}
|
||||
|
||||
return w
|
||||
case Float32, Float64:
|
||||
return constant.ToFloat(v)
|
||||
case Bool:
|
||||
if v.Kind() == constant.Bool {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return unknown
|
||||
}
|
11
vendor/modernc.org/opt/AUTHORS
generated
vendored
11
vendor/modernc.org/opt/AUTHORS
generated
vendored
|
@ -1,11 +0,0 @@
|
|||
# This file lists authors for copyright purposes. This file is distinct from
|
||||
# the CONTRIBUTORS files. See the latter for an explanation.
|
||||
#
|
||||
# Names should be added to this file as:
|
||||
# Name or Organization <email address>
|
||||
#
|
||||
# The email address is not required for organizations.
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Jan Mercl <0xjnml@gmail.com>
|
9
vendor/modernc.org/opt/CONTRIBUTORS
generated
vendored
9
vendor/modernc.org/opt/CONTRIBUTORS
generated
vendored
|
@ -1,9 +0,0 @@
|
|||
# This file lists people who contributed code to this repository. The AUTHORS
|
||||
# file lists the copyright holders; this file lists people.
|
||||
#
|
||||
# Names should be added to this file like so:
|
||||
# Name <email address>
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Jan Mercl <0xjnml@gmail.com>
|
27
vendor/modernc.org/opt/LICENSE
generated
vendored
27
vendor/modernc.org/opt/LICENSE
generated
vendored
|
@ -1,27 +0,0 @@
|
|||
Copyright (c) 2019 The Opt Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the names of the authors nor the names of the
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
18
vendor/modernc.org/opt/Makefile
generated
vendored
18
vendor/modernc.org/opt/Makefile
generated
vendored
|
@ -1,18 +0,0 @@
|
|||
# Copyright 2022 The Opt Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
.PHONY: clean edit editor
|
||||
|
||||
clean:
|
||||
rm -f log-* cpu.test mem.test *.out
|
||||
go clean
|
||||
|
||||
edit:
|
||||
@touch log
|
||||
@if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile *.go & fi
|
||||
|
||||
editor:
|
||||
gofmt -l -s -w *.go
|
||||
go test -o /dev/null -c
|
||||
go install 2>&1 | tee log-editor
|
11
vendor/modernc.org/opt/README.md
generated
vendored
11
vendor/modernc.org/opt/README.md
generated
vendored
|
@ -1,11 +0,0 @@
|
|||
# opt
|
||||
|
||||
Package opt implements command-line flag parsing.
|
||||
|
||||
### Installation
|
||||
|
||||
$ go get [-u] modernc.org/opt
|
||||
|
||||
### Documentation
|
||||
|
||||
[godoc.org/modernc.org/opt](http://godoc.org/modernc.org/opt)
|
155
vendor/modernc.org/opt/opt.go
generated
vendored
155
vendor/modernc.org/opt/opt.go
generated
vendored
|
@ -1,155 +0,0 @@
|
|||
// Package opt implements command-line flag parsing.
|
||||
package opt // import "modernc.org/opt"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type opt struct {
|
||||
handler func(opt, arg string) error
|
||||
name string
|
||||
|
||||
arg bool // Enable argument, e.g. `-I foo` or `-I=foo`
|
||||
}
|
||||
|
||||
// A Set represents a set of defined options.
|
||||
type Set struct {
|
||||
cfg map[string]*opt
|
||||
imm []*opt
|
||||
}
|
||||
|
||||
// NewSet returns a new, empty option set.
|
||||
func NewSet() *Set { return &Set{cfg: map[string]*opt{}} }
|
||||
|
||||
// Opt defines a simple option, e.g. `-f`. When the option is found during
|
||||
// Parse, the handler is called with the value of the option, e.g. "-f".
|
||||
func (p *Set) Opt(name string, handler func(opt string) error) {
|
||||
p.cfg[name] = &opt{
|
||||
handler: func(opt, arg string) error { return handler(opt) },
|
||||
}
|
||||
}
|
||||
|
||||
// Arg defines a simple option with an argument, e.g. `-I foo` or `-I=foo`.
|
||||
// Setting imm argument enables additionally `-Ifoo`. When the option is found
|
||||
// during Parse, the handler is called with the values of the option and the
|
||||
// argument, e.g. "-I" and "foo" for all of the variants.
|
||||
func (p *Set) Arg(name string, imm bool, handler func(opt, arg string) error) {
|
||||
switch {
|
||||
case imm:
|
||||
p.imm = append(p.imm, &opt{
|
||||
handler: handler,
|
||||
name: name,
|
||||
})
|
||||
default:
|
||||
p.cfg[name] = &opt{
|
||||
arg: true,
|
||||
handler: handler,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse parses opts. Must be called after all options are defined. The handler
|
||||
// is called for all items in opts that were not defined before using Opt or
|
||||
// Arg.
|
||||
//
|
||||
// If any handler returns a non-nil error, Parse will stop. If the error is of
|
||||
// type Skip, the error returned by Parse will contain all the unprocessed
|
||||
// items of opts.
|
||||
//
|
||||
// The opts slice must not be modified by any handler while Parser is
|
||||
// executing.
|
||||
func (p *Set) Parse(opts []string, handler func(string) error) (err error) {
|
||||
defer func() {
|
||||
switch err.(type) {
|
||||
case Skip:
|
||||
err = Skip(opts)
|
||||
}
|
||||
}()
|
||||
|
||||
for len(opts) != 0 {
|
||||
opt := opts[0]
|
||||
opt0 := opt
|
||||
opts = opts[1:]
|
||||
var arg string
|
||||
out:
|
||||
switch {
|
||||
case strings.HasPrefix(opt, "-"):
|
||||
name := opt[1:]
|
||||
for _, cfg := range p.imm {
|
||||
if strings.HasPrefix(name, cfg.name) {
|
||||
switch {
|
||||
case name == cfg.name:
|
||||
if len(opts) == 0 {
|
||||
return fmt.Errorf("missing argument of %s", opt)
|
||||
}
|
||||
|
||||
if err = cfg.handler(opt, opts[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts = opts[1:]
|
||||
default:
|
||||
opt = opt[:len(cfg.name)+1]
|
||||
val := strings.TrimPrefix(name[len(cfg.name):], "=")
|
||||
if err = cfg.handler(opt, val); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
break out
|
||||
}
|
||||
}
|
||||
|
||||
if n := strings.IndexByte(opt, '='); n > 0 {
|
||||
arg = opt[n+1:]
|
||||
name = opt[1:n]
|
||||
opt = opt[:n]
|
||||
}
|
||||
switch cfg := p.cfg[name]; {
|
||||
case cfg == nil:
|
||||
if err = handler(opt0); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
switch {
|
||||
case cfg.arg:
|
||||
switch {
|
||||
case arg != "":
|
||||
if err = cfg.handler(opt, arg); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
if len(opts) == 0 {
|
||||
return fmt.Errorf("missing argument of %s", opt)
|
||||
}
|
||||
|
||||
if err = cfg.handler(opt, opts[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts = opts[1:]
|
||||
}
|
||||
default:
|
||||
if err = cfg.handler(opt, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
if opt == "" {
|
||||
break
|
||||
}
|
||||
|
||||
if err = handler(opt); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Skip is an error that contains all unprocessed items passed to Parse.
|
||||
type Skip []string
|
||||
|
||||
func (s Skip) Error() string { return fmt.Sprint([]string(s)) }
|
4
vendor/modernc.org/opt/unconvert.sh
generated
vendored
4
vendor/modernc.org/opt/unconvert.sh
generated
vendored
|
@ -1,4 +0,0 @@
|
|||
until unconvert -fastmath . &> /dev/null
|
||||
do
|
||||
unconvert -fastmath -apply . &> /dev/null
|
||||
done
|
1
vendor/modernc.org/sqlite/CONTRIBUTORS
generated
vendored
1
vendor/modernc.org/sqlite/CONTRIBUTORS
generated
vendored
|
@ -21,6 +21,7 @@ Jaap Aarts <jaap.aarts1@gmail.com>
|
|||
Jan Mercl <0xjnml@gmail.com>
|
||||
Josh Bleecher Snyder <josharian@gmail.com>
|
||||
Josh Klein <josh.klein@outlook.com>
|
||||
Kim <grufwub@gmail.com>
|
||||
Logan Snow <logansnow@protonmail.com>
|
||||
Mark Summerfield <mark@qtrac.eu>
|
||||
Matthew Gabeler-Lee <fastcat@gmail.com>
|
||||
|
|
251
vendor/modernc.org/sqlite/Makefile
generated
vendored
251
vendor/modernc.org/sqlite/Makefile
generated
vendored
|
@ -1,242 +1,83 @@
|
|||
# Copyright 2017 The Sqlite Authors. All rights reserved.
|
||||
# Copyright 2024 The Sqlite Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
.PHONY: all clean cover cpu editor internalError later mem nuke todo edit tcl extraquick full tidy uncomment unconvert
|
||||
|
||||
grep=--include=*.go --include=*.l --include=*.y --include=*.yy
|
||||
ngrep='TODOOK\|internal\/vfs\|internal\/bin\|internal\/mptest\|.*stringer.*\.go'
|
||||
host=$(shell go env GOOS)-$(shell go env GOARCH)
|
||||
testlog=testdata/testlog-$(shell echo $$GOOS)-$(shell echo $$GOARCH)$(shell echo $$SQLITE_TEST_SUFFIX)
|
||||
.PHONY: all build_all_targets clean edit editor test vendor work
|
||||
|
||||
all: editor
|
||||
date
|
||||
go version 2>&1 | tee log
|
||||
./unconvert.sh
|
||||
gofmt -l -s -w *.go
|
||||
go test -i
|
||||
go test -v 2>&1 -timeout 24h | tee -a log
|
||||
go run speedtest1/main_$(shell go env GOOS)_$(shell go env GOARCH).go
|
||||
golint 2>&1 | grep -v $(ngrep) || true
|
||||
misspell *.go
|
||||
staticcheck || true
|
||||
maligned || true
|
||||
git diff --unified=0 testdata *.golden
|
||||
grep -n --color=always 'FAIL\|PASS' log
|
||||
go version
|
||||
date 2>&1 | tee -a log
|
||||
|
||||
# $ go install modernc.org/uncomment@latest
|
||||
uncomment:
|
||||
uncomment -v -gofmt libtest/sqlite*.go internal/mptest/main*.go internal/testfixture/testfixture*.go speedtest1/main*.go vfs/vfs*.go
|
||||
uncomment -v -gofmt -keep-godoc lib/sqlite*.go
|
||||
|
||||
# $ go install github.com/mdempsky/unconvert@latest
|
||||
unconvert:
|
||||
./unconvert.sh && echo ok || echo fail
|
||||
|
||||
tidy: uncomment unconvert
|
||||
gofmt -l -s -w .
|
||||
golint 2>&1
|
||||
staticcheck 2>&1
|
||||
|
||||
build_all_targets:
|
||||
GOOS=darwin GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=darwin GOARCH=amd64 go build -v ./...
|
||||
GOOS=darwin GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=darwin GOARCH=arm64 go build -v ./...
|
||||
GOOS=freebsd GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=amd64 go build -v ./...
|
||||
GOOS=freebsd GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=386 go build -v ./...
|
||||
GOOS=freebsd GOARCH=arm go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=arm go build -v ./...
|
||||
GOOS=freebsd GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=freebsd GOARCH=arm64 go build -v ./...
|
||||
GOOS=linux GOARCH=386 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=386 go build -v ./...
|
||||
GOOS=linux GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=amd64 go build -v ./...
|
||||
GOOS=linux GOARCH=arm go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=arm go build -v ./...
|
||||
GOOS=linux GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=arm64 go build -v ./...
|
||||
GOOS=linux GOARCH=ppc64le go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=ppc64le go build -v ./...
|
||||
GOOS=linux GOARCH=riscv64 go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=riscv64 go build -v ./...
|
||||
GOOS=linux GOARCH=s390x go test -c -o /dev/null
|
||||
GOOS=linux GOARCH=s390x go build -v ./...
|
||||
GOOS=netbsd GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=netbsd GOARCH=amd64 go build -v ./...
|
||||
GOOS=openbsd GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=openbsd GOARCH=amd64 go build -v ./...
|
||||
GOOS=openbsd GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=openbsd GOARCH=arm64 go build -v ./...
|
||||
# GOOS=windows GOARCH=386 go test -c -o /dev/null
|
||||
# GOOS=windows GOARCH=386 go build -v ./...
|
||||
GOOS=windows GOARCH=amd64 go test -c -o /dev/null
|
||||
GOOS=windows GOARCH=amd64 go build -v ./...
|
||||
GOOS=windows GOARCH=arm64 go test -c -o /dev/null
|
||||
GOOS=windows GOARCH=arm64 go build -v ./...
|
||||
echo done
|
||||
|
||||
# 3900x
|
||||
windows_amd64:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
CCGO_CPP=x86_64-w64-mingw32-cpp TARGET_GOOS=windows TARGET_GOARCH=amd64 go generate 2>&1 | tee log-generate
|
||||
GOOS=windows GOARCH=amd64 go test -c -o /dev/null
|
||||
|
||||
windows_arm64:
|
||||
go run addport.go windows_amd64 windows_arm64
|
||||
GOOS=windows GOARCH=arm64 go test -c -o /dev/null
|
||||
|
||||
# 3900x
|
||||
windows_386:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
CCGO_CPP=i686-w64-mingw32-cpp TARGET_GOOS=windows TARGET_GOARCH=386 go generate 2>&1 | tee log-generate
|
||||
GOOS=windows GOARCH=386 go test -c -o /dev/null
|
||||
|
||||
# 3900x/qemu
|
||||
darwin_amd64:
|
||||
@echo "Should be executed only on darwin/amd64."
|
||||
go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
# 3900x/qemu
|
||||
netbsd_amd64:
|
||||
@echo "Should be executed only on netbsd/amd64."
|
||||
go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
# darwin-m1
|
||||
darwin_arm64:
|
||||
@echo "Should be executed only on darwin/arm64."
|
||||
go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
# 3900x/qemu
|
||||
freebsd_amd64:
|
||||
@echo "Should be executed only on freebsd/amd64."
|
||||
go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
freebsd_arm64:
|
||||
go run addport.go freebsd_amd64 freebsd_arm64
|
||||
GOOS=freebsd GOARCH=arm64 go test -c -o /dev/null
|
||||
|
||||
# 3900x/qemu
|
||||
freebsd_386:
|
||||
@echo "Should be executed only on freebsd/386."
|
||||
go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
# 3900x/qemu
|
||||
freebsd_arm:
|
||||
@echo "Should be executed only on freebsd/arm."
|
||||
go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
# 3900x
|
||||
linux_amd64:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
# 3900x
|
||||
linux_386:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
CCGO_CPP=i686-linux-gnu-cpp TARGET_GOARCH=386 TARGET_GOOS=linux go generate 2>&1 | tee log-generate
|
||||
GOOS=linux GOARCH=386 go test -c -o /dev/null
|
||||
|
||||
# 3900x
|
||||
linux_arm:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
CCGO_CPP=arm-linux-gnueabi-cpp TARGET_GOARCH=arm TARGET_GOOS=linux go generate 2>&1 | tee log-generate
|
||||
GOOS=linux GOARCH=arm go test -c -o /dev/null
|
||||
|
||||
# 3900x
|
||||
linux_arm64:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
CCGO_CPP=aarch64-linux-gnu-cpp TARGET_GOARCH=arm64 TARGET_GOOS=linux go generate 2>&1 | tee log-generate
|
||||
GOOS=linux GOARCH=arm64 go test -c -o /dev/null
|
||||
|
||||
# 3900x
|
||||
linux_ppc64le:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
CCGO_CPP=powerpc64le-linux-gnu-cpp TARGET_GOARCH=ppc64le TARGET_GOOS=linux go generate 2>&1 | tee log-generate
|
||||
GOOS=linux GOARCH=ppc64le go test -c -o /dev/null
|
||||
|
||||
# linux/riscv64
|
||||
linux_riscv64:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
CCGO_CPP=riscv64-linux-gnu-cpp TARGET_GOARCH=riscv64 TARGET_GOOS=linux go generate 2>&1 | tee log-generate
|
||||
GOOS=linux GOARCH=riscv64 go test -c -o /dev/null
|
||||
|
||||
# 3900x
|
||||
linux_s390x:
|
||||
@echo "Should be executed only on linux/amd64."
|
||||
CCGO_CPP=s390x-linux-gnu-cpp TARGET_GOARCH=s390x TARGET_GOOS=linux go generate 2>&1 | tee log-generate
|
||||
GOOS=linux GOARCH=s390x go test -c -o /dev/null
|
||||
|
||||
# 3900x/qemu
|
||||
openbsd_amd64:
|
||||
@echo "Should be executed only on openbsd/amd64."
|
||||
go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
# 3900x/qemu
|
||||
openbsd_arm64:
|
||||
@echo "Should be executed only on openbsd/arm64."
|
||||
GOGC=10 GOMEMLIMIT=6GiB go generate 2>&1 | tee log-generate
|
||||
go test -c -o /dev/null
|
||||
|
||||
generate_all_targets_on_linux_amd64: linux_amd64 linux_386 linux_arm linux_arm64 linux_s390x linux_ppc64le linux_riscv64 windows_amd64 windows_arm64 #TODO windows_386
|
||||
gofmt -l -s -w .
|
||||
echo done
|
||||
|
||||
tcl_test_wine:
|
||||
GOOS=windows GOARCH=amd64 go build -o testfixture.exe modernc.org/sqlite/internal/testfixture
|
||||
|
||||
run_tcl_test_wine:
|
||||
TCL_LIBRARY=Z:/home/jnml/src/modernc.org/tcl/assets wine testfixture.exe ./testdata/tcl/zipfile.test
|
||||
|
||||
extraquick:
|
||||
go test -timeout 24h -v -failfast -suite extraquick -maxerror 1 2>&1 | tee log-extraquick
|
||||
date
|
||||
|
||||
full:
|
||||
go test -timeout 24h -v -run Tcl -suite full 2>&1 | tee log-full
|
||||
date
|
||||
|
||||
clean:
|
||||
rm -f log-* cpu.test mem.test *.out go.work*
|
||||
go clean
|
||||
rm -f *~ *.test *.out test.db* tt4-test*.db* test_sv.* testdb-*
|
||||
|
||||
cover:
|
||||
t=$(shell tempfile) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t
|
||||
|
||||
cpu: clean
|
||||
go test -run @ -bench . -cpuprofile cpu.out
|
||||
go tool pprof -lines *.test cpu.out
|
||||
|
||||
edit:
|
||||
@touch log
|
||||
@if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile all_test.go sqlite.go & fi
|
||||
@if [ -f "Session.vim" ]; then novim -S & else novim -p Makefile all_test.go generator.go & fi
|
||||
|
||||
editor:
|
||||
gofmt -l -s -w *.go
|
||||
go install -v ./...
|
||||
go test -c -o /dev/null -tags=cgo,cgotest
|
||||
gofmt -l -s -w . 2>&1 | tee log-editor
|
||||
go test -c -o /dev/null 2>&1 | tee -a log-editor
|
||||
go build -v -o /dev/null ./... 2>&1 | tee -a log-editor
|
||||
go build -o /dev/null vendor_libsqlite3.go
|
||||
|
||||
internalError:
|
||||
egrep -ho '"internal error.*"' *.go | sort | cat -n
|
||||
test:
|
||||
go test -v -timeout 24h 2>&1 | tee log-test
|
||||
|
||||
vendor:
|
||||
go run vendor_libsqlite3.go && make build_all_targets
|
||||
make build_all_targets
|
||||
|
||||
later:
|
||||
@grep -n $(grep) LATER * || true
|
||||
@grep -n $(grep) MAYBE * || true
|
||||
|
||||
mem: clean
|
||||
go test -run @ -bench . -memprofile mem.out -memprofilerate 1 -timeout 24h
|
||||
go tool pprof -lines -web -alloc_space *.test mem.out
|
||||
|
||||
memgrind:
|
||||
go test -v -timeout 24h -tags libc.memgrind,cgobench -bench . -suite extraquick -xtags=libc.memgrind
|
||||
|
||||
regression_base_release:
|
||||
GO111MODULE=on go test -v -timeout 24h -tags=cgobench -run @ -bench '(Reading1|InsertComparative)/sqlite[^3]' -recs_per_sec_as_mbps 2>&1 | tee log-regression-base
|
||||
|
||||
regression_base_master:
|
||||
GO111MODULE=off go test -v -timeout 24h -tags=cgobench -run @ -bench '(Reading1|InsertComparative)/sqlite[^3]' -recs_per_sec_as_mbps 2>&1 | tee log-regression-base
|
||||
|
||||
regression_check:
|
||||
GO111MODULE=off go test -v -timeout 24h -tags=cgobench -run @ -bench '(Reading1|InsertComparative)/sqlite[^3]' -recs_per_sec_as_mbps 2>&1 | tee log-regression
|
||||
benchcmp -changed -mag log-regression-base log-regression
|
||||
|
||||
nuke: clean
|
||||
go clean -i
|
||||
|
||||
todo:
|
||||
@grep -nr $(grep) ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) TODO * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) BUG * | grep -v $(ngrep) || true
|
||||
@grep -nr $(grep) [^[:alpha:]]println * | grep -v $(ngrep) || true
|
||||
work:
|
||||
rm -f go.work*
|
||||
go work init
|
||||
go work use .
|
||||
go work use ../cc/v4
|
||||
go work use ../ccgo/v3
|
||||
go work use ../ccgo/v4
|
||||
go work use ../libc
|
||||
go work use ../libtcl8.6
|
||||
go work use ../libsqlite3
|
||||
go work use ../libz
|
||||
|
|
87
vendor/modernc.org/sqlite/doc.go
generated
vendored
87
vendor/modernc.org/sqlite/doc.go
generated
vendored
|
@ -19,19 +19,19 @@
|
|||
//
|
||||
// OS Arch SQLite version
|
||||
// ------------------------------
|
||||
// darwin amd64 3.41.2
|
||||
// darwin arm64 3.41.2
|
||||
// freebsd amd64 3.41.2
|
||||
// freebsd arm64 3.41.2
|
||||
// linux 386 3.41.2
|
||||
// linux amd64 3.41.2
|
||||
// linux arm 3.41.2
|
||||
// linux arm64 3.41.2
|
||||
// linux ppc64le 3.41.2
|
||||
// linux riscv64 3.41.2
|
||||
// linux s390x 3.41.2
|
||||
// windows amd64 3.41.2
|
||||
// windows arm64 3.41.2
|
||||
// darwin amd64 3.45.1
|
||||
// darwin arm64 3.45.1
|
||||
// freebsd amd64 3.45.1
|
||||
// freebsd arm64 3.45.1
|
||||
// linux 386 3.45.1
|
||||
// linux amd64 3.45.1
|
||||
// linux arm 3.45.1
|
||||
// linux arm64 3.45.1
|
||||
// linux ppc64le 3.45.1
|
||||
// linux riscv64 3.45.1
|
||||
// linux s390x 3.45.1
|
||||
// windows amd64 3.45.1
|
||||
// windows arm64 3.45.1
|
||||
//
|
||||
// # Builders
|
||||
//
|
||||
|
@ -39,62 +39,21 @@
|
|||
//
|
||||
// https://modern-c.appspot.com/-/builder/?importpath=modernc.org%2fsqlite
|
||||
//
|
||||
// # Speedtest1
|
||||
// # Fragile modernc.org/libc dependency
|
||||
//
|
||||
// Numbers for the pure Go version were produced by
|
||||
// When you import this package you should use in your go.mod file the exact
|
||||
// same version of modernc.org/libc as seen in the go.mod file of this
|
||||
// repository.
|
||||
//
|
||||
// ~/src/modernc.org/sqlite/speedtest1$ go build && ./speedtest1
|
||||
//
|
||||
// Numbers for the pure C version were produced by
|
||||
//
|
||||
// ~/src/modernc.org/sqlite/testdata/sqlite-src-3410200/test$ gcc speedtest1.c ../../sqlite-amalgamation-3410200/sqlite3.c -lpthread -ldl && ./a.out
|
||||
//
|
||||
// The results are from Go version 1.20.4 and GCC version 10.2.1 on a
|
||||
// Linux/amd64 machine, CPU: AMD Ryzen 9 3900X 12-Core Processor × 24, 128GB
|
||||
// RAM. Shown are the best of 3 runs.
|
||||
//
|
||||
// Go C
|
||||
//
|
||||
// -- Speedtest1 for SQLite 3.41.2 2023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69 -- Speedtest1 for SQLite 3.41.2 2023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69
|
||||
// 100 - 50000 INSERTs into table with no index...................... 0.071s 100 - 50000 INSERTs into table with no index...................... 0.077s
|
||||
// 110 - 50000 ordered INSERTS with one index/PK..................... 0.114s 110 - 50000 ordered INSERTS with one index/PK..................... 0.082s
|
||||
// 120 - 50000 unordered INSERTS with one index/PK................... 0.137s 120 - 50000 unordered INSERTS with one index/PK................... 0.099s
|
||||
// 130 - 25 SELECTS, numeric BETWEEN, unindexed...................... 0.083s 130 - 25 SELECTS, numeric BETWEEN, unindexed...................... 0.091s
|
||||
// 140 - 10 SELECTS, LIKE, unindexed................................. 0.210s 140 - 10 SELECTS, LIKE, unindexed................................. 0.120s
|
||||
// 142 - 10 SELECTS w/ORDER BY, unindexed............................ 0.276s 142 - 10 SELECTS w/ORDER BY, unindexed............................ 0.182s
|
||||
// 145 - 10 SELECTS w/ORDER BY and LIMIT, unindexed.................. 0.183s 145 - 10 SELECTS w/ORDER BY and LIMIT, unindexed.................. 0.099s
|
||||
// 150 - CREATE INDEX five times..................................... 0.172s 150 - CREATE INDEX five times..................................... 0.127s
|
||||
// 160 - 10000 SELECTS, numeric BETWEEN, indexed..................... 0.080s 160 - 10000 SELECTS, numeric BETWEEN, indexed..................... 0.078s
|
||||
// 161 - 10000 SELECTS, numeric BETWEEN, PK.......................... 0.080s 161 - 10000 SELECTS, numeric BETWEEN, PK.......................... 0.078s
|
||||
// 170 - 10000 SELECTS, text BETWEEN, indexed........................ 0.187s 170 - 10000 SELECTS, text BETWEEN, indexed........................ 0.169s
|
||||
// 180 - 50000 INSERTS with three indexes............................ 0.196s 180 - 50000 INSERTS with three indexes............................ 0.154s
|
||||
// 190 - DELETE and REFILL one table................................. 0.200s 190 - DELETE and REFILL one table................................. 0.155s
|
||||
// 200 - VACUUM...................................................... 0.180s 200 - VACUUM...................................................... 0.142s
|
||||
// 210 - ALTER TABLE ADD COLUMN, and query........................... 0.004s 210 - ALTER TABLE ADD COLUMN, and query........................... 0.005s
|
||||
// 230 - 10000 UPDATES, numeric BETWEEN, indexed..................... 0.093s 230 - 10000 UPDATES, numeric BETWEEN, indexed..................... 0.080s
|
||||
// 240 - 50000 UPDATES of individual rows............................ 0.153s 240 - 50000 UPDATES of individual rows............................ 0.137s
|
||||
// 250 - One big UPDATE of the whole 50000-row table................. 0.024s 250 - One big UPDATE of the whole 50000-row table................. 0.019s
|
||||
// 260 - Query added column after filling............................ 0.004s 260 - Query added column after filling............................ 0.005s
|
||||
// 270 - 10000 DELETEs, numeric BETWEEN, indexed..................... 0.278s 270 - 10000 DELETEs, numeric BETWEEN, indexed..................... 0.263s
|
||||
// 280 - 50000 DELETEs of individual rows............................ 0.188s 280 - 50000 DELETEs of individual rows............................ 0.180s
|
||||
// 290 - Refill two 50000-row tables using REPLACE................... 0.411s 290 - Refill two 50000-row tables using REPLACE................... 0.359s
|
||||
// 300 - Refill a 50000-row table using (b&1)==(a&1)................. 0.175s 300 - Refill a 50000-row table using (b&1)==(a&1)................. 0.151s
|
||||
// 310 - 10000 four-ways joins....................................... 0.427s 310 - 10000 four-ways joins....................................... 0.365s
|
||||
// 320 - subquery in result set...................................... 0.440s 320 - subquery in result set...................................... 0.521s
|
||||
// 400 - 70000 REPLACE ops on an IPK................................. 0.125s 400 - 70000 REPLACE ops on an IPK................................. 0.106s
|
||||
// 410 - 70000 SELECTS on an IPK..................................... 0.081s 410 - 70000 SELECTS on an IPK..................................... 0.078s
|
||||
// 500 - 70000 REPLACE on TEXT PK.................................... 0.174s 500 - 70000 REPLACE on TEXT PK.................................... 0.116s
|
||||
// 510 - 70000 SELECTS on a TEXT PK.................................. 0.153s 510 - 70000 SELECTS on a TEXT PK.................................. 0.117s
|
||||
// 520 - 70000 SELECT DISTINCT....................................... 0.083s 520 - 70000 SELECT DISTINCT....................................... 0.067s
|
||||
// 980 - PRAGMA integrity_check...................................... 0.436s 980 - PRAGMA integrity_check...................................... 0.377s
|
||||
// 990 - ANALYZE..................................................... 0.107s 990 - ANALYZE..................................................... 0.038s
|
||||
// TOTAL....................................................... 5.525s TOTAL....................................................... 4.637s
|
||||
//
|
||||
// This particular test executes 16.1% faster in the C version.
|
||||
// See the discussion at https://gitlab.com/cznic/sqlite/-/issues/177 for more details.
|
||||
//
|
||||
// # Changelog
|
||||
//
|
||||
// 2023-12-14 v1.28.0:
|
||||
// 2024-02-13: v1.29.0
|
||||
//
|
||||
// Upgrade to SQLite 3.45.1, release notes at https://sqlite.org/releaselog/3_45_1.html.
|
||||
//
|
||||
// 2023-12-14 v1.28.0:
|
||||
//
|
||||
// (*Driver).RegisterConnectionHook: added
|
||||
// ConnectionHookFn: added
|
||||
|
|
887
vendor/modernc.org/sqlite/generator.go
generated
vendored
887
vendor/modernc.org/sqlite/generator.go
generated
vendored
|
@ -1,887 +0,0 @@
|
|||
// Copyright 2017 The Sqlite Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build generator
|
||||
// +build generator
|
||||
|
||||
//TODO 2023-02-23, netbsd/amd64 fails generating SQLite 3.41:
|
||||
//
|
||||
// C front end 36/85: testdata/sqlite-src-3410000/ext/recover/sqlite3recover.c ... testdata/sqlite-src-3410000/ext/recover/sqlite3recover.c:2023:41: front-end: undefined: SQLITE_FCNTL_RESET_CACHE
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"modernc.org/ccgo/v3/lib"
|
||||
)
|
||||
|
||||
// gcc
|
||||
// -g
|
||||
// -O2
|
||||
// -DSQLITE_OS_UNIX=1
|
||||
// -I.
|
||||
// -I/home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src
|
||||
// -I/home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/rtree
|
||||
// -I/home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/icu
|
||||
// -I/home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/fts3
|
||||
// -I/home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/async
|
||||
// -I/home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/session
|
||||
// -I/home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/userauth
|
||||
// -D_HAVE_SQLITE_CONFIG_H
|
||||
// -DBUILD_sqlite
|
||||
// -DNDEBUG
|
||||
// -I/usr/include/tcl8.6
|
||||
// -DSQLITE_THREADSAFE=1
|
||||
// -DSQLITE_HAVE_ZLIB=1
|
||||
// -DSQLITE_NO_SYNC=1
|
||||
// -DSQLITE_TEMP_STORE=1
|
||||
// -DSQLITE_TEST=1
|
||||
// -DSQLITE_CRASH_TEST=1
|
||||
// -DTCLSH_INIT_PROC=sqlite3TestInit
|
||||
// -DSQLITE_SERVER=1
|
||||
// -DSQLITE_PRIVATE=
|
||||
// -DSQLITE_CORE
|
||||
// -DBUILD_sqlite
|
||||
// -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
|
||||
// -DSQLITE_DEFAULT_PAGE_SIZE=1024
|
||||
// -DSQLITE_ENABLE_STMTVTAB
|
||||
// -DSQLITE_ENABLE_DBPAGE_VTAB
|
||||
// -DSQLITE_ENABLE_BYTECODE_VTAB
|
||||
// -DSQLITE_ENABLE_DESERIALIZE
|
||||
// -o testfixture
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test1.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test2.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test3.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test4.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test5.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test6.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test7.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test8.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test9.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_autoext.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_async.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_backup.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_bestindex.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_blob.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_btree.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_config.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_delete.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_demovfs.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_devsym.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_fs.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_func.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_hexio.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_init.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_intarray.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_journal.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_malloc.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_md5.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_multiplex.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_mutex.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_onefile.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_osinst.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_pcache.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_quota.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_rtree.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_schema.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_server.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_superlock.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_syscall.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_tclsh.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_tclvar.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_thread.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_vdbecov.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_vfs.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_windirent.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_window.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/test_wsd.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/fts3/fts3_term.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/fts3/fts3_test.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/session/test_session.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/rbu/test_rbu.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/expert/sqlite3expert.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/expert/test_expert.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/amatch.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/carray.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/closure.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/csv.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/decimal.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/eval.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/explain.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/fileio.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/fuzzer.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/fts5/fts5_tcl.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/fts5/fts5_test_mi.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/fts5/fts5_test_tok.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/ieee754.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/mmapwarm.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/nextchar.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/normalize.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/percentile.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/prefixes.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/regexp.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/remember.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/series.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/spellfix.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/totype.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/unionvtab.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/wholenumber.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/misc/zipfile.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/ext/userauth/userauth.c
|
||||
// /home/jnml/src/modernc.org/sqlite/testdata/SQLite-3c5e63c2/src/tclsqlite.c
|
||||
// sqlite3.c
|
||||
// -L/usr/lib/x86_64-linux-gnu
|
||||
// -ltcl8.6
|
||||
// -ldl
|
||||
// -lz
|
||||
// -lpthread
|
||||
|
||||
const (
|
||||
volatiles = "-volatile=sqlite3_io_error_pending,sqlite3_open_file_count,sqlite3_pager_readdb_count,sqlite3_pager_writedb_count,sqlite3_pager_writej_count,sqlite3_search_count,sqlite3_sort_count,saved_cnt,randomnessPid"
|
||||
)
|
||||
|
||||
// 2022-11-27 Removing -DSQLITE_ENABLE_SNAPSHOT from configTest. This #define
|
||||
// makes a single test fail on linux/ppc64le. That test is run only when the
|
||||
// -DSQLITE_ENABLE_SNAPSHOT is present when compiling the testfixture. When
|
||||
// investigating the failure it turns out this #define is actually NOT present
|
||||
// when doing '$ ./configure && make tcltest' in sqlite-src-3400000, ie. in the
|
||||
// original C code.
|
||||
//
|
||||
// libtool: link: gcc -g -O2 -DSQLITE_OS_UNIX=1 -I. -I/home/jnml/sqlite-src-3400000/src -I/home/jnml/sqlite-src-3400000/ext/rtree -I/home/jnml/sqlite-src-3400000/ext/icu -I/home/jnml/sqlite-src-3400000/ext/fts3 -I/home/jnml/sqlite-src-3400000/ext/async -I/home/jnml/sqlite-src-3400000/ext/session -I/home/jnml/sqlite-src-3400000/ext/userauth -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite -DNDEBUG -I/usr/include/tcl8.6 -DSQLITE_THREADSAFE=1 -DSQLITE_ENABLE_MATH_FUNCTIONS -DSQLITE_HAVE_ZLIB=1 -DSQLITE_NO_SYNC=1 -DSQLITE_TEMP_STORE=1 -DSQLITE_TEST=1 -DSQLITE_CRASH_TEST=1 -DTCLSH_INIT_PROC=sqlite3TestInit -DSQLITE_SERVER=1 -DSQLITE_PRIVATE= -DSQLITE_CORE -DBUILD_sqlite -DSQLITE_SERIES_CONSTRAINT_VERIFY=1 -DSQLITE_DEFAULT_PAGE_SIZE=1024 -DSQLITE_ENABLE_STMTVTAB -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_ENABLE_BYTECODE_VTAB -DSQLITE_CKSUMVFS_STATIC -o testfixture ...
|
||||
|
||||
var (
|
||||
configProduction = []string{
|
||||
"-DHAVE_USLEEP",
|
||||
"-DLONGDOUBLE_TYPE=double",
|
||||
"-DSQLITE_CORE",
|
||||
"-DSQLITE_DEFAULT_MEMSTATUS=0",
|
||||
"-DSQLITE_ENABLE_COLUMN_METADATA",
|
||||
"-DSQLITE_ENABLE_DBSTAT_VTAB",
|
||||
"-DSQLITE_ENABLE_FTS5",
|
||||
"-DSQLITE_ENABLE_GEOPOLY",
|
||||
"-DSQLITE_ENABLE_MATH_FUNCTIONS",
|
||||
"-DSQLITE_ENABLE_MEMORY_MANAGEMENT",
|
||||
"-DSQLITE_ENABLE_OFFSET_SQL_FUNC",
|
||||
"-DSQLITE_ENABLE_PREUPDATE_HOOK",
|
||||
"-DSQLITE_ENABLE_RBU",
|
||||
"-DSQLITE_ENABLE_RTREE",
|
||||
"-DSQLITE_ENABLE_SESSION",
|
||||
"-DSQLITE_ENABLE_SNAPSHOT",
|
||||
"-DSQLITE_ENABLE_STAT4",
|
||||
"-DSQLITE_ENABLE_UNLOCK_NOTIFY", // Adds sqlite3_unlock_notify().
|
||||
"-DSQLITE_LIKE_DOESNT_MATCH_BLOBS",
|
||||
"-DSQLITE_MUTEX_APPDEF=1",
|
||||
"-DSQLITE_MUTEX_NOOP",
|
||||
"-DSQLITE_SOUNDEX",
|
||||
"-DSQLITE_THREADSAFE=1",
|
||||
//DONT "-DNDEBUG", // To enable GO_GENERATE=-DSQLITE_DEBUG
|
||||
//DONT "-DSQLITE_DQS=0", // testfixture
|
||||
//DONT "-DSQLITE_NO_SYNC=1",
|
||||
//DONT "-DSQLITE_OMIT_DECLTYPE", // testfixture
|
||||
//DONT "-DSQLITE_OMIT_DEPRECATED", // mptest
|
||||
//DONT "-DSQLITE_OMIT_LOAD_EXTENSION", // mptest
|
||||
//DONT "-DSQLITE_OMIT_SHARED_CACHE",
|
||||
//DONT "-DSQLITE_USE_ALLOCA",
|
||||
//TODO "-DHAVE_MALLOC_USABLE_SIZE"
|
||||
//TODO "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", //TODO report bug
|
||||
//TODO "-DSQLITE_ENABLE_FTS3",
|
||||
//TODO "-DSQLITE_ENABLE_FTS3_PARENTHESIS",
|
||||
//TODO "-DSQLITE_ENABLE_FTS3_TOKENIZER",
|
||||
//TODO "-DSQLITE_ENABLE_FTS4",
|
||||
//TODO "-DSQLITE_ENABLE_ICU",
|
||||
//TODO "-DSQLITE_MAX_EXPR_DEPTH=0", // bug reported https://sqlite.org/forum/forumpost/87b9262f66, fixed in https://sqlite.org/src/info/5f58dd3a19605b6f
|
||||
//TODO "-DSQLITE_MAX_MMAP_SIZE=8589934592", // testfixture, bug reported https://sqlite.org/forum/forumpost/34380589f7, fixed in https://sqlite.org/src/info/d8e47382160e98be
|
||||
//TODO- "-DSQLITE_DEBUG",
|
||||
//TODO- "-DSQLITE_ENABLE_API_ARMOR",
|
||||
//TODO- "-DSQLITE_MEMDEBUG",
|
||||
}
|
||||
|
||||
configTest = []string{
|
||||
"-DHAVE_USLEEP",
|
||||
"-DLONGDOUBLE_TYPE=double",
|
||||
"-DSQLITE_CKSUMVFS_STATIC",
|
||||
"-DSQLITE_CORE", // testfixture
|
||||
"-DSQLITE_DEFAULT_MEMSTATUS=1",
|
||||
"-DSQLITE_DEFAULT_PAGE_SIZE=1024", // testfixture, hardcoded. See file_pages in autovacuum.test.
|
||||
"-DSQLITE_ENABLE_BYTECODE_VTAB", // testfixture
|
||||
"-DSQLITE_ENABLE_COLUMN_METADATA",
|
||||
"-DSQLITE_ENABLE_DBPAGE_VTAB", // testfixture
|
||||
"-DSQLITE_ENABLE_DBSTAT_VTAB",
|
||||
"-DSQLITE_ENABLE_DESERIALIZE", // testfixture
|
||||
"-DSQLITE_ENABLE_EXPLAIN_COMMENTS",
|
||||
"-DSQLITE_ENABLE_FTS5",
|
||||
"-DSQLITE_ENABLE_GEOPOLY",
|
||||
"-DSQLITE_ENABLE_MATH_FUNCTIONS",
|
||||
"-DSQLITE_ENABLE_MEMORY_MANAGEMENT",
|
||||
"-DSQLITE_ENABLE_OFFSET_SQL_FUNC",
|
||||
"-DSQLITE_ENABLE_PREUPDATE_HOOK",
|
||||
"-DSQLITE_ENABLE_RBU",
|
||||
"-DSQLITE_ENABLE_RTREE",
|
||||
"-DSQLITE_ENABLE_SESSION",
|
||||
"-DSQLITE_ENABLE_STAT4",
|
||||
"-DSQLITE_ENABLE_STMTVTAB", // testfixture
|
||||
"-DSQLITE_ENABLE_UNLOCK_NOTIFY", // Adds sqlite3_unlock_notify().
|
||||
"-DSQLITE_LIKE_DOESNT_MATCH_BLOBS",
|
||||
"-DSQLITE_MUTEX_APPDEF=1",
|
||||
"-DSQLITE_MUTEX_NOOP",
|
||||
"-DSQLITE_SOUNDEX",
|
||||
"-DSQLITE_TEMP_STORE=1", // testfixture
|
||||
"-DSQLITE_TEST",
|
||||
"-DSQLITE_THREADSAFE=1",
|
||||
//DONT "-DNDEBUG", // To enable GO_GENERATE=-DSQLITE_DEBUG
|
||||
//DONT "-DSQLITE_DQS=0", // testfixture
|
||||
//DONT "-DSQLITE_ENABLE_SNAPSHOT",
|
||||
//DONT "-DSQLITE_NO_SYNC=1",
|
||||
//DONT "-DSQLITE_OMIT_DECLTYPE", // testfixture
|
||||
//DONT "-DSQLITE_OMIT_DEPRECATED", // mptest
|
||||
//DONT "-DSQLITE_OMIT_LOAD_EXTENSION", // mptest
|
||||
//DONT "-DSQLITE_OMIT_SHARED_CACHE",
|
||||
//DONT "-DSQLITE_USE_ALLOCA",
|
||||
//TODO "-DHAVE_MALLOC_USABLE_SIZE"
|
||||
//TODO "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", //TODO report bug
|
||||
//TODO "-DSQLITE_ENABLE_FTS3",
|
||||
//TODO "-DSQLITE_ENABLE_FTS3_PARENTHESIS",
|
||||
//TODO "-DSQLITE_ENABLE_FTS3_TOKENIZER",
|
||||
//TODO "-DSQLITE_ENABLE_FTS4",
|
||||
//TODO "-DSQLITE_ENABLE_ICU",
|
||||
//TODO "-DSQLITE_MAX_EXPR_DEPTH=0", // bug reported https://sqlite.org/forum/forumpost/87b9262f66, fixed in https://sqlite.org/src/info/5f58dd3a19605b6f
|
||||
//TODO "-DSQLITE_MAX_MMAP_SIZE=8589934592", // testfixture, bug reported https://sqlite.org/forum/forumpost/34380589f7, fixed in https://sqlite.org/src/info/d8e47382160e98be
|
||||
//TODO- "-DSQLITE_DEBUG",
|
||||
//TODO- "-DSQLITE_ENABLE_API_ARMOR",
|
||||
//TODO- "-DSQLITE_MEMDEBUG",
|
||||
}
|
||||
|
||||
downloads = []struct {
|
||||
dir, url string
|
||||
sz int
|
||||
dev bool
|
||||
}{
|
||||
{sqliteDir, "https://www.sqlite.org/2023/sqlite-amalgamation-3410200.zip", 2457, false},
|
||||
{sqliteSrcDir, "https://www.sqlite.org/2023/sqlite-src-3410200.zip", 12814, false},
|
||||
}
|
||||
|
||||
sqliteDir = filepath.FromSlash("testdata/sqlite-amalgamation-3410200")
|
||||
sqliteSrcDir = filepath.FromSlash("testdata/sqlite-src-3410200")
|
||||
)
|
||||
|
||||
func download() {
|
||||
tmp, err := os.MkdirTemp("", "")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
for _, v := range downloads {
|
||||
dir := filepath.FromSlash(v.dir)
|
||||
root := filepath.Dir(v.dir)
|
||||
fi, err := os.Stat(dir)
|
||||
switch {
|
||||
case err == nil:
|
||||
if !fi.IsDir() {
|
||||
fmt.Fprintf(os.Stderr, "expected %s to be a directory\n", dir)
|
||||
}
|
||||
continue
|
||||
default:
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Fprintf(os.Stderr, "%s", err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := func() error {
|
||||
fmt.Printf("Downloading %v MB from %s\n", float64(v.sz)/1000, v.url)
|
||||
resp, err := http.Get(v.url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
base := filepath.Base(v.url)
|
||||
name := filepath.Join(tmp, base)
|
||||
f, err := os.Create(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer os.Remove(name)
|
||||
|
||||
n, err := io.Copy(f, resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := f.Seek(0, io.SeekStart); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch {
|
||||
case strings.HasSuffix(base, ".zip"):
|
||||
r, err := zip.NewReader(f, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, f := range r.File {
|
||||
fi := f.FileInfo()
|
||||
if fi.IsDir() {
|
||||
if err := os.MkdirAll(filepath.Join(root, f.Name), 0770); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if err := func() error {
|
||||
rc, err := f.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer rc.Close()
|
||||
|
||||
file, err := os.OpenFile(filepath.Join(root, f.Name), os.O_CREATE|os.O_WRONLY, fi.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w := bufio.NewWriter(file)
|
||||
if _, err = io.Copy(w, rc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := w.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return file.Close()
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
panic("internal error") //TODOOK
|
||||
}(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fail(s string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, s, args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var (
|
||||
oFullPathComments = flag.Bool("full-path-comments", false, "")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
fmt.Printf("Running on %s/%s.\n", runtime.GOOS, runtime.GOARCH)
|
||||
env := os.Getenv("GO_GENERATE")
|
||||
goarch := runtime.GOARCH
|
||||
goos := runtime.GOOS
|
||||
if s := os.Getenv("TARGET_GOOS"); s != "" {
|
||||
goos = s
|
||||
}
|
||||
if s := os.Getenv("TARGET_GOARCH"); s != "" {
|
||||
goarch = s
|
||||
}
|
||||
var more []string
|
||||
if env != "" {
|
||||
more = strings.Split(env, ",")
|
||||
}
|
||||
ndebug := []string{"-DNDEBUG"}
|
||||
for _, v := range more {
|
||||
if v == "-DSQLITE_DEBUG" {
|
||||
ndebug = nil
|
||||
}
|
||||
}
|
||||
more = append(more, ndebug...)
|
||||
download()
|
||||
switch goos {
|
||||
case "linux", "freebsd", "openbsd":
|
||||
configProduction = append(configProduction, "-DSQLITE_OS_UNIX=1")
|
||||
case "netbsd":
|
||||
configProduction = append(configProduction, []string{
|
||||
"-DSQLITE_OS_UNIX=1",
|
||||
"-D__libc_cond_broadcast=pthread_cond_broadcast",
|
||||
"-D__libc_cond_destroy=pthread_cond_destroy",
|
||||
"-D__libc_cond_init=pthread_cond_init",
|
||||
"-D__libc_cond_signal=pthread_cond_signal",
|
||||
"-D__libc_cond_wait=pthread_cond_wait",
|
||||
"-D__libc_mutex_destroy=pthread_mutex_destroy",
|
||||
"-D__libc_mutex_init=pthread_mutex_init",
|
||||
"-D__libc_mutex_lock=pthread_mutex_lock",
|
||||
"-D__libc_mutex_trylock=pthread_mutex_trylock",
|
||||
"-D__libc_mutex_unlock=pthread_mutex_unlock",
|
||||
"-D__libc_mutexattr_destroy=pthread_mutexattr_destroy",
|
||||
"-D__libc_mutexattr_init=pthread_mutexattr_init",
|
||||
"-D__libc_mutexattr_settype=pthread_mutexattr_settype",
|
||||
"-D__libc_thr_yield=sched_yield",
|
||||
}...)
|
||||
case "darwin":
|
||||
configProduction = append(configProduction,
|
||||
"-DSQLITE_OS_UNIX=1",
|
||||
"-DSQLITE_WITHOUT_ZONEMALLOC",
|
||||
)
|
||||
configTest = append(configTest,
|
||||
"-DSQLITE_OS_UNIX=1",
|
||||
"-DSQLITE_WITHOUT_ZONEMALLOC",
|
||||
)
|
||||
case "windows":
|
||||
configProduction = append(configProduction,
|
||||
"-DSQLITE_OS_WIN=1",
|
||||
"-D_MSC_VER=1900",
|
||||
)
|
||||
configTest = append(configTest,
|
||||
"-DSQLITE_OS_WIN=1",
|
||||
"-D_MSC_VER=1900",
|
||||
)
|
||||
default:
|
||||
fail("unknows/unsupported os: %s\n", goos)
|
||||
}
|
||||
makeSqliteProduction(goos, goarch, more)
|
||||
makeSqliteTest(goos, goarch, more)
|
||||
makeMpTest(goos, goarch, more)
|
||||
makeSpeedTest(goos, goarch, more)
|
||||
makeTestfixture(goos, goarch, more)
|
||||
ccgo.MustCopyDir(true, "testdata/tcl", sqliteSrcDir+"/test", nil)
|
||||
ccgo.MustCopyDir(true, "testdata/tcl", "testdata/overlay", nil)
|
||||
}
|
||||
|
||||
func configure(goos, goarch string) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fail("%s", err)
|
||||
}
|
||||
|
||||
defer os.Chdir(wd)
|
||||
|
||||
if err := os.Chdir(sqliteSrcDir); err != nil {
|
||||
fail("%s", err)
|
||||
}
|
||||
|
||||
cmd := newCmd("make", "distclean")
|
||||
cmd.Run()
|
||||
var args []string
|
||||
switch goos {
|
||||
case "linux", "freebsd", "netbsd", "openbsd":
|
||||
// nop
|
||||
case "darwin":
|
||||
args = append(args, "--with-tcl=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Tcl.framework")
|
||||
case "windows":
|
||||
switch goarch {
|
||||
case "amd64":
|
||||
args = append(args, "--host=x86_64-w64-mingw32")
|
||||
case "386":
|
||||
args = append(args, "--host=i686-w64-mingw32")
|
||||
default:
|
||||
fail("unknown/unsupported os/arch: %s/%s\n", goos, goarch)
|
||||
}
|
||||
default:
|
||||
fail("unknown/unsupported os/arch: %s/%s\n", goos, goarch)
|
||||
}
|
||||
cmd = newCmd("./configure", args...)
|
||||
if err = cmd.Run(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
|
||||
cmd = newCmd("make", "parse.h", "opcodes.h")
|
||||
if err = cmd.Run(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func newCmd(bin string, args ...string) *exec.Cmd {
|
||||
fmt.Printf("==== newCmd %s\n", bin)
|
||||
for _, v := range args {
|
||||
fmt.Printf("\t%v\n", v)
|
||||
}
|
||||
r := exec.Command(bin, args...)
|
||||
r.Stdout = os.Stdout
|
||||
r.Stderr = os.Stderr
|
||||
return r
|
||||
}
|
||||
|
||||
func makeTestfixture(goos, goarch string, more []string) {
|
||||
dir := filepath.FromSlash(fmt.Sprintf("internal/testfixture"))
|
||||
files := []string{
|
||||
"ext/expert/sqlite3expert.c",
|
||||
"ext/expert/test_expert.c",
|
||||
"ext/fts3/fts3_term.c",
|
||||
"ext/fts3/fts3_test.c",
|
||||
"ext/fts5/fts5_tcl.c",
|
||||
"ext/fts5/fts5_test_mi.c",
|
||||
"ext/fts5/fts5_test_tok.c",
|
||||
"ext/misc/amatch.c",
|
||||
"ext/misc/appendvfs.c",
|
||||
"ext/misc/basexx.c",
|
||||
"ext/misc/carray.c",
|
||||
"ext/misc/cksumvfs.c",
|
||||
"ext/misc/closure.c",
|
||||
"ext/misc/csv.c",
|
||||
"ext/misc/decimal.c",
|
||||
"ext/misc/eval.c",
|
||||
"ext/misc/explain.c",
|
||||
"ext/misc/fileio.c",
|
||||
"ext/misc/fuzzer.c",
|
||||
"ext/misc/ieee754.c",
|
||||
"ext/misc/mmapwarm.c",
|
||||
"ext/misc/nextchar.c",
|
||||
"ext/misc/normalize.c",
|
||||
"ext/misc/percentile.c",
|
||||
"ext/misc/prefixes.c",
|
||||
"ext/misc/qpvtab.c",
|
||||
"ext/misc/regexp.c",
|
||||
"ext/misc/remember.c",
|
||||
"ext/misc/series.c",
|
||||
"ext/misc/spellfix.c",
|
||||
"ext/misc/totype.c",
|
||||
"ext/misc/unionvtab.c",
|
||||
"ext/misc/wholenumber.c",
|
||||
"ext/rbu/test_rbu.c",
|
||||
"ext/recover/dbdata.c",
|
||||
"ext/recover/sqlite3recover.c",
|
||||
"ext/recover/test_recover.c",
|
||||
"ext/rtree/test_rtreedoc.c",
|
||||
"ext/session/test_session.c",
|
||||
"ext/userauth/userauth.c",
|
||||
"src/tclsqlite.c",
|
||||
"src/test1.c",
|
||||
"src/test2.c",
|
||||
"src/test3.c",
|
||||
"src/test4.c",
|
||||
"src/test5.c",
|
||||
"src/test6.c",
|
||||
"src/test8.c",
|
||||
"src/test9.c",
|
||||
"src/test_async.c",
|
||||
"src/test_autoext.c",
|
||||
"src/test_backup.c",
|
||||
"src/test_bestindex.c",
|
||||
"src/test_blob.c",
|
||||
"src/test_btree.c",
|
||||
"src/test_config.c",
|
||||
"src/test_delete.c",
|
||||
"src/test_demovfs.c",
|
||||
"src/test_devsym.c",
|
||||
"src/test_fs.c",
|
||||
"src/test_func.c",
|
||||
"src/test_hexio.c",
|
||||
"src/test_init.c",
|
||||
"src/test_intarray.c",
|
||||
"src/test_journal.c",
|
||||
"src/test_malloc.c",
|
||||
"src/test_md5.c",
|
||||
"src/test_multiplex.c",
|
||||
"src/test_mutex.c",
|
||||
"src/test_onefile.c",
|
||||
"src/test_osinst.c",
|
||||
"src/test_pcache.c",
|
||||
"src/test_quota.c",
|
||||
"src/test_rtree.c",
|
||||
"src/test_schema.c",
|
||||
"src/test_superlock.c",
|
||||
"src/test_syscall.c",
|
||||
"src/test_tclsh.c",
|
||||
"src/test_tclvar.c",
|
||||
"src/test_thread.c",
|
||||
"src/test_vdbecov.c",
|
||||
"src/test_vfs.c",
|
||||
"src/test_windirent.c",
|
||||
"src/test_window.c",
|
||||
"src/test_wsd.c",
|
||||
}
|
||||
for i, v := range files {
|
||||
files[i] = filepath.Join(sqliteSrcDir, filepath.FromSlash(v))
|
||||
}
|
||||
configure(goos, goarch)
|
||||
|
||||
var defines, includes []string
|
||||
switch goos {
|
||||
case "freebsd", "openbsd":
|
||||
includes = []string{"-I/usr/local/include/tcl8.6"}
|
||||
case "linux":
|
||||
includes = []string{"-I/usr/include/tcl8.6"}
|
||||
case "windows":
|
||||
includes = []string{"-I/usr/include/tcl8.6"}
|
||||
case "netbsd":
|
||||
includes = []string{"-I/usr/pkg/include"}
|
||||
defines = []string{
|
||||
"-D__libc_cond_broadcast=pthread_cond_broadcast",
|
||||
"-D__libc_cond_destroy=pthread_cond_destroy",
|
||||
"-D__libc_cond_init=pthread_cond_init",
|
||||
"-D__libc_cond_signal=pthread_cond_signal",
|
||||
"-D__libc_cond_wait=pthread_cond_wait",
|
||||
"-D__libc_mutex_destroy=pthread_mutex_destroy",
|
||||
"-D__libc_mutex_init=pthread_mutex_init",
|
||||
"-D__libc_mutex_lock=pthread_mutex_lock",
|
||||
"-D__libc_mutex_trylock=pthread_mutex_trylock",
|
||||
"-D__libc_mutex_unlock=pthread_mutex_unlock",
|
||||
"-D__libc_mutexattr_destroy=pthread_mutexattr_destroy",
|
||||
"-D__libc_mutexattr_init=pthread_mutexattr_init",
|
||||
"-D__libc_mutexattr_settype=pthread_mutexattr_settype",
|
||||
"-D__libc_thr_yield=sched_yield",
|
||||
}
|
||||
}
|
||||
|
||||
args := join(
|
||||
[]string{
|
||||
"ccgo",
|
||||
"-DBUILD_sqlite",
|
||||
"-DNDEBUG",
|
||||
"-DSQLITE_CKSUMVFS_STATIC",
|
||||
"-DSQLITE_CORE",
|
||||
"-DSQLITE_CRASH_TEST=1",
|
||||
"-DSQLITE_DEFAULT_PAGE_SIZE=1024",
|
||||
"-DSQLITE_ENABLE_BYTECODE_VTAB",
|
||||
"-DSQLITE_ENABLE_DBPAGE_VTAB",
|
||||
"-DSQLITE_ENABLE_MATH_FUNCTIONS",
|
||||
"-DSQLITE_ENABLE_STMTVTAB",
|
||||
"-DSQLITE_NO_SYNC=1",
|
||||
"-DSQLITE_OMIT_LOAD_EXTENSION",
|
||||
"-DSQLITE_PRIVATE=\"\"",
|
||||
"-DSQLITE_SERIES_CONSTRAINT_VERIFY=1",
|
||||
"-DSQLITE_SERVER=1",
|
||||
"-DSQLITE_TEMP_STORE=1",
|
||||
"-DSQLITE_TEST=1",
|
||||
"-DSQLITE_THREADSAFE=1",
|
||||
"-DTCLSH_INIT_PROC=sqlite3TestInit",
|
||||
"-D_HAVE_SQLITE_CONFIG_H",
|
||||
},
|
||||
defines,
|
||||
includes,
|
||||
[]string{
|
||||
"-export-defines", "",
|
||||
"-export-fields", "F",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-trace-translation-units",
|
||||
volatiles,
|
||||
"-lmodernc.org/sqlite/libtest",
|
||||
"-lmodernc.org/tcl/lib",
|
||||
"-lmodernc.org/z/lib",
|
||||
"-o", filepath.Join(dir, fmt.Sprintf("testfixture_%s_%s.go", goos, goarch)),
|
||||
fmt.Sprintf("-I%s", filepath.Join(sqliteSrcDir, filepath.FromSlash("ext/async"))),
|
||||
fmt.Sprintf("-I%s", filepath.Join(sqliteSrcDir, filepath.FromSlash("ext/fts3"))),
|
||||
fmt.Sprintf("-I%s", filepath.Join(sqliteSrcDir, filepath.FromSlash("ext/icu"))),
|
||||
fmt.Sprintf("-I%s", filepath.Join(sqliteSrcDir, filepath.FromSlash("ext/rtree"))),
|
||||
fmt.Sprintf("-I%s", filepath.Join(sqliteSrcDir, filepath.FromSlash("ext/session"))),
|
||||
fmt.Sprintf("-I%s", filepath.Join(sqliteSrcDir, filepath.FromSlash("ext/userauth"))),
|
||||
fmt.Sprintf("-I%s", filepath.Join(sqliteSrcDir, filepath.FromSlash("src"))),
|
||||
fmt.Sprintf("-I%s", sqliteDir),
|
||||
fmt.Sprintf("-I%s", sqliteSrcDir),
|
||||
},
|
||||
otherOpts(),
|
||||
files,
|
||||
more,
|
||||
configTest,
|
||||
)
|
||||
task := ccgo.NewTask(args, nil, nil)
|
||||
if err := task.Main(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func otherOpts() (r []string) {
|
||||
if *oFullPathComments {
|
||||
r = append(r, "-full-path-comments")
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func makeSpeedTest(goos, goarch string, more []string) {
|
||||
task := ccgo.NewTask(
|
||||
join(
|
||||
[]string{
|
||||
"ccgo",
|
||||
"-export-defines", "",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-o", filepath.FromSlash(fmt.Sprintf("speedtest1/main_%s_%s.go", goos, goarch)),
|
||||
"-trace-translation-units",
|
||||
filepath.Join(sqliteSrcDir, "test", "speedtest1.c"),
|
||||
fmt.Sprintf("-I%s", sqliteDir),
|
||||
"-l", "modernc.org/sqlite/lib",
|
||||
},
|
||||
otherOpts(),
|
||||
more,
|
||||
configProduction,
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if err := task.Main(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func makeMpTest(goos, goarch string, more []string) {
|
||||
task := ccgo.NewTask(
|
||||
join(
|
||||
[]string{
|
||||
"ccgo",
|
||||
"-export-defines", "",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-o", filepath.FromSlash(fmt.Sprintf("internal/mptest/main_%s_%s.go", goos, goarch)),
|
||||
"-trace-translation-units",
|
||||
// filepath.Join(sqliteSrcDir, "mptest", "mptest.c"),
|
||||
filepath.Join("testdata", "mptest.c"),
|
||||
fmt.Sprintf("-I%s", sqliteDir),
|
||||
"-l", "modernc.org/sqlite/lib",
|
||||
},
|
||||
otherOpts(),
|
||||
more,
|
||||
configProduction,
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if err := task.Main(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func makeSqliteProduction(goos, goarch string, more []string) {
|
||||
fn := filepath.FromSlash(fmt.Sprintf("lib/sqlite_%s_%s.go", goos, goarch))
|
||||
task := ccgo.NewTask(
|
||||
join(
|
||||
[]string{
|
||||
"ccgo",
|
||||
"-DSQLITE_PRIVATE=",
|
||||
"-export-defines", "",
|
||||
"-export-enums", "",
|
||||
"-export-externs", "X",
|
||||
"-export-fields", "F",
|
||||
"-export-typedefs", "",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-pkgname", "sqlite3",
|
||||
volatiles,
|
||||
"-o", fn,
|
||||
"-trace-translation-units",
|
||||
filepath.Join(sqliteDir, "sqlite3.c"),
|
||||
},
|
||||
otherOpts(),
|
||||
more,
|
||||
configProduction,
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if err := task.Main(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
|
||||
if err := patchXsqlite3_initialize(fn); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func makeSqliteTest(goos, goarch string, more []string) {
|
||||
fn := filepath.FromSlash(fmt.Sprintf("libtest/sqlite_%s_%s.go", goos, goarch))
|
||||
task := ccgo.NewTask(
|
||||
join(
|
||||
[]string{
|
||||
"ccgo",
|
||||
"-DSQLITE_PRIVATE=",
|
||||
"-export-defines", "",
|
||||
"-export-enums", "",
|
||||
"-export-externs", "X",
|
||||
"-export-fields", "F",
|
||||
"-export-typedefs", "",
|
||||
"-ignore-unsupported-alignment",
|
||||
"-pkgname", "sqlite3",
|
||||
volatiles,
|
||||
"-o", fn,
|
||||
"-trace-translation-units",
|
||||
volatiles,
|
||||
filepath.Join(sqliteDir, "sqlite3.c"),
|
||||
},
|
||||
otherOpts(),
|
||||
more,
|
||||
configTest,
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
if err := task.Main(); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
|
||||
if err := patchXsqlite3_initialize(fn); err != nil {
|
||||
fail("%s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func join(a ...[]string) (r []string) {
|
||||
n := 0
|
||||
for _, v := range a {
|
||||
n += len(v)
|
||||
}
|
||||
r = make([]string, 0, n)
|
||||
for _, v := range a {
|
||||
r = append(r, v...)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func patchXsqlite3_initialize(fn string) error {
|
||||
const s = "func Xsqlite3_initialize(tls *libc.TLS) int32 {"
|
||||
return patch(fn, func(b []byte) []diff {
|
||||
x := bytes.Index(b, []byte(s))
|
||||
return []diff{{x, x + len(s), `
|
||||
var mu mutex
|
||||
|
||||
func init() { mu.recursive = true }
|
||||
|
||||
func Xsqlite3_initialize(tls *libc.TLS) int32 {
|
||||
mu.enter(tls.ID)
|
||||
defer mu.leave(tls.ID)
|
||||
|
||||
`}}
|
||||
})
|
||||
}
|
||||
|
||||
type diff struct {
|
||||
from, to int // byte offsets
|
||||
replace string // replaces b[from:to]
|
||||
}
|
||||
|
||||
func patch(fn string, f func([]byte) []diff) error {
|
||||
b, err := os.ReadFile(fn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
diffs := f(b)
|
||||
sort.Slice(diffs, func(i, j int) bool { return diffs[i].from < diffs[j].from })
|
||||
var patched [][]byte
|
||||
off := 0
|
||||
for _, diff := range diffs {
|
||||
from := diff.from - off
|
||||
to := diff.to - off
|
||||
patched = append(patched, b[:from])
|
||||
patched = append(patched, []byte(diff.replace))
|
||||
b = b[to:]
|
||||
off += to
|
||||
}
|
||||
patched = append(patched, b)
|
||||
return os.WriteFile(fn, bytes.Join(patched, nil), 0660)
|
||||
}
|
1384
vendor/modernc.org/sqlite/lib/capi_darwin_amd64.go
generated
vendored
1384
vendor/modernc.org/sqlite/lib/capi_darwin_amd64.go
generated
vendored
File diff suppressed because it is too large
Load diff
1384
vendor/modernc.org/sqlite/lib/capi_darwin_arm64.go
generated
vendored
1384
vendor/modernc.org/sqlite/lib/capi_darwin_arm64.go
generated
vendored
File diff suppressed because it is too large
Load diff
1360
vendor/modernc.org/sqlite/lib/capi_freebsd_386.go
generated
vendored
1360
vendor/modernc.org/sqlite/lib/capi_freebsd_386.go
generated
vendored
File diff suppressed because it is too large
Load diff
1360
vendor/modernc.org/sqlite/lib/capi_freebsd_amd64.go
generated
vendored
1360
vendor/modernc.org/sqlite/lib/capi_freebsd_amd64.go
generated
vendored
File diff suppressed because it is too large
Load diff
1360
vendor/modernc.org/sqlite/lib/capi_freebsd_arm.go
generated
vendored
1360
vendor/modernc.org/sqlite/lib/capi_freebsd_arm.go
generated
vendored
File diff suppressed because it is too large
Load diff
1360
vendor/modernc.org/sqlite/lib/capi_freebsd_arm64.go
generated
vendored
1360
vendor/modernc.org/sqlite/lib/capi_freebsd_arm64.go
generated
vendored
File diff suppressed because it is too large
Load diff
1360
vendor/modernc.org/sqlite/lib/capi_linux_386.go
generated
vendored
1360
vendor/modernc.org/sqlite/lib/capi_linux_386.go
generated
vendored
File diff suppressed because it is too large
Load diff
1360
vendor/modernc.org/sqlite/lib/capi_linux_amd64.go
generated
vendored
1360
vendor/modernc.org/sqlite/lib/capi_linux_amd64.go
generated
vendored
File diff suppressed because it is too large
Load diff
1360
vendor/modernc.org/sqlite/lib/capi_linux_arm.go
generated
vendored
1360
vendor/modernc.org/sqlite/lib/capi_linux_arm.go
generated
vendored
File diff suppressed because it is too large
Load diff
1360
vendor/modernc.org/sqlite/lib/capi_linux_arm64.go
generated
vendored
1360
vendor/modernc.org/sqlite/lib/capi_linux_arm64.go
generated
vendored
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue