rucc-parse 0.2.14

Recursive descent with a Pratt expression parser, declarators, and error recovery.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
//! Expressions, as a Pratt parser over a precedence table.
//!
//! Design: `spec/06-lexer-and-parser.md` section 6.3.
//!
//! C has fifteen levels of binary precedence. Writing them as fifteen mutually recursive
//! functions is the textbook approach and it means fifteen calls to reach an identifier, so the
//! binary part is one loop over a table instead, which is both shorter to read and measurably
//! faster. The prefix and postfix parts stay as ordinary recursive descent, because they are not
//! a precedence problem: they are a small set of shapes, each of which is its own production.
//!
//! # Where the entry points differ
//!
//! Three of them, and the difference is only which binding power the loop starts at. A full
//! expression takes the comma operator, an assignment expression does not, and a constant
//! expression takes neither the comma nor the assignment. That is exactly what the grammar says
//! in three places that would otherwise be three functions.

use rucc_ast::{BinaryOp, Designator, Expr, ExprId, ExprList, GenericAssoc, TypeNameId, UnaryOp};
use rucc_base::Symbol;
use rucc_lex::{Keyword, Punct, Token, TokenKind};

use crate::parser::Parser;

/// What a punctuator does when it turns up after an operand.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Infix {
    /// An ordinary binary operator.
    Binary(BinaryOp),
    /// `=`, or a compound assignment with its operator.
    Assign(Option<BinaryOp>),
    /// `,`, which is not a binary operator because it is a sequence point that throws its left
    /// operand away.
    Comma,
    /// `?`, which takes a third operand and its own closing token.
    Cond,
}

/// The binding powers, lowest first.
///
/// Left and right power rather than one power and an associativity flag: an operator binds
/// tighter on the side whose number is larger, so `(4, 3)` is right associative and `(23, 24)`
/// is left associative, and the loop needs no second test. The numbers are gaps of two so that
/// the three entry points can sit between the levels.
fn infix(punct: Punct) -> Option<(Infix, u8, u8)> {
    use BinaryOp as B;
    let (what, lbp, rbp) = match punct {
        Punct::Comma => (Infix::Comma, 1, 2),
        Punct::Eq => (Infix::Assign(None), 4, 3),
        Punct::StarEq => (Infix::Assign(Some(B::Mul)), 4, 3),
        Punct::SlashEq => (Infix::Assign(Some(B::Div)), 4, 3),
        Punct::PercentEq => (Infix::Assign(Some(B::Rem)), 4, 3),
        Punct::PlusEq => (Infix::Assign(Some(B::Add)), 4, 3),
        Punct::MinusEq => (Infix::Assign(Some(B::Sub)), 4, 3),
        Punct::ShlEq => (Infix::Assign(Some(B::Shl)), 4, 3),
        Punct::ShrEq => (Infix::Assign(Some(B::Shr)), 4, 3),
        Punct::AmpEq => (Infix::Assign(Some(B::BitAnd)), 4, 3),
        Punct::CaretEq => (Infix::Assign(Some(B::BitXor)), 4, 3),
        Punct::PipeEq => (Infix::Assign(Some(B::BitOr)), 4, 3),
        Punct::Question => (Infix::Cond, 6, 5),
        Punct::PipePipe => (Infix::Binary(B::LogOr), 7, 8),
        Punct::AmpAmp => (Infix::Binary(B::LogAnd), 9, 10),
        Punct::Pipe => (Infix::Binary(B::BitOr), 11, 12),
        Punct::Caret => (Infix::Binary(B::BitXor), 13, 14),
        Punct::Amp => (Infix::Binary(B::BitAnd), 15, 16),
        Punct::EqEq => (Infix::Binary(B::Eq), 17, 18),
        Punct::Ne => (Infix::Binary(B::Ne), 17, 18),
        Punct::Lt => (Infix::Binary(B::Lt), 19, 20),
        Punct::Gt => (Infix::Binary(B::Gt), 19, 20),
        Punct::Le => (Infix::Binary(B::Le), 19, 20),
        Punct::Ge => (Infix::Binary(B::Ge), 19, 20),
        Punct::Shl => (Infix::Binary(B::Shl), 21, 22),
        Punct::Shr => (Infix::Binary(B::Shr), 21, 22),
        Punct::Plus => (Infix::Binary(B::Add), 23, 24),
        Punct::Minus => (Infix::Binary(B::Sub), 23, 24),
        Punct::Star => (Infix::Binary(B::Mul), 25, 26),
        Punct::Slash => (Infix::Binary(B::Div), 25, 26),
        Punct::Percent => (Infix::Binary(B::Rem), 25, 26),
        _ => return None,
    };
    Some((what, lbp, rbp))
}

