Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

lib/type.x

Semantic type values and their structural operations.

Primary API

FunctionSummary
List.typeViews x as a Type without validating its type shape.
Symbol.is_builtin_typeReturns whether sym can begin a builtin C type specifier.
Symbol.is_inlineReturns whether sym is the inline function specifier.
Symbol.is_storage_classReturns whether sym is a storage-class specifier.
Symbol.is_type_modifierReturns whether sym modifies the width or signedness of a scalar.
Symbol.is_type_qualifierReturns whether sym is const, restrict, or volatile.
Type.applyReturns the result Type of a function Type, following pointer and array modifiers, or NULL when the chain does not end at a function.
Type.base_typeReturns the suffix of type beginning at its builtin or typedef base.
Type.bodyReturns the stored body portion of an enum, struct, or union Type.
Type.canonicalizeRemoves non-typedef storage classes, inline, and type qualifiers from type.
Type.declaredReturns the stored declaration Type after removing non-typedef storage classes and inline.
Type.dereferenceRemoves one outer pointer-like or array modifier, or returns NULL.
Type.discards_qualifiersReturns whether handing a source value to a target declaration would silently drop a qualifier the target does not keep.
Type.function_partsSplits a direct or pointer function type into its fixed params, which are NULL for (void), and its return_type when one is asked for.
Type.integer_literal_magnitudeReads an integer literal of type spelled in digits, with any suffix, into value.
Type.is_aggregateReturns whether type is any struct or union shape.
Type.is_aggregate_tagReturns whether t is a body-free struct or union tag reference.
Type.is_aggregate_tag_bodyReturns whether type is a tagged struct or union definition.
Type.is_arrayReturns whether the outer declarator represented by type is an array.
Type.is_bare_typedef_nameReturns whether type is one bare typedef-name String.
Type.is_bitfieldReturns whether the outer declarator represented by type is a bitfield.
Type.is_builtinReturns whether type is a builtin scalar, struct, union, or enum.
Type.is_char_pointer_likeReturns whether type is exactly a pointer or array of char or const char, without resolving typedefs or removing qualifiers.
Type.is_enumReturns whether type is any enum shape.
Type.is_enum_tagReturns whether type is a body-free enum tag reference.
Type.is_enum_tag_bodyReturns whether type is a tagged enum definition.
Type.is_externReturns whether type carries the extern storage class.
Type.is_functionReturns whether the outer declarator is a function or inline function.
Type.is_inlineReturns whether type carries the inline function specifier.
Type.is_integralReturns whether type is a fixed integral scalar or an enum.
Type.is_numberReturns whether type is a fixed numeric scalar or an enum.
Type.is_pointerReturns whether t begins with a pointer-like modifier.
Type.is_referenceReturns whether t is a reference or an optional reference.
Type.is_staticReturns whether type carries the static storage class.
Type.is_threadedReturns whether type carries the threaded storage class.
Type.is_typedefReturns whether type begins with the typedef storage class.
Type.is_typedef_nameReturns whether the base of type is exactly one typedef-name String.
Type.listViews x as its underlying List without validating its type shape.
Type.numeric_literalReturns the native type selected by a validated numeric token.
Type.numeric_literal_valueReads a validated numeric literal at its semantic type’s precision.
Type.promoteApplies integer promotion to type.
Type.qualifyApplies source’s outer qualifiers to type.
Type.referenceReturns the pointer Type formed by prefixing type with *.
Type.scalarReturns the normalized builtin scalar spelling, or NULL when t is not one valid scalar combination.
Type.scalar_tagReturns the fixed Var numeric tag for type, or zero when none exists.
Type.tagReturns the one-element tag List of an enum, struct, or union Type.
Type.var_numeric_extractorReturns the numeric Var reader for type, or NULL when unsupported.
Type.var_numeric_update_helperReturns the native numeric update helper for type, or NULL when the scalar has no registered update helper.
Type.widestReturns the usual arithmetic result Type for two scalar operands.
Var.typeReturns the List payload of x as a Type, or NULL for another tag.

List

List.type

inline Type List.type(List x)

Views x as a Type without validating its type shape.

Source: lib/type.x:28

Symbol

Symbol.is_builtin_type

int Symbol.is_builtin_type(Symbol sym)

Returns whether sym can begin a builtin C type specifier.

Source: lib/type.x:57

Symbol.is_inline

int Symbol.is_inline(Symbol sym)

Returns whether sym is the inline function specifier.

Source: lib/type.x:44

Symbol.is_storage_class

int Symbol.is_storage_class(Symbol sym)

Returns whether sym is a storage-class specifier.

Source: lib/type.x:41

Symbol.is_type_modifier

int Symbol.is_type_modifier(Symbol sym)

Returns whether sym modifies the width or signedness of a scalar.

Source: lib/type.x:50

Symbol.is_type_qualifier

int Symbol.is_type_qualifier(Symbol sym)

Returns whether sym is const, restrict, or volatile.

Source: lib/type.x:47

Type

Type.apply

Type Type.apply(Type type)

Returns the result Type of a function Type, following pointer and array modifiers, or NULL when the chain does not end at a function.

Source: lib/type.x:164

Type.base_type

Type Type.base_type(Type type)

Returns the suffix of type beginning at its builtin or typedef base. The result shares the original List and is NULL when no base is present.

Source: lib/type.x:217

Type.body

List Type.body(Type t)

Returns the stored body portion of an enum, struct, or union Type. Tag references and Types without a stored body return NULL.

Source: lib/type.x:102

Type.canonicalize

Type Type.canonicalize(Type type)

Removes non-typedef storage classes, inline, and type qualifiers from type.

Source: lib/type.x:222

Type.declared

Type Type.declared(Type type)

Returns the stored declaration Type after removing non-typedef storage classes and inline. Those specifiers describe declaration placement; const, restrict, and volatile describe the stored value and remain.

Source: lib/type.x:228

Type.dereference

Type Type.dereference(Type type)

Removes one outer pointer-like or array modifier, or returns NULL.

Source: lib/type.x:137

Type.discards_qualifiers

int Type.discards_qualifiers(Type source, Type target)

Returns whether handing a source value to a target declaration would silently drop a qualifier the target does not keep. The leading qualifiers of each type describe the copied value, not what it points at, so only the deeper levels are compared. Callers use this where the two types are otherwise the same, or where one points at void, which has no deeper levels to compare; a conversion through a converter function copies instead of aliasing.

Source: lib/type.x:256

Type.function_parts

int Type.function_parts(Type type, List &params, Type &?return_type)

Splits a direct or pointer function type into its fixed params, which are NULL for (void), and its return_type when one is asked for. Returns 0 and leaves both unchanged when type is not a function.

Source: lib/type.x:177

Type.integer_literal_magnitude

int Type.integer_literal_magnitude( Type type, String text, unsigned long long &value)

Reads an integer literal of type spelled in digits, with any suffix, into value. Returns 0 for any other literal.

Source: lib/type.x:545

Type.is_aggregate

int Type.is_aggregate(Type type)

Returns whether type is any struct or union shape.

Source: lib/type.x:63

Type.is_aggregate_tag

int Type.is_aggregate_tag(Type t)

Returns whether t is a body-free struct or union tag reference.

Source: lib/type.x:66

Type.is_aggregate_tag_body

int Type.is_aggregate_tag_body(Type type)

Returns whether type is a tagged struct or union definition.

Source: lib/type.x:73

Type.is_array

int Type.is_array(Type type)

Returns whether the outer declarator represented by type is an array.

Source: lib/type.x:118

Type.is_bare_typedef_name

int Type.is_bare_typedef_name(Type type)

Returns whether type is one bare typedef-name String. Unlike is_typedef_name, this rejects pointer and array wrappers.

Source: lib/type.x:318

Type.is_bitfield

int Type.is_bitfield(Type type)

Returns whether the outer declarator represented by type is a bitfield.

Source: lib/type.x:129

Type.is_builtin

int Type.is_builtin(Type type)

Returns whether type is a builtin scalar, struct, union, or enum.

Source: lib/type.x:300

Type.is_char_pointer_like

int Type.is_char_pointer_like(Type type)

Returns whether type is exactly a pointer or array of char or const char, without resolving typedefs or removing qualifiers.

Source: lib/type.x:293

Type.is_enum

int Type.is_enum(Type type)

Returns whether type is any enum shape.

Source: lib/type.x:77

Type.is_enum_tag

int Type.is_enum_tag(Type type)

Returns whether type is a body-free enum tag reference.

