diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-03-23 16:58:37 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-03-23 16:58:37 -0300 |
| commit | 1f4e2ba7b29628dad7d98030c8432ca7265a85c9 (patch) | |
| tree | f8e6cca35129f2a6a2b383ddf0c0436efecec945 | |
| parent | d6ff06751af3e52ae1e0e1697021fe884f104fc8 (diff) | |
| download | lua-1f4e2ba7b29628dad7d98030c8432ca7265a85c9.tar.gz lua-1f4e2ba7b29628dad7d98030c8432ca7265a85c9.tar.bz2 lua-1f4e2ba7b29628dad7d98030c8432ca7265a85c9.zip | |
more precise debug information about local variables
| -rw-r--r-- | lparser.c | 20 |
1 files changed, 16 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.28 1999/03/10 14:09:45 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.29 1999/03/11 19:00:12 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -315,6 +315,16 @@ static void add_localvar (LexState *ls, TaggedString *name) { | |||
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | 317 | ||
| 318 | static void correctvarlines (LexState *ls, int nvars) { | ||
| 319 | FuncState *fs = ls->fs; | ||
| 320 | if (fs->nvars != -1) { /* debug information? */ | ||
| 321 | for (; nvars; nvars--) { /* correct line information */ | ||
| 322 | fs->f->locvars[fs->nvars-nvars].line = fs->lastsetline; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | } | ||
| 326 | |||
| 327 | |||
| 318 | static int aux_localname (FuncState *fs, TaggedString *n) { | 328 | static int aux_localname (FuncState *fs, TaggedString *n) { |
| 319 | int i; | 329 | int i; |
| 320 | for (i=fs->nlocalvar-1; i >= 0; i--) | 330 | for (i=fs->nlocalvar-1; i >= 0; i--) |
| @@ -652,6 +662,7 @@ TProtoFunc *luaY_parser (ZIO *z) { | |||
| 652 | init_state(&lexstate, &funcstate, luaS_new(zname(z))); | 662 | init_state(&lexstate, &funcstate, luaS_new(zname(z))); |
| 653 | next(&lexstate); /* read first token */ | 663 | next(&lexstate); /* read first token */ |
| 654 | chunk(&lexstate); | 664 | chunk(&lexstate); |
| 665 | check_debugline(&lexstate); | ||
| 655 | if (lexstate.token != EOS) | 666 | if (lexstate.token != EOS) |
| 656 | luaX_error(&lexstate, "<eof> expected"); | 667 | luaX_error(&lexstate, "<eof> expected"); |
| 657 | close_func(&lexstate); | 668 | close_func(&lexstate); |
| @@ -743,7 +754,8 @@ static int stat (LexState *ls) { | |||
| 743 | next(ls); | 754 | next(ls); |
| 744 | nvars = localnamelist(ls); | 755 | nvars = localnamelist(ls); |
| 745 | decinit(ls, &d); | 756 | decinit(ls, &d); |
| 746 | ls->fs->nlocalvar += nvars; | 757 | fs->nlocalvar += nvars; |
| 758 | correctvarlines(ls, nvars); /* vars will be alive only after decinit */ | ||
| 747 | adjust_mult_assign(ls, nvars, &d); | 759 | adjust_mult_assign(ls, nvars, &d); |
| 748 | return 1; | 760 | return 1; |
| 749 | } | 761 | } |
| @@ -799,7 +811,7 @@ static void block (LexState *ls) { | |||
| 799 | chunk(ls); | 811 | chunk(ls); |
| 800 | adjuststack(ls, fs->nlocalvar - nlocalvar); | 812 | adjuststack(ls, fs->nlocalvar - nlocalvar); |
| 801 | for (; fs->nlocalvar > nlocalvar; fs->nlocalvar--) | 813 | for (; fs->nlocalvar > nlocalvar; fs->nlocalvar--) |
| 802 | luaI_unregisterlocalvar(fs, ls->linenumber); | 814 | luaI_unregisterlocalvar(fs, fs->lastsetline); |
| 803 | } | 815 | } |
| 804 | 816 | ||
| 805 | static int funcname (LexState *ls, vardesc *v) { | 817 | static int funcname (LexState *ls, vardesc *v) { |
| @@ -855,9 +867,9 @@ static void ifpart (LexState *ls, int line) { | |||
| 855 | 867 | ||
| 856 | static void ret (LexState *ls) { | 868 | static void ret (LexState *ls) { |
| 857 | /* ret -> [RETURN explist sc] */ | 869 | /* ret -> [RETURN explist sc] */ |
| 858 | check_debugline(ls); | ||
| 859 | if (optional(ls, RETURN)) { | 870 | if (optional(ls, RETURN)) { |
| 860 | listdesc e; | 871 | listdesc e; |
| 872 | check_debugline(ls); | ||
| 861 | explist(ls, &e); | 873 | explist(ls, &e); |
| 862 | if (e.pc > 0) { /* expression is an open function call? */ | 874 | if (e.pc > 0) { /* expression is an open function call? */ |
| 863 | Byte *code = ls->fs->f->code; | 875 | Byte *code = ls->fs->f->code; |
