ast_printer: add support for method data

This commit is contained in:
Luna 2019-08-26 20:36:48 -03:00
parent e0d712cd9f
commit 20e5c2339f
1 changed files with 20 additions and 3 deletions

View File

@ -37,14 +37,31 @@ fn printBlock(ident: usize, block: var, endNewline: bool) void {
pub fn printNode(node: *Node, ident: usize) void {
switch (node.*) {
.FnDecl => |decl| {
print(ident, "(fn {} (", decl.func_name.lexeme);
const name = decl.func_name.lexeme;
printIdent(ident);
// TODO print return types
if (decl.method) |method| {
const vari = method.variable.lexeme;
const typ = method.typ.lexeme;
if (method.mutable) {
warn("(method mut {} {} {} ", vari, typ, name);
} else {
warn("(method {} {} {} ", vari, typ, name);
}
} else {
warn("(fn {} (", name);
}
for (decl.params.toSlice()) |param| {
std.debug.warn("({} {}) ", param.name.lexeme, param.typ.lexeme);
warn("({} {}) ", param.name.lexeme, param.typ.lexeme);
}
printBlock(ident + 1, decl.body, false);
std.debug.warn(")\n");
warn(")\n");
},
.ConstDecl => |consts| {