Skip to content

Commit

Permalink
Merge pull request #13 from Srekel/srekel-compound-stmt-fixes
Browse files Browse the repository at this point in the history
Srekel compound stmt fixes
  • Loading branch information
lassade authored Dec 13, 2023
2 parents aafff0e + 0ce3ebf commit f4f237e
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions src/Transpiler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1392,12 +1392,18 @@ fn visitFunctionTemplateDecl(self: *Self, node: *const json.Value) !void {
}

const f_items = f_inner.?.array.items;

if (f_items.len > 0) {
if (!mem.eql(u8, f_items[f_items.len - 1].object.getPtr("kind").?.string, "CompoundStmt")) {
log.err("`FunctionTemplateDecl` `{s}` without `CompoundStmt`", .{name});
return;
const found_compound_stmt = blk: {
for (f_items) |f_item| {
const f_item_kind = f_item.object.getPtr("kind").?.string;
if (mem.eql(u8, f_item_kind, "CompoundStmt")) {
break :blk true;
}
}
break :blk false;
};
if (!found_compound_stmt) {
log.err("`FunctionTemplateDecl` `{s}` without `CompoundStmt`", .{name});
return;
}

const sig = parseFnSignature(item).?;
Expand Down Expand Up @@ -1850,30 +1856,30 @@ fn visitClassTemplateDecl(self: *Self, value: *const json.Value) !void {
fn visitCompoundStmt(self: *Self, value: *const json.Value) !void {
self.nodes_visited += 1;

var inner = value.object.get("inner");
if (inner == null) {
return;
}
try self.out.print("{{", .{});

try self.out.print("{{\n", .{});
var inner_opt = value.object.get("inner");
if (inner_opt) |inner| {
try self.out.print("\n", .{});

const scope = self.scope;
defer self.scope = scope;
self.scope = .{
.tag = .local,
.name = null,
};
const scope = self.scope;
defer self.scope = scope;
self.scope = .{
.tag = .local,
.name = null,
};

self.semicolon = true;
self.semicolon = true;

for (inner.?.array.items) |*item| {
try self.visit(item);
for (inner.array.items) |*item| {
try self.visit(item);

if (self.semicolon) {
_ = try self.out.write(";\n");
} else {
// reset
self.semicolon = true;
if (self.semicolon) {
_ = try self.out.write(";\n");
} else {
// reset
self.semicolon = true;
}
}
}

Expand Down

0 comments on commit f4f237e

Please sign in to comment.