struct_table.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef DD_STRUCT_TABLE_H
  2. #define DD_STRUCT_TABLE_H
  3. // get variable types
  4. #include "dd_variable_type.h"
  5. // struct sizes
  6. #define DD_STRUCT_TABLE_NAME_SIZE 100
  7. #define DD_STRUCT_TABLE_MEMBER_TOTAL 100
  8. // struct members
  9. struct struct_table_entry_member {
  10. char name[DD_STRUCT_TABLE_NAME_SIZE];
  11. enum dd_variable_type type;
  12. char nametype[DD_STRUCT_TABLE_NAME_SIZE];
  13. int arrayCount;
  14. int isRef;
  15. };
  16. // structs
  17. struct struct_table_entry {
  18. char name[DD_STRUCT_TABLE_NAME_SIZE];
  19. struct struct_table_entry_member members[100];
  20. int member_total;
  21. int parent;
  22. };
  23. // struct table
  24. #define DD_STRUCT_TABLE_TOTAL 100
  25. extern struct struct_table_entry struct_table[DD_STRUCT_TABLE_TOTAL];
  26. extern int struct_table_current;
  27. // functions
  28. void struct_table_init();
  29. // push/pop a struct to the table, optionally with a parent name (or `0` for none)
  30. // same for members
  31. int struct_table_push(const char *structname, const char *parentname);
  32. void struct_table_pop();
  33. struct struct_table_entry_member *struct_table_push_member(const char *name, enum dd_variable_type type, const char *nametype, int isRef);
  34. void struct_table_push_member_array(const char *name, enum dd_variable_type type, const char *nametype, int arrayCount, int isRef);
  35. // print all structs and their members -- this is meant for debug only
  36. void struct_table_print();
  37. // get name of struct, or name of member of struct, on given indices
  38. const char *struct_table_get_name(int structIndex);
  39. int struct_table_get_index(const char *structname);
  40. const char *struct_table_get_member_name(int structIndex, int memberIndex);
  41. int struct_table_getMemberArrayCount(int structIndex, int memberIndex);
  42. int struct_table_getMemberIsRef(int structIndex, int memberIndex);
  43. // get struct member type
  44. enum dd_variable_type struct_table_get_member_type(int structIndex, int memberIndex);
  45. // check if member is a primitive type, primitives are int, float and string
  46. int struct_table_is_member_primitive(int structIndex, int memberIndex);
  47. int struct_table_is_member_primitive_string(int structIndex, const char *membername);
  48. // get index of member
  49. int struct_table_get_member(int structIndex, const char *membername);
  50. // check if the given member is a member of one of the parents
  51. int struct_table_has_member(int structIndex, const char *membername);
  52. int struct_table_has_member_parent(int structIndex, const char *membername);
  53. int struct_table_is_member_parent(int structIndex, const char *membername);
  54. int struct_table_get_member_scope(int structIndex, int memberIndex);
  55. int struct_table_get_member_scope_string(int structIndex, const char *memberIndex);
  56. int struct_table_get_parent(int structIndex);
  57. unsigned int struct_table_get_member_total(int structIndex);
  58. char *struct_table_get_member_nametype(int structIndex, int memberIndex);
  59. // getters
  60. int struct_table_count();
  61. int struct_table_exists(const char *structname);
  62. #endif