Mesa (glsl-pp-rework-2): glsl/pp: Differentiate between integer and floating-point number tokens.

Michał Król michal at kemper.freedesktop.org
Tue Sep 22 11:21:35 UTC 2009


Module: Mesa
Branch: glsl-pp-rework-2
Commit: 0481e85af7195e13c30580afba233a80feeee740
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0481e85af7195e13c30580afba233a80feeee740

Author: Michal Krol <michal at vmware.com>
Date:   Tue Sep 22 12:51:08 2009 +0200

glsl/pp: Differentiate between integer and floating-point number tokens.

---

 src/glsl/pp/sl_pp_error.c      |    8 ++++++--
 src/glsl/pp/sl_pp_expression.c |    4 ++--
 src/glsl/pp/sl_pp_if.c         |    8 ++++----
 src/glsl/pp/sl_pp_line.c       |    8 ++++----
 src/glsl/pp/sl_pp_macro.c      |    4 ++--
 src/glsl/pp/sl_pp_token.c      |   19 +++++++++++++++----
 src/glsl/pp/sl_pp_token.h      |    6 ++++--
 src/glsl/pp/sl_pp_version.c    |    4 ++--
 8 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/src/glsl/pp/sl_pp_error.c b/src/glsl/pp/sl_pp_error.c
