harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a540ab1d3ae435ae22ab1acade5b22648c836db7
parent 371d1eacb62d1a09eccad4132f09570d834e0715
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 22 Nov 2020 11:21:39 -0500

parse: trace imports

Diffstat:
Msrc/identifier.c | 8++++++--
Msrc/parse.c | 12++++++++++--
2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/identifier.c b/src/identifier.c @@ -50,10 +50,14 @@ identifier_unparse_static(const struct identifier *ident, char *buf, size_t len) if (ident->ns) { int prefix = identifier_unparse_static(ident->ns, buf, len); int n = snprintf(&buf[prefix], len - prefix, "::%s", ident->name); - assert(prefix + n < (int)len); + if (n >= (int)len) { + buf[len - 1] = '\0'; + } return n; } int n = snprintf(buf, len, ident->name); - assert(n < (int)len); + if (n >= (int)len) { + buf[len - 1] = '\0'; + } return n; } diff --git a/src/parse.c b/src/parse.c @@ -114,7 +114,8 @@ parse_imports(struct parser *par, struct ast_subunit *subunit) struct token tok = {0}; struct ast_imports **next = &subunit->imports; - while (true) { + bool more = true; + while (more) { struct ast_imports *imports; switch (lex(par->lex, &tok)) { case T_USE: @@ -125,9 +126,16 @@ parse_imports(struct parser *par, struct ast_subunit *subunit) break; default: unlex(par->lex, &tok); - return; + more = false; + break; } } + + for (struct ast_imports *i = subunit->imports; i; i = i->next) { + char buf[1024]; + identifier_unparse_static(&i->ident, buf, sizeof(buf)); + trace("parse", "-> use %s", buf); + } } void