#136: Start working on database persistence

This commit is contained in:
TwinProduction
2021-07-12 00:56:30 -04:00
committed by Chris
parent e6335da94f
commit bd1eb7c61b
657 changed files with 2190821 additions and 82 deletions

19
vendor/modernc.org/cc/v3/AUTHORS generated vendored Normal file
View File

@ -0,0 +1,19 @@
# This file lists authors for copyright purposes. This file is distinct from
# the CONTRIBUTORS files. See the latter for an explanation.
#
# Names should be added to this file as:
# Name or Organization <email address>
#
# The email address is not required for organizations.
#
# Please keep the list sorted.
Dan Kortschak <dan.kortschak@adelaide.edu.au>
Dan Peterson <danp@danp.net>
Denys Smirnov <denis.smirnov.91@gmail.com>
Jan Mercl <0xjnml@gmail.com>
Maxim Kupriianov <max@kc.vc>
Peter Waller <p@pwaller.net>
Steffen Butzer <steffen(dot)butzer@outlook.com>
Tommi Virtanen <tv@eagain.net>
Yasuhiro Matsumoto <mattn.jp@gmail.com>

18
vendor/modernc.org/cc/v3/CONTRIBUTORS generated vendored Normal file
View File

@ -0,0 +1,18 @@
# This file lists people who contributed code to this repository. The AUTHORS
# file lists the copyright holders; this file lists people.
#
# Names should be added to this file like so:
# Name <email address>
#
# Please keep the list sorted.
Dan Kortschak <dan.kortschak@adelaide.edu.au>
Dan Peterson <danp@danp.net>
Denys Smirnov <denis.smirnov.91@gmail.com>
Jan Mercl <0xjnml@gmail.com>
Maxim Kupriianov <max@kc.vc>
Peter Waller <p@pwaller.net>
Steffen Butzer <steffen(dot)butzer@outlook.com>
Tommi Virtanen <tv@eagain.net>
Yasuhiro Matsumoto <mattn.jp@gmail.com>
Zvi Effron <zeffron@cs.hmc.edu>

27
vendor/modernc.org/cc/v3/GO-LICENSE generated vendored Normal file
View File

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

27
vendor/modernc.org/cc/v3/LICENSE generated vendored Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 2017 The CC 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.

121
vendor/modernc.org/cc/v3/Makefile generated vendored Normal file
View File

@ -0,0 +1,121 @@
# Copyright 2019 The CC Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
.PHONY: all bench clean cover cpu editor internalError later mem nuke todo edit devbench
grep=--include=*.go --include=*.l --include=*.y --include=*.yy
ngrep='internalError\|TODOOK\|lexer\.go\|ast.go\|trigraphs\.go\|.*_string\.go\|stringer\.go\|testdata\/gcc'
testlog=testdata/testlog-$(shell echo $$GOOS)-$(shell echo $$GOARCH)-on-$(shell go env GOOS)-$(shell go env GOARCH)
all: lexer.go
LC_ALL=C make all_log 2>&1 | tee log
all_log:
date
go version
uname -a
./unconvert.sh
gofmt -l -s -w *.go
GOOS=darwin GOARCH=amd64 go build
GOOS=darwin GOARCH=arm64 go build
GOOS=linux GOARCH=386 go build
GOOS=linux GOARCH=amd64 go build
GOOS=linux GOARCH=arm go build
GOOS=windows GOARCH=386 go build
GOOS=windows GOARCH=amd64 go build
go vet | grep -v $(ngrep) || true
golint | grep -v $(ngrep) || true
misspell *.go
staticcheck | grep -v 'lexer\.go' || true
pcregrep -nM 'FAIL|false|<nil>|:\n}' ast_test.go || true
test:
go version | tee $(testlog)
uname -a | tee -a $(testlog)
go test -v -timeout 24h | tee -a $(testlog)
grep -ni fail $(testlog) | tee -a $(testlog) || true
LC_ALL=C date | tee -a $(testlog)
grep -ni --color=always fail $(testlog) || true
test_linux_amd64:
GOOS=linux GOARCH=amd64 make test
test_linux_386:
GOOS=linux GOARCH=386 make test
test_linux_arm:
GOOS=linux GOARCH=arm make test
test_linux_arm64:
GOOS=linux GOARCH=arm64 make test
test_windows_amd64:
go version
go test -v -timeout 24h
test_windows386:
go version
go test -v -timeout 24h
build_all_targets:
GOOS=darwin GOARCH=amd64 go build -v ./...
GOOS=darwin GOARCH=arm64 go build -v ./...
GOOS=linux GOARCH=386 go build -v ./...
GOOS=linux GOARCH=amd64 go build -v ./...
GOOS=linux GOARCH=arm go build -v ./...
GOOS=linux GOARCH=arm64 go build -v ./...
GOOS=windows GOARCH=386 go build -v ./...
GOOS=windows GOARCH=amd64 go build -v ./...
devbench:
date 2>&1 | tee log-devbench
go test -timeout 24h -dev -run @ -bench . 2>&1 | tee -a log-devbench
grep -n 'FAIL\|SKIP' log-devbench || true
bench:
date 2>&1 | tee log-bench
go test -timeout 24h -v -run '^[^E]' -bench . 2>&1 | tee -a log-bench
grep -n 'FAIL\|SKIP' log-bench || true
clean:
go clean
rm -f *~ *.test *.out
cover:
t=$(shell mktemp) ; go test -coverprofile $$t && go tool cover -html $$t && unlink $$t
cpu: clean
go test -run @ -bench . -cpuprofile cpu.out
go tool pprof -lines *.test cpu.out
edit:
@touch log
@if [ -f "Session.vim" ]; then gvim -S & else gvim -p Makefile *.go & fi
editor: lexer.go
gofmt -l -s -w *.go
GO111MODULE=off go test -o /dev/null -c
GO111MODULE=off go install 2>&1 | tee log
ast.go lexer.go stringer.go: lexer.l parser.yy enum.go
go generate
later:
@grep -n $(grep) LATER * || true
@grep -n $(grep) MAYBE * || true
mem: clean
# go test -v -run ParserCS -csmith 2m -memprofile mem.out -timeout 24h
# go test -v -run @ -bench BenchmarkScanner -memprofile mem.out -timeout 24h
go test -v -run TestTranslateSQLite -memprofile mem.out -timeout 24h
go tool pprof -lines -web -alloc_space *.test mem.out
nuke: clean
go clean -i
todo:
@grep -nr $(grep) ^[[:space:]]*_[[:space:]]*=[[:space:]][[:alpha:]][[:alnum:]]* * | grep -v $(ngrep) || true
@grep -nr $(grep) 'TODO\|panic' * | grep -v $(ngrep) || true
@grep -nr $(grep) BUG * | grep -v $(ngrep) || true
@grep -nr $(grep) [^[:alpha:]]println * | grep -v $(ngrep) || true

11
vendor/modernc.org/cc/v3/README.md generated vendored Normal file
View File

