DataType.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 DT_INT32 0
  9. #define DT_INT64 1
  10. #define DT_FLOAT 2
  11. #define DT_BOOL 3
  12. #define DT_NULL 4
  13. #define DT_VOID 5
  14. #define DT_STRUCT 6
  15. typedef struct {
  16. unsigned int type : 4;
  17. unsigned int pointers : 4;
  18. unsigned int constant : 1;
  19. unsigned int structId : 23;
  20. } DataType;
  21. typedef struct {
  22. const char* name;
  23. DataType type;
  24. } StructVariable;
  25. typedef struct {
  26. const char* name;
  27. int id;
  28. int amount;
  29. StructVariable* vars;
  30. } Struct;
  31. typedef struct {
  32. int capacity;
  33. int entries;
  34. Struct* data;
  35. } Structs;
  36. typedef struct {
  37. int32 array;
  38. int32 offset;
  39. } Pointer;
  40. int dtGetSize(DataType dt, Structs* sts);
  41. DataType dtInt32();
  42. DataType dtInt64();
  43. DataType dtFloat();
  44. DataType dtBool();
  45. DataType dtNull();
  46. DataType dtText();
  47. DataType dtVoid();
  48. DataType dtStruct(Struct* st);
  49. DataType dtReference(DataType dt);
  50. bool dtDereference(DataType* dt);
  51. Struct* dtGetStruct(Structs* sts, DataType dt);
  52. DataType dtToVariable(DataType dt);
  53. bool dtRemoveVariable(DataType* dt);
  54. DataType dtConst(DataType dt);
  55. bool dtCompare(DataType a, DataType b);
  56. bool dtNullCompare(DataType a, DataType bOrNull);
  57. bool dtIsInt32(DataType dt);
  58. bool dtIsInt64(DataType dt);
  59. bool dtIsFloat(DataType dt);
  60. bool dtIsBool(DataType dt);
  61. bool dtIsNull(DataType dt);
  62. bool dtIsVoid(DataType dt);
  63. bool dtIsPointer(DataType dt);
  64. bool dtIsVariable(DataType dt);
  65. const char* dtGetName(Structs* sts, DataType dt);
  66. void stAddVariable(Struct* st, const char* name, DataType type);
  67. void stsInit(Structs* sts);
  68. void stsDelete(Structs* sts);
  69. Struct* stsSearch(Structs* sts, const char* name);
  70. Struct* stsAdd(Structs* sts, const char* name);
  71. void gstsInit();
  72. void gstsDelete();
  73. Structs* gstsGet();
  74. Struct* gstsAdd(const char* name);
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif