DataType.h 2.0 KB

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