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

Make sl_pp_context struct opaque.
Move all public declarations to sl_pp_public.h.
This commit is contained in:
Michal Krol 2009-09-18 11:19:25 +02:00
parent 2a661c383f
commit 95956bb8cb
8 changed files with 52 additions and 29 deletions

View file

@ -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

View file

@ -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 */

View file

@ -26,6 +26,7 @@
**************************************************************************/
#include <stdlib.h>
#include "sl_pp_public.h"
#include "sl_pp_process.h"

View file

@ -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,

View file

@ -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 */

View file

@ -26,6 +26,7 @@
**************************************************************************/
#include <stdlib.h>
#include "sl_pp_context.h"
#include "sl_pp_token.h"

View file

@ -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,

View file

@ -26,7 +26,8 @@
**************************************************************************/
#include <stdlib.h>
#include "sl_pp_version.h"
#include "sl_pp_public.h"
#include "sl_pp_context.h"
int