commit 1f4e2ba7b29628dad7d98030c8432ca7265a85c9
parent d6ff06751af3e52ae1e0e1697021fe884f104fc8
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 23 Mar 1999 16:58:15 -0300
more precise debug information about local variables
Diffstat:
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git 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, "<eof> 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;