summaryrefslogtreecommitdiff
path: root/src/glsl
diff options
context:
space:
mode:
authorMichal Krol <michal@vmware.com>2009-11-20 08:59:50 +0100
committerMichal Krol <michal@vmware.com>2009-11-20 08:59:50 +0100
commitb89cd8afc510541a18f2f5c04884637626e104e1 (patch)
tree884ab2925e280177e7ae834d7a546bc99959f225 /src/glsl
parent547ac2869b1e1bbdbf8e51cd40d50e6ab0f4f9f1 (diff)
glsl/pp: Expand unknown identifiers to 0 in if/elif expressions.
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/pp/sl_pp_if.c2
-rw-r--r--src/glsl/pp/sl_pp_line.c2
-rw-r--r--src/glsl/pp/sl_pp_macro.c15
-rw-r--r--src/glsl/pp/sl_pp_macro.h8
-rw-r--r--src/glsl/pp/sl_pp_process.c3
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 a0b3635dd5..6610bc69f3 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 fc2dd89e68..ed5acc697c 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 d6c32a0e78..29f1229dd7 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 e3ae2fc712..3ad3438236 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 4b783e40b4..e2adc2a021 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;