summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/parse.c b/parse.c
index b066708..c40e556 100644
--- a/parse.c
+++ b/parse.c
@@ -3051,3 +3051,24 @@ static inline void construct_resolved_builtin_type(Type *t, BuiltinType builtin)
t->builtin = builtin;
t->flags = TYPE_IS_RESOLVED;
}
+
+#ifndef TOC_DEBUG
+static
+#endif
+char *location_to_str(Location *where) {
+ File *file = where->file;
+ Token *tokens = file->tokens;
+ SourcePos pos = tokens[where->start].pos;
+ char *contents = file->contents;
+ char *s = contents + pos.start;
+ size_t nchars = 10;
+ char buf[64] = {0};
+ snprintf(buf, sizeof buf - 12, "Line %u of %s: ", (unsigned)pos.line, file->filename);
+ char *end = memchr(s, '\0', nchars);
+ if (!end) end = s + nchars;
+ char tmp = *end;
+ *end = '\0';
+ strcat(buf, s);
+ *end = tmp;
+ return str_dup(buf);
+}