Mesa (glsl-pp-rework-2): glsl/pp: Define a public interface for external modules.

Michał Król michal at kemper.freedesktop.org
Fri Sep 18 09:42:54 UTC 2009


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

Author: Michal Krol <michal at vmware.com>
Date:   Fri Sep 18 11:19:25 2009 +0200

glsl/pp: Define a public interface for external modules.

Make sl_pp_context struct opaque.
Move all public declarations to sl_pp_public.h.

---

 src/glsl/pp/sl_pp_context.c                     |   29 ++++++++++++++++-----
 src/glsl/pp/sl_pp_context.h                     |   10 -------
 src/glsl/pp/sl_pp_line.c                        |    1 +
 src/glsl/pp/sl_pp_process.h                     |    5 ----
 src/glsl/pp/{sl_pp_version.h => sl_pp_public.h} |   30 +++++++++++++++++++---
 src/glsl/pp/sl_pp_token.c                       |    1 +
 src/glsl/pp/sl_pp_token.h                       |    2 -
 src/glsl/pp/sl_pp_version.c                     |    3 +-
 8 files changed, 52 insertions(+), 29 deletions(-)

diff --git a/src/glsl/pp/sl_pp_context.c b/src/glsl/pp/sl_pp_context.c
index b196d81..fd205de 100644
--- a/src/glsl/pp/sl_pp_context.c
+++ b/src/glsl/pp/sl_pp_context.c
@@ -26,17 +26,23 @@
  **************************************************************************/
 
 #include <stdlib.h>
+#include "sl_pp_public.h"
 #include "sl_pp_context.h"
 
 
-int
-sl_pp_context_init(struct sl_pp_context *context)
+struct sl_pp_context *
+sl_pp_context_create(void)
 {
-   memset(context, 0, sizeof(struct sl_pp_context));
+   struct sl_pp_context *context;
+
+   context = calloc(1, sizeof(struct sl_pp_context));
+   if (!context) {
+      return NULL;
+   }
 
    if (sl_pp_dict_init(context)) {
       sl_pp_context_destroy(context);
-      return -1;
+      return NULL;
    }
 
    context->macro_tail = &context->macro;
@@ -46,14 +52,23 @@ sl_pp_context_init(struct sl_pp_context *context)
    context->line = 1;
    context->file = 0;
 
-   return 0;
+   return context;
 }
 
 void
 sl_pp_context_destroy(struct sl_pp_context *context)
 {
-   free(context->cstr_pool);
-   sl_pp_macro_free(context->macro);
+   if (context) {
+      free(context->cstr_pool);
+      sl_pp_macro_free(context->macro);
+      free(context);
+   }
+}
+
+const char *
+sl_pp_context_error_message(const struct sl_pp_context *context)
+{
+   return context->error_msg;
 }
 
 int
diff --git a/src/glsl/pp/sl_pp_context.h b/src/glsl/pp/sl_pp_context.h
index 8bed142..6b8cc2f 100644
--- a/src/glsl/pp/sl_pp_context.h
+++ b/src/glsl/pp/sl_pp_context.h
@@ -56,17 +56,7 @@ struct sl_pp_context {
 };
 
 int
-sl_pp_context_init(struct sl_pp_context *context);
-
-void
-sl_pp_context_destroy(struct sl_pp_context *context);
-
-int
 sl_pp_context_add_unique_str(struct sl_pp_context *context,
                              const char *str);
 
-const char *
-sl_pp_context_cstr(const struct sl_pp_context *context,
-                   int offset);
-
 #endif /* SL_PP_CONTEXT_H */
diff --git a/src/glsl/pp/sl_pp_line.c b/src/glsl/pp/sl_pp_line.c
index 504c20e..cab0262 100644
--- a/src/glsl/pp/sl_pp_line.c
+++ b/src/glsl/pp/sl_pp_line.c
@@ -26,6 +26,7 @@
  **************************************************************************/
 
 #include <stdlib.h>
