From 21ecec1683eb14016fe2bff89be0b76122a3160c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 9 Nov 2010 05:05:41 -0500 Subject: [PATCH] Made ErrorList struct opaque to callers. --- mojoshader.c | 2 +- mojoshader_assembler.c | 2 +- mojoshader_common.c | 23 +++++++++++++++++++++++ mojoshader_compiler.c | 12 ++++++------ mojoshader_internal.h | 20 +++----------------- mojoshader_preprocessor.c | 5 +++-- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index c4422bec..56cf9542 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -7359,7 +7359,7 @@ static MOJOSHADER_parseData *build_parsedata(Context *ctx) if (!isfail(ctx)) samplers = build_samplers(ctx); - const int error_count = ctx->errors->count; + const int error_count = errorlist_count(ctx->errors); errors = errorlist_flatten(ctx->errors); if (!isfail(ctx)) diff --git a/mojoshader_assembler.c b/mojoshader_assembler.c index 99ee6406..09ffa43a 100644 --- a/mojoshader_assembler.c +++ b/mojoshader_assembler.c @@ -1515,7 +1515,7 @@ static const MOJOSHADER_parseData *build_failed_assembly(Context *ctx) retval->free = (ctx->free == MOJOSHADER_internal_free) ? NULL : ctx->free; retval->malloc_data = ctx->malloc_data; - retval->error_count = ctx->errors->count; + retval->error_count = errorlist_count(ctx->errors); retval->errors = errorlist_flatten(ctx->errors); if (ctx->out_of_memory) { diff --git a/mojoshader_common.c b/mojoshader_common.c index 5c4bc789..8b6f35d0 100644 --- a/mojoshader_common.c +++ b/mojoshader_common.c @@ -390,6 +390,23 @@ void stringcache_destroy(StringCache *cache) } // stringcache_destroy +// We chain errors as a linked list with a head/tail for easy appending. +// These get flattened before passing to the application. +typedef struct ErrorItem +{ + MOJOSHADER_error error; + struct ErrorItem *next; +} ErrorItem; + +struct ErrorList +{ + ErrorItem head; + ErrorItem *tail; + int count; + MOJOSHADER_malloc m; + MOJOSHADER_free f; + void *d; +}; ErrorList *errorlist_create(MOJOSHADER_malloc m, MOJOSHADER_free f, void *d) { @@ -483,6 +500,12 @@ int errorlist_add_va(ErrorList *list, const char *_fname, } // errorlist_add_va +int errorlist_count(ErrorList *list) +{ + return list->count; +} // errorlist_count + + MOJOSHADER_error *errorlist_flatten(ErrorList *list) { if (list->count == 0) diff --git a/mojoshader_compiler.c b/mojoshader_compiler.c index 6419ce6a..0cc239b0 100644 --- a/mojoshader_compiler.c +++ b/mojoshader_compiler.c @@ -2368,7 +2368,7 @@ static const MOJOSHADER_astData *build_failed_ast(Context *ctx) retval->malloc = (ctx->malloc == MOJOSHADER_internal_malloc) ? NULL : ctx->malloc; retval->free = (ctx->free == MOJOSHADER_internal_free) ? NULL : ctx->free; retval->malloc_data = ctx->malloc_data; - retval->error_count = ctx->errors->count; + retval->error_count = errorlist_count(ctx->errors); retval->errors = errorlist_flatten(ctx->errors); if (ctx->out_of_memory) @@ -2403,7 +2403,7 @@ static const MOJOSHADER_astData *build_astdata(Context *ctx) retval->ast = ctx->ast; } // if - retval->error_count = ctx->errors->count; + retval->error_count = errorlist_count(ctx->errors); retval->errors = errorlist_flatten(ctx->errors); if (ctx->out_of_memory) { @@ -2462,9 +2462,9 @@ static const MOJOSHADER_compileData *build_failed_compile(Context *ctx) retval->free = (ctx->free == MOJOSHADER_internal_free) ? NULL : ctx->free; retval->malloc_data = ctx->malloc_data; retval->source_profile = ctx->source_profile; - retval->error_count = ctx->errors->count; + retval->error_count = errorlist_count(ctx->errors); retval->errors = errorlist_flatten(ctx->errors); - retval->warning_count = ctx->warnings->count; + retval->warning_count = errorlist_count(ctx->warnings); retval->warnings = errorlist_flatten(ctx->warnings); if (ctx->out_of_memory) // in case something failed up there. @@ -2503,9 +2503,9 @@ static const MOJOSHADER_compileData *build_compiledata(Context *ctx) // !!! FIXME: build symbols and symbol_count here. } // if - retval->error_count = ctx->errors->count; + retval->error_count = errorlist_count(ctx->errors); retval->errors = errorlist_flatten(ctx->errors); - retval->warning_count = ctx->warnings->count; + retval->warning_count = errorlist_count(ctx->warnings); retval->warnings = errorlist_flatten(ctx->warnings); if (ctx->out_of_memory) // in case something failed up there. diff --git a/mojoshader_internal.h b/mojoshader_internal.h index 8e65e8a7..735ee6ca 100644 --- a/mojoshader_internal.h +++ b/mojoshader_internal.h @@ -194,24 +194,9 @@ const char *stringcache_fmt(StringCache *cache, const char *fmt, ...); void stringcache_destroy(StringCache *cache); -// We chain errors as a linked list with a head/tail for easy appending. -// These get flattened before passing to the application. -typedef struct ErrorItem -{ - MOJOSHADER_error error; - struct ErrorItem *next; -} ErrorItem; - -typedef struct ErrorList -{ - ErrorItem head; - ErrorItem *tail; - int count; - MOJOSHADER_malloc m; - MOJOSHADER_free f; - void *d; -} ErrorList; +// Error lists... +typedef struct ErrorList ErrorList; ErrorList *errorlist_create(MOJOSHADER_malloc m, MOJOSHADER_free f, void *d); int errorlist_add(ErrorList *list, const char *fname, const int errpos, const char *str); @@ -219,6 +204,7 @@ int errorlist_add_fmt(ErrorList *list, const char *fname, const int errpos, const char *fmt, ...) ISPRINTF(4,5); int errorlist_add_va(ErrorList *list, const char *_fname, const int errpos, const char *fmt, va_list va); +int errorlist_count(ErrorList *list); MOJOSHADER_error *errorlist_flatten(ErrorList *list); // resets the list! void errorlist_destroy(ErrorList *list); diff --git a/mojoshader_preprocessor.c b/mojoshader_preprocessor.c index 9095cf63..4949cd3f 100644 --- a/mojoshader_preprocessor.c +++ b/mojoshader_preprocessor.c @@ -2319,9 +2319,10 @@ const MOJOSHADER_preprocessData *MOJOSHADER_preprocess(const char *filename, } // if memset(retval, '\0', sizeof (*retval)); - if (errors->count > 0) + const int errcount = errorlist_count(errors); + if (errcount > 0) { - retval->error_count = errors->count; + retval->error_count = errcount; retval->errors = errorlist_flatten(errors); if (retval->errors == NULL) {