[Mesa-dev] [PATCH 2/5] glsl: Extend s-expression parsing to handle infinity.
Paul Berry
stereotype441 at gmail.com
Wed Oct 26 18:42:53 PDT 2011
In order to implement the GLSL 1.30 isinf() function, it will be
necessary to be able to represent infinity in the GLSL IR s-expression
format. This patch extends the s-expression parser so that it treats
the string "#inf" as a floating point value representing positive
infinity.
---
src/glsl/s_expression.cpp | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/src/glsl/s_expression.cpp b/src/glsl/s_expression.cpp
index e704a3b..4391488 100644
--- a/src/glsl/s_expression.cpp
+++ b/src/glsl/s_expression.cpp
@@ -64,21 +64,26 @@ read_atom(void *ctx, const char *&src, char *&symbol_buffer)
if (n == 0)
return NULL; // no atom
- // Check if the atom is a number.
- char *float_end = NULL;
- double f = glsl_strtod(src, &float_end);
- if (float_end != src) {
- char *int_end = NULL;
- int i = strtol(src, &int_end, 10);
- // If strtod matched more characters, it must have a decimal part
- if (float_end > int_end)
- expr = new(ctx) s_float(f);
- else
- expr = new(ctx) s_int(i);
+ // Check for the special symbol '#inf', which means +Infinity
+ if (n == 4 && strncmp(src, "#inf", 4) == 0) {
+ expr = new(ctx) s_float(INFINITY);
} else {
- // Not a number; return a symbol.
- symbol_buffer[n] = '\0';
- expr = new(ctx) s_symbol(symbol_buffer, n);
+ // Check if the atom is a number.
+ char *float_end = NULL;
+ double f = glsl_strtod(src, &float_end);
+ if (float_end != src) {
+ char *int_end = NULL;
+ int i = strtol(src, &int_end, 10);
+ // If strtod matched more characters, it must have a decimal part
+ if (float_end > int_end)
+ expr = new(ctx) s_float(f);
+ else
+ expr = new(ctx) s_int(i);
+ } else {
+ // Not a number; return a symbol.
+ symbol_buffer[n] = '\0';
+ expr = new(ctx) s_symbol(symbol_buffer, n);
+ }
}
src += n;
--
1.7.6.4
More information about the mesa-dev
mailing list