[chore] Downgrade sqlite v1.29.2 -> v1.28.0 (#2736)

* [chore] Downgrade sqlite v1.29.2 -> v1.29.0

* go down to v1.28.0
This commit is contained in:
tobi 2024-03-08 11:45:15 +01:00 committed by GitHub
commit ebdee5aed8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
117 changed files with 1835338 additions and 2454288 deletions

27
vendor/modernc.org/gc/v3/GO-LICENSE generated vendored
View file

@ -1,27 +0,0 @@
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.

69
vendor/modernc.org/gc/v3/LICENSE generated vendored
View file

@ -1,69 +0,0 @@
-------------------------------------------------------------------------------
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
View file

@ -1,113 +0,0 @@
.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
View file

@ -1,682 +0,0 @@
// 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
View file

@ -1,598 +0,0 @@
// 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
View file

@ -1,559 +0,0 @@
// 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 &parallel{
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
View file

@ -1,761 +0,0 @@
// 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

File diff suppressed because it is too large Load diff

1446
vendor/modernc.org/gc/v3/scanner.go generated vendored

File diff suppressed because it is too large Load diff

115
vendor/modernc.org/gc/v3/stringer.go generated vendored
View file

@ -1,115 +0,0 @@
// 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
View file

@ -1,90 +0,0 @@
// 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
View file

@ -1,813 +0,0 @@
// 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
View file

@ -1,716 +0,0 @@
// 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
}