@ -0,0 +1,11 @@
# cc/v3
Package CC is a C99 compiler front end.
Most of the functionality is now working.
Installation
$ go get -u modernc.org/cc/v3
Documentation: [godoc.org/modernc.org/cc/v3](http://godoc.org/modernc.org/cc/v3)

1019
vendor/modernc.org/cc/v3/abi.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

335
vendor/modernc.org/cc/v3/abi_platforms.go generated vendored Normal file
View File

@ -0,0 +1,335 @@
package cc
import "encoding/binary"
// abiByteOrders contains byte order information for known architectures.
var abiByteOrders = map[string]binary.ByteOrder{
"amd64": binary.LittleEndian,
"386": binary.LittleEndian,
"arm": binary.LittleEndian,
"arm64": binary.LittleEndian,
"s390x": binary.BigEndian,
}
// abiTypes contains size and alignment information for known OS/arch pairs.
//
// The content is generated by ./cmd/cabi/main.c.
var abiTypes = map[[2]string]map[Kind]ABIType{
// Linux, generated by GCC 8.3.0
{"linux", "amd64"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {8, 8, 8},
ULong: {8, 8, 8},
LongLong: {8, 8, 8},
ULongLong: {8, 8, 8},
Ptr: {8, 8, 8},
Function: {8, 8, 8},
Float: {4, 4, 4},
Double: {8, 8, 8},
LongDouble: {16, 16, 16},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 8, 8},
UInt64: {8, 8, 8},
Int128: {16, 16, 16},
UInt128: {16, 16, 16},
Float32: {4, 4, 4},
Float32x: {8, 8, 8},
Float64: {8, 8, 8},
Float64x: {16, 16, 16},
Float128: {16, 16, 16},
Decimal32: {4, 4, 4},
Decimal64: {8, 8, 8},
Decimal128: {16, 16, 16},
},
{"linux", "386"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {4, 4, 4},
ULong: {4, 4, 4},
LongLong: {8, 4, 4},
ULongLong: {8, 4, 4},
Ptr: {4, 4, 4},
Function: {4, 4, 4},
Float: {4, 4, 4},
Double: {8, 4, 4},
LongDouble: {12, 4, 4},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 4, 4},
UInt64: {8, 4, 4},
Float32: {4, 4, 4},
Float32x: {8, 4, 4},
Float64: {8, 4, 4},
Float64x: {12, 4, 4},
Float128: {16, 16, 16},
Decimal32: {4, 4, 4},
Decimal64: {8, 8, 8},
Decimal128: {16, 16, 16},
},
{"linux", "arm"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {4, 4, 4},
ULong: {4, 4, 4},
LongLong: {8, 8, 8},
ULongLong: {8, 8, 8},
Ptr: {4, 4, 4},
Function: {4, 4, 4},
Float: {4, 4, 4},
Double: {8, 8, 8},
LongDouble: {8, 8, 8},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 8, 8},
UInt64: {8, 8, 8},
},
{"linux", "arm64"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {8, 8, 8},
ULong: {8, 8, 8},
LongLong: {8, 8, 8},
ULongLong: {8, 8, 8},
Ptr: {8, 8, 8},
Function: {8, 8, 8},
Float: {4, 4, 4},
Double: {8, 8, 8},
LongDouble: {16, 16, 16},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 8, 8},
UInt64: {8, 8, 8},
Int128: {16, 16, 16},
UInt128: {16, 16, 16},
},
// $ x86_64-w64-mingw32-gcc main.c && wine a.exe
{"windows", "amd64"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {4, 4, 4},
ULong: {4, 4, 4},
LongLong: {8, 8, 8},
ULongLong: {8, 8, 8},
Ptr: {8, 8, 8},
Function: {8, 8, 8},
Float: {4, 4, 4},
Double: {8, 8, 8},
LongDouble: {16, 16, 16},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 8, 8},
UInt64: {8, 8, 8},
Int128: {16, 16, 16},
UInt128: {16, 16, 16},
Float32: {4, 4, 4},
Float32x: {8, 8, 8},
Float64: {8, 8, 8},
Float64x: {16, 16, 16},
Float128: {16, 16, 16},
Decimal32: {4, 4, 4},
Decimal64: {8, 8, 8},
Decimal128: {16, 16, 16},
},
// $ i686-w64-mingw32-gcc main.c && wine a.exe
{"windows", "386"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {4, 4, 4},
ULong: {4, 4, 4},
LongLong: {8, 8, 8},
ULongLong: {8, 8, 8},
Ptr: {4, 4, 4},
Function: {4, 4, 4},
Float: {4, 4, 4},
Double: {8, 8, 8},
LongDouble: {12, 4, 4},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 8, 8},
UInt64: {8, 8, 8},
Float32: {4, 4, 4},
Float32x: {8, 8, 8},
Float64: {8, 8, 8},
Float64x: {12, 4, 4},
Float128: {16, 16, 16},
Decimal32: {4, 4, 4},
Decimal64: {8, 8, 8},
Decimal128: {16, 16, 16},
},
{"darwin", "amd64"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {8, 8, 8},
ULong: {8, 8, 8},
LongLong: {8, 8, 8},
ULongLong: {8, 8, 8},
Ptr: {8, 8, 8},
Function: {8, 8, 8},
Float: {4, 4, 4},
Double: {8, 8, 8},
LongDouble: {16, 16, 16},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 8, 8},
UInt64: {8, 8, 8},
Int128: {16, 16, 16},
UInt128: {16, 16, 16},
},
{"darwin", "arm64"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {8, 8, 8},
ULong: {8, 8, 8},
LongLong: {8, 8, 8},
ULongLong: {8, 8, 8},
Ptr: {8, 8, 8},
Function: {8, 8, 8},
Float: {4, 4, 4},
Double: {8, 8, 8},
LongDouble: {8, 8, 8},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 8, 8},
UInt64: {8, 8, 8},
Int128: {16, 16, 16},
UInt128: {16, 16, 16},
},
// gcc (SUSE Linux) 7.5.0
{"linux", "s390x"}: {
Void: {1, 1, 1},
Bool: {1, 1, 1},
Char: {1, 1, 1},
SChar: {1, 1, 1},
UChar: {1, 1, 1},
Short: {2, 2, 2},
UShort: {2, 2, 2},
Enum: {4, 4, 4},
Int: {4, 4, 4},
UInt: {4, 4, 4},
Long: {8, 8, 8},
ULong: {8, 8, 8},
LongLong: {8, 8, 8},
ULongLong: {8, 8, 8},
Ptr: {8, 8, 8},
Function: {8, 8, 8},
Float: {4, 4, 4},
Double: {8, 8, 8},
LongDouble: {16, 8, 8},
Int8: {1, 1, 1},
UInt8: {1, 1, 1},
Int16: {2, 2, 2},
UInt16: {2, 2, 2},
Int32: {4, 4, 4},
UInt32: {4, 4, 4},
Int64: {8, 8, 8},
UInt64: {8, 8, 8},
Int128: {16, 8, 8},
UInt128: {16, 8, 8},
Float32: {4, 4, 4},
Float32x: {8, 8, 8},
Float64: {8, 8, 8},
Float64x: {16, 8, 8},
Float128: {16, 8, 8},
Decimal32: {4, 4, 4},
Decimal64: {8, 8, 8},
Decimal128: {16, 8, 8},
},
}

5226
vendor/modernc.org/cc/v3/ast.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

1160
vendor/modernc.org/cc/v3/ast2.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

960
vendor/modernc.org/cc/v3/cc.go generated vendored Normal file
View File

