Merge type and parsetype into a single struct.
It doesn't make sense to re-create the same structure, or even re-allocated any of the memory.
This commit is contained in:
@@ -3,15 +3,11 @@
|
||||
|
||||
#include "result.h"
|
||||
#include "vec.h"
|
||||
#include "basetype.h"
|
||||
|
||||
/**
|
||||
* The variant of the given parse type.
|
||||
*/
|
||||
enum libab_parsetype_variant_e {
|
||||
PT_STRING,
|
||||
PT_PLACEHOLDER,
|
||||
PT_PARENT
|
||||
};
|
||||
#define LIBABACUS_TYPE_F_PARENT (1)
|
||||
#define LIBABACUS_TYPE_F_PLACE (1 << 1)
|
||||
#define LIBABACUS_TYPE_F_RESOLVED (1 << 2)
|
||||
|
||||
/**
|
||||
* A parse type.
|
||||
@@ -26,11 +22,20 @@ struct libab_parsetype_s {
|
||||
/**
|
||||
* The variant of the given parse type.
|
||||
*/
|
||||
enum libab_parsetype_variant_e variant;
|
||||
int variant;
|
||||
/**
|
||||
* The name of the type that this parse type describes.
|
||||
* Union that represents the data carried by this type.
|
||||
*/
|
||||
char* name;
|
||||
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;
|
||||
/**
|
||||
* A vector of children that this parse type contains.
|
||||
* The children are effectively type parameters.
|
||||
@@ -38,7 +43,6 @@ struct libab_parsetype_s {
|
||||
vec children;
|
||||
};
|
||||
|
||||
typedef enum libab_parsetype_variant_e libab_parsetype_variant;
|
||||
typedef struct libab_parsetype_s libab_parsetype;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#ifndef LIBABACUS_TYPE_H
|
||||
#define LIBABACUS_TYPE_H
|
||||
|
||||
#include "ref_vec.h"
|
||||
#include "basetype.h"
|
||||
|
||||
/**
|
||||
* A type instance. This is created at runtime
|
||||
* for every value that has a type, and represents an instance
|
||||
* of a basetype with concrete (though possibly templated) parameters.
|
||||
*/
|
||||
struct libab_type_s {
|
||||
/**
|
||||
* The base type that this type is an instance of.
|
||||
*/
|
||||
libab_basetype* base;
|
||||
/**
|
||||
* The list of parameters this type holds.
|
||||
*/
|
||||
libab_ref_vec params;
|
||||
};
|
||||
|
||||
typedef struct libab_type_s libab_type;
|
||||
|
||||
/**
|
||||
* Initializes a given type with the given basetype.
|
||||
* @param type the type to initialize.
|
||||
* @param base the base type to use.
|
||||
* @return the result of the initialization.
|
||||
*/
|
||||
libab_result libab_type_init(libab_type* type, libab_basetype* base);
|
||||
/**
|
||||
* Frees the memory allocated by the given type.
|
||||
* @param type the type to free.
|
||||
*/
|
||||
void libab_type_free(libab_type* type);
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef LIBABACUS_VALUE_H
|
||||
#define LIBABACUS_VALUE_H
|
||||
|
||||
#include "type.h"
|
||||
#include "result.h"
|
||||
#include "refcount.h"
|
||||
|
||||
/**
|
||||
* A struct that represents a value.
|
||||
|
||||
Reference in New Issue
Block a user