From 95956bb8cb9513c429b9749426720be94f4cf5a8 Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Fri, 18 Sep 2009 11:19:25 +0200 Subject: [PATCH] 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 ---- .../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(-) rename src/glsl/pp/{sl_pp_version.h => sl_pp_public.h} (73%) 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 +#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 @@ -55,18 +55,8 @@ struct sl_pp_context { unsigned int file; }; -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 +#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 @@ -39,11 +39,6 @@ struct sl_pp_process_state { unsigned int out_max; }; -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, 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 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 +#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 -#include "sl_pp_version.h" +#include "sl_pp_public.h" +#include "sl_pp_context.h" int -- 2.30.2