@ -0,0 +1,960 @@
// Copyright 2019 The CC Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//TODO https://todo.sr.ht/~mcf/cc-issues/34
//TODO http://mcpp.sourceforge.net/ "Provides a validation suite to test C/C++ preprocessor's conformance and quality comprehensively."
//go:generate rm -f lexer.go
//go:generate golex -o lexer.go lexer.l
//go:generate rm -f ast.go
//go:generate yy -o /dev/null -position -astImport "\"fmt\"\n\n\"modernc.org/token\"" -prettyString PrettyString -kind Case -noListKind -noPrivateHelpers -forceOptPos parser.yy
//go:generate stringer -output stringer.go -linecomment -type=Kind,Linkage
//go:generate sh -c "go test -run ^Example |fe"
// Package cc is a C99 compiler front end (Work in progress).
//
// Installation
//
// To install/update cc/v3 invoke:
//
// $ go get [-u] modernc.org/cc/v3
//
// Online documentation
//
// See https://godoc.org/modernc.org/cc/v3.
//
// Status
//
// Most of the functionality is now working.
//
// Supported platforms
//
// The code is known to work on Darwin, Linux and Windows, but the supported
// features may vary.
//
// Links
//
// Referenced from elsewhere:
//
// [0]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
// [1]: https://www.spinellis.gr/blog/20060626/cpp.algo.pdf
// [2]: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
// [3]: http://gallium.inria.fr/~fpottier/publis/jourdan-fpottier-2016.pdf
// [4]: https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc/Attribute-Syntax.html#Attribute-Syntax
package cc // import "modernc.org/cc/v3"
import (
"fmt"
goscanner "go/scanner"
gotoken "go/token"
"hash/maphash"
"io"
"math"
"os"
"os/exec"
"reflect"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"modernc.org/strutil"
"modernc.org/token"
)
const (
scopeParent StringID = -iota - 1
scopeSkip
)
var (
_ Pragma = (*pragma)(nil)
cache = newPPCache()
dict = newDictionary()
dictStrings [math.MaxUint8 + 1]string
noPos token.Position
debugIncludePaths bool
debugWorkingDir bool
isTesting bool
isTestingMingw bool
idPtrdiffT = dict.sid("ptrdiff_t")
idSizeT = dict.sid("size_t")
idWCharT = dict.sid("wchar_t")
token4Pool = sync.Pool{New: func() interface{} { r := make([]token4, 0); return &r }} //DONE benchmrk tuned capacity
tokenPool = sync.Pool{New: func() interface{} { r := make([]Token, 0); return &r }} //DONE benchmrk tuned capacity
printHooks = strutil.PrettyPrintHooks{
reflect.TypeOf(Token{}): func(f strutil.Formatter, v interface{}, prefix, suffix string) {
t := v.(Token)
if (t == Token{}) {
return
}
f.Format(prefix)
r := t.Rune
if p := t.Position(); p.IsValid() {
f.Format("%v: ", p)
}
s := tokName(r)
if x := s[0]; x >= '0' && x <= '9' {
s = strconv.QuoteRune(r)
}
f.Format("%s", s)
if s := t.Value.String(); len(s) != 0 {
f.Format(" %q", s)
}
f.Format(suffix)
},
reflect.TypeOf((*operand)(nil)): func(f strutil.Formatter, v interface{}, prefix, suffix string) {
op := v.(*operand)
f.Format(prefix)
f.Format("[%v %T(%[2]v)]", op.Type(), op.Value())
f.Format(suffix)
},
}
)
func todo(s string, args ...interface{}) string { //TODO-
switch {
case s == "":
s = fmt.Sprintf(strings.Repeat("%v ", len(args)), args...)
default:
s = fmt.Sprintf(s, args...)
}
pc, fn, fl, _ := runtime.Caller(1)
f := runtime.FuncForPC(pc)
var fns string
if f != nil {
fns = f.Name()
if x := strings.LastIndex(fns, "."); x > 0 {
fns = fns[x+1:]
}
}
r := fmt.Sprintf("%s:%d:%s: TODOTODO %s", fn, fl, fns, s) //TODOOK
fmt.Fprintf(os.Stdout, "%s\n", r)
os.Stdout.Sync()
return r
}
func trc(s string, args ...interface{}) string { //TODO-
switch {
case s == "":
s = fmt.Sprintf(strings.Repeat("%v ", len(args)), args...)
default:
s = fmt.Sprintf(s, args...)
}
_, fn, fl, _ := runtime.Caller(1)
r := fmt.Sprintf("%s:%d: TRC %s", fn, fl, s)
fmt.Fprintf(os.Stdout, "%s\n", r)
os.Stdout.Sync()
return r
}
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:]
}
}
return fmt.Sprintf("%s:%d:%s", fn, fl, fns)
}
// String returns a StringID for a given value.
func String(s string) StringID {
return dict.sid(s)
}
// Linkage represents identifier linkage.
//
// [0]6.2.2: An identifier declared in different scopes or in the same scope
// more than once can be made to refer to the same object or function by a
// process called linkage. There are three kinds of linkage: External,
// Internal, and None.
type Linkage int
// StorageClass determines storage duration.
//
// [0]6.2.4: An object has a storage duration that determines its lifetime.
// There are three storage durations: Static, Automatic, and Allocated.
type StorageClass int
// Pragma defines behavior of the object passed to Config.PragmaHandler.
type Pragma interface {
Error(msg string, args ...interface{}) // Report error.
MaxAligment() int // Returns the current maximum alignment. May return zero.
MaxInitialAligment() int // Support #pragma pack(). Returns the maximum alignment in effect at start. May return zero.
PopMacro(string)
PushMacro(string)
SetAlignment(n int) // Support #pragma pack(n)
}
type pragma struct {
tok cppToken
c *cpp
}
func (p *pragma) Error(msg string, args ...interface{}) { p.c.err(p.tok, msg, args...) }
func (p *pragma) MaxAligment() int { return p.c.ctx.maxAlign }
func (p *pragma) MaxInitialAligment() int { return p.c.ctx.maxAlign0 }
func (p *pragma) SetAlignment(n int) {
if n <= 0 {
p.Error("%T.SetAlignment(%d): invalid argument", p, n)
return
}
p.c.ctx.maxAlign = n
}
func (p *pragma) PushMacro(nm string) {
id := dict.sid(nm)
if p.c.macroStack == nil {
p.c.macroStack = map[StringID][]*Macro{}
}
if m := p.c.macros[id]; m != nil {
p.c.macroStack[id] = append(p.c.macroStack[id], p.c.macros[id])
}
}
func (p *pragma) PopMacro(nm string) {
id := dict.sid(nm)
a := p.c.macroStack[id]
if n := len(a); n != 0 {
p.c.macros[id] = a[n-1]
p.c.macroStack[id] = a[:n-1]
}
}
// PrettyString returns a formatted representation of things produced by this package.
func PrettyString(v interface{}) string {
return strutil.PrettyString(v, "", "", printHooks)
}
// StringID is a process-unique string numeric identifier. Its zero value
// represents an empty string.
type StringID int32
// String implements fmt.Stringer.
func (n StringID) String() (r string) {
if n < 256 {
return dictStrings[byte(n)]
}
dict.mu.RLock()
r = dict.strings[n]
dict.mu.RUnlock()
return r
}
// Node is implemented by Token and all AST nodes.
type Node interface {
Position() token.Position
}
type noder struct{}
func (noder) Position() token.Position { panic(internalError()) }
// Scope maps identifiers to definitions.
type Scope map[StringID][]Node
func (s *Scope) new() (r Scope) {
if *s == nil {
*s = Scope{}
}
r = Scope{scopeParent: []Node{struct {
noder
Scope
}{Scope: *s}}}
return r
}
func (s *Scope) declare(nm StringID, n Node) {
sc := *s
if sc == nil {
*s = map[StringID][]Node{nm: {n}}
// t := ""
// if x, ok := n.(*Declarator); ok && x.IsTypedefName {
// t = ", typedefname"
// }
// dbg("declared %s%s at %v in scope %p", nm, t, n.Position(), *s)
return
}
switch x := n.(type) {
case *Declarator, *StructDeclarator, *LabeledStatement, *BlockItem:
// nop
case *StructOrUnionSpecifier, *EnumSpecifier, *Enumerator:
for {
if _, ok := sc[scopeSkip]; !ok {
break
}
sc = sc.Parent()
}
default:
panic(todo("%T", x))
}
sc[nm] = append(sc[nm], n)
// t := ""
// if x, ok := n.(*Declarator); ok && x.IsTypedefName {
// t = ", typedefname"
// }
// dbg("declared %s%s at %v in scope %p", nm, t, n.Position(), sc)
}
// Parent returns s's outer scope, if any.
func (s Scope) Parent() Scope {
if s == nil {
return nil
}
if x, ok := s[scopeParent]; ok {
return x[0].(struct {
noder
Scope
}).Scope
}
return nil
}
func (s *Scope) typedef(nm StringID, tok Token) *Declarator {
seq := tok.seq
for s := *s; s != nil; s = s.Parent() {
for _, v := range s[nm] {
switch x := v.(type) {
case *Declarator:
if !x.isVisible(seq) {
continue
}
if x.IsTypedefName {
return x
}
return nil
case *Enumerator:
return nil
case *EnumSpecifier, *StructOrUnionSpecifier, *StructDeclarator:
// nop
default:
panic(internalError())
}
}
}
return nil
}
func (s *Scope) declarator(nm StringID, tok Token) *Declarator {
seq := tok.seq
for s := *s; s != nil; s = s.Parent() {
defs := s[nm]
for _, v := range defs {
switch x := v.(type) {
case *Declarator:
if !x.isVisible(seq) {
continue
}
for _, v := range defs {
if x, ok := v.(*Declarator); ok {
t := x.Type()
if t != nil && t.Kind() == Function {
if x.fnDef {
return x
}
continue
}
if t != nil && !x.Type().IsIncomplete() {
return x
}
}
}
return x
case *Enumerator:
return nil
case *EnumSpecifier, *StructOrUnionSpecifier, *StructDeclarator:
// nop
default:
panic(internalError())
}
}
}
return nil
}
func (s *Scope) enumerator(nm StringID, tok Token) *Enumerator {
seq := tok.seq
for s := *s; s != nil; s = s.Parent() {
for _, v := range s[nm] {
switch x := v.(type) {
case *Declarator:
if !x.isVisible(seq) {
continue
}
return nil
case *Enumerator:
return x
case *EnumSpecifier, *StructOrUnionSpecifier, *StructDeclarator:
// nop
default:
panic(internalError())
}
}
}
return nil
}
// Config3 amends behavior of translation phases 1 to 3.
type Config3 struct {
// If IgnoreInclude is not nil, its MatchString method will be called by the
// preprocessor with the argument any include directive expands to. If the call
// evaluates to is true the include directive will be ignored completely.
IgnoreInclude *regexp.Regexp
// Name of a macro to use instead of FD_ZERO.
//
// Note: Temporary solution will be removed/replaced
ReplaceMacroFdZero string
// Name of a macro to use instead of TCL_DEFAULT_DOUBLE_ROUNDING.
//
// Note: Temporary solution will be removed/replaced
ReplaceMacroTclDefaultDoubleRounding string // Name of a macro to use instead of TCL_DEFAULT_DOUBLE_ROUNDING. Note: Temporrary solution will be removed/replaced
// Name of a macro to use instead of TCL_IEEE_DOUBLE_ROUNDING.
//
// Note: Temporary solution will be removed/replaced
ReplaceMacroTclIeeeDoubleRounding string
WorkingDir string // Overrides os.Getwd if non empty.
Filesystem Filesystem // Overrides filesystem access if not empty.
MaxSourceLine int // Zero: Scanner will use default buffer. Non zero: Scanner will use max(default buffer size, MaxSourceLine).
// DisableBuiltinResolution disables resolution of undefined identifiers such
// that eg. abort, becomes the same as __builtin_abort, prototype of which is
// expected to be provided by one of the sources passed to Parse, Preprocess or
// Translate.
DisableBuiltinResolution bool
DisableTrigraphs bool // GCC ignores them unless -trigraphs is used: https://gcc.gnu.org/onlinedocs/cpp/Initial-processing.html
GCCStructs bool // Assume __attribute__(gcc_struct) applied to structs by default.
//TODO MSStructs bool // Assume __attribute__(ms_struct) applied to structs by default.
NoFieldAndBitfieldOverlap bool // Only bitfields can be grouped together.
PreserveOnlyLastNonBlankSeparator bool // If PreserveWhiteSpace is true, keep only the last white space, do not combine
PreserveWhiteSpace bool // Including also comments.
RejectElseExtraTokens bool // Pedantic: do not silently accept "#else foo".
RejectEndifExtraTokens bool // Pedantic: do not silently accept "#endif foo".
RejectFinalBackslash bool // Pedantic: do not silently accept "foo\\\n".
RejectFunctionMacroEmptyReplacementList bool // Pedantic: do not silently accept "#define foo(bar)\n".
RejectIfdefExtraTokens bool // Pedantic: do not silently accept "#ifdef foo bar".
RejectIfndefExtraTokens bool // Pedantic: do not silently accept "#ifndef foo bar".
RejectIncludeNext bool // Pedantic: do not silently accept "#include_next".
RejectInvalidVariadicMacros bool // Pedantic: do not silently accept "#define foo(bar...)". Standard allows only #define foo(bar, ...)
RejectLineExtraTokens bool // Pedantic: do not silently accept "#line 1234 \"foo.c\" bar".
RejectMissingFinalNewline bool // Pedantic: do not silently accept "foo\nbar".
RejectUndefExtraTokens bool // Pedantic: do not silently accept "#undef foo bar".
UnsignedEnums bool // GCC compatibility: enums with no negative values will have unsigned type.
}
type SharedFunctionDefinitions struct {
M map[*FunctionDefinition]struct{}
m map[sharedFunctionDefinitionKey]*FunctionDefinition //TODO
hash maphash.Hash
}
type sharedFunctionDefinitionKey struct {
pos StringID
nm StringID
hash uint64
}
// Config amends behavior of translation phase 4 and above. Instances of Config
// are not mutated by this package and it's safe to share/reuse them.
//
// The *Config passed to Parse or Translate should not be mutated afterwards.
type Config struct {
Config3
ABI ABI
PragmaHandler func(Pragma, []Token) // Called on pragmas, other than #pragma STDC ..., if non nil
// SharedFunctionDefinitions collects function definitions having the
// same position and definition. This can happen, for example, when a
// function is defined in a header file included multiple times. Either
// within a single translation unit or across translation units. In the
// later case just supply the same SharedFunctionDefinitions in Config
// when translating/parsing each translation unit.
SharedFunctionDefinitions *SharedFunctionDefinitions
MaxErrors int // 0: default (10), < 0: unlimited, n: n.
CheckExternInlineFnBodies bool // Translate will consider extern inline function bodies.
DebugIncludePaths bool // Output to stderr.
DebugWorkingDir bool // Output to stderr.
DoNotTypecheckAsm bool
EnableAssignmentCompatibilityChecking bool // No such checks performed up to v3.31.0. Currently only partially implemented.
InjectTracingCode bool // Output to stderr.
LongDoubleIsDouble bool
PreprocessOnly bool
RejectAnonymousFields bool // Pedantic: do not silently accept "struct{int;}".
RejectCaseRange bool // Pedantic: do not silently accept "case 'a'...'z':".
RejectEmptyCompositeLiterals bool // Pedantic: do not silently accept "foo = (T){}".
RejectEmptyDeclarations bool // Pedantic: do not silently accept "int foo(){};".
RejectEmptyFields bool // Pedantic: do not silently accept "struct {int a;;} foo;".
RejectEmptyInitializerList bool // Pedantic: do not silently accept "foo f = {};".
RejectEmptyStructDeclaration bool // Pedantic: do not silently accept "struct{; int i}".
RejectEmptyStructs bool // Pedantic: do not silently accept "struct foo {};".
RejectIncompatibleMacroRedef bool // Pedantic: do not silently accept "#define MIN(A,B) ...\n#define MIN(a,b) ...\n" etc.
RejectLabelValues bool // Pedantic: do not silently accept "foo: bar(); void *ptr = &&foo;" or "goto *ptr".
RejectLateBinding bool // Pedantic: do not silently accept void f() { g(); } void g() {}
RejectMissingConditionalExpr bool // Pedantic: do not silently accept "foo = bar ? : baz;".
RejectMissingDeclarationSpecifiers bool // Pedantic: do not silently accept "main() {}".
RejectMissingFinalStructFieldSemicolon bool // Pedantic: do not silently accept "struct{int i; int j}".
RejectNestedFunctionDefinitions bool // Pedantic: do not silently accept nested function definitons.
RejectParamSemicolon bool // Pedantic: do not silently accept "int f(int a; int b)".
RejectStatementExpressions bool // Pedantic: do not silently accept "i = ({foo();})".
RejectTypeof bool // Pedantic: do not silently accept "typeof foo" or "typeof(bar*)".
RejectUninitializedDeclarators bool // Reject int f() { int j; return j; }
TrackAssignments bool // Collect a list of LHS declarators a declarator is used in RHS or as an function argument.
doNotSanityCheckComplexTypes bool // Testing only
fakeIncludes bool // Testing only.
ignoreErrors bool // Testing only.
ignoreIncludes bool // Testing only.
ignoreUndefinedIdentifiers bool // Testing only.
}
type context struct {
ast *AST
breakCtx Node
breaks int
casePromote Type
cases []*LabeledStatement // switch
cfg *Config
checkFn *FunctionDefinition
closure map[StringID]struct{}
continues int
enums map[StringID]Operand //TODO putting this in alphabetical order within the struct causes crashes in VirtualBox/386 ???
goscanner.ErrorList
includePaths []string
intBits int
intMaxWidth int64 // Set if the preprocessor saw __INTMAX_WIDTH__.
keywords map[StringID]rune
maxAlign int // If non zero: maximum alignment of members of structures (other than zero-width bitfields).
maxAlign0 int
maxErrors int
mode mode
modes []mode
mu sync.Mutex
ptrdiffT Type
readDelta int
sizeT Type
structTypes map[StringID]Type
structs map[StructInfo]struct{}
switches int
sysIncludePaths []string
tuSize0 int64 // Sum of sizes of processed inputs
tuSources0 int32 // Number of processed inputs
wcharT Type
capture bool
evalIdentError bool
}
func newContext(cfg *Config) *context {
maxErrors := cfg.MaxErrors
if maxErrors == 0 {
maxErrors = 10
}
return &context{
cfg: cfg,
enums: map[StringID]Operand{},
keywords: keywords,
maxErrors: maxErrors,
structTypes: map[StringID]Type{},
structs: map[StructInfo]struct{}{},
}
}
func (c *context) tuSizeAdd(n int64) { atomic.AddInt64(&c.tuSize0, n) }
func (c *context) tuSize() int64 { return atomic.LoadInt64(&c.tuSize0) }
func (c *context) tuSourcesAdd(n int32) { atomic.AddInt32(&c.tuSources0, n) }
func (c *context) tuSources() int { return int(atomic.LoadInt32(&c.tuSources0)) }
func (c *context) stddef(nm StringID, s Scope, tok Token) Type {
if d := s.typedef(nm, tok); d != nil {
if t := d.Type(); t != nil && t.Kind() != Invalid {
return t
}
}
c.errNode(&tok, "front-end: undefined: %s", nm)
return noType
}
func (c *context) assignmentCompatibilityErrorCond(n Node, a, b Type) (stop bool) {
if !c.cfg.EnableAssignmentCompatibilityChecking {
return
}
return c.errNode(n, "invalid type combination of conditional operator: %v and %v", a, b)
}
func (c *context) assignmentCompatibilityError(n Node, lhs, rhs Type) (stop bool) {
if !c.cfg.EnableAssignmentCompatibilityChecking {
return
}
return c.errNode(n, "cannot use %v as type %v in assignment", rhs, lhs)
}
func (c *context) errNode(n Node, msg string, args ...interface{}) (stop bool) {
return c.err(n.Position(), msg, args...)
}
func (c *context) err(pos token.Position, msg string, args ...interface{}) (stop bool) {
// dbg("FAIL "+msg, args...)
//fmt.Printf("FAIL "+msg+"\n", args...)
if c.cfg.ignoreErrors {
return false
}
s := fmt.Sprintf(msg, args...)
c.mu.Lock()
max := c.maxErrors
switch {
case max < 0 || max > len(c.ErrorList):
c.ErrorList.Add(gotoken.Position(pos), s)
default:
stop = true
}
c.mu.Unlock()
return stop
}
func (c *context) errs(list goscanner.ErrorList) (stop bool) {
c.mu.Lock()
defer c.mu.Unlock()
max := c.maxErrors
for _, v := range list {
switch {
case max < 0 || max > len(c.ErrorList):
c.ErrorList = append(c.ErrorList, v)
default:
return true
}
}
return false
}
func (c *context) Err() error {
c.mu.Lock()
switch x := c.ErrorList.Err().(type) {
case goscanner.ErrorList:
x = append(goscanner.ErrorList(nil), x...)
c.mu.Unlock()
var lpos gotoken.Position
w := 0
for _, v := range x {
if lpos.Filename != "" {
if v.Pos.Filename == lpos.Filename && v.Pos.Line == lpos.Line {
continue
}
}
x[w] = v
w++
lpos = v.Pos
}
x = x[:w]
sort.Slice(x, func(i, j int) bool {
a := x[i]
b := x[j]
if !a.Pos.IsValid() && b.Pos.IsValid() {
return true
}
if a.Pos.IsValid() && !b.Pos.IsValid() {
return false
}
if a.Pos.Filename < b.Pos.Filename {
return true
}
if a.Pos.Filename > b.Pos.Filename {
return false
}
if a.Pos.Line < b.Pos.Line {
return true
}
if a.Pos.Line > b.Pos.Line {
return false
}
return a.Pos.Column < b.Pos.Column
})
a := make([]string, 0, len(x))
for _, v := range x {
a = append(a, v.Error())
}
return fmt.Errorf("%s", strings.Join(a, "\n"))
default:
c.mu.Unlock()
return x
}
}
func (c *context) not(n Node, mode mode) {
if c.mode&mode != 0 {
switch mode {
case mIntConstExpr:
c.errNode(n, "invalid integer constant expression")
default:
panic(internalError())
}
}
}
func (c *context) push(mode mode) {
c.modes = append(c.modes, c.mode)
c.mode = mode
}
func (c *context) pop() {
n := len(c.modes)
c.mode = c.modes[n-1]
c.modes = c.modes[:n-1]
}
func (c *context) statFile(name string, sys bool) (os.FileInfo, error) {
fs := c.cfg.Config3.Filesystem
if fs == nil {
fs = LocalFS()
}
return fs.Stat(name, sys)
}
func (c *context) openFile(name string, sys bool) (io.ReadCloser, error) {
fs := c.cfg.Config3.Filesystem
if fs == nil {
fs = LocalFS()
}
return fs.Open(name, sys)
}
// HostConfig returns the system C preprocessor/compiler configuration, or an
// error, if any. The configuration is obtained by running the command named
// by the cpp argumnent or "cpp" when it's empty. For the predefined macros
// list the '-dM' options is added. For the include paths lists, the option
// '-v' is added and the output is parsed to extract the "..." include and
// <...> include paths. To add any other options to cpp, list them in opts.
//
// The function relies on a POSIX/GCC compatible C preprocessor installed.
// Execution of HostConfig is not free, so caching of the results is
// recommended.
func HostConfig(cpp string, opts ...string) (predefined string, includePaths, sysIncludePaths []string, err error) {
if cpp == "" {
cpp = "cpp"
}
args := append(append([]string{"-dM"}, opts...), os.DevNull)
pre, err := exec.Command(cpp, args...).Output()
if err != nil {
return "", nil, nil, err
}
args = append(append([]string{"-v"}, opts...), os.DevNull)
out, err := exec.Command(cpp, args...).CombinedOutput()
if err != nil {
return "", nil, nil, err
}
sep := "\n"
if env("GOOS", runtime.GOOS) == "windows" {
sep = "\r\n"
}
a := strings.Split(string(out), sep)
for i := 0; i < len(a); {
switch a[i] {
case "#include \"...\" search starts here:":
loop:
for i = i + 1; i < len(a); {
switch v := a[i]; {
case strings.HasPrefix(v, "#") || v == "End of search list.":
break loop
default:
includePaths = append(includePaths, strings.TrimSpace(v))
i++
}
}
case "#include <...> search starts here:":
for i = i + 1; i < len(a); {
switch v := a[i]; {
case strings.HasPrefix(v, "#") || v == "End of search list.":
return string(pre), includePaths, sysIncludePaths, nil
default:
sysIncludePaths = append(sysIncludePaths, strings.TrimSpace(v))
i++
}
}
default:
i++
}
}
return "", nil, nil, fmt.Errorf("failed parsing %s -v output", cpp)
}
func env(key, val string) string {
if s := os.Getenv(key); s != "" {
return s
}
return val
}
// Token is a grammar terminal.
type Token struct {
Rune rune // ';' or IDENTIFIER etc.
Sep StringID // If Config3.PreserveWhiteSpace is in effect: All preceding white space combined, including comments.
Value StringID // ";" or "foo" etc.
Src StringID
file *tokenFile
macro StringID
pos int32
seq int32
}
// Seq returns t's sequential number.
//
// Comparing positions as in 'before', 'after' is complicated as tokens in a
// translation unit usually come from more than one source file. Macro
// expansion further complicates that. The solution is sequentially numbering
// the tokens as they are finally seen by the parser, so the usual arithmetic
// '<', '>' operators can be used for that purpose.
func (t Token) Seq() int { return int(t.seq) }
// Macro returns the name of a macro that expanded to this token, if any.
func (t *Token) Macro() StringID { return t.macro }
// String implements fmt.Stringer.
func (t Token) String() string { return t.Value.String() }
// Position implements Node.
func (t *Token) Position() (r token.Position) {
if t.pos != 0 && t.file != nil {
r = t.file.PositionFor(token.Pos(t.pos), true)
}
return r
}
func tokStr(toks interface{}, sep string) string {
var b strings.Builder
switch x := toks.(type) {
case []token3:
for i, v := range x {
if i != 0 {
b.WriteString(sep)
}
b.WriteString(v.String())
}
case []token4:
for i, v := range x {
if i != 0 {
b.WriteString(sep)
}
b.WriteString(v.String())
}
case []cppToken:
for i, v := range x {
if i != 0 {
b.WriteString(sep)
}
b.WriteString(v.String())
}
case []Token:
for i, v := range x {
if i != 0 {
b.WriteString(sep)
}
b.WriteString(v.String())
}
default:
panic(internalError())
}
return b.String()
}
func internalError() int {
panic(fmt.Errorf("%v: internal error", origin(2)))
}
func internalErrorf(s string, args ...interface{}) int {
s = fmt.Sprintf(s, args)
panic(fmt.Errorf("%v: %s", origin(2), s))
}
func detectMingw(s string) bool {
return strings.Contains(s, "#define __MINGW")
}
func nodeSource(n ...Node) (r string) {
if len(n) == 0 {
return ""
}
var a []*Token
for _, v := range n {
Inspect(v, func(n Node, _ bool) bool {
if x, ok := n.(*Token); ok && x.Seq() != 0 {
a = append(a, x)
}
return true
})
}
sort.Slice(a, func(i, j int) bool {
return a[i].Seq() < a[j].Seq()
})
w := 0
seq := -1
for _, v := range a {
if n := v.Seq(); n != seq {
seq = n
a[w] = v
w++
}
}
a = a[:w]
var b strings.Builder
for _, v := range a {
b.WriteString(v.Sep.String())
b.WriteString(v.Src.String())
}
return b.String()
}

