Mesa (glsl-pp-rework-1): glsl: Centralise sl_pp_macro constructor.

Michał Król michal at kemper.freedesktop.org
Fri Jun 26 10:54:18 UTC 2009


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

Author: Michal Krol <michal at vmware.com>
Date:   Mon Jun 22 09:14:14 2009 +0200

glsl: Centralise sl_pp_macro constructor.

---

 src/glsl/pp/sl_pp_define.c  |    6 ------
 src/glsl/pp/sl_pp_macro.c   |   29 +++++++++++++++++++----------
 src/glsl/pp/sl_pp_macro.h   |    5 ++++-
 src/glsl/pp/sl_pp_process.c |    2 +-
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/glsl/pp/sl_pp_define.c b/src/glsl/pp/sl_pp_define.c
index 39d1435..e8a23fe 100644
--- a/src/glsl/pp/sl_pp_define.c
+++ b/src/glsl/pp/sl_pp_define.c
@@ -112,12 +112,6 @@ sl_pp_process_define(struct sl_pp_context *context,
    unsigned int body_len;
    unsigned int j;
 
-   macro->name = -1;
-   macro->num_args = -1;
-   macro->arg = NULL;
-   macro->body = NULL;
-   macro->next = NULL;
-
    if (first < last && input[first].token == SL_PP_IDENTIFIER) {
       macro->name = input[first].data.identifier;
       first++;
diff --git a/src/glsl/pp/sl_pp_macro.c b/src/glsl/pp/sl_pp_macro.c
index 82591b9..0138270 100644
--- a/src/glsl/pp/sl_pp_macro.c
+++ b/src/glsl/pp/sl_pp_macro.c
@@ -30,13 +30,17 @@
 #include "sl_pp_process.h"
 
 
-static void
-skip_whitespace(const struct sl_pp_token_info *input,
-                unsigned int *pi)
+struct sl_pp_macro *
+sl_pp_macro_new(void)
 {
-   while (input[*pi].token == SL_PP_WHITESPACE) {
-      (*pi)++;
+   struct sl_pp_macro *macro;
+
+   macro = calloc(1, sizeof(struct sl_pp_macro));
+   if (macro) {
+      macro->name = -1;
+      macro->num_args = -1;
    }
+   return macro;
 }
 
 void
@@ -60,6 +64,15 @@ sl_pp_macro_free(struct sl_pp_macro *macro)
    }
 }
 
+static void
+skip_whitespace(const struct sl_pp_token_info *input,
+                unsigned int *pi)
+{
+   while (input[*pi].token == SL_PP_WHITESPACE) {
+      (*pi)++;
+   }
+}
+
 int
 sl_pp_macro_expand(struct sl_pp_context *context,
                    const struct sl_pp_token_info *input,
@@ -124,16 +137,12 @@ sl_pp_macro_expand(struct sl_pp_context *context,
          unsigned int paren_nesting = 0;
          unsigned int k;
 
-         *pmacro = malloc(sizeof(struct sl_pp_macro));
+         *pmacro = sl_pp_macro_new();
          if (!*pmacro) {
             return -1;
          }
 
          (**pmacro).name = formal_arg->name;
-         (**pmacro).num_args = -1;
-         (**pmacro).arg = NULL;
-         (**pmacro).body = NULL;
-         (**pmacro).next = NULL;
 
          body_len = 1;
          for (i = *pi; !done; i++) {
diff --git a/src/glsl/pp/sl_pp_macro.h b/src/glsl/pp/sl_pp_macro.h
index eeb338e..63edd21 100644
--- a/src/glsl/pp/sl_pp_macro.h
+++ b/src/glsl/pp/sl_pp_macro.h
@@ -38,12 +38,15 @@ struct sl_pp_macro_formal_arg {
 
 struct sl_pp_macro {
    int name;
-   int num_args;
+   int num_args;                       /* -1 means no args, 0 means `()' */
    struct sl_pp_macro_formal_arg *arg;
    struct sl_pp_token_info *body;
    struct sl_pp_macro *next;
 };
 
+struct sl_pp_macro *
+sl_pp_macro_new(void);
+
 void
 sl_pp_macro_free(struct sl_pp_macro *macro);
 
diff --git a/src/glsl/pp/sl_pp_process.c b/src/glsl/pp/sl_pp_process.c
index e930966..baffaf2 100644
--- a/src/glsl/pp/sl_pp_process.c
+++ b/src/glsl/pp/sl_pp_process.c
@@ -133,7 +133,7 @@ sl_pp_process(struct sl_pp_context *context,
                last = i - 1;
 
                if (!strcmp(name, "define")) {
-                  *macro = malloc(sizeof(struct sl_pp_macro));
+                  *macro = sl_pp_macro_new();
                   if (!*macro) {
                      return -1;
                   }




More information about the mesa-commit mailing list