Mesa (glsl-pp-rework-1): glsl: Implement `undef' preprocessor directive.
MichaŠKról
michal at kemper.freedesktop.org
Fri Jun 26 10:54:19 UTC 2009
Module: Mesa
Branch: glsl-pp-rework-1
Commit: 7b792171c43a947bc66db40db139f46a1e46efd6
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7b792171c43a947bc66db40db139f46a1e46efd6
Author: Michal Krol <michal at vmware.com>
Date: Fri Jun 26 12:48:14 2009 +0200
glsl: Implement `undef' preprocessor directive.
---
src/glsl/pp/sl_pp_define.c | 35 +++++++++++++++++++++++++++++++++++
src/glsl/pp/sl_pp_process.c | 22 +++++++++++++---------
src/glsl/pp/sl_pp_process.h | 6 ++++++
3 files changed, 54 insertions(+), 9 deletions(-)
diff --git a/src/glsl/pp/sl_pp_define.c b/src/glsl/pp/sl_pp_define.c
index 0509646..9bc9fb5 100644
--- a/src/glsl/pp/sl_pp_define.c
+++ b/src/glsl/pp/sl_pp_define.c
@@ -176,3 +176,38 @@ sl_pp_process_define(struct sl_pp_context *context,
return 0;
}
+
+
+int
+sl_pp_process_undef(struct sl_pp_context *context,
+ const struct sl_pp_token_info *input,
+ unsigned int first,
+ unsigned int last)
+{
+ int macro_name = -1;
+ struct sl_pp_macro **pmacro;
+ struct sl_pp_macro *macro;
+
+ if (first < last && input[first].token == SL_PP_IDENTIFIER) {
+ macro_name = input[first].data.identifier;
+ }
+ if (macro_name == -1) {
+ return 0;
+ }
+
+ for (pmacro = &context->macro; *pmacro; pmacro = &(**pmacro).next) {
+ if ((**pmacro).name == macro_name) {
+ break;
+ }
+ }
+ if (!*pmacro) {
+ return 0;
+ }
+
+ macro = *pmacro;
+ *pmacro = macro->next;
+ macro->next = NULL;
+ sl_pp_macro_free(macro);
+
+ return 0;
+}
diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c
index 4715eed..c17a3ac 100644
--- a/src/glsl/pp/sl_pp_process.c
+++ b/src/glsl/pp/sl_pp_process.c
@@ -122,13 +122,7 @@ sl_pp_process(struct sl_pp_context *context,
last = i - 1;
- if (!strcmp(name, "define")) {
- if (context->if_value) {
- if (sl_pp_process_define(context, input, first, last)) {
- return -1;
- }
- }
- } else if (!strcmp(name, "if")) {
+ if (!strcmp(name, "if")) {
if (sl_pp_process_if(context, input, first, last)) {
return -1;
}
@@ -152,8 +146,18 @@ sl_pp_process(struct sl_pp_context *context,
if (sl_pp_process_endif(context, input, first, last)) {
return -1;
}
- } else {
- /* XXX: Ignore. */
+ } else if (context->if_value) {
+ if (!strcmp(name, "define")) {
+ if (sl_pp_process_define(context, input, first, last)) {
+ return -1;
+ }
+ } else if (!strcmp(name, "undef")) {
+ if (sl_pp_process_undef(context, input, first, last)) {
+ return -1;
+ }
+ } else {
+ /* XXX: Ignore. */
+ }
}
}
break;
diff --git a/src/glsl/pp/sl_pp_process.h b/src/glsl/pp/sl_pp_process.h
index 66d6149..61e67fe 100644
--- a/src/glsl/pp/sl_pp_process.h
+++ b/src/glsl/pp/sl_pp_process.h
@@ -51,6 +51,12 @@ sl_pp_process_define(struct sl_pp_context *context,
unsigned int last);
int
+sl_pp_process_undef(struct sl_pp_context *context,
+ const struct sl_pp_token_info *input,
+ unsigned int first,
+ unsigned int last);
+
+int
sl_pp_process_if(struct sl_pp_context *context,
const struct sl_pp_token_info *input,
unsigned int first,
More information about the mesa-commit
mailing list