2018-03-06 16:44:56 -08:00
|
|
|
#ifndef LIBABACUS_PARSETYPE_H
|
|
|
|
#define LIBABACUS_PARSETYPE_H
|
|
|
|
|
2018-04-17 15:49:09 -07:00
|
|
|
#include "basetype.h"
|
2018-04-21 14:09:01 -07:00
|
|
|
#include "ref_vec.h"
|
|
|
|
#include "result.h"
|
2018-03-06 16:44:56 -08:00
|
|
|
|
2018-04-17 15:49:09 -07:00
|
|
|
#define LIBABACUS_TYPE_F_PARENT (1)
|
|
|
|
#define LIBABACUS_TYPE_F_PLACE (1 << 1)
|
|
|
|
#define LIBABACUS_TYPE_F_RESOLVED (1 << 2)
|
2018-03-06 16:44:56 -08:00
|
|
|
|
|
|
|
/**
|
2018-04-17 22:14:07 -07:00
|
|
|
* A type, either parsed or resolved.
|
2018-03-06 16:44:56 -08:00
|
|
|
*/
|
|
|
|
struct libab_parsetype_s {
|
|
|
|
/**
|
|
|
|
* The variant of the given parse type.
|
|
|
|
*/
|
2018-04-17 15:49:09 -07:00
|
|
|
int variant;
|
2018-03-06 16:44:56 -08:00
|
|
|
/**
|
2018-04-17 15:49:09 -07:00
|
|
|
* Union that represents the data carried by this type.
|
2018-03-06 16:44:56 -08:00
|
|
|
*/
|
2018-04-17 15:49:09 -07:00
|
|
|
union {
|
|
|
|
/**
|
|
|
|
* The name of the type that this parse type describes.
|
|
|
|
*/
|
|
|
|
char* name;
|
|
|
|
/**
|
|
|
|
* The pointer to the base of this type.
|
|
|
|
*/
|
|
|
|
libab_basetype* base;
|
|
|
|
} data_u;
|
2018-03-06 16:44:56 -08:00
|
|
|
/**
|
|
|
|
* A vector of children that this parse type contains.
|
|
|
|
* The children are effectively type parameters.
|
|
|
|
*/
|
2018-04-17 22:14:07 -07:00
|
|
|
libab_ref_vec children;
|
2018-03-06 16:44:56 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct libab_parsetype_s libab_parsetype;
|
|
|
|
|
2018-04-22 20:44:08 -07:00
|
|
|
/**
|
|
|
|
* Creates a new type instance.
|
|
|
|
* @param into the reference to store the new type into.
|
|
|
|
* @param from the basetype to instantiate.
|
|
|
|
* @param n the number of type parameters.
|
|
|
|
* @return the result of the instantiation.
|
|
|
|
*/
|
|
|
|
libab_result libab_parsetype_init(libab_parsetype* into, libab_basetype* from,
|
|
|
|
size_t n, ...);
|
|
|
|
/**
|
|
|
|
* Same as _init, but using a pre-initialized va_list.
|
|
|
|
* @param into the reference to store the new type into.
|
|
|
|
* @param from the basetype to instantiate.
|
|
|
|
* @param n the number of type parameters.
|
|
|
|
* @param args the list of parameters to this parsetype.
|
|
|
|
* @return the result of the instantiation.
|
|
|
|
*/
|
|
|
|
libab_result libab_parsetype_init_va(libab_parsetype* into, libab_basetype* from,
|
|
|
|
size_t n, va_list args);
|
|
|
|
|
2018-03-06 16:44:56 -08:00
|
|
|
/**
|
|
|
|
* Frees the data associated with this type, ignoring
|
|
|
|
* its children.
|
|
|
|
* @param type the type to free.
|
|
|
|
*/
|
|
|
|
void libab_parsetype_free(libab_parsetype* type);
|
|
|
|
|
|
|
|
#endif
|