Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Made ErrorList struct opaque to callers.
  • Loading branch information
icculus committed Nov 9, 2010
1 parent c208fba commit 21ecec1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion mojoshader.c
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion mojoshader_assembler.c
Expand Up @@ -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)
{
Expand Down
23 changes: 23 additions & 0 deletions mojoshader_common.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions mojoshader_compiler.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 3 additions & 17 deletions mojoshader_internal.h
Expand Up @@ -194,31 +194,17 @@ 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);
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);

Expand Down
5 changes: 3 additions & 2 deletions mojoshader_preprocessor.c
Expand Up @@ -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)
{
Expand Down

0 comments on commit 21ecec1

Please sign in to comment.