# HG changeset patch # User Ryan C. Gordon # Date 1266782094 18000 # Node ID d557c433624251ca9cc89f82857efcef2504bca1 # Parent 1ea7f51250fbb1f99e735b7974bdc8db597d36fd Keep track of token location when parsing. diff -r 1ea7f51250fb -r d557c4336242 mojoshader_compiler.c --- a/mojoshader_compiler.c Sun Feb 21 01:02:34 2010 -0500 +++ b/mojoshader_compiler.c Sun Feb 21 14:54:54 2010 -0500 @@ -482,6 +482,8 @@ ErrorList *errors; Preprocessor *preprocessor; StringBucket *string_hashtable[256]; + const char *sourcefile; + unsigned int sourceline; const char *usertypes[512]; // !!! FIXME: dynamic allocation int usertype_count; CompilationUnit *ast; // Abstract Syntax Tree @@ -522,7 +524,7 @@ { // !!! FIXME: placeholder. (void) ctx; - printf("FAIL: %s\n", str); + printf("%s:%u: %s\n", ctx->sourcefile, ctx->sourceline, str); } // fail // These functions are mostly for construction and cleanup of nodes in the @@ -1787,6 +1789,7 @@ Token tokenval; const char *token; int lemon_token; + const char *fname; if (m == NULL) m = MOJOSHADER_internal_malloc; if (f == NULL) f = MOJOSHADER_internal_free; @@ -1816,7 +1819,10 @@ break; } // if - else if (tokenval == TOKEN_BAD_CHARS) + fname = preprocessor_sourcepos(ctx.preprocessor, &ctx.sourceline); + ctx.sourcefile = fname ? cache_string(&ctx, fname, strlen(fname)) : 0; + + if (tokenval == TOKEN_BAD_CHARS) { fail(&ctx, "Bad characters in source file"); continue;