index d42568d..e591f4b 100644
--- a/src/glsl/pp/sl_pp_error.c
+++ b/src/glsl/pp/sl_pp_error.c
@@ -239,8 +239,12 @@ sl_pp_process_error(struct sl_pp_context *context,
          s = sl_pp_context_cstr(context, input[i].data.identifier);
          break;
 
-      case SL_PP_NUMBER:
-         s = sl_pp_context_cstr(context, input[i].data.number);
+      case SL_PP_UINT:
+         s = sl_pp_context_cstr(context, input[i].data._uint);
+         break;
+
+      case SL_PP_FLOAT:
+         s = sl_pp_context_cstr(context, input[i].data._float);
          break;
 
       case SL_PP_OTHER:
diff --git a/src/glsl/pp/sl_pp_expression.c b/src/glsl/pp/sl_pp_expression.c
index 6b2329e..5093ef6 100644
--- a/src/glsl/pp/sl_pp_expression.c
+++ b/src/glsl/pp/sl_pp_expression.c
@@ -42,8 +42,8 @@ static int
 _parse_primary(struct parse_context *ctx,
                int *result)
 {
-   if (ctx->input->token == SL_PP_NUMBER) {
-      *result = atoi(sl_pp_context_cstr(ctx->context, ctx->input->data.number));
+   if (ctx->input->token == SL_PP_UINT) {
+      *result = atoi(sl_pp_context_cstr(ctx->context, ctx->input->data._uint));
       ctx->input++;
    } else {
       if (ctx->input->token != SL_PP_LPAREN) {
diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c
index cf1c746..5fa27fc 100644
--- a/src/glsl/pp/sl_pp_if.c
+++ b/src/glsl/pp/sl_pp_if.c
@@ -81,13 +81,13 @@ _parse_defined(struct sl_pp_context *context,
       (*pi)++;
    }
 
-   result.token = SL_PP_NUMBER;
+   result.token = SL_PP_UINT;
    if (defined) {
-      result.data.number = sl_pp_context_add_unique_str(context, "1");
+      result.data._uint = sl_pp_context_add_unique_str(context, "1");
    } else {
-      result.data.number = sl_pp_context_add_unique_str(context, "0");
+      result.data._uint = sl_pp_context_add_unique_str(context, "0");
    }
-   if (result.data.number == -1) {
+   if (result.data._uint == -1) {
       return -1;
    }
 
diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c
index cab0262..e8f7510 100644
--- a/src/glsl/pp/sl_pp_line.c
+++ b/src/glsl/pp/sl_pp_line.c
@@ -67,8 +67,8 @@ sl_pp_process_line(struct sl_pp_context *context,
       }
    }
 
-   if (state.out_len > 0 && state.out[0].token == SL_PP_NUMBER) {
-      line_number = state.out[0].data.number;
+   if (state.out_len > 0 && state.out[0].token == SL_PP_UINT) {
+      line_number = state.out[0].data._uint;
    } else {
       strcpy(context->error_msg, "expected a number after `#line'");
       free(state.out);
@@ -76,8 +76,8 @@ sl_pp_process_line(struct sl_pp_context *context,
    }
 
    if (state.out_len > 1) {
-      if (state.out[1].token == SL_PP_NUMBER) {
-         file_number = state.out[1].data.number;
+      if (state.out[1].token == SL_PP_UINT) {
+         file_number = state.out[1].data._uint;
       } else {
          strcpy(context->error_msg, "expected a number after line number");
          free(state.out);
diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c
index 878b22e..3956ba3 100644
--- a/src/glsl/pp/sl_pp_macro.c
+++ b/src/glsl/pp/sl_pp_macro.c
@@ -105,8 +105,8 @@ _out_number(struct sl_pp_context *context,
 
    sprintf(buf, "%u", number);
 
-   ti.token = SL_PP_NUMBER;
-   ti.data.number = sl_pp_context_add_unique_str(context, buf);
+   ti.token = SL_PP_UINT;
+   ti.data._uint = sl_pp_context_add_unique_str(context, buf);
    if (sl_pp_process_out(state, &ti)) {
       strcpy(context->error_msg, "out of memory");
       return -1;
diff --git a/src/glsl/pp/sl_pp_token.c b/src/glsl/pp/sl_pp_token.c
index 3a7ffe7..99a32a6 100644
--- a/src/glsl/pp/sl_pp_token.c
+++ b/src/glsl/pp/sl_pp_token.c
@@ -271,6 +271,7 @@ _tokenise_number(struct sl_pp_context *context,
 {
    const char *input = *pinput;
    unsigned int eaten;
+   unsigned int is_float = 0;
    char number[256];   /* XXX: Remove this artifical limit. */
 
    eaten = _parse_float(input);
@@ -282,6 +283,8 @@ _tokenise_number(struct sl_pp_context *context,
             eaten = _parse_dec(input);
          }
       }
+   } else {
+      is_float = 1;
    }
 
    if (!eaten || _is_identifier_char(input[eaten])) {
@@ -297,10 +300,18 @@ _tokenise_number(struct sl_pp_context *context,
    memcpy(number, input, eaten);
    number[eaten] = '\0';
 
-   info->token = SL_PP_NUMBER;
-   info->data.number = sl_pp_context_add_unique_str(context, number);
-   if (info->data.number == -1) {
-      return -1;
+   if (is_float) {
+      info->token = SL_PP_FLOAT;
+      info->data._float = sl_pp_context_add_unique_str(context, number);
+      if (info->data._float == -1) {
+         return -1;
+      }
+   } else {
+      info->token = SL_PP_UINT;
+      info->data._uint = sl_pp_context_add_unique_str(context, number);
+      if (info->data._uint == -1) {
+         return -1;
+      }
    }
 
    *pinput = input + eaten;
diff --git a/src/glsl/pp/sl_pp_token.h b/src/glsl/pp/sl_pp_token.h
index 4131be6..2a7b79e 100644
--- a/src/glsl/pp/sl_pp_token.h
+++ b/src/glsl/pp/sl_pp_token.h
@@ -82,7 +82,8 @@ enum sl_pp_token {
 
    SL_PP_IDENTIFIER,
 
-   SL_PP_NUMBER,
+   SL_PP_UINT,
+   SL_PP_FLOAT,
 
    SL_PP_OTHER,
 
@@ -102,7 +103,8 @@ enum sl_pp_token {
 
 union sl_pp_token_data {
    int identifier;
-   int number;
+   int _uint;
+   int _float;
    char other;
    int pragma;
    int extension;
diff --git a/src/glsl/pp/sl_pp_version.c b/src/glsl/pp/sl_pp_version.c
index 825967d..adf3017 100644
--- a/src/glsl/pp/sl_pp_version.c
+++ b/src/glsl/pp/sl_pp_version.c
@@ -99,8 +99,8 @@ sl_pp_version(struct sl_pp_context *context,
             i++;
             break;
 
-         case SL_PP_NUMBER:
-            *version = atoi(sl_pp_context_cstr(context, input[i].data.number));
+         case SL_PP_UINT:
+            *version = atoi(sl_pp_context_cstr(context, input[i].data._uint));
             i++;
             found_number = 1;
             break;




More information about the mesa-commit mailing list