DataType.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 : 3;
  11. unsigned int reference : 1;
  12. unsigned int pointers : 4;
  13. unsigned int structId : 24;
  14. } DataType;
  15. typedef struct {
  16. const char* name;
  17. DataType type;
  18. } StructVariable;
  19. typedef struct {
  20. const char* name;
  21. int id;
  22. int amount;
  23. StructVariable* vars;
  24. } Struct;
  25. typedef struct {
  26. int capacity;
  27. int entries;
  28. Struct* data;
  29. } Structs;
  30. int dtGetSize(DataType dt);
  31. DataType dtInt();
  32. DataType dtFloat();
  33. DataType dtBool();
  34. DataType dtVoid();
  35. DataType dtStruct(Struct* st);
  36. DataType dtToReference(DataType dt);
  37. DataType dtToArray(DataType dt, int dimension);
  38. bool dtIsArray(DataType dt);
  39. bool dtCompare(DataType a, DataType b);
  40. int dtMaxDimensions();
  41. const char* dtGetName(Structs* sts, DataType dt);
  42. unsigned int dtAsInt(DataType dt);
  43. void stAddVariable(Struct* st, const char* name, DataType type);
  44. void stsInit(Structs* sts);
  45. void stsDelete(Structs* sts);
  46. Struct* stsSearch(Structs* sts, const char* name);
  47. Struct* stsAdd(Structs* sts, const char* name);
  48. #endif