Change (read/write)PackedInt to (read/write)PackedIntNative in aro/Preprocessor

This commit is contained in:
Krzysztof Wolicki 2024-10-12 17:59:41 +02:00
parent b1eaed6c8d
commit 8a4bcc4ec3

View File

@ -390,7 +390,6 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
var if_level: u8 = 0;
var if_kind: [64]u8 = .{0} ** 64;
const native_endian = @import("builtin").cpu.arch.endian();
const until_else = 0;
const until_endif = 1;
const until_endif_seen_else = 2;
@ -431,24 +430,12 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if_level = sum;
if (try pp.expr(&tokenizer)) {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_endif,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #if", .{});
}
} else {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #if", .{});
@ -464,24 +451,12 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) != null) {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_endif,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #ifdef", .{});
}
} else {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #ifdef", .{});
@ -497,21 +472,9 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue;
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name) == null) {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_endif,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
} else {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
}
},
@ -519,25 +482,13 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elif_without_if);
if_level += 1;
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => if (try pp.expr(&tokenizer)) {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_endif,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elif", .{});
}
@ -559,27 +510,15 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elifdef_without_if);
if_level += 1;
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
const macro_name = try pp.expectMacroName(&tokenizer);
if (macro_name == null) {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifdef", .{});
@ -587,24 +526,12 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
} else {
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name.?) != null) {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_endif,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elifdef", .{});
}
} else {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifdef", .{});
@ -624,27 +551,15 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
if (if_level == 0) {
try pp.err(directive, .elifdef_without_if);
if_level += 1;
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
} else if (if_level == 1) {
guard_name = null;
}
switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
const macro_name = try pp.expectMacroName(&tokenizer);
if (macro_name == null) {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifndef", .{});
@ -652,24 +567,12 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
} else {
try pp.expectNl(&tokenizer);
if (pp.defines.get(macro_name.?) == null) {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_endif,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif);
if (pp.verbose) {
pp.verboseLog(directive, "entering then branch of #elifndef", .{});
}
} else {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_else);
try pp.skip(&tokenizer, .until_else);
if (pp.verbose) {
pp.verboseLog(directive, "entering else branch of #elifndef", .{});
@ -693,15 +596,9 @@ fn preprocessExtra(pp: *Preprocessor, source: Source) MacroError!TokenWithExpans
} else if (if_level == 1) {
guard_name = null;
}
switch (std.mem.readPackedInt(u2, &if_kind, if_level * 2, native_endian)) {
switch (std.mem.readPackedIntNative(u2, &if_kind, if_level * 2)) {
until_else => {
std.mem.writePackedInt(
u2,
&if_kind,
if_level * 2,
until_endif_seen_else,
native_endian,
);
std.mem.writePackedIntNative(u2, &if_kind, if_level * 2, until_endif_seen_else);
if (pp.verbose) {
pp.verboseLog(directive, "#else branch here", .{});
}