From 1f4e2ba7b29628dad7d98030c8432ca7265a85c9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 23 Mar 1999 16:58:37 -0300 Subject: [PATCH] more precise debug information about local variables --- lparser.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lparser.c b/lparser.c index 8f3f7efb..6e95738c 100644 --- a/lparser.c +++ b/lparser.c @@ -1,5 +1,5 @@ /* -** $Id: lparser.c,v 1.28 1999/03/10 14:09:45 roberto Exp roberto $ +** $Id: lparser.c,v 1.29 1999/03/11 19:00:12 roberto Exp roberto $ ** LL(1) Parser and code generator for Lua ** See Copyright Notice in lua.h */ @@ -315,6 +315,16 @@ static void add_localvar (LexState *ls, TaggedString *name) { } +static void correctvarlines (LexState *ls, int nvars) { + FuncState *fs = ls->fs; + if (fs->nvars != -1) { /* debug information? */ + for (; nvars; nvars--) { /* correct line information */ + fs->f->locvars[fs->nvars-nvars].line = fs->lastsetline; + } + } +} + + static int aux_localname (FuncState *fs, TaggedString *n) { int i; for (i=fs->nlocalvar-1; i >= 0; i--) @@ -652,6 +662,7 @@ TProtoFunc *luaY_parser (ZIO *z) { init_state(&lexstate, &funcstate, luaS_new(zname(z))); next(&lexstate); /* read first token */ chunk(&lexstate); + check_debugline(&lexstate); if (lexstate.token != EOS) luaX_error(&lexstate, " expected"); close_func(&lexstate); @@ -743,7 +754,8 @@ static int stat (LexState *ls) { next(ls); nvars = localnamelist(ls); decinit(ls, &d); - ls->fs->nlocalvar += nvars; + fs->nlocalvar += nvars; + correctvarlines(ls, nvars); /* vars will be alive only after decinit */ adjust_mult_assign(ls, nvars, &d); return 1; } @@ -799,7 +811,7 @@ static void block (LexState *ls) { chunk(ls); adjuststack(ls, fs->nlocalvar - nlocalvar); for (; fs->nlocalvar > nlocalvar; fs->nlocalvar--) - luaI_unregisterlocalvar(fs, ls->linenumber); + luaI_unregisterlocalvar(fs, fs->lastsetline); } static int funcname (LexState *ls, vardesc *v) { @@ -855,9 +867,9 @@ static void ifpart (LexState *ls, int line) { static void ret (LexState *ls) { /* ret -> [RETURN explist sc] */ - check_debugline(ls); if (optional(ls, RETURN)) { listdesc e; + check_debugline(ls); explist(ls, &e); if (e.pc > 0) { /* expression is an open function call? */ Byte *code = ls->fs->f->code;