7 * This file written by Ryan C. Gordon. |
7 * This file written by Ryan C. Gordon. |
8 */ |
8 */ |
9 |
9 |
10 #define __MOJOSHADER_INTERNAL__ 1 |
10 #define __MOJOSHADER_INTERNAL__ 1 |
11 #include "mojoshader_internal.h" |
11 #include "mojoshader_internal.h" |
|
12 |
|
13 #define DEBUG_TOKENIZER 1 |
12 |
14 |
13 typedef struct DefineHash |
15 typedef struct DefineHash |
14 { |
16 { |
15 MOJOSHADER_preprocessorDefine define; |
17 MOJOSHADER_preprocessorDefine define; |
16 struct DefineHash *next; |
18 struct DefineHash *next; |
325 Context *ctx = (Context *) _ctx; |
327 Context *ctx = (Context *) _ctx; |
326 return ctx->out_of_memory; |
328 return ctx->out_of_memory; |
327 } // preprocessor_outofmemory |
329 } // preprocessor_outofmemory |
328 |
330 |
329 |
331 |
330 const char *preprocessor_nexttoken(Preprocessor *_ctx, unsigned int *_len, |
332 static inline const char *_preprocessor_nexttoken(Preprocessor *_ctx, |
331 Token *_token) |
333 unsigned int *_len, Token *_token) |
332 { |
334 { |
333 Context *ctx = (Context *) _ctx; |
335 Context *ctx = (Context *) _ctx; |
334 |
336 |
335 while (1) |
337 while (1) |
336 { |
338 { |
387 |
389 |
388 *_token = token; |
390 *_token = token; |
389 *_len = (unsigned int) (state->source - state->token); |
391 *_len = (unsigned int) (state->source - state->token); |
390 return state->token; |
392 return state->token; |
391 } // while |
393 } // while |
|
394 |
|
395 assert(0 && "shouldn't hit this code"); |
|
396 *_token = TOKEN_UNKNOWN; |
|
397 *_len = 0; |
|
398 return NULL; |
|
399 } // _preprocessor_nexttoken |
|
400 |
|
401 |
|
402 const char *preprocessor_nexttoken(Preprocessor *ctx, unsigned int *len, |
|
403 Token *token) |
|
404 { |
|
405 const char *retval = _preprocessor_nexttoken(ctx, len, token); |
|
406 |
|
407 #if DEBUG_TOKENIZER |
|
408 printf("TOKEN: \""); |
|
409 unsigned int i; |
|
410 for (i = 0; i < *len; i++) |
|
411 { |
|
412 if (retval[i] == '\n') |
|
413 printf("\\n"); |
|
414 else |
|
415 printf("%c", retval[i]); |
|
416 } // for |
|
417 printf("\" ("); |
|
418 switch (*token) |
|
419 { |
|
420 #define TOKENCASE(x) case x: printf("%s", #x); break |
|
421 TOKENCASE(TOKEN_UNKNOWN); |
|
422 TOKENCASE(TOKEN_IDENTIFIER); |
|
423 TOKENCASE(TOKEN_INT_LITERAL); |
|
424 TOKENCASE(TOKEN_FLOAT_LITERAL); |
|
425 TOKENCASE(TOKEN_STRING_LITERAL); |
|
426 TOKENCASE(TOKEN_ELLIPSIS); |
|
427 TOKENCASE(TOKEN_RSHIFT); |
|
428 TOKENCASE(TOKEN_LSHIFT); |
|
429 TOKENCASE(TOKEN_ANDAND); |
|
430 TOKENCASE(TOKEN_OROR); |
|
431 TOKENCASE(TOKEN_LEQ); |
|
432 TOKENCASE(TOKEN_GEQ); |
|
433 TOKENCASE(TOKEN_EQL); |
|
434 TOKENCASE(TOKEN_NEQ); |
|
435 TOKENCASE(TOKEN_HASHHASH); |
|
436 TOKENCASE(TOKEN_PP_INCLUDE); |
|
437 TOKENCASE(TOKEN_PP_LINE); |
|
438 TOKENCASE(TOKEN_PP_DEFINE); |
|
439 TOKENCASE(TOKEN_PP_UNDEF); |
|
440 TOKENCASE(TOKEN_PP_IF); |
|
441 TOKENCASE(TOKEN_PP_IFDEF); |
|
442 TOKENCASE(TOKEN_PP_IFNDEF); |
|
443 TOKENCASE(TOKEN_PP_ELSE); |
|
444 TOKENCASE(TOKEN_PP_ELIF); |
|
445 TOKENCASE(TOKEN_PP_ENDIF); |
|
446 TOKENCASE(TOKEN_PP_ERROR); |
|
447 TOKENCASE(TOKEN_PP_INCOMPLETE_COMMENT); |
|
448 TOKENCASE(TOKEN_EOI); |
|
449 #undef TOKENCASE |
|
450 |
|
451 case ((Token) '\n'): |
|
452 printf("'\\n'"); |
|
453 break; |
|
454 |
|
455 default: |
|
456 assert(((int)*token) < 256); |
|
457 printf("'%c'", (char) *token); |
|
458 break; |
|
459 } // switch |
|
460 printf(")\n"); |
|
461 #endif |
|
462 |
|
463 return retval; |
392 } // preprocessor_nexttoken |
464 } // preprocessor_nexttoken |
393 |
465 |
394 |
466 |
395 const char *preprocessor_sourcepos(Preprocessor *_ctx, unsigned int *pos) |
467 const char *preprocessor_sourcepos(Preprocessor *_ctx, unsigned int *pos) |
396 { |
468 { |