// 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.

// Package typesinternal provides helpful operators for dealing with
// go/types:
//
//   - operators for querying typed syntax trees (e.g. [Imports], [IsFunctionNamed]);
//   - functions for converting types to strings or syntax (e.g. [TypeExpr], FileQualifier]);
//   - helpers for working with the [go/types] API (e.g. [NewTypesInfo]);
//   - access to internal go/types APIs that are not yet
//     exported (e.g. [SetUsesCgo], [ErrorCodeStartEnd], [VarKind]); and
//   - common algorithms related to types (e.g. [TooNewStdSymbols]).
//
// See also:
//   - [golang.org/x/tools/internal/astutil], for operations on untyped syntax;
//   - [golang.org/x/tools/internal/analysisinernal], for helpers for analyzers;
//   - [golang.org/x/tools/internal/refactor], for operators to compute text edits.
package typesinternal

import (
	"go/ast"
	"go/token"
	"go/types"
	"reflect"

	"golang.org/x/tools/go/ast/inspector"
)

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
		}
	}

	*(*bool)(f.Addr().UnsafePointer()) = true

	return true
}

// ErrorCodeStartEnd extracts additional information from types.Error values
// generated by Go version 1.16 and later: the error code, start position, and
// end position. If all positions are valid, start <= err.Pos <= end.
//
// If the data could not be read, the final result parameter will be false.
