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

Author: Michal Krol <[email protected]>
Date:   Fri Sep  4 15:27:08 2009 +0200

glsl: Handle file numbering.

---

 src/glsl/pp/sl_pp_context.c |    1 +
 src/glsl/pp/sl_pp_context.h |    1 +
 src/glsl/pp/sl_pp_line.c    |   21 ++++++++++++++++++++-
 src/glsl/pp/sl_pp_macro.c   |    3 +--
 src/glsl/pp/sl_pp_token.h   |    2 ++
 5 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/glsl/pp/sl_pp_context.c b/src/glsl/pp/sl_pp_context.c
index 6aaf768..2fca379 100644
--- a/src/glsl/pp/sl_pp_context.c
+++ b/src/glsl/pp/sl_pp_context.c
@@ -38,6 +38,7 @@ sl_pp_context_init(struct sl_pp_context *context)
    context->if_value = 1;
    memset(context->error_msg, 0, sizeof(context->error_msg));
    context->line = 1;
+   context->file = 0;
 }
 
 void
diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h
index d656648..c7e6770 100644
--- a/src/glsl/pp/sl_pp_context.h
+++ b/src/glsl/pp/sl_pp_context.h
@@ -50,6 +50,7 @@ struct sl_pp_context {
    char error_msg[SL_PP_MAX_ERROR_MSG];
 
    unsigned int line;
+   unsigned int file;
 };
 
 void
diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c
index 9b9f45d..a56417a 100644
--- a/src/glsl/pp/sl_pp_line.c
+++ b/src/glsl/pp/sl_pp_line.c
@@ -134,7 +134,26 @@ sl_pp_process_line(struct sl_pp_context *context,
       context->line = line;
    }
 
-   /* TODO: Do something with the file number. */
+   if (file_number != -1) {
+      unsigned int file;
+
+      str = sl_pp_context_cstr(context, file_number);
+      if (_parse_integer(str, &file)) {
+         return -1;
+      }
+
+      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)) {
+            return -1;
+         }
+
+         context->file = file;
+      }
+   }
 
    return 0;
 }
diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c
index b6214f6..d14c982 100644
--- a/src/glsl/pp/sl_pp_macro.c
+++ b/src/glsl/pp/sl_pp_macro.c
@@ -138,9 +138,8 @@ sl_pp_macro_expand(struct sl_pp_context *context,
       (*pi)++;
       return 0;
    }
-   /* TODO: Having the following built-ins hardcoded is a bit lame. */
    if (!strcmp(macro_str, "__FILE__")) {
-      if (!mute && _out_number(context, state, 0)) {
+      if (!mute && _out_number(context, state, context->file)) {
          return -1;
       }
       (*pi)++;
diff --git a/src/glsl/pp/sl_pp_token.h b/src/glsl/pp/sl_pp_token.h
index b347e5c..5901959 100644
--- a/src/glsl/pp/sl_pp_token.h
+++ b/src/glsl/pp/sl_pp_token.h
@@ -97,6 +97,7 @@ enum sl_pp_token {
    SL_PP_EXTENSION_DISABLE,
 
    SL_PP_LINE,
+   SL_PP_FILE,
 
    SL_PP_EOF
 };
@@ -108,6 +109,7 @@ union sl_pp_token_data {
    int pragma;
    int extension;
    unsigned int line;
+   unsigned int file;
 };
 
 struct sl_pp_token_info {

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to