.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / golang.org / x / tools@v0.1.1-0.20210319172145-bda8f5cee399 / 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.
7 package typesinternal
8
9 import (
10         "go/token"
11         "go/types"
12         "reflect"
13         "unsafe"
14 )
15
16 func SetUsesCgo(conf *types.Config) bool {
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 func ReadGo116ErrorData(terr types.Error) (ErrorCode, token.Pos, token.Pos, bool) {
34         var data [3]int
35         // By coincidence all of these fields are ints, which simplifies things.
36         v := reflect.ValueOf(terr)
37         for i, name := range []string{"go116code", "go116start", "go116end"} {
38                 f := v.FieldByName(name)
39                 if !f.IsValid() {
40                         return 0, 0, 0, false
41                 }
42                 data[i] = int(f.Int())
43         }
44         return ErrorCode(data[0]), token.Pos(data[1]), token.Pos(data[2]), true
45 }