DataType.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef DATATYPE_H
  2. #define DATATYPE_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <assert.h>
  7. #include <stdbool.h>
  8. #include "Check.h"
  9. #include "Types.h"
  10. typedef enum {
  11. VT_INVALID = 0,
  12. VT_NOT_SET,
  13. VT_INT,
  14. VT_FLOAT,
  15. VT_POINTER,
  16. VT_ARRAY,
  17. VT_LAST
  18. } ValueType;
  19. #define VALUE_TYPE_BIT_SIZE 4
  20. static_assert(VT_LAST < (1 << VALUE_TYPE_BIT_SIZE));
  21. typedef struct {
  22. uint32 typeAndOffset;
  23. union {
  24. int32 intValue;
  25. float32 floatValue;
  26. } data;
  27. } Value;
  28. #define DT_INT 0
  29. #define DT_FLOAT 1
  30. #define DT_VOID 2
  31. #define DT_STRUCT 3
  32. typedef struct {
  33. uint8 type : 7;
  34. uint8 pointer : 1;
  35. uint8 array;
  36. uint16 structId;
  37. } DataType;
  38. typedef struct {
  39. const char* name;
  40. DataType type;
  41. char padding[sizeof(const char*) - sizeof(DataType)];
  42. } StructVariable;
  43. typedef struct {
  44. const char* name;
  45. uint16 id;
  46. char padding[2];
  47. int amount;
  48. StructVariable* vars;
  49. } Struct;
  50. typedef struct {
  51. int capacity;
  52. int entries;
  53. Struct* data;
  54. } Structs;
  55. const char* vtGetName(ValueType vt);
  56. ValueType vGetType(Value v);
  57. check_return bool vSetType(Value* v, ValueType vt);
  58. uint32 vGetOffset(Value v);
  59. check_return bool vSetOffset(Value* v, uint32 offset);
  60. int dtGetSize(DataType dt, const Structs* sts);
  61. DataType dtInt(void);
  62. DataType dtFloat(void);
  63. DataType dtVoid(void);
  64. DataType dtStruct(const Struct* st);
  65. DataType dtText(void);
  66. DataType dtToArray(DataType dt);
  67. DataType dtRemoveArray(DataType dt);
  68. Struct* dtGetStruct(const Structs* sts, DataType dt);
  69. DataType dtToPointer(DataType dt);
  70. bool dtRemovePointer(DataType* dt);
  71. bool dtCompare(DataType a, DataType b);
  72. bool dtIsInt(DataType dt);
  73. bool dtIsFloat(DataType dt);
  74. bool dtIsVoid(DataType dt);
  75. bool dtIsArray(DataType dt);
  76. const char* dtGetName(const Structs* sts, DataType dt);
  77. void stAddVariable(Struct* st, const char* name, DataType type);
  78. void stsInit(Structs* sts);
  79. void stsDelete(Structs* sts);
  80. Struct* stsSearch(Structs* sts, const char* name);
  81. Struct* stsAdd(Structs* sts, const char* name);
  82. void gstsInit(void);
  83. void gstsDelete(void);
  84. Structs* gstsGet(void);
  85. Struct* gstsAdd(const char* name);
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89. #endif