DataType.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef DATATYPE_H
  2. #define DATATYPE_H
  3. #include <stdbool.h>
  4. #define DT_INT 0
  5. #define DT_LONG 1
  6. #define DT_FLOAT 2
  7. #define DT_BOOL 3
  8. #define DT_NULL 4
  9. #define DT_VOID 5
  10. #define DT_STRUCT 6
  11. typedef struct {
  12. unsigned int type : 4;
  13. unsigned int pointers : 4;
  14. unsigned int structId : 24;
  15. } DataType;
  16. typedef struct {
  17. const char* name;
  18. DataType type;
  19. } StructVariable;
  20. typedef struct {
  21. const char* name;
  22. int id;
  23. int amount;
  24. StructVariable* vars;
  25. } Struct;
  26. typedef struct {
  27. int capacity;
  28. int entries;
  29. Struct* data;
  30. } Structs;
  31. typedef struct {
  32. int array;
  33. int offset;
  34. } Pointer;
  35. int dtGetSize(DataType dt, Structs* sts);
  36. DataType dtInt();
  37. DataType dtLong();
  38. DataType dtFloat();
  39. DataType dtBool();
  40. DataType dtNull();
  41. DataType dtVoid();
  42. DataType dtStruct(Struct* st);
  43. DataType dtReference(DataType dt);
  44. bool dtDereference(DataType* dt);
  45. Struct* dtGetStruct(Structs* sts, DataType dt);
  46. DataType dtToVariable(DataType dt);
  47. bool dtRemoveVariable(DataType* dt);
  48. bool dtCompare(DataType a, DataType b);
  49. bool dtIsInt(DataType dt);
  50. bool dtIsLong(DataType dt);
  51. bool dtIsFloat(DataType dt);
  52. bool dtIsBool(DataType dt);
  53. bool dtIsNull(DataType dt);
  54. bool dtIsVoid(DataType dt);
  55. bool dtIsPointer(DataType dt);
  56. bool dtIsVariable(DataType dt);
  57. const char* dtGetName(Structs* sts, DataType dt);
  58. void stAddVariable(Struct* st, const char* name, DataType type);
  59. void stsInit(Structs* sts);
  60. void stsDelete(Structs* sts);
  61. Struct* stsSearch(Structs* sts, const char* name);
  62. Struct* stsAdd(Structs* sts, const char* name);
  63. #endif