Source: lib/type.x:80

Type.is_enum_tag_body

int Type.is_enum_tag_body(Type type)

Returns whether type is a tagged enum definition.

Source: lib/type.x:86

Type.is_extern

int Type.is_extern(Type type)

Returns whether type carries the extern storage class.

Source: lib/type.x:203

Type.is_function

int Type.is_function(Type type)

Returns whether the outer declarator is a function or inline function.

Source: lib/type.x:121

Type.is_inline

int Type.is_inline(Type type)

Returns whether type carries the inline function specifier.

Source: lib/type.x:200

Type.is_integral

int Type.is_integral(Type type)

Returns whether type is a fixed integral scalar or an enum.

Source: lib/type.x:325

Type.is_number

int Type.is_number(Type type)

Returns whether type is a fixed numeric scalar or an enum.

Source: lib/type.x:322

Type.is_pointer

int Type.is_pointer(Type t)

Returns whether t begins with a pointer-like modifier.

Source: lib/type.x:112

Type.is_reference

int Type.is_reference(Type t)

Returns whether t is a reference or an optional reference.

Source: lib/type.x:115

Type.is_static

int Type.is_static(Type type)

Returns whether type carries the static storage class.

Source: lib/type.x:197

Type.is_threaded

int Type.is_threaded(Type type)

Returns whether type carries the threaded storage class.

Source: lib/type.x:206

Type.is_typedef

int Type.is_typedef(Type type)

Returns whether type begins with the typedef storage class.

Source: lib/type.x:209

Type.is_typedef_name

int Type.is_typedef_name(Type type)

Returns whether the base of type is exactly one typedef-name String.

Source: lib/type.x:310

Type.list

inline List Type.list(Type x)

Views x as its underlying List without validating its type shape.

Source: lib/type.x:25

Type.numeric_literal

Type Type.numeric_literal(String text, int floating)

Returns the native type selected by a validated numeric token. floating selects floating suffix rules; an integer outside all supported native families returns NULL. A signed data token includes its sign when selecting a family, so a signed minimum fits that family.

Source: lib/type.x:497

Type.numeric_literal_value

Var Type.numeric_literal_value(Type type, String text)

Reads a validated numeric literal at its semantic type’s precision. Returns void when its magnitude exceeds the integer representation.

Source: lib/type.x:525

Type.promote

Type Type.promote(Type type)

Applies integer promotion to type. Enums and narrow integers become int; other scalars retain their canonical spelling, and a non-scalar returns NULL.

Source: lib/type.x:445

Type.qualify

Type Type.qualify(Type type, Type source)

Applies source’s outer qualifiers to type.

Source: lib/type.x:146

Type.reference

Type Type.reference(Type type)

Returns the pointer Type formed by prefixing type with *.

Source: lib/type.x:159

Type.scalar

Type Type.scalar(Type t)

Returns the normalized builtin scalar spelling, or NULL when t is not one valid scalar combination. Storage classes and qualifiers do not affect the result.

Source: lib/type.x:343

Type.scalar_tag

Symbol Type.scalar_tag(Type type)

Returns the fixed Var numeric tag for type, or zero when none exists.

Source: lib/type.x:417

Type.tag

List Type.tag(Type type)

Returns the one-element tag List of an enum, struct, or union Type. For a compiler-generated anonymous tag, that element is a gensym node. A shape with no tag slot returns NULL.

Source: lib/type.x:92

Type.var_numeric_extractor

String Type.var_numeric_extractor(Type type)

Returns the numeric Var reader for type, or NULL when unsupported. Enums use Var_int after conversion to their shared integer tag.

Source: lib/type.x:425

Type.var_numeric_update_helper

String Type.var_numeric_update_helper(Type type)

Returns the native numeric update helper for type, or NULL when the scalar has no registered update helper.

Source: lib/type.x:434

Type.widest

Type Type.widest(Type a, Type b)

Returns the usual arithmetic result Type for two scalar operands. A missing or non-scalar operand produces NULL.

Source: lib/type.x:458

Var

Var.type

inline Type Var.type(Var x)

Returns the List payload of x as a Type, or NULL for another tag.

Source: lib/type.x:22

Design notes

These operations inspect captured types without compiler state. Name resolution and translation-unit registrations belong to the compiler.

Tests and examples

make verify (meta-type-values compiler fixture).