typep

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2023 License: MIT Imports: 3 Imported by: 10

README

typep

build-img pkg-img reportcard-img version-img

Package typep provides type predicates.

Installation:

Go version 1.16+

go get github.com/go-toolsmith/typep

Example

package main

import (
	"fmt"

	"github.com/go-toolsmith/typep"
	"github.com/go-toolsmith/strparse"
)

func main() {
	floatTyp := types.Typ[types.Float32]
	intTyp := types.Typ[types.Int]
	ptr := types.NewPointer(intTyp)
	arr := types.NewArray(intTyp, 64)

	fmt.Println(typep.HasFloatProp(floatTyp)) // => true
	fmt.Println(typep.HasFloatProp(intTyp))   // => false
	fmt.Println(typep.IsPointer(ptr))         // => true
	fmt.Println(typep.IsArray(arr))           // => true
}

License

MIT License.

Documentation

Overview

Package typep provides type predicates.

Example
package main

import (
	"fmt"
	"go/types"

	"github.com/go-toolsmith/typep"
)

func main() {
	floatTyp := types.Typ[types.Float32]
	intTyp := types.Typ[types.Int]
	ptr := types.NewPointer(intTyp)
	arr := types.NewArray(intTyp, 64)

	fmt.Println(typep.HasFloatProp(floatTyp)) // => true
	fmt.Println(typep.HasFloatProp(intTyp))   // => false
	fmt.Println(typep.IsPointer(ptr))         // => true
	fmt.Println(typep.IsArray(arr))           // => true

}
Output:

true
false
true
true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasBoolKind

func HasBoolKind(typ types.Type) bool

HasBoolKind reports whether typ is a *types.Basic with its kind set to types.Bool.

func HasBooleanProp

func HasBooleanProp(typ types.Type) bool

HasBooleanProp reports whether typ is a *types.Basic has IsBoolean property.

func HasComplex128Kind

func HasComplex128Kind(typ types.Type) bool

HasComplex128Kind reports whether typ is a *types.Basic with its kind set to types.Complex128.

func HasComplex64Kind

func HasComplex64Kind(typ types.Type) bool

HasComplex64Kind reports whether typ is a *types.Basic with its kind set to types.Complex64.

func HasComplexProp

func HasComplexProp(typ types.Type) bool

HasComplexProp reports whether typ is a *types.Basic has IsComplex property.

func HasConstTypeProp

func HasConstTypeProp(typ types.Type) bool

HasConstTypeProp reports whether typ is a *types.Basic has IsConstType property.

func HasFloat32Kind

func HasFloat32Kind(typ types.Type) bool

HasFloat32Kind reports whether typ is a *types.Basic with its kind set to types.Float32.

func HasFloat64Kind

func HasFloat64Kind(typ types.Type) bool

HasFloat64Kind reports whether typ is a *types.Basic with its kind set to types.Float64.

func HasFloatProp

func HasFloatProp(typ types.Type) bool

HasFloatProp reports whether typ is a *types.Basic has IsFloat property.

func HasInt16Kind

func HasInt16Kind(typ types.Type) bool

HasInt16Kind reports whether typ is a *types.Basic with its kind set to types.Int16.

func HasInt32Kind

func HasInt32Kind(typ types.Type) bool

HasInt32Kind reports whether typ is a *types.Basic with its kind set to types.Int32.

func HasInt64Kind

func HasInt64Kind(typ types.Type) bool

HasInt64Kind reports whether typ is a *types.Basic with its kind set to types.Int64.

func HasInt8Kind

func HasInt8Kind(typ types.Type) bool

HasInt8Kind reports whether typ is a *types.Basic with its kind set to types.Int8.

func HasIntKind

func HasIntKind(typ types.Type) bool

HasIntKind reports whether typ is a *types.Basic with its kind set to types.Int.

func HasIntegerProp

func HasIntegerProp(typ types.Type) bool

HasIntegerProp reports whether typ is a *types.Basic has IsInteger property.

func HasNumericProp

func HasNumericProp(typ types.Type) bool

HasNumericProp reports whether typ is a *types.Basic has IsNumeric property.

func HasOrderedProp

func HasOrderedProp(typ types.Type) bool

HasOrderedProp reports whether typ is a *types.Basic has IsOrdered property.

func HasStringKind

func HasStringKind(typ types.Type) bool

HasStringKind reports whether typ is a *types.Basic with its kind set to types.String.

func HasStringProp

func HasStringProp(typ types.Type) bool

HasStringProp reports whether typ is a *types.Basic has IsString property.

func HasUint16Kind

func HasUint16Kind(typ types.Type) bool

HasUint16Kind reports whether typ is a *types.Basic with its kind set to types.Uint16.

func HasUint32Kind

func HasUint32Kind(typ types.Type) bool

