flex-scanner.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Common parts between scan-code.l, scan-gram.l, and scan-skel.l.
  2. Copyright (C) 2006, 2009-2015, 2018-2021 Free Software Foundation,
  3. Inc.
  4. This file is part of Bison, the GNU Compiler Compiler.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  15. #ifndef FLEX_PREFIX
  16. # error "FLEX_PREFIX not defined"
  17. #endif
  18. /* Flex full version as a number. */
  19. #define FLEX_VERSION \
  20. ((YY_FLEX_MAJOR_VERSION) * 1000000 \
  21. + (YY_FLEX_MINOR_VERSION) * 1000 \
  22. + (YY_FLEX_SUBMINOR_VERSION))
  23. // Pacify warnings in yy_init_buffer (observed with Flex 2.6.4 and GCC
  24. // 6.4.0 and 7.3.0).
  25. //
  26. // ./src/scan-skel.c: In function 'skel_restart':
  27. // ./src/scan-skel.c:2035:20: error: potential null pointer dereference [-Werror=null-dereference]
  28. // b->yy_fill_buffer = 1;
  29. // ~~~~~~~~~~~~~~~~~~^~~
  30. // ./src/scan-skel.c:2031:19: error: potential null pointer dereference [-Werror=null-dereference]
  31. // b->yy_input_file = file;
  32. // ~~~~~~~~~~~~~~~~~^~~~~~
  33. #if defined __GNUC__ && ! defined __clang__ && 6 <= __GNUC__
  34. # pragma GCC diagnostic ignored "-Wnull-dereference"
  35. #endif
  36. // Old versions of Flex (2.5.35) generate an incomplete documentation comment.
  37. //
  38. // In file included from src/scan-code-c.c:3:
  39. // src/scan-code.c:2198:21: error: empty paragraph passed to '@param' command
  40. // [-Werror,-Wdocumentation]
  41. // * @param line_number
  42. // ~~~~~~~~~~~~~~~~~^
  43. // 1 error generated.
  44. #if FLEX_VERSION <= 20060000 && defined __clang__
  45. # pragma clang diagnostic ignored "-Wdocumentation"
  46. #endif
  47. /* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used. */
  48. #if FLEX_VERSION <= 2005031
  49. int FLEX_PREFIX (get_lineno) (void);
  50. FILE *FLEX_PREFIX (get_in) (void);
  51. FILE *FLEX_PREFIX (get_out) (void);
  52. int FLEX_PREFIX (get_leng) (void);
  53. char *FLEX_PREFIX (get_text) (void);
  54. void FLEX_PREFIX (set_lineno) (int);
  55. void FLEX_PREFIX (set_in) (FILE *);
  56. void FLEX_PREFIX (set_out) (FILE *);
  57. int FLEX_PREFIX (get_debug) (void);
  58. void FLEX_PREFIX (set_debug) (int);
  59. int FLEX_PREFIX (lex_destroy) (void);
  60. #endif
  61. #define last_string FLEX_PREFIX (last_string)
  62. /* It seems to be a nice "feature" of Flex that one cannot use yytext,
  63. yyleng etc. when a prefix is given, since there is no longer a
  64. #define, but rather the token is actually changed in the output.
  65. However, this is not true for Flex 2.5.4. */
  66. #ifndef yyleng
  67. # define yyleng FLEX_PREFIX (leng)
  68. #endif
  69. #ifndef yytext
  70. # define yytext FLEX_PREFIX (text)
  71. #endif
  72. /* Non-reentrant scanners generated by Flex 2.5.9 and later (and some earlier
  73. versions according to the Flex manual) leak memory if yylex_destroy is not
  74. invoked. However, yylex_destroy is not defined before Flex 2.5.9, so give
  75. an implementation here that at least appears to work with Flex 2.5.4. */
  76. #if FLEX_VERSION <= 2005009
  77. # define yylex_destroy() yy_delete_buffer (YY_CURRENT_BUFFER)
  78. #endif
  79. /* OBSTACK_FOR_STRING -- Used to store all the characters that we need to
  80. keep (to construct ID, STRINGS etc.). Use the following macros to
  81. use it.
  82. Use STRING_GROW () to append what has just been matched, and
  83. STRING_FINISH () to end the string (it puts the ending 0).
  84. STRING_FINISH () also stores this string in LAST_STRING, which can be
  85. used, and which is used by STRING_FREE () to free the last string. */
  86. #ifndef FLEX_NO_OBSTACK
  87. static struct obstack obstack_for_string;
  88. # define STRING_GROW() \
  89. obstack_grow (&obstack_for_string, yytext, yyleng)
  90. # define STRING_FINISH() \
  91. (last_string = obstack_finish0 (&obstack_for_string))
  92. # define STRING_1GROW(Char) \
  93. obstack_1grow (&obstack_for_string, Char)
  94. # ifdef NDEBUG
  95. # define STRING_FREE() \
  96. obstack_free (&obstack_for_string, last_string)
  97. # else
  98. # define STRING_FREE() \
  99. do { \
  100. obstack_free (&obstack_for_string, last_string); \
  101. last_string = NULL; \
  102. } while (0)
  103. # endif
  104. #endif