From: Michal Krol Date: Fri, 20 Nov 2009 07:59:50 +0000 (+0100) Subject: glsl/pp: Expand unknown identifiers to 0 in if/elif expressions. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b89cd8afc510541a18f2f5c04884637626e104e1;p=mesa.git glsl/pp: Expand unknown identifiers to 0 in if/elif expressions. --- diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c index a0b3635dd5a..6610bc69f3c 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 fc2dd89e68b..ed5acc697ce 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 d6c32a0e782..29f1229dd7d 100644 --- a/src/glsl/pp/sl_pp_macro.c +++ b/src/glsl/pp/sl_pp_macro.c @@ -28,6 +28,7 @@ #include #include #include +#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 e3ae2fc7125..3ad3438236a 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 4b783e40b4d..e2adc2a0215 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;