Skip to content
Permalink
Browse files
Added error position information to MOJOSHADER_parseData.
  • Loading branch information
icculus committed Dec 10, 2008
1 parent 16caf77 commit 95e6c633d83f10b5f9bac4e7258b5dafa95f5fc7
Showing with 24 additions and 4 deletions.
  1. +1 −1 finderrors.c
  2. +12 −1 mojoshader.c
  3. +9 −0 mojoshader.h
  4. +1 −1 testoutput.c
  5. +1 −1 testparse.c
@@ -96,7 +96,7 @@ static int do_file(const char *profile, const char *dname, const char *fn, int *
#else
const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, buf, rc, NULL, 0, NULL, NULL, NULL);
if (pd->error != NULL)
report("FAIL: %s %s\n", fname, pd->error);
report("FAIL: %s (position %d) %s\n", fname, pd->error_position, pd->error);
else
report("PASS: %s\n", fname);
MOJOSHADER_freeParseData(pd);
@@ -161,8 +161,10 @@ struct Context
MOJOSHADER_malloc malloc;
MOJOSHADER_free free;
void *malloc_data;
const uint32 *orig_tokens;
const uint32 *tokens;
uint32 tokencount;
int started_parsing;
const MOJOSHADER_swizzle *swizzles;
unsigned int swizzles_count;
OutputList *output;
@@ -234,7 +236,7 @@ struct Context
// Convenience functions for allocators...

MOJOSHADER_parseData out_of_mem_data = {
"Out of memory", 0, 0, 0, 0, MOJOSHADER_TYPE_UNKNOWN, 0, 0, 0, 0
"Out of memory", -1, 0, 0, 0, 0, MOJOSHADER_TYPE_UNKNOWN, 0, 0, 0, 0
};

const char *out_of_mem_str = "Out of memory";
@@ -6627,6 +6629,7 @@ static Context *build_context(const char *profile,
ctx->free = f;
ctx->malloc_data = d;
ctx->tokens = (const uint32 *) tokenbuf;
ctx->orig_tokens = (const uint32 *) tokenbuf;
ctx->tokencount = bufsize / sizeof (uint32);
ctx->swizzles = swiz;
ctx->swizzles_count = swizcount;
@@ -7083,11 +7086,16 @@ static MOJOSHADER_parseData *build_parsedata(Context *ctx)
Free(ctx, samplers);
} // if

if (ctx->started_parsing)
retval->error_position = (ctx->tokens - ctx->orig_tokens) * sizeof (uint32);
else
retval->error_position = -1;
retval->error = ctx->failstr; // we recycle. :)
ctx->failstr = NULL; // don't let this get free()'d too soon.
} // if
else
{
retval->error_position = -2;
retval->profile = ctx->profile->name;
retval->output = output;
retval->output_len = ctx->output_len;
@@ -7297,7 +7305,10 @@ const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,

// Version token always comes first.
if (!isfail(ctx))
{
ctx->started_parsing = 1;
rc = parse_version_token(ctx, profile);
} // if

// parse out the rest of the tokens after the version token...
while ( (rc > 0) && (!isfail(ctx)) )
@@ -251,6 +251,15 @@ typedef struct MOJOSHADER_parseData
*/
const char *error;

/*
* Position of error, if there is one. Will be -2 if there was no
* error, and -1 if there was an error before processing started. If >= 0,
* MOJOSHADER_parse() sets this to the byte offset (starting at zero) into
* the bytecode you supplied, and MOJOSHADER_assemble() sets this to a
* a line number in the source code you supplied (starting at zero).
*/
int error_position;

/*
* The name of the profile used to parse the shader. Will be NULL on error.
*/
@@ -18,7 +18,7 @@ static int do_parse(const unsigned char *buf, const int len, const char *prof)

pd = MOJOSHADER_parse(prof, buf, len, NULL, 0, NULL, NULL, NULL);
if (pd->error != NULL)
printf("ERROR: %s\n", pd->error);
printf("ERROR: (position %d) %s\n", pd->error_position, pd->error);
else
{
retval = 1;
@@ -62,7 +62,7 @@ static int do_parse(const unsigned char *buf, const int len, const char *prof)
pd = MOJOSHADER_parse(prof, buf, len, NULL, 0, Malloc, Free, NULL);
printf("PROFILE: %s\n", prof);
if (pd->error != NULL)
printf("ERROR: %s\n", pd->error);
printf("ERROR: (position %d) %s\n", pd->error_position, pd->error);
else
{
retval = 1;

0 comments on commit 95e6c63

Please sign in to comment.