infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Registry Introspection API

APIs for inspecting and serializing the contents of a named type registry. More...

Collaboration diagram for Registry Introspection API:

Typedefs

typedef struct infix_registry_iterator_t infix_registry_iterator_t
 An opaque handle to a registry iterator. Created by infix_registry_iterator_begin.
 

Functions

c23_nodiscard infix_status infix_registry_print (char *, size_t, const infix_registry_t *)
 Serializes all defined types within a registry into a single, human-readable string.
 
c23_nodiscard infix_registry_iterator_t infix_registry_iterator_begin (const infix_registry_t *)
 Initializes an iterator for traversing the types in a registry.
 
c23_nodiscard bool infix_registry_iterator_next (infix_registry_iterator_t *)
 Advances the iterator to the next defined type in the registry.
 
c23_nodiscard const char * infix_registry_iterator_get_name (const infix_registry_iterator_t *)
 Gets the name of the type at the iterator's current position.
 
c23_nodiscard const infix_typeinfix_registry_iterator_get_type (const infix_registry_iterator_t *)
 Gets the infix_type object of the type at the iterator's current position.
 
c23_nodiscard bool infix_registry_is_defined (const infix_registry_t *, const char *)
 Checks if a type with the given name is fully defined in the registry.
 
c23_nodiscard const infix_typeinfix_registry_lookup_type (const infix_registry_t *, const char *)
 Retrieves the canonical infix_type object for a given name from the registry.
 
c23_nodiscard infix_registry_tinfix_registry_create_in_arena (infix_arena_t *arena)
 Creates a new named type registry that allocates from a user-provided arena.
 

Detailed Description

APIs for inspecting and serializing the contents of a named type registry.

Typedef Documentation

◆ infix_registry_iterator_t

An opaque handle to a registry iterator. Created by infix_registry_iterator_begin.

Function Documentation

◆ infix_registry_create_in_arena()

c23_nodiscard infix_registry_t * infix_registry_create_in_arena ( infix_arena_t arena)

Creates a new named type registry that allocates from a user-provided arena.

This advanced function allows multiple registries and trampolines to share a single memory arena, enabling pointer sharing and reducing memory overhead. The user is responsible for managing the lifetime of the provided arena.

Parameters
[in]arenaThe user-managed arena to use for all internal allocations.
Returns
A pointer to the new registry, or nullptr on allocation failure.
Note
The registry should still be destroyed with infix_registry_destroy, but this will not free the user-provided arena itself.

Creates a new named type registry that allocates from a user-provided arena.

A registry acts as a dictionary for infix types, allowing you to define complex structs, unions, or aliases once and refer to them by name (e.g., @MyStruct) in any signature string. This is essential for managing complex, recursive, or mutually-dependent types.

Parameters
[in]arenaThe arena to allocate from.
Returns
A pointer to the new registry, or nullptr on allocation failure. The returned handle must be freed with infix_registry_destroy.

◆ infix_registry_is_defined()

c23_nodiscard bool infix_registry_is_defined ( const infix_registry_t registry,
const char *  name 
)

Checks if a type with the given name is fully defined in the registry.

This function will return false for names that are only forward-declared but have not been given a definition.

Parameters
[in]registryThe registry to search.
[in]nameThe name of the type to check (e.g., "MyStruct").
Returns
true if a complete definition for the name exists, false otherwise.

This function will return false for names that are only forward-declared (e.g., via @Name;) but have not been given a complete definition.

Parameters
[in]registryThe registry to search.
[in]nameThe name of the type to check (e.g., "MyStruct").
Returns
true if a complete definition for the name exists, false otherwise.

◆ infix_registry_iterator_begin()

c23_nodiscard infix_registry_iterator_t infix_registry_iterator_begin ( const infix_registry_t registry)

Initializes an iterator for traversing the types in a registry.

Parameters
[in]registryThe registry to iterate over.
Returns
An initialized iterator. If the registry is empty, the first call to infix_registry_iterator_next on this iterator will return false.

This function creates an iterator that can be used with infix_registry_iterator_next to loop through all fully-defined types in a registry. The order of traversal is not guaranteed.

