package gcimporter
import (
"fmt"
"go/token"
"go/types"
"internal/pkgbits"
"sync"
)
func assert(b bool ) {
if !b {
panic ("assertion failed" )
}
}
func errorf(format string , args ...any ) {
panic (fmt .Sprintf (format , args ...))
}
const deltaNewFile = -64
type fakeFileSet struct {
fset *token .FileSet
files map [string ]*fileInfo
}
type fileInfo struct {
file *token .File
lastline int
}
const maxlines = 64 * 1024
func (s *fakeFileSet ) pos (file string , line , column int ) token .Pos {
f := s .files [file ]
if f == nil {
f = &fileInfo {file : s .fset .AddFile (file , -1 , maxlines )}
s .files [file ] = f
}
if line > maxlines {
line = 1
}
if line > f .lastline {
f .lastline = line
}
return token .Pos (f .file .Base () + line - 1 )
}
func (s *fakeFileSet ) setLines () {
fakeLinesOnce .Do (func () {
fakeLines = make ([]int , maxlines )
for i := range fakeLines {
fakeLines [i ] = i
}
})
for _ , f := range s .files {
f .file .SetLines (fakeLines [:f .lastline ])
}
}
var (
fakeLines []int
fakeLinesOnce sync .Once
)
func chanDir(d int ) types .ChanDir {
switch d {
case 1 :
return types .RecvOnly
case 2 :
return types .SendOnly
case 3 :
return types .SendRecv
default :
errorf ("unexpected channel dir %d" , d )
return 0
}
}
var predeclared = []types .Type {
types .Typ [types .Bool ],
types .Typ [types .Int ],
types .Typ [types .Int8 ],
types .Typ [types .Int16 ],
types .Typ [types .Int32 ],
types .Typ [types .Int64 ],
types .Typ [types .Uint ],
types .Typ [types .Uint8 ],
types .Typ [types .Uint16 ],
types .Typ [types .Uint32 ],
types .Typ [types .Uint64 ],
types .Typ [types .Uintptr ],
types .Typ [types .Float32 ],
types .Typ [types .Float64 ],
types .Typ [types .Complex64 ],
types .Typ [types .Complex128 ],
types .Typ [types .String ],
types .Universe .Lookup ("byte" ).Type (),
types .Universe .Lookup ("rune" ).Type (),
types .Universe .Lookup ("error" ).Type (),
types .Typ [types .UntypedBool ],
types .Typ [types .UntypedInt ],
types .Typ [types .UntypedRune ],
types .Typ [types .UntypedFloat ],
types .Typ [types .UntypedComplex ],
types .Typ [types .UntypedString ],
types .Typ [types .UntypedNil ],
types .Typ [types .UnsafePointer ],
types .Typ [types .Invalid ],
anyType {},
types .Universe .Lookup ("comparable" ).Type (),
}
type anyType struct {}
func (t anyType ) Underlying () types .Type { return t }
func (t anyType ) String () string { return "any" }
type derivedInfo struct {
idx pkgbits .Index
needed bool
}
type typeInfo struct {
idx pkgbits .Index
derived bool
}
func splitVargenSuffix(name string ) (base , suffix string ) {
i := len (name )
for i > 0 && name [i -1 ] >= '0' && name [i -1 ] <= '9' {
i --
}
const dot = "ยท"
if i >= len (dot ) && name [i -len (dot ):i ] == dot {
i -= len (dot )
return name [:i ], name [i :]
}
return name , ""
}
The pages are generated with Golds v0.7.0-preview . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .