DataType.h 1.3 KB

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