From 20e5c2339f55c4d5060e4cec299e060bbb99c4ad Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 26 Aug 2019 20:36:48 -0300 Subject: [PATCH] ast_printer: add support for method data --- src/ast_printer.zig | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ast_printer.zig b/src/ast_printer.zig index b386b32..1b278dc 100644 --- a/src/ast_printer.zig +++ b/src/ast_printer.zig @@ -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| {