keywords.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. static struct resword {
  3. const char *name;
  4. int token;
  5. } keywords[] = {
  6. { "__GENKSYMS_EXPORT_SYMBOL", EXPORT_SYMBOL_KEYW },
  7. { "__asm", ASM_KEYW },
  8. { "__asm__", ASM_KEYW },
  9. { "__attribute", ATTRIBUTE_KEYW },
  10. { "__attribute__", ATTRIBUTE_KEYW },
  11. { "__const", CONST_KEYW },
  12. { "__const__", CONST_KEYW },
  13. { "__extension__", EXTENSION_KEYW },
  14. { "__inline", INLINE_KEYW },
  15. { "__inline__", INLINE_KEYW },
  16. { "__signed", SIGNED_KEYW },
  17. { "__signed__", SIGNED_KEYW },
  18. { "__typeof", TYPEOF_KEYW },
  19. { "__typeof__", TYPEOF_KEYW },
  20. { "__typeof_unqual", TYPEOF_KEYW },
  21. { "__typeof_unqual__", TYPEOF_KEYW },
  22. { "__volatile", VOLATILE_KEYW },
  23. { "__volatile__", VOLATILE_KEYW },
  24. { "__builtin_va_list", VA_LIST_KEYW },
  25. { "__int128", BUILTIN_INT_KEYW },
  26. { "__int128_t", BUILTIN_INT_KEYW },
  27. { "__uint128_t", BUILTIN_INT_KEYW },
  28. // According to rth, c99 defines "_Bool", "__restrict", "__restrict__", "restrict". KAO
  29. { "_Bool", BOOL_KEYW },
  30. { "__restrict", RESTRICT_KEYW },
  31. { "__restrict__", RESTRICT_KEYW },
  32. { "restrict", RESTRICT_KEYW },
  33. { "asm", ASM_KEYW },
  34. // c11 keywords that can be used at module scope
  35. { "_Static_assert", STATIC_ASSERT_KEYW },
  36. // attribute commented out in modutils 2.4.2. People are using 'attribute' as a
  37. // field name which breaks the genksyms parser. It is not a gcc keyword anyway.
  38. // KAO. },
  39. // { "attribute", ATTRIBUTE_KEYW },
  40. // X86 named address space qualifiers
  41. { "__seg_gs", X86_SEG_KEYW },
  42. { "__seg_fs", X86_SEG_KEYW },
  43. { "auto", AUTO_KEYW },
  44. { "char", CHAR_KEYW },
  45. { "const", CONST_KEYW },
  46. { "double", DOUBLE_KEYW },
  47. { "enum", ENUM_KEYW },
  48. { "extern", EXTERN_KEYW },
  49. { "float", FLOAT_KEYW },
  50. { "inline", INLINE_KEYW },
  51. { "int", INT_KEYW },
  52. { "long", LONG_KEYW },
  53. { "register", REGISTER_KEYW },
  54. { "short", SHORT_KEYW },
  55. { "signed", SIGNED_KEYW },
  56. { "static", STATIC_KEYW },
  57. { "struct", STRUCT_KEYW },
  58. { "typedef", TYPEDEF_KEYW },
  59. { "typeof", TYPEOF_KEYW },
  60. { "typeof_unqual", TYPEOF_KEYW },
  61. { "union", UNION_KEYW },
  62. { "unsigned", UNSIGNED_KEYW },
  63. { "void", VOID_KEYW },
  64. { "volatile", VOLATILE_KEYW },
  65. };
  66. #define NR_KEYWORDS (sizeof(keywords)/sizeof(struct resword))
  67. static int is_reserved_word(register const char *str, register unsigned int len)
  68. {
  69. int i;
  70. for (i = 0; i < NR_KEYWORDS; i++) {
  71. struct resword *r = keywords + i;
  72. int l = strlen(r->name);
  73. if (len == l && !memcmp(str, r->name, len))
  74. return r->token;
  75. }
  76. return -1;
  77. }