2020-08-15 19:13:07 +02:00
|
|
|
// Copyright 2020 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-01-28 17:56:38 +01:00
|
|
|
// Package typesinternal provides access to internal go/types APIs that are not
|
|
|
|
// yet exported.
|
2020-08-15 19:13:07 +02:00
|
|
|
package typesinternal
|
|
|
|
|
|
|
|
import (
|
2021-01-28 17:56:38 +01:00
|
|
|
"go/token"
|
2020-08-15 19:13:07 +02:00
|
|
|
"go/types"
|
|
|
|
"reflect"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetUsesCgo(conf *types.Config) bool {
|
|
|
|
v := reflect.ValueOf(conf).Elem()
|
|
|
|
|
|
|
|
f := v.FieldByName("go115UsesCgo")
|
|
|
|
if !f.IsValid() {
|
|
|
|
f = v.FieldByName("UsesCgo")
|
|
|
|
if !f.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addr := unsafe.Pointer(f.UnsafeAddr())
|
|
|
|
*(*bool)(addr) = true
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
2021-01-28 17:56:38 +01:00
|
|
|
|
|
|
|
func ReadGo116ErrorData(terr types.Error) (ErrorCode, token.Pos, token.Pos, bool) {
|
|
|
|
var data [3]int
|
|
|
|
// By coincidence all of these fields are ints, which simplifies things.
|
|
|
|
v := reflect.ValueOf(terr)
|
|
|
|
for i, name := range []string{"go116code", "go116start", "go116end"} {
|
|
|
|
f := v.FieldByName(name)
|
|
|
|
if !f.IsValid() {
|
|
|
|
return 0, 0, 0, false
|
|
|
|
}
|
|
|
|
data[i] = int(f.Int())
|
|
|
|
}
|
|
|
|
return ErrorCode(data[0]), token.Pos(data[1]), token.Pos(data[2]), true
|
|
|
|
}
|