summaryrefslogtreecommitdiffstats
path: root/src/glsl/pp
diff options
context:
space:
mode:
authorMichal Krol <[email protected]>2009-09-18 11:19:25 +0200
committerMichal Krol <[email protected]>2009-09-18 11:19:25 +0200
commit95956bb8cb9513c429b9749426720be94f4cf5a8 (patch)
treeec7396e2766d2f5b415d3224f8c28bcc5a80ebe3 /src/glsl/pp
parent2a661c383fee65bc4413541e706925fa3e9b9cf5 (diff)
glsl/pp: Define a public interface for external modules.
Make sl_pp_context struct opaque. Move all public declarations to sl_pp_public.h.
Diffstat (limited to 'src/glsl/pp')
-rw-r--r--src/glsl/pp/sl_pp_context.c29
-rw-r--r--src/glsl/pp/sl_pp_context.h10
-rw-r--r--src/glsl/pp/sl_pp_line.c1
-rw-r--r--src/glsl/pp/sl_pp_process.h5
-rw-r--r--src/glsl/pp/sl_pp_public.h (renamed from src/glsl/pp/sl_pp_version.h)30
-rw-r--r--src/glsl/pp/sl_pp_token.c1
-rw-r--r--src/glsl/pp/sl_pp_token.h2
-rw-r--r--src/glsl/pp/sl_pp_version.c3
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 b196d8102a0..fd205de5d32 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 8bed1420454..6b8cc2f960d 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 504c20ebcdd..cab0262686c 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 adc08c18ae3..24311bab603 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
index cee9f55bc6c..b1d92d02a7a 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 a6a2bb27485..3a7ffe7db15 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 59019593839..4131be6bdad 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 814da46a672..825967d4c10 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