<commit_before>// Copyright 2015 The go-python 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 bind

import (
	"golang.org/x/tools/go/types"
)

type Object interface {
	Package() *Package
	ID() string
	Doc() string
	GoName() string
}

type Type interface {
	Object
	GoType() types.Type
}

func needWrapType(typ types.Type) bool {
	switch typ.(type) {
	case *types.Struct:
		return true
	case *types.Named:
		switch typ.Underlying().(type) {
		case *types.Struct:
			return true
		}
	}
	return false
}

func cTypeName(typ types.Type) string {
	switch typ := typ.(type) {
	case *types.Basic:
		kind := typ.Kind()
		o, ok := typedescr[kind]
		if ok {
			return o.ctype
		}
	}
	return typ.String()
}

func cgoTypeName(typ types.Type) string {
	switch typ := typ.(type) {
	case *types.Basic:
		kind := typ.Kind()
		o, ok := typedescr[kind]
		if ok {
			return o.cgotype
		}
	}
	return typ.String()
}

func pyTypeName(typ types.Type) string {
	switch typ := typ.(type) {
	case *types.Basic:
		kind := typ.Kind()
		o, ok := typedescr[kind]
		if ok {
			return o.pysig
		}
	}
	return "object"
}

type typedesc struct {
	ctype   string
	cgotype string
	pyfmt   string
	pysig   string
}

var typedescr = map[types.BasicKind]typedesc{
	types.Bool: typedesc{
		ctype:   "_Bool",
		cgotype: "GoBool",
		pyfmt:   "b",
		pysig:   "bool",
	},

	types.Int: typedesc{
		ctype:   "int",
		cgotype: "GoInt",
		pyfmt:   "i",
		pysig:   "int",
	},

	types.Int8: typedesc{
		ctype:   "int8_t",
		cgotype: "GoInt8",
		pyfmt:   "c",
		pysig:   "int",
	},

	types.Int16: typedesc{
		ctype:   "int16_t",
		cgotype: "GoInt16",
		pyfmt:   "h",
		pysig:   "int",<commit_msg>bind: correctly handle int/uint size and pyfmt for PyArg_Parse<commit_after>// Copyright 2015 The go-python 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 bind

import (
	"reflect"

	"golang.org/x/tools/go/types"
)

type Object interface {
	Package() *Package
	ID() string
	Doc() string
	GoName() string
}

type Type interface {
	Object
	GoType() types.Type
}

func needWrapType(typ types.Type) bool {
	switch typ.(type) {
	case *types.Struct:
		return true
	case *types.Named:
		switch typ.Underlying().(type) {
		case *types.Struct:
			return true
		}
	}
	return false
}

func cTypeName(typ types.Type) string {
	switch typ := typ.(type) {
	case *types.Basic:
		kind := typ.Kind()
		o, ok := typedescr[kind]
		if ok {
			return o.ctype
		}
	}
	return typ.String()
}

func cgoTypeName(typ types.Type) string {
	switch typ := typ.(type) {
	case *types.Basic:
		kind := typ.Kind()
		o, ok := typedescr[kind]
		if ok {
			return o.cgotype
		}
	}
	return typ.String()
}

func pyTypeName(typ types.Type) string {
	switch typ := typ.(type) {
	case *types.Basic:
		kind := typ.Kind()
		o, ok := typedescr[kind]
		if ok {
			return o.pysig
		}
	}
	return "object"
}

type typedesc struct {
	ctype   string
	cgotype string
	pyfmt   string
	pysig   string
}

var (
	intsize = reflect.TypeOf(int(0)).Size()
)

func init() {
	if intsize == 8 {
		typedescr[types.Int] = typedesc{
			ctype:   "int64_t",
			cgotype: "GoInt",
			pyfmt:   "k",
			pysig:   "int",
		}

		typedescr[types.Uint] = typedesc{
			ctype:   "uint64_t",
			cgotype: "GoUint",
			pyfmt:   "K",
			pysig:   "int",
		}
	}
}

var typedescr = map[types.BasicKind]typedesc{
	types.Bool: typedesc{
		ctype:   "_Bool",
		cgotype: "GoBool",
		pyfmt:   "b",
		pysig:   "bool",
	},

	types.Int: typedesc{
		ctype:   "int",
		cgotype: "GoInt",
		pyfmt:   "i",
		pysig:   "int",
	},

	types.Int8: typedesc{
		ctype:   "int8_t",
		cgotype: "GoInt8",
		pyfmt:   "c",
		pysig:   "int",
	},

	types.Int16: typedesc{
		ctype:   "int16_t",
		cgotype: "GoInt16",
		pyfmt:   "h",
		pysig:   "int",
{'fraction_non_alphanumeric': 0.14488636363636365, 'fraction_numerical': 0.008264462809917356, 'mean_word_length': 3.0051706308169597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3250737', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1545, 'n_words': 402}