| ... | @@ -389,7 +389,8 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -389,7 +389,8 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 389 | try pp.ensureTotalTokenCapacity(pp.tokens.len + estimated_token_count); | 389 | try pp.ensureTotalTokenCapacity(pp.tokens.len + estimated_token_count); |
| 390 | | 390 | |
| 391 | var if_level: u8 = 0; | 391 | var if_level: u8 = 0; |
| 392 | var if_kind = std.PackedIntArray(u2, 256).init([1]u2{0} ** 256); | 392 | var if_kind: [64]u8 = .{0} ** 64; |
| | 393 | const native_endian = @import("builtin").cpu.arch.endian(); |
| 393 | const until_else = 0; | 394 | const until_else = 0; |
| 394 | const until_endif = 1; | 395 | const until_endif = 1; |
| 395 | const until_endif_seen_else = 2; | 396 | const until_endif_seen_else = 2; |
| ... | @@ -430,12 +431,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -430,12 +431,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 430 | if_level = sum; | 431 | if_level = sum; |
| 431 | | 432 | |
| 432 | if (try pp.expr(&tokenizer)) { | 433 | if (try pp.expr(&tokenizer)) { |
| 433 | if_kind.set(if_level, until_endif); | 434 | std.mem.writePackedInt( |
| | 435 | u2, |
| | 436 | &if_kind, |
| | 437 | if_level * 2, |
| | 438 | until_endif, |
| | 439 | native_endian, |
| | 440 | ); |
| 434 | if (pp.verbose) { | 441 | if (pp.verbose) { |
| 435 | pp.verboseLog(directive, "entering then branch of #if", .{}); | 442 | pp.verboseLog(directive, "entering then branch of #if", .{}); |
| 436 | } | 443 | } |
| 437 | } else { | 444 | } else { |
| 438 | if_kind.set(if_level, until_else); | 445 | std.mem.writePackedInt( |
| | 446 | u2, |
| | 447 | &if_kind, |
| | 448 | if_level * 2, |
| | 449 | until_else, |
| | 450 | native_endian, |
| | 451 | ); |
| 439 | try pp.skip(&tokenizer, .until_else); | 452 | try pp.skip(&tokenizer, .until_else); |
| 440 | if (pp.verbose) { | 453 | if (pp.verbose) { |
| 441 | pp.verboseLog(directive, "entering else branch of #if", .{}); | 454 | pp.verboseLog(directive, "entering else branch of #if", .{}); |
| ... | @@ -451,12 +464,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -451,12 +464,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 451 | const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue; | 464 | const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue; |
| 452 | try pp.expectNl(&tokenizer); | 465 | try pp.expectNl(&tokenizer); |
| 453 | if (pp.defines.get(macro_name) != null) { | 466 | if (pp.defines.get(macro_name) != null) { |
| 454 | if_kind.set(if_level, until_endif); | 467 | std.mem.writePackedInt( |
| | 468 | u2, |
| | 469 | &if_kind, |
| | 470 | if_level * 2, |
| | 471 | until_endif, |
| | 472 | native_endian, |
| | 473 | ); |
| 455 | if (pp.verbose) { | 474 | if (pp.verbose) { |
| 456 | pp.verboseLog(directive, "entering then branch of #ifdef", .{}); | 475 | pp.verboseLog(directive, "entering then branch of #ifdef", .{}); |
| 457 | } | 476 | } |
| 458 | } else { | 477 | } else { |
| 459 | if_kind.set(if_level, until_else); | 478 | std.mem.writePackedInt( |
| | 479 | u2, |
| | 480 | &if_kind, |
| | 481 | if_level * 2, |
| | 482 | until_else, |
| | 483 | native_endian, |
| | 484 | ); |
| 460 | try pp.skip(&tokenizer, .until_else); | 485 | try pp.skip(&tokenizer, .until_else); |
| 461 | if (pp.verbose) { | 486 | if (pp.verbose) { |
| 462 | pp.verboseLog(directive, "entering else branch of #ifdef", .{}); | 487 | pp.verboseLog(directive, "entering else branch of #ifdef", .{}); |
| ... | @@ -472,9 +497,21 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -472,9 +497,21 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 472 | const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue; | 497 | const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue; |
| 473 | try pp.expectNl(&tokenizer); | 498 | try pp.expectNl(&tokenizer); |
| 474 | if (pp.defines.get(macro_name) == null) { | 499 | if (pp.defines.get(macro_name) == null) { |
| 475 | if_kind.set(if_level, until_endif); | 500 | std.mem.writePackedInt( |
| | 501 | u2, |
| | 502 | &if_kind, |
| | 503 | if_level * 2, |
| | 504 | until_endif, |
| | 505 | native_endian, |
| | 506 | ); |
| 476 | } else { | 507 | } else { |
| 477 | if_kind.set(if_level, until_else); | 508 | std.mem.writePackedInt( |
| | 509 | u2, |
| | 510 | &if_kind, |
| | 511 | if_level * 2, |
| | 512 | until_else, |
| | 513 | native_endian, |
| | 514 | ); |
| 478 | try pp.skip(&tokenizer, .until_else); | 515 | try pp.skip(&tokenizer, .until_else); |
| 479 | } | 516 | } |
| 480 | }, | 517 | }, |
| ... | @@ -482,13 +519,25 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -482,13 +519,25 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 482 | if (if_level == 0) { | 519 | if (if_level == 0) { |
| 483 | try pp.err(directive, .elif_without_if); | 520 | try pp.err(directive, .elif_without_if); |
| 484 | if_level += 1; | 521 | if_level += 1; |
| 485 | if_kind.set(if_level, until_else); | 522 | std.mem.writePackedInt( |
| | 523 | u2, |
| | 524 | &if_kind, |
| | 525 | if_level * 2, |
| | 526 | until_else, |
| | 527 | native_endian, |
| | 528 | ); |
| 486 | } else if (if_level == 1) { | 529 | } else if (if_level == 1) { |
| 487 | guard_name = null; | 530 | guard_name = null; |
| 488 | } | 531 | } |
| 489 | switch (if_kind.get(if_level)) { | 532 | switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) { |
| 490 | until_else => if (try pp.expr(&tokenizer)) { | 533 | until_else => if (try pp.expr(&tokenizer)) { |
| 491 | if_kind.set(if_level, until_endif); | 534 | std.mem.writePackedInt( |
| | 535 | u2, |
| | 536 | &if_kind, |
| | 537 | if_level * 2, |
| | 538 | until_endif, |
| | 539 | native_endian, |
| | 540 | ); |
| 492 | if (pp.verbose) { | 541 | if (pp.verbose) { |
| 493 | pp.verboseLog(directive, "entering then branch of #elif", .{}); | 542 | pp.verboseLog(directive, "entering then branch of #elif", .{}); |
| 494 | } | 543 | } |
| ... | @@ -510,15 +559,27 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -510,15 +559,27 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 510 | if (if_level == 0) { | 559 | if (if_level == 0) { |
| 511 | try pp.err(directive, .elifdef_without_if); | 560 | try pp.err(directive, .elifdef_without_if); |
| 512 | if_level += 1; | 561 | if_level += 1; |
| 513 | if_kind.set(if_level, until_else); | 562 | std.mem.writePackedInt( |
| | 563 | u2, |
| | 564 | &if_kind, |
| | 565 | if_level * 2, |
| | 566 | until_else, |
| | 567 | native_endian, |
| | 568 | ); |
| 514 | } else if (if_level == 1) { | 569 | } else if (if_level == 1) { |
| 515 | guard_name = null; | 570 | guard_name = null; |
| 516 | } | 571 | } |
| 517 | switch (if_kind.get(if_level)) { | 572 | switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) { |
| 518 | until_else => { | 573 | until_else => { |
| 519 | const macro_name = try pp.expectMacroName(&tokenizer); | 574 | const macro_name = try pp.expectMacroName(&tokenizer); |
| 520 | if (macro_name == null) { | 575 | if (macro_name == null) { |
| 521 | if_kind.set(if_level, until_else); | 576 | std.mem.writePackedInt( |
| | 577 | u2, |
| | 578 | &if_kind, |
| | 579 | if_level * 2, |
| | 580 | until_else, |
| | 581 | native_endian, |
| | 582 | ); |
| 522 | try pp.skip(&tokenizer, .until_else); | 583 | try pp.skip(&tokenizer, .until_else); |
| 523 | if (pp.verbose) { | 584 | if (pp.verbose) { |
| 524 | pp.verboseLog(directive, "entering else branch of #elifdef", .{}); | 585 | pp.verboseLog(directive, "entering else branch of #elifdef", .{}); |
| ... | @@ -526,12 +587,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -526,12 +587,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 526 | } else { | 587 | } else { |
| 527 | try pp.expectNl(&tokenizer); | 588 | try pp.expectNl(&tokenizer); |
| 528 | if (pp.defines.get(macro_name.?) != null) { | 589 | if (pp.defines.get(macro_name.?) != null) { |
| 529 | if_kind.set(if_level, until_endif); | 590 | std.mem.writePackedInt( |
| | 591 | u2, |
| | 592 | &if_kind, |
| | 593 | if_level * 2, |
| | 594 | until_endif, |
| | 595 | native_endian, |
| | 596 | ); |
| 530 | if (pp.verbose) { | 597 | if (pp.verbose) { |
| 531 | pp.verboseLog(directive, "entering then branch of #elifdef", .{}); | 598 | pp.verboseLog(directive, "entering then branch of #elifdef", .{}); |
| 532 | } | 599 | } |
| 533 | } else { | 600 | } else { |
| 534 | if_kind.set(if_level, until_else); | 601 | std.mem.writePackedInt( |
| | 602 | u2, |
| | 603 | &if_kind, |
| | 604 | if_level * 2, |
| | 605 | until_else, |
| | 606 | native_endian, |
| | 607 | ); |
| 535 | try pp.skip(&tokenizer, .until_else); | 608 | try pp.skip(&tokenizer, .until_else); |
| 536 | if (pp.verbose) { | 609 | if (pp.verbose) { |
| 537 | pp.verboseLog(directive, "entering else branch of #elifdef", .{}); | 610 | pp.verboseLog(directive, "entering else branch of #elifdef", .{}); |
| ... | @@ -551,15 +624,27 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -551,15 +624,27 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 551 | if (if_level == 0) { | 624 | if (if_level == 0) { |
| 552 | try pp.err(directive, .elifdef_without_if); | 625 | try pp.err(directive, .elifdef_without_if); |
| 553 | if_level += 1; | 626 | if_level += 1; |
| 554 | if_kind.set(if_level, until_else); | 627 | std.mem.writePackedInt( |
| | 628 | u2, |
| | 629 | &if_kind, |
| | 630 | if_level * 2, |
| | 631 | until_else, |
| | 632 | native_endian, |
| | 633 | ); |
| 555 | } else if (if_level == 1) { | 634 | } else if (if_level == 1) { |
| 556 | guard_name = null; | 635 | guard_name = null; |
| 557 | } | 636 | } |
| 558 | switch (if_kind.get(if_level)) { | 637 | switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) { |
| 559 | until_else => { | 638 | until_else => { |
| 560 | const macro_name = try pp.expectMacroName(&tokenizer); | 639 | const macro_name = try pp.expectMacroName(&tokenizer); |
| 561 | if (macro_name == null) { | 640 | if (macro_name == null) { |
| 562 | if_kind.set(if_level, until_else); | 641 | std.mem.writePackedInt( |
| | 642 | u2, |
| | 643 | &if_kind, |
| | 644 | if_level * 2, |
| | 645 | until_else, |
| | 646 | native_endian, |
| | 647 | ); |
| 563 | try pp.skip(&tokenizer, .until_else); | 648 | try pp.skip(&tokenizer, .until_else); |
| 564 | if (pp.verbose) { | 649 | if (pp.verbose) { |
| 565 | pp.verboseLog(directive, "entering else branch of #elifndef", .{}); | 650 | pp.verboseLog(directive, "entering else branch of #elifndef", .{}); |
| ... | @@ -567,12 +652,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -567,12 +652,24 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 567 | } else { | 652 | } else { |
| 568 | try pp.expectNl(&tokenizer); | 653 | try pp.expectNl(&tokenizer); |
| 569 | if (pp.defines.get(macro_name.?) == null) { | 654 | if (pp.defines.get(macro_name.?) == null) { |
| 570 | if_kind.set(if_level, until_endif); | 655 | std.mem.writePackedInt( |
| | 656 | u2, |
| | 657 | &if_kind, |
| | 658 | if_level * 2, |
| | 659 | until_endif, |
| | 660 | native_endian, |
| | 661 | ); |
| 571 | if (pp.verbose) { | 662 | if (pp.verbose) { |
| 572 | pp.verboseLog(directive, "entering then branch of #elifndef", .{}); | 663 | pp.verboseLog(directive, "entering then branch of #elifndef", .{}); |
| 573 | } | 664 | } |
| 574 | } else { | 665 | } else { |
| 575 | if_kind.set(if_level, until_else); | 666 | std.mem.writePackedInt( |
| | 667 | u2, |
| | 668 | &if_kind, |
| | 669 | if_level * 2, |
| | 670 | until_else, |
| | 671 | native_endian, |
| | 672 | ); |
| 576 | try pp.skip(&tokenizer, .until_else); | 673 | try pp.skip(&tokenizer, .until_else); |
| 577 | if (pp.verbose) { | 674 | if (pp.verbose) { |
| 578 | pp.verboseLog(directive, "entering else branch of #elifndef", .{}); | 675 | pp.verboseLog(directive, "entering else branch of #elifndef", .{}); |
| ... | @@ -596,9 +693,15 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans | ... | @@ -596,9 +693,15 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans |
| 596 | } else if (if_level == 1) { | 693 | } else if (if_level == 1) { |
| 597 | guard_name = null; | 694 | guard_name = null; |
| 598 | } | 695 | } |
| 599 | switch (if_kind.get(if_level)) { | 696 | switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) { |
| 600 | until_else => { | 697 | until_else => { |
| 601 | if_kind.set(if_level, until_endif_seen_else); | 698 | std.mem.writePackedInt( |
| | 699 | u2, |
| | 700 | &if_kind, |
| | 701 | if_level * 2, |
| | 702 | until_endif_seen_else, |
| | 703 | native_endian, |
| | 704 | ); |
| 602 | if (pp.verbose) { | 705 | if (pp.verbose) { |
| 603 | pp.verboseLog(directive, "#else branch here", .{}); | 706 | pp.verboseLog(directive, "#else branch here", .{}); |
| 604 | } | 707 | } |