123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- #ifndef DATATYPE_H
- #define DATATYPE_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <assert.h>
- #include <stdbool.h>
- #include "Check.h"
- #include "Types.h"
- typedef enum {
- VT_INVALID = 0,
- VT_NOT_SET,
- VT_INT,
- VT_FLOAT,
- VT_POINTER,
- VT_ARRAY,
- VT_LAST
- } ValueType;
- #define VALUE_TYPE_BIT_SIZE 4
- static_assert(VT_LAST < (1 << VALUE_TYPE_BIT_SIZE));
- typedef struct {
- uint32 typeAndOffset;
- union {
- int32 intValue;
- float32 floatValue;
- } data;
- } Value;
- typedef enum {
- RDT_INVALID = 0,
- RDT_INT,
- RDT_FLOAT,
- RDT_VOID,
- RDT_STRUCT,
- RDT_LAST
- } RawDataType;
- typedef struct {
- uint32 data;
- } DataType;
- #define DT_TYPE_BIT_SIZE 4
- #define DT_IS_POINTER_BIT_SIZE 1
- #define DT_IS_ARRAY_BIT_SIZE 1
- #define DT_STRUCT_ID_BIT_SIZE \
- (32 - DT_TYPE_BIT_SIZE - DT_IS_POINTER_BIT_SIZE - DT_IS_ARRAY_BIT_SIZE)
- static_assert(RDT_LAST < (1 << DT_TYPE_BIT_SIZE));
- #define DT_MAX_STRUCT_ID ((1 << DT_STRUCT_ID_BIT_SIZE) - 1)
- #define DT_TYPE_OFFSET 0
- #define DT_IS_POINTER_OFFSET (DT_TYPE_OFFSET + DT_TYPE_BIT_SIZE)
- #define DT_IS_ARRAY_OFFSET (DT_IS_POINTER_OFFSET + DT_IS_POINTER_BIT_SIZE)
- #define DT_STRUCT_ID_OFFSET (DT_IS_ARRAY_OFFSET + DT_IS_ARRAY_BIT_SIZE)
- typedef struct {
- const char* name;
- DataType type;
- char padding[sizeof(const char*) - sizeof(DataType)];
- } StructVariable;
- typedef struct {
- const char* name;
- uint16 id;
- char padding[2];
- int amount;
- StructVariable* vars;
- } Struct;
- typedef struct {
- int capacity;
- int entries;
- Struct* data;
- } Structs;
- check_return const char* vtGetName(ValueType vt);
- check_return ValueType vGetType(Value v);
- check_return bool vSetType(Value* v, ValueType vt);
- check_return int32 vGetOffset(Value v);
- check_return bool vSetOffset(Value* v, int32 offset);
- check_return bool dtGetSize(DataType dt, const Structs* sts, int* size);
- check_return DataType dtInt(void);
- check_return DataType dtFloat(void);
- check_return DataType dtVoid(void);
- check_return DataType dtStruct(const Struct* st);
- check_return DataType dtText(void);
- check_return DataType dtToArray(DataType dt);
- check_return DataType dtRemoveArray(DataType dt);
- check_return Struct* dtGetStruct(const Structs* sts, DataType dt);
- check_return DataType dtToPointer(DataType dt);
- bool dtRemovePointer(DataType* dt);
- check_return RawDataType dtGetType(DataType dt);
- check_return bool dtCompare(DataType a, DataType b);
- check_return bool dtIsInt(DataType dt);
- check_return bool dtIsFloat(DataType dt);
- check_return bool dtIsVoid(DataType dt);
- check_return bool dtIsArray(DataType dt);
- check_return bool dtIsStruct(DataType dt);
- check_return bool dtIsPointer(DataType dt);
- check_return const char* dtGetName(const Structs* sts, DataType dt);
- void stAddVariable(Struct* st, const char* name, DataType type);
- void stsInit(Structs* sts);
- void stsDelete(Structs* sts);
- check_return Struct* stsSearch(Structs* sts, const char* name);
- check_return Struct* stsAdd(Structs* sts, const char* name);
- void gstsInit(void);
- void gstsDelete(void);
- check_return Structs* gstsGet(void);
- check_return Struct* gstsAdd(const char* name);
- #ifdef __cplusplus
- }
- #endif
- #endif
|