From: Michal Krol Date: Fri, 18 Sep 2009 09:19:25 +0000 (+0200) Subject: glsl/pp: Define a public interface for external modules. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=95956bb8cb9513c429b9749426720be94f4cf5a8;p=mesa.git glsl/pp: Define a public interface for external modules. Make sl_pp_context struct opaque. Move all public declarations to sl_pp_public.h. --- 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_public.h b/src/glsl/pp/sl_pp_public.h new file mode 100644 index 00000000000..b1d92d02a7a --- /dev/null +++ b/src/glsl/pp/sl_pp_public.h @@ -0,0 +1,63 @@ +/************************************************************************** + * + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#ifndef SL_PP_PUBLIC_H +#define SL_PP_PUBLIC_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); + +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 diff --git a/src/glsl/pp/sl_pp_version.h b/src/glsl/pp/sl_pp_version.h deleted file mode 100644 index cee9f55bc6c..00000000000 --- a/src/glsl/pp/sl_pp_version.h +++ /dev/null @@ -1,41 +0,0 @@ -/************************************************************************** - * - * Copyright 2009 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef SL_PP_VERSION_H -#define SL_PP_VERSION_H - -#include "sl_pp_context.h" -#include "sl_pp_token.h" - - -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 */