5105
vendor/modernc.org/cc/v3/check.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

3076
vendor/modernc.org/cc/v3/cpp.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

84
vendor/modernc.org/cc/v3/enum.go generated vendored Normal file
View File

@ -0,0 +1,84 @@
// Copyright 2019 The CC Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cc // import "modernc.org/cc/v3"
// Values of Kind
const (
Invalid Kind = iota
Array // T[]
Bool // _Bool
Char // char
ComplexChar // complex char
ComplexDouble // complex double
ComplexFloat // complex float
ComplexInt // complex int
ComplexLong // complex long
ComplexLongDouble // complex long double
ComplexLongLong // complex long long
ComplexShort // complex short
ComplexUInt // complex unsigned
ComplexULong // complex unsigned long
ComplexULongLong // complex unsigned long long
ComplexUShort // complex shor
Decimal128 // _Decimal128
Decimal32 // _Decimal32
Decimal64 // _Decimal64
Double // double
Enum // enum
Float // float
Float128 // _Float128
Float32 // _Float32
Float32x // _Float32x
Float64 // _Float64
Float64x // _Float64x
Function // function
Int // int
Int8 // __int8
Int16 // __int16
Int32 // __int32
Int64 // __int64
Int128 // __int128
Long // long
LongDouble // long double
LongLong // long long
Ptr // pointer
SChar // signed char
Short // short
Struct // struct
TypedefName // typedefname
UChar // unsigned char
UInt // unsigned
UInt8 // unsigned __int8
UInt16 // unsigned __int16
UInt32 // unsigned __int32
UInt64 // unsigned __int64
UInt128 // unsigned __int128
ULong // unsigned long
ULongLong // unsigned long long
UShort // unsigned short
Union // union
Void // void
Vector // vector
typeofExpr
typeofType
maxKind
)
// Values of Linkage
const (
None Linkage = iota
Internal
External
)
// Values of StorageClass
const (
Static StorageClass = iota
Automatic
Allocated
)

