lj_cparse.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. ** C declaration parser.
  3. ** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #ifndef _LJ_CPARSE_H
  6. #define _LJ_CPARSE_H
  7. #include "lj_obj.h"
  8. #include "lj_ctype.h"
  9. #if LJ_HASFFI
  10. /* C parser limits. */
  11. #define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */
  12. #define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */
  13. #define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */
  14. #define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */
  15. /* Flags for C parser mode. */
  16. #define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */
  17. #define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */
  18. #define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */
  19. #define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */
  20. #define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */
  21. #define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */
  22. typedef int CPChar; /* C parser character. Unsigned ext. from char. */
  23. typedef int CPToken; /* C parser token. */
  24. /* C parser internal value representation. */
  25. typedef struct CPValue {
  26. union {
  27. int32_t i32; /* Value for CTID_INT32. */
  28. uint32_t u32; /* Value for CTID_UINT32. */
  29. };
  30. CTypeID id; /* C Type ID of the value. */
  31. } CPValue;
  32. /* C parser state. */
  33. typedef struct CPState {
  34. CPChar c; /* Current character. */
  35. CPToken tok; /* Current token. */
  36. CPValue val; /* Token value. */
  37. GCstr *str; /* Interned string of identifier/keyword. */
  38. CType *ct; /* C type table entry. */
  39. const char *p; /* Current position in input buffer. */
  40. SBuf sb; /* String buffer for tokens. */
  41. lua_State *L; /* Lua state. */
  42. CTState *cts; /* C type state. */
  43. TValue *param; /* C type parameters. */
  44. const char *srcname; /* Current source name. */
  45. BCLine linenumber; /* Input line counter. */
  46. int depth; /* Recursive declaration depth. */
  47. uint32_t tmask; /* Type mask for next identifier. */
  48. uint32_t mode; /* C parser mode. */
  49. uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */
  50. uint8_t curpack; /* Current position in pack pragma stack. */
  51. } CPState;
  52. LJ_FUNC int lj_cparse(CPState *cp);
  53. LJ_FUNC int lj_cparse_case(GCstr *str, const char *match);
  54. #endif
  55. #endif