1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00

more precise debug information about local variables

This commit is contained in:
Roberto Ierusalimschy 1999-03-23 16:58:37 -03:00
parent d6ff06751a
commit 1f4e2ba7b2

View File

@ -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;