DataType.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. int dtGetSize(DataType dt, Structs* sts);
  30. DataType dtInt();
  31. DataType dtFloat();
  32. DataType dtBool();
  33. DataType dtVoid();
  34. DataType dtStruct(Struct* st);
  35. DataType dtReference(DataType dt);
  36. DataType dtDereference(DataType dt);
  37. DataType dtToArray(DataType dt, int dimension);
  38. bool dtIsPointer(DataType dt);
  39. Struct* dtGetStruct(Structs* sts, DataType dt);
  40. bool dtCompare(DataType a, DataType b);
  41. int dtMaxDimensions();
  42. const char* dtGetName(Structs* sts, DataType dt);
  43. unsigned int dtAsInt(DataType dt);
  44. void stAddVariable(Struct* st, const char* name, DataType type);
  45. void stsInit(Structs* sts);
  46. void stsDelete(Structs* sts);
  47. Struct* stsSearch(Structs* sts, const char* name);
  48. Struct* stsAdd(Structs* sts, const char* name);
  49. #endif