/// The binding power a full expression starts at, which takes everything.
const EXPRESSION: u8 = 1;
/// The binding power an assignment expression starts at, which leaves out the comma.
const ASSIGNMENT: u8 = 3;
/// The binding power a constant expression starts at, which leaves out the assignment too.
const CONDITIONAL: u8 = 5;

impl Parser<'_> {
    /// An `expression`, comma operator included.
    pub(crate) fn expr(&mut self) -> ExprId {
        self.expr_bp(EXPRESSION)
    }

    /// An `assignment-expression`, which is what an argument and an initializer are.
    pub(crate) fn assign_expr(&mut self) -> ExprId {
        self.expr_bp(ASSIGNMENT)
    }

    /// A `constant-expression`, which is a conditional expression the grammar promises is
    /// constant. Nothing here checks that it is; that is the constant evaluator's job.
    pub(crate) fn const_expr(&mut self) -> ExprId {
        self.expr_bp(CONDITIONAL)
    }

    /// The operator at the cursor, when there is one and it binds tightly enough to belong to
    /// this call rather than to the one that asked for `min_bp`.
    fn infix_here(&self, min_bp: u8) -> Option<(Infix, u8)> {
        let (what, lbp, rbp) = infix(self.cursor.current().punct()?)?;
        if lbp < min_bp {
            return None;
        }
        Some((what, rbp))
    }

    /// The precedence loop.
    fn expr_bp(&mut self, min_bp: u8) -> ExprId {
        let mut lhs = self.cast_expr();
        while let Some((what, rbp)) = self.infix_here(min_bp) {
            self.cursor.bump();
            let start = self.ast.expr_span(lhs);
            lhs = match what {
                Infix::Cond => {
                    // GNU leaves the middle out in `a ?: b`, which evaluates `a` once. It is a
                    // different node rather than a rewrite, because rewriting it would need a
                    // temporary that the tree has no way to talk about.
                    let then =
                        if self.cursor.at_punct(Punct::Colon) { None } else { Some(self.expr()) };
                    self.expect_punct(Punct::Colon);
                    let otherwise = self.expr_bp(rbp);
                    let span = start.to(self.ast.expr_span(otherwise));
                    self.add_expr(Expr::Cond { cond: lhs, then, otherwise }, span)
                }
                Infix::Comma => {
                    let rhs = self.expr_bp(rbp);
                    let span = start.to(self.ast.expr_span(rhs));
                    self.add_expr(Expr::Comma { lhs, rhs }, span)
                }
                Infix::Assign(op) => {
                    let rhs = self.expr_bp(rbp);
                    let span = start.to(self.ast.expr_span(rhs));
                    self.add_expr(Expr::Assign { op, lhs, rhs }, span)
                }
                Infix::Binary(op) => {
                    let rhs = self.expr_bp(rbp);
                    let span = start.to(self.ast.expr_span(rhs));
                    self.add_expr(Expr::Binary { op, lhs, rhs }, span)
                }
            };
        }
        lhs
    }

    /// A `cast-expression`, which is a unary expression or a type name in parentheses applied
    /// to one.
    ///
    /// The parenthesis is the one place the grammar needs the scopes, because `(A)*B` is a cast
    /// when `A` is a type name and a multiplication when it is not. Once the type name is read
    /// the second ambiguity is one token wide: a `{` after the closing parenthesis makes it a
    /// compound literal, which is an object rather than a conversion.
    fn cast_expr(&mut self) -> ExprId {
        if !self.at_parenthesised_type() {
            return self.unary();
        }
        let start = self.cursor.span();
        if !self.enter() {
            self.cursor.bump();
            return self.poison_expr(start);
        }
        self.cursor.bump();
        let ty = self.type_name();
        self.expect_punct(Punct::RParen);
        self.leave();
        if self.cursor.at_punct(Punct::LBrace) {
            let init = self.braced_init();
            let span = self.span_from(start);
            let literal = self.add_expr(Expr::CompoundLiteral { ty, init }, span);
            return self.postfix_ops(literal);
        }
        let operand = self.cast_expr();
        let span = start.to(self.ast.expr_span(operand));
        self.add_expr(Expr::Cast { ty, operand }, span)
    }

    /// Whether the parser is looking at a parenthesised type name.
    ///
    /// One token of lookahead past the parenthesis, which is all the grammar needs: the token
    /// after a `(` decides between a type name and an expression on its own, since a type name
    /// always starts with a keyword that names a type, a qualifier, or an identifier the scopes
    /// say is a typedef name.
    pub(crate) fn at_parenthesised_type(&self) -> bool {
        self.cursor.at_punct(Punct::LParen) && self.starts_type_name(self.cursor.peek(1))
    }

    /// A `unary-expression`.
    fn unary(&mut self) -> ExprId {
        let start = self.cursor.span();
        let token = self.cursor.current();
        if let Some(punct) = token.punct() {
            // The operand of `++` and `--` is a unary expression and the operand of the rest is
            // a cast expression, which is why `-(int)x` parses and `++(int)x` does not.
            let prefix = match punct {
                Punct::PlusPlus => Some((UnaryOp::PreInc, true)),
                Punct::MinusMinus => Some((UnaryOp::PreDec, true)),
                Punct::Amp => Some((UnaryOp::AddrOf, false)),
                Punct::Star => Some((UnaryOp::Deref, false)),
                Punct::Plus => Some((UnaryOp::Plus, false)),
                Punct::Minus => Some((UnaryOp::Minus, false)),
                Punct::Tilde => Some((UnaryOp::BitNot, false)),
                Punct::Bang => Some((UnaryOp::Not, false)),
                _ => None,
            };
            if let Some((op, unary_operand)) = prefix {
                self.cursor.bump();
                let operand = if unary_operand { self.unary() } else { self.cast_expr() };
                let span = start.to(self.ast.expr_span(operand));
                return self.add_expr(Expr::Unary { op, operand }, span);
            }
            // `&&x` is the address of the label `x`, GNU's, and not the address of an address.
            // The lexer has already joined the two ampersands, so there is nothing to undo.
            if punct == Punct::AmpAmp {
                self.cursor.bump();
                let name = self.expect_ident();
                let span = self.span_from(start);
                return match name {
                    Some((name, _)) => self.add_expr(Expr::LabelAddr(name), span),
                    None => self.poison_expr(span),
                };
            }
        }
        if let Some(word) = token.keyword() {
            match word {
                Keyword::Sizeof => return self.sizeof_expr(),
                Keyword::Alignof | Keyword::GnuAlignof => return self.alignof_expr(),
                Keyword::Extension => {
                    self.cursor.bump();
                    let operand = self.cast_expr();
                    let span = start.to(self.ast.expr_span(operand));
                    return self.add_expr(Expr::Extension(operand), span);
                }
                Keyword::Real | Keyword::Imag => {
                    self.cursor.bump();
                    let op = if word == Keyword::Real { UnaryOp::Real } else { UnaryOp::Imag };
                    let operand = self.cast_expr();
                    let span = start.to(self.ast.expr_span(operand));
                    return self.add_expr(Expr::Unary { op, operand }, span);
                }
                _ => {}
            }
        }
        let base = self.primary();
        self.postfix_ops(base)
    }

    /// `sizeof expr` or `sizeof (type)`.
    fn sizeof_expr(&mut self) -> ExprId {
        let start = self.cursor.span();
        self.cursor.bump();
        if let Some(ty) = self.parenthesised_type_operand() {
            // `sizeof (T){ ... }` measures the compound literal and not the type, which is why
            // the type name alone is not the answer until the `{` has been ruled out.
            if self.cursor.at_punct(Punct::LBrace) {
                let init = self.braced_init();
                let span = self.span_from(start);
                let literal = self.add_expr(Expr::CompoundLiteral { ty, init }, span);
                let operand = self.postfix_ops(literal);
                let span = self.span_from(start);
                return self.add_expr(Expr::SizeofExpr(operand), span);
            }
            let span = self.span_from(start);
            return self.add_expr(Expr::SizeofType(ty), span);
        }
        let operand = self.unary();
        let span = start.to(self.ast.expr_span(operand));
        self.add_expr(Expr::SizeofExpr(operand), span)
    }

    /// `alignof (type)`, or GNU's `__alignof__ expr`.
    fn alignof_expr(&mut self) -> ExprId {
        let start = self.cursor.span();
        self.cursor.bump();
        if let Some(ty) = self.parenthesised_type_operand() {
            let span = self.span_from(start);
            return self.add_expr(Expr::AlignofType(ty), span);
        }
        let operand = self.unary();
        let span = start.to(self.ast.expr_span(operand));
        self.add_expr(Expr::AlignofExpr(operand), span)
    }

    /// Reads `(type-name)` when that is what comes next, and nothing when it is not.
    fn parenthesised_type_operand(&mut self) -> Option<TypeNameId> {
        if !self.at_parenthesised_type() {
            return None;
        }
        self.cursor.bump();
        let ty = self.type_name();
        self.expect_punct(Punct::RParen);
        Some(ty)
    }

    /// The suffixes that bind tighter than any prefix: subscript, call, member, and the two
    /// that are written after their operand.
    fn postfix_ops(&mut self, mut base: ExprId) -> ExprId {
        loop {
            let start = self.ast.expr_span(base);
            let Some(punct) = self.cursor.current().punct() else { break };
            match punct {
                Punct::LBracket => {
                    if !self.enter() {
                        self.cursor.bump();
                        break;
                    }
                    self.cursor.bump();
                    let index = self.expr();
                    self.expect_punct(Punct::RBracket);
                    self.leave();
                    let span = self.span_from(start);
                    base = self.add_expr(Expr::Index { base, index }, span);
                }
                Punct::LParen => {
                    if !self.enter() {
                        self.cursor.bump();
                        break;
                    }
                    self.cursor.bump();
                    let args = self.call_arguments();
                    self.expect_punct(Punct::RParen);
                    self.leave();
                    let span = self.span_from(start);
                    base = self.add_expr(Expr::Call { callee: base, args }, span);
                }
                Punct::Dot | Punct::Arrow => {
                    let arrow = punct == Punct::Arrow;
                    self.cursor.bump();
                    let span_before = start;
                    match self.expect_ident() {
                        Some((name, _)) => {
                            let span = self.span_from(span_before);
                            base = self.add_expr(Expr::Member { base, name, arrow }, span);
                        }
                        None => {
                            let span = self.span_from(span_before);
                            base = self.poison_expr(span);
                        }
                    }
                }
                Punct::PlusPlus | Punct::MinusMinus => {
                    let op =
                        if punct == Punct::PlusPlus { UnaryOp::PostInc } else { UnaryOp::PostDec };
                    self.cursor.bump();
                    let span = self.span_from(start);
                    base = self.add_expr(Expr::Unary { op, operand: base }, span);
                }
                _ => break,
            }
        }
        base
    }

    /// The arguments of a call, with the opening parenthesis already consumed.
    fn call_arguments(&mut self) -> ExprList {
        let mut args = Vec::new();
        if !self.cursor.at_punct(Punct::RParen) {
            loop {
                let before = self.cursor.index();
                args.push(self.assign_expr());
                if !self.cursor.eat_punct(Punct::Comma) {
                    break;
                }
                // An argument that consumed nothing means the token is not the start of any
                // expression, and going round again would not consume it either.
                if self.cursor.index() == before {
                    break;
                }
            }
        }
        self.ast.add_expr_list(&args)
    }

    /// A `primary-expression`, plus the GNU and C23 constructs that are written like one.
    fn primary(&mut self) -> ExprId {
        let token = self.cursor.current();
        let start = token.span;
        match token.kind {
            TokenKind::Ident => {
                self.cursor.bump();
                self.add_expr(Expr::Name(Symbol::from_raw(token.value)), start)
            }
            TokenKind::Int | TokenKind::Float | TokenKind::Char | TokenKind::Str => {
                self.cursor.bump();
                let expr = self.constant(token);
                self.add_expr(expr, start)
            }
            TokenKind::Keyword(word) => self.primary_keyword(word),
            TokenKind::Punct(Punct::LParen) => self.parenthesised(),
            _ => {
                let found = self.describe(token);
                self.error("E0403", format!("expected an expression, found {found}"), start);
                self.poison_expr(start)
            }
        }
    }

    /// The constant a token refers to, copied out of the token stream and into the tree.
    ///
    /// The tree owns its constants, because it outlives the token stream and because the
    /// printer and everything after it should not have to hold both.
    fn constant(&mut self, token: Token) -> Expr {
        let index = token.value as usize;
        match token.kind {
            TokenKind::Int => Expr::Int(self.ast.add_int(self.tokens.ints[index])),
            TokenKind::Float => Expr::Float(self.ast.add_float(self.tokens.floats[index])),
            TokenKind::Char => Expr::Char(self.ast.add_char(self.tokens.chars[index])),
            TokenKind::Str => {
                let literal = self.tokens.strings[index].clone();
                Expr::Str(self.ast.add_string(literal))
            }
            _ => Expr::Error,
        }
    }

    /// A keyword where an operand was expected.
    fn primary_keyword(&mut self, word: Keyword) -> ExprId {
        let start = self.cursor.span();
        match word {
            Keyword::True => {
                self.cursor.bump();
                self.add_expr(Expr::Bool(true), start)
            }
            Keyword::False => {
                self.cursor.bump();
                self.add_expr(Expr::Bool(false), start)
            }
            Keyword::Nullptr => {
                self.cursor.bump();
                self.add_expr(Expr::Nullptr, start)
            }
            Keyword::Generic => self.generic_selection(),
            Keyword::BuiltinOffsetof => self.builtin_offsetof(),
            Keyword::BuiltinChooseExpr => self.builtin_choose_expr(),
            Keyword::BuiltinTypesCompatibleP => self.builtin_types_compatible(),
            Keyword::BuiltinVaArg => self.builtin_va_arg(),
            _ => {
                let found = self.describe(self.cursor.current());
                self.error("E0403", format!("expected an expression, found {found}"), start);
                self.poison_expr(start)
            }
        }
    }

    /// `(expr)`, or GNU's `({ statements })`.
    fn parenthesised(&mut self) -> ExprId {
        let start = self.cursor.span();
        if !self.enter() {
            self.cursor.bump();
            return self.poison_expr(start);
        }
        self.cursor.bump();
        let result = if self.cursor.at_punct(Punct::LBrace) {
            // A statement expression's value is the value of its last statement, which is a
            // semantic rule rather than a syntactic one, so the block is kept as a block.
            let body = self.compound_stmt();
            let span = self.span_from(start);
            self.add_expr(Expr::StmtExpr(body), span)
        } else {
            self.expr()
        };
        self.expect_punct(Punct::RParen);
        self.leave();
        result
    }

    /// `_Generic(control, type: value, ..., default: value)`.
    fn generic_selection(&mut self) -> ExprId {
        let start = self.cursor.span();
        self.cursor.bump();
        if !self.expect_punct(Punct::LParen) {
            return self.poison_expr(start);
        }
        let control = self.assign_expr();
        let mut assocs = Vec::new();
        while self.cursor.eat_punct(Punct::Comma) {
            let before = self.cursor.index();
            let ty = if self.cursor.eat_keyword(Keyword::Default) {
                None
            } else {
                Some(self.type_name())
            };
            self.expect_punct(Punct::Colon);
            let value = self.assign_expr();
            assocs.push(GenericAssoc { ty, value });
            if self.cursor.index() == before {
                break;
            }
        }
        self.expect_punct(Punct::RParen);
        let assocs = self.ast.add_generic_list(&assocs);
        let span = self.span_from(start);
        self.add_expr(Expr::Generic { control, assocs }, span)
    }

    /// `__builtin_offsetof(type, member.path[3])`.
    ///
    /// The path is not an expression. The members in it are looked up in the type rather than in
    /// any scope, so they are kept as designators, which is the same shape a designated
    /// initializer uses and for the same reason.
    fn builtin_offsetof(&mut self) -> ExprId {
        let start = self.cursor.span();
        self.cursor.bump();
        if !self.expect_punct(Punct::LParen) {
            return self.poison_expr(start);
        }
        let ty = self.type_name();
        self.expect_punct(Punct::Comma);
        let mut path = Vec::new();
        if let Some((name, _)) = self.expect_ident() {
            path.push(Designator::Field(name));
        }
        loop {
            if self.cursor.eat_punct(Punct::Dot) {
                match self.expect_ident() {
                    Some((name, _)) => path.push(Designator::Field(name)),
                    None => break,
                }
            } else if self.cursor.at_punct(Punct::LBracket) {
                self.cursor.bump();
                let index = self.expr();
                self.expect_punct(Punct::RBracket);
                path.push(Designator::Index(index));
            } else {
                break;
            }
        }
        self.expect_punct(Punct::RParen);
        let path = self.ast.add_designator_list(&path);
        let span = self.span_from(start);
        self.add_expr(Expr::Offsetof { ty, path }, span)
    }

    /// `__builtin_choose_expr(cond, then, otherwise)`.
    fn builtin_choose_expr(&mut self) -> ExprId {
        let start = self.cursor.span();
        self.cursor.bump();
        if !self.expect_punct(Punct::LParen) {
            return self.poison_expr(start);
        }
        let cond = self.assign_expr();
        self.expect_punct(Punct::Comma);
        let then = self.assign_expr();
        self.expect_punct(Punct::Comma);
        let otherwise = self.assign_expr();
        self.expect_punct(Punct::RParen);
        let span = self.span_from(start);
        self.add_expr(Expr::ChooseExpr { cond, then, otherwise }, span)
    }

    /// `__builtin_types_compatible_p(a, b)`.
    fn builtin_types_compatible(&mut self) -> ExprId {
        let start = self.cursor.span();
        self.cursor.bump();
        if !self.expect_punct(Punct::LParen) {
            return self.poison_expr(start);
        }
        let a = self.type_name();
        self.expect_punct(Punct::Comma);
        let b = self.type_name();
        self.expect_punct(Punct::RParen);
        let span = self.span_from(start);
        self.add_expr(Expr::TypesCompatible { a, b }, span)
    }

    /// `__builtin_va_arg(list, type)`.
    fn builtin_va_arg(&mut self) -> ExprId {
        let start = self.cursor.span();
        self.cursor.bump();
        if !self.expect_punct(Punct::LParen) {
            return self.poison_expr(start);
        }
        let list = self.assign_expr();
        self.expect_punct(Punct::Comma);
        let ty = self.type_name();
        self.expect_punct(Punct::RParen);
        let span = self.span_from(start);
        self.add_expr(Expr::VaArg { list, ty }, span)
    }
}