summaryrefslogtreecommitdiffstats
path: root/src/glsl/pp/sl_pp_process.c
diff options
context:
space:
mode:
authorMichal Krol <[email protected]>2009-06-19 12:02:28 +0200
committerMichal Krol <[email protected]>2009-09-07 10:11:45 +0200
commitfd991d845a5f639b9b675a4840ad234c151d56b4 (patch)
tree46a786562e309631fcdcb3e5ffaec820a4b4baef /src/glsl/pp/sl_pp_process.c
parent3ce5e668180748e2eccd1a8d3931ab98c2919df3 (diff)
glsl: Parse define directive in preprocessor.
Diffstat (limited to 'src/glsl/pp/sl_pp_process.c')
-rw-r--r--src/glsl/pp/sl_pp_process.c29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c
index 1005c501050..2a375df71a4 100644
--- a/src/glsl/pp/sl_pp_process.c
+++ b/src/glsl/pp/sl_pp_process.c
@@ -80,8 +80,10 @@ sl_pp_process(struct sl_pp_context *context,
{
unsigned int i = 0;
int found_eof = 0;
+ struct sl_pp_macro **macro;
struct process_state state;
+ macro = &context->macro;
memset(&state, 0, sizeof(state));
while (!found_eof) {
@@ -94,18 +96,18 @@ sl_pp_process(struct sl_pp_context *context,
{
const char *name;
int found_eol = 0;
+ unsigned int first;
+ unsigned int last;
+ /* Directive name. */
name = sl_pp_context_cstr(context, input[i].data.identifier);
i++;
skip_whitespace(input, &i);
+ first = i;
+
while (!found_eol) {
switch (input[i].token) {
- case SL_PP_WHITESPACE:
- /* Drop whitespace all together at this point. */
- i++;
- break;
-
case SL_PP_NEWLINE:
/* Preserve newline just for the sake of line numbering. */
if (out_token(&state, &input[i])) {
@@ -128,6 +130,23 @@ sl_pp_process(struct sl_pp_context *context,
i++;
}
}
+
+ last = i - 1;
+
+ if (!strcmp(name, "define")) {
+ *macro = malloc(sizeof(struct sl_pp_macro));
+ if (!*macro) {
+ return -1;
+ }
+
+ if (sl_pp_process_define(context, input, first, last, *macro)) {
+ return -1;
+ }
+
+ macro = &(**macro).next;
+ } else {
+ /* XXX: Ignore. */
+ }
}
break;