remove Stmt as an AST node
it was only used for printing purposes, even though we can use the existing printStmt() function.
This commit is contained in:
parent
9d1c9cab7f
commit
5348e2b5c4
3 changed files with 2 additions and 16 deletions
|
@ -18,7 +18,6 @@ pub const NodeType = enum {
|
||||||
Struct,
|
Struct,
|
||||||
Enum,
|
Enum,
|
||||||
Block,
|
Block,
|
||||||
Stmt,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ParamDecl = struct {
|
pub const ParamDecl = struct {
|
||||||
|
@ -323,8 +322,6 @@ pub const Node = union(NodeType) {
|
||||||
|
|
||||||
Block: StmtList,
|
Block: StmtList,
|
||||||
|
|
||||||
Stmt: *Stmt,
|
|
||||||
|
|
||||||
pub fn mkRoot(allocator: *std.mem.Allocator) !*Node {
|
pub fn mkRoot(allocator: *std.mem.Allocator) !*Node {
|
||||||
var node = try allocator.create(Node);
|
var node = try allocator.create(Node);
|
||||||
node.* = Node{ .Root = NodeList.init(allocator) };
|
node.* = Node{ .Root = NodeList.init(allocator) };
|
||||||
|
|
|
@ -99,12 +99,6 @@ pub fn printNode(node: *const Node, ident: usize) void {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
.Stmt => |stmt| {
|
|
||||||
printIdent(ident);
|
|
||||||
printStmt(ident, stmt);
|
|
||||||
std.debug.warn("\n");
|
|
||||||
},
|
|
||||||
|
|
||||||
.Struct => |struc| {
|
.Struct => |struc| {
|
||||||
print(ident, "(struct {} (\n", struc.name.lexeme);
|
print(ident, "(struct {} (\n", struc.name.lexeme);
|
||||||
for (struc.fields.toSlice()) |field| {
|
for (struc.fields.toSlice()) |field| {
|
||||||
|
|
|
@ -236,12 +236,6 @@ pub const Parser = struct {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mkStmt(self: *Parser, stmt: *Stmt) !*ast.Node {
|
|
||||||
var node = try self.allocator.create(Node);
|
|
||||||
node.* = Node{ .Stmt = stmt };
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mkStmtExpr(self: *Parser, expr: *Expr) !*Stmt {
|
fn mkStmtExpr(self: *Parser, expr: *Expr) !*Stmt {
|
||||||
var stmt = try self.allocator.create(Stmt);
|
var stmt = try self.allocator.create(Stmt);
|
||||||
stmt.* = Stmt{ .Expr = expr };
|
stmt.* = Stmt{ .Expr = expr };
|
||||||
|
@ -634,7 +628,8 @@ pub const Parser = struct {
|
||||||
|
|
||||||
while (self.peek().typ != .RightBrace) {
|
while (self.peek().typ != .RightBrace) {
|
||||||
var stmt = try self.parseStmt();
|
var stmt = try self.parseStmt();
|
||||||
printer.printNode(try self.mkStmt(stmt), 0);
|
printer.printStmt(0, stmt);
|
||||||
|
|
||||||
if (self.check(.Semicolon))
|
if (self.check(.Semicolon))
|
||||||
_ = try self.consumeSingle(.Semicolon);
|
_ = try self.consumeSingle(.Semicolon);
|
||||||
try stmts.append(stmt.*);
|
try stmts.append(stmt.*);
|
||||||
|
|
Loading…
Reference in a new issue