Mesa (master): glcpp: Fix so that trailing punctuation does not prevent macro expansion

Carl Worth cworth at kemper.freedesktop.org
Thu Feb 2 21:29:45 UTC 2012


Module: Mesa
Branch: master
Commit: 7ab1c7f7926c75a07f33eb149d0fc17dcfaffd5e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7ab1c7f7926c75a07f33eb149d0fc17dcfaffd5e

Author: Carl Worth <cworth at cworth.org>
Date:   Sat Jan 21 09:24:11 2012 -0800

glcpp: Fix so that trailing punctuation does not prevent macro expansion

The trick here is that flex always chooses the rule that matches the most
text. So with a input text of "two:" which we want to be lexed as an
IDENTIFIER token "two" followed by an OTHER token ":" the previous OTHER
rule would match longer as a single token of "two:" which we don't want.

We prevent this by forcing the OTHER pattern to never match any
characters that appear in other constructs, (no letters, numbers, #,
_, whitespace, nor any punctuation that appear in CPP operators).

Fixes bug #44764:

	GLSL preprocessor doesn't replace defines ending with ":"
	https://bugs.freedesktop.org/show_bug.cgi?id=44764

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

NOTE: This is a candidate for stable release branches.

---

 src/glsl/glcpp/glcpp-lex.l |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
index 8661887..b34f2c0 100644
--- a/src/glsl/glcpp/glcpp-lex.l
+++ b/src/glsl/glcpp/glcpp-lex.l
@@ -70,7 +70,15 @@ HSPACE		[ \t]
 HASH		^{HSPACE}*#{HSPACE}*
 IDENTIFIER	[_a-zA-Z][_a-zA-Z0-9]*
 PUNCTUATION	[][(){}.&*~!/%<>^|;,=+-]
-OTHER		[^][(){}.&*~!/%<>^|;,=#[:space:]+-]+
+
+/* The OTHER class is simply a catch-all for things that the CPP
+parser just doesn't care about. Since flex regular expressions that
+match longer strings take priority over those matching shorter
+strings, we have to be careful to avoid OTHER matching and hiding
+something that CPP does care about. So we simply exclude all
+characters that appear in any other expressions. */
+
+OTHER		[^][_#[:space:]#a-zA-Z0-9(){}.&*~!/%<>^|;,=+-]
 
 DIGITS			[0-9][0-9]*
 DECIMAL_INTEGER		[1-9][0-9]*[uU]?




More information about the mesa-commit mailing list