From 0e046420e468bcb81301aa5a5e4de736a8b4844a Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 4 Sep 2009 10:48:51 +0200 Subject: glsl: Implement `pragma' preprocessor directive. Handle `optimize(on|off)' and `debug(on|off)' pragmas. --- src/glsl/pp/sl_pp_pragma.c | 106 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/glsl/pp/sl_pp_pragma.c (limited to 'src/glsl/pp/sl_pp_pragma.c') diff --git a/src/glsl/pp/sl_pp_pragma.c b/src/glsl/pp/sl_pp_pragma.c new file mode 100644 index 0000000000..059bc6f288 --- /dev/null +++ b/src/glsl/pp/sl_pp_pragma.c @@ -0,0 +1,106 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include +#include "sl_pp_process.h" + + +int +sl_pp_process_pragma(struct sl_pp_context *context, + const struct sl_pp_token_info *input, + unsigned int first, + unsigned int last, + struct sl_pp_process_state *state) +{ + const char *pragma_name = NULL; + struct sl_pp_token_info out; + const char *arg_name = NULL; + + if (first < last && input[first].token == SL_PP_IDENTIFIER) { + pragma_name = sl_pp_context_cstr(context, input[first].data.identifier); + first++; + } + if (!pragma_name) { + return 0; + } + + if (!strcmp(pragma_name, "optimize")) { + out.token = SL_PP_PRAGMA_OPTIMIZE; + } else if (!strcmp(pragma_name, "debug")) { + out.token = SL_PP_PRAGMA_DEBUG; + } else { + return 0; + } + + while (first < last && input[first].token == SL_PP_WHITESPACE) { + first++; + } + + if (first < last && input[first].token == SL_PP_LPAREN) { + first++; + } else { + return 0; + } + + while (first < last && input[first].token == SL_PP_WHITESPACE) { + first++; + } + + if (first < last && input[first].token == SL_PP_IDENTIFIER) { + arg_name = sl_pp_context_cstr(context, input[first].data.identifier); + first++; + } + if (!arg_name) { + return 0; + } + + if (!strcmp(arg_name, "off")) { + out.data.pragma = 0; + } else if (!strcmp(arg_name, "on")) { + out.data.pragma = 1; + } else { + return 0; + } + + while (first < last && input[first].token == SL_PP_WHITESPACE) { + first++; + } + + if (first < last && input[first].token == SL_PP_RPAREN) { + first++; + } else { + return 0; + } + + /* Ignore the tokens that follow. */ + + if (sl_pp_process_out(state, &out)) { + return -1; + } + + return 0; +} -- cgit v1.2.3 From 0ddf41d34d511b339e0bb5a59673765f1bf0b3a5 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 17 Sep 2009 11:51:35 +0200 Subject: glsl/pp: Add remaining error messages. --- src/glsl/pp/sl_pp_context.c | 1 + src/glsl/pp/sl_pp_context.h | 2 +- src/glsl/pp/sl_pp_define.c | 19 ++++++++++++------ src/glsl/pp/sl_pp_expression.c | 2 ++ src/glsl/pp/sl_pp_if.c | 35 +++++++++++++++++++------------- src/glsl/pp/sl_pp_line.c | 45 ++++++++---------------------------------- src/glsl/pp/sl_pp_macro.c | 18 ++++++++++++++++- src/glsl/pp/sl_pp_pragma.c | 1 + src/glsl/pp/sl_pp_version.c | 42 ++++----------------------------------- 9 files changed, 68 insertions(+), 97 deletions(-) (limited to 'src/glsl/pp/sl_pp_pragma.c') diff --git a/src/glsl/pp/sl_pp_context.c b/src/glsl/pp/sl_pp_context.c index 88a002c1c7..b196d8102a 100644 --- a/src/glsl/pp/sl_pp_context.c +++ b/src/glsl/pp/sl_pp_context.c @@ -85,6 +85,7 @@ sl_pp_context_add_unique_str(struct sl_pp_context *context, } if (!context->cstr_pool) { + strcpy(context->error_msg, "out of memory"); return -1; } diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h index 5826f9448d..8bed142045 100644 --- a/src/glsl/pp/sl_pp_context.h +++ b/src/glsl/pp/sl_pp_context.h @@ -47,7 +47,7 @@ struct sl_pp_context { unsigned int if_stack[SL_PP_MAX_IF_NESTING]; unsigned int if_ptr; - int if_value; + unsigned int if_value; char error_msg[SL_PP_MAX_ERROR_MSG]; diff --git a/src/glsl/pp/sl_pp_define.c b/src/glsl/pp/sl_pp_define.c index 9bc9fb5359..391178aa69 100644 --- a/src/glsl/pp/sl_pp_define.c +++ b/src/glsl/pp/sl_pp_define.c @@ -41,7 +41,8 @@ skip_whitespace(const struct sl_pp_token_info *input, static int -_parse_formal_args(const struct sl_pp_token_info *input, +_parse_formal_args(struct sl_pp_context *context, + const struct sl_pp_token_info *input, unsigned int *first, unsigned int last, struct sl_pp_macro *macro) @@ -57,7 +58,7 @@ _parse_formal_args(const struct sl_pp_token_info *input, return 0; } } else { - /* Expected either an identifier or `)'. */ + strcpy(context->error_msg, "expected either an identifier or `)'"); return -1; } @@ -65,12 +66,13 @@ _parse_formal_args(const struct sl_pp_token_info *input, for (;;) { if (*first < last && input[*first].token != SL_PP_IDENTIFIER) { - /* Expected an identifier. */ + strcpy(context->error_msg, "expected an identifier"); return -1; } *arg = malloc(sizeof(struct sl_pp_macro_formal_arg)); if (!*arg) { + strcpy(context->error_msg, "out of memory"); return -1; } @@ -90,14 +92,16 @@ _parse_formal_args(const struct sl_pp_token_info *input, (*first)++; return 0; } else { - /* Expected either `,' or `)'. */ + strcpy(context->error_msg, "expected either `,' or `)'"); return -1; } } else { - /* Expected either `,' or `)'. */ + strcpy(context->error_msg, "expected either `,' or `)'"); return -1; } } + + /* Should not gete here. */ } @@ -118,6 +122,7 @@ sl_pp_process_define(struct sl_pp_context *context, first++; } if (macro_name == -1) { + strcpy(context->error_msg, "expected an identifier"); return -1; } @@ -130,6 +135,7 @@ sl_pp_process_define(struct sl_pp_context *context, if (!macro) { macro = sl_pp_macro_new(); if (!macro) { + strcpy(context->error_msg, "out of memory"); return -1; } @@ -149,7 +155,7 @@ sl_pp_process_define(struct sl_pp_context *context, */ if (first < last && input[first].token == SL_PP_LPAREN) { first++; - if (_parse_formal_args(input, &first, last, macro)) { + if (_parse_formal_args(context, input, &first, last, macro)) { return -1; } } @@ -164,6 +170,7 @@ sl_pp_process_define(struct sl_pp_context *context, macro->body = malloc(sizeof(struct sl_pp_token_info) * body_len); if (!macro->body) { + strcpy(context->error_msg, "out of memory"); return -1; } diff --git a/src/glsl/pp/sl_pp_expression.c b/src/glsl/pp/sl_pp_expression.c index a692430abb..6b2329ed1a 100644 --- a/src/glsl/pp/sl_pp_expression.c +++ b/src/glsl/pp/sl_pp_expression.c @@ -47,6 +47,7 @@ _parse_primary(struct parse_context *ctx, ctx->input++; } else { if (ctx->input->token != SL_PP_LPAREN) { + strcpy(ctx->context->error_msg, "expected `('"); return -1; } ctx->input++; @@ -54,6 +55,7 @@ _parse_primary(struct parse_context *ctx, return -1; } if (ctx->input->token != SL_PP_RPAREN) { + strcpy(ctx->context->error_msg, "expected `)'"); return -1; } ctx->input++; diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c index 90b8051237..44bbefa357 100644 --- a/src/glsl/pp/sl_pp_if.c +++ b/src/glsl/pp/sl_pp_if.c @@ -59,7 +59,7 @@ _parse_defined(struct sl_pp_context *context, } if (input[*pi].token != SL_PP_IDENTIFIER) { - /* Identifier expected. */ + strcpy(context->error_msg, "expected an identifier"); return -1; } @@ -75,7 +75,7 @@ _parse_defined(struct sl_pp_context *context, if (parens) { skip_whitespace(input, pi); if (input[*pi].token != SL_PP_RPAREN) { - /* `)' expected */ + strcpy(context->error_msg, "expected `)'"); return -1; } (*pi)++; @@ -91,10 +91,15 @@ _parse_defined(struct sl_pp_context *context, return -1; } - return sl_pp_process_out(state, &result); + if (sl_pp_process_out(state, &result)) { + strcpy(context->error_msg, "out of memory"); + return -1; + } + + return 0; } -static int +static unsigned int _evaluate_if_stack(struct sl_pp_context *context) { unsigned int i; @@ -119,7 +124,7 @@ _parse_if(struct sl_pp_context *context, int result; if (!context->if_ptr) { - /* #if nesting too deep. */ + strcpy(context->error_msg, "`#if' nesting too deep"); return -1; } @@ -151,6 +156,7 @@ _parse_if(struct sl_pp_context *context, default: if (sl_pp_process_out(&state, &input[i])) { + strcpy(context->error_msg, "out of memory"); free(state.out); return -1; } @@ -160,6 +166,7 @@ _parse_if(struct sl_pp_context *context, eof.token = SL_PP_EOF; if (sl_pp_process_out(&state, &eof)) { + strcpy(context->error_msg, "out of memory"); free(state.out); return -1; } @@ -182,13 +189,13 @@ static int _parse_else(struct sl_pp_context *context) { if (context->if_ptr == SL_PP_MAX_IF_NESTING) { - /* No matching #if. */ + strcpy(context->error_msg, "no matching `#if'"); return -1; } /* Bit b1 indicates we already went through #else. */ if (context->if_stack[context->if_ptr] & 2) { - /* No matching #if. */ + strcpy(context->error_msg, "no matching `#if'"); return -1; } @@ -217,7 +224,7 @@ sl_pp_process_ifdef(struct sl_pp_context *context, unsigned int i; if (!context->if_ptr) { - /* #if nesting too deep. */ + strcpy(context->error_msg, "`#if' nesting too deep"); return -1; } @@ -246,12 +253,12 @@ sl_pp_process_ifdef(struct sl_pp_context *context, break; default: - /* Expected an identifier. */ + strcpy(context->error_msg, "expected an identifier"); return -1; } } - /* Expected an identifier. */ + strcpy(context->error_msg, "expected an identifier"); return -1; } @@ -264,7 +271,7 @@ sl_pp_process_ifndef(struct sl_pp_context *context, unsigned int i; if (!context->if_ptr) { - /* #if nesting too deep. */ + strcpy(context->error_msg, "`#if' nesting too deep"); return -1; } @@ -293,12 +300,12 @@ sl_pp_process_ifndef(struct sl_pp_context *context, break; default: - /* Expected an identifier. */ + strcpy(context->error_msg, "expected an identifier"); return -1; } } - /* Expected an identifier. */ + strcpy(context->error_msg, "expected an identifier"); return -1; } @@ -341,7 +348,7 @@ sl_pp_process_endif(struct sl_pp_context *context, unsigned int last) { if (context->if_ptr == SL_PP_MAX_IF_NESTING) { - /* No matching #if. */ + strcpy(context->error_msg, "no matching `#if'"); return -1; } diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c index a56417a861..c38f4b0f2e 100644 --- a/src/glsl/pp/sl_pp_line.c +++ b/src/glsl/pp/sl_pp_line.c @@ -29,31 +29,6 @@ #include "sl_pp_process.h" -static int -_parse_integer(const char *input, - unsigned int *number) -{ - unsigned int n = 0; - - while (*input >= '0' && *input <= '9') { - if (n * 10 < n) { - /* Overflow. */ - return -1; - } - - n = n * 10 + (*input++ - '0'); - } - - if (*input != '\0') { - /* Invalid decimal number. */ - return -1; - } - - *number = n; - return 0; -} - - int sl_pp_process_line(struct sl_pp_context *context, const struct sl_pp_token_info *input, @@ -65,7 +40,6 @@ sl_pp_process_line(struct sl_pp_context *context, struct sl_pp_process_state state; int line_number = -1; int file_number = -1; - const char *str; unsigned int line; memset(&state, 0, sizeof(state)); @@ -84,6 +58,7 @@ sl_pp_process_line(struct sl_pp_context *context, default: if (sl_pp_process_out(&state, &input[i])) { + strcpy(context->error_msg, "out of memory"); free(state.out); return -1; } @@ -94,7 +69,7 @@ sl_pp_process_line(struct sl_pp_context *context, if (state.out_len > 0 && state.out[0].token == SL_PP_NUMBER) { line_number = state.out[0].data.number; } else { - strcpy(context->error_msg, "expected number after `#line'"); + strcpy(context->error_msg, "expected a number after `#line'"); free(state.out); return -1; } @@ -103,13 +78,13 @@ sl_pp_process_line(struct sl_pp_context *context, if (state.out[1].token == SL_PP_NUMBER) { file_number = state.out[1].data.number; } else { - strcpy(context->error_msg, "expected number after line number"); + strcpy(context->error_msg, "expected a number after line number"); free(state.out); return -1; } if (state.out_len > 2) { - strcpy(context->error_msg, "expected end of line after file number"); + strcpy(context->error_msg, "expected an end of line after file number"); free(state.out); return -1; } @@ -117,10 +92,7 @@ sl_pp_process_line(struct sl_pp_context *context, free(state.out); - str = sl_pp_context_cstr(context, line_number); - if (_parse_integer(str, &line)) { - return -1; - } + line = atoi(sl_pp_context_cstr(context, line_number)); if (context->line != line) { struct sl_pp_token_info ti; @@ -128,6 +100,7 @@ sl_pp_process_line(struct sl_pp_context *context, ti.token = SL_PP_LINE; ti.data.line = line; if (sl_pp_process_out(pstate, &ti)) { + strcpy(context->error_msg, "out of memory"); return -1; } @@ -137,10 +110,7 @@ sl_pp_process_line(struct sl_pp_context *context, if (file_number != -1) { unsigned int file; - str = sl_pp_context_cstr(context, file_number); - if (_parse_integer(str, &file)) { - return -1; - } + file_number = atoi(sl_pp_context_cstr(context, file_number)); if (context->file != file) { struct sl_pp_token_info ti; @@ -148,6 +118,7 @@ sl_pp_process_line(struct sl_pp_context *context, ti.token = SL_PP_FILE; ti.data.file = file; if (sl_pp_process_out(pstate, &ti)) { + strcpy(context->error_msg, "out of memory"); return -1; } diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c index d14c982555..7793562781 100644 --- a/src/glsl/pp/sl_pp_macro.c +++ b/src/glsl/pp/sl_pp_macro.c @@ -107,7 +107,12 @@ _out_number(struct sl_pp_context *context, ti.token = SL_PP_NUMBER; ti.data.number = sl_pp_context_add_unique_str(context, buf); - return sl_pp_process_out(state, &ti); + if (sl_pp_process_out(state, &ti)) { + strcpy(context->error_msg, "out of memory"); + return -1; + } + + return 0; } int @@ -125,6 +130,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, unsigned int j; if (input[*pi].token != SL_PP_IDENTIFIER) { + strcpy(context->error_msg, "expected an identifier"); return -1; } @@ -172,6 +178,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, if (!macro) { if (!mute) { if (sl_pp_process_out(state, &input[*pi])) { + strcpy(context->error_msg, "out of memory"); return -1; } } @@ -184,6 +191,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, if (macro->num_args >= 0) { skip_whitespace(input, pi); if (input[*pi].token != SL_PP_LPAREN) { + strcpy(context->error_msg, "expected `('"); return -1; } (*pi)++; @@ -203,6 +211,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, *pmacro = sl_pp_macro_new(); if (!*pmacro) { + strcpy(context->error_msg, "out of memory"); return -1; } @@ -219,6 +228,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, if (j < (unsigned int)macro->num_args - 1) { done = 1; } else { + strcpy(context->error_msg, "too many actual macro arguments"); return -1; } } else { @@ -236,6 +246,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, if (j == (unsigned int)macro->num_args - 1) { done = 1; } else { + strcpy(context->error_msg, "too few actual macro arguments"); return -1; } } else { @@ -245,6 +256,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, break; case SL_PP_EOF: + strcpy(context->error_msg, "too few actual macro arguments"); return -1; default: @@ -254,6 +266,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, (**pmacro).body = malloc(sizeof(struct sl_pp_token_info) * body_len); if (!(**pmacro).body) { + strcpy(context->error_msg, "out of memory"); return -1; } @@ -301,6 +314,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, if (macro->num_args == 0) { skip_whitespace(input, pi); if (input[*pi].token != SL_PP_RPAREN) { + strcpy(context->error_msg, "expected `)'"); return -1; } (*pi)++; @@ -310,6 +324,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, switch (macro->body[j].token) { case SL_PP_NEWLINE: if (sl_pp_process_out(state, ¯o->body[j])) { + strcpy(context->error_msg, "out of memory"); return -1; } j++; @@ -328,6 +343,7 @@ sl_pp_macro_expand(struct sl_pp_context *context, default: if (!mute) { if (sl_pp_process_out(state, ¯o->body[j])) { + strcpy(context->error_msg, "out of memory"); return -1; } } diff --git a/src/glsl/pp/sl_pp_pragma.c b/src/glsl/pp/sl_pp_pragma.c index 059bc6f288..1cd9fd8234 100644 --- a/src/glsl/pp/sl_pp_pragma.c +++ b/src/glsl/pp/sl_pp_pragma.c @@ -99,6 +99,7 @@ sl_pp_process_pragma(struct sl_pp_context *context, /* Ignore the tokens that follow. */ if (sl_pp_process_out(state, &out)) { + strcpy(context->error_msg, "out of memory"); return -1; } diff --git a/src/glsl/pp/sl_pp_version.c b/src/glsl/pp/sl_pp_version.c index 82acdd1d5a..6cd63f4925 100644 --- a/src/glsl/pp/sl_pp_version.c +++ b/src/glsl/pp/sl_pp_version.c @@ -25,34 +25,10 @@ * **************************************************************************/ +#include #include "sl_pp_version.h" -static int -_parse_integer(const char *input, - unsigned int *number) -{ - unsigned int n = 0; - - while (*input >= '0' && *input <= '9') { - if (n * 10 < n) { - /* Overflow. */ - return -1; - } - - n = n * 10 + (*input++ - '0'); - } - - if (*input != '\0') { - /* Invalid decimal number. */ - return -1; - } - - *number = n; - return 0; -} - - int sl_pp_version(struct sl_pp_context *context, const struct sl_pp_token_info *input, @@ -130,19 +106,9 @@ sl_pp_version(struct sl_pp_context *context, break; case SL_PP_NUMBER: - { - const char *num = sl_pp_context_cstr(context, input[i].data.number); - - if (!num) { - return -1; - } - if (_parse_integer(num, version)) { - strcpy(context->error_msg, "expected version number after `#version'"); - return -1; - } - i++; - found_number = 1; - } + *version = atoi(sl_pp_context_cstr(context, input[i].data.number)); + i++; + found_number = 1; break; default: -- cgit v1.2.3 From ce8f486156f5c4b28b51954ea862675275c38f6d Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 17 Sep 2009 12:12:34 +0200 Subject: slang/pp: Use a dictionary for the remaining string literals. --- src/glsl/pp/sl_pp_dict.c | 27 +++++++++++++++++++++++++++ src/glsl/pp/sl_pp_dict.h | 27 +++++++++++++++++++++++++++ src/glsl/pp/sl_pp_if.c | 24 ++++++++++-------------- src/glsl/pp/sl_pp_macro.c | 8 +++----- src/glsl/pp/sl_pp_pragma.c | 20 ++++++++++---------- src/glsl/pp/sl_pp_process.c | 28 ++++++++++++++-------------- src/glsl/pp/sl_pp_version.c | 15 ++++----------- 7 files changed, 95 insertions(+), 54 deletions(-) (limited to 'src/glsl/pp/sl_pp_pragma.c') diff --git a/src/glsl/pp/sl_pp_dict.c b/src/glsl/pp/sl_pp_dict.c index 65b91d9e98..f2885c763d 100644 --- a/src/glsl/pp/sl_pp_dict.c +++ b/src/glsl/pp/sl_pp_dict.c @@ -52,5 +52,32 @@ sl_pp_dict_init(struct sl_pp_context *context) ADD_NAME(context, warn); ADD_NAME(context, disable); + ADD_NAME(context, defined); + + ADD_NAME_STR(context, ___LINE__, "__LINE__"); + ADD_NAME_STR(context, ___FILE__, "__FILE__"); + ADD_NAME(context, __VERSION__); + + ADD_NAME(context, optimize); + ADD_NAME(context, debug); + + ADD_NAME(context, off); + ADD_NAME(context, on); + + ADD_NAME(context, define); + ADD_NAME(context, elif); + ADD_NAME_STR(context, _else, "else"); + ADD_NAME(context, endif); + ADD_NAME(context, error); + ADD_NAME(context, extension); + ADD_NAME_STR(context, _if, "if"); + ADD_NAME(context, ifdef); + ADD_NAME(context, ifndef); + ADD_NAME(context, line); + ADD_NAME(context, pragma); + ADD_NAME(context, undef); + + ADD_NAME(context, version); + return 0; } diff --git a/src/glsl/pp/sl_pp_dict.h b/src/glsl/pp/sl_pp_dict.h index ce138d98f5..ba82b389b2 100644 --- a/src/glsl/pp/sl_pp_dict.h +++ b/src/glsl/pp/sl_pp_dict.h @@ -37,6 +37,33 @@ struct sl_pp_dict { int enable; int warn; int disable; + + int defined; + + int ___LINE__; + int ___FILE__; + int __VERSION__; + + int optimize; + int debug; + + int off; + int on; + + int define; + int elif; + int _else; + int endif; + int error; + int extension; + int _if; + int ifdef; + int ifndef; + int line; + int pragma; + int undef; + + int version; }; diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c index 44bbefa357..cf1c746d5f 100644 --- a/src/glsl/pp/sl_pp_if.c +++ b/src/glsl/pp/sl_pp_if.c @@ -136,20 +136,16 @@ _parse_if(struct sl_pp_context *context, break; case SL_PP_IDENTIFIER: - { - const char *id = sl_pp_context_cstr(context, input[i].data.identifier); - - if (!strcmp(id, "defined")) { - i++; - if (_parse_defined(context, input, &i, &state)) { - free(state.out); - return -1; - } - } else { - if (sl_pp_macro_expand(context, input, &i, NULL, &state, 0)) { - free(state.out); - return -1; - } + if (input[i].data.identifier == context->dict.defined) { + i++; + if (_parse_defined(context, input, &i, &state)) { + free(state.out); + return -1; + } + } else { + if (sl_pp_macro_expand(context, input, &i, NULL, &state, 0)) { + free(state.out); + return -1; } } break; diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c index 7793562781..6772100847 100644 --- a/src/glsl/pp/sl_pp_macro.c +++ b/src/glsl/pp/sl_pp_macro.c @@ -124,7 +124,6 @@ sl_pp_macro_expand(struct sl_pp_context *context, int mute) { int macro_name; - const char *macro_str; struct sl_pp_macro *macro = NULL; struct sl_pp_macro *actual_arg = NULL; unsigned int j; @@ -135,23 +134,22 @@ sl_pp_macro_expand(struct sl_pp_context *context, } macro_name = input[*pi].data.identifier; - macro_str = sl_pp_context_cstr(context, macro_name); - if (!strcmp(macro_str, "__LINE__")) { + if (macro_name == context->dict.___LINE__) { if (!mute && _out_number(context, state, context->line)) { return -1; } (*pi)++; return 0; } - if (!strcmp(macro_str, "__FILE__")) { + if (macro_name == context->dict.___FILE__) { if (!mute && _out_number(context, state, context->file)) { return -1; } (*pi)++; return 0; } - if (!strcmp(macro_str, "__VERSION__")) { + if (macro_name == context->dict.__VERSION__) { if (!mute && _out_number(context, state, 110)) { return -1; } diff --git a/src/glsl/pp/sl_pp_pragma.c b/src/glsl/pp/sl_pp_pragma.c index 1cd9fd8234..03269b63db 100644 --- a/src/glsl/pp/sl_pp_pragma.c +++ b/src/glsl/pp/sl_pp_pragma.c @@ -36,21 +36,21 @@ sl_pp_process_pragma(struct sl_pp_context *context, unsigned int last, struct sl_pp_process_state *state) { - const char *pragma_name = NULL; + int pragma_name = -1; struct sl_pp_token_info out; - const char *arg_name = NULL; + int arg_name = -1; if (first < last && input[first].token == SL_PP_IDENTIFIER) { - pragma_name = sl_pp_context_cstr(context, input[first].data.identifier); + pragma_name = input[first].data.identifier; first++; } - if (!pragma_name) { + if (pragma_name == -1) { return 0; } - if (!strcmp(pragma_name, "optimize")) { + if (pragma_name == context->dict.optimize) { out.token = SL_PP_PRAGMA_OPTIMIZE; - } else if (!strcmp(pragma_name, "debug")) { + } else if (pragma_name == context->dict.debug) { out.token = SL_PP_PRAGMA_DEBUG; } else { return 0; @@ -71,16 +71,16 @@ sl_pp_process_pragma(struct sl_pp_context *context, } if (first < last && input[first].token == SL_PP_IDENTIFIER) { - arg_name = sl_pp_context_cstr(context, input[first].data.identifier); + arg_name = input[first].data.identifier; first++; } - if (!arg_name) { + if (arg_name == -1) { return 0; } - if (!strcmp(arg_name, "off")) { + if (arg_name == context->dict.off) { out.data.pragma = 0; - } else if (!strcmp(arg_name, "on")) { + } else if (arg_name == context->dict.on) { out.data.pragma = 1; } else { return 0; diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c index 03a3051838..ab2f2d8eb4 100644 --- a/src/glsl/pp/sl_pp_process.c +++ b/src/glsl/pp/sl_pp_process.c @@ -100,14 +100,14 @@ sl_pp_process(struct sl_pp_context *context, switch (input[i].token) { case SL_PP_IDENTIFIER: { - const char *name; + int name; int found_eol = 0; unsigned int first; unsigned int last; struct sl_pp_token_info endof; /* Directive name. */ - name = sl_pp_context_cstr(context, input[i].data.identifier); + name = input[i].data.identifier; i++; skip_whitespace(input, &i); @@ -136,51 +136,51 @@ sl_pp_process(struct sl_pp_context *context, last = i - 1; - if (!strcmp(name, "if")) { + if (name == context->dict._if) { if (sl_pp_process_if(context, input, first, last)) { return -1; } - } else if (!strcmp(name, "ifdef")) { + } else if (name == context->dict.ifdef) { if (sl_pp_process_ifdef(context, input, first, last)) { return -1; } - } else if (!strcmp(name, "ifndef")) { + } else if (name == context->dict.ifndef) { if (sl_pp_process_ifndef(context, input, first, last)) { return -1; } - } else if (!strcmp(name, "elif")) { + } else if (name == context->dict.elif) { if (sl_pp_process_elif(context, input, first, last)) { return -1; } - } else if (!strcmp(name, "else")) { + } else if (name == context->dict._else) { if (sl_pp_process_else(context, input, first, last)) { return -1; } - } else if (!strcmp(name, "endif")) { + } else if (name == context->dict.endif) { if (sl_pp_process_endif(context, input, first, last)) { return -1; } } else if (context->if_value) { - if (!strcmp(name, "define")) { + if (name == context->dict.define) { if (sl_pp_process_define(context, input, first, last)) { return -1; } - } else if (!strcmp(name, "error")) { + } else if (name == context->dict.error) { sl_pp_process_error(context, input, first, last); return -1; - } else if (!strcmp(name, "extension")) { + } else if (name == context->dict.extension) { if (sl_pp_process_extension(context, input, first, last, &state)) { return -1; } - } else if (!strcmp(name, "line")) { + } else if (name == context->dict.line) { if (sl_pp_process_line(context, input, first, last, &state)) { return -1; } - } else if (!strcmp(name, "pragma")) { + } else if (name == context->dict.pragma) { if (sl_pp_process_pragma(context, input, first, last, &state)) { return -1; } - } else if (!strcmp(name, "undef")) { + } else if (name == context->dict.undef) { if (sl_pp_process_undef(context, input, first, last)) { return -1; } diff --git a/src/glsl/pp/sl_pp_version.c b/src/glsl/pp/sl_pp_version.c index 6cd63f4925..814da46a67 100644 --- a/src/glsl/pp/sl_pp_version.c +++ b/src/glsl/pp/sl_pp_version.c @@ -79,18 +79,11 @@ sl_pp_version(struct sl_pp_context *context, break; case SL_PP_IDENTIFIER: - { - const char *id = sl_pp_context_cstr(context, input[i].data.identifier); - - if (!id) { - return -1; - } - if (strcmp(id, "version")) { - return 0; - } - i++; - found_version = 1; + if (input[i].data.identifier != context->dict.version) { + return 0; } + i++; + found_version = 1; break; default: -- cgit v1.2.3 From 7a95a3c7c4ba49ec174681c36951e3c0672df06c Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Thu, 24 Sep 2009 10:56:46 +0200 Subject: glsl/pp: Include missing headers. --- src/glsl/pp/sl_pp_context.c | 1 + src/glsl/pp/sl_pp_error.c | 1 + src/glsl/pp/sl_pp_expression.c | 1 + src/glsl/pp/sl_pp_extension.c | 1 + src/glsl/pp/sl_pp_if.c | 1 + src/glsl/pp/sl_pp_line.c | 1 + src/glsl/pp/sl_pp_pragma.c | 1 + src/glsl/pp/sl_pp_process.c | 2 ++ src/glsl/pp/sl_pp_token.c | 1 + src/glsl/pp/sl_pp_version.c | 1 + 10 files changed, 11 insertions(+) (limited to 'src/glsl/pp/sl_pp_pragma.c') diff --git a/src/glsl/pp/sl_pp_context.c b/src/glsl/pp/sl_pp_context.c index fd205de5d3..8ce189d955 100644 --- a/src/glsl/pp/sl_pp_context.c +++ b/src/glsl/pp/sl_pp_context.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_public.h" #include "sl_pp_context.h" diff --git a/src/glsl/pp/sl_pp_error.c b/src/glsl/pp/sl_pp_error.c index df9b191dfe..a9eeff98ba 100644 --- a/src/glsl/pp/sl_pp_error.c +++ b/src/glsl/pp/sl_pp_error.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_process.h" #include "sl_pp_public.h" diff --git a/src/glsl/pp/sl_pp_expression.c b/src/glsl/pp/sl_pp_expression.c index 3f6dfb5a6d..ec904787dd 100644 --- a/src/glsl/pp/sl_pp_expression.c +++ b/src/glsl/pp/sl_pp_expression.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_expression.h" #include "sl_pp_public.h" diff --git a/src/glsl/pp/sl_pp_extension.c b/src/glsl/pp/sl_pp_extension.c index 33193d03a8..4148fd9a5a 100644 --- a/src/glsl/pp/sl_pp_extension.c +++ b/src/glsl/pp/sl_pp_extension.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_process.h" diff --git a/src/glsl/pp/sl_pp_if.c b/src/glsl/pp/sl_pp_if.c index c8e958eab4..a0b3635dd5 100644 --- a/src/glsl/pp/sl_pp_if.c +++ b/src/glsl/pp/sl_pp_if.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_expression.h" #include "sl_pp_process.h" diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c index 41ddaf6ba2..fc2dd89e68 100644 --- a/src/glsl/pp/sl_pp_line.c +++ b/src/glsl/pp/sl_pp_line.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_public.h" #include "sl_pp_process.h" diff --git a/src/glsl/pp/sl_pp_pragma.c b/src/glsl/pp/sl_pp_pragma.c index 03269b63db..489eb17b8e 100644 --- a/src/glsl/pp/sl_pp_pragma.c +++ b/src/glsl/pp/sl_pp_pragma.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_process.h" diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c index 67ed588818..4b783e40b4 100644 --- a/src/glsl/pp/sl_pp_process.c +++ b/src/glsl/pp/sl_pp_process.c @@ -26,7 +26,9 @@ **************************************************************************/ #include +#include #include "sl_pp_process.h" +#include "sl_pp_public.h" static void diff --git a/src/glsl/pp/sl_pp_token.c b/src/glsl/pp/sl_pp_token.c index 99a32a6e67..f232dafc68 100644 --- a/src/glsl/pp/sl_pp_token.c +++ b/src/glsl/pp/sl_pp_token.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_context.h" #include "sl_pp_token.h" diff --git a/src/glsl/pp/sl_pp_version.c b/src/glsl/pp/sl_pp_version.c index adf3017bf2..db06523749 100644 --- a/src/glsl/pp/sl_pp_version.c +++ b/src/glsl/pp/sl_pp_version.c @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include #include "sl_pp_public.h" #include "sl_pp_context.h" -- cgit v1.2.3