Parameters
[in]registryThe registry to iterate over.
Returns
An initialized iterator. If the registry is empty, the first call to infix_registry_iterator_next on this iterator will return false.
const char* name = infix_registry_iterator_get_name(&it);
printf("Found type: %s\n", name);
}
infix_registry_t * registry
Definition 008_registry_introspection.c:35
c23_nodiscard const infix_type * infix_registry_iterator_get_type(const infix_registry_iterator_t *)
Gets the infix_type object of the type at the iterator's current position.
Definition type_registry.c:769
c23_nodiscard infix_registry_iterator_t infix_registry_iterator_begin(const infix_registry_t *)
Initializes an iterator for traversing the types in a registry.
Definition type_registry.c:695
c23_nodiscard bool infix_registry_iterator_next(infix_registry_iterator_t *)
Advances the iterator to the next defined type in the registry.
Definition type_registry.c:708
c23_nodiscard const char * infix_registry_iterator_get_name(const infix_registry_iterator_t *)
Gets the name of the type at the iterator's current position.
Definition type_registry.c:755
Internal definition of a registry iterator.
Definition infix_internals.h:190
A semi-opaque structure that describes a C type.
Definition infix.h:211

◆ infix_registry_iterator_get_name()

c23_nodiscard const char * infix_registry_iterator_get_name ( const infix_registry_iterator_t iter)

Gets the name of the type at the iterator's current position.

Parameters
[in]iteratorThe iterator.
Returns
The name of the type (e.g., "MyStruct"), or nullptr if the iterator is invalid or at the end.
Parameters
[in]iteratorThe iterator, which must have been successfully advanced by infix_registry_iterator_next.
Returns
The name of the type (e.g., "Point"), or nullptr if the iterator is invalid or has reached the end of the collection.

◆ infix_registry_iterator_get_type()

c23_nodiscard const infix_type * infix_registry_iterator_get_type ( const infix_registry_iterator_t iter)

Gets the infix_type object of the type at the iterator's current position.

Parameters
[in]iteratorThe iterator.
Returns
A pointer to the canonical infix_type object, or nullptr if the iterator is invalid or at the end.
Parameters
[in]iteratorThe iterator, which must have been successfully advanced by infix_registry_iterator_next.
Returns
A pointer to the canonical infix_type object, or nullptr if the iterator is invalid or has reached the end of the collection.

◆ infix_registry_iterator_next()

c23_nodiscard bool infix_registry_iterator_next ( infix_registry_iterator_t iter)

Advances the iterator to the next defined type in the registry.

Parameters
[in,out]iteratorThe iterator to advance.
Returns
true if the iterator was advanced to a valid type, or false if there are no more types.
Parameters
[in,out]iteratorThe iterator to advance.
Returns
true if the iterator was advanced to a valid type, or false if there are no more types to visit.

◆ infix_registry_lookup_type()

c23_nodiscard const infix_type * infix_registry_lookup_type ( const infix_registry_t registry,
const char *  name 
)

Retrieves the canonical infix_type object for a given name from the registry.

Parameters
[in]registryThe registry to search.
[in]nameThe name of the type to retrieve.
Returns
A pointer to the canonical infix_type object if found and fully defined. Returns nullptr if the name is not found or is only a forward declaration. The returned pointer is owned by the registry and is valid for its lifetime.
Parameters
[in]registryThe registry to search.
[in]nameThe name of the type to retrieve (e.g., "Point").
Returns
A pointer to the canonical infix_type object if found and fully defined. Returns nullptr if the name is not found or is only a forward declaration. The returned pointer is owned by the registry and is valid for its lifetime.

◆ infix_registry_print()

c23_nodiscard infix_status infix_registry_print ( char *  buffer,
size_t  buffer_size,
const infix_registry_t registry 
)

Serializes all defined types within a registry into a single, human-readable string.

The output format is a sequence of definitions (e.g., @Name = { ... };) separated by newlines, suitable for logging, debugging, or saving to a file. This function will not print forward declarations that have not been fully defined.

Parameters
[out]bufferThe output buffer to write the string into.
[in]buffer_sizeThe size of the output buffer.
[in]registryThe registry to serialize.
Returns
INFIX_SUCCESS on success, or INFIX_ERROR_INVALID_ARGUMENT if the buffer is too small.

The output format is a sequence of definitions (e.g., @Name = { ... };) separated by newlines, suitable for logging, debugging, or saving to a file. This function will not print forward declarations that have not been fully defined. The order of definitions in the output string is not guaranteed.

Parameters
[out]bufferThe output buffer to write the string into.
[in]buffer_sizeThe size of the output buffer.
[in]registryThe registry to serialize.
Returns
INFIX_SUCCESS on success, or INFIX_ERROR_INVALID_ARGUMENT if the buffer is too small or another error occurs.