schemautil

package
v1.44.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MPL-2.0 Imports: 14 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(errs *perr.List, 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(errs *perr.List, 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 GetArgument added in v1.20.4

func GetArgument(fields *ast.FieldList, n int) (f *ast.Field, name option.Option[string])

GetArgument gets the n'th argument from the field list. It reports the name of the n'th argument if it has one.

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 IsBuiltinOrList added in v1.20.1

func IsBuiltinOrList(t schema.Type) (kind schema.BuiltinKind, isList bool, ok bool)

IsBuiltinOrList reports whether the given type is a builtin, a list of builtins, or neither.

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