authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2021-06-14 10:14:11+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-14 19:48:45+03:00
logec36b82d058b7e20101a2f55a7ec123077ce9b70
treecf280270930703d42355fb763f08f57166d37bb8
parent4173a2bc24af6839f87b4b4dfd5096f34764d7cc

translate-c: remove old code i forgot in last pr


1 files changed, 21 insertions(+), 42 deletions(-)

src/translate_c.zig+21-42
......@@ -5331,7 +5331,7 @@ fn parseCPrimaryExprInner(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!N
53315331 // for handling type macros (EVIL)
53325332 // TODO maybe detect and treat type macros as typedefs in parseCSpecifierQualifierList?
53335333 m.i -= 1;
5334 if (try parseCTypeName(c, m, scope)) |type_name| {
5334 if (try parseCTypeName(c, m, scope, true)) |type_name| {
53355335 return type_name;
53365336 }
53375337 try m.fail(c, "unable to translate C expr: unexpected token .{s}", .{@tagName(tok)});
......@@ -5543,33 +5543,9 @@ fn parseCMulExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
55435543 while (true) {
55445544 switch (m.next().?) {
55455545 .Asterisk => {
5546 const next = m.peek().?;
5547 if (next == .RParen or next == .Nl or next == .Eof) {
5548 // type *)
5549
5550 // last token of `node`
5551 const prev_id = m.list[m.i - 1].id;
5552
5553 if (prev_id == .Keyword_void) {
5554 const ptr = try Tag.single_pointer.create(c.arena, .{
5555 .is_const = false,
5556 .is_volatile = false,
5557 .elem_type = node,
5558 });
5559 return Tag.optional_type.create(c.arena, ptr);
5560 } else {
5561 return Tag.c_pointer.create(c.arena, .{
5562 .is_const = false,
5563 .is_volatile = false,
5564 .elem_type = node,
5565 });
5566 }
5567 } else {
5568 // expr * expr
5569 const lhs = try macroBoolToInt(c, node);
5570 const rhs = try macroBoolToInt(c, try parseCCastExpr(c, m, scope));
5571 node = try Tag.mul.create(c.arena, .{ .lhs = lhs, .rhs = rhs });
5572 }
5546 const lhs = try macroBoolToInt(c, node);
5547 const rhs = try macroBoolToInt(c, try parseCCastExpr(c, m, scope));
5548 node = try Tag.mul.create(c.arena, .{ .lhs = lhs, .rhs = rhs });
55735549 },
55745550 .Slash => {
55755551 const lhs = try macroBoolToInt(c, node);
......@@ -5592,7 +5568,7 @@ fn parseCMulExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
55925568fn parseCCastExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
55935569 switch (m.next().?) {
55945570 .LParen => {
5595 if (try parseCTypeName(c, m, scope)) |type_name| {
5571 if (try parseCTypeName(c, m, scope, true)) |type_name| {
55965572 if (m.next().? != .RParen) {
55975573 try m.fail(c, "unable to translate C expr: expected ')'", .{});
55985574 return error.ParseError;
......@@ -5611,19 +5587,21 @@ fn parseCCastExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
56115587 return parseCUnaryExpr(c, m, scope);
56125588}
56135589
5614fn parseCTypeName(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!?Node {
5615 if (try parseCSpecifierQualifierList(c, m, scope)) |node| {
5590// allow_fail is set when unsure if we are parsing a type-name
5591fn parseCTypeName(c: *Context, m: *MacroCtx, scope: *Scope, allow_fail: bool) ParseError!?Node {
5592 if (try parseCSpecifierQualifierList(c, m, scope, allow_fail)) |node| {
56165593 return try parseCAbstractDeclarator(c, m, scope, node);
56175594 } else {
56185595 return null;
56195596 }
56205597}
56215598
5622fn parseCSpecifierQualifierList(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!?Node {
5623 switch (m.next().?) {
5599fn parseCSpecifierQualifierList(c: *Context, m: *MacroCtx, scope: *Scope, allow_fail: bool) ParseError!?Node {
5600 const tok = m.next().?;
5601 switch (tok) {
56245602 .Identifier => {
56255603 const mangled_name = scope.getAlias(m.slice());
5626 if (c.typedefs.contains(mangled_name)) {
5604 if (!allow_fail or c.typedefs.contains(mangled_name)) {
56275605 return try Tag.identifier.create(c.arena, builtin_typedef_map.get(mangled_name) orelse mangled_name);
56285606 }
56295607 },
......@@ -5657,8 +5635,13 @@ fn parseCSpecifierQualifierList(c: *Context, m: *MacroCtx, scope: *Scope) ParseE
56575635 else => {},
56585636 }
56595637
5660 m.i -= 1;
5661 return null;
5638 if (allow_fail) {
5639 m.i -= 1;
5640 return null;
5641 } else {
5642 try m.fail(c, "unable to translate C expr: unexpected token .{s}", .{@tagName(tok)});
5643 return error.ParseError;
5644 }
56625645}
56635646
56645647fn parseCNumericType(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
......@@ -5934,9 +5917,7 @@ fn parseCUnaryExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
59345917 .Keyword_sizeof => {
59355918 const operand = if (m.peek().? == .LParen) blk: {
59365919 _ = m.next();
5937 // C grammar says this should be 'type-name' but we have to
5938 // use parseCMulExpr to correctly handle pointer types.
5939 const inner = try parseCMulExpr(c, m, scope);
5920 const inner = (try parseCTypeName(c, m, scope, false)).?;
59405921 if (m.next().? != .RParen) {
59415922 try m.fail(c, "unable to translate C expr: expected ')'", .{});
59425923 return error.ParseError;
......@@ -5953,9 +5934,7 @@ fn parseCUnaryExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node {
59535934 try m.fail(c, "unable to translate C expr: expected '('", .{});
59545935 return error.ParseError;
59555936 }
5956 // C grammar says this should be 'type-name' but we have to
5957 // use parseCMulExpr to correctly handle pointer types.
5958 const operand = try parseCMulExpr(c, m, scope);
5937 const operand = (try parseCTypeName(c, m, scope, false)).?;
59595938 if (m.next().? != .RParen) {
59605939 try m.fail(c, "unable to translate C expr: expected ')'", .{});
59615940 return error.ParseError;