Mesa (glsl-pp-rework-2): glsl/pp: Store both line number and file index in a single token.

Michał Król michal at kemper.freedesktop.org
Thu Sep 24 08:58:09 UTC 2009


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

Author: Michal Krol <michal at vmware.com>
Date:   Thu Sep 24 08:43:05 2009 +0200

glsl/pp: Store both line number and file index in a single token.

---

 src/glsl/pp/sl_pp_line.c    |   31 ++++++++++---------------------
 src/glsl/pp/sl_pp_process.c |    3 ++-
 src/glsl/pp/sl_pp_token.h   |    7 ++++---
 3 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c
index e8f7510..41ddaf6 100644
--- a/src/glsl/pp/sl_pp_line.c
+++ b/src/glsl/pp/sl_pp_line.c
@@ -42,6 +42,7 @@ sl_pp_process_line(struct sl_pp_context *context,
    int line_number = -1;
    int file_number = -1;
    unsigned int line;
+   unsigned int file;
 
    memset(&state, 0, sizeof(state));
    for (i = first; i < last;) {
@@ -94,37 +95,25 @@ sl_pp_process_line(struct sl_pp_context *context,
    free(state.out);
 
    line = atoi(sl_pp_context_cstr(context, line_number));
+   if (file_number != -1) {
+      file = atoi(sl_pp_context_cstr(context, file_number));
+   } else {
+      file = context->file;
+   }
 
-   if (context->line != line) {
+   if (context->line != line || context->file != file) {
       struct sl_pp_token_info ti;
 
       ti.token = SL_PP_LINE;
-      ti.data.line = line;
+      ti.data.line.lineno = line;
+      ti.data.line.fileno = file;
       if (sl_pp_process_out(pstate, &ti)) {
          strcpy(context->error_msg, "out of memory");
          return -1;
       }
 
       context->line = line;
-   }
-
-   if (file_number != -1) {
-      unsigned int file;
-
-      file = atoi(sl_pp_context_cstr(context, file_number));
-
-      if (context->file != file) {
-         struct sl_pp_token_info ti;
-
-         ti.token = SL_PP_FILE;
-         ti.data.file = file;
-         if (sl_pp_process_out(pstate, &ti)) {
-            strcpy(context->error_msg, "out of memory");
-            return -1;
-         }
-
-         context->file = file;
-      }
+      context->file = file;
    }
 
    return 0;
diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c
index ab2f2d8..67ed588 100644
--- a/src/glsl/pp/sl_pp_process.c
+++ b/src/glsl/pp/sl_pp_process.c
@@ -79,7 +79,8 @@ sl_pp_process(struct sl_pp_context *context,
       struct sl_pp_token_info ti;
 
       ti.token = SL_PP_LINE;
-      ti.data.line = context->line - 1;
+      ti.data.line.lineno = context->line - 1;
+      ti.data.line.fileno = context->file;
       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.h b/src/glsl/pp/sl_pp_token.h
index 2a7b79e..b1f3389 100644
--- a/src/glsl/pp/sl_pp_token.h
+++ b/src/glsl/pp/sl_pp_token.h
@@ -96,7 +96,6 @@ enum sl_pp_token {
    SL_PP_EXTENSION_DISABLE,
 
    SL_PP_LINE,
-   SL_PP_FILE,
 
    SL_PP_EOF
 };
@@ -108,8 +107,10 @@ union sl_pp_token_data {
    char other;
    int pragma;
    int extension;
-   unsigned int line;
-   unsigned int file;
+   union {
+      unsigned int lineno: 24;
+      unsigned int fileno: 8;
+   } line;
 };
 
 struct sl_pp_token_info {




More information about the mesa-commit mailing list