+#include "sl_pp_public.h"
 #include "sl_pp_process.h"
 
 
diff --git a/src/glsl/pp/sl_pp_process.h b/src/glsl/pp/sl_pp_process.h
index adc08c1..24311ba 100644
--- a/src/glsl/pp/sl_pp_process.h
+++ b/src/glsl/pp/sl_pp_process.h
@@ -40,11 +40,6 @@ struct sl_pp_process_state {
 };
 
 int
-sl_pp_process(struct sl_pp_context *context,
-              const struct sl_pp_token_info *input,
-              struct sl_pp_token_info **output);
-
-int
 sl_pp_process_define(struct sl_pp_context *context,
                      const struct sl_pp_token_info *input,
                      unsigned int first,
diff --git a/src/glsl/pp/sl_pp_version.h b/src/glsl/pp/sl_pp_public.h
similarity index 73%
rename from src/glsl/pp/sl_pp_version.h
rename to src/glsl/pp/sl_pp_public.h
index cee9f55..b1d92d0 100644
--- a/src/glsl/pp/sl_pp_version.h
+++ b/src/glsl/pp/sl_pp_public.h
@@ -25,17 +25,39 @@
  * 
  **************************************************************************/
 
-#ifndef SL_PP_VERSION_H
-#define SL_PP_VERSION_H
+#ifndef SL_PP_PUBLIC_H
+#define SL_PP_PUBLIC_H
 
-#include "sl_pp_context.h"
+
+struct sl_pp_context;
+
+
+#include "sl_pp_purify.h"
 #include "sl_pp_token.h"
 
 
+struct sl_pp_context *
+sl_pp_context_create(void);
+
+void
+sl_pp_context_destroy(struct sl_pp_context *context);
+
+const char *
+sl_pp_context_error_message(const struct sl_pp_context *context);
+
+const char *
+sl_pp_context_cstr(const struct sl_pp_context *context,
+                   int offset);
+
 int
 sl_pp_version(struct sl_pp_context *context,
               const struct sl_pp_token_info *input,
               unsigned int *version,
               unsigned int *tokens_eaten);
 
-#endif /* SL_PP_VERSION_H */
+int
+sl_pp_process(struct sl_pp_context *context,
+              const struct sl_pp_token_info *input,
+              struct sl_pp_token_info **output);
+
+#endif /* SL_PP_PUBLIC_H */
diff --git a/src/glsl/pp/sl_pp_token.c b/src/glsl/pp/sl_pp_token.c
index a6a2bb2..3a7ffe7 100644
--- a/src/glsl/pp/sl_pp_token.c
+++ b/src/glsl/pp/sl_pp_token.c
@@ -26,6 +26,7 @@
  **************************************************************************/
 
 #include <stdlib.h>
+#include "sl_pp_context.h"
 #include "sl_pp_token.h"
 
 
diff --git a/src/glsl/pp/sl_pp_token.h b/src/glsl/pp/sl_pp_token.h
index 5901959..4131be6 100644
--- a/src/glsl/pp/sl_pp_token.h
+++ b/src/glsl/pp/sl_pp_token.h
@@ -28,8 +28,6 @@
 #ifndef SL_PP_TOKEN_H
 #define SL_PP_TOKEN_H
 
-#include "sl_pp_context.h"
-
 
 enum sl_pp_token {
    SL_PP_WHITESPACE,
diff --git a/src/glsl/pp/sl_pp_version.c b/src/glsl/pp/sl_pp_version.c
index 814da46..825967d 100644
--- a/src/glsl/pp/sl_pp_version.c
+++ b/src/glsl/pp/sl_pp_version.c
@@ -26,7 +26,8 @@
  **************************************************************************/
 
 #include <stdlib.h>
-#include "sl_pp_version.h"
+#include "sl_pp_public.h"
+#include "sl_pp_context.h"
 
 
 int




More information about the mesa-commit mailing list