GoPLS Viewer

Home|gopls/internal/typesinternal/types.go
1// Copyright 2020 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package typesinternal provides access to internal go/types APIs that are not
6// yet exported.
7package typesinternal
8
9import (
10    "go/token"
11    "go/types"
12    "reflect"
13    "unsafe"
14)
15
16func SetUsesCgo(conf *types.Configbool {
17    v := reflect.ValueOf(conf).Elem()
18
19    f := v.FieldByName("go115UsesCgo")
20    if !f.IsValid() {
21        f = v.FieldByName("UsesCgo")
22        if !f.IsValid() {
23            return false
24        }
25    }
26
27    addr := unsafe.Pointer(f.UnsafeAddr())
28    *(*bool)(addr) = true
29
30    return true
31}
32
33// ReadGo116ErrorData extracts additional information from types.Error values
34// generated by Go version 1.16 and later: the error code, start position, and
35// end position. If all positions are valid, start <= err.Pos <= end.
36//
37// If the data could not be read, the final result parameter will be false.
38func ReadGo116ErrorData(err types.Error) (code ErrorCodestartend token.Posok bool) {
39    var data [3]int
40    // By coincidence all of these fields are ints, which simplifies things.
41    v := reflect.ValueOf(err)
42    for iname := range []string{"go116code""go116start""go116end"} {
43        f := v.FieldByName(name)
44        if !f.IsValid() {
45            return 000false
46        }
47        data[i] = int(f.Int())
48    }
49    return ErrorCode(data[0]), token.Pos(data[1]), token.Pos(data[2]), true
50}
51
52var SetGoVersion = func(conf *types.Configversion stringbool { return false }
53
MembersX
ReadGo116ErrorData
ReadGo116ErrorData.err
ReadGo116ErrorData.start
ReadGo116ErrorData.ok
ReadGo116ErrorData.data
unsafe
SetUsesCgo
SetUsesCgo.f
ReadGo116ErrorData.code
ReadGo116ErrorData.v
ReadGo116ErrorData.RangeStmt_1143.BlockStmt.f
SetUsesCgo.addr
ReadGo116ErrorData.RangeStmt_1143.name
reflect
SetUsesCgo.conf
SetUsesCgo.v
ReadGo116ErrorData.end
ReadGo116ErrorData.RangeStmt_1143.i
Members
X