glcpp: Don't use infinite lookhead for #define differentiation.
authorKenneth Graunke <kenneth@whitecape.org>
Mon, 22 Oct 2012 17:56:46 +0000 (10:56 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 25 Oct 2012 21:52:53 +0000 (14:52 -0700)
commit9142ade15416415f2d5eb20b093b898c649cd2bb
tree48292bfda5326e7696bc830fe31320cf860c50df
parenteeb2fb72eb4f573410eae45896bc744d6c47b4d6
glcpp: Don't use infinite lookhead for #define differentiation.

Previously, we used lookahead patterns to differentiate:

   #define FOO(x)  function macro
   #define FOO (x) object macro

Unfortunately, our rule for function macros:

   {HASH}define{HSPACE}+/{IDENTIFIER}"("

relies on infinite lookahead, and apparently triggers a Flex bug where
the generated code overflows a state buffer (see YY_STATE_BUF_SIZE).

There's no need to use infinite lookahead.  We can simply change state,
match the identifier, and use a single character lookahead for the '('.
This apparently makes Flex not generate the giant state array, which
avoids the buffer overflow, and should be more efficient anyway.

Fixes piglit test 17000-consecutive-chars-identifier.frag.

NOTE: This is a candidate for every release branch ever.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Carl Worth <cworth@cworth.org>
src/glsl/glcpp/glcpp-lex.l
src/glsl/glcpp/glcpp-parse.y