DataType.h 1.8 KB

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