authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-10-13 20:17:30+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-10-13 20:17:30+02:00
log6ba1fdf7e0d8dfc348a163219b3c3215c3644dd6
treea8e5d328bc8f1dc3f47f8d84fc16ce1582ed673c
parentf01c3150c19fa3d6c605cc1940f70cce303c5997
signaturelock-open Commit is signed but in an unrecognized format.

stage2: use meta.stringToEnum for Color parsing

This requires renaming the variants to be snake_case, which is the new recommended style anyways.

2 files changed, 15 insertions(+), 27 deletions(-)

src/Compilation.zig+3-3
...@@ -103,7 +103,7 @@ owned_link_dir: ?std.fs.Dir,...@@ -103,7 +103,7 @@ owned_link_dir: ?std.fs.Dir,
103103
104/// This is for stage1 and should be deleted upon completion of self-hosting.104/// This is for stage1 and should be deleted upon completion of self-hosting.
105/// Don't use this for anything other than stage1 compatibility.105/// Don't use this for anything other than stage1 compatibility.
106color: @import("main.zig").Color = .Auto,106color: @import("main.zig").Color = .auto,
107107
108test_filter: ?[]const u8,108test_filter: ?[]const u8,
109test_name_prefix: ?[]const u8,109test_name_prefix: ?[]const u8,
...@@ -385,7 +385,7 @@ pub const InitOptions = struct {...@@ -385,7 +385,7 @@ pub const InitOptions = struct {
385 machine_code_model: std.builtin.CodeModel = .default,385 machine_code_model: std.builtin.CodeModel = .default,
386 clang_preprocessor_mode: ClangPreprocessorMode = .no,386 clang_preprocessor_mode: ClangPreprocessorMode = .no,
387 /// This is for stage1 and should be deleted upon completion of self-hosting.387 /// This is for stage1 and should be deleted upon completion of self-hosting.
388 color: @import("main.zig").Color = .Auto,388 color: @import("main.zig").Color = .auto,
389 test_filter: ?[]const u8 = null,389 test_filter: ?[]const u8 = null,
390 test_name_prefix: ?[]const u8 = null,390 test_name_prefix: ?[]const u8 = null,
391 subsystem: ?std.Target.SubSystem = null,391 subsystem: ?std.Target.SubSystem = null,
...@@ -1179,7 +1179,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -1179,7 +1179,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
1179 var progress: std.Progress = .{};1179 var progress: std.Progress = .{};
1180 var main_progress_node = try progress.start("", null);1180 var main_progress_node = try progress.start("", null);
1181 defer main_progress_node.end();1181 defer main_progress_node.end();
1182 if (self.color == .Off) progress.terminal = null;1182 if (self.color == .off) progress.terminal = null;
11831183
1184 var c_comp_progress_node = main_progress_node.start("Compile C Objects", self.c_source_files.len);1184 var c_comp_progress_node = main_progress_node.start("Compile C Objects", self.c_source_files.len);
1185 defer c_comp_progress_node.end();1185 defer c_comp_progress_node.end();
src/main.zig+12-24
...@@ -28,9 +28,9 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn {...@@ -28,9 +28,9 @@ pub fn fatal(comptime format: []const u8, args: anytype) noreturn {
28pub const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB28pub const max_src_size = 2 * 1024 * 1024 * 1024; // 2 GiB
2929
30pub const Color = enum {30pub const Color = enum {
31 Auto,31 auto,
32 Off,32 off,
33 On,33 on,
34};34};
3535
36const usage =36const usage =
...@@ -380,7 +380,7 @@ fn buildOutputType(...@@ -380,7 +380,7 @@ fn buildOutputType(
380 run,380 run,
381 },381 },
382) !void {382) !void {
383 var color: Color = .Auto;383 var color: Color = .auto;
384 var optimize_mode: std.builtin.Mode = .Debug;384 var optimize_mode: std.builtin.Mode = .Debug;
385 var provided_name: ?[]const u8 = null;385 var provided_name: ?[]const u8 = null;
386 var link_mode: ?std.builtin.LinkMode = null;386 var link_mode: ?std.builtin.LinkMode = null;
...@@ -585,15 +585,9 @@ fn buildOutputType(...@@ -585,15 +585,9 @@ fn buildOutputType(
585 }585 }
586 i += 1;586 i += 1;
587 const next_arg = args[i];587 const next_arg = args[i];
588 if (mem.eql(u8, next_arg, "auto")) {588 color = std.meta.stringToEnum(Color, next_arg) orelse {
589 color = .Auto;
590 } else if (mem.eql(u8, next_arg, "on")) {
591 color = .On;
592 } else if (mem.eql(u8, next_arg, "off")) {
593 color = .Off;
594 } else {
595 fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg});589 fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg});
596 }590 };
597 } else if (mem.eql(u8, arg, "--subsystem")) {591 } else if (mem.eql(u8, arg, "--subsystem")) {
598 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});592 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
599 i += 1;593 i += 1;
...@@ -2374,7 +2368,7 @@ const Fmt = struct {...@@ -2374,7 +2368,7 @@ const Fmt = struct {
23742368
2375pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {2369pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {
2376 const stderr_file = io.getStdErr();2370 const stderr_file = io.getStdErr();
2377 var color: Color = .Auto;2371 var color: Color = .auto;
2378 var stdin_flag: bool = false;2372 var stdin_flag: bool = false;
2379 var check_flag: bool = false;2373 var check_flag: bool = false;
2380 var input_files = ArrayList([]const u8).init(gpa);2374 var input_files = ArrayList([]const u8).init(gpa);
...@@ -2394,15 +2388,9 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {...@@ -2394,15 +2388,9 @@ pub fn cmdFmt(gpa: *Allocator, args: []const []const u8) !void {
2394 }2388 }
2395 i += 1;2389 i += 1;
2396 const next_arg = args[i];2390 const next_arg = args[i];
2397 if (mem.eql(u8, next_arg, "auto")) {2391 color = std.meta.stringToEnum(Color, next_arg) orelse {
2398 color = .Auto;
2399 } else if (mem.eql(u8, next_arg, "on")) {
2400 color = .On;
2401 } else if (mem.eql(u8, next_arg, "off")) {
2402 color = .Off;
2403 } else {
2404 fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg});2392 fatal("expected [auto|on|off] after --color, found '{}'", .{next_arg});
2405 }2393 };
2406 } else if (mem.eql(u8, arg, "--stdin")) {2394 } else if (mem.eql(u8, arg, "--stdin")) {
2407 stdin_flag = true;2395 stdin_flag = true;
2408 } else if (mem.eql(u8, arg, "--check")) {2396 } else if (mem.eql(u8, arg, "--check")) {
...@@ -2626,9 +2614,9 @@ fn printErrMsgToFile(...@@ -2626,9 +2614,9 @@ fn printErrMsgToFile(
2626 color: Color,2614 color: Color,
2627) !void {2615) !void {
2628 const color_on = switch (color) {2616 const color_on = switch (color) {
2629 .Auto => file.isTty(),2617 .auto => file.isTty(),
2630 .On => true,2618 .on => true,
2631 .Off => false,2619 .off => false,
2632 };2620 };
2633 const lok_token = parse_error.loc();2621 const lok_token = parse_error.loc();
2634 const span_first = lok_token;2622 const span_first = lok_token;