156
vendor/modernc.org/cc/v3/filesystem.go generated vendored Normal file
View File

@ -0,0 +1,156 @@
// Copyright 2019 The CC Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cc
import (
"io"
"io/ioutil"
"os"
"path"
"strings"
"time"
)
// Filesystem abstraction used in CC. The underlying value must be comparable (e.g. pointer) to be used in map keys.
type Filesystem interface {
// Stat is an analog of os.Stat, but also accepts a flag to indicate a system include (<file.h>).
Stat(path string, sys bool) (os.FileInfo, error)
// Open is an analog of os.Open, but also accepts a flag to indicate a system include (<file.h>).
Open(path string, sys bool) (io.ReadCloser, error)
}
// LocalFS returns a local filesystem implementation.
func LocalFS() Filesystem {
return localFS{}
}
type localFS struct{}
// Stat implements Filesystem.
func (localFS) Stat(path string, sys bool) (os.FileInfo, error) {
return os.Stat(path)
}
// Open implements Filesystem.
func (localFS) Open(path string, sys bool) (io.ReadCloser, error) {
return os.Open(path)
}
// WorkingDir is a filesystem implementation that resolves paths relative to a given directory.
// If filesystem is not specified, the local one will be used.
func WorkingDir(wd string, fs Filesystem) Filesystem {
if fs == nil {
fs = LocalFS()
}
return workDir{fs: fs, wd: wd}
}
type workDir struct {
fs Filesystem
wd string
}
// Stat implements Filesystem.
func (fs workDir) Stat(fname string, sys bool) (os.FileInfo, error) {
if !path.IsAbs(fname) {
fname = path.Join(fs.wd, fname)
}
return fs.fs.Stat(fname, sys)
}
// Open implements Filesystem.
func (fs workDir) Open(fname string, sys bool) (io.ReadCloser, error) {
if !path.IsAbs(fname) {
fname = path.Join(fs.wd, fname)
}
return fs.fs.Open(fname, sys)
}
// Overlay is a filesystem implementation that first check if the file is available in the primary FS
// and if not, falls back to a secondary FS.
func Overlay(pri, sec Filesystem) Filesystem {
return overlayFS{pri: pri, sec: sec}
}
type overlayFS struct {
pri, sec Filesystem
}
// Stat implements Filesystem.
func (fs overlayFS) Stat(path string, sys bool) (os.FileInfo, error) {
st, err := fs.pri.Stat(path, sys)
if err == nil || !os.IsNotExist(err) {
return st, err
}
return fs.sec.Stat(path, sys)
}
// Open implements Filesystem.
func (fs overlayFS) Open(path string, sys bool) (io.ReadCloser, error) {
f, err := fs.pri.Open(path, sys)
if err == nil || !os.IsNotExist(err) {
return f, err
}
return fs.sec.Open(path, sys)
}
// StaticFS implements filesystem interface by serving string values form the provided map.
func StaticFS(files map[string]string) Filesystem {
return &staticFS{m: files, ts: time.Now()}
}
type staticFS struct {
ts time.Time
m map[string]string
}
// Stat implements Filesystem.
func (fs *staticFS) Stat(path string, sys bool) (os.FileInfo, error) {
v, ok := fs.m[path]
if !ok {
return nil, &os.PathError{"stat", path, os.ErrNotExist}
}
return staticFileInfo{name: path, size: int64(len(v)), mode: 0, mod: fs.ts}, nil
}
// Open implements Filesystem.
func (fs *staticFS) Open(path string, sys bool) (io.ReadCloser, error) {
v, ok := fs.m[path]
if !ok {
return nil, &os.PathError{"open", path, os.ErrNotExist}
}
return ioutil.NopCloser(strings.NewReader(v)), nil
}
type staticFileInfo struct {
name string
size int64
mode os.FileMode
mod time.Time
}
func (fi staticFileInfo) Name() string {
return fi.name
}
func (fi staticFileInfo) Size() int64 {
return fi.size
}
func (fi staticFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi staticFileInfo) ModTime() time.Time {
return fi.mod
}
func (fi staticFileInfo) IsDir() bool {
return fi.mode.IsDir()
}
func (fi staticFileInfo) Sys() interface{} {
return fi
}

