Mesa (glsl-pp-rework-2): slang/pp: Use a dictionary for the remaining string literals.

Michał Król michal at kemper.freedesktop.org
Thu Sep 17 10:16:42 UTC 2009


Module: Mesa
Branch: glsl-pp-rework-2
Commit: ce8f486156f5c4b28b51954ea862675275c38f6d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=ce8f486156f5c4b28b51954ea862675275c38f6d

Author: Michal Krol <michal at vmware.com>
Date:   Thu Sep 17 12:12:34 2009 +0200

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(-)

diff --git a/src/glsl/pp/sl_pp_dict.c b/src/glsl/pp/sl_pp_dict.c
index 65b91d9..f2885c7 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 ce138d9..ba82b38 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 44bbefa..cf1c746 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 7793562..6772100 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 1cd9fd8..03269b6 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 03a3051..ab2f2d8 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 6cd63f4..814da46 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:




More information about the mesa-commit mailing list