Unified · Split
| @@ -443,6 +443,10 @@ TokenSym *tok_alloc(char *str, int len) · 442 unmodified lines | |||
| 443 | return ts; | 443 | return ts; |
| 444 | pts = &(ts->hash_next); | 444 | pts = &(ts->hash_next); |
| 445 | } | 445 | } |
| 446 | |||
| 447 | if (tok_ident >= SYM_FIRST_ANOM) | ||
| 448 | error("memory full"); | ||
| 449 | |||
| 446 | /* expand token table if needed */ | 450 | /* expand token table if needed */ |
| 447 | i = tok_ident - TOK_IDENT; | 451 | i = tok_ident - TOK_IDENT; |
| 448 | if ((i % TOK_ALLOC_INCR) == 0) { | 452 | if ((i % TOK_ALLOC_INCR) == 0) { |
| @@ -451,8 +455,9 @@ TokenSym *tok_alloc(char *str, int len) · 2 unmodified lines | |||
| 451 | error("memory full"); | 455 | error("memory full"); |
| 452 | table_ident = ptable; | 456 | table_ident = ptable; |
| 453 | } | 457 | } |
| 458 | |||
| 454 | ts = malloc(sizeof(TokenSym) + len); | 459 | ts = malloc(sizeof(TokenSym) + len); |
| 455 | if (!ts || tok_ident >= SYM_FIRST_ANOM) | 460 | if (!ts) |
| 456 | error("memory full"); | 461 | error("memory full"); |
| 457 | table_ident[i] = ts; | 462 | table_ident[i] = ts; |
| 458 | ts->tok = tok_ident++; | 463 | ts->tok = tok_ident++; |
| @@ -1468,7 +1473,7 @@ void macro_subst(int **tok_str, int *tok_len, · 1009 unmodified lines | |||
| 1468 | } | 1473 | } |
| 1469 | 1474 | ||
| 1470 | /* return next token with macro substitution */ | 1475 | /* return next token with macro substitution */ |
| 1471 | void next() | 1476 | void next(void) |
| 1472 | { | 1477 | { |
| 1473 | int len, *ptr; | 1478 | int len, *ptr; |
| 1474 | Sym *nested_list; | 1479 | Sym *nested_list; |
| @@ -2413,46 +2418,87 @@ int struct_decl(int u) · 938 unmodified lines | |||
| 2413 | */ | 2418 | */ |
| 2414 | int ist(void) | 2419 | int ist(void) |
| 2415 | { | 2420 | { |
| 2416 | int t; | 2421 | int t, u; |
| 2417 | Sym *s; | 2422 | Sym *s; |
| 2418 | 2423 | ||
| 2419 | t = 0; | 2424 | t = 0; |
| 2420 | while(1) { | 2425 | while(1) { |
| 2421 | if (tok == TOK_ENUM) { | 2426 | switch(tok) { |
| 2422 | t |= struct_decl(VT_ENUM); | 2427 | /* basic types */ |
| 2423 | } else if (tok == TOK_STRUCT || tok == TOK_UNION) { | 2428 | case TOK_CHAR: |
| 2424 | t |= struct_decl(VT_STRUCT); | 2429 | u = VT_BYTE; |
| 2425 | } else { | 2430 | basic_type: |
| 2426 | if (tok == TOK_CHAR) { | 2431 | next(); |
| 2427 | t |= VT_BYTE; | 2432 | basic_type1: |
| 2428 | } else if (tok == TOK_VOID) { | 2433 | if ((t & VT_BTYPE) != 0) |
| 2429 | t |= VT_VOID; | 2434 | error("too many basic types %x", t); |
| 2430 | } else if (tok == TOK_SHORT) { | 2435 | t |= u; |
| 2431 | t |= VT_SHORT; | 2436 | break; |
| 2432 | } else if (tok == TOK_INT | | 2437 | case TOK_VOID: |
| 2433 | (tok >= TOK_CONST & tok <= TOK_INLINE)) { | 2438 | u = VT_VOID; |
| 2434 | /* ignored types */ | 2439 | goto basic_type; |
| 2435 | } else if (tok == TOK_FLOAT || tok == TOK_DOUBLE) { | 2440 | case TOK_SHORT: |
| 2436 | /* We allow that to compile standard headers */ | 2441 | u = VT_SHORT; |
| 2437 | // warning("floats not supported"); | 2442 | goto basic_type; |
| 2438 | } else if (tok == TOK_EXTERN) { | 2443 | case TOK_INT: |
| 2439 | t |= VT_EXTERN; | 2444 | next(); |
| 2440 | } else if (tok == TOK_STATIC) { | 2445 | break; |
| 2441 | t |= VT_STATIC; | 2446 | case TOK_LONG: |
| 2442 | } else if (tok == TOK_UNSIGNED) { | 2447 | /* XXX: add long type */ |
| 2443 | t |= VT_UNSIGNED; | 2448 | u = VT_INT; |
| 2444 | } else if (tok == TOK_TYPEDEF) { | 2449 | goto basic_type; |
| 2445 | t |= VT_TYPEDEF; | 2450 | case TOK_FLOAT: |
| 2446 | } else { | 2451 | case TOK_DOUBLE: |
| 2447 | s = sym_find(tok); | 2452 | /* XXX: add float types */ |
| 2448 | if (!s || !(s->t & VT_TYPEDEF)) | 2453 | u = VT_INT; |
| 2449 | break; | 2454 | goto basic_type; |
| 2450 | t |= (s->t & ~VT_TYPEDEF); | 2455 | case TOK_ENUM: |
| 2451 | } | 2456 | u = struct_decl(VT_ENUM); |
| 2457 | goto basic_type1; | ||
| 2458 | case TOK_STRUCT: | ||
| 2459 | case TOK_UNION: | ||
| 2460 | u = struct_decl(VT_STRUCT); | ||
| 2461 | goto basic_type1; | ||
| 2462 | |||
| 2463 | /* type modifiers */ | ||
| 2464 | case TOK_CONST: | ||
| 2465 | case TOK_VOLATILE: | ||
| 2466 | case TOK_REGISTER: | ||
| 2467 | case TOK_SIGNED: | ||
| 2468 | case TOK_AUTO: | ||
| 2469 | case TOK_INLINE: | ||
| 2470 | case TOK_RESTRICT: | ||
| 2471 | next(); | ||
| 2472 | break; | ||
| 2473 | case TOK_UNSIGNED: | ||
| 2474 | t |= VT_UNSIGNED; | ||
| 2475 | next(); | ||
| 2476 | break; | ||
| 2477 | |||
| 2478 | /* storage */ | ||
| 2479 | case TOK_EXTERN: | ||
| 2480 | t |= VT_EXTERN; | ||
| 2481 | next(); | ||
| 2482 | break; | ||
| 2483 | case TOK_STATIC: | ||
| 2484 | t |= VT_STATIC; | ||
| 2485 | next(); | ||
| 2486 | break; | ||
| 2487 | case TOK_TYPEDEF: | ||
| 2488 | t |= VT_TYPEDEF; | ||
| 2489 | next(); | ||
| 2490 | break; | ||
| 2491 | default: | ||
| 2492 | s = sym_find(tok); | ||
| 2493 | if (!s || !(s->t & VT_TYPEDEF)) | ||
| 2494 | goto the_end; | ||
| 2495 | t |= (s->t & ~VT_TYPEDEF); | ||
| 2452 | next(); | 2496 | next(); |
| 2497 | break; | ||
| 2453 | } | 2498 | } |
| 2454 | t |= 2; | 2499 | t |= 2; |
| 2455 | } | 2500 | } |
| 2501 | the_end: | ||
| 2456 | return t; | 2502 | return t; |
| 2457 | } | 2503 | } |
| 2458 | 2504 | ||
| @@ -3268,7 +3314,7 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 809 unmodified lines | |||
| 3268 | case_reg = gv(); | 3314 | case_reg = gv(); |
| 3269 | skip(')'); | 3315 | skip(')'); |
| 3270 | a = 0; | 3316 | a = 0; |
| 3271 | b = 0; | 3317 | b = gjmp(0); /* jump to first case */ |
| 3272 | c = 0; | 3318 | c = 0; |
| 3273 | block(&a, csym, &b, &c, case_reg); | 3319 | block(&a, csym, &b, &c, case_reg); |
| 3274 | /* if no default, jmp after switch */ | 3320 | /* if no default, jmp after switch */ |
| @@ -3284,12 +3330,15 @@ void block(int *bsym, int *csym, int *case_sym, int *def_sym, int case_reg) · 9 unmodified lines | |||
| 3284 | a = expr_const(); | 3330 | a = expr_const(); |
| 3285 | if (!case_sym) | 3331 | if (!case_sym) |
| 3286 | expect("switch"); | 3332 | expect("switch"); |
| 3333 | /* since a case is like a label, we must skip it with a jmp */ | ||
| 3334 | b = gjmp(0); | ||
| 3287 | gsym(*case_sym); | 3335 | gsym(*case_sym); |
| 3288 | vset(case_reg, 0); | 3336 | vset(case_reg, 0); |
| 3289 | vpush(); | 3337 | vpush(); |
| 3290 | vset(VT_CONST, a); | 3338 | vset(VT_CONST, a); |
| 3291 | gen_op(TOK_EQ); | 3339 | gen_op(TOK_EQ); |
| 3292 | *case_sym = gtst(1, 0); | 3340 | *case_sym = gtst(1, 0); |
| 3341 | gsym(b); | ||
| 3293 | skip(':'); | 3342 | skip(':'); |
| 3294 | block(bsym, csym, case_sym, def_sym, case_reg); | 3343 | block(bsym, csym, case_sym, def_sym, case_reg); |
| 3295 | } else | 3344 | } else |