12
vendor/modernc.org/cc/v3/go.mod generated vendored Normal file
View File

@ -0,0 +1,12 @@
module modernc.org/cc/v3
go 1.15
require (
github.com/dustin/go-humanize v1.0.0
github.com/google/go-cmp v0.5.3
lukechampine.com/uint128 v1.1.1
modernc.org/mathutil v1.4.0
modernc.org/strutil v1.1.1
modernc.org/token v1.0.0
)

17
vendor/modernc.org/cc/v3/go.sum generated vendored Normal file
View File

@ -0,0 +1,17 @@
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/google/go-cmp v0.5.3 h1:x95R7cp+rSeeqAMI2knLtQ0DKlaBhv2NrtrOvafPHRo=
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
lukechampine.com/uint128 v1.1.1 h1:pnxCASz787iMf+02ssImqk6OLt+Z5QHMoZyUXR4z6JU=
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/mathutil v1.4.0 h1:GCjoRaBew8ECCKINQA2nYjzvufFW9YiEuuB+rQ9bn2E=
modernc.org/mathutil v1.4.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/strutil v1.1.1 h1:xv+J1BXY3Opl2ALrBwyfEikFAj8pmqcpnfmuwUwcozs=
modernc.org/strutil v1.1.1/go.mod h1:DE+MQQ/hjKBZS2zNInV5hhcipt5rLPWkmpbGeW5mmdw=
modernc.org/token v1.0.0 h1:a0jaWiNMDhDUtqOj09wvjWWAqd3q7WpBulmL9H2egsk=
modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=

632
vendor/modernc.org/cc/v3/inspect.go generated vendored Normal file
View File