HasUint32Kind reports whether typ is a *types.Basic with its kind set to types.Uint32.

func HasUint64Kind

func HasUint64Kind(typ types.Type) bool

HasUint64Kind reports whether typ is a *types.Basic with its kind set to types.Uint64.

func HasUint8Kind

func HasUint8Kind(typ types.Type) bool

HasUint8Kind reports whether typ is a *types.Basic with its kind set to types.Uint8.

func HasUintKind

func HasUintKind(typ types.Type) bool

HasUintKind reports whether typ is a *types.Basic with its kind set to types.Uint.

func HasUintptrKind

func HasUintptrKind(typ types.Type) bool

HasUintptrKind reports whether typ is a *types.Basic with its kind set to types.Uintptr.

func HasUnsafePointerKind

func HasUnsafePointerKind(typ types.Type) bool

HasUnsafePointerKind reports whether typ is a *types.Basic with its kind set to types.UnsafePointer.

func HasUnsignedProp

func HasUnsignedProp(typ types.Type) bool

HasUnsignedProp reports whether typ is a *types.Basic has IsUnsigned property.

func HasUntypedBoolKind

func HasUntypedBoolKind(typ types.Type) bool

HasUntypedBoolKind reports whether typ is a *types.Basic with its kind set to types.UntypedBool.

func HasUntypedComplexKind

func HasUntypedComplexKind(typ types.Type) bool

HasUntypedComplexKind reports whether typ is a *types.Basic with its kind set to types.UntypedComplex.

func HasUntypedFloatKind

func HasUntypedFloatKind(typ types.Type) bool

HasUntypedFloatKind reports whether typ is a *types.Basic with its kind set to types.UntypedFloat.

func HasUntypedIntKind

func HasUntypedIntKind(typ types.Type) bool

HasUntypedIntKind reports whether typ is a *types.Basic with its kind set to types.UntypedInt.

func HasUntypedNilKind

func HasUntypedNilKind(typ types.Type) bool

HasUntypedNilKind reports whether typ is a *types.Basic with its kind set to types.UntypedNil.

func HasUntypedProp

func HasUntypedProp(typ types.Type) bool

HasUntypedProp reports whether typ is a *types.Basic has IsUntyped property.

func HasUntypedRuneKind

func HasUntypedRuneKind(typ types.Type) bool

HasUntypedRuneKind reports whether typ is a *types.Basic with its kind set to types.UntypedRune.

func HasUntypedStringKind

func HasUntypedStringKind(typ types.Type) bool

HasUntypedStringKind reports whether typ is a *types.Basic with its kind set to types.UntypedString.

func IsArray

func IsArray(typ types.Type) bool

IsArray reports whether a given type has *types.Array type.

func IsBasic

func IsBasic(typ types.Type) bool

IsBasic reports whether a given type has *types.Basic type.

func IsChan

func IsChan(typ types.Type) bool

IsChan reports whether a given type has *types.Chan type.

func IsInterface

func IsInterface(typ types.Type) bool

IsInterface reports whether a given type has *types.Interface type.

func IsMap

func IsMap(typ types.Type) bool

IsMap reports whether a given type has *types.Map type.

func IsNamed

func IsNamed(typ types.Type) bool

IsNamed reports whether a given type has *types.Named type.

func IsPointer

func IsPointer(typ types.Type) bool

IsPointer reports whether a given type has *types.Pointer type.

func IsSignature

func IsSignature(typ types.Type) bool

IsSignature reports whether a given type has *types.Signature type.

func IsSlice

func IsSlice(typ types.Type) bool

IsSlice reports whether a given type has *types.Slice type.

func IsStruct

func IsStruct(typ types.Type) bool

IsStruct reports whether a given type has *types.Struct type.

func IsTuple

func IsTuple(typ types.Type) bool

IsTuple reports whether a given type has *types.Tuple type.

func IsTypeExpr

func IsTypeExpr(info *types.Info, x ast.Expr) bool

IsTypeExpr reports whether x represents a type expression.

Type expression does not evaluate to any run time value, but rather describes a type that is used inside Go expression.

For example, (*T)(v) is a CallExpr that "calls" (*T). (*T) is a type expression that tells Go compiler type v should be converted to.

func SideEffectFree

func SideEffectFree(info *types.Info, expr ast.Expr) bool

SideEffectFree reports whether expr is softly safe expression and contains no significant side-effects. As opposed to strictly safe expressions, soft safe expressions permit some forms of side-effects, like panic possibility during indexing or nil pointer dereference.

Uses types info to determine type conversion expressions that are the only permitted kinds of call expressions. Note that is does not check whether called function really has any side effects. The analysis is very conservative.

func SideEffectFreeList

func SideEffectFreeList(info *types.Info, list []ast.Expr) bool

SideEffectFreeList reports whether every expr in list is safe.

See SideEffectFree.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL