parser.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "cpp.h"
  2. struct cp_ctx;
  3. typedef struct cp_ctx cp_ctx_t;
  4. typedef struct ast_type {
  5. char type; // s, e, u, [b]uiltin
  6. int stars;
  7. uint32_t specs;
  8. lexer_token_t* type_name;
  9. } ast_type_t;
  10. typedef struct ast_typedef {
  11. lexer_token_t* name;
  12. VEC(lexer_token_t*) names;
  13. VEC(lexer_token_t*) specs;
  14. } ast_typedef_t;
  15. typedef struct ast_var_def {
  16. lexer_token_t* name;
  17. ast_type_t* type;
  18. VEC(unsigned long) array_dims;
  19. } ast_var_def_t;
  20. typedef struct ast_struct_def {
  21. lexer_token_t* name; // NULL for anonymous structs
  22. VEC(ast_var_def_t*) members;
  23. } ast_struct_def_t;
  24. typedef struct ast_union_def {
  25. lexer_token_t* name;
  26. VEC(ast_var_def_t*) members;
  27. } ast_union_def_t;
  28. typedef struct ast_symbol {
  29. char type; // s, u, v, ?
  30. char* name;
  31. union {
  32. ast_struct_def_t* Struct;
  33. ast_union_def_t* Union;
  34. ast_var_def_t* Var;
  35. };
  36. } ast_symbol_t;
  37. typedef struct ast_symbol_table {
  38. // TODO:
  39. HT(ast_symbol_t*) seu; // struct, enum, union
  40. HT(ast_symbol_t*) fbt; // functions, builtins, and typedefs
  41. struct ast_symbol_table* next;
  42. } ast_symbol_table_t;
  43. typedef struct ast_tu {
  44. cpp_tu_t* cpp;
  45. // VEC(ast_typedef_t*) typedefs;
  46. // VEC(ast_type_t*) types;
  47. // VEC(ast_struct_t*) structs;
  48. // VEC(ast_enum_t*) enums;
  49. ast_symbol_table_t* globals;
  50. } ast_tu_t;
  51. void cp_ctx_init(cp_ctx_t* ctx);
  52. void c_parser_tu(cpp_tu_t* cpp_tu, ast_tu_t* tu);