From dfe8c5a2e9b1778c1911e987c9286d05db307fe7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 5 Aug 2019 03:09:17 -0400 Subject: [PATCH] add a src() method to AstNode to aid debugging --- src/all_types.hpp | 4 ++++ src/ast_render.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/all_types.hpp b/src/all_types.hpp index 85f00a6baf..0098a630d8 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1009,6 +1009,10 @@ struct AstNode { AstNodeAnyFrameType anyframe_type; AstNodeEnumLiteral enum_literal; } data; + + // This is a function for use in the debugger to print + // the source location. + void src(); }; // this struct is allocated with allocate_nonzero diff --git a/src/ast_render.cpp b/src/ast_render.cpp index e54bd58676..dd4d9cf646 100644 --- a/src/ast_render.cpp +++ b/src/ast_render.cpp @@ -1186,3 +1186,9 @@ void ast_render(FILE *f, AstNode *node, int indent_size) { render_node_grouped(&ar, node); } + +void AstNode::src() { + fprintf(stderr, "%s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize "\n", + buf_ptr(this->owner->data.structure.root_struct->path), + this->line + 1, this->column + 1); +}