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

Author: Michal Krol <[email protected]>
Date:   Fri Nov 20 08:59:50 2009 +0100

glsl/pp: Expand unknown identifiers to 0 in if/elif expressions.

---

 src/glsl/pp/sl_pp_if.c      |    2 +-
 src/glsl/pp/sl_pp_line.c    |    2 +-
 src/glsl/pp/sl_pp_macro.c   |   15 +++++++++++----
 src/glsl/pp/sl_pp_macro.h   |    8 +++++++-
 src/glsl/pp/sl_pp_process.c |    3 ++-
 5 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c
index a0b3635..6610bc6 100644
--- a/src/glsl/pp/sl_pp_if.c
+++ b/src/glsl/pp/sl_pp_if.c
@@ -137,7 +137,7 @@ _parse_if(struct sl_pp_context *context,
                return -1;
             }
          } else {
-            if (sl_pp_macro_expand(context, input, &i, NULL, &state, 0)) {
+            if (sl_pp_macro_expand(context, input, &i, NULL, &state, 
sl_pp_macro_expand_unknown_to_0)) {
                free(state.out);
                return -1;
             }
diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c
index fc2dd89..ed5acc6 100644
--- a/src/glsl/pp/sl_pp_line.c
+++ b/src/glsl/pp/sl_pp_line.c
@@ -53,7 +53,7 @@ sl_pp_process_line(struct sl_pp_context *context,
          break;
 
       case SL_PP_IDENTIFIER:
-         if (sl_pp_macro_expand(context, input, &i, NULL, &state, 0)) {
+         if (sl_pp_macro_expand(context, input, &i, NULL, &state, 
sl_pp_macro_expand_normal)) {
             free(state.out);
             return -1;
          }
diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c
index d6c32a0..29f1229 100644
--- a/src/glsl/pp/sl_pp_macro.c
+++ b/src/glsl/pp/sl_pp_macro.c
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include "sl_pp_public.h"
 #include "sl_pp_macro.h"
 #include "sl_pp_process.h"
 
@@ -122,8 +123,9 @@ sl_pp_macro_expand(struct sl_pp_context *context,
                    unsigned int *pi,
                    struct sl_pp_macro *local,
                    struct sl_pp_process_state *state,
-                   int mute)
+                   enum sl_pp_macro_expand_behaviour behaviour)
 {
+   int mute = (behaviour == sl_pp_macro_expand_mute);
    int macro_name;
    struct sl_pp_macro *macro = NULL;
    struct sl_pp_macro *actual_arg = NULL;
@@ -183,7 +185,12 @@ sl_pp_macro_expand(struct sl_pp_context *context,
    }
 
    if (!macro) {
-      if (!mute) {
+      if (behaviour == sl_pp_macro_expand_unknown_to_0) {
+         if (_out_number(context, state, 0)) {
+            strcpy(context->error_msg, "out of memory");
+            return -1;
+         }
+      } else if (!mute) {
          if (sl_pp_process_out(state, &input[*pi])) {
             strcpy(context->error_msg, "out of memory");
             return -1;
@@ -274,7 +281,7 @@ sl_pp_macro_expand(struct sl_pp_context *context,
                break;
 
             case SL_PP_IDENTIFIER:
-               if (sl_pp_macro_expand(context, input, &i, local, &arg_state, 
0)) {
+               if (sl_pp_macro_expand(context, input, &i, local, &arg_state, 
sl_pp_macro_expand_normal)) {
                   free(arg_state.out);
                   return -1;
                }
@@ -339,7 +346,7 @@ sl_pp_macro_expand(struct sl_pp_context *context,
          break;
 
       case SL_PP_IDENTIFIER:
-         if (sl_pp_macro_expand(context, macro->body, &j, actual_arg, state, 
mute)) {
+         if (sl_pp_macro_expand(context, macro->body, &j, actual_arg, state, 
behaviour)) {
             return -1;
          }
          break;
diff --git a/src/glsl/pp/sl_pp_macro.h b/src/glsl/pp/sl_pp_macro.h
index e3ae2fc..3ad3438 100644
--- a/src/glsl/pp/sl_pp_macro.h
+++ b/src/glsl/pp/sl_pp_macro.h
@@ -56,12 +56,18 @@ sl_pp_macro_free(struct sl_pp_macro *macro);
 void
 sl_pp_macro_reset(struct sl_pp_macro *macro);
 
+enum sl_pp_macro_expand_behaviour {
+   sl_pp_macro_expand_normal,
+   sl_pp_macro_expand_mute,
+   sl_pp_macro_expand_unknown_to_0
+};
+
 int
 sl_pp_macro_expand(struct sl_pp_context *context,
                    const struct sl_pp_token_info *input,
                    unsigned int *pi,
                    struct sl_pp_macro *local,
                    struct sl_pp_process_state *state,
-                   int mute);
+                   enum sl_pp_macro_expand_behaviour behaviour);
 
 #endif /* SL_PP_MACRO_H */
diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c
index 4b783e4..e2adc2a 100644
--- a/src/glsl/pp/sl_pp_process.c
+++ b/src/glsl/pp/sl_pp_process.c
@@ -257,7 +257,8 @@ sl_pp_process(struct sl_pp_context *context,
                break;
 
             case SL_PP_IDENTIFIER:
-               if (sl_pp_macro_expand(context, input, &i, NULL, &state, 
!context->if_value)) {
+               if (sl_pp_macro_expand(context, input, &i, NULL, &state,
+                                      context->if_value ? 
sl_pp_macro_expand_normal : sl_pp_macro_expand_mute)) {
                   return -1;
                }
                break;

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

Reply via email to