mojoshader_compiler.c
changeset 843 d557c4336242
parent 842 1ea7f51250fb
child 844 06494572317b
equal deleted inserted replaced
842:1ea7f51250fb 843:d557c4336242
   480     void *malloc_data;
   480     void *malloc_data;
   481     int error_count;
   481     int error_count;
   482     ErrorList *errors;
   482     ErrorList *errors;
   483     Preprocessor *preprocessor;
   483     Preprocessor *preprocessor;
   484     StringBucket *string_hashtable[256];
   484     StringBucket *string_hashtable[256];
       
   485     const char *sourcefile;
       
   486     unsigned int sourceline;
   485     const char *usertypes[512];  // !!! FIXME: dynamic allocation
   487     const char *usertypes[512];  // !!! FIXME: dynamic allocation
   486     int usertype_count;
   488     int usertype_count;
   487     CompilationUnit *ast;  // Abstract Syntax Tree
   489     CompilationUnit *ast;  // Abstract Syntax Tree
   488 } Context;
   490 } Context;
   489 
   491 
   520 
   522 
   521 static void fail(Context *ctx, const char *str)
   523 static void fail(Context *ctx, const char *str)
   522 {
   524 {
   523     // !!! FIXME: placeholder.
   525     // !!! FIXME: placeholder.
   524     (void) ctx;
   526     (void) ctx;
   525     printf("FAIL: %s\n", str);
   527     printf("%s:%u: %s\n", ctx->sourcefile, ctx->sourceline, str);
   526 } // fail
   528 } // fail
   527 
   529 
   528 // These functions are mostly for construction and cleanup of nodes in the
   530 // These functions are mostly for construction and cleanup of nodes in the
   529 //  parse tree. Mostly this is simple allocation and initialization, so we
   531 //  parse tree. Mostly this is simple allocation and initialization, so we
   530 //  can do as little in the lemon code as possible, and then sort it all out
   532 //  can do as little in the lemon code as possible, and then sort it all out
  1785     TokenData data;
  1787     TokenData data;
  1786     unsigned int tokenlen;
  1788     unsigned int tokenlen;
  1787     Token tokenval;
  1789     Token tokenval;
  1788     const char *token;
  1790     const char *token;
  1789     int lemon_token;
  1791     int lemon_token;
       
  1792     const char *fname;
  1790 
  1793 
  1791     if (m == NULL) m = MOJOSHADER_internal_malloc;
  1794     if (m == NULL) m = MOJOSHADER_internal_malloc;
  1792     if (f == NULL) f = MOJOSHADER_internal_free;
  1795     if (f == NULL) f = MOJOSHADER_internal_free;
  1793 
  1796 
  1794     memset(&ctx, '\0', sizeof (Context));
  1797     memset(&ctx, '\0', sizeof (Context));
  1814         {
  1817         {
  1815             out_of_memory(&ctx);
  1818             out_of_memory(&ctx);
  1816             break;
  1819             break;
  1817         } // if
  1820         } // if
  1818 
  1821 
  1819         else if (tokenval == TOKEN_BAD_CHARS)
  1822         fname = preprocessor_sourcepos(ctx.preprocessor, &ctx.sourceline);
       
  1823         ctx.sourcefile = fname ? cache_string(&ctx, fname, strlen(fname)) : 0;
       
  1824 
       
  1825         if (tokenval == TOKEN_BAD_CHARS)
  1820         {
  1826         {
  1821             fail(&ctx, "Bad characters in source file");
  1827             fail(&ctx, "Bad characters in source file");
  1822             continue;
  1828             continue;
  1823         } // else if
  1829         } // else if
  1824 
  1830