feature. See also
. The project being documented here (as the example) is the Zig library itself.
MacroTranslator.parseCUnaryExpr
fn parseCUnaryExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode
File
Code
fn parseCUnaryExpr(mt: *MacroTranslator, scope: *Scope) ParseError!ZigNode {
switch (mt.peek()) {
.bang => {
mt.i += 1;
const operand = try mt.macroIntToBool(try mt.parseCCastExpr(scope));
return ZigTag.not.create(mt.t.arena, operand);
},
.minus => {
mt.i += 1;
const operand = try mt.macroIntFromBool(try mt.parseCCastExpr(scope));
return ZigTag.negate.create(mt.t.arena, operand);
},
.plus => {
mt.i += 1;
return try mt.parseCCastExpr(scope);
},
.tilde => {
mt.i += 1;
const operand = try mt.macroIntFromBool(try mt.parseCCastExpr(scope));
return ZigTag.bit_not.create(mt.t.arena, operand);
},
.asterisk => {
mt.i += 1;
const operand = try mt.parseCCastExpr(scope);
return ZigTag.deref.create(mt.t.arena, operand);
},
.ampersand => {
mt.i += 1;
const operand = try mt.parseCCastExpr(scope);
return ZigTag.address_of.create(mt.t.arena, operand);
},
.keyword_sizeof => {
mt.i += 1;
const operand = if (mt.eat(.l_paren)) blk: {
const inner = (try mt.parseCTypeName(scope)) orelse try mt.parseCUnaryExpr(scope);
try mt.expect(.r_paren);
break :blk inner;
} else try mt.parseCUnaryExpr(scope);
return mt.t.createHelperCallNode(.sizeof, &.{operand});
},
.keyword_alignof => {
mt.i += 1;
// #define alignof _Alignof
try mt.expect(.l_paren);
const operand = (try mt.parseCTypeName(scope)) orelse try mt.parseCUnaryExpr(scope);
try mt.expect(.r_paren);
return ZigTag.alignof.create(mt.t.arena, operand);
},
.plus_plus, .minus_minus => {
try mt.fail("TODO unary inc/dec expr", .{});
return error.ParseError;
},
else => {},
}
return try mt.parseCPostfixExpr(scope, null);
}