@ -0,0 +1,632 @@
// Copyright 2020 The CC Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cc // import "modernc.org/cc/v3"
// Inspect inspects AST node trees.
//
// If n is a non-terminal node, f(n, true) is called first. Next, f is called
// recursively for each of n's non-nil non-terminal children nodes, if any, in
// alphabetical order. Next, all n's terminal nodes, if any, are visited in
// the numeric order of their suffixes (Token, Token2, Token3, ...). Finally,
// f(n, false) is invoked.
//
// If n a terminal node, of type *Token, f(n, <unspecified boolean value> is
// called once.
//
// Inspect stops when any invocation of f returns false.
func Inspect(n Node, f func(Node, bool) bool) {
see(n, f)
}
func see(n Node, f func(Node, bool) bool) bool {
switch x := n.(type) {
case *AbstractDeclarator:
return x == nil || f(x, true) &&
see(x.DirectAbstractDeclarator, f) &&
see(x.Pointer, f) &&
f(x, false)
case *AdditiveExpression:
return x == nil || f(x, true) &&
see(x.AdditiveExpression, f) &&
see(x.MultiplicativeExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *AlignmentSpecifier:
return x == nil || f(x, true) &&
see(x.ConstantExpression, f) &&
see(x.TypeName, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *AndExpression:
return x == nil || f(x, true) &&
see(x.AndExpression, f) &&
see(x.EqualityExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *ArgumentExpressionList:
return x == nil || f(x, true) &&
see(x.ArgumentExpressionList, f) &&
see(x.AssignmentExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *Asm:
return x == nil || f(x, true) &&
see(x.AsmArgList, f) &&
see(x.AsmQualifierList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
see(&x.Token4, f) &&
f(x, false)
case *AsmArgList:
return x == nil || f(x, true) &&
see(x.AsmArgList, f) &&
see(x.AsmExpressionList, f) &&
see(&x.Token, f) &&
f(x, false)
case *AsmExpressionList:
return x == nil || f(x, true) &&
see(x.AsmExpressionList, f) &&
see(x.AsmIndex, f) &&
see(x.AssignmentExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *AsmFunctionDefinition:
return x == nil || f(x, true) &&
see(x.AsmStatement, f) &&
see(x.DeclarationSpecifiers, f) &&
see(x.Declarator, f) &&
f(x, false)
case *AsmIndex:
return x == nil || f(x, true) &&
see(x.Expression, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *AsmQualifier:
return x == nil || f(x, true) &&
see(&x.Token, f) &&
f(x, false)
case *AsmQualifierList:
return x == nil || f(x, true) &&
see(x.AsmQualifier, f) &&
see(x.AsmQualifierList, f) &&
f(x, false)
case *AsmStatement:
return x == nil || f(x, true) &&
see(x.Asm, f) &&
see(x.AttributeSpecifierList, f) &&
see(&x.Token, f) &&
f(x, false)
case *AssignmentExpression:
return x == nil || f(x, true) &&
see(x.AssignmentExpression, f) &&
see(x.ConditionalExpression, f) &&
see(x.UnaryExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *AtomicTypeSpecifier:
return x == nil || f(x, true) &&
see(x.TypeName, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *AttributeSpecifier:
return x == nil || f(x, true) &&
see(x.AttributeValueList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
see(&x.Token4, f) &&
see(&x.Token5, f) &&
f(x, false)
case *AttributeSpecifierList:
return x == nil || f(x, true) &&
see(x.AttributeSpecifier, f) &&
see(x.AttributeSpecifierList, f) &&
f(x, false)
case *AttributeValue:
return x == nil || f(x, true) &&
see(x.ExpressionList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *AttributeValueList:
return x == nil || f(x, true) &&
see(x.AttributeValue, f) &&
see(x.AttributeValueList, f) &&
see(&x.Token, f) &&
f(x, false)
case *BlockItem:
return x == nil || f(x, true) &&
see(x.CompoundStatement, f) &&
see(x.Declaration, f) &&
see(x.DeclarationSpecifiers, f) &&
see(x.Declarator, f) &&
see(x.LabelDeclaration, f) &&
see(x.PragmaSTDC, f) &&
see(x.Statement, f) &&
f(x, false)
case *BlockItemList:
return x == nil || f(x, true) &&
see(x.BlockItem, f) &&
see(x.BlockItemList, f) &&
f(x, false)
case *CastExpression:
return x == nil || f(x, true) &&
see(x.CastExpression, f) &&
see(x.TypeName, f) &&
see(x.UnaryExpression, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *CompoundStatement:
return x == nil || f(x, true) &&
see(x.BlockItemList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *ConditionalExpression:
return x == nil || f(x, true) &&
see(x.ConditionalExpression, f) &&
see(x.Expression, f) &&
see(x.LogicalOrExpression, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *ConstantExpression:
return x == nil || f(x, true) &&
see(x.ConditionalExpression, f) &&
f(x, false)
case *Declaration:
return x == nil || f(x, true) &&
see(x.DeclarationSpecifiers, f) &&
see(x.InitDeclaratorList, f) &&
see(&x.Token, f) &&
f(x, false)
case *DeclarationList:
return x == nil || f(x, true) &&
see(x.Declaration, f) &&
see(x.DeclarationList, f) &&
f(x, false)
case *DeclarationSpecifiers:
return x == nil || f(x, true) &&
see(x.AlignmentSpecifier, f) &&
see(x.AttributeSpecifier, f) &&
see(x.DeclarationSpecifiers, f) &&
see(x.FunctionSpecifier, f) &&
see(x.StorageClassSpecifier, f) &&
see(x.TypeQualifier, f) &&
see(x.TypeSpecifier, f) &&
f(x, false)
case *Declarator:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.DirectDeclarator, f) &&
see(x.Pointer, f) &&
f(x, false)
case *Designation:
return x == nil || f(x, true) &&
see(x.DesignatorList, f) &&
see(&x.Token, f) &&
f(x, false)
case *Designator:
return x == nil || f(x, true) &&
see(x.ConstantExpression, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *DesignatorList:
return x == nil || f(x, true) &&
see(x.Designator, f) &&
see(x.DesignatorList, f) &&
f(x, false)
case *DirectAbstractDeclarator:
return x == nil || f(x, true) &&
see(x.AbstractDeclarator, f) &&
see(x.AssignmentExpression, f) &&
see(x.DirectAbstractDeclarator, f) &&
see(x.ParameterTypeList, f) &&
see(x.TypeQualifiers, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *DirectDeclarator:
return x == nil || f(x, true) &&
see(x.Asm, f) &&
see(x.AssignmentExpression, f) &&
see(x.AttributeSpecifierList, f) &&
see(x.Declarator, f) &&
see(x.DirectDeclarator, f) &&
see(x.IdentifierList, f) &&
see(x.ParameterTypeList, f) &&
see(x.TypeQualifiers, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *EnumSpecifier:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.EnumeratorList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
see(&x.Token4, f) &&
see(&x.Token5, f) &&
f(x, false)
case *Enumerator:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.ConstantExpression, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *EnumeratorList:
return x == nil || f(x, true) &&
see(x.Enumerator, f) &&
see(x.EnumeratorList, f) &&
see(&x.Token, f) &&
f(x, false)
case *EqualityExpression:
return x == nil || f(x, true) &&
see(x.EqualityExpression, f) &&
see(x.RelationalExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *ExclusiveOrExpression:
return x == nil || f(x, true) &&
see(x.AndExpression, f) &&
see(x.ExclusiveOrExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *Expression:
return x == nil || f(x, true) &&
see(x.AssignmentExpression, f) &&
see(x.Expression, f) &&
see(&x.Token, f) &&
f(x, false)
case *ExpressionList:
return x == nil || f(x, true) &&
see(x.AssignmentExpression, f) &&
see(x.ExpressionList, f) &&
see(&x.Token, f) &&
f(x, false)
case *ExpressionStatement:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.Expression, f) &&
see(&x.Token, f) &&
f(x, false)
case *ExternalDeclaration:
return x == nil || f(x, true) &&
see(x.AsmFunctionDefinition, f) &&
see(x.AsmStatement, f) &&
see(x.Declaration, f) &&
see(x.FunctionDefinition, f) &&
see(x.PragmaSTDC, f) &&
see(&x.Token, f) &&
f(x, false)
case *FunctionDefinition:
return x == nil || f(x, true) &&
see(x.CompoundStatement, f) &&
see(x.DeclarationList, f) &&
see(x.DeclarationSpecifiers, f) &&
see(x.Declarator, f) &&
f(x, false)
case *FunctionSpecifier:
return x == nil || f(x, true) &&
see(&x.Token, f) &&
f(x, false)
case *IdentifierList:
return x == nil || f(x, true) &&
see(x.IdentifierList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *InclusiveOrExpression:
return x == nil || f(x, true) &&
see(x.ExclusiveOrExpression, f) &&
see(x.InclusiveOrExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *InitDeclarator:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.Declarator, f) &&
see(x.Initializer, f) &&
see(&x.Token, f) &&
f(x, false)
case *InitDeclaratorList:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.InitDeclarator, f) &&
see(x.InitDeclaratorList, f) &&
see(&x.Token, f) &&
f(x, false)
case *Initializer:
return x == nil || f(x, true) &&
see(x.AssignmentExpression, f) &&
see(x.InitializerList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *InitializerList:
return x == nil || f(x, true) &&
see(x.Designation, f) &&
see(x.Initializer, f) &&
see(x.InitializerList, f) &&
see(&x.Token, f) &&
f(x, false)
case *IterationStatement:
return x == nil || f(x, true) &&
see(x.Declaration, f) &&
see(x.Expression, f) &&
see(x.Expression2, f) &&
see(x.Expression3, f) &&
see(x.Statement, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
see(&x.Token4, f) &&
see(&x.Token5, f) &&
f(x, false)
case *JumpStatement:
return x == nil || f(x, true) &&
see(x.Expression, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *LabelDeclaration:
return x == nil || f(x, true) &&
see(x.IdentifierList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *LabeledStatement:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.ConstantExpression, f) &&
see(x.ConstantExpression2, f) &&
see(x.Statement, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *LogicalAndExpression:
return x == nil || f(x, true) &&
see(x.InclusiveOrExpression, f) &&
see(x.LogicalAndExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *LogicalOrExpression:
return x == nil || f(x, true) &&
see(x.LogicalAndExpression, f) &&
see(x.LogicalOrExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *MultiplicativeExpression:
return x == nil || f(x, true) &&
see(x.CastExpression, f) &&
see(x.MultiplicativeExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *ParameterDeclaration:
return x == nil || f(x, true) &&
see(x.AbstractDeclarator, f) &&
see(x.AttributeSpecifierList, f) &&
see(x.DeclarationSpecifiers, f) &&
see(x.Declarator, f) &&
f(x, false)
case *ParameterList:
return x == nil || f(x, true) &&
see(x.ParameterDeclaration, f) &&
see(x.ParameterList, f) &&
see(&x.Token, f) &&
f(x, false)
case *ParameterTypeList:
return x == nil || f(x, true) &&
see(x.ParameterList, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *Pointer:
return x == nil || f(x, true) &&
see(x.Pointer, f) &&
see(x.TypeQualifiers, f) &&
see(&x.Token, f) &&
f(x, false)
case *PostfixExpression:
return x == nil || f(x, true) &&
see(x.ArgumentExpressionList, f) &&
see(x.Expression, f) &&
see(x.InitializerList, f) &&
see(x.PostfixExpression, f) &&
see(x.PrimaryExpression, f) &&
see(x.TypeName, f) &&
see(x.TypeName2, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
see(&x.Token4, f) &&
see(&x.Token5, f) &&
f(x, false)
case *PragmaSTDC:
return x == nil || f(x, true) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
see(&x.Token4, f) &&
f(x, false)
case *PrimaryExpression:
return x == nil || f(x, true) &&
see(x.CompoundStatement, f) &&
see(x.Expression, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
f(x, false)
case *RelationalExpression:
return x == nil || f(x, true) &&
see(x.RelationalExpression, f) &&
see(x.ShiftExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *SelectionStatement:
return x == nil || f(x, true) &&
see(x.Expression, f) &&
see(x.Statement, f) &&
see(x.Statement2, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
see(&x.Token4, f) &&
f(x, false)
case *ShiftExpression:
return x == nil || f(x, true) &&
see(x.AdditiveExpression, f) &&
see(x.ShiftExpression, f) &&
see(&x.Token, f) &&
f(x, false)
case *SpecifierQualifierList:
return x == nil || f(x, true) &&
see(x.AlignmentSpecifier, f) &&
see(x.AttributeSpecifier, f) &&
see(x.SpecifierQualifierList, f) &&
see(x.TypeQualifier, f) &&
see(x.TypeSpecifier, f) &&
f(x, false)
case *Statement:
return x == nil || f(x, true) &&
see(x.AsmStatement, f) &&
see(x.CompoundStatement, f) &&
see(x.ExpressionStatement, f) &&
see(x.IterationStatement, f) &&
see(x.JumpStatement, f) &&
see(x.LabeledStatement, f) &&
see(x.SelectionStatement, f) &&
f(x, false)
case *StorageClassSpecifier:
return x == nil || f(x, true) &&
see(&x.Token, f) &&
f(x, false)
case *StructDeclaration:
return x == nil || f(x, true) &&
see(x.SpecifierQualifierList, f) &&
see(x.StructDeclaratorList, f) &&
see(&x.Token, f) &&
f(x, false)
case *StructDeclarationList:
return x == nil || f(x, true) &&
see(x.StructDeclaration, f) &&
see(x.StructDeclarationList, f) &&
f(x, false)
case *StructDeclarator:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.ConstantExpression, f) &&
see(x.Declarator, f) &&
see(&x.Token, f) &&
f(x, false)
case *StructDeclaratorList:
return x == nil || f(x, true) &&
see(x.StructDeclarator, f) &&
see(x.StructDeclaratorList, f) &&
see(&x.Token, f) &&
f(x, false)
case *StructOrUnion:
return x == nil || f(x, true) &&
see(&x.Token, f) &&
f(x, false)
case *StructOrUnionSpecifier:
return x == nil || f(x, true) &&
see(x.AttributeSpecifierList, f) &&
see(x.StructDeclarationList, f) &&
see(x.StructOrUnion, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *TranslationUnit:
return x == nil || f(x, true) &&
see(x.ExternalDeclaration, f) &&
see(x.TranslationUnit, f) &&
f(x, false)
case *TypeName:
return x == nil || f(x, true) &&
see(x.AbstractDeclarator, f) &&
see(x.SpecifierQualifierList, f) &&
f(x, false)
case *TypeQualifier:
return x == nil || f(x, true) &&
see(&x.Token, f) &&
f(x, false)
case *TypeQualifiers:
return x == nil || f(x, true) &&
see(x.AttributeSpecifier, f) &&
see(x.TypeQualifier, f) &&
see(x.TypeQualifiers, f) &&
f(x, false)
case *TypeSpecifier:
return x == nil || f(x, true) &&
see(x.AtomicTypeSpecifier, f) &&
see(x.EnumSpecifier, f) &&
see(x.Expression, f) &&
see(x.StructOrUnionSpecifier, f) &&
see(x.TypeName, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *UnaryExpression:
return x == nil || f(x, true) &&
see(x.CastExpression, f) &&
see(x.PostfixExpression, f) &&
see(x.TypeName, f) &&
see(x.UnaryExpression, f) &&
see(&x.Token, f) &&
see(&x.Token2, f) &&
see(&x.Token2, f) &&
see(&x.Token3, f) &&
f(x, false)
case *Token:
return f(x, true)
default:
panic(todo("internal error: %T", x))
}
}

1555
vendor/modernc.org/cc/v3/lexer.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

97
vendor/modernc.org/cc/v3/lexer.l generated vendored Normal file
View File

@ -0,0 +1,97 @@
%{
// Copyright 2019 The CC Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
%}
%yyc c
%yyn c = s.next()
%yym s.mark = len(s.charBuf)
%{
package cc // import "modernc.org/cc/v3"
func (s *scanner) scan() (r rune) {
%}
c-char [^'\n\x80\\]|{escape-sequence}
c-char-sequence {c-char}+
character-constant '{c-char-sequence}'
comment "/*"([^*\x80]|\*+[^*/\x80])*\*+\/
comment-not-terminated "/*"([^*\x80]|\*+[^*/\x80])*(\*+)?\n\x80
digit [0-9]
escape-sequence {simple-sequence}|{octal-escape-sequence}|{hexadecimal-escape-sequence}|{universal-character-name}
hex-quad {hexadecimal-digit}{hexadecimal-digit}{hexadecimal-digit}{hexadecimal-digit}
hexadecimal-digit [0-9a-fA-F]
hexadecimal-escape-sequence \\x{hexadecimal-digit}+
identifier {identifier-nondigit}({identifier-nondigit}|{digit}|"$")*
identifier-nondigit {nondigit}|"$"|{universal-character-name}
line-comment "//"[^\n\x80]*
nondigit [_a-zA-Z\x81]
octal-digit [0-7]
octal-escape-sequence \\{octal-digit}{octal-digit}?{octal-digit}?
pp-number ({digit}|\.{digit})({digit}|{identifier-nondigit}|[eEpP]{sign}|\.)*
s-char [^\x22\n\x80\\]|{escape-sequence}
s-char-sequence {s-char}+
sign [-+]
simple-sequence \\['\x22?\\abfnrtv]
string-literal \x22{s-char-sequence}?\x22
universal-character-name \\u{hex-quad}|\\U{hex-quad}{hex-quad}
white-space [ \t\f\v]
%%
c := s.initScan()
({white-space}|{comment})*{line-comment} |
({white-space}|{comment})+{line-comment}?
return ' '
(({white-space}|{comment})*{comment-not-terminated})+
return s.unterminatedComment()
"!=" return NEQ
"##" return PPPASTE
"%:" return '#'
"%:%:" return PPPASTE
"%=" return MODASSIGN
"%>" return '}'
"&&" return ANDAND
"&=" return ANDASSIGN
"*=" return MULASSIGN
"++" return INC
"+=" return ADDASSIGN
"--" return DEC
"-=" return SUBASSIGN
"->" return ARROW
"..." return DDD
"/=" return DIVASSIGN
":>" return ']'
"<%" return '{'
"<:" return '['
"<<" return LSH
"<<=" return LSHASSIGN
"<=" return LEQ
"==" return EQ
">=" return GEQ
">>" return RSH
">>=" return RSHASSIGN
"^=" return XORASSIGN
"|=" return ORASSIGN
"||" return OROR
L{string-literal} return LONGSTRINGLITERAL
L{character-constant} return LONGCHARCONST
{character-constant} return CHARCONST
{identifier} return IDENTIFIER
{pp-number} return PPNUMBER
{string-literal} return STRINGLITERAL
\r?\n return '\n'
%%
if c, ok := s.abort(); ok {
return rune(c)
}
goto yyAction
}

1337
vendor/modernc.org/cc/v3/operand.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

4278
vendor/modernc.org/cc/v3/parser.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

1029
vendor/modernc.org/cc/v3/parser.yy generated vendored Normal file

File diff suppressed because it is too large Load Diff

1269
vendor/modernc.org/cc/v3/scanner.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

99
vendor/modernc.org/cc/v3/stringer.go generated vendored Normal file
View File

@ -0,0 +1,99 @@
// Code generated by "stringer -output stringer.go -linecomment -type=Kind,Linkage"; DO NOT EDIT.
package cc
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[Invalid-0]
_ = x[Array-1]
_ = x[Bool-2]
_ = x[Char-3]
_ = x[ComplexChar-4]
_ = x[ComplexDouble-5]
_ = x[ComplexFloat-6]
_ = x[ComplexInt-7]
_ = x[ComplexLong-8]
_ = x[ComplexLongDouble-9]
_ = x[ComplexLongLong-10]
_ = x[ComplexShort-11]
_ = x[ComplexUInt-12]
_ = x[ComplexULong-13]
_ = x[ComplexULongLong-14]
_ = x[ComplexUShort-15]
_ = x[Decimal128-16]
_ = x[Decimal32-17]
_ = x[Decimal64-18]
_ = x[Double-19]
_ = x[Enum-20]
_ = x[Float-21]
_ = x[Float128-22]
_ = x[Float32-23]
_ = x[Float32x-24]
_ = x[Float64-25]
_ = x[Float64x-26]
_ = x[Function-27]
_ = x[Int-28]
_ = x[Int8-29]
_ = x[Int16-30]
_ = x[Int32-31]
_ = x[Int64-32]
_ = x[Int128-33]
_ = x[Long-34]
_ = x[LongDouble-35]
_ = x[LongLong-36]
_ = x[Ptr-37]
_ = x[SChar-38]
_ = x[Short-39]
_ = x[Struct-40]
_ = x[TypedefName-41]
_ = x[UChar-42]
_ = x[UInt-43]
_ = x[UInt8-44]
_ = x[UInt16-45]
_ = x[UInt32-46]
_ = x[UInt64-47]
_ = x[UInt128-48]
_ = x[ULong-49]
_ = x[ULongLong-50]
_ = x[UShort-51]
_ = x[Union-52]
_ = x[Void-53]
_ = x[Vector-54]
_ = x[typeofExpr-55]
_ = x[typeofType-56]
_ = x[maxKind-57]
}
const _Kind_name = "InvalidT[]_Boolcharcomplex charcomplex doublecomplex floatcomplex intcomplex longcomplex long doublecomplex long longcomplex shortcomplex unsignedcomplex unsigned longcomplex unsigned long longcomplex shor_Decimal128_Decimal32_Decimal64doubleenumfloat_Float128_Float32_Float32x_Float64_Float64xfunctionint__int8__int16__int32__int64__int128longlong doublelong longpointersigned charshortstructtypedefnameunsigned charunsignedunsigned __int8unsigned __int16unsigned __int32unsigned __int64unsigned __int128unsigned longunsigned long longunsigned shortunionvoidvectortypeofExprtypeofTypemaxKind"
var _Kind_index = [...]uint16{0, 7, 10, 15, 19, 31, 45, 58, 69, 81, 100, 117, 130, 146, 167, 193, 205, 216, 226, 236, 242, 246, 251, 260, 268, 277, 285, 294, 302, 305, 311, 318, 325, 332, 340, 344, 355, 364, 371, 382, 387, 393, 404, 417, 425, 440, 456, 472, 488, 505, 518, 536, 550, 555, 559, 565, 575, 585, 592}
func (i Kind) String() string {
if i >= Kind(len(_Kind_index)-1) {
return "Kind(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Kind_name[_Kind_index[i]:_Kind_index[i+1]]
}
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[None-0]
_ = x[Internal-1]
_ = x[External-2]
}
const _Linkage_name = "NoneInternalExternal"
var _Linkage_index = [...]uint8{0, 4, 12, 20}
func (i Linkage) String() string {
if i < 0 || i >= Linkage(len(_Linkage_index)-1) {
return "Linkage(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Linkage_name[_Linkage_index[i]:_Linkage_index[i+1]]
}

3271
vendor/modernc.org/cc/v3/type.go generated vendored Normal file

File diff suppressed because it is too large Load Diff

4
vendor/modernc.org/cc/v3/unconvert.sh generated vendored Normal file
View File

@ -0,0 +1,4 @@
until unconvert -fastmath . &> /dev/null
do
unconvert -fastmath -apply . &> /dev/null
done