diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-03-12 16:53:56 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-03-12 16:53:56 -0300 |
| commit | a003e891252a2f6b4b7d1d006b20d2b306626caa (patch) | |
| tree | b4ca1f1a192713897aa40d0248178f7d2cb8b367 /lparser.c | |
| parent | b876ec61c03e05ea0c4c02d8ad8abb84cf55e87c (diff) | |
| download | lua-a003e891252a2f6b4b7d1d006b20d2b306626caa.tar.gz lua-a003e891252a2f6b4b7d1d006b20d2b306626caa.tar.bz2 lua-a003e891252a2f6b4b7d1d006b20d2b306626caa.zip | |
better error messages for some limits
Diffstat (limited to 'lparser.c')
| -rw-r--r-- | lparser.c | 24 |
1 files changed, 17 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.222 2003/12/09 16:56:11 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ |
| 3 | ** Lua Parser | 3 | ** Lua Parser |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -28,9 +28,10 @@ | |||
| 28 | 28 | ||
| 29 | #define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) | 29 | #define getlocvar(fs, i) ((fs)->f->locvars[(fs)->actvar[i]]) |
| 30 | 30 | ||
| 31 | #define luaY_checklimit(fs,v,l,m) if ((v)>(l)) luaY_errorlimit(fs,l,m) | ||
| 31 | 32 | ||
| 32 | #define enterlevel(ls) if (++(ls)->nestlevel > LUA_MAXPARSERLEVEL) \ | 33 | #define enterlevel(ls) if (++(ls)->nestlevel > LUA_MAXPARSERLEVEL) \ |
| 33 | luaX_syntaxerror(ls, "too many syntax levels"); | 34 | luaX_lexerror(ls, "chunk has too many syntax levels", 0) |
| 34 | #define leavelevel(ls) ((ls)->nestlevel--) | 35 | #define leavelevel(ls) ((ls)->nestlevel--) |
| 35 | 36 | ||
| 36 | 37 | ||
| @@ -86,6 +87,15 @@ static void error_expected (LexState *ls, int token) { | |||
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | 89 | ||
| 90 | static void luaY_errorlimit (FuncState *fs, int limit, const char *what) { | ||
| 91 | const char *msg = (fs->f->lineDefined == 0) ? | ||
| 92 | luaO_pushfstring(fs->L, "main function has more than %d %s", limit, what) : | ||
| 93 | luaO_pushfstring(fs->L, "function at line %d has more than %d %s", | ||
| 94 | fs->f->lineDefined, limit, what); | ||
| 95 | luaX_lexerror(fs->ls, msg, 0); | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 89 | static int testnext (LexState *ls, int c) { | 99 | static int testnext (LexState *ls, int c) { |
| 90 | if (ls->t.token == c) { | 100 | if (ls->t.token == c) { |
| 91 | next(ls); | 101 | next(ls); |
| @@ -163,7 +173,7 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { | |||
| 163 | 173 | ||
| 164 | static void new_localvar (LexState *ls, TString *name, int n) { | 174 | static void new_localvar (LexState *ls, TString *name, int n) { |
| 165 | FuncState *fs = ls->fs; | 175 | FuncState *fs = ls->fs; |
| 166 | luaX_checklimit(ls, fs->nactvar+n+1, MAXVARS, "local variables"); | 176 | luaY_checklimit(fs, fs->nactvar+n+1, MAXVARS, "local variables"); |
| 167 | fs->actvar[fs->nactvar+n] = cast(unsigned short, | 177 | fs->actvar[fs->nactvar+n] = cast(unsigned short, |
| 168 | luaI_registerlocalvar(ls, name)); | 178 | luaI_registerlocalvar(ls, name)); |
| 169 | } | 179 | } |
| @@ -196,7 +206,7 @@ static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { | |||
| 196 | } | 206 | } |
| 197 | } | 207 | } |
| 198 | /* new one */ | 208 | /* new one */ |
| 199 | luaX_checklimit(fs->ls, f->nups + 1, MAXUPVALUES, "upvalues"); | 209 | luaY_checklimit(fs, f->nups + 1, MAXUPVALUES, "upvalues"); |
| 200 | luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, | 210 | luaM_growvector(fs->L, f->upvalues, f->nups, f->sizeupvalues, |
| 201 | TString *, MAX_INT, ""); | 211 | TString *, MAX_INT, ""); |
| 202 | while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; | 212 | while (oldsize < f->sizeupvalues) f->upvalues[oldsize++] = NULL; |
| @@ -441,7 +451,7 @@ static void recfield (LexState *ls, struct ConsControl *cc) { | |||
| 441 | int reg = ls->fs->freereg; | 451 | int reg = ls->fs->freereg; |
| 442 | expdesc key, val; | 452 | expdesc key, val; |
| 443 | if (ls->t.token == TK_NAME) { | 453 | if (ls->t.token == TK_NAME) { |
| 444 | luaX_checklimit(ls, cc->nh, MAX_INT, "items in a constructor"); | 454 | luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); |
| 445 | cc->nh++; | 455 | cc->nh++; |
| 446 | checkname(ls, &key); | 456 | checkname(ls, &key); |
| 447 | } | 457 | } |
| @@ -485,7 +495,7 @@ static void lastlistfield (FuncState *fs, struct ConsControl *cc) { | |||
| 485 | 495 | ||
| 486 | static void listfield (LexState *ls, struct ConsControl *cc) { | 496 | static void listfield (LexState *ls, struct ConsControl *cc) { |
| 487 | expr(ls, &cc->v); | 497 | expr(ls, &cc->v); |
| 488 | luaX_checklimit(ls, cc->na, MAXARG_Bx, "items in a constructor"); | 498 | luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor"); |
| 489 | cc->na++; | 499 | cc->na++; |
| 490 | cc->tostore++; | 500 | cc->tostore++; |
| 491 | } | 501 | } |
