schemautil

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Integers = append(append([]schema.BuiltinKind{}, Signed...), Unsigned...)

Integers is a list of all integer builtin kinds.

Functions

func ConcretizeGenericType

func ConcretizeGenericType(typ schema.Type) schema.Type

ConcretizeGenericType takes a type and applies any type arguments into the slots of the type parameters, producing a concrete type.

To be more robust in the presence of typing errors it supports partial application, where the number of type arguments may be different than the number of type parameters on the decl.

func ConcretizeWithTypeArgs

func ConcretizeWithTypeArgs(typ schema.Type, typeArgs []schema.Type) schema.Type

ConcretizeWithTypeArgs is like ConcretizeGenericType but operates with a list of type arguments. It is used when the type arguments are known separately from the type itself, such as when using *schema.TypeDeclRef.

func Deref

func Deref(t schema.Type) (schema.Type, int)

Deref dereferences a type until it is not a pointer type. It returns the number of pointer dereferences required.

func DerefNamedInfo added in v1.16.0

func DerefNamedInfo(t schema.Type, requirePointer bool) (info *pkginfo.PkgDeclInfo, ok bool)

DerefNamedInfo returns what package declaration a given named type references, if any.

It always requires at most one pointer dereference, and if requirePointer is true it must be exactly one pointer dereference.

If the type is not a named type or otherwise doesn't match the requirements, it returns (nil, false).

func IsBuiltinKind

func IsBuiltinKind(t schema.Type, kinds ...schema.BuiltinKind) bool

IsBuiltinKind reports whether the given type is a builtin of one of the given kinds.

func IsNamed

func IsNamed(t schema.Type, pkg paths.Pkg, name string) bool

IsNamed reports whether a given type is a named type with the given package path and name.

func IsPointer

func IsPointer(t schema.Type) bool

IsPointer reports whether t is a pointer type.

func ResolveNamedStruct

func ResolveNamedStruct(t schema.Type, requirePointer bool) (ref *schema.TypeDeclRef, ok bool)

ResolveNamedStruct reports whether a given type is a named type pointing to a struct type.

It always requires at most one pointer dereference, and if requirePointer is true it must be exactly one pointer dereference.

If it doesn't match the requirements it returns (nil, false).

func UnwrapConfigType

func UnwrapConfigType(errs *perr.List, t schema.NamedType) (typ schema.Type, isList, isConfig bool)

UnwrapConfigType unwraps a config.Value[T] or config.Values[T] type to T or []T respectively. If the type is not a config.Value[T] or config.Values[T] type, it returns the type unchanged. If there are any errors encountered they are reported to errs.

func Walk

func Walk(root schema.Type, visitor func(node schema.Type) bool)

Walk performs a depth-first walk of all schema nodes starting at node, calling visitor for each type.

If visitor returns false, the walk is aborted.

Types

type TypeHash

type TypeHash [32]byte

func Hash

func Hash(typ schema.Type) TypeHash

Hash produces a hash of the given type. Identical types return identical hashes.

Jump to

Keyboard shortcuts

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