authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-16 00:43:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-16 00:43:28-04:00
log288fc3a8d361972daeded19d207b410128d70d67
tree49ecb7a09c27306ca3f8e28fed82cd95f2b81772
parent5cfabdd493c6602243f47e24320bae940a3c417a

convert more std lib files to postfix pointer deref


6 files changed, 1211 insertions(+), 1378 deletions(-)

std/crypto/test.zig+1-2
......@@ -14,9 +14,8 @@ pub fn assertEqualHash(comptime Hasher: var, comptime expected: []const u8, inpu
1414pub fn assertEqual(comptime expected: []const u8, input: []const u8) void {
1515 var expected_bytes: [expected.len / 2]u8 = undefined;
1616 for (expected_bytes) |*r, i| {
17 *r = fmt.parseInt(u8, expected[2*i .. 2*i+2], 16) catch unreachable;
17 r.* = fmt.parseInt(u8, expected[2 * i .. 2 * i + 2], 16) catch unreachable;
1818 }
1919
2020 debug.assert(mem.eql(u8, expected_bytes, input));
2121}
22
std/fmt/errol/index.zig+22-32
......@@ -86,7 +86,7 @@ pub fn errol3(value: f64, buffer: []u8) FloatDecimal {
8686 const data = enum3_data[i];
8787 const digits = buffer[1..data.str.len + 1];
8888 mem.copy(u8, digits, data.str);
89 return FloatDecimal {
89 return FloatDecimal{
9090 .digits = digits,
9191 .exp = data.exp,
9292 };
......@@ -105,7 +105,6 @@ fn errol3u(val: f64, buffer: []u8) FloatDecimal {
105105 return errolFixed(val, buffer);
106106 }
107107
108
109108 // normalize the midpoint
110109
111110 const e = math.frexp(val).exponent;
......@@ -137,11 +136,11 @@ fn errol3u(val: f64, buffer: []u8) FloatDecimal {
137136 }
138137
139138 // compute boundaries
140 var high = HP {
139 var high = HP{
141140 .val = mid.val,
142141 .off = mid.off + (fpnext(val) - val) * lten * ten / 2.0,
143142 };
144 var low = HP {
143 var low = HP{
145144 .val = mid.val,
146145 .off = mid.off + (fpprev(val) - val) * lten * ten / 2.0,
147146 };
......@@ -171,15 +170,12 @@ fn errol3u(val: f64, buffer: []u8) FloatDecimal {
171170 var buf_index: usize = 1;
172171 while (true) {
173172 var hdig = u8(math.floor(high.val));
174 if ((high.val == f64(hdig)) and (high.off < 0))
175 hdig -= 1;
173 if ((high.val == f64(hdig)) and (high.off < 0)) hdig -= 1;
176174
177175 var ldig = u8(math.floor(low.val));
178 if ((low.val == f64(ldig)) and (low.off < 0))
179 ldig -= 1;
176 if ((low.val == f64(ldig)) and (low.off < 0)) ldig -= 1;
180177
181 if (ldig != hdig)
182 break;
178 if (ldig != hdig) break;
183179
184180 buffer[buf_index] = hdig + '0';
185181 buf_index += 1;
......@@ -191,13 +187,12 @@ fn errol3u(val: f64, buffer: []u8) FloatDecimal {
191187
192188 const tmp = (high.val + low.val) / 2.0;
193189 var mdig = u8(math.floor(tmp + 0.5));
194 if ((f64(mdig) - tmp) == 0.5 and (mdig & 0x1) != 0)
195 mdig -= 1;
190 if ((f64(mdig) - tmp) == 0.5 and (mdig & 0x1) != 0) mdig -= 1;
196191
197192 buffer[buf_index] = mdig + '0';
198193 buf_index += 1;
199194
200 return FloatDecimal {
195 return FloatDecimal{
201196 .digits = buffer[1..buf_index],
202197 .exp = exp,
203198 };
......@@ -235,7 +230,7 @@ fn hpProd(in: &const HP, val: f64) HP {
235230 const p = in.val * val;
236231 const e = ((hi * hi2 - p) + lo * hi2 + hi * lo2) + lo * lo2;
237232
238 return HP {
233 return HP{
239234 .val = p,
240235 .off = in.off * val + e,
241236 };
......@@ -246,8 +241,8 @@ fn hpProd(in: &const HP, val: f64) HP {
246241/// @hi: The high bits.
247242/// @lo: The low bits.
248243fn split(val: f64, hi: &f64, lo: &f64) void {
249 *hi = gethi(val);
250 *lo = val - *hi;
244 hi.* = gethi(val);
245 lo.* = val - hi.*;
251246}
252247
253248fn gethi(in: f64) f64 {
......@@ -301,7 +296,6 @@ fn hpMul10(hp: &HP) void {
301296 hpNormalize(hp);
302297}
303298
304
305299/// Integer conversion algorithm, guaranteed correct, optimal, and best.
306300/// @val: The val.
307301/// @buf: The output buffer.
......@@ -343,8 +337,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
343337 }
344338 const m64 = @truncate(u64, @divTrunc(mid, x));
345339
346 if (lf != hf)
347 mi += 19;
340 if (lf != hf) mi += 19;
348341
349342 var buf_index = u64toa(m64, buffer) - 1;
350343
......@@ -354,7 +347,7 @@ fn errolInt(val: f64, buffer: []u8) FloatDecimal {
354347 buf_index += 1;
355348 }
356349
357 return FloatDecimal {
350 return FloatDecimal{
358351 .digits = buffer[0..buf_index],
359352 .exp = i32(buf_index) + mi,
360353 };
......@@ -396,25 +389,24 @@ fn errolFixed(val: f64, buffer: []u8) FloatDecimal {
396389 buffer[j] = u8(mdig + '0');
397390 j += 1;
398391
399 if(hdig != ldig or j > 50)
400 break;
392 if (hdig != ldig or j > 50) break;
401393 }
402394
403395 if (mid > 0.5) {
404 buffer[j-1] += 1;
405 } else if ((mid == 0.5) and (buffer[j-1] & 0x1) != 0) {
406 buffer[j-1] += 1;
396 buffer[j - 1] += 1;
397 } else if ((mid == 0.5) and (buffer[j - 1] & 0x1) != 0) {
398 buffer[j - 1] += 1;
407399 }
408400 } else {
409 while (buffer[j-1] == '0') {
410 buffer[j-1] = 0;
401 while (buffer[j - 1] == '0') {
402 buffer[j - 1] = 0;
411403 j -= 1;
412404 }
413405 }
414406
415407 buffer[j] = 0;
416408
417 return FloatDecimal {
409 return FloatDecimal{
418410 .digits = buffer[0..j],
419411 .exp = exp,
420412 };
......@@ -587,7 +579,7 @@ fn u64toa(value_param: u64, buffer: []u8) usize {
587579 buffer[buf_index] = c_digits_lut[d8 + 1];
588580 buf_index += 1;
589581 } else {
590 const a = u32(value / kTen16); // 1 to 1844
582 const a = u32(value / kTen16); // 1 to 1844
591583 value %= kTen16;
592584
593585 if (a < 10) {
......@@ -686,7 +678,6 @@ fn fpeint(from: f64) u128 {
686678 return u128(1) << @truncate(u7, (bits >> 52) -% 1023);
687679}
688680
689
690681/// Given two different integers with the same length in terms of the number
691682/// of decimal digits, index the digits from the right-most position starting
692683/// from zero, find the first index where the digits in the two integers
......@@ -713,7 +704,6 @@ fn mismatch10(a: u64, b: u64) i32 {
713704 a_copy /= 10;
714705 b_copy /= 10;
715706
716 if (a_copy == b_copy)
717 return i;
707 if (a_copy == b_copy) return i;
718708 }
719709}
std/os/darwin.zig+182-100
......@@ -10,33 +10,56 @@ pub const STDIN_FILENO = 0;
1010pub const STDOUT_FILENO = 1;
1111pub const STDERR_FILENO = 2;
1212
13pub const PROT_NONE = 0x00; /// [MC2] no permissions
14pub const PROT_READ = 0x01; /// [MC2] pages can be read
15pub const PROT_WRITE = 0x02; /// [MC2] pages can be written
16pub const PROT_EXEC = 0x04; /// [MC2] pages can be executed
17
18pub const MAP_ANONYMOUS = 0x1000; /// allocated from memory, swap space
19pub const MAP_FILE = 0x0000; /// map from file (default)
20pub const MAP_FIXED = 0x0010; /// interpret addr exactly
21pub const MAP_HASSEMAPHORE = 0x0200; /// region may contain semaphores
22pub const MAP_PRIVATE = 0x0002; /// changes are private
23pub const MAP_SHARED = 0x0001; /// share changes
24pub const MAP_NOCACHE = 0x0400; /// don't cache pages for this mapping
25pub const MAP_NORESERVE = 0x0040; /// don't reserve needed swap area
13/// [MC2] no permissions
14pub const PROT_NONE = 0x00;
15/// [MC2] pages can be read
16pub const PROT_READ = 0x01;
17/// [MC2] pages can be written
18pub const PROT_WRITE = 0x02;
19/// [MC2] pages can be executed
20pub const PROT_EXEC = 0x04;
21
22/// allocated from memory, swap space
23pub const MAP_ANONYMOUS = 0x1000;
24/// map from file (default)
25pub const MAP_FILE = 0x0000;
26/// interpret addr exactly
27pub const MAP_FIXED = 0x0010;
28/// region may contain semaphores
29pub const MAP_HASSEMAPHORE = 0x0200;
30/// changes are private
31pub const MAP_PRIVATE = 0x0002;
32/// share changes
33pub const MAP_SHARED = 0x0001;
34/// don't cache pages for this mapping
35pub const MAP_NOCACHE = 0x0400;
36/// don't reserve needed swap area
37pub const MAP_NORESERVE = 0x0040;
2638pub const MAP_FAILED = @maxValue(usize);
2739
28pub const WNOHANG = 0x00000001; /// [XSI] no hang in wait/no child to reap
29pub const WUNTRACED = 0x00000002; /// [XSI] notify on stop, untraced child
30
31pub const SA_ONSTACK = 0x0001; /// take signal on signal stack
32pub const SA_RESTART = 0x0002; /// restart system on signal return
33pub const SA_RESETHAND = 0x0004; /// reset to SIG_DFL when taking signal
34pub const SA_NOCLDSTOP = 0x0008; /// do not generate SIGCHLD on child stop
35pub const SA_NODEFER = 0x0010; /// don't mask the signal we're delivering
36pub const SA_NOCLDWAIT = 0x0020; /// don't keep zombies around
37pub const SA_SIGINFO = 0x0040; /// signal handler with SA_SIGINFO args
38pub const SA_USERTRAMP = 0x0100; /// do not bounce off kernel's sigtramp
39pub const SA_64REGSET = 0x0200; /// signal handler with SA_SIGINFO args with 64bit regs information
40/// [XSI] no hang in wait/no child to reap
41pub const WNOHANG = 0x00000001;
42/// [XSI] notify on stop, untraced child
43pub const WUNTRACED = 0x00000002;
44
45/// take signal on signal stack
46pub const SA_ONSTACK = 0x0001;
47/// restart system on signal return
48pub const SA_RESTART = 0x0002;
49/// reset to SIG_DFL when taking signal
50pub const SA_RESETHAND = 0x0004;
51/// do not generate SIGCHLD on child stop
52pub const SA_NOCLDSTOP = 0x0008;
53/// don't mask the signal we're delivering
54pub const SA_NODEFER = 0x0010;
55/// don't keep zombies around
56pub const SA_NOCLDWAIT = 0x0020;
57/// signal handler with SA_SIGINFO args
58pub const SA_SIGINFO = 0x0040;
59/// do not bounce off kernel's sigtramp
60pub const SA_USERTRAMP = 0x0100;
61/// signal handler with SA_SIGINFO args with 64bit regs information
62pub const SA_64REGSET = 0x0200;
4063
4164pub const O_LARGEFILE = 0x0000;
4265pub const O_PATH = 0x0000;
......@@ -46,20 +69,34 @@ pub const X_OK = 1;
4669pub const W_OK = 2;
4770pub const R_OK = 4;
4871
49pub const O_RDONLY = 0x0000; /// open for reading only
50pub const O_WRONLY = 0x0001; /// open for writing only
51pub const O_RDWR = 0x0002; /// open for reading and writing
52pub const O_NONBLOCK = 0x0004; /// do not block on open or for data to become available
53pub const O_APPEND = 0x0008; /// append on each write
54pub const O_CREAT = 0x0200; /// create file if it does not exist
55pub const O_TRUNC = 0x0400; /// truncate size to 0
56pub const O_EXCL = 0x0800; /// error if O_CREAT and the file exists
57pub const O_SHLOCK = 0x0010; /// atomically obtain a shared lock
58pub const O_EXLOCK = 0x0020; /// atomically obtain an exclusive lock
59pub const O_NOFOLLOW = 0x0100; /// do not follow symlinks
60pub const O_SYMLINK = 0x200000; /// allow open of symlinks
61pub const O_EVTONLY = 0x8000; /// descriptor requested for event notifications only
62pub const O_CLOEXEC = 0x1000000; /// mark as close-on-exec
72/// open for reading only
73pub const O_RDONLY = 0x0000;
74/// open for writing only
75pub const O_WRONLY = 0x0001;
76/// open for reading and writing
77pub const O_RDWR = 0x0002;
78/// do not block on open or for data to become available
79pub const O_NONBLOCK = 0x0004;
80/// append on each write
81pub const O_APPEND = 0x0008;
82/// create file if it does not exist
83pub const O_CREAT = 0x0200;
84/// truncate size to 0
85pub const O_TRUNC = 0x0400;
86/// error if O_CREAT and the file exists
87pub const O_EXCL = 0x0800;
88/// atomically obtain a shared lock
89pub const O_SHLOCK = 0x0010;
90/// atomically obtain an exclusive lock
91pub const O_EXLOCK = 0x0020;
92/// do not follow symlinks
93pub const O_NOFOLLOW = 0x0100;
94/// allow open of symlinks
95pub const O_SYMLINK = 0x200000;
96/// descriptor requested for event notifications only
97pub const O_EVTONLY = 0x8000;
98/// mark as close-on-exec
99pub const O_CLOEXEC = 0x1000000;
63100
64101pub const O_ACCMODE = 3;
65102pub const O_ALERT = 536870912;
......@@ -87,52 +124,102 @@ pub const DT_LNK = 10;
87124pub const DT_SOCK = 12;
88125pub const DT_WHT = 14;
89126
90pub const SIG_BLOCK = 1; /// block specified signal set
91pub const SIG_UNBLOCK = 2; /// unblock specified signal set
92pub const SIG_SETMASK = 3; /// set specified signal set
93
94pub const SIGHUP = 1; /// hangup
95pub const SIGINT = 2; /// interrupt
96pub const SIGQUIT = 3; /// quit
97pub const SIGILL = 4; /// illegal instruction (not reset when caught)
98pub const SIGTRAP = 5; /// trace trap (not reset when caught)
99pub const SIGABRT = 6; /// abort()
100pub const SIGPOLL = 7; /// pollable event ([XSR] generated, not supported)
101pub const SIGIOT = SIGABRT; /// compatibility
102pub const SIGEMT = 7; /// EMT instruction
103pub const SIGFPE = 8; /// floating point exception
104pub const SIGKILL = 9; /// kill (cannot be caught or ignored)
105pub const SIGBUS = 10; /// bus error
106pub const SIGSEGV = 11; /// segmentation violation
107pub const SIGSYS = 12; /// bad argument to system call
108pub const SIGPIPE = 13; /// write on a pipe with no one to read it
109pub const SIGALRM = 14; /// alarm clock
110pub const SIGTERM = 15; /// software termination signal from kill
111pub const SIGURG = 16; /// urgent condition on IO channel
112pub const SIGSTOP = 17; /// sendable stop signal not from tty
113pub const SIGTSTP = 18; /// stop signal from tty
114pub const SIGCONT = 19; /// continue a stopped process
115pub const SIGCHLD = 20; /// to parent on child stop or exit
116pub const SIGTTIN = 21; /// to readers pgrp upon background tty read
117pub const SIGTTOU = 22; /// like TTIN for output if (tp->t_local&LTOSTOP)
118pub const SIGIO = 23; /// input/output possible signal
119pub const SIGXCPU = 24; /// exceeded CPU time limit
120pub const SIGXFSZ = 25; /// exceeded file size limit
121pub const SIGVTALRM = 26; /// virtual time alarm
122pub const SIGPROF = 27; /// profiling time alarm
123pub const SIGWINCH = 28; /// window size changes
124pub const SIGINFO = 29; /// information request
125pub const SIGUSR1 = 30; /// user defined signal 1
126pub const SIGUSR2 = 31; /// user defined signal 2
127
128fn wstatus(x: i32) i32 { return x & 0o177; }
127/// block specified signal set
128pub const SIG_BLOCK = 1;
129/// unblock specified signal set
130pub const SIG_UNBLOCK = 2;
131/// set specified signal set
132pub const SIG_SETMASK = 3;
133
134/// hangup
135pub const SIGHUP = 1;
136/// interrupt
137pub const SIGINT = 2;
138/// quit
139pub const SIGQUIT = 3;
140/// illegal instruction (not reset when caught)
141pub const SIGILL = 4;
142/// trace trap (not reset when caught)
143pub const SIGTRAP = 5;
144/// abort()
145pub const SIGABRT = 6;
146/// pollable event ([XSR] generated, not supported)
147pub const SIGPOLL = 7;
148/// compatibility
149pub const SIGIOT = SIGABRT;
150/// EMT instruction
151pub const SIGEMT = 7;
152/// floating point exception
153pub const SIGFPE = 8;
154/// kill (cannot be caught or ignored)
155pub const SIGKILL = 9;
156/// bus error
157pub const SIGBUS = 10;
158/// segmentation violation
159pub const SIGSEGV = 11;
160/// bad argument to system call
161pub const SIGSYS = 12;
162/// write on a pipe with no one to read it
163pub const SIGPIPE = 13;
164/// alarm clock
165pub const SIGALRM = 14;
166/// software termination signal from kill
167pub const SIGTERM = 15;
168/// urgent condition on IO channel
169pub const SIGURG = 16;
170/// sendable stop signal not from tty
171pub const SIGSTOP = 17;
172/// stop signal from tty
173pub const SIGTSTP = 18;
174/// continue a stopped process
175pub const SIGCONT = 19;
176/// to parent on child stop or exit
177pub const SIGCHLD = 20;
178/// to readers pgrp upon background tty read
179pub const SIGTTIN = 21;
180/// like TTIN for output if (tp->t_local&LTOSTOP)
181pub const SIGTTOU = 22;
182/// input/output possible signal
183pub const SIGIO = 23;
184/// exceeded CPU time limit
185pub const SIGXCPU = 24;
186/// exceeded file size limit
187pub const SIGXFSZ = 25;
188/// virtual time alarm
189pub const SIGVTALRM = 26;
190/// profiling time alarm
191pub const SIGPROF = 27;
192/// window size changes
193pub const SIGWINCH = 28;
194/// information request
195pub const SIGINFO = 29;
196/// user defined signal 1
197pub const SIGUSR1 = 30;
198/// user defined signal 2
199pub const SIGUSR2 = 31;
200
201fn wstatus(x: i32) i32 {
202 return x & 0o177;
203}
129204const wstopped = 0o177;
130pub fn WEXITSTATUS(x: i32) i32 { return x >> 8; }
131pub fn WTERMSIG(x: i32) i32 { return wstatus(x); }
132pub fn WSTOPSIG(x: i32) i32 { return x >> 8; }
133pub fn WIFEXITED(x: i32) bool { return wstatus(x) == 0; }
134pub fn WIFSTOPPED(x: i32) bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; }
135pub fn WIFSIGNALED(x: i32) bool { return wstatus(x) != wstopped and wstatus(x) != 0; }
205pub fn WEXITSTATUS(x: i32) i32 {
206 return x >> 8;
207}
208pub fn WTERMSIG(x: i32) i32 {
209 return wstatus(x);
210}
211pub fn WSTOPSIG(x: i32) i32 {
212 return x >> 8;
213}
214pub fn WIFEXITED(x: i32) bool {
215 return wstatus(x) == 0;
216}
217pub fn WIFSTOPPED(x: i32) bool {
218 return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13;
219}
220pub fn WIFSIGNALED(x: i32) bool {
221 return wstatus(x) != wstopped and wstatus(x) != 0;
222}
136223
137224/// Get the errno from a syscall return value, or 0 for no error.
138225pub fn getErrno(r: usize) usize {
......@@ -184,11 +271,8 @@ pub fn write(fd: i32, buf: &const u8, nbyte: usize) usize {
184271 return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
185272}
186273
187pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32,
188 offset: isize) usize
189{
190 const ptr_result = c.mmap(@ptrCast(&c_void, address), length,
191 @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
274pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
275 const ptr_result = c.mmap(@ptrCast(&c_void, address), length, @bitCast(c_int, c_uint(prot)), @bitCast(c_int, c_uint(flags)), fd, offset);
192276 const isize_result = @bitCast(isize, @ptrToInt(ptr_result));
193277 return errnoWrap(isize_result);
194278}
......@@ -202,7 +286,7 @@ pub fn unlink(path: &const u8) usize {
202286}
203287
204288pub fn getcwd(buf: &u8, size: usize) usize {
205 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0;
289 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
206290}
207291
208292pub fn waitpid(pid: i32, status: &i32, options: u32) usize {
......@@ -223,7 +307,6 @@ pub fn pipe(fds: &[2]i32) usize {
223307 return errnoWrap(c.pipe(@ptrCast(&c_int, fds)));
224308}
225309
226
227310pub fn getdirentries64(fd: i32, buf_ptr: &u8, buf_len: usize, basep: &i64) usize {
228311 return errnoWrap(@bitCast(isize, c.__getdirentries64(fd, buf_ptr, buf_len, basep)));
229312}
......@@ -269,7 +352,7 @@ pub fn nanosleep(req: &const timespec, rem: ?&timespec) usize {
269352}
270353
271354pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) usize {
272 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0;
355 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(c._errno().*)) else 0;
273356}
274357
275358pub fn setreuid(ruid: u32, euid: u32) usize {
......@@ -287,8 +370,8 @@ pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&s
287370pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
288371 assert(sig != SIGKILL);
289372 assert(sig != SIGSTOP);
290 var cact = c.Sigaction {
291 .handler = @ptrCast(extern fn(c_int)void, act.handler),
373 var cact = c.Sigaction{
374 .handler = @ptrCast(extern fn(c_int) void, act.handler),
292375 .sa_flags = @bitCast(c_int, act.flags),
293376 .sa_mask = act.mask,
294377 };
......@@ -298,8 +381,8 @@ pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigacti
298381 return result;
299382 }
300383 if (oact) |old| {
301 *old = Sigaction {
302 .handler = @ptrCast(extern fn(i32)void, coact.handler),
384 old.* = Sigaction{
385 .handler = @ptrCast(extern fn(i32) void, coact.handler),
303386 .flags = @bitCast(u32, coact.sa_flags),
304387 .mask = coact.sa_mask,
305388 };
......@@ -319,23 +402,22 @@ pub const sockaddr = c.sockaddr;
319402
320403/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
321404pub const Sigaction = struct {
322 handler: extern fn(i32)void,
405 handler: extern fn(i32) void,
323406 mask: sigset_t,
324407 flags: u32,
325408};
326409
327410pub fn sigaddset(set: &sigset_t, signo: u5) void {
328 *set |= u32(1) << (signo - 1);
411 set.* |= u32(1) << (signo - 1);
329412}
330413
331414/// Takes the return value from a syscall and formats it back in the way
332415/// that the kernel represents it to libc. Errno was a mistake, let's make
333416/// it go away forever.
334417fn errnoWrap(value: isize) usize {
335 return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);
418 return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value);
336419}
337420
338
339421pub const timezone = c.timezone;
340422pub const timeval = c.timeval;
341423pub const mach_timebase_info_data = c.mach_timebase_info_data;
std/zig/ast.zig+32-39
......@@ -40,7 +40,7 @@ pub const Tree = struct {
4040 };
4141
4242 pub fn tokenLocationPtr(self: &Tree, start_index: usize, token: &const Token) Location {
43 var loc = Location {
43 var loc = Location{
4444 .line = 0,
4545 .column = 0,
4646 .line_start = start_index,
......@@ -71,7 +71,6 @@ pub const Tree = struct {
7171 pub fn dump(self: &Tree) void {
7272 self.root_node.base.dump(0);
7373 }
74
7574};
7675
7776pub const Error = union(enum) {
......@@ -95,7 +94,7 @@ pub const Error = union(enum) {
9594 ExpectedCommaOrEnd: ExpectedCommaOrEnd,
9695
9796 pub fn render(self: &Error, tokens: &Tree.TokenList, stream: var) !void {
98 switch (*self) {
97 switch (self.*) {
9998 // TODO https://github.com/zig-lang/zig/issues/683
10099 @TagType(Error).InvalidToken => |*x| return x.render(tokens, stream),
101100 @TagType(Error).ExpectedVarDeclOrFn => |*x| return x.render(tokens, stream),
......@@ -119,7 +118,7 @@ pub const Error = union(enum) {
119118 }
120119
121120 pub fn loc(self: &Error) TokenIndex {
122 switch (*self) {
121 switch (self.*) {
123122 // TODO https://github.com/zig-lang/zig/issues/683
124123 @TagType(Error).InvalidToken => |x| return x.token,
125124 @TagType(Error).ExpectedVarDeclOrFn => |x| return x.token,
......@@ -144,15 +143,12 @@ pub const Error = union(enum) {
144143
145144 pub const InvalidToken = SingleTokenError("Invalid token {}");
146145 pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found {}");
147 pub const ExpectedAggregateKw = SingleTokenError("Expected " ++
148 @tagName(Token.Id.Keyword_struct) ++ ", " ++ @tagName(Token.Id.Keyword_union) ++ ", or " ++
149 @tagName(Token.Id.Keyword_enum) ++ ", found {}");
146 pub const ExpectedAggregateKw = SingleTokenError("Expected " ++ @tagName(Token.Id.Keyword_struct) ++ ", " ++ @tagName(Token.Id.Keyword_union) ++ ", or " ++ @tagName(Token.Id.Keyword_enum) ++ ", found {}");
150147 pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found {}");
151148 pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found {}");
152149 pub const ExpectedLabelable = SingleTokenError("Expected 'while', 'for', 'inline', 'suspend', or '{{', found {}");
153150 pub const ExpectedInlinable = SingleTokenError("Expected 'while' or 'for', found {}");
154 pub const ExpectedAsmOutputReturnOrType = SingleTokenError("Expected '->' or " ++
155 @tagName(Token.Id.Identifier) ++ ", found {}");
151 pub const ExpectedAsmOutputReturnOrType = SingleTokenError("Expected '->' or " ++ @tagName(Token.Id.Identifier) ++ ", found {}");
156152 pub const ExpectedSliceOrRBracket = SingleTokenError("Expected ']' or '..', found {}");
157153 pub const ExpectedPrimaryExpr = SingleTokenError("Expected primary expression, found {}");
158154
......@@ -165,8 +161,7 @@ pub const Error = union(enum) {
165161 node: &Node,
166162
167163 pub fn render(self: &ExpectedCall, tokens: &Tree.TokenList, stream: var) !void {
168 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}",
169 @tagName(self.node.id));
164 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ ", found {}", @tagName(self.node.id));
170165 }
171166 };
172167
......@@ -174,8 +169,7 @@ pub const Error = union(enum) {
174169 node: &Node,
175170
176171 pub fn render(self: &ExpectedCallOrFnProto, tokens: &Tree.TokenList, stream: var) !void {
177 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++
178 @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id));
172 return stream.print("expected " ++ @tagName(@TagType(Node.SuffixOp.Op).Call) ++ " or " ++ @tagName(Node.Id.FnProto) ++ ", found {}", @tagName(self.node.id));
179173 }
180174 };
181175
......@@ -445,17 +439,17 @@ pub const Node = struct {
445439
446440 pub fn iterate(self: &Root, index: usize) ?&Node {
447441 if (index < self.decls.len) {
448 return *self.decls.at(index);
442 return self.decls.at(index).*;
449443 }
450444 return null;
451445 }
452446
453447 pub fn firstToken(self: &Root) TokenIndex {
454 return if (self.decls.len == 0) self.eof_token else (*self.decls.at(0)).firstToken();
448 return if (self.decls.len == 0) self.eof_token else (self.decls.at(0).*).firstToken();
455449 }
456450
457451 pub fn lastToken(self: &Root) TokenIndex {
458 return if (self.decls.len == 0) self.eof_token else (*self.decls.at(self.decls.len - 1)).lastToken();
452 return if (self.decls.len == 0) self.eof_token else (self.decls.at(self.decls.len - 1).*).lastToken();
459453 }
460454 };
461455
......@@ -545,7 +539,7 @@ pub const Node = struct {
545539 pub fn iterate(self: &ErrorSetDecl, index: usize) ?&Node {
546540 var i = index;
547541
548 if (i < self.decls.len) return *self.decls.at(i);
542 if (i < self.decls.len) return self.decls.at(i).*;
549543 i -= self.decls.len;
550544
551545 return null;
......@@ -598,10 +592,10 @@ pub const Node = struct {
598592 i -= 1;
599593 },
600594 InitArg.None,
601 InitArg.Enum => { }
595 InitArg.Enum => {},
602596 }
603597
604 if (i < self.fields_and_decls.len) return *self.fields_and_decls.at(i);
598 if (i < self.fields_and_decls.len) return self.fields_and_decls.at(i).*;
605599 i -= self.fields_and_decls.len;
606600
607601 return null;
......@@ -814,7 +808,7 @@ pub const Node = struct {
814808 i -= 1;
815809 }
816810
817 if (i < self.params.len) return *self.params.at(self.params.len - i - 1);
811 if (i < self.params.len) return self.params.at(self.params.len - i - 1).*;
818812 i -= self.params.len;
819813
820814 if (self.align_expr) |align_expr| {
......@@ -839,7 +833,6 @@ pub const Node = struct {
839833 i -= 1;
840834 }
841835
842
843836 return null;
844837 }
845838
......@@ -934,7 +927,7 @@ pub const Node = struct {
934927 pub fn iterate(self: &Block, index: usize) ?&Node {
935928 var i = index;
936929
937 if (i < self.statements.len) return *self.statements.at(i);
930 if (i < self.statements.len) return self.statements.at(i).*;
938931 i -= self.statements.len;
939932
940933 return null;
......@@ -1119,6 +1112,7 @@ pub const Node = struct {
11191112 base: Node,
11201113 switch_token: TokenIndex,
11211114 expr: &Node,
1115
11221116 /// these can be SwitchCase nodes or LineComment nodes
11231117 cases: CaseList,
11241118 rbrace: TokenIndex,
......@@ -1131,7 +1125,7 @@ pub const Node = struct {
11311125 if (i < 1) return self.expr;
11321126 i -= 1;
11331127
1134 if (i < self.cases.len) return *self.cases.at(i);
1128 if (i < self.cases.len) return self.cases.at(i).*;
11351129 i -= self.cases.len;
11361130
11371131 return null;
......@@ -1157,7 +1151,7 @@ pub const Node = struct {
11571151 pub fn iterate(self: &SwitchCase, index: usize) ?&Node {
11581152 var i = index;
11591153
1160 if (i < self.items.len) return *self.items.at(i);
1154 if (i < self.items.len) return self.items.at(i).*;
11611155 i -= self.items.len;
11621156
11631157 if (self.payload) |payload| {
......@@ -1172,7 +1166,7 @@ pub const Node = struct {
11721166 }
11731167
11741168 pub fn firstToken(self: &SwitchCase) TokenIndex {
1175 return (*self.items.at(0)).firstToken();
1169 return (self.items.at(0).*).firstToken();
11761170 }
11771171
11781172 pub fn lastToken(self: &SwitchCase) TokenIndex {
......@@ -1616,7 +1610,7 @@ pub const Node = struct {
16161610
16171611 switch (self.op) {
16181612 @TagType(Op).Call => |*call_info| {
1619 if (i < call_info.params.len) return *call_info.params.at(i);
1613 if (i < call_info.params.len) return call_info.params.at(i).*;
16201614 i -= call_info.params.len;
16211615 },
16221616 Op.ArrayAccess => |index_expr| {
......@@ -1633,11 +1627,11 @@ pub const Node = struct {
16331627 }
16341628 },
16351629 Op.ArrayInitializer => |*exprs| {
1636 if (i < exprs.len) return *exprs.at(i);
1630 if (i < exprs.len) return exprs.at(i).*;
16371631 i -= exprs.len;
16381632 },
16391633 Op.StructInitializer => |*fields| {
1640 if (i < fields.len) return *fields.at(i);
1634 if (i < fields.len) return fields.at(i).*;
16411635 i -= fields.len;
16421636 },
16431637 }
......@@ -1830,7 +1824,7 @@ pub const Node = struct {
18301824 pub fn iterate(self: &BuiltinCall, index: usize) ?&Node {
18311825 var i = index;
18321826
1833 if (i < self.params.len) return *self.params.at(i);
1827 if (i < self.params.len) return self.params.at(i).*;
18341828 i -= self.params.len;
18351829
18361830 return null;
......@@ -1873,11 +1867,11 @@ pub const Node = struct {
18731867 }
18741868
18751869 pub fn firstToken(self: &MultilineStringLiteral) TokenIndex {
1876 return *self.lines.at(0);
1870 return self.lines.at(0).*;
18771871 }
18781872
18791873 pub fn lastToken(self: &MultilineStringLiteral) TokenIndex {
1880 return *self.lines.at(self.lines.len - 1);
1874 return self.lines.at(self.lines.len - 1).*;
18811875 }
18821876 };
18831877
......@@ -1974,7 +1968,7 @@ pub const Node = struct {
19741968
19751969 const Kind = union(enum) {
19761970 Variable: &Identifier,
1977 Return: &Node
1971 Return: &Node,
19781972 };
19791973
19801974 pub fn iterate(self: &AsmOutput, index: usize) ?&Node {
......@@ -1994,7 +1988,7 @@ pub const Node = struct {
19941988 Kind.Return => |return_type| {
19951989 if (i < 1) return return_type;
19961990 i -= 1;
1997 }
1991 },
19981992 }
19991993
20001994 return null;
......@@ -2059,13 +2053,13 @@ pub const Node = struct {
20592053 pub fn iterate(self: &Asm, index: usize) ?&Node {
20602054 var i = index;
20612055
2062 if (i < self.outputs.len) return &(*self.outputs.at(index)).base;
2056 if (i < self.outputs.len) return &(self.outputs.at(index).*).base;
20632057 i -= self.outputs.len;
20642058
2065 if (i < self.inputs.len) return &(*self.inputs.at(index)).base;
2059 if (i < self.inputs.len) return &(self.inputs.at(index).*).base;
20662060 i -= self.inputs.len;
20672061
2068 if (i < self.clobbers.len) return *self.clobbers.at(index);
2062 if (i < self.clobbers.len) return self.clobbers.at(index).*;
20692063 i -= self.clobbers.len;
20702064
20712065 return null;
......@@ -2159,11 +2153,11 @@ pub const Node = struct {
21592153 }
21602154
21612155 pub fn firstToken(self: &DocComment) TokenIndex {
2162 return *self.lines.at(0);
2156 return self.lines.at(0).*;
21632157 }
21642158
21652159 pub fn lastToken(self: &DocComment) TokenIndex {
2166 return *self.lines.at(self.lines.len - 1);
2160 return self.lines.at(self.lines.len - 1).*;
21672161 }
21682162 };
21692163
......@@ -2192,4 +2186,3 @@ pub const Node = struct {
21922186 }
21932187 };
21942188};
2195
std/zig/parse.zig+930-1161
......@@ -17,15 +17,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1717 defer stack.deinit();
1818
1919 const arena = &tree_arena.allocator;
20 const root_node = try arena.construct(ast.Node.Root {
21 .base = ast.Node { .id = ast.Node.Id.Root },
20 const root_node = try arena.construct(ast.Node.Root{
21 .base = ast.Node{ .id = ast.Node.Id.Root },
2222 .decls = ast.Node.Root.DeclList.init(arena),
2323 .doc_comments = null,
2424 // initialized when we get the eof token
2525 .eof_token = undefined,
2626 });
2727
28 var tree = ast.Tree {
28 var tree = ast.Tree{
2929 .source = source,
3030 .root_node = root_node,
3131 .arena_allocator = tree_arena,
......@@ -36,9 +36,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
3636 var tokenizer = Tokenizer.init(tree.source);
3737 while (true) {
3838 const token_ptr = try tree.tokens.addOne();
39 *token_ptr = tokenizer.next();
40 if (token_ptr.id == Token.Id.Eof)
41 break;
39 token_ptr.* = tokenizer.next();
40 if (token_ptr.id == Token.Id.Eof) break;
4241 }
4342 var tok_it = tree.tokens.iterator(0);
4443
......@@ -63,33 +62,27 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
6362 Token.Id.Keyword_test => {
6463 stack.append(State.TopLevel) catch unreachable;
6564
66 const block = try arena.construct(ast.Node.Block {
67 .base = ast.Node {
68 .id = ast.Node.Id.Block,
69 },
65 const block = try arena.construct(ast.Node.Block{
66 .base = ast.Node{ .id = ast.Node.Id.Block },
7067 .label = null,
7168 .lbrace = undefined,
7269 .statements = ast.Node.Block.StatementList.init(arena),
7370 .rbrace = undefined,
7471 });
75 const test_node = try arena.construct(ast.Node.TestDecl {
76 .base = ast.Node {
77 .id = ast.Node.Id.TestDecl,
78 },
72 const test_node = try arena.construct(ast.Node.TestDecl{
73 .base = ast.Node{ .id = ast.Node.Id.TestDecl },
7974 .doc_comments = comments,
8075 .test_token = token_index,
8176 .name = undefined,
8277 .body_node = &block.base,
8378 });
8479 try root_node.decls.push(&test_node.base);
85 try stack.append(State { .Block = block });
86 try stack.append(State {
87 .ExpectTokenSave = ExpectTokenSave {
88 .id = Token.Id.LBrace,
89 .ptr = &block.rbrace,
90 }
91 });
92 try stack.append(State { .StringLiteral = OptionalCtx { .Required = &test_node.name } });
80 try stack.append(State{ .Block = block });
81 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
82 .id = Token.Id.LBrace,
83 .ptr = &block.rbrace,
84 } });
85 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &test_node.name } });
9386 continue;
9487 },
9588 Token.Id.Eof => {
......@@ -99,29 +92,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
9992 },
10093 Token.Id.Keyword_pub => {
10194 stack.append(State.TopLevel) catch unreachable;
102 try stack.append(State {
103 .TopLevelExtern = TopLevelDeclCtx {
104 .decls = &root_node.decls,
105 .visib_token = token_index,
106 .extern_export_inline_token = null,
107 .lib_name = null,
108 .comments = comments,
109 }
110 });
95 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
96 .decls = &root_node.decls,
97 .visib_token = token_index,
98 .extern_export_inline_token = null,
99 .lib_name = null,
100 .comments = comments,
101 } });
111102 continue;
112103 },
113104 Token.Id.Keyword_comptime => {
114 const block = try arena.construct(ast.Node.Block {
115 .base = ast.Node {.id = ast.Node.Id.Block },
105 const block = try arena.construct(ast.Node.Block{
106 .base = ast.Node{ .id = ast.Node.Id.Block },
116107 .label = null,
117108 .lbrace = undefined,
118109 .statements = ast.Node.Block.StatementList.init(arena),
119110 .rbrace = undefined,
120111 });
121 const node = try arena.construct(ast.Node.Comptime {
122 .base = ast.Node {
123 .id = ast.Node.Id.Comptime,
124 },
112 const node = try arena.construct(ast.Node.Comptime{
113 .base = ast.Node{ .id = ast.Node.Id.Comptime },
125114 .comptime_token = token_index,
126115 .expr = &block.base,
127116 .doc_comments = comments,
......@@ -129,27 +118,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
129118 try root_node.decls.push(&node.base);
130119
131120 stack.append(State.TopLevel) catch unreachable;
132 try stack.append(State { .Block = block });
133 try stack.append(State {
134 .ExpectTokenSave = ExpectTokenSave {
135 .id = Token.Id.LBrace,
136 .ptr = &block.rbrace,
137 }
138 });
121 try stack.append(State{ .Block = block });
122 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
123 .id = Token.Id.LBrace,
124 .ptr = &block.rbrace,
125 } });
139126 continue;
140127 },
141128 else => {
142129 putBackToken(&tok_it, &tree);
143130 stack.append(State.TopLevel) catch unreachable;
144 try stack.append(State {
145 .TopLevelExtern = TopLevelDeclCtx {
146 .decls = &root_node.decls,
147 .visib_token = null,
148 .extern_export_inline_token = null,
149 .lib_name = null,
150 .comments = comments,
151 }
152 });
131 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
132 .decls = &root_node.decls,
133 .visib_token = null,
134 .extern_export_inline_token = null,
135 .lib_name = null,
136 .comments = comments,
137 } });
153138 continue;
154139 },
155140 }
......@@ -159,41 +144,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
159144 const token_index = token.index;
160145 const token_ptr = token.ptr;
161146 switch (token_ptr.id) {
162 Token.Id.Keyword_export, Token.Id.Keyword_inline => {
163 stack.append(State {
164 .TopLevelDecl = TopLevelDeclCtx {
165 .decls = ctx.decls,
166 .visib_token = ctx.visib_token,
167 .extern_export_inline_token = AnnotatedToken {
168 .index = token_index,
169 .ptr = token_ptr,
170 },
171 .lib_name = null,
172 .comments = ctx.comments,
147 Token.Id.Keyword_export,
148 Token.Id.Keyword_inline => {
149 stack.append(State{ .TopLevelDecl = TopLevelDeclCtx{
150 .decls = ctx.decls,
151 .visib_token = ctx.visib_token,
152 .extern_export_inline_token = AnnotatedToken{
153 .index = token_index,
154 .ptr = token_ptr,
173155 },
174 }) catch unreachable;
156 .lib_name = null,
157 .comments = ctx.comments,
158 } }) catch unreachable;
175159 continue;
176160 },
177161 Token.Id.Keyword_extern => {
178 stack.append(State {
179 .TopLevelLibname = TopLevelDeclCtx {
180 .decls = ctx.decls,
181 .visib_token = ctx.visib_token,
182 .extern_export_inline_token = AnnotatedToken {
183 .index = token_index,
184 .ptr = token_ptr,
185 },
186 .lib_name = null,
187 .comments = ctx.comments,
162 stack.append(State{ .TopLevelLibname = TopLevelDeclCtx{
163 .decls = ctx.decls,
164 .visib_token = ctx.visib_token,
165 .extern_export_inline_token = AnnotatedToken{
166 .index = token_index,
167 .ptr = token_ptr,
188168 },
189 }) catch unreachable;
169 .lib_name = null,
170 .comments = ctx.comments,
171 } }) catch unreachable;
190172 continue;
191173 },
192174 else => {
193175 putBackToken(&tok_it, &tree);
194 stack.append(State { .TopLevelDecl = ctx }) catch unreachable;
176 stack.append(State{ .TopLevelDecl = ctx }) catch unreachable;
195177 continue;
196 }
178 },
197179 }
198180 },
199181 State.TopLevelLibname => |ctx| {
......@@ -207,15 +189,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
207189 };
208190 };
209191
210 stack.append(State {
211 .TopLevelDecl = TopLevelDeclCtx {
212 .decls = ctx.decls,
213 .visib_token = ctx.visib_token,
214 .extern_export_inline_token = ctx.extern_export_inline_token,
215 .lib_name = lib_name,
216 .comments = ctx.comments,
217 },
218 }) catch unreachable;
192 stack.append(State{ .TopLevelDecl = TopLevelDeclCtx{
193 .decls = ctx.decls,
194 .visib_token = ctx.visib_token,
195 .extern_export_inline_token = ctx.extern_export_inline_token,
196 .lib_name = lib_name,
197 .comments = ctx.comments,
198 } }) catch unreachable;
219199 continue;
220200 },
221201 State.TopLevelDecl => |ctx| {
......@@ -225,14 +205,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
225205 switch (token_ptr.id) {
226206 Token.Id.Keyword_use => {
227207 if (ctx.extern_export_inline_token) |annotated_token| {
228 *(try tree.errors.addOne()) = Error {
229 .InvalidToken = Error.InvalidToken { .token = annotated_token.index },
230 };
208 ((try tree.errors.addOne())).* = Error{ .InvalidToken = Error.InvalidToken{ .token = annotated_token.index } };
231209 return tree;
232210 }
233211
234 const node = try arena.construct(ast.Node.Use {
235 .base = ast.Node {.id = ast.Node.Id.Use },
212 const node = try arena.construct(ast.Node.Use{
213 .base = ast.Node{ .id = ast.Node.Id.Use },
236214 .visib_token = ctx.visib_token,
237215 .expr = undefined,
238216 .semicolon_token = undefined,
......@@ -240,44 +218,39 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
240218 });
241219 try ctx.decls.push(&node.base);
242220
243 stack.append(State {
244 .ExpectTokenSave = ExpectTokenSave {
245 .id = Token.Id.Semicolon,
246 .ptr = &node.semicolon_token,
247 }
248 }) catch unreachable;
249 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
221 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
222 .id = Token.Id.Semicolon,
223 .ptr = &node.semicolon_token,
224 } }) catch unreachable;
225 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
250226 continue;
251227 },
252 Token.Id.Keyword_var, Token.Id.Keyword_const => {
228 Token.Id.Keyword_var,
229 Token.Id.Keyword_const => {
253230 if (ctx.extern_export_inline_token) |annotated_token| {
254231 if (annotated_token.ptr.id == Token.Id.Keyword_inline) {
255 *(try tree.errors.addOne()) = Error {
256 .InvalidToken = Error.InvalidToken { .token = annotated_token.index },
257 };
232 ((try tree.errors.addOne())).* = Error{ .InvalidToken = Error.InvalidToken{ .token = annotated_token.index } };
258233 return tree;
259234 }
260235 }
261236
262 try stack.append(State {
263 .VarDecl = VarDeclCtx {
264 .comments = ctx.comments,
265 .visib_token = ctx.visib_token,
266 .lib_name = ctx.lib_name,
267 .comptime_token = null,
268 .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null,
269 .mut_token = token_index,
270 .list = ctx.decls
271 }
272 });
273 continue;
274 },
275 Token.Id.Keyword_fn, Token.Id.Keyword_nakedcc,
276 Token.Id.Keyword_stdcallcc, Token.Id.Keyword_async => {
277 const fn_proto = try arena.construct(ast.Node.FnProto {
278 .base = ast.Node {
279 .id = ast.Node.Id.FnProto,
280 },
237 try stack.append(State{ .VarDecl = VarDeclCtx{
238 .comments = ctx.comments,
239 .visib_token = ctx.visib_token,
240 .lib_name = ctx.lib_name,
241 .comptime_token = null,
242 .extern_export_token = if (ctx.extern_export_inline_token) |at| at.index else null,
243 .mut_token = token_index,
244 .list = ctx.decls,
245 } });
246 continue;
247 },
248 Token.Id.Keyword_fn,
249 Token.Id.Keyword_nakedcc,
250 Token.Id.Keyword_stdcallcc,
251 Token.Id.Keyword_async => {
252 const fn_proto = try arena.construct(ast.Node.FnProto{
253 .base = ast.Node{ .id = ast.Node.Id.FnProto },
281254 .doc_comments = ctx.comments,
282255 .visib_token = ctx.visib_token,
283256 .name_token = null,
......@@ -293,36 +266,33 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
293266 .align_expr = null,
294267 });
295268 try ctx.decls.push(&fn_proto.base);
296 stack.append(State { .FnDef = fn_proto }) catch unreachable;
297 try stack.append(State { .FnProto = fn_proto });
269 stack.append(State{ .FnDef = fn_proto }) catch unreachable;
270 try stack.append(State{ .FnProto = fn_proto });
298271
299272 switch (token_ptr.id) {
300 Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
273 Token.Id.Keyword_nakedcc,
274 Token.Id.Keyword_stdcallcc => {
301275 fn_proto.cc_token = token_index;
302 try stack.append(State {
303 .ExpectTokenSave = ExpectTokenSave {
304 .id = Token.Id.Keyword_fn,
305 .ptr = &fn_proto.fn_token,
306 }
307 });
276 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
277 .id = Token.Id.Keyword_fn,
278 .ptr = &fn_proto.fn_token,
279 } });
308280 continue;
309281 },
310282 Token.Id.Keyword_async => {
311 const async_node = try arena.construct(ast.Node.AsyncAttribute {
312 .base = ast.Node {.id = ast.Node.Id.AsyncAttribute },
283 const async_node = try arena.construct(ast.Node.AsyncAttribute{
284 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
313285 .async_token = token_index,
314286 .allocator_type = null,
315287 .rangle_bracket = null,
316288 });
317289 fn_proto.async_attr = async_node;
318290
319 try stack.append(State {
320 .ExpectTokenSave = ExpectTokenSave {
321 .id = Token.Id.Keyword_fn,
322 .ptr = &fn_proto.fn_token,
323 }
324 });
325 try stack.append(State { .AsyncAllocator = async_node });
291 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
292 .id = Token.Id.Keyword_fn,
293 .ptr = &fn_proto.fn_token,
294 } });
295 try stack.append(State{ .AsyncAllocator = async_node });
326296 continue;
327297 },
328298 Token.Id.Keyword_fn => {
......@@ -333,9 +303,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
333303 }
334304 },
335305 else => {
336 *(try tree.errors.addOne()) = Error {
337 .ExpectedVarDeclOrFn = Error.ExpectedVarDeclOrFn { .token = token_index },
338 };
306 ((try tree.errors.addOne())).* = Error{ .ExpectedVarDeclOrFn = Error.ExpectedVarDeclOrFn{ .token = token_index } };
339307 return tree;
340308 },
341309 }
......@@ -343,34 +311,30 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
343311 State.TopLevelExternOrField => |ctx| {
344312 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |identifier| {
345313 std.debug.assert(ctx.container_decl.kind == ast.Node.ContainerDecl.Kind.Struct);
346 const node = try arena.construct(ast.Node.StructField {
347 .base = ast.Node {
348 .id = ast.Node.Id.StructField,
349 },
314 const node = try arena.construct(ast.Node.StructField{
315 .base = ast.Node{ .id = ast.Node.Id.StructField },
350316 .doc_comments = ctx.comments,
351317 .visib_token = ctx.visib_token,
352318 .name_token = identifier,
353319 .type_expr = undefined,
354320 });
355321 const node_ptr = try ctx.container_decl.fields_and_decls.addOne();
356 *node_ptr = &node.base;
322 node_ptr.* = &node.base;
357323
358 stack.append(State { .FieldListCommaOrEnd = ctx.container_decl }) catch unreachable;
359 try stack.append(State { .Expression = OptionalCtx { .Required = &node.type_expr } });
360 try stack.append(State { .ExpectToken = Token.Id.Colon });
324 stack.append(State{ .FieldListCommaOrEnd = ctx.container_decl }) catch unreachable;
325 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.type_expr } });
326 try stack.append(State{ .ExpectToken = Token.Id.Colon });
361327 continue;
362328 }
363329
364330 stack.append(State{ .ContainerDecl = ctx.container_decl }) catch unreachable;
365 try stack.append(State {
366 .TopLevelExtern = TopLevelDeclCtx {
367 .decls = &ctx.container_decl.fields_and_decls,
368 .visib_token = ctx.visib_token,
369 .extern_export_inline_token = null,
370 .lib_name = null,
371 .comments = ctx.comments,
372 }
373 });
331 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
332 .decls = &ctx.container_decl.fields_and_decls,
333 .visib_token = ctx.visib_token,
334 .extern_export_inline_token = null,
335 .lib_name = null,
336 .comments = ctx.comments,
337 } });
374338 continue;
375339 },
376340
......@@ -382,7 +346,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
382346 putBackToken(&tok_it, &tree);
383347 continue;
384348 }
385 stack.append(State { .Expression = ctx }) catch unreachable;
349 stack.append(State{ .Expression = ctx }) catch unreachable;
386350 continue;
387351 },
388352
......@@ -390,8 +354,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
390354 const token = nextToken(&tok_it, &tree);
391355 const token_index = token.index;
392356 const token_ptr = token.ptr;
393 const node = try arena.construct(ast.Node.ContainerDecl {
394 .base = ast.Node {.id = ast.Node.Id.ContainerDecl },
357 const node = try arena.construct(ast.Node.ContainerDecl{
358 .base = ast.Node{ .id = ast.Node.Id.ContainerDecl },
395359 .ltoken = ctx.ltoken,
396360 .layout = ctx.layout,
397361 .kind = switch (token_ptr.id) {
......@@ -399,9 +363,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
399363 Token.Id.Keyword_union => ast.Node.ContainerDecl.Kind.Union,
400364 Token.Id.Keyword_enum => ast.Node.ContainerDecl.Kind.Enum,
401365 else => {
402 *(try tree.errors.addOne()) = Error {
403 .ExpectedAggregateKw = Error.ExpectedAggregateKw { .token = token_index },
404 };
366 ((try tree.errors.addOne())).* = Error{ .ExpectedAggregateKw = Error.ExpectedAggregateKw{ .token = token_index } };
405367 return tree;
406368 },
407369 },
......@@ -411,9 +373,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
411373 });
412374 ctx.opt_ctx.store(&node.base);
413375
414 stack.append(State { .ContainerDecl = node }) catch unreachable;
415 try stack.append(State { .ExpectToken = Token.Id.LBrace });
416 try stack.append(State { .ContainerInitArgStart = node });
376 stack.append(State{ .ContainerDecl = node }) catch unreachable;
377 try stack.append(State{ .ExpectToken = Token.Id.LBrace });
378 try stack.append(State{ .ContainerInitArgStart = node });
417379 continue;
418380 },
419381
......@@ -422,8 +384,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
422384 continue;
423385 }
424386
425 stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
426 try stack.append(State { .ContainerInitArg = container_decl });
387 stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable;
388 try stack.append(State{ .ContainerInitArg = container_decl });
427389 continue;
428390 },
429391
......@@ -433,23 +395,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
433395 const init_arg_token_ptr = init_arg_token.ptr;
434396 switch (init_arg_token_ptr.id) {
435397 Token.Id.Keyword_enum => {
436 container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg {.Enum = null};
398 container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg{ .Enum = null };
437399 const lparen_tok = nextToken(&tok_it, &tree);
438400 const lparen_tok_index = lparen_tok.index;
439401 const lparen_tok_ptr = lparen_tok.ptr;
440402 if (lparen_tok_ptr.id == Token.Id.LParen) {
441 try stack.append(State { .ExpectToken = Token.Id.RParen } );
442 try stack.append(State { .Expression = OptionalCtx {
443 .RequiredNull = &container_decl.init_arg_expr.Enum,
444 } });
403 try stack.append(State{ .ExpectToken = Token.Id.RParen });
404 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &container_decl.init_arg_expr.Enum } });
445405 } else {
446406 putBackToken(&tok_it, &tree);
447407 }
448408 },
449409 else => {
450410 putBackToken(&tok_it, &tree);
451 container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg { .Type = undefined };
452 stack.append(State { .Expression = OptionalCtx { .Required = &container_decl.init_arg_expr.Type } }) catch unreachable;
411 container_decl.init_arg_expr = ast.Node.ContainerDecl.InitArg{ .Type = undefined };
412 stack.append(State{ .Expression = OptionalCtx{ .Required = &container_decl.init_arg_expr.Type } }) catch unreachable;
453413 },
454414 }
455415 continue;
......@@ -468,26 +428,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
468428 Token.Id.Identifier => {
469429 switch (container_decl.kind) {
470430 ast.Node.ContainerDecl.Kind.Struct => {
471 const node = try arena.construct(ast.Node.StructField {
472 .base = ast.Node {
473 .id = ast.Node.Id.StructField,
474 },
431 const node = try arena.construct(ast.Node.StructField{
432 .base = ast.Node{ .id = ast.Node.Id.StructField },
475433 .doc_comments = comments,
476434 .visib_token = null,
477435 .name_token = token_index,
478436 .type_expr = undefined,
479437 });
480438 const node_ptr = try container_decl.fields_and_decls.addOne();
481 *node_ptr = &node.base;
439 node_ptr.* = &node.base;
482440
483 try stack.append(State { .FieldListCommaOrEnd = container_decl });
484 try stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.type_expr } });
485 try stack.append(State { .ExpectToken = Token.Id.Colon });
441 try stack.append(State{ .FieldListCommaOrEnd = container_decl });
442 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.type_expr } });
443 try stack.append(State{ .ExpectToken = Token.Id.Colon });
486444 continue;
487445 },
488446 ast.Node.ContainerDecl.Kind.Union => {
489 const node = try arena.construct(ast.Node.UnionTag {
490 .base = ast.Node {.id = ast.Node.Id.UnionTag },
447 const node = try arena.construct(ast.Node.UnionTag{
448 .base = ast.Node{ .id = ast.Node.Id.UnionTag },
491449 .name_token = token_index,
492450 .type_expr = null,
493451 .value_expr = null,
......@@ -495,24 +453,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
495453 });
496454 try container_decl.fields_and_decls.push(&node.base);
497455
498 stack.append(State { .FieldListCommaOrEnd = container_decl }) catch unreachable;
499 try stack.append(State { .FieldInitValue = OptionalCtx { .RequiredNull = &node.value_expr } });
500 try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &node.type_expr } });
501 try stack.append(State { .IfToken = Token.Id.Colon });
456 stack.append(State{ .FieldListCommaOrEnd = container_decl }) catch unreachable;
457 try stack.append(State{ .FieldInitValue = OptionalCtx{ .RequiredNull = &node.value_expr } });
458 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &node.type_expr } });
459 try stack.append(State{ .IfToken = Token.Id.Colon });
502460 continue;
503461 },
504462 ast.Node.ContainerDecl.Kind.Enum => {
505 const node = try arena.construct(ast.Node.EnumTag {
506 .base = ast.Node { .id = ast.Node.Id.EnumTag },
463 const node = try arena.construct(ast.Node.EnumTag{
464 .base = ast.Node{ .id = ast.Node.Id.EnumTag },
507465 .name_token = token_index,
508466 .value = null,
509467 .doc_comments = comments,
510468 });
511469 try container_decl.fields_and_decls.push(&node.base);
512470
513 stack.append(State { .FieldListCommaOrEnd = container_decl }) catch unreachable;
514 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &node.value } });
515 try stack.append(State { .IfToken = Token.Id.Equal });
471 stack.append(State{ .FieldListCommaOrEnd = container_decl }) catch unreachable;
472 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &node.value } });
473 try stack.append(State{ .IfToken = Token.Id.Equal });
516474 continue;
517475 },
518476 }
......@@ -520,48 +478,40 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
520478 Token.Id.Keyword_pub => {
521479 switch (container_decl.kind) {
522480 ast.Node.ContainerDecl.Kind.Struct => {
523 try stack.append(State {
524 .TopLevelExternOrField = TopLevelExternOrFieldCtx {
525 .visib_token = token_index,
526 .container_decl = container_decl,
527 .comments = comments,
528 }
529 });
481 try stack.append(State{ .TopLevelExternOrField = TopLevelExternOrFieldCtx{
482 .visib_token = token_index,
483 .container_decl = container_decl,
484 .comments = comments,
485 } });
530486 continue;
531487 },
532488 else => {
533489 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
534 try stack.append(State {
535 .TopLevelExtern = TopLevelDeclCtx {
536 .decls = &container_decl.fields_and_decls,
537 .visib_token = token_index,
538 .extern_export_inline_token = null,
539 .lib_name = null,
540 .comments = comments,
541 }
542 });
490 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
491 .decls = &container_decl.fields_and_decls,
492 .visib_token = token_index,
493 .extern_export_inline_token = null,
494 .lib_name = null,
495 .comments = comments,
496 } });
543497 continue;
544 }
498 },
545499 }
546500 },
547501 Token.Id.Keyword_export => {
548502 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
549 try stack.append(State {
550 .TopLevelExtern = TopLevelDeclCtx {
551 .decls = &container_decl.fields_and_decls,
552 .visib_token = token_index,
553 .extern_export_inline_token = null,
554 .lib_name = null,
555 .comments = comments,
556 }
557 });
503 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
504 .decls = &container_decl.fields_and_decls,
505 .visib_token = token_index,
506 .extern_export_inline_token = null,
507 .lib_name = null,
508 .comments = comments,
509 } });
558510 continue;
559511 },
560512 Token.Id.RBrace => {
561513 if (comments != null) {
562 *(try tree.errors.addOne()) = Error {
563 .UnattachedDocComment = Error.UnattachedDocComment { .token = token_index },
564 };
514 ((try tree.errors.addOne())).* = Error{ .UnattachedDocComment = Error.UnattachedDocComment{ .token = token_index } };
565515 return tree;
566516 }
567517 container_decl.rbrace_token = token_index;
......@@ -570,26 +520,21 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
570520 else => {
571521 putBackToken(&tok_it, &tree);
572522 stack.append(State{ .ContainerDecl = container_decl }) catch unreachable;
573 try stack.append(State {
574 .TopLevelExtern = TopLevelDeclCtx {
575 .decls = &container_decl.fields_and_decls,
576 .visib_token = null,
577 .extern_export_inline_token = null,
578 .lib_name = null,
579 .comments = comments,
580 }
581 });
523 try stack.append(State{ .TopLevelExtern = TopLevelDeclCtx{
524 .decls = &container_decl.fields_and_decls,
525 .visib_token = null,
526 .extern_export_inline_token = null,
527 .lib_name = null,
528 .comments = comments,
529 } });
582530 continue;
583 }
531 },
584532 }
585533 },
586534
587
588535 State.VarDecl => |ctx| {
589 const var_decl = try arena.construct(ast.Node.VarDecl {
590 .base = ast.Node {
591 .id = ast.Node.Id.VarDecl,
592 },
536 const var_decl = try arena.construct(ast.Node.VarDecl{
537 .base = ast.Node{ .id = ast.Node.Id.VarDecl },
593538 .doc_comments = ctx.comments,
594539 .visib_token = ctx.visib_token,
595540 .mut_token = ctx.mut_token,
......@@ -606,27 +551,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
606551 });
607552 try ctx.list.push(&var_decl.base);
608553
609 try stack.append(State { .VarDeclAlign = var_decl });
610 try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &var_decl.type_node} });
611 try stack.append(State { .IfToken = Token.Id.Colon });
612 try stack.append(State {
613 .ExpectTokenSave = ExpectTokenSave {
614 .id = Token.Id.Identifier,
615 .ptr = &var_decl.name_token,
616 }
617 });
554 try stack.append(State{ .VarDeclAlign = var_decl });
555 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &var_decl.type_node } });
556 try stack.append(State{ .IfToken = Token.Id.Colon });
557 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
558 .id = Token.Id.Identifier,
559 .ptr = &var_decl.name_token,
560 } });
618561 continue;
619562 },
620563 State.VarDeclAlign => |var_decl| {
621 try stack.append(State { .VarDeclEq = var_decl });
564 try stack.append(State{ .VarDeclEq = var_decl });
622565
623566 const next_token = nextToken(&tok_it, &tree);
624567 const next_token_index = next_token.index;
625568 const next_token_ptr = next_token.ptr;
626569 if (next_token_ptr.id == Token.Id.Keyword_align) {
627 try stack.append(State { .ExpectToken = Token.Id.RParen });
628 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.align_node} });
629 try stack.append(State { .ExpectToken = Token.Id.LParen });
570 try stack.append(State{ .ExpectToken = Token.Id.RParen });
571 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &var_decl.align_node } });
572 try stack.append(State{ .ExpectToken = Token.Id.LParen });
630573 continue;
631574 }
632575
......@@ -640,8 +583,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
640583 switch (token_ptr.id) {
641584 Token.Id.Equal => {
642585 var_decl.eq_token = token_index;
643 stack.append(State { .VarDeclSemiColon = var_decl }) catch unreachable;
644 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &var_decl.init_node } });
586 stack.append(State{ .VarDeclSemiColon = var_decl }) catch unreachable;
587 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &var_decl.init_node } });
645588 continue;
646589 },
647590 Token.Id.Semicolon => {
......@@ -649,11 +592,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
649592 continue;
650593 },
651594 else => {
652 *(try tree.errors.addOne()) = Error {
653 .ExpectedEqOrSemi = Error.ExpectedEqOrSemi { .token = token_index },
654 };
595 ((try tree.errors.addOne())).* = Error{ .ExpectedEqOrSemi = Error.ExpectedEqOrSemi{ .token = token_index } };
655596 return tree;
656 }
597 },
657598 }
658599 },
659600
......@@ -661,12 +602,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
661602 const semicolon_token = nextToken(&tok_it, &tree);
662603
663604 if (semicolon_token.ptr.id != Token.Id.Semicolon) {
664 *(try tree.errors.addOne()) = Error {
665 .ExpectedToken = Error.ExpectedToken {
666 .token = semicolon_token.index,
667 .expected_id = Token.Id.Semicolon,
668 },
669 };
605 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
606 .token = semicolon_token.index,
607 .expected_id = Token.Id.Semicolon,
608 } };
670609 return tree;
671610 }
672611
......@@ -686,32 +625,30 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
686625 const token = nextToken(&tok_it, &tree);
687626 const token_index = token.index;
688627 const token_ptr = token.ptr;
689 switch(token_ptr.id) {
628 switch (token_ptr.id) {
690629 Token.Id.LBrace => {
691 const block = try arena.construct(ast.Node.Block {
692 .base = ast.Node { .id = ast.Node.Id.Block },
630 const block = try arena.construct(ast.Node.Block{
631 .base = ast.Node{ .id = ast.Node.Id.Block },
693632 .label = null,
694633 .lbrace = token_index,
695634 .statements = ast.Node.Block.StatementList.init(arena),
696635 .rbrace = undefined,
697636 });
698637 fn_proto.body_node = &block.base;
699 stack.append(State { .Block = block }) catch unreachable;
638 stack.append(State{ .Block = block }) catch unreachable;
700639 continue;
701640 },
702641 Token.Id.Semicolon => continue,
703642 else => {
704 *(try tree.errors.addOne()) = Error {
705 .ExpectedSemiOrLBrace = Error.ExpectedSemiOrLBrace { .token = token_index },
706 };
643 ((try tree.errors.addOne())).* = Error{ .ExpectedSemiOrLBrace = Error.ExpectedSemiOrLBrace{ .token = token_index } };
707644 return tree;
708645 },
709646 }
710647 },
711648 State.FnProto => |fn_proto| {
712 stack.append(State { .FnProtoAlign = fn_proto }) catch unreachable;
713 try stack.append(State { .ParamDecl = fn_proto });
714 try stack.append(State { .ExpectToken = Token.Id.LParen });
649 stack.append(State{ .FnProtoAlign = fn_proto }) catch unreachable;
650 try stack.append(State{ .ParamDecl = fn_proto });
651 try stack.append(State{ .ExpectToken = Token.Id.LParen });
715652
716653 if (eatToken(&tok_it, &tree, Token.Id.Identifier)) |name_token| {
717654 fn_proto.name_token = name_token;
......@@ -719,12 +656,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
719656 continue;
720657 },
721658 State.FnProtoAlign => |fn_proto| {
722 stack.append(State { .FnProtoReturnType = fn_proto }) catch unreachable;
659 stack.append(State{ .FnProtoReturnType = fn_proto }) catch unreachable;
723660
724661 if (eatToken(&tok_it, &tree, Token.Id.Keyword_align)) |align_token| {
725 try stack.append(State { .ExpectToken = Token.Id.RParen });
726 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &fn_proto.align_expr } });
727 try stack.append(State { .ExpectToken = Token.Id.LParen });
662 try stack.append(State{ .ExpectToken = Token.Id.RParen });
663 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &fn_proto.align_expr } });
664 try stack.append(State{ .ExpectToken = Token.Id.LParen });
728665 }
729666 continue;
730667 },
......@@ -734,42 +671,37 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
734671 const token_ptr = token.ptr;
735672 switch (token_ptr.id) {
736673 Token.Id.Bang => {
737 fn_proto.return_type = ast.Node.FnProto.ReturnType { .InferErrorSet = undefined };
738 stack.append(State {
739 .TypeExprBegin = OptionalCtx { .Required = &fn_proto.return_type.InferErrorSet },
740 }) catch unreachable;
674 fn_proto.return_type = ast.Node.FnProto.ReturnType{ .InferErrorSet = undefined };
675 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &fn_proto.return_type.InferErrorSet } }) catch unreachable;
741676 continue;
742677 },
743678 else => {
744679 // TODO: this is a special case. Remove this when #760 is fixed
745680 if (token_ptr.id == Token.Id.Keyword_error) {
746681 if ((??tok_it.peek()).id == Token.Id.LBrace) {
747 const error_type_node = try arena.construct(ast.Node.ErrorType {
748 .base = ast.Node { .id = ast.Node.Id.ErrorType },
682 const error_type_node = try arena.construct(ast.Node.ErrorType{
683 .base = ast.Node{ .id = ast.Node.Id.ErrorType },
749684 .token = token_index,
750685 });
751 fn_proto.return_type = ast.Node.FnProto.ReturnType {
752 .Explicit = &error_type_node.base,
753 };
686 fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = &error_type_node.base };
754687 continue;
755688 }
756689 }
757690
758691 putBackToken(&tok_it, &tree);
759 fn_proto.return_type = ast.Node.FnProto.ReturnType { .Explicit = undefined };
760 stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &fn_proto.return_type.Explicit }, }) catch unreachable;
692 fn_proto.return_type = ast.Node.FnProto.ReturnType{ .Explicit = undefined };
693 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &fn_proto.return_type.Explicit } }) catch unreachable;
761694 continue;
762695 },
763696 }
764697 },
765698
766
767699 State.ParamDecl => |fn_proto| {
768700 if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
769701 continue;
770702 }
771 const param_decl = try arena.construct(ast.Node.ParamDecl {
772 .base = ast.Node {.id = ast.Node.Id.ParamDecl },
703 const param_decl = try arena.construct(ast.Node.ParamDecl{
704 .base = ast.Node{ .id = ast.Node.Id.ParamDecl },
773705 .comptime_token = null,
774706 .noalias_token = null,
775707 .name_token = null,
......@@ -778,14 +710,12 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
778710 });
779711 try fn_proto.params.push(&param_decl.base);
780712
781 stack.append(State {
782 .ParamDeclEnd = ParamDeclEndCtx {
783 .param_decl = param_decl,
784 .fn_proto = fn_proto,
785 }
786 }) catch unreachable;
787 try stack.append(State { .ParamDeclName = param_decl });
788 try stack.append(State { .ParamDeclAliasOrComptime = param_decl });
713 stack.append(State{ .ParamDeclEnd = ParamDeclEndCtx{
714 .param_decl = param_decl,
715 .fn_proto = fn_proto,
716 } }) catch unreachable;
717 try stack.append(State{ .ParamDeclName = param_decl });
718 try stack.append(State{ .ParamDeclAliasOrComptime = param_decl });
789719 continue;
790720 },
791721 State.ParamDeclAliasOrComptime => |param_decl| {
......@@ -811,21 +741,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
811741 State.ParamDeclEnd => |ctx| {
812742 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
813743 ctx.param_decl.var_args_token = ellipsis3;
814 stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
744 stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable;
815745 continue;
816746 }
817747
818 try stack.append(State { .ParamDeclComma = ctx.fn_proto });
819 try stack.append(State {
820 .TypeExprBegin = OptionalCtx { .Required = &ctx.param_decl.type_node }
821 });
748 try stack.append(State{ .ParamDeclComma = ctx.fn_proto });
749 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &ctx.param_decl.type_node } });
822750 continue;
823751 },
824752 State.ParamDeclComma => |fn_proto| {
825753 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) {
826754 ExpectCommaOrEndResult.end_token => |t| {
827755 if (t == null) {
828 stack.append(State { .ParamDecl = fn_proto }) catch unreachable;
756 stack.append(State{ .ParamDecl = fn_proto }) catch unreachable;
829757 }
830758 continue;
831759 },
......@@ -838,12 +766,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
838766
839767 State.MaybeLabeledExpression => |ctx| {
840768 if (eatToken(&tok_it, &tree, Token.Id.Colon)) |_| {
841 stack.append(State {
842 .LabeledExpression = LabelCtx {
843 .label = ctx.label,
844 .opt_ctx = ctx.opt_ctx,
845 }
846 }) catch unreachable;
769 stack.append(State{ .LabeledExpression = LabelCtx{
770 .label = ctx.label,
771 .opt_ctx = ctx.opt_ctx,
772 } }) catch unreachable;
847773 continue;
848774 }
849775
......@@ -856,69 +782,59 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
856782 const token_ptr = token.ptr;
857783 switch (token_ptr.id) {
858784 Token.Id.LBrace => {
859 const block = try arena.construct(ast.Node.Block {
860 .base = ast.Node {.id = ast.Node.Id.Block},
785 const block = try arena.construct(ast.Node.Block{
786 .base = ast.Node{ .id = ast.Node.Id.Block },
861787 .label = ctx.label,
862788 .lbrace = token_index,
863789 .statements = ast.Node.Block.StatementList.init(arena),
864790 .rbrace = undefined,
865791 });
866792 ctx.opt_ctx.store(&block.base);
867 stack.append(State { .Block = block }) catch unreachable;
793 stack.append(State{ .Block = block }) catch unreachable;
868794 continue;
869795 },
870796 Token.Id.Keyword_while => {
871 stack.append(State {
872 .While = LoopCtx {
873 .label = ctx.label,
874 .inline_token = null,
875 .loop_token = token_index,
876 .opt_ctx = ctx.opt_ctx.toRequired(),
877 }
878 }) catch unreachable;
797 stack.append(State{ .While = LoopCtx{
798 .label = ctx.label,
799 .inline_token = null,
800 .loop_token = token_index,
801 .opt_ctx = ctx.opt_ctx.toRequired(),
802 } }) catch unreachable;
879803 continue;
880804 },
881805 Token.Id.Keyword_for => {
882 stack.append(State {
883 .For = LoopCtx {
884 .label = ctx.label,
885 .inline_token = null,
886 .loop_token = token_index,
887 .opt_ctx = ctx.opt_ctx.toRequired(),
888 }
889 }) catch unreachable;
806 stack.append(State{ .For = LoopCtx{
807 .label = ctx.label,
808 .inline_token = null,
809 .loop_token = token_index,
810 .opt_ctx = ctx.opt_ctx.toRequired(),
811 } }) catch unreachable;
890812 continue;
891813 },
892814 Token.Id.Keyword_suspend => {
893 const node = try arena.construct(ast.Node.Suspend {
894 .base = ast.Node {
895 .id = ast.Node.Id.Suspend,
896 },
815 const node = try arena.construct(ast.Node.Suspend{
816 .base = ast.Node{ .id = ast.Node.Id.Suspend },
897817 .label = ctx.label,
898818 .suspend_token = token_index,
899819 .payload = null,
900820 .body = null,
901821 });
902822 ctx.opt_ctx.store(&node.base);
903 stack.append(State { .SuspendBody = node }) catch unreachable;
904 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
823 stack.append(State{ .SuspendBody = node }) catch unreachable;
824 try stack.append(State{ .Payload = OptionalCtx{ .Optional = &node.payload } });
905825 continue;
906826 },
907827 Token.Id.Keyword_inline => {
908 stack.append(State {
909 .Inline = InlineCtx {
910 .label = ctx.label,
911 .inline_token = token_index,
912 .opt_ctx = ctx.opt_ctx.toRequired(),
913 }
914 }) catch unreachable;
828 stack.append(State{ .Inline = InlineCtx{
829 .label = ctx.label,
830 .inline_token = token_index,
831 .opt_ctx = ctx.opt_ctx.toRequired(),
832 } }) catch unreachable;
915833 continue;
916834 },
917835 else => {
918836 if (ctx.opt_ctx != OptionalCtx.Optional) {
919 *(try tree.errors.addOne()) = Error {
920 .ExpectedLabelable = Error.ExpectedLabelable { .token = token_index },
921 };
837 ((try tree.errors.addOne())).* = Error{ .ExpectedLabelable = Error.ExpectedLabelable{ .token = token_index } };
922838 return tree;
923839 }
924840
......@@ -933,32 +849,26 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
933849 const token_ptr = token.ptr;
934850 switch (token_ptr.id) {
935851 Token.Id.Keyword_while => {
936 stack.append(State {
937 .While = LoopCtx {
938 .inline_token = ctx.inline_token,
939 .label = ctx.label,
940 .loop_token = token_index,
941 .opt_ctx = ctx.opt_ctx.toRequired(),
942 }
943 }) catch unreachable;
852 stack.append(State{ .While = LoopCtx{
853 .inline_token = ctx.inline_token,
854 .label = ctx.label,
855 .loop_token = token_index,
856 .opt_ctx = ctx.opt_ctx.toRequired(),
857 } }) catch unreachable;
944858 continue;
945859 },
946860 Token.Id.Keyword_for => {
947 stack.append(State {
948 .For = LoopCtx {
949 .inline_token = ctx.inline_token,
950 .label = ctx.label,
951 .loop_token = token_index,
952 .opt_ctx = ctx.opt_ctx.toRequired(),
953 }
954 }) catch unreachable;
861 stack.append(State{ .For = LoopCtx{
862 .inline_token = ctx.inline_token,
863 .label = ctx.label,
864 .loop_token = token_index,
865 .opt_ctx = ctx.opt_ctx.toRequired(),
866 } }) catch unreachable;
955867 continue;
956868 },
957869 else => {
958870 if (ctx.opt_ctx != OptionalCtx.Optional) {
959 *(try tree.errors.addOne()) = Error {
960 .ExpectedInlinable = Error.ExpectedInlinable { .token = token_index },
961 };
871 ((try tree.errors.addOne())).* = Error{ .ExpectedInlinable = Error.ExpectedInlinable{ .token = token_index } };
962872 return tree;
963873 }
964874
......@@ -968,8 +878,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
968878 }
969879 },
970880 State.While => |ctx| {
971 const node = try arena.construct(ast.Node.While {
972 .base = ast.Node {.id = ast.Node.Id.While },
881 const node = try arena.construct(ast.Node.While{
882 .base = ast.Node{ .id = ast.Node.Id.While },
973883 .label = ctx.label,
974884 .inline_token = ctx.inline_token,
975885 .while_token = ctx.loop_token,
......@@ -980,25 +890,25 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
980890 .@"else" = null,
981891 });
982892 ctx.opt_ctx.store(&node.base);
983 stack.append(State { .Else = &node.@"else" }) catch unreachable;
984 try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } });
985 try stack.append(State { .WhileContinueExpr = &node.continue_expr });
986 try stack.append(State { .IfToken = Token.Id.Colon });
987 try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
988 try stack.append(State { .ExpectToken = Token.Id.RParen });
989 try stack.append(State { .Expression = OptionalCtx { .Required = &node.condition } });
990 try stack.append(State { .ExpectToken = Token.Id.LParen });
893 stack.append(State{ .Else = &node.@"else" }) catch unreachable;
894 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } });
895 try stack.append(State{ .WhileContinueExpr = &node.continue_expr });
896 try stack.append(State{ .IfToken = Token.Id.Colon });
897 try stack.append(State{ .PointerPayload = OptionalCtx{ .Optional = &node.payload } });
898 try stack.append(State{ .ExpectToken = Token.Id.RParen });
899 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.condition } });
900 try stack.append(State{ .ExpectToken = Token.Id.LParen });
991901 continue;
992902 },
993903 State.WhileContinueExpr => |dest| {
994 stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
995 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .RequiredNull = dest } });
996 try stack.append(State { .ExpectToken = Token.Id.LParen });
904 stack.append(State{ .ExpectToken = Token.Id.RParen }) catch unreachable;
905 try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .RequiredNull = dest } });
906 try stack.append(State{ .ExpectToken = Token.Id.LParen });
997907 continue;
998908 },
999909 State.For => |ctx| {
1000 const node = try arena.construct(ast.Node.For {
1001 .base = ast.Node {.id = ast.Node.Id.For },
910 const node = try arena.construct(ast.Node.For{
911 .base = ast.Node{ .id = ast.Node.Id.For },
1002912 .label = ctx.label,
1003913 .inline_token = ctx.inline_token,
1004914 .for_token = ctx.loop_token,
......@@ -1008,33 +918,32 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1008918 .@"else" = null,
1009919 });
1010920 ctx.opt_ctx.store(&node.base);
1011 stack.append(State { .Else = &node.@"else" }) catch unreachable;
1012 try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } });
1013 try stack.append(State { .PointerIndexPayload = OptionalCtx { .Optional = &node.payload } });
1014 try stack.append(State { .ExpectToken = Token.Id.RParen });
1015 try stack.append(State { .Expression = OptionalCtx { .Required = &node.array_expr } });
1016 try stack.append(State { .ExpectToken = Token.Id.LParen });
921 stack.append(State{ .Else = &node.@"else" }) catch unreachable;
922 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } });
923 try stack.append(State{ .PointerIndexPayload = OptionalCtx{ .Optional = &node.payload } });
924 try stack.append(State{ .ExpectToken = Token.Id.RParen });
925 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.array_expr } });
926 try stack.append(State{ .ExpectToken = Token.Id.LParen });
1017927 continue;
1018928 },
1019929 State.Else => |dest| {
1020930 if (eatToken(&tok_it, &tree, Token.Id.Keyword_else)) |else_token| {
1021 const node = try arena.construct(ast.Node.Else {
1022 .base = ast.Node {.id = ast.Node.Id.Else },
931 const node = try arena.construct(ast.Node.Else{
932 .base = ast.Node{ .id = ast.Node.Id.Else },
1023933 .else_token = else_token,
1024934 .payload = null,
1025935 .body = undefined,
1026936 });
1027 *dest = node;
937 dest.* = node;
1028938
1029 stack.append(State { .Expression = OptionalCtx { .Required = &node.body } }) catch unreachable;
1030 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
939 stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } }) catch unreachable;
940 try stack.append(State{ .Payload = OptionalCtx{ .Optional = &node.payload } });
1031941 continue;
1032942 } else {
1033943 continue;
1034944 }
1035945 },
1036946
1037
1038947 State.Block => |block| {
1039948 const token = nextToken(&tok_it, &tree);
1040949 const token_index = token.index;
......@@ -1046,7 +955,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1046955 },
1047956 else => {
1048957 putBackToken(&tok_it, &tree);
1049 stack.append(State { .Block = block }) catch unreachable;
958 stack.append(State{ .Block = block }) catch unreachable;
1050959
1051960 var any_comments = false;
1052961 while (try eatLineComment(arena, &tok_it, &tree)) |line_comment| {
......@@ -1055,7 +964,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1055964 }
1056965 if (any_comments) continue;
1057966
1058 try stack.append(State { .Statement = block });
967 try stack.append(State{ .Statement = block });
1059968 continue;
1060969 },
1061970 }
......@@ -1066,33 +975,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
1066975 const token_ptr = token.ptr;
1067976 switch (token_ptr.id) {
1068977 Token.Id.Keyword_comptime => {
1069 stack.append(State {
1070 .ComptimeStatement = ComptimeStatementCtx {
1071 .comptime_token = token_index,
1072 .block = block,
1073 }
1074 }) catch unreachable;
1075 continue;
1076 },
1077 Token.Id.Keyword_var, Token.Id.Keyword_const => {
1078 stack.append(State {
1079 .VarDecl = VarDeclCtx {
1080 .comments = null,
1081 .visib_token = null,
1082 .comptime_token = null,
1083 .extern_export_token = null,
1084 .lib_name = null,
1085 .mut_token = token_index,
1086 .list = &block.statements,
1087 }
1088 }) catch unreachable;
978 stack.append(State{ .ComptimeStatement = ComptimeStatementCtx{
979 .comptime_token = token_index,
980 .block = block,
981 } }) catch unreachable;
1089982 continue;
1090983 },
1091 Token.Id.Keyword_defer, Token.Id.Keyword_errdefer => {
1092 const node = try arena.construct(ast.Node.Defer {
1093 .base = ast.Node {
1094 .id = ast.Node.Id.Defer,
1095 },
984 Token.Id.Keyword_var,
985 Token.Id.Keyword_const => {
986 stack.append(State{ .VarDecl = VarDeclCtx{
987 .comments = null,
988 .visib_token = null,
989 .comptime_token = null,
990 .extern_export_token = null,
991 .lib_name = null,
992 .mut_token = token_index,
993 .list = &block.statements,
994 } }) catch unreachable;
995 continue;
996 },
997 Token.Id.Keyword_defer,
998 Token.Id.Keyword_errdefer => {
999 const node = try arena.construct(ast.Node.Defer{
1000 .base = ast.Node{ .id = ast.Node.Id.Defer },
10961001 .defer_token = token_index,
10971002 .kind = switch (token_ptr.id) {
10981003 Token.Id.Keyword_defer => ast.Node.Defer.Kind.Unconditional,
......@@ -1102,15 +1007,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11021007 .expr = undefined,
11031008 });
11041009 const node_ptr = try block.statements.addOne();
1105 *node_ptr = &node.base;
1010 node_ptr.* = &node.base;
11061011
1107 stack.append(State { .Semicolon = node_ptr }) catch unreachable;
1108 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } });
1012 stack.append(State{ .Semicolon = node_ptr }) catch unreachable;
1013 try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } });
11091014 continue;
11101015 },
11111016 Token.Id.LBrace => {
1112 const inner_block = try arena.construct(ast.Node.Block {
1113 .base = ast.Node { .id = ast.Node.Id.Block },
1017 const inner_block = try arena.construct(ast.Node.Block{
1018 .base = ast.Node{ .id = ast.Node.Id.Block },
11141019 .label = null,
11151020 .lbrace = token_index,
11161021 .statements = ast.Node.Block.StatementList.init(arena),
......@@ -1118,16 +1023,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11181023 });
11191024 try block.statements.push(&inner_block.base);
11201025
1121 stack.append(State { .Block = inner_block }) catch unreachable;
1026 stack.append(State{ .Block = inner_block }) catch unreachable;
11221027 continue;
11231028 },
11241029 else => {
11251030 putBackToken(&tok_it, &tree);
11261031 const statement = try block.statements.addOne();
1127 try stack.append(State { .Semicolon = statement });
1128 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx{ .Required = statement } });
1032 try stack.append(State{ .Semicolon = statement });
1033 try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = statement } });
11291034 continue;
1130 }
1035 },
11311036 }
11321037 },
11331038 State.ComptimeStatement => |ctx| {
......@@ -1135,34 +1040,33 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11351040 const token_index = token.index;
11361041 const token_ptr = token.ptr;
11371042 switch (token_ptr.id) {
1138 Token.Id.Keyword_var, Token.Id.Keyword_const => {
1139 stack.append(State {
1140 .VarDecl = VarDeclCtx {
1141 .comments = null,
1142 .visib_token = null,
1143 .comptime_token = ctx.comptime_token,
1144 .extern_export_token = null,
1145 .lib_name = null,
1146 .mut_token = token_index,
1147 .list = &ctx.block.statements,
1148 }
1149 }) catch unreachable;
1043 Token.Id.Keyword_var,
1044 Token.Id.Keyword_const => {
1045 stack.append(State{ .VarDecl = VarDeclCtx{
1046 .comments = null,
1047 .visib_token = null,
1048 .comptime_token = ctx.comptime_token,
1049 .extern_export_token = null,
1050 .lib_name = null,
1051 .mut_token = token_index,
1052 .list = &ctx.block.statements,
1053 } }) catch unreachable;
11501054 continue;
11511055 },
11521056 else => {
11531057 putBackToken(&tok_it, &tree);
11541058 putBackToken(&tok_it, &tree);
11551059 const statement = try ctx.block.statements.addOne();
1156 try stack.append(State { .Semicolon = statement });
1157 try stack.append(State { .Expression = OptionalCtx { .Required = statement } });
1060 try stack.append(State{ .Semicolon = statement });
1061 try stack.append(State{ .Expression = OptionalCtx{ .Required = statement } });
11581062 continue;
1159 }
1063 },
11601064 }
11611065 },
11621066 State.Semicolon => |node_ptr| {
1163 const node = *node_ptr;
1067 const node = node_ptr.*;
11641068 if (node.requireSemiColon()) {
1165 stack.append(State { .ExpectToken = Token.Id.Semicolon }) catch unreachable;
1069 stack.append(State{ .ExpectToken = Token.Id.Semicolon }) catch unreachable;
11661070 continue;
11671071 }
11681072 continue;
......@@ -1177,22 +1081,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
11771081 continue;
11781082 }
11791083
1180 const node = try arena.construct(ast.Node.AsmOutput {
1181 .base = ast.Node {.id = ast.Node.Id.AsmOutput },
1084 const node = try arena.construct(ast.Node.AsmOutput{
1085 .base = ast.Node{ .id = ast.Node.Id.AsmOutput },
11821086 .symbolic_name = undefined,
11831087 .constraint = undefined,
11841088 .kind = undefined,
11851089 });
11861090 try items.push(node);
11871091
1188 stack.append(State { .AsmOutputItems = items }) catch unreachable;
1189 try stack.append(State { .IfToken = Token.Id.Comma });
1190 try stack.append(State { .ExpectToken = Token.Id.RParen });
1191 try stack.append(State { .AsmOutputReturnOrType = node });
1192 try stack.append(State { .ExpectToken = Token.Id.LParen });
1193 try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.constraint } });
1194 try stack.append(State { .ExpectToken = Token.Id.RBracket });
1195 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.symbolic_name } });
1092 stack.append(State{ .AsmOutputItems = items }) catch unreachable;
1093 try stack.append(State{ .IfToken = Token.Id.Comma });
1094 try stack.append(State{ .ExpectToken = Token.Id.RParen });
1095 try stack.append(State{ .AsmOutputReturnOrType = node });
1096 try stack.append(State{ .ExpectToken = Token.Id.LParen });
1097 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.constraint } });
1098 try stack.append(State{ .ExpectToken = Token.Id.RBracket });
1099 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.symbolic_name } });
11961100 continue;
11971101 },
11981102 State.AsmOutputReturnOrType => |node| {
......@@ -1201,20 +1105,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12011105 const token_ptr = token.ptr;
12021106 switch (token_ptr.id) {
12031107 Token.Id.Identifier => {
1204 node.kind = ast.Node.AsmOutput.Kind { .Variable = try createLiteral(arena, ast.Node.Identifier, token_index) };
1108 node.kind = ast.Node.AsmOutput.Kind{ .Variable = try createLiteral(arena, ast.Node.Identifier, token_index) };
12051109 continue;
12061110 },
12071111 Token.Id.Arrow => {
1208 node.kind = ast.Node.AsmOutput.Kind { .Return = undefined };
1209 try stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.kind.Return } });
1112 node.kind = ast.Node.AsmOutput.Kind{ .Return = undefined };
1113 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.kind.Return } });
12101114 continue;
12111115 },
12121116 else => {
1213 *(try tree.errors.addOne()) = Error {
1214 .ExpectedAsmOutputReturnOrType = Error.ExpectedAsmOutputReturnOrType {
1215 .token = token_index,
1216 },
1217 };
1117 ((try tree.errors.addOne())).* = Error{ .ExpectedAsmOutputReturnOrType = Error.ExpectedAsmOutputReturnOrType{ .token = token_index } };
12181118 return tree;
12191119 },
12201120 }
......@@ -1228,49 +1128,48 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12281128 continue;
12291129 }
12301130
1231 const node = try arena.construct(ast.Node.AsmInput {
1232 .base = ast.Node {.id = ast.Node.Id.AsmInput },
1131 const node = try arena.construct(ast.Node.AsmInput{
1132 .base = ast.Node{ .id = ast.Node.Id.AsmInput },
12331133 .symbolic_name = undefined,
12341134 .constraint = undefined,
12351135 .expr = undefined,
12361136 });
12371137 try items.push(node);
12381138
1239 stack.append(State { .AsmInputItems = items }) catch unreachable;
1240 try stack.append(State { .IfToken = Token.Id.Comma });
1241 try stack.append(State { .ExpectToken = Token.Id.RParen });
1242 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
1243 try stack.append(State { .ExpectToken = Token.Id.LParen });
1244 try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.constraint } });
1245 try stack.append(State { .ExpectToken = Token.Id.RBracket });
1246 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.symbolic_name } });
1139 stack.append(State{ .AsmInputItems = items }) catch unreachable;
1140 try stack.append(State{ .IfToken = Token.Id.Comma });
1141 try stack.append(State{ .ExpectToken = Token.Id.RParen });
1142 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
1143 try stack.append(State{ .ExpectToken = Token.Id.LParen });
1144 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.constraint } });
1145 try stack.append(State{ .ExpectToken = Token.Id.RBracket });
1146 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.symbolic_name } });
12471147 continue;
12481148 },
12491149 State.AsmClobberItems => |items| {
1250 stack.append(State { .AsmClobberItems = items }) catch unreachable;
1251 try stack.append(State { .IfToken = Token.Id.Comma });
1252 try stack.append(State { .StringLiteral = OptionalCtx { .Required = try items.addOne() } });
1150 stack.append(State{ .AsmClobberItems = items }) catch unreachable;
1151 try stack.append(State{ .IfToken = Token.Id.Comma });
1152 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = try items.addOne() } });
12531153 continue;
12541154 },
12551155
1256
12571156 State.ExprListItemOrEnd => |list_state| {
12581157 if (eatToken(&tok_it, &tree, list_state.end)) |token_index| {
1259 *list_state.ptr = token_index;
1158 (list_state.ptr).* = token_index;
12601159 continue;
12611160 }
12621161
1263 stack.append(State { .ExprListCommaOrEnd = list_state }) catch unreachable;
1264 try stack.append(State { .Expression = OptionalCtx { .Required = try list_state.list.addOne() } });
1162 stack.append(State{ .ExprListCommaOrEnd = list_state }) catch unreachable;
1163 try stack.append(State{ .Expression = OptionalCtx{ .Required = try list_state.list.addOne() } });
12651164 continue;
12661165 },
12671166 State.ExprListCommaOrEnd => |list_state| {
12681167 switch (expectCommaOrEnd(&tok_it, &tree, list_state.end)) {
12691168 ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| {
1270 *list_state.ptr = end;
1169 (list_state.ptr).* = end;
12711170 continue;
12721171 } else {
1273 stack.append(State { .ExprListItemOrEnd = list_state }) catch unreachable;
1172 stack.append(State{ .ExprListItemOrEnd = list_state }) catch unreachable;
12741173 continue;
12751174 },
12761175 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1285,44 +1184,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
12851184 }
12861185
12871186 if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| {
1288 *list_state.ptr = rbrace;
1187 (list_state.ptr).* = rbrace;
12891188 continue;
12901189 }
12911190
1292 const node = try arena.construct(ast.Node.FieldInitializer {
1293 .base = ast.Node {
1294 .id = ast.Node.Id.FieldInitializer,
1295 },
1191 const node = try arena.construct(ast.Node.FieldInitializer{
1192 .base = ast.Node{ .id = ast.Node.Id.FieldInitializer },
12961193 .period_token = undefined,
12971194 .name_token = undefined,
12981195 .expr = undefined,
12991196 });
13001197 try list_state.list.push(&node.base);
13011198
1302 stack.append(State { .FieldInitListCommaOrEnd = list_state }) catch unreachable;
1303 try stack.append(State { .Expression = OptionalCtx{ .Required = &node.expr } });
1304 try stack.append(State { .ExpectToken = Token.Id.Equal });
1305 try stack.append(State {
1306 .ExpectTokenSave = ExpectTokenSave {
1307 .id = Token.Id.Identifier,
1308 .ptr = &node.name_token,
1309 }
1310 });
1311 try stack.append(State {
1312 .ExpectTokenSave = ExpectTokenSave {
1313 .id = Token.Id.Period,
1314 .ptr = &node.period_token,
1315 }
1316 });
1199 stack.append(State{ .FieldInitListCommaOrEnd = list_state }) catch unreachable;
1200 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
1201 try stack.append(State{ .ExpectToken = Token.Id.Equal });
1202 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1203 .id = Token.Id.Identifier,
1204 .ptr = &node.name_token,
1205 } });
1206 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1207 .id = Token.Id.Period,
1208 .ptr = &node.period_token,
1209 } });
13171210 continue;
13181211 },
13191212 State.FieldInitListCommaOrEnd => |list_state| {
13201213 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) {
13211214 ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| {
1322 *list_state.ptr = end;
1215 (list_state.ptr).* = end;
13231216 continue;
13241217 } else {
1325 stack.append(State { .FieldInitListItemOrEnd = list_state }) catch unreachable;
1218 stack.append(State{ .FieldInitListItemOrEnd = list_state }) catch unreachable;
13261219 continue;
13271220 },
13281221 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1337,7 +1230,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13371230 container_decl.rbrace_token = end;
13381231 continue;
13391232 } else {
1340 try stack.append(State { .ContainerDecl = container_decl });
1233 try stack.append(State{ .ContainerDecl = container_decl });
13411234 continue;
13421235 },
13431236 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1352,23 +1245,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13521245 }
13531246
13541247 if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| {
1355 *list_state.ptr = rbrace;
1248 (list_state.ptr).* = rbrace;
13561249 continue;
13571250 }
13581251
13591252 const node_ptr = try list_state.list.addOne();
13601253
1361 try stack.append(State { .ErrorTagListCommaOrEnd = list_state });
1362 try stack.append(State { .ErrorTag = node_ptr });
1254 try stack.append(State{ .ErrorTagListCommaOrEnd = list_state });
1255 try stack.append(State{ .ErrorTag = node_ptr });
13631256 continue;
13641257 },
13651258 State.ErrorTagListCommaOrEnd => |list_state| {
13661259 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RBrace)) {
13671260 ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| {
1368 *list_state.ptr = end;
1261 (list_state.ptr).* = end;
13691262 continue;
13701263 } else {
1371 stack.append(State { .ErrorTagListItemOrEnd = list_state }) catch unreachable;
1264 stack.append(State{ .ErrorTagListItemOrEnd = list_state }) catch unreachable;
13721265 continue;
13731266 },
13741267 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1383,24 +1276,22 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
13831276 }
13841277
13851278 if (eatToken(&tok_it, &tree, Token.Id.RBrace)) |rbrace| {
1386 *list_state.ptr = rbrace;
1279 (list_state.ptr).* = rbrace;
13871280 continue;
13881281 }
13891282
13901283 const comments = try eatDocComments(arena, &tok_it, &tree);
1391 const node = try arena.construct(ast.Node.SwitchCase {
1392 .base = ast.Node {
1393 .id = ast.Node.Id.SwitchCase,
1394 },
1284 const node = try arena.construct(ast.Node.SwitchCase{
1285 .base = ast.Node{ .id = ast.Node.Id.SwitchCase },
13951286 .items = ast.Node.SwitchCase.ItemList.init(arena),
13961287 .payload = null,
13971288 .expr = undefined,
13981289 });
13991290 try list_state.list.push(&node.base);
1400 try stack.append(State { .SwitchCaseCommaOrEnd = list_state });
1401 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .Required = &node.expr } });
1402 try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
1403 try stack.append(State { .SwitchCaseFirstItem = &node.items });
1291 try stack.append(State{ .SwitchCaseCommaOrEnd = list_state });
1292 try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .Required = &node.expr } });
1293 try stack.append(State{ .PointerPayload = OptionalCtx{ .Optional = &node.payload } });
1294 try stack.append(State{ .SwitchCaseFirstItem = &node.items });
14041295
14051296 continue;
14061297 },
......@@ -1408,10 +1299,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14081299 State.SwitchCaseCommaOrEnd => |list_state| {
14091300 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.RParen)) {
14101301 ExpectCommaOrEndResult.end_token => |maybe_end| if (maybe_end) |end| {
1411 *list_state.ptr = end;
1302 (list_state.ptr).* = end;
14121303 continue;
14131304 } else {
1414 try stack.append(State { .SwitchCaseOrEnd = list_state });
1305 try stack.append(State{ .SwitchCaseOrEnd = list_state });
14151306 continue;
14161307 },
14171308 ExpectCommaOrEndResult.parse_error => |e| {
......@@ -1426,29 +1317,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14261317 const token_index = token.index;
14271318 const token_ptr = token.ptr;
14281319 if (token_ptr.id == Token.Id.Keyword_else) {
1429 const else_node = try arena.construct(ast.Node.SwitchElse {
1430 .base = ast.Node{ .id = ast.Node.Id.SwitchElse},
1320 const else_node = try arena.construct(ast.Node.SwitchElse{
1321 .base = ast.Node{ .id = ast.Node.Id.SwitchElse },
14311322 .token = token_index,
14321323 });
14331324 try case_items.push(&else_node.base);
14341325
1435 try stack.append(State { .ExpectToken = Token.Id.EqualAngleBracketRight });
1326 try stack.append(State{ .ExpectToken = Token.Id.EqualAngleBracketRight });
14361327 continue;
14371328 } else {
14381329 putBackToken(&tok_it, &tree);
1439 try stack.append(State { .SwitchCaseItem = case_items });
1330 try stack.append(State{ .SwitchCaseItem = case_items });
14401331 continue;
14411332 }
14421333 },
14431334 State.SwitchCaseItem => |case_items| {
1444 stack.append(State { .SwitchCaseItemCommaOrEnd = case_items }) catch unreachable;
1445 try stack.append(State { .RangeExpressionBegin = OptionalCtx { .Required = try case_items.addOne() } });
1335 stack.append(State{ .SwitchCaseItemCommaOrEnd = case_items }) catch unreachable;
1336 try stack.append(State{ .RangeExpressionBegin = OptionalCtx{ .Required = try case_items.addOne() } });
14461337 },
14471338 State.SwitchCaseItemCommaOrEnd => |case_items| {
14481339 switch (expectCommaOrEnd(&tok_it, &tree, Token.Id.EqualAngleBracketRight)) {
14491340 ExpectCommaOrEndResult.end_token => |t| {
14501341 if (t == null) {
1451 stack.append(State { .SwitchCaseItem = case_items }) catch unreachable;
1342 stack.append(State{ .SwitchCaseItem = case_items }) catch unreachable;
14521343 }
14531344 continue;
14541345 },
......@@ -1460,10 +1351,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14601351 continue;
14611352 },
14621353
1463
14641354 State.SuspendBody => |suspend_node| {
14651355 if (suspend_node.payload != null) {
1466 try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .RequiredNull = &suspend_node.body } });
1356 try stack.append(State{ .AssignmentExpressionBegin = OptionalCtx{ .RequiredNull = &suspend_node.body } });
14671357 }
14681358 continue;
14691359 },
......@@ -1473,13 +1363,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14731363 }
14741364
14751365 async_node.rangle_bracket = TokenIndex(0);
1476 try stack.append(State {
1477 .ExpectTokenSave = ExpectTokenSave {
1478 .id = Token.Id.AngleBracketRight,
1479 .ptr = &??async_node.rangle_bracket,
1480 }
1481 });
1482 try stack.append(State { .TypeExprBegin = OptionalCtx { .RequiredNull = &async_node.allocator_type } });
1366 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1367 .id = Token.Id.AngleBracketRight,
1368 .ptr = &??async_node.rangle_bracket,
1369 } });
1370 try stack.append(State{ .TypeExprBegin = OptionalCtx{ .RequiredNull = &async_node.allocator_type } });
14831371 continue;
14841372 },
14851373 State.AsyncEnd => |ctx| {
......@@ -1498,27 +1386,20 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
14981386 continue;
14991387 }
15001388
1501 *(try tree.errors.addOne()) = Error {
1502 .ExpectedCall = Error.ExpectedCall { .node = node },
1503 };
1389 ((try tree.errors.addOne())).* = Error{ .ExpectedCall = Error.ExpectedCall{ .node = node } };
15041390 return tree;
15051391 },
15061392 else => {
1507 *(try tree.errors.addOne()) = Error {
1508 .ExpectedCallOrFnProto = Error.ExpectedCallOrFnProto { .node = node },
1509 };
1393 ((try tree.errors.addOne())).* = Error{ .ExpectedCallOrFnProto = Error.ExpectedCallOrFnProto{ .node = node } };
15101394 return tree;
1511 }
1395 },
15121396 }
15131397 },
15141398
1515
15161399 State.ExternType => |ctx| {
15171400 if (eatToken(&tok_it, &tree, Token.Id.Keyword_fn)) |fn_token| {
1518 const fn_proto = try arena.construct(ast.Node.FnProto {
1519 .base = ast.Node {
1520 .id = ast.Node.Id.FnProto,
1521 },
1401 const fn_proto = try arena.construct(ast.Node.FnProto{
1402 .base = ast.Node{ .id = ast.Node.Id.FnProto },
15221403 .doc_comments = ctx.comments,
15231404 .visib_token = null,
15241405 .name_token = null,
......@@ -1534,17 +1415,15 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15341415 .align_expr = null,
15351416 });
15361417 ctx.opt_ctx.store(&fn_proto.base);
1537 stack.append(State { .FnProto = fn_proto }) catch unreachable;
1418 stack.append(State{ .FnProto = fn_proto }) catch unreachable;
15381419 continue;
15391420 }
15401421
1541 stack.append(State {
1542 .ContainerKind = ContainerKindCtx {
1543 .opt_ctx = ctx.opt_ctx,
1544 .ltoken = ctx.extern_token,
1545 .layout = ast.Node.ContainerDecl.Layout.Extern,
1546 },
1547 }) catch unreachable;
1422 stack.append(State{ .ContainerKind = ContainerKindCtx{
1423 .opt_ctx = ctx.opt_ctx,
1424 .ltoken = ctx.extern_token,
1425 .layout = ast.Node.ContainerDecl.Layout.Extern,
1426 } }) catch unreachable;
15481427 continue;
15491428 },
15501429 State.SliceOrArrayAccess => |node| {
......@@ -1554,20 +1433,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15541433 switch (token_ptr.id) {
15551434 Token.Id.Ellipsis2 => {
15561435 const start = node.op.ArrayAccess;
1557 node.op = ast.Node.SuffixOp.Op {
1558 .Slice = ast.Node.SuffixOp.Op.Slice {
1559 .start = start,
1560 .end = null,
1561 }
1562 };
1436 node.op = ast.Node.SuffixOp.Op{ .Slice = ast.Node.SuffixOp.Op.Slice{
1437 .start = start,
1438 .end = null,
1439 } };
15631440
1564 stack.append(State {
1565 .ExpectTokenSave = ExpectTokenSave {
1566 .id = Token.Id.RBracket,
1567 .ptr = &node.rtoken,
1568 }
1569 }) catch unreachable;
1570 try stack.append(State { .Expression = OptionalCtx { .Optional = &node.op.Slice.end } });
1441 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1442 .id = Token.Id.RBracket,
1443 .ptr = &node.rtoken,
1444 } }) catch unreachable;
1445 try stack.append(State{ .Expression = OptionalCtx{ .Optional = &node.op.Slice.end } });
15711446 continue;
15721447 },
15731448 Token.Id.RBracket => {
......@@ -1575,33 +1450,29 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
15751450 continue;
15761451 },
15771452 else => {
1578 *(try tree.errors.addOne()) = Error {
1579 .ExpectedSliceOrRBracket = Error.ExpectedSliceOrRBracket { .token = token_index },
1580 };
1453 ((try tree.errors.addOne())).* = Error{ .ExpectedSliceOrRBracket = Error.ExpectedSliceOrRBracket{ .token = token_index } };
15811454 return tree;
1582 }
1455 },
15831456 }
15841457 },
15851458 State.SliceOrArrayType => |node| {
15861459 if (eatToken(&tok_it, &tree, Token.Id.RBracket)) |_| {
1587 node.op = ast.Node.PrefixOp.Op {
1588 .SliceType = ast.Node.PrefixOp.AddrOfInfo {
1589 .align_expr = null,
1590 .bit_offset_start_token = null,
1591 .bit_offset_end_token = null,
1592 .const_token = null,
1593 .volatile_token = null,
1594 }
1595 };
1596 stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1597 try stack.append(State { .AddrOfModifiers = &node.op.SliceType });
1460 node.op = ast.Node.PrefixOp.Op{ .SliceType = ast.Node.PrefixOp.AddrOfInfo{
1461 .align_expr = null,
1462 .bit_offset_start_token = null,
1463 .bit_offset_end_token = null,
1464 .const_token = null,
1465 .volatile_token = null,
1466 } };
1467 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
1468 try stack.append(State{ .AddrOfModifiers = &node.op.SliceType });
15981469 continue;
15991470 }
16001471
1601 node.op = ast.Node.PrefixOp.Op { .ArrayType = undefined };
1602 stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1603 try stack.append(State { .ExpectToken = Token.Id.RBracket });
1604 try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayType } });
1472 node.op = ast.Node.PrefixOp.Op{ .ArrayType = undefined };
1473 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
1474 try stack.append(State{ .ExpectToken = Token.Id.RBracket });
1475 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.op.ArrayType } });
16051476 continue;
16061477 },
16071478 State.AddrOfModifiers => |addr_of_info| {
......@@ -1612,22 +1483,18 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16121483 Token.Id.Keyword_align => {
16131484 stack.append(state) catch unreachable;
16141485 if (addr_of_info.align_expr != null) {
1615 *(try tree.errors.addOne()) = Error {
1616 .ExtraAlignQualifier = Error.ExtraAlignQualifier { .token = token_index },
1617 };
1486 ((try tree.errors.addOne())).* = Error{ .ExtraAlignQualifier = Error.ExtraAlignQualifier{ .token = token_index } };
16181487 return tree;
16191488 }
1620 try stack.append(State { .ExpectToken = Token.Id.RParen });
1621 try stack.append(State { .Expression = OptionalCtx { .RequiredNull = &addr_of_info.align_expr} });
1622 try stack.append(State { .ExpectToken = Token.Id.LParen });
1489 try stack.append(State{ .ExpectToken = Token.Id.RParen });
1490 try stack.append(State{ .Expression = OptionalCtx{ .RequiredNull = &addr_of_info.align_expr } });
1491 try stack.append(State{ .ExpectToken = Token.Id.LParen });
16231492 continue;
16241493 },
16251494 Token.Id.Keyword_const => {
16261495 stack.append(state) catch unreachable;
16271496 if (addr_of_info.const_token != null) {
1628 *(try tree.errors.addOne()) = Error {
1629 .ExtraConstQualifier = Error.ExtraConstQualifier { .token = token_index },
1630 };
1497 ((try tree.errors.addOne())).* = Error{ .ExtraConstQualifier = Error.ExtraConstQualifier{ .token = token_index } };
16311498 return tree;
16321499 }
16331500 addr_of_info.const_token = token_index;
......@@ -1636,9 +1503,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16361503 Token.Id.Keyword_volatile => {
16371504 stack.append(state) catch unreachable;
16381505 if (addr_of_info.volatile_token != null) {
1639 *(try tree.errors.addOne()) = Error {
1640 .ExtraVolatileQualifier = Error.ExtraVolatileQualifier { .token = token_index },
1641 };
1506 ((try tree.errors.addOne())).* = Error{ .ExtraVolatileQualifier = Error.ExtraVolatileQualifier{ .token = token_index } };
16421507 return tree;
16431508 }
16441509 addr_of_info.volatile_token = token_index;
......@@ -1651,19 +1516,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16511516 }
16521517 },
16531518
1654
16551519 State.Payload => |opt_ctx| {
16561520 const token = nextToken(&tok_it, &tree);
16571521 const token_index = token.index;
16581522 const token_ptr = token.ptr;
16591523 if (token_ptr.id != Token.Id.Pipe) {
16601524 if (opt_ctx != OptionalCtx.Optional) {
1661 *(try tree.errors.addOne()) = Error {
1662 .ExpectedToken = Error.ExpectedToken {
1663 .token = token_index,
1664 .expected_id = Token.Id.Pipe,
1665 },
1666 };
1525 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
1526 .token = token_index,
1527 .expected_id = Token.Id.Pipe,
1528 } };
16671529 return tree;
16681530 }
16691531
......@@ -1671,21 +1533,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16711533 continue;
16721534 }
16731535
1674 const node = try arena.construct(ast.Node.Payload {
1675 .base = ast.Node {.id = ast.Node.Id.Payload },
1536 const node = try arena.construct(ast.Node.Payload{
1537 .base = ast.Node{ .id = ast.Node.Id.Payload },
16761538 .lpipe = token_index,
16771539 .error_symbol = undefined,
1678 .rpipe = undefined
1540 .rpipe = undefined,
16791541 });
16801542 opt_ctx.store(&node.base);
16811543
1682 stack.append(State {
1683 .ExpectTokenSave = ExpectTokenSave {
1684 .id = Token.Id.Pipe,
1685 .ptr = &node.rpipe,
1686 }
1687 }) catch unreachable;
1688 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.error_symbol } });
1544 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1545 .id = Token.Id.Pipe,
1546 .ptr = &node.rpipe,
1547 } }) catch unreachable;
1548 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.error_symbol } });
16891549 continue;
16901550 },
16911551 State.PointerPayload => |opt_ctx| {
......@@ -1694,12 +1554,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
16941554 const token_ptr = token.ptr;
16951555 if (token_ptr.id != Token.Id.Pipe) {
16961556 if (opt_ctx != OptionalCtx.Optional) {
1697 *(try tree.errors.addOne()) = Error {
1698 .ExpectedToken = Error.ExpectedToken {
1699 .token = token_index,
1700 .expected_id = Token.Id.Pipe,
1701 },
1702 };
1557 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
1558 .token = token_index,
1559 .expected_id = Token.Id.Pipe,
1560 } };
17031561 return tree;
17041562 }
17051563
......@@ -1707,28 +1565,24 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
17071565 continue;
17081566 }
17091567
1710 const node = try arena.construct(ast.Node.PointerPayload {
1711 .base = ast.Node {.id = ast.Node.Id.PointerPayload },
1568 const node = try arena.construct(ast.Node.PointerPayload{
1569 .base = ast.Node{ .id = ast.Node.Id.PointerPayload },
17121570 .lpipe = token_index,
17131571 .ptr_token = null,
17141572 .value_symbol = undefined,
1715 .rpipe = undefined
1573 .rpipe = undefined,
17161574 });
17171575 opt_ctx.store(&node.base);
17181576
1719 try stack.append(State {
1720 .ExpectTokenSave = ExpectTokenSave {
1721 .id = Token.Id.Pipe,
1722 .ptr = &node.rpipe,
1723 }
1724 });
1725 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } });
1726 try stack.append(State {
1727 .OptionalTokenSave = OptionalTokenSave {
1728 .id = Token.Id.Asterisk,
1729 .ptr = &node.ptr_token,
1730 }
1731 });
1577 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1578 .id = Token.Id.Pipe,
1579 .ptr = &node.rpipe,
1580 } });
1581 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.value_symbol } });
1582 try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{
1583 .id = Token.Id.Asterisk,
1584 .ptr = &node.ptr_token,
1585 } });
17321586 continue;
17331587 },
17341588 State.PointerIndexPayload => |opt_ctx| {
......@@ -1737,12 +1591,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
17371591 const token_ptr = token.ptr;
17381592 if (token_ptr.id != Token.Id.Pipe) {
17391593 if (opt_ctx != OptionalCtx.Optional) {
1740 *(try tree.errors.addOne()) = Error {
1741 .ExpectedToken = Error.ExpectedToken {
1742 .token = token_index,
1743 .expected_id = Token.Id.Pipe,
1744 },
1745 };
1594 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
1595 .token = token_index,
1596 .expected_id = Token.Id.Pipe,
1597 } };
17461598 return tree;
17471599 }
17481600
......@@ -1750,61 +1602,58 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
17501602 continue;
17511603 }
17521604
1753 const node = try arena.construct(ast.Node.PointerIndexPayload {
1754 .base = ast.Node {.id = ast.Node.Id.PointerIndexPayload },
1605 const node = try arena.construct(ast.Node.PointerIndexPayload{
1606 .base = ast.Node{ .id = ast.Node.Id.PointerIndexPayload },
17551607 .lpipe = token_index,
17561608 .ptr_token = null,
17571609 .value_symbol = undefined,
17581610 .index_symbol = null,
1759 .rpipe = undefined
1611 .rpipe = undefined,
17601612 });
17611613 opt_ctx.store(&node.base);
17621614
1763 stack.append(State {
1764 .ExpectTokenSave = ExpectTokenSave {
1765 .id = Token.Id.Pipe,
1766 .ptr = &node.rpipe,
1767 }
1768 }) catch unreachable;
1769 try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.index_symbol } });
1770 try stack.append(State { .IfToken = Token.Id.Comma });
1771 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.value_symbol } });
1772 try stack.append(State {
1773 .OptionalTokenSave = OptionalTokenSave {
1774 .id = Token.Id.Asterisk,
1775 .ptr = &node.ptr_token,
1776 }
1777 });
1615 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
1616 .id = Token.Id.Pipe,
1617 .ptr = &node.rpipe,
1618 } }) catch unreachable;
1619 try stack.append(State{ .Identifier = OptionalCtx{ .RequiredNull = &node.index_symbol } });
1620 try stack.append(State{ .IfToken = Token.Id.Comma });
1621 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.value_symbol } });
1622 try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{
1623 .id = Token.Id.Asterisk,
1624 .ptr = &node.ptr_token,
1625 } });
17781626 continue;
17791627 },
17801628
1781
17821629 State.Expression => |opt_ctx| {
17831630 const token = nextToken(&tok_it, &tree);
17841631 const token_index = token.index;
17851632 const token_ptr = token.ptr;
17861633 switch (token_ptr.id) {
1787 Token.Id.Keyword_return, Token.Id.Keyword_break, Token.Id.Keyword_continue => {
1788 const node = try arena.construct(ast.Node.ControlFlowExpression {
1789 .base = ast.Node {.id = ast.Node.Id.ControlFlowExpression },
1634 Token.Id.Keyword_return,
1635 Token.Id.Keyword_break,
1636 Token.Id.Keyword_continue => {
1637 const node = try arena.construct(ast.Node.ControlFlowExpression{
1638 .base = ast.Node{ .id = ast.Node.Id.ControlFlowExpression },
17901639 .ltoken = token_index,
17911640 .kind = undefined,
17921641 .rhs = null,
17931642 });
17941643 opt_ctx.store(&node.base);
17951644
1796 stack.append(State { .Expression = OptionalCtx { .Optional = &node.rhs } }) catch unreachable;
1645 stack.append(State{ .Expression = OptionalCtx{ .Optional = &node.rhs } }) catch unreachable;
17971646
17981647 switch (token_ptr.id) {
17991648 Token.Id.Keyword_break => {
1800 node.kind = ast.Node.ControlFlowExpression.Kind { .Break = null };
1801 try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.kind.Break } });
1802 try stack.append(State { .IfToken = Token.Id.Colon });
1649 node.kind = ast.Node.ControlFlowExpression.Kind{ .Break = null };
1650 try stack.append(State{ .Identifier = OptionalCtx{ .RequiredNull = &node.kind.Break } });
1651 try stack.append(State{ .IfToken = Token.Id.Colon });
18031652 },
18041653 Token.Id.Keyword_continue => {
1805 node.kind = ast.Node.ControlFlowExpression.Kind { .Continue = null };
1806 try stack.append(State { .Identifier = OptionalCtx { .RequiredNull = &node.kind.Continue } });
1807 try stack.append(State { .IfToken = Token.Id.Colon });
1654 node.kind = ast.Node.ControlFlowExpression.Kind{ .Continue = null };
1655 try stack.append(State{ .Identifier = OptionalCtx{ .RequiredNull = &node.kind.Continue } });
1656 try stack.append(State{ .IfToken = Token.Id.Colon });
18081657 },
18091658 Token.Id.Keyword_return => {
18101659 node.kind = ast.Node.ControlFlowExpression.Kind.Return;
......@@ -1813,56 +1662,58 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
18131662 }
18141663 continue;
18151664 },
1816 Token.Id.Keyword_try, Token.Id.Keyword_cancel, Token.Id.Keyword_resume => {
1817 const node = try arena.construct(ast.Node.PrefixOp {
1818 .base = ast.Node {.id = ast.Node.Id.PrefixOp },
1665 Token.Id.Keyword_try,
1666 Token.Id.Keyword_cancel,
1667 Token.Id.Keyword_resume => {
1668 const node = try arena.construct(ast.Node.PrefixOp{
1669 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
18191670 .op_token = token_index,
18201671 .op = switch (token_ptr.id) {
1821 Token.Id.Keyword_try => ast.Node.PrefixOp.Op { .Try = void{} },
1822 Token.Id.Keyword_cancel => ast.Node.PrefixOp.Op { .Cancel = void{} },
1823 Token.Id.Keyword_resume => ast.Node.PrefixOp.Op { .Resume = void{} },
1672 Token.Id.Keyword_try => ast.Node.PrefixOp.Op{ .Try = void{} },
1673 Token.Id.Keyword_cancel => ast.Node.PrefixOp.Op{ .Cancel = void{} },
1674 Token.Id.Keyword_resume => ast.Node.PrefixOp.Op{ .Resume = void{} },
18241675 else => unreachable,
18251676 },
18261677 .rhs = undefined,
18271678 });
18281679 opt_ctx.store(&node.base);
18291680
1830 stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1681 stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
18311682 continue;
18321683 },
18331684 else => {
18341685 if (!try parseBlockExpr(&stack, arena, opt_ctx, token_ptr, token_index)) {
18351686 putBackToken(&tok_it, &tree);
1836 stack.append(State { .UnwrapExpressionBegin = opt_ctx }) catch unreachable;
1687 stack.append(State{ .UnwrapExpressionBegin = opt_ctx }) catch unreachable;
18371688 }
18381689 continue;
1839 }
1690 },
18401691 }
18411692 },
18421693 State.RangeExpressionBegin => |opt_ctx| {
1843 stack.append(State { .RangeExpressionEnd = opt_ctx }) catch unreachable;
1844 try stack.append(State { .Expression = opt_ctx });
1694 stack.append(State{ .RangeExpressionEnd = opt_ctx }) catch unreachable;
1695 try stack.append(State{ .Expression = opt_ctx });
18451696 continue;
18461697 },
18471698 State.RangeExpressionEnd => |opt_ctx| {
18481699 const lhs = opt_ctx.get() ?? continue;
18491700
18501701 if (eatToken(&tok_it, &tree, Token.Id.Ellipsis3)) |ellipsis3| {
1851 const node = try arena.construct(ast.Node.InfixOp {
1852 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1702 const node = try arena.construct(ast.Node.InfixOp{
1703 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
18531704 .lhs = lhs,
18541705 .op_token = ellipsis3,
18551706 .op = ast.Node.InfixOp.Op.Range,
18561707 .rhs = undefined,
18571708 });
18581709 opt_ctx.store(&node.base);
1859 stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
1710 stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
18601711 continue;
18611712 }
18621713 },
18631714 State.AssignmentExpressionBegin => |opt_ctx| {
1864 stack.append(State { .AssignmentExpressionEnd = opt_ctx }) catch unreachable;
1865 try stack.append(State { .Expression = opt_ctx });
1715 stack.append(State{ .AssignmentExpressionEnd = opt_ctx }) catch unreachable;
1716 try stack.append(State{ .Expression = opt_ctx });
18661717 continue;
18671718 },
18681719
......@@ -1873,16 +1724,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
18731724 const token_index = token.index;
18741725 const token_ptr = token.ptr;
18751726 if (tokenIdToAssignment(token_ptr.id)) |ass_id| {
1876 const node = try arena.construct(ast.Node.InfixOp {
1877 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1727 const node = try arena.construct(ast.Node.InfixOp{
1728 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
18781729 .lhs = lhs,
18791730 .op_token = token_index,
18801731 .op = ass_id,
18811732 .rhs = undefined,
18821733 });
18831734 opt_ctx.store(&node.base);
1884 stack.append(State { .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1885 try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } });
1735 stack.append(State{ .AssignmentExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1736 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } });
18861737 continue;
18871738 } else {
18881739 putBackToken(&tok_it, &tree);
......@@ -1891,8 +1742,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
18911742 },
18921743
18931744 State.UnwrapExpressionBegin => |opt_ctx| {
1894 stack.append(State { .UnwrapExpressionEnd = opt_ctx }) catch unreachable;
1895 try stack.append(State { .BoolOrExpressionBegin = opt_ctx });
1745 stack.append(State{ .UnwrapExpressionEnd = opt_ctx }) catch unreachable;
1746 try stack.append(State{ .BoolOrExpressionBegin = opt_ctx });
18961747 continue;
18971748 },
18981749
......@@ -1903,8 +1754,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19031754 const token_index = token.index;
19041755 const token_ptr = token.ptr;
19051756 if (tokenIdToUnwrapExpr(token_ptr.id)) |unwrap_id| {
1906 const node = try arena.construct(ast.Node.InfixOp {
1907 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1757 const node = try arena.construct(ast.Node.InfixOp{
1758 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
19081759 .lhs = lhs,
19091760 .op_token = token_index,
19101761 .op = unwrap_id,
......@@ -1912,11 +1763,11 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19121763 });
19131764 opt_ctx.store(&node.base);
19141765
1915 stack.append(State { .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1916 try stack.append(State { .Expression = OptionalCtx { .Required = &node.rhs } });
1766 stack.append(State{ .UnwrapExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1767 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.rhs } });
19171768
19181769 if (node.op == ast.Node.InfixOp.Op.Catch) {
1919 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.op.Catch } });
1770 try stack.append(State{ .Payload = OptionalCtx{ .Optional = &node.op.Catch } });
19201771 }
19211772 continue;
19221773 } else {
......@@ -1926,8 +1777,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19261777 },
19271778
19281779 State.BoolOrExpressionBegin => |opt_ctx| {
1929 stack.append(State { .BoolOrExpressionEnd = opt_ctx }) catch unreachable;
1930 try stack.append(State { .BoolAndExpressionBegin = opt_ctx });
1780 stack.append(State{ .BoolOrExpressionEnd = opt_ctx }) catch unreachable;
1781 try stack.append(State{ .BoolAndExpressionBegin = opt_ctx });
19311782 continue;
19321783 },
19331784
......@@ -1935,23 +1786,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19351786 const lhs = opt_ctx.get() ?? continue;
19361787
19371788 if (eatToken(&tok_it, &tree, Token.Id.Keyword_or)) |or_token| {
1938 const node = try arena.construct(ast.Node.InfixOp {
1939 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1789 const node = try arena.construct(ast.Node.InfixOp{
1790 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
19401791 .lhs = lhs,
19411792 .op_token = or_token,
19421793 .op = ast.Node.InfixOp.Op.BoolOr,
19431794 .rhs = undefined,
19441795 });
19451796 opt_ctx.store(&node.base);
1946 stack.append(State { .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1947 try stack.append(State { .BoolAndExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1797 stack.append(State{ .BoolOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1798 try stack.append(State{ .BoolAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
19481799 continue;
19491800 }
19501801 },
19511802
19521803 State.BoolAndExpressionBegin => |opt_ctx| {
1953 stack.append(State { .BoolAndExpressionEnd = opt_ctx }) catch unreachable;
1954 try stack.append(State { .ComparisonExpressionBegin = opt_ctx });
1804 stack.append(State{ .BoolAndExpressionEnd = opt_ctx }) catch unreachable;
1805 try stack.append(State{ .ComparisonExpressionBegin = opt_ctx });
19551806 continue;
19561807 },
19571808
......@@ -1959,23 +1810,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19591810 const lhs = opt_ctx.get() ?? continue;
19601811
19611812 if (eatToken(&tok_it, &tree, Token.Id.Keyword_and)) |and_token| {
1962 const node = try arena.construct(ast.Node.InfixOp {
1963 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1813 const node = try arena.construct(ast.Node.InfixOp{
1814 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
19641815 .lhs = lhs,
19651816 .op_token = and_token,
19661817 .op = ast.Node.InfixOp.Op.BoolAnd,
19671818 .rhs = undefined,
19681819 });
19691820 opt_ctx.store(&node.base);
1970 stack.append(State { .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1971 try stack.append(State { .ComparisonExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1821 stack.append(State{ .BoolAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1822 try stack.append(State{ .ComparisonExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
19721823 continue;
19731824 }
19741825 },
19751826
19761827 State.ComparisonExpressionBegin => |opt_ctx| {
1977 stack.append(State { .ComparisonExpressionEnd = opt_ctx }) catch unreachable;
1978 try stack.append(State { .BinaryOrExpressionBegin = opt_ctx });
1828 stack.append(State{ .ComparisonExpressionEnd = opt_ctx }) catch unreachable;
1829 try stack.append(State{ .BinaryOrExpressionBegin = opt_ctx });
19791830 continue;
19801831 },
19811832
......@@ -1986,16 +1837,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
19861837 const token_index = token.index;
19871838 const token_ptr = token.ptr;
19881839 if (tokenIdToComparison(token_ptr.id)) |comp_id| {
1989 const node = try arena.construct(ast.Node.InfixOp {
1990 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1840 const node = try arena.construct(ast.Node.InfixOp{
1841 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
19911842 .lhs = lhs,
19921843 .op_token = token_index,
19931844 .op = comp_id,
19941845 .rhs = undefined,
19951846 });
19961847 opt_ctx.store(&node.base);
1997 stack.append(State { .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1998 try stack.append(State { .BinaryOrExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1848 stack.append(State{ .ComparisonExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1849 try stack.append(State{ .BinaryOrExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
19991850 continue;
20001851 } else {
20011852 putBackToken(&tok_it, &tree);
......@@ -2004,8 +1855,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20041855 },
20051856
20061857 State.BinaryOrExpressionBegin => |opt_ctx| {
2007 stack.append(State { .BinaryOrExpressionEnd = opt_ctx }) catch unreachable;
2008 try stack.append(State { .BinaryXorExpressionBegin = opt_ctx });
1858 stack.append(State{ .BinaryOrExpressionEnd = opt_ctx }) catch unreachable;
1859 try stack.append(State{ .BinaryXorExpressionBegin = opt_ctx });
20091860 continue;
20101861 },
20111862
......@@ -2013,23 +1864,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20131864 const lhs = opt_ctx.get() ?? continue;
20141865
20151866 if (eatToken(&tok_it, &tree, Token.Id.Pipe)) |pipe| {
2016 const node = try arena.construct(ast.Node.InfixOp {
2017 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1867 const node = try arena.construct(ast.Node.InfixOp{
1868 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
20181869 .lhs = lhs,
20191870 .op_token = pipe,
20201871 .op = ast.Node.InfixOp.Op.BitOr,
20211872 .rhs = undefined,
20221873 });
20231874 opt_ctx.store(&node.base);
2024 stack.append(State { .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2025 try stack.append(State { .BinaryXorExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1875 stack.append(State{ .BinaryOrExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1876 try stack.append(State{ .BinaryXorExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
20261877 continue;
20271878 }
20281879 },
20291880
20301881 State.BinaryXorExpressionBegin => |opt_ctx| {
2031 stack.append(State { .BinaryXorExpressionEnd = opt_ctx }) catch unreachable;
2032 try stack.append(State { .BinaryAndExpressionBegin = opt_ctx });
1882 stack.append(State{ .BinaryXorExpressionEnd = opt_ctx }) catch unreachable;
1883 try stack.append(State{ .BinaryAndExpressionBegin = opt_ctx });
20331884 continue;
20341885 },
20351886
......@@ -2037,23 +1888,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20371888 const lhs = opt_ctx.get() ?? continue;
20381889
20391890 if (eatToken(&tok_it, &tree, Token.Id.Caret)) |caret| {
2040 const node = try arena.construct(ast.Node.InfixOp {
2041 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1891 const node = try arena.construct(ast.Node.InfixOp{
1892 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
20421893 .lhs = lhs,
20431894 .op_token = caret,
20441895 .op = ast.Node.InfixOp.Op.BitXor,
20451896 .rhs = undefined,
20461897 });
20471898 opt_ctx.store(&node.base);
2048 stack.append(State { .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2049 try stack.append(State { .BinaryAndExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1899 stack.append(State{ .BinaryXorExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1900 try stack.append(State{ .BinaryAndExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
20501901 continue;
20511902 }
20521903 },
20531904
20541905 State.BinaryAndExpressionBegin => |opt_ctx| {
2055 stack.append(State { .BinaryAndExpressionEnd = opt_ctx }) catch unreachable;
2056 try stack.append(State { .BitShiftExpressionBegin = opt_ctx });
1906 stack.append(State{ .BinaryAndExpressionEnd = opt_ctx }) catch unreachable;
1907 try stack.append(State{ .BitShiftExpressionBegin = opt_ctx });
20571908 continue;
20581909 },
20591910
......@@ -2061,23 +1912,23 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20611912 const lhs = opt_ctx.get() ?? continue;
20621913
20631914 if (eatToken(&tok_it, &tree, Token.Id.Ampersand)) |ampersand| {
2064 const node = try arena.construct(ast.Node.InfixOp {
2065 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1915 const node = try arena.construct(ast.Node.InfixOp{
1916 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
20661917 .lhs = lhs,
20671918 .op_token = ampersand,
20681919 .op = ast.Node.InfixOp.Op.BitAnd,
20691920 .rhs = undefined,
20701921 });
20711922 opt_ctx.store(&node.base);
2072 stack.append(State { .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2073 try stack.append(State { .BitShiftExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1923 stack.append(State{ .BinaryAndExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1924 try stack.append(State{ .BitShiftExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
20741925 continue;
20751926 }
20761927 },
20771928
20781929 State.BitShiftExpressionBegin => |opt_ctx| {
2079 stack.append(State { .BitShiftExpressionEnd = opt_ctx }) catch unreachable;
2080 try stack.append(State { .AdditionExpressionBegin = opt_ctx });
1930 stack.append(State{ .BitShiftExpressionEnd = opt_ctx }) catch unreachable;
1931 try stack.append(State{ .AdditionExpressionBegin = opt_ctx });
20811932 continue;
20821933 },
20831934
......@@ -2088,16 +1939,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
20881939 const token_index = token.index;
20891940 const token_ptr = token.ptr;
20901941 if (tokenIdToBitShift(token_ptr.id)) |bitshift_id| {
2091 const node = try arena.construct(ast.Node.InfixOp {
2092 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1942 const node = try arena.construct(ast.Node.InfixOp{
1943 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
20931944 .lhs = lhs,
20941945 .op_token = token_index,
20951946 .op = bitshift_id,
20961947 .rhs = undefined,
20971948 });
20981949 opt_ctx.store(&node.base);
2099 stack.append(State { .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2100 try stack.append(State { .AdditionExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1950 stack.append(State{ .BitShiftExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1951 try stack.append(State{ .AdditionExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
21011952 continue;
21021953 } else {
21031954 putBackToken(&tok_it, &tree);
......@@ -2106,8 +1957,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21061957 },
21071958
21081959 State.AdditionExpressionBegin => |opt_ctx| {
2109 stack.append(State { .AdditionExpressionEnd = opt_ctx }) catch unreachable;
2110 try stack.append(State { .MultiplyExpressionBegin = opt_ctx });
1960 stack.append(State{ .AdditionExpressionEnd = opt_ctx }) catch unreachable;
1961 try stack.append(State{ .MultiplyExpressionBegin = opt_ctx });
21111962 continue;
21121963 },
21131964
......@@ -2118,16 +1969,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21181969 const token_index = token.index;
21191970 const token_ptr = token.ptr;
21201971 if (tokenIdToAddition(token_ptr.id)) |add_id| {
2121 const node = try arena.construct(ast.Node.InfixOp {
2122 .base = ast.Node {.id = ast.Node.Id.InfixOp },
1972 const node = try arena.construct(ast.Node.InfixOp{
1973 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
21231974 .lhs = lhs,
21241975 .op_token = token_index,
21251976 .op = add_id,
21261977 .rhs = undefined,
21271978 });
21281979 opt_ctx.store(&node.base);
2129 stack.append(State { .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2130 try stack.append(State { .MultiplyExpressionBegin = OptionalCtx { .Required = &node.rhs } });
1980 stack.append(State{ .AdditionExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
1981 try stack.append(State{ .MultiplyExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
21311982 continue;
21321983 } else {
21331984 putBackToken(&tok_it, &tree);
......@@ -2136,8 +1987,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21361987 },
21371988
21381989 State.MultiplyExpressionBegin => |opt_ctx| {
2139 stack.append(State { .MultiplyExpressionEnd = opt_ctx }) catch unreachable;
2140 try stack.append(State { .CurlySuffixExpressionBegin = opt_ctx });
1990 stack.append(State{ .MultiplyExpressionEnd = opt_ctx }) catch unreachable;
1991 try stack.append(State{ .CurlySuffixExpressionBegin = opt_ctx });
21411992 continue;
21421993 },
21431994
......@@ -2148,16 +1999,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21481999 const token_index = token.index;
21492000 const token_ptr = token.ptr;
21502001 if (tokenIdToMultiply(token_ptr.id)) |mult_id| {
2151 const node = try arena.construct(ast.Node.InfixOp {
2152 .base = ast.Node {.id = ast.Node.Id.InfixOp },
2002 const node = try arena.construct(ast.Node.InfixOp{
2003 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
21532004 .lhs = lhs,
21542005 .op_token = token_index,
21552006 .op = mult_id,
21562007 .rhs = undefined,
21572008 });
21582009 opt_ctx.store(&node.base);
2159 stack.append(State { .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2160 try stack.append(State { .CurlySuffixExpressionBegin = OptionalCtx { .Required = &node.rhs } });
2010 stack.append(State{ .MultiplyExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2011 try stack.append(State{ .CurlySuffixExpressionBegin = OptionalCtx{ .Required = &node.rhs } });
21612012 continue;
21622013 } else {
21632014 putBackToken(&tok_it, &tree);
......@@ -2166,9 +2017,9 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21662017 },
21672018
21682019 State.CurlySuffixExpressionBegin => |opt_ctx| {
2169 stack.append(State { .CurlySuffixExpressionEnd = opt_ctx }) catch unreachable;
2170 try stack.append(State { .IfToken = Token.Id.LBrace });
2171 try stack.append(State { .TypeExprBegin = opt_ctx });
2020 stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx }) catch unreachable;
2021 try stack.append(State{ .IfToken = Token.Id.LBrace });
2022 try stack.append(State{ .TypeExprBegin = opt_ctx });
21722023 continue;
21732024 },
21742025
......@@ -2176,51 +2027,43 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
21762027 const lhs = opt_ctx.get() ?? continue;
21772028
21782029 if ((??tok_it.peek()).id == Token.Id.Period) {
2179 const node = try arena.construct(ast.Node.SuffixOp {
2180 .base = ast.Node { .id = ast.Node.Id.SuffixOp },
2030 const node = try arena.construct(ast.Node.SuffixOp{
2031 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
21812032 .lhs = lhs,
2182 .op = ast.Node.SuffixOp.Op {
2183 .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena),
2184 },
2033 .op = ast.Node.SuffixOp.Op{ .StructInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },
21852034 .rtoken = undefined,
21862035 });
21872036 opt_ctx.store(&node.base);
21882037
2189 stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2190 try stack.append(State { .IfToken = Token.Id.LBrace });
2191 try stack.append(State {
2192 .FieldInitListItemOrEnd = ListSave(@typeOf(node.op.StructInitializer)) {
2193 .list = &node.op.StructInitializer,
2194 .ptr = &node.rtoken,
2195 }
2196 });
2038 stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2039 try stack.append(State{ .IfToken = Token.Id.LBrace });
2040 try stack.append(State{ .FieldInitListItemOrEnd = ListSave(@typeOf(node.op.StructInitializer)){
2041 .list = &node.op.StructInitializer,
2042 .ptr = &node.rtoken,
2043 } });
21972044 continue;
21982045 }
21992046
2200 const node = try arena.construct(ast.Node.SuffixOp {
2201 .base = ast.Node {.id = ast.Node.Id.SuffixOp },
2047 const node = try arena.construct(ast.Node.SuffixOp{
2048 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
22022049 .lhs = lhs,
2203 .op = ast.Node.SuffixOp.Op {
2204 .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena),
2205 },
2050 .op = ast.Node.SuffixOp.Op{ .ArrayInitializer = ast.Node.SuffixOp.Op.InitList.init(arena) },
22062051 .rtoken = undefined,
22072052 });
22082053 opt_ctx.store(&node.base);
2209 stack.append(State { .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2210 try stack.append(State { .IfToken = Token.Id.LBrace });
2211 try stack.append(State {
2212 .ExprListItemOrEnd = ExprListCtx {
2213 .list = &node.op.ArrayInitializer,
2214 .end = Token.Id.RBrace,
2215 .ptr = &node.rtoken,
2216 }
2217 });
2054 stack.append(State{ .CurlySuffixExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2055 try stack.append(State{ .IfToken = Token.Id.LBrace });
2056 try stack.append(State{ .ExprListItemOrEnd = ExprListCtx{
2057 .list = &node.op.ArrayInitializer,
2058 .end = Token.Id.RBrace,
2059 .ptr = &node.rtoken,
2060 } });
22182061 continue;
22192062 },
22202063
22212064 State.TypeExprBegin => |opt_ctx| {
2222 stack.append(State { .TypeExprEnd = opt_ctx }) catch unreachable;
2223 try stack.append(State { .PrefixOpExpression = opt_ctx });
2065 stack.append(State{ .TypeExprEnd = opt_ctx }) catch unreachable;
2066 try stack.append(State{ .PrefixOpExpression = opt_ctx });
22242067 continue;
22252068 },
22262069
......@@ -2228,16 +2071,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22282071 const lhs = opt_ctx.get() ?? continue;
22292072
22302073 if (eatToken(&tok_it, &tree, Token.Id.Bang)) |bang| {
2231 const node = try arena.construct(ast.Node.InfixOp {
2232 .base = ast.Node {.id = ast.Node.Id.InfixOp },
2074 const node = try arena.construct(ast.Node.InfixOp{
2075 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
22332076 .lhs = lhs,
22342077 .op_token = bang,
22352078 .op = ast.Node.InfixOp.Op.ErrorUnion,
22362079 .rhs = undefined,
22372080 });
22382081 opt_ctx.store(&node.base);
2239 stack.append(State { .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable;
2240 try stack.append(State { .PrefixOpExpression = OptionalCtx { .Required = &node.rhs } });
2082 stack.append(State{ .TypeExprEnd = opt_ctx.toRequired() }) catch unreachable;
2083 try stack.append(State{ .PrefixOpExpression = OptionalCtx{ .Required = &node.rhs } });
22412084 continue;
22422085 }
22432086 },
......@@ -2247,8 +2090,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22472090 const token_index = token.index;
22482091 const token_ptr = token.ptr;
22492092 if (tokenIdToPrefixOp(token_ptr.id)) |prefix_id| {
2250 var node = try arena.construct(ast.Node.PrefixOp {
2251 .base = ast.Node {.id = ast.Node.Id.PrefixOp },
2093 var node = try arena.construct(ast.Node.PrefixOp{
2094 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
22522095 .op_token = token_index,
22532096 .op = prefix_id,
22542097 .rhs = undefined,
......@@ -2257,8 +2100,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22572100
22582101 // Treat '**' token as two derefs
22592102 if (token_ptr.id == Token.Id.AsteriskAsterisk) {
2260 const child = try arena.construct(ast.Node.PrefixOp {
2261 .base = ast.Node {.id = ast.Node.Id.PrefixOp},
2103 const child = try arena.construct(ast.Node.PrefixOp{
2104 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
22622105 .op_token = token_index,
22632106 .op = prefix_id,
22642107 .rhs = undefined,
......@@ -2267,40 +2110,38 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
22672110 node = child;
22682111 }
22692112
2270 stack.append(State { .TypeExprBegin = OptionalCtx { .Required = &node.rhs } }) catch unreachable;
2113 stack.append(State{ .TypeExprBegin = OptionalCtx{ .Required = &node.rhs } }) catch unreachable;
22712114 if (node.op == ast.Node.PrefixOp.Op.AddrOf) {
2272 try stack.append(State { .AddrOfModifiers = &node.op.AddrOf });
2115 try stack.append(State{ .AddrOfModifiers = &node.op.AddrOf });
22732116 }
22742117 continue;
22752118 } else {
22762119 putBackToken(&tok_it, &tree);
2277 stack.append(State { .SuffixOpExpressionBegin = opt_ctx }) catch unreachable;
2120 stack.append(State{ .SuffixOpExpressionBegin = opt_ctx }) catch unreachable;
22782121 continue;
22792122 }
22802123 },
22812124
22822125 State.SuffixOpExpressionBegin => |opt_ctx| {
22832126 if (eatToken(&tok_it, &tree, Token.Id.Keyword_async)) |async_token| {
2284 const async_node = try arena.construct(ast.Node.AsyncAttribute {
2285 .base = ast.Node {.id = ast.Node.Id.AsyncAttribute},
2127 const async_node = try arena.construct(ast.Node.AsyncAttribute{
2128 .base = ast.Node{ .id = ast.Node.Id.AsyncAttribute },
22862129 .async_token = async_token,
22872130 .allocator_type = null,
22882131 .rangle_bracket = null,
22892132 });
2290 stack.append(State {
2291 .AsyncEnd = AsyncEndCtx {
2292 .ctx = opt_ctx,
2293 .attribute = async_node,
2294 }
2295 }) catch unreachable;
2296 try stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() });
2297 try stack.append(State { .PrimaryExpression = opt_ctx.toRequired() });
2298 try stack.append(State { .AsyncAllocator = async_node });
2133 stack.append(State{ .AsyncEnd = AsyncEndCtx{
2134 .ctx = opt_ctx,
2135 .attribute = async_node,
2136 } }) catch unreachable;
2137 try stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() });
2138 try stack.append(State{ .PrimaryExpression = opt_ctx.toRequired() });
2139 try stack.append(State{ .AsyncAllocator = async_node });
22992140 continue;
23002141 }
23012142
2302 stack.append(State { .SuffixOpExpressionEnd = opt_ctx }) catch unreachable;
2303 try stack.append(State { .PrimaryExpression = opt_ctx });
2143 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx }) catch unreachable;
2144 try stack.append(State{ .PrimaryExpression = opt_ctx });
23042145 continue;
23052146 },
23062147
......@@ -2312,48 +2153,42 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23122153 const token_ptr = token.ptr;
23132154 switch (token_ptr.id) {
23142155 Token.Id.LParen => {
2315 const node = try arena.construct(ast.Node.SuffixOp {
2316 .base = ast.Node {.id = ast.Node.Id.SuffixOp },
2156 const node = try arena.construct(ast.Node.SuffixOp{
2157 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
23172158 .lhs = lhs,
2318 .op = ast.Node.SuffixOp.Op {
2319 .Call = ast.Node.SuffixOp.Op.Call {
2320 .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena),
2321 .async_attr = null,
2322 }
2323 },
2159 .op = ast.Node.SuffixOp.Op{ .Call = ast.Node.SuffixOp.Op.Call{
2160 .params = ast.Node.SuffixOp.Op.Call.ParamList.init(arena),
2161 .async_attr = null,
2162 } },
23242163 .rtoken = undefined,
23252164 });
23262165 opt_ctx.store(&node.base);
23272166
2328 stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2329 try stack.append(State {
2330 .ExprListItemOrEnd = ExprListCtx {
2331 .list = &node.op.Call.params,
2332 .end = Token.Id.RParen,
2333 .ptr = &node.rtoken,
2334 }
2335 });
2167 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2168 try stack.append(State{ .ExprListItemOrEnd = ExprListCtx{
2169 .list = &node.op.Call.params,
2170 .end = Token.Id.RParen,
2171 .ptr = &node.rtoken,
2172 } });
23362173 continue;
23372174 },
23382175 Token.Id.LBracket => {
2339 const node = try arena.construct(ast.Node.SuffixOp {
2340 .base = ast.Node {.id = ast.Node.Id.SuffixOp },
2176 const node = try arena.construct(ast.Node.SuffixOp{
2177 .base = ast.Node{ .id = ast.Node.Id.SuffixOp },
23412178 .lhs = lhs,
2342 .op = ast.Node.SuffixOp.Op {
2343 .ArrayAccess = undefined,
2344 },
2345 .rtoken = undefined
2179 .op = ast.Node.SuffixOp.Op{ .ArrayAccess = undefined },
2180 .rtoken = undefined,
23462181 });
23472182 opt_ctx.store(&node.base);
23482183
2349 stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2350 try stack.append(State { .SliceOrArrayAccess = node });
2351 try stack.append(State { .Expression = OptionalCtx { .Required = &node.op.ArrayAccess }});
2184 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2185 try stack.append(State{ .SliceOrArrayAccess = node });
2186 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.op.ArrayAccess } });
23522187 continue;
23532188 },
23542189 Token.Id.Period => {
2355 const node = try arena.construct(ast.Node.InfixOp {
2356 .base = ast.Node {.id = ast.Node.Id.InfixOp },
2190 const node = try arena.construct(ast.Node.InfixOp{
2191 .base = ast.Node{ .id = ast.Node.Id.InfixOp },
23572192 .lhs = lhs,
23582193 .op_token = token_index,
23592194 .op = ast.Node.InfixOp.Op.Period,
......@@ -2361,8 +2196,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23612196 });
23622197 opt_ctx.store(&node.base);
23632198
2364 stack.append(State { .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2365 try stack.append(State { .Identifier = OptionalCtx { .Required = &node.rhs } });
2199 stack.append(State{ .SuffixOpExpressionEnd = opt_ctx.toRequired() }) catch unreachable;
2200 try stack.append(State{ .Identifier = OptionalCtx{ .Required = &node.rhs } });
23662201 continue;
23672202 },
23682203 else => {
......@@ -2391,7 +2226,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
23912226 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.UndefinedLiteral, token.index);
23922227 continue;
23932228 },
2394 Token.Id.Keyword_true, Token.Id.Keyword_false => {
2229 Token.Id.Keyword_true,
2230 Token.Id.Keyword_false => {
23952231 _ = try createToCtxLiteral(arena, opt_ctx, ast.Node.BoolLiteral, token.index);
23962232 continue;
23972233 },
......@@ -2412,10 +2248,8 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24122248 continue;
24132249 },
24142250 Token.Id.Keyword_promise => {
2415 const node = try arena.construct(ast.Node.PromiseType {
2416 .base = ast.Node {
2417 .id = ast.Node.Id.PromiseType,
2418 },
2251 const node = try arena.construct(ast.Node.PromiseType{
2252 .base = ast.Node{ .id = ast.Node.Id.PromiseType },
24192253 .promise_token = token.index,
24202254 .result = null,
24212255 });
......@@ -2427,121 +2261,108 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
24272261 putBackToken(&tok_it, &tree);
24282262 continue;
24292263 }
2430 node.result = ast.Node.PromiseType.Result {
2264 node.result = ast.Node.PromiseType.Result{
24312265 .arrow_token = next_token_index,
24322266 .return_type = undefined,
24332267 };
24342268 const return_type_ptr = &((??node.result).return_type);
2435 try stack.append(State { .Expression = OptionalCtx { .Required = return_type_ptr, } });
2269 try stack.append(State{ .Expression = OptionalCtx{ .Required = return_type_ptr } });
24362270 continue;
24372271 },
2438 Token.Id.StringLiteral, Token.Id.MultilineStringLiteralLine => {
2272 Token.Id.StringLiteral,
2273 Token.Id.MultilineStringLiteralLine => {
24392274 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token.ptr, token.index, &tree)) ?? unreachable);
24402275 continue;
24412276 },
24422277 Token.Id.LParen => {
2443 const node = try arena.construct(ast.Node.GroupedExpression {
2444 .base = ast.Node {.id = ast.Node.Id.GroupedExpression },
2278 const node = try arena.construct(ast.Node.GroupedExpression{
2279 .base = ast.Node{ .id = ast.Node.Id.GroupedExpression },
24452280 .lparen = token.index,
24462281 .expr = undefined,
24472282 .rparen = undefined,
24482283 });
24492284 opt_ctx.store(&node.base);
24502285
2451 stack.append(State {
2452 .ExpectTokenSave = ExpectTokenSave {
2453 .id = Token.Id.RParen,
2454 .ptr = &node.rparen,
2455 }
2456 }) catch unreachable;
2457 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
2286 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
2287 .id = Token.Id.RParen,
2288 .ptr = &node.rparen,
2289 } }) catch unreachable;
2290 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
24582291 continue;
24592292 },
24602293 Token.Id.Builtin => {
2461 const node = try arena.construct(ast.Node.BuiltinCall {
2462 .base = ast.Node {.id = ast.Node.Id.BuiltinCall },
2294 const node = try arena.construct(ast.Node.BuiltinCall{
2295 .base = ast.Node{ .id = ast.Node.Id.BuiltinCall },
24632296 .builtin_token = token.index,
24642297 .params = ast.Node.BuiltinCall.ParamList.init(arena),
24652298 .rparen_token = undefined,
24662299 });
24672300 opt_ctx.store(&node.base);
24682301
2469 stack.append(State {
2470 .ExprListItemOrEnd = ExprListCtx {
2471 .list = &node.params,
2472 .end = Token.Id.RParen,
2473 .ptr = &node.rparen_token,
2474 }
2475 }) catch unreachable;
2476 try stack.append(State { .ExpectToken = Token.Id.LParen, });
2302 stack.append(State{ .ExprListItemOrEnd = ExprListCtx{
2303 .list = &node.params,
2304 .end = Token.Id.RParen,
2305 .ptr = &node.rparen_token,
2306 } }) catch unreachable;
2307 try stack.append(State{ .ExpectToken = Token.Id.LParen });
24772308 continue;
24782309 },
24792310 Token.Id.LBracket => {
2480 const node = try arena.construct(ast.Node.PrefixOp {
2481 .base = ast.Node {.id = ast.Node.Id.PrefixOp },
2311 const node = try arena.construct(ast.Node.PrefixOp{
2312 .base = ast.Node{ .id = ast.Node.Id.PrefixOp },
24822313 .op_token = token.index,
24832314 .op = undefined,
24842315 .rhs = undefined,
24852316 });
24862317 opt_ctx.store(&node.base);
24872318
2488 stack.append(State { .SliceOrArrayType = node }) catch unreachable;
2319 stack.append(State{ .SliceOrArrayType = node }) catch unreachable;
24892320 continue;
24902321 },
24912322 Token.Id.Keyword_error => {
2492 stack.append(State {
2493 .ErrorTypeOrSetDecl = ErrorTypeOrSetDeclCtx {
2494 .error_token = token.index,
2495 .opt_ctx = opt_ctx
2496 }
2497 }) catch unreachable;
2323 stack.append(State{ .ErrorTypeOrSetDecl = ErrorTypeOrSetDeclCtx{
2324 .error_token = token.index,
2325 .opt_ctx = opt_ctx,
2326 } }) catch unreachable;
24982327 continue;
24992328 },
25002329 Token.Id.Keyword_packed => {
2501 stack.append(State {
2502 .ContainerKind = ContainerKindCtx {
2503 .opt_ctx = opt_ctx,
2504 .ltoken = token.index,
2505 .layout = ast.Node.ContainerDecl.Layout.Packed,
2506 },
2507 }) catch unreachable;
2330 stack.append(State{ .ContainerKind = ContainerKindCtx{
2331 .opt_ctx = opt_ctx,
2332 .ltoken = token.index,
2333 .layout = ast.Node.ContainerDecl.Layout.Packed,
2334 } }) catch unreachable;
25082335 continue;
25092336 },
25102337 Token.Id.Keyword_extern => {
2511 stack.append(State {
2512 .ExternType = ExternTypeCtx {
2513 .opt_ctx = opt_ctx,
2514 .extern_token = token.index,
2515 .comments = null,
2516 },
2517 }) catch unreachable;
2338 stack.append(State{ .ExternType = ExternTypeCtx{
2339 .opt_ctx = opt_ctx,
2340 .extern_token = token.index,
2341 .comments = null,
2342 } }) catch unreachable;
25182343 continue;
25192344 },
2520 Token.Id.Keyword_struct, Token.Id.Keyword_union, Token.Id.Keyword_enum => {
2345 Token.Id.Keyword_struct,
2346 Token.Id.Keyword_union,
2347 Token.Id.Keyword_enum => {
25212348 putBackToken(&tok_it, &tree);
2522 stack.append(State {
2523 .ContainerKind = ContainerKindCtx {
2524 .opt_ctx = opt_ctx,
2525 .ltoken = token.index,
2526 .layout = ast.Node.ContainerDecl.Layout.Auto,
2527 },
2528 }) catch unreachable;
2349 stack.append(State{ .ContainerKind = ContainerKindCtx{
2350 .opt_ctx = opt_ctx,
2351 .ltoken = token.index,
2352 .layout = ast.Node.ContainerDecl.Layout.Auto,
2353 } }) catch unreachable;
25292354 continue;
25302355 },
25312356 Token.Id.Identifier => {
2532 stack.append(State {
2533 .MaybeLabeledExpression = MaybeLabeledExpressionCtx {
2534 .label = token.index,
2535 .opt_ctx = opt_ctx
2536 }
2537 }) catch unreachable;
2357 stack.append(State{ .MaybeLabeledExpression = MaybeLabeledExpressionCtx{
2358 .label = token.index,
2359 .opt_ctx = opt_ctx,
2360 } }) catch unreachable;
25382361 continue;
25392362 },
25402363 Token.Id.Keyword_fn => {
2541 const fn_proto = try arena.construct(ast.Node.FnProto {
2542 .base = ast.Node {
2543 .id = ast.Node.Id.FnProto,
2544 },
2364 const fn_proto = try arena.construct(ast.Node.FnProto{
2365 .base = ast.Node{ .id = ast.Node.Id.FnProto },
25452366 .doc_comments = null,
25462367 .visib_token = null,
25472368 .name_token = null,
......@@ -2557,14 +2378,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25572378 .align_expr = null,
25582379 });
25592380 opt_ctx.store(&fn_proto.base);
2560 stack.append(State { .FnProto = fn_proto }) catch unreachable;
2381 stack.append(State{ .FnProto = fn_proto }) catch unreachable;
25612382 continue;
25622383 },
2563 Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
2564 const fn_proto = try arena.construct(ast.Node.FnProto {
2565 .base = ast.Node {
2566 .id = ast.Node.Id.FnProto,
2567 },
2384 Token.Id.Keyword_nakedcc,
2385 Token.Id.Keyword_stdcallcc => {
2386 const fn_proto = try arena.construct(ast.Node.FnProto{
2387 .base = ast.Node{ .id = ast.Node.Id.FnProto },
25682388 .doc_comments = null,
25692389 .visib_token = null,
25702390 .name_token = null,
......@@ -2580,18 +2400,16 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
25802400 .align_expr = null,
25812401 });
25822402 opt_ctx.store(&fn_proto.base);
2583 stack.append(State { .FnProto = fn_proto }) catch unreachable;
2584 try stack.append(State {
2585 .ExpectTokenSave = ExpectTokenSave {
2586 .id = Token.Id.Keyword_fn,
2587 .ptr = &fn_proto.fn_token
2588 }
2589 });
2403 stack.append(State{ .FnProto = fn_proto }) catch unreachable;
2404 try stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
2405 .id = Token.Id.Keyword_fn,
2406 .ptr = &fn_proto.fn_token,
2407 } });
25902408 continue;
25912409 },
25922410 Token.Id.Keyword_asm => {
2593 const node = try arena.construct(ast.Node.Asm {
2594 .base = ast.Node {.id = ast.Node.Id.Asm },
2411 const node = try arena.construct(ast.Node.Asm{
2412 .base = ast.Node{ .id = ast.Node.Id.Asm },
25952413 .asm_token = token.index,
25962414 .volatile_token = null,
25972415 .template = undefined,
......@@ -2602,94 +2420,77 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
26022420 });
26032421 opt_ctx.store(&node.base);
26042422
2605 stack.append(State {
2606 .ExpectTokenSave = ExpectTokenSave {
2607 .id = Token.Id.RParen,
2608 .ptr = &node.rparen,
2609 }
2610 }) catch unreachable;
2611 try stack.append(State { .AsmClobberItems = &node.clobbers });
2612 try stack.append(State { .IfToken = Token.Id.Colon });
2613 try stack.append(State { .AsmInputItems = &node.inputs });
2614 try stack.append(State { .IfToken = Token.Id.Colon });
2615 try stack.append(State { .AsmOutputItems = &node.outputs });
2616 try stack.append(State { .IfToken = Token.Id.Colon });
2617 try stack.append(State { .StringLiteral = OptionalCtx { .Required = &node.template } });
2618 try stack.append(State { .ExpectToken = Token.Id.LParen });
2619 try stack.append(State {
2620 .OptionalTokenSave = OptionalTokenSave {
2621 .id = Token.Id.Keyword_volatile,
2622 .ptr = &node.volatile_token,
2623 }
2624 });
2423 stack.append(State{ .ExpectTokenSave = ExpectTokenSave{
2424 .id = Token.Id.RParen,
2425 .ptr = &node.rparen,
2426 } }) catch unreachable;
2427 try stack.append(State{ .AsmClobberItems = &node.clobbers });
2428 try stack.append(State{ .IfToken = Token.Id.Colon });
2429 try stack.append(State{ .AsmInputItems = &node.inputs });
2430 try stack.append(State{ .IfToken = Token.Id.Colon });
2431 try stack.append(State{ .AsmOutputItems = &node.outputs });
2432 try stack.append(State{ .IfToken = Token.Id.Colon });
2433 try stack.append(State{ .StringLiteral = OptionalCtx{ .Required = &node.template } });
2434 try stack.append(State{ .ExpectToken = Token.Id.LParen });
2435 try stack.append(State{ .OptionalTokenSave = OptionalTokenSave{
2436 .id = Token.Id.Keyword_volatile,
2437 .ptr = &node.volatile_token,
2438 } });
26252439 },
26262440 Token.Id.Keyword_inline => {
2627 stack.append(State {
2628 .Inline = InlineCtx {
2629 .label = null,
2630 .inline_token = token.index,
2631 .opt_ctx = opt_ctx,
2632 }
2633 }) catch unreachable;
2441 stack.append(State{ .Inline = InlineCtx{
2442 .label = null,
2443 .inline_token = token.index,
2444 .opt_ctx = opt_ctx,
2445 } }) catch unreachable;
26342446 continue;
26352447 },
26362448 else => {
26372449 if (!try parseBlockExpr(&stack, arena, opt_ctx, token.ptr, token.index)) {
26382450 putBackToken(&tok_it, &tree);
26392451 if (opt_ctx != OptionalCtx.Optional) {
2640 *(try tree.errors.addOne()) = Error {
2641 .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr { .token = token.index },
2642 };
2452 ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token.index } };
26432453 return tree;
26442454 }
26452455 }
26462456 continue;
2647 }
2457 },
26482458 }
26492459 },
26502460
2651
26522461 State.ErrorTypeOrSetDecl => |ctx| {
26532462 if (eatToken(&tok_it, &tree, Token.Id.LBrace) == null) {
26542463 _ = try createToCtxLiteral(arena, ctx.opt_ctx, ast.Node.ErrorType, ctx.error_token);
26552464 continue;
26562465 }
26572466
2658 const node = try arena.construct(ast.Node.ErrorSetDecl {
2659 .base = ast.Node {
2660 .id = ast.Node.Id.ErrorSetDecl,
2661 },
2467 const node = try arena.construct(ast.Node.ErrorSetDecl{
2468 .base = ast.Node{ .id = ast.Node.Id.ErrorSetDecl },
26622469 .error_token = ctx.error_token,
26632470 .decls = ast.Node.ErrorSetDecl.DeclList.init(arena),
26642471 .rbrace_token = undefined,
26652472 });
26662473 ctx.opt_ctx.store(&node.base);
26672474
2668 stack.append(State {
2669 .ErrorTagListItemOrEnd = ListSave(@typeOf(node.decls)) {
2670 .list = &node.decls,
2671 .ptr = &node.rbrace_token,
2672 }
2673 }) catch unreachable;
2475 stack.append(State{ .ErrorTagListItemOrEnd = ListSave(@typeOf(node.decls)){
2476 .list = &node.decls,
2477 .ptr = &node.rbrace_token,
2478 } }) catch unreachable;
26742479 continue;
26752480 },
26762481 State.StringLiteral => |opt_ctx| {
26772482 const token = nextToken(&tok_it, &tree);
26782483 const token_index = token.index;
26792484 const token_ptr = token.ptr;
2680 opt_ctx.store(
2681 (try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) ?? {
2682 putBackToken(&tok_it, &tree);
2683 if (opt_ctx != OptionalCtx.Optional) {
2684 *(try tree.errors.addOne()) = Error {
2685 .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr { .token = token_index },
2686 };
2687 return tree;
2688 }
2689
2690 continue;
2485 opt_ctx.store((try parseStringLiteral(arena, &tok_it, token_ptr, token_index, &tree)) ?? {
2486 putBackToken(&tok_it, &tree);
2487 if (opt_ctx != OptionalCtx.Optional) {
2488 ((try tree.errors.addOne())).* = Error{ .ExpectedPrimaryExpr = Error.ExpectedPrimaryExpr{ .token = token_index } };
2489 return tree;
26912490 }
2692 );
2491
2492 continue;
2493 });
26932494 },
26942495
26952496 State.Identifier => |opt_ctx| {
......@@ -2702,12 +2503,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
27022503 const token = nextToken(&tok_it, &tree);
27032504 const token_index = token.index;
27042505 const token_ptr = token.ptr;
2705 *(try tree.errors.addOne()) = Error {
2706 .ExpectedToken = Error.ExpectedToken {
2707 .token = token_index,
2708 .expected_id = Token.Id.Identifier,
2709 },
2710 };
2506 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
2507 .token = token_index,
2508 .expected_id = Token.Id.Identifier,
2509 } };
27112510 return tree;
27122511 }
27132512 },
......@@ -2718,23 +2517,19 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
27182517 const ident_token_index = ident_token.index;
27192518 const ident_token_ptr = ident_token.ptr;
27202519 if (ident_token_ptr.id != Token.Id.Identifier) {
2721 *(try tree.errors.addOne()) = Error {
2722 .ExpectedToken = Error.ExpectedToken {
2723 .token = ident_token_index,
2724 .expected_id = Token.Id.Identifier,
2725 },
2726 };
2520 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
2521 .token = ident_token_index,
2522 .expected_id = Token.Id.Identifier,
2523 } };
27272524 return tree;
27282525 }
27292526
2730 const node = try arena.construct(ast.Node.ErrorTag {
2731 .base = ast.Node {
2732 .id = ast.Node.Id.ErrorTag,
2733 },
2527 const node = try arena.construct(ast.Node.ErrorTag{
2528 .base = ast.Node{ .id = ast.Node.Id.ErrorTag },
27342529 .doc_comments = comments,
27352530 .name_token = ident_token_index,
27362531 });
2737 *node_ptr = &node.base;
2532 node_ptr.* = &node.base;
27382533 continue;
27392534 },
27402535
......@@ -2743,12 +2538,10 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
27432538 const token_index = token.index;
27442539 const token_ptr = token.ptr;
27452540 if (token_ptr.id != token_id) {
2746 *(try tree.errors.addOne()) = Error {
2747 .ExpectedToken = Error.ExpectedToken {
2748 .token = token_index,
2749 .expected_id = token_id,
2750 },
2751 };
2541 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
2542 .token = token_index,
2543 .expected_id = token_id,
2544 } };
27522545 return tree;
27532546 }
27542547 continue;
......@@ -2758,15 +2551,13 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
27582551 const token_index = token.index;
27592552 const token_ptr = token.ptr;
27602553 if (token_ptr.id != expect_token_save.id) {
2761 *(try tree.errors.addOne()) = Error {
2762 .ExpectedToken = Error.ExpectedToken {
2763 .token = token_index,
2764 .expected_id = expect_token_save.id,
2765 },
2766 };
2554 ((try tree.errors.addOne())).* = Error{ .ExpectedToken = Error.ExpectedToken{
2555 .token = token_index,
2556 .expected_id = expect_token_save.id,
2557 } };
27672558 return tree;
27682559 }
2769 *expect_token_save.ptr = token_index;
2560 (expect_token_save.ptr).* = token_index;
27702561 continue;
27712562 },
27722563 State.IfToken => |token_id| {
......@@ -2779,7 +2570,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
27792570 },
27802571 State.IfTokenSave => |if_token_save| {
27812572 if (eatToken(&tok_it, &tree, if_token_save.id)) |token_index| {
2782 *if_token_save.ptr = token_index;
2573 (if_token_save.ptr).* = token_index;
27832574 continue;
27842575 }
27852576
......@@ -2788,7 +2579,7 @@ pub fn parse(allocator: &mem.Allocator, source: []const u8) !ast.Tree {
27882579 },
27892580 State.OptionalTokenSave => |optional_token_save| {
27902581 if (eatToken(&tok_it, &tree, optional_token_save.id)) |token_index| {
2791 *optional_token_save.ptr = token_index;
2582 (optional_token_save.ptr).* = token_index;
27922583 continue;
27932584 }
27942585
......@@ -2911,28 +2702,28 @@ const OptionalCtx = union(enum) {
29112702 Required: &&ast.Node,
29122703
29132704 pub fn store(self: &const OptionalCtx, value: &ast.Node) void {
2914 switch (*self) {
2915 OptionalCtx.Optional => |ptr| *ptr = value,
2916 OptionalCtx.RequiredNull => |ptr| *ptr = value,
2917 OptionalCtx.Required => |ptr| *ptr = value,
2705 switch (self.*) {
2706 OptionalCtx.Optional => |ptr| ptr.* = value,
2707 OptionalCtx.RequiredNull => |ptr| ptr.* = value,
2708 OptionalCtx.Required => |ptr| ptr.* = value,
29182709 }
29192710 }
29202711
29212712 pub fn get(self: &const OptionalCtx) ?&ast.Node {
2922 switch (*self) {
2923 OptionalCtx.Optional => |ptr| return *ptr,
2924 OptionalCtx.RequiredNull => |ptr| return ??*ptr,
2925 OptionalCtx.Required => |ptr| return *ptr,
2713 switch (self.*) {
2714 OptionalCtx.Optional => |ptr| return ptr.*,
2715 OptionalCtx.RequiredNull => |ptr| return ??ptr.*,
2716 OptionalCtx.Required => |ptr| return ptr.*,
29262717 }
29272718 }
29282719
29292720 pub fn toRequired(self: &const OptionalCtx) OptionalCtx {
2930 switch (*self) {
2721 switch (self.*) {
29312722 OptionalCtx.Optional => |ptr| {
2932 return OptionalCtx { .RequiredNull = ptr };
2723 return OptionalCtx{ .RequiredNull = ptr };
29332724 },
2934 OptionalCtx.RequiredNull => |ptr| return *self,
2935 OptionalCtx.Required => |ptr| return *self,
2725 OptionalCtx.RequiredNull => |ptr| return self.*,
2726 OptionalCtx.Required => |ptr| return self.*,
29362727 }
29372728 }
29382729};
......@@ -3054,7 +2845,6 @@ const State = union(enum) {
30542845 Identifier: OptionalCtx,
30552846 ErrorTag: &&ast.Node,
30562847
3057
30582848 IfToken: @TagType(Token.Id),
30592849 IfTokenSave: ExpectTokenSave,
30602850 ExpectToken: @TagType(Token.Id),
......@@ -3064,16 +2854,14 @@ const State = union(enum) {
30642854
30652855fn pushDocComment(arena: &mem.Allocator, line_comment: TokenIndex, result: &?&ast.Node.DocComment) !void {
30662856 const node = blk: {
3067 if (*result) |comment_node| {
2857 if (result.*) |comment_node| {
30682858 break :blk comment_node;
30692859 } else {
3070 const comment_node = try arena.construct(ast.Node.DocComment {
3071 .base = ast.Node {
3072 .id = ast.Node.Id.DocComment,
3073 },
2860 const comment_node = try arena.construct(ast.Node.DocComment{
2861 .base = ast.Node{ .id = ast.Node.Id.DocComment },
30742862 .lines = ast.Node.DocComment.LineList.init(arena),
30752863 });
3076 *result = comment_node;
2864 result.* = comment_node;
30772865 break :blk comment_node;
30782866 }
30792867 };
......@@ -3094,24 +2882,20 @@ fn eatDocComments(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, t
30942882
30952883fn eatLineComment(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) !?&ast.Node.LineComment {
30962884 const token = eatToken(tok_it, tree, Token.Id.LineComment) ?? return null;
3097 return try arena.construct(ast.Node.LineComment {
3098 .base = ast.Node {
3099 .id = ast.Node.Id.LineComment,
3100 },
2885 return try arena.construct(ast.Node.LineComment{
2886 .base = ast.Node{ .id = ast.Node.Id.LineComment },
31012887 .token = token,
31022888 });
31032889}
31042890
3105fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator,
3106 token_ptr: &const Token, token_index: TokenIndex, tree: &ast.Tree) !?&ast.Node
3107{
2891fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterator, token_ptr: &const Token, token_index: TokenIndex, tree: &ast.Tree) !?&ast.Node {
31082892 switch (token_ptr.id) {
31092893 Token.Id.StringLiteral => {
31102894 return &(try createLiteral(arena, ast.Node.StringLiteral, token_index)).base;
31112895 },
31122896 Token.Id.MultilineStringLiteralLine => {
3113 const node = try arena.construct(ast.Node.MultilineStringLiteral {
3114 .base = ast.Node { .id = ast.Node.Id.MultilineStringLiteral },
2897 const node = try arena.construct(ast.Node.MultilineStringLiteral{
2898 .base = ast.Node{ .id = ast.Node.Id.MultilineStringLiteral },
31152899 .lines = ast.Node.MultilineStringLiteral.LineList.init(arena),
31162900 });
31172901 try node.lines.push(token_index);
......@@ -3135,12 +2919,11 @@ fn parseStringLiteral(arena: &mem.Allocator, tok_it: &ast.Tree.TokenList.Iterato
31352919 }
31362920}
31372921
3138fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &const OptionalCtx,
3139 token_ptr: &const Token, token_index: TokenIndex) !bool {
2922fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &const OptionalCtx, token_ptr: &const Token, token_index: TokenIndex) !bool {
31402923 switch (token_ptr.id) {
31412924 Token.Id.Keyword_suspend => {
3142 const node = try arena.construct(ast.Node.Suspend {
3143 .base = ast.Node {.id = ast.Node.Id.Suspend },
2925 const node = try arena.construct(ast.Node.Suspend{
2926 .base = ast.Node{ .id = ast.Node.Id.Suspend },
31442927 .label = null,
31452928 .suspend_token = token_index,
31462929 .payload = null,
......@@ -3148,13 +2931,13 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con
31482931 });
31492932 ctx.store(&node.base);
31502933
3151 stack.append(State { .SuspendBody = node }) catch unreachable;
3152 try stack.append(State { .Payload = OptionalCtx { .Optional = &node.payload } });
2934 stack.append(State{ .SuspendBody = node }) catch unreachable;
2935 try stack.append(State{ .Payload = OptionalCtx{ .Optional = &node.payload } });
31532936 return true;
31542937 },
31552938 Token.Id.Keyword_if => {
3156 const node = try arena.construct(ast.Node.If {
3157 .base = ast.Node {.id = ast.Node.Id.If },
2939 const node = try arena.construct(ast.Node.If{
2940 .base = ast.Node{ .id = ast.Node.Id.If },
31582941 .if_token = token_index,
31592942 .condition = undefined,
31602943 .payload = null,
......@@ -3163,41 +2946,35 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con
31632946 });
31642947 ctx.store(&node.base);
31652948
3166 stack.append(State { .Else = &node.@"else" }) catch unreachable;
3167 try stack.append(State { .Expression = OptionalCtx { .Required = &node.body } });
3168 try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } });
3169 try stack.append(State { .ExpectToken = Token.Id.RParen });
3170 try stack.append(State { .Expression = OptionalCtx { .Required = &node.condition } });
3171 try stack.append(State { .ExpectToken = Token.Id.LParen });
2949 stack.append(State{ .Else = &node.@"else" }) catch unreachable;
2950 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.body } });
2951 try stack.append(State{ .PointerPayload = OptionalCtx{ .Optional = &node.payload } });
2952 try stack.append(State{ .ExpectToken = Token.Id.RParen });
2953 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.condition } });
2954 try stack.append(State{ .ExpectToken = Token.Id.LParen });
31722955 return true;
31732956 },
31742957 Token.Id.Keyword_while => {
3175 stack.append(State {
3176 .While = LoopCtx {
3177 .label = null,
3178 .inline_token = null,
3179 .loop_token = token_index,
3180 .opt_ctx = *ctx,
3181 }
3182 }) catch unreachable;
2958 stack.append(State{ .While = LoopCtx{
2959 .label = null,
2960 .inline_token = null,
2961 .loop_token = token_index,
2962 .opt_ctx = ctx.*,
2963 } }) catch unreachable;
31832964 return true;
31842965 },
31852966 Token.Id.Keyword_for => {
3186 stack.append(State {
3187 .For = LoopCtx {
3188 .label = null,
3189 .inline_token = null,
3190 .loop_token = token_index,
3191 .opt_ctx = *ctx,
3192 }
3193 }) catch unreachable;
2967 stack.append(State{ .For = LoopCtx{
2968 .label = null,
2969 .inline_token = null,
2970 .loop_token = token_index,
2971 .opt_ctx = ctx.*,
2972 } }) catch unreachable;
31942973 return true;
31952974 },
31962975 Token.Id.Keyword_switch => {
3197 const node = try arena.construct(ast.Node.Switch {
3198 .base = ast.Node {
3199 .id = ast.Node.Id.Switch,
3200 },
2976 const node = try arena.construct(ast.Node.Switch{
2977 .base = ast.Node{ .id = ast.Node.Id.Switch },
32012978 .switch_token = token_index,
32022979 .expr = undefined,
32032980 .cases = ast.Node.Switch.CaseList.init(arena),
......@@ -3205,45 +2982,43 @@ fn parseBlockExpr(stack: &std.ArrayList(State), arena: &mem.Allocator, ctx: &con
32052982 });
32062983 ctx.store(&node.base);
32072984
3208 stack.append(State {
3209 .SwitchCaseOrEnd = ListSave(@typeOf(node.cases)) {
3210 .list = &node.cases,
3211 .ptr = &node.rbrace,
3212 },
3213 }) catch unreachable;
3214 try stack.append(State { .ExpectToken = Token.Id.LBrace });
3215 try stack.append(State { .ExpectToken = Token.Id.RParen });
3216 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
3217 try stack.append(State { .ExpectToken = Token.Id.LParen });
2985 stack.append(State{ .SwitchCaseOrEnd = ListSave(@typeOf(node.cases)){
2986 .list = &node.cases,
2987 .ptr = &node.rbrace,
2988 } }) catch unreachable;
2989 try stack.append(State{ .ExpectToken = Token.Id.LBrace });
2990 try stack.append(State{ .ExpectToken = Token.Id.RParen });
2991 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
2992 try stack.append(State{ .ExpectToken = Token.Id.LParen });
32182993 return true;
32192994 },
32202995 Token.Id.Keyword_comptime => {
3221 const node = try arena.construct(ast.Node.Comptime {
3222 .base = ast.Node {.id = ast.Node.Id.Comptime },
2996 const node = try arena.construct(ast.Node.Comptime{
2997 .base = ast.Node{ .id = ast.Node.Id.Comptime },
32232998 .comptime_token = token_index,
32242999 .expr = undefined,
32253000 .doc_comments = null,
32263001 });
32273002 ctx.store(&node.base);
32283003
3229 try stack.append(State { .Expression = OptionalCtx { .Required = &node.expr } });
3004 try stack.append(State{ .Expression = OptionalCtx{ .Required = &node.expr } });
32303005 return true;
32313006 },
32323007 Token.Id.LBrace => {
3233 const block = try arena.construct(ast.Node.Block {
3234 .base = ast.Node {.id = ast.Node.Id.Block },
3008 const block = try arena.construct(ast.Node.Block{
3009 .base = ast.Node{ .id = ast.Node.Id.Block },
32353010 .label = null,
32363011 .lbrace = token_index,
32373012 .statements = ast.Node.Block.StatementList.init(arena),
32383013 .rbrace = undefined,
32393014 });
32403015 ctx.store(&block.base);
3241 stack.append(State { .Block = block }) catch unreachable;
3016 stack.append(State{ .Block = block }) catch unreachable;
32423017 return true;
32433018 },
32443019 else => {
32453020 return false;
3246 }
3021 },
32473022 }
32483023}
32493024
......@@ -3257,20 +3032,16 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end:
32573032 const token_index = token.index;
32583033 const token_ptr = token.ptr;
32593034 switch (token_ptr.id) {
3260 Token.Id.Comma => return ExpectCommaOrEndResult { .end_token = null},
3035 Token.Id.Comma => return ExpectCommaOrEndResult{ .end_token = null },
32613036 else => {
32623037 if (end == token_ptr.id) {
3263 return ExpectCommaOrEndResult { .end_token = token_index };
3038 return ExpectCommaOrEndResult{ .end_token = token_index };
32643039 }
32653040
3266 return ExpectCommaOrEndResult {
3267 .parse_error = Error {
3268 .ExpectedCommaOrEnd = Error.ExpectedCommaOrEnd {
3269 .token = token_index,
3270 .end_id = end,
3271 },
3272 },
3273 };
3041 return ExpectCommaOrEndResult{ .parse_error = Error{ .ExpectedCommaOrEnd = Error.ExpectedCommaOrEnd{
3042 .token = token_index,
3043 .end_id = end,
3044 } } };
32743045 },
32753046 }
32763047}
......@@ -3278,103 +3049,102 @@ fn expectCommaOrEnd(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, end:
32783049fn tokenIdToAssignment(id: &const Token.Id) ?ast.Node.InfixOp.Op {
32793050 // TODO: We have to cast all cases because of this:
32803051 // error: expected type '?InfixOp', found '?@TagType(InfixOp)'
3281 return switch (*id) {
3282 Token.Id.AmpersandEqual => ast.Node.InfixOp.Op { .AssignBitAnd = {} },
3283 Token.Id.AngleBracketAngleBracketLeftEqual => ast.Node.InfixOp.Op { .AssignBitShiftLeft = {} },
3284 Token.Id.AngleBracketAngleBracketRightEqual => ast.Node.InfixOp.Op { .AssignBitShiftRight = {} },
3285 Token.Id.AsteriskEqual => ast.Node.InfixOp.Op { .AssignTimes = {} },
3286 Token.Id.AsteriskPercentEqual => ast.Node.InfixOp.Op { .AssignTimesWarp = {} },
3287 Token.Id.CaretEqual => ast.Node.InfixOp.Op { .AssignBitXor = {} },
3288 Token.Id.Equal => ast.Node.InfixOp.Op { .Assign = {} },
3289 Token.Id.MinusEqual => ast.Node.InfixOp.Op { .AssignMinus = {} },
3290 Token.Id.MinusPercentEqual => ast.Node.InfixOp.Op { .AssignMinusWrap = {} },
3291 Token.Id.PercentEqual => ast.Node.InfixOp.Op { .AssignMod = {} },
3292 Token.Id.PipeEqual => ast.Node.InfixOp.Op { .AssignBitOr = {} },
3293 Token.Id.PlusEqual => ast.Node.InfixOp.Op { .AssignPlus = {} },
3294 Token.Id.PlusPercentEqual => ast.Node.InfixOp.Op { .AssignPlusWrap = {} },
3295 Token.Id.SlashEqual => ast.Node.InfixOp.Op { .AssignDiv = {} },
3052 return switch (id.*) {
3053 Token.Id.AmpersandEqual => ast.Node.InfixOp.Op{ .AssignBitAnd = {} },
3054 Token.Id.AngleBracketAngleBracketLeftEqual => ast.Node.InfixOp.Op{ .AssignBitShiftLeft = {} },
3055 Token.Id.AngleBracketAngleBracketRightEqual => ast.Node.InfixOp.Op{ .AssignBitShiftRight = {} },
3056 Token.Id.AsteriskEqual => ast.Node.InfixOp.Op{ .AssignTimes = {} },
3057 Token.Id.AsteriskPercentEqual => ast.Node.InfixOp.Op{ .AssignTimesWarp = {} },
3058 Token.Id.CaretEqual => ast.Node.InfixOp.Op{ .AssignBitXor = {} },
3059 Token.Id.Equal => ast.Node.InfixOp.Op{ .Assign = {} },
3060 Token.Id.MinusEqual => ast.Node.InfixOp.Op{ .AssignMinus = {} },
3061 Token.Id.MinusPercentEqual => ast.Node.InfixOp.Op{ .AssignMinusWrap = {} },
3062 Token.Id.PercentEqual => ast.Node.InfixOp.Op{ .AssignMod = {} },
3063 Token.Id.PipeEqual => ast.Node.InfixOp.Op{ .AssignBitOr = {} },
3064 Token.Id.PlusEqual => ast.Node.InfixOp.Op{ .AssignPlus = {} },
3065 Token.Id.PlusPercentEqual => ast.Node.InfixOp.Op{ .AssignPlusWrap = {} },
3066 Token.Id.SlashEqual => ast.Node.InfixOp.Op{ .AssignDiv = {} },
32963067 else => null,
32973068 };
32983069}
32993070
33003071fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
33013072 return switch (id) {
3302 Token.Id.Keyword_catch => ast.Node.InfixOp.Op { .Catch = null },
3303 Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op { .UnwrapMaybe = void{} },
3073 Token.Id.Keyword_catch => ast.Node.InfixOp.Op{ .Catch = null },
3074 Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op{ .UnwrapMaybe = void{} },
33043075 else => null,
33053076 };
33063077}
33073078
33083079fn tokenIdToComparison(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
33093080 return switch (id) {
3310 Token.Id.BangEqual => ast.Node.InfixOp.Op { .BangEqual = void{} },
3311 Token.Id.EqualEqual => ast.Node.InfixOp.Op { .EqualEqual = void{} },
3312 Token.Id.AngleBracketLeft => ast.Node.InfixOp.Op { .LessThan = void{} },
3313 Token.Id.AngleBracketLeftEqual => ast.Node.InfixOp.Op { .LessOrEqual = void{} },
3314 Token.Id.AngleBracketRight => ast.Node.InfixOp.Op { .GreaterThan = void{} },
3315 Token.Id.AngleBracketRightEqual => ast.Node.InfixOp.Op { .GreaterOrEqual = void{} },
3081 Token.Id.BangEqual => ast.Node.InfixOp.Op{ .BangEqual = void{} },
3082 Token.Id.EqualEqual => ast.Node.InfixOp.Op{ .EqualEqual = void{} },
3083 Token.Id.AngleBracketLeft => ast.Node.InfixOp.Op{ .LessThan = void{} },
3084 Token.Id.AngleBracketLeftEqual => ast.Node.InfixOp.Op{ .LessOrEqual = void{} },
3085 Token.Id.AngleBracketRight => ast.Node.InfixOp.Op{ .GreaterThan = void{} },
3086 Token.Id.AngleBracketRightEqual => ast.Node.InfixOp.Op{ .GreaterOrEqual = void{} },
33163087 else => null,
33173088 };
33183089}
33193090
33203091fn tokenIdToBitShift(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
33213092 return switch (id) {
3322 Token.Id.AngleBracketAngleBracketLeft => ast.Node.InfixOp.Op { .BitShiftLeft = void{} },
3323 Token.Id.AngleBracketAngleBracketRight => ast.Node.InfixOp.Op { .BitShiftRight = void{} },
3093 Token.Id.AngleBracketAngleBracketLeft => ast.Node.InfixOp.Op{ .BitShiftLeft = void{} },
3094 Token.Id.AngleBracketAngleBracketRight => ast.Node.InfixOp.Op{ .BitShiftRight = void{} },
33243095 else => null,
33253096 };
33263097}
33273098
33283099fn tokenIdToAddition(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
33293100 return switch (id) {
3330 Token.Id.Minus => ast.Node.InfixOp.Op { .Sub = void{} },
3331 Token.Id.MinusPercent => ast.Node.InfixOp.Op { .SubWrap = void{} },
3332 Token.Id.Plus => ast.Node.InfixOp.Op { .Add = void{} },
3333 Token.Id.PlusPercent => ast.Node.InfixOp.Op { .AddWrap = void{} },
3334 Token.Id.PlusPlus => ast.Node.InfixOp.Op { .ArrayCat = void{} },
3101 Token.Id.Minus => ast.Node.InfixOp.Op{ .Sub = void{} },
3102 Token.Id.MinusPercent => ast.Node.InfixOp.Op{ .SubWrap = void{} },
3103 Token.Id.Plus => ast.Node.InfixOp.Op{ .Add = void{} },
3104 Token.Id.PlusPercent => ast.Node.InfixOp.Op{ .AddWrap = void{} },
3105 Token.Id.PlusPlus => ast.Node.InfixOp.Op{ .ArrayCat = void{} },
33353106 else => null,
33363107 };
33373108}
33383109
33393110fn tokenIdToMultiply(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
33403111 return switch (id) {
3341 Token.Id.Slash => ast.Node.InfixOp.Op { .Div = void{} },
3342 Token.Id.Asterisk => ast.Node.InfixOp.Op { .Mult = void{} },
3343 Token.Id.AsteriskAsterisk => ast.Node.InfixOp.Op { .ArrayMult = void{} },
3344 Token.Id.AsteriskPercent => ast.Node.InfixOp.Op { .MultWrap = void{} },
3345 Token.Id.Percent => ast.Node.InfixOp.Op { .Mod = void{} },
3346 Token.Id.PipePipe => ast.Node.InfixOp.Op { .MergeErrorSets = void{} },
3112 Token.Id.Slash => ast.Node.InfixOp.Op{ .Div = void{} },
3113 Token.Id.Asterisk => ast.Node.InfixOp.Op{ .Mult = void{} },
3114 Token.Id.AsteriskAsterisk => ast.Node.InfixOp.Op{ .ArrayMult = void{} },
3115 Token.Id.AsteriskPercent => ast.Node.InfixOp.Op{ .MultWrap = void{} },
3116 Token.Id.Percent => ast.Node.InfixOp.Op{ .Mod = void{} },
3117 Token.Id.PipePipe => ast.Node.InfixOp.Op{ .MergeErrorSets = void{} },
33473118 else => null,
33483119 };
33493120}
33503121
33513122fn tokenIdToPrefixOp(id: @TagType(Token.Id)) ?ast.Node.PrefixOp.Op {
33523123 return switch (id) {
3353 Token.Id.Bang => ast.Node.PrefixOp.Op { .BoolNot = void{} },
3354 Token.Id.Tilde => ast.Node.PrefixOp.Op { .BitNot = void{} },
3355 Token.Id.Minus => ast.Node.PrefixOp.Op { .Negation = void{} },
3356 Token.Id.MinusPercent => ast.Node.PrefixOp.Op { .NegationWrap = void{} },
3357 Token.Id.Asterisk, Token.Id.AsteriskAsterisk => ast.Node.PrefixOp.Op { .Deref = void{} },
3358 Token.Id.Ampersand => ast.Node.PrefixOp.Op {
3359 .AddrOf = ast.Node.PrefixOp.AddrOfInfo {
3360 .align_expr = null,
3361 .bit_offset_start_token = null,
3362 .bit_offset_end_token = null,
3363 .const_token = null,
3364 .volatile_token = null,
3365 },
3366 },
3367 Token.Id.QuestionMark => ast.Node.PrefixOp.Op { .MaybeType = void{} },
3368 Token.Id.QuestionMarkQuestionMark => ast.Node.PrefixOp.Op { .UnwrapMaybe = void{} },
3369 Token.Id.Keyword_await => ast.Node.PrefixOp.Op { .Await = void{} },
3370 Token.Id.Keyword_try => ast.Node.PrefixOp.Op { .Try = void{ } },
3124 Token.Id.Bang => ast.Node.PrefixOp.Op{ .BoolNot = void{} },
3125 Token.Id.Tilde => ast.Node.PrefixOp.Op{ .BitNot = void{} },
3126 Token.Id.Minus => ast.Node.PrefixOp.Op{ .Negation = void{} },
3127 Token.Id.MinusPercent => ast.Node.PrefixOp.Op{ .NegationWrap = void{} },
3128 Token.Id.Asterisk,
3129 Token.Id.AsteriskAsterisk => ast.Node.PrefixOp.Op{ .Deref = void{} },
3130 Token.Id.Ampersand => ast.Node.PrefixOp.Op{ .AddrOf = ast.Node.PrefixOp.AddrOfInfo{
3131 .align_expr = null,
3132 .bit_offset_start_token = null,
3133 .bit_offset_end_token = null,
3134 .const_token = null,
3135 .volatile_token = null,
3136 } },
3137 Token.Id.QuestionMark => ast.Node.PrefixOp.Op{ .MaybeType = void{} },
3138 Token.Id.QuestionMarkQuestionMark => ast.Node.PrefixOp.Op{ .UnwrapMaybe = void{} },
3139 Token.Id.Keyword_await => ast.Node.PrefixOp.Op{ .Await = void{} },
3140 Token.Id.Keyword_try => ast.Node.PrefixOp.Op{ .Try = void{} },
33713141 else => null,
33723142 };
33733143}
33743144
33753145fn createLiteral(arena: &mem.Allocator, comptime T: type, token_index: TokenIndex) !&T {
3376 return arena.construct(T {
3377 .base = ast.Node {.id = ast.Node.typeToId(T)},
3146 return arena.construct(T{
3147 .base = ast.Node{ .id = ast.Node.typeToId(T) },
33783148 .token = token_index,
33793149 });
33803150}
......@@ -3389,15 +3159,14 @@ fn createToCtxLiteral(arena: &mem.Allocator, opt_ctx: &const OptionalCtx, compti
33893159fn eatToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree, id: @TagType(Token.Id)) ?TokenIndex {
33903160 const token = nextToken(tok_it, tree);
33913161
3392 if (token.ptr.id == id)
3393 return token.index;
3162 if (token.ptr.id == id) return token.index;
33943163
33953164 putBackToken(tok_it, tree);
33963165 return null;
33973166}
33983167
33993168fn nextToken(tok_it: &ast.Tree.TokenList.Iterator, tree: &ast.Tree) AnnotatedToken {
3400 const result = AnnotatedToken {
3169 const result = AnnotatedToken{
34013170 .index = tok_it.index,
34023171 .ptr = ??tok_it.next(),
34033172 };
std/zig/render.zig+44-44
......@@ -7,7 +7,7 @@ const Token = std.zig.Token;
77
88const indent_delta = 4;
99
10pub const Error = error {
10pub const Error = error{
1111 /// Ran out of memory allocating call stack frames to complete rendering.
1212 OutOfMemory,
1313};
......@@ -17,9 +17,9 @@ pub fn render(allocator: &mem.Allocator, stream: var, tree: &ast.Tree) (@typeOf(
1717
1818 var it = tree.root_node.decls.iterator(0);
1919 while (it.next()) |decl| {
20 try renderTopLevelDecl(allocator, stream, tree, 0, *decl);
20 try renderTopLevelDecl(allocator, stream, tree, 0, decl.*);
2121 if (it.peek()) |next_decl| {
22 const n = if (nodeLineOffset(tree, *decl, *next_decl) >= 2) u8(2) else u8(1);
22 const n = if (nodeLineOffset(tree, decl.*, next_decl.*) >= 2) u8(2) else u8(1);
2323 try stream.writeByteNTimes('\n', n);
2424 }
2525 }
......@@ -154,10 +154,10 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
154154 var it = block.statements.iterator(0);
155155 while (it.next()) |statement| {
156156 try stream.writeByteNTimes(' ', block_indent);
157 try renderStatement(allocator, stream, tree, block_indent, *statement);
157 try renderStatement(allocator, stream, tree, block_indent, statement.*);
158158
159159 if (it.peek()) |next_statement| {
160 const n = if (nodeLineOffset(tree, *statement, *next_statement) >= 2) u8(2) else u8(1);
160 const n = if (nodeLineOffset(tree, statement.*, next_statement.*) >= 2) u8(2) else u8(1);
161161 try stream.writeByteNTimes('\n', n);
162162 }
163163 }
......@@ -203,7 +203,6 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
203203 try stream.write(" ");
204204 try renderExpression(allocator, stream, tree, indent, body);
205205 }
206
207206 },
208207
209208 ast.Node.Id.InfixOp => {
......@@ -335,7 +334,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
335334
336335 var it = call_info.params.iterator(0);
337336 while (it.next()) |param_node| {
338 try renderExpression(allocator, stream, tree, indent, *param_node);
337 try renderExpression(allocator, stream, tree, indent, param_node.*);
339338 if (it.peek() != null) {
340339 try stream.write(", ");
341340 }
......@@ -351,7 +350,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
351350 try stream.write("]");
352351 },
353352
354 ast.Node.SuffixOp.Op.SuffixOp {
353 ast.Node.SuffixOp.Op.SuffixOp => {
355354 try renderExpression(allocator, stream, tree, indent, suffix_op.lhs);
356355 try stream.write(".*");
357356 },
......@@ -375,7 +374,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
375374 }
376375
377376 if (field_inits.len == 1) {
378 const field_init = *field_inits.at(0);
377 const field_init = field_inits.at(0).*;
379378
380379 try renderExpression(allocator, stream, tree, indent, suffix_op.lhs);
381380 try stream.write("{ ");
......@@ -392,12 +391,12 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
392391 var it = field_inits.iterator(0);
393392 while (it.next()) |field_init| {
394393 try stream.writeByteNTimes(' ', new_indent);
395 try renderExpression(allocator, stream, tree, new_indent, *field_init);
396 if ((*field_init).id != ast.Node.Id.LineComment) {
394 try renderExpression(allocator, stream, tree, new_indent, field_init.*);
395 if ((field_init.*).id != ast.Node.Id.LineComment) {
397396 try stream.write(",");
398397 }
399398 if (it.peek()) |next_field_init| {
400 const n = if (nodeLineOffset(tree, *field_init, *next_field_init) >= 2) u8(2) else u8(1);
399 const n = if (nodeLineOffset(tree, field_init.*, next_field_init.*) >= 2) u8(2) else u8(1);
401400 try stream.writeByteNTimes('\n', n);
402401 }
403402 }
......@@ -408,14 +407,13 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
408407 },
409408
410409 ast.Node.SuffixOp.Op.ArrayInitializer => |*exprs| {
411
412410 if (exprs.len == 0) {
413411 try renderExpression(allocator, stream, tree, indent, suffix_op.lhs);
414412 try stream.write("{}");
415413 return;
416414 }
417415 if (exprs.len == 1) {
418 const expr = *exprs.at(0);
416 const expr = exprs.at(0).*;
419417
420418 try renderExpression(allocator, stream, tree, indent, suffix_op.lhs);
421419 try stream.write("{");
......@@ -432,11 +430,11 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
432430 var it = exprs.iterator(0);
433431 while (it.next()) |expr| {
434432 try stream.writeByteNTimes(' ', new_indent);
435 try renderExpression(allocator, stream, tree, new_indent, *expr);
433 try renderExpression(allocator, stream, tree, new_indent, expr.*);
436434 try stream.write(",");
437435
438436 if (it.peek()) |next_expr| {
439 const n = if (nodeLineOffset(tree, *expr, *next_expr) >= 2) u8(2) else u8(1);
437 const n = if (nodeLineOffset(tree, expr.*, next_expr.*) >= 2) u8(2) else u8(1);
440438 try stream.writeByteNTimes('\n', n);
441439 }
442440 }
......@@ -469,7 +467,6 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
469467 ast.Node.ControlFlowExpression.Kind.Return => {
470468 try stream.print("return");
471469 },
472
473470 }
474471
475472 if (flow_expr.rhs) |rhs| {
......@@ -575,7 +572,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
575572 switch (container_decl.layout) {
576573 ast.Node.ContainerDecl.Layout.Packed => try stream.print("packed "),
577574 ast.Node.ContainerDecl.Layout.Extern => try stream.print("extern "),
578 ast.Node.ContainerDecl.Layout.Auto => { },
575 ast.Node.ContainerDecl.Layout.Auto => {},
579576 }
580577
581578 switch (container_decl.kind) {
......@@ -611,10 +608,10 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
611608 var it = container_decl.fields_and_decls.iterator(0);
612609 while (it.next()) |decl| {
613610 try stream.writeByteNTimes(' ', new_indent);
614 try renderTopLevelDecl(allocator, stream, tree, new_indent, *decl);
611 try renderTopLevelDecl(allocator, stream, tree, new_indent, decl.*);
615612
616613 if (it.peek()) |next_decl| {
617 const n = if (nodeLineOffset(tree, *decl, *next_decl) >= 2) u8(2) else u8(1);
614 const n = if (nodeLineOffset(tree, decl.*, next_decl.*) >= 2) u8(2) else u8(1);
618615 try stream.writeByteNTimes('\n', n);
619616 }
620617 }
......@@ -634,7 +631,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
634631 }
635632
636633 if (err_set_decl.decls.len == 1) blk: {
637 const node = *err_set_decl.decls.at(0);
634 const node = err_set_decl.decls.at(0).*;
638635
639636 // if there are any doc comments or same line comments
640637 // don't try to put it all on one line
......@@ -644,7 +641,6 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
644641 break :blk;
645642 }
646643
647
648644 try stream.write("error{");
649645 try renderTopLevelDecl(allocator, stream, tree, indent, node);
650646 try stream.write("}");
......@@ -657,12 +653,12 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
657653 var it = err_set_decl.decls.iterator(0);
658654 while (it.next()) |node| {
659655 try stream.writeByteNTimes(' ', new_indent);
660 try renderTopLevelDecl(allocator, stream, tree, new_indent, *node);
661 if ((*node).id != ast.Node.Id.LineComment) {
656 try renderTopLevelDecl(allocator, stream, tree, new_indent, node.*);
657 if ((node.*).id != ast.Node.Id.LineComment) {
662658 try stream.write(",");
663659 }
664660 if (it.peek()) |next_node| {
665 const n = if (nodeLineOffset(tree, *node, *next_node) >= 2) u8(2) else u8(1);
661 const n = if (nodeLineOffset(tree, node.*, next_node.*) >= 2) u8(2) else u8(1);
666662 try stream.writeByteNTimes('\n', n);
667663 }
668664 }
......@@ -676,9 +672,9 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
676672 const multiline_str_literal = @fieldParentPtr(ast.Node.MultilineStringLiteral, "base", base);
677673 try stream.print("\n");
678674
679 var i : usize = 0;
675 var i: usize = 0;
680676 while (i < multiline_str_literal.lines.len) : (i += 1) {
681 const t = *multiline_str_literal.lines.at(i);
677 const t = multiline_str_literal.lines.at(i).*;
682678 try stream.writeByteNTimes(' ', indent + indent_delta);
683679 try stream.print("{}", tree.tokenSlice(t));
684680 }
......@@ -695,7 +691,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
695691
696692 var it = builtin_call.params.iterator(0);
697693 while (it.next()) |param_node| {
698 try renderExpression(allocator, stream, tree, indent, *param_node);
694 try renderExpression(allocator, stream, tree, indent, param_node.*);
699695 if (it.peek() != null) {
700696 try stream.write(", ");
701697 }
......@@ -740,7 +736,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
740736
741737 var it = fn_proto.params.iterator(0);
742738 while (it.next()) |param_decl_node| {
743 try renderParamDecl(allocator, stream, tree, indent, *param_decl_node);
739 try renderParamDecl(allocator, stream, tree, indent, param_decl_node.*);
744740
745741 if (it.peek() != null) {
746742 try stream.write(", ");
......@@ -764,7 +760,6 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
764760 try renderExpression(allocator, stream, tree, indent, node);
765761 },
766762 }
767
768763 },
769764
770765 ast.Node.Id.PromiseType => {
......@@ -801,10 +796,10 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
801796 var it = switch_node.cases.iterator(0);
802797 while (it.next()) |node| {
803798 try stream.writeByteNTimes(' ', new_indent);
804 try renderExpression(allocator, stream, tree, new_indent, *node);
799 try renderExpression(allocator, stream, tree, new_indent, node.*);
805800
806801 if (it.peek()) |next_node| {
807 const n = if (nodeLineOffset(tree, *node, *next_node) >= 2) u8(2) else u8(1);
802 const n = if (nodeLineOffset(tree, node.*, next_node.*) >= 2) u8(2) else u8(1);
808803 try stream.writeByteNTimes('\n', n);
809804 }
810805 }
......@@ -819,7 +814,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
819814
820815 var it = switch_case.items.iterator(0);
821816 while (it.next()) |node| {
822 try renderExpression(allocator, stream, tree, indent, *node);
817 try renderExpression(allocator, stream, tree, indent, node.*);
823818
824819 if (it.peek() != null) {
825820 try stream.write(",\n");
......@@ -846,8 +841,10 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
846841 try stream.print("{}", tree.tokenSlice(else_node.else_token));
847842
848843 const block_body = switch (else_node.body.id) {
849 ast.Node.Id.Block, ast.Node.Id.If,
850 ast.Node.Id.For, ast.Node.Id.While,
844 ast.Node.Id.Block,
845 ast.Node.Id.If,
846 ast.Node.Id.For,
847 ast.Node.Id.While,
851848 ast.Node.Id.Switch => true,
852849 else => false,
853850 };
......@@ -972,7 +969,11 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
972969 try renderExpression(allocator, stream, tree, indent, if_node.body);
973970
974971 switch (if_node.body.id) {
975 ast.Node.Id.Block, ast.Node.Id.If, ast.Node.Id.For, ast.Node.Id.While, ast.Node.Id.Switch => {
972 ast.Node.Id.Block,
973 ast.Node.Id.If,
974 ast.Node.Id.For,
975 ast.Node.Id.While,
976 ast.Node.Id.Switch => {
976977 if (if_node.@"else") |@"else"| {
977978 if (if_node.body.id == ast.Node.Id.Block) {
978979 try stream.write(" ");
......@@ -995,7 +996,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
995996
996997 try renderExpression(allocator, stream, tree, indent, @"else".body);
997998 }
998 }
999 },
9991000 }
10001001 },
10011002
......@@ -1018,11 +1019,11 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
10181019 {
10191020 var it = asm_node.outputs.iterator(0);
10201021 while (it.next()) |asm_output| {
1021 const node = &(*asm_output).base;
1022 const node = &(asm_output.*).base;
10221023 try renderExpression(allocator, stream, tree, indent_extra, node);
10231024
10241025 if (it.peek()) |next_asm_output| {
1025 const next_node = &(*next_asm_output).base;
1026 const next_node = &(next_asm_output.*).base;
10261027 const n = if (nodeLineOffset(tree, node, next_node) >= 2) u8(2) else u8(1);
10271028 try stream.writeByte(',');
10281029 try stream.writeByteNTimes('\n', n);
......@@ -1038,11 +1039,11 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
10381039 {
10391040 var it = asm_node.inputs.iterator(0);
10401041 while (it.next()) |asm_input| {
1041 const node = &(*asm_input).base;
1042 const node = &(asm_input.*).base;
10421043 try renderExpression(allocator, stream, tree, indent_extra, node);
10431044
10441045 if (it.peek()) |next_asm_input| {
1045 const next_node = &(*next_asm_input).base;
1046 const next_node = &(next_asm_input.*).base;
10461047 const n = if (nodeLineOffset(tree, node, next_node) >= 2) u8(2) else u8(1);
10471048 try stream.writeByte(',');
10481049 try stream.writeByteNTimes('\n', n);
......@@ -1058,7 +1059,7 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
10581059 {
10591060 var it = asm_node.clobbers.iterator(0);
10601061 while (it.next()) |node| {
1061 try renderExpression(allocator, stream, tree, indent_once, *node);
1062 try renderExpression(allocator, stream, tree, indent_once, node.*);
10621063
10631064 if (it.peek() != null) {
10641065 try stream.write(", ");
......@@ -1220,8 +1221,7 @@ fn renderComments(tree: &ast.Tree, stream: var, node: var, indent: usize) (@type
12201221 const comment = node.doc_comments ?? return;
12211222 var it = comment.lines.iterator(0);
12221223 while (it.next()) |line_token_index| {
1223 try stream.print("{}\n", tree.tokenSlice(*line_token_index));
1224 try stream.print("{}\n", tree.tokenSlice(line_token_index.*));
12241225 try stream.writeByteNTimes(' ', indent);
12251226 }
12261227}
1227