diff options
| -rw-r--r-- | llex.c | 21 | ||||
| -rw-r--r-- | llex.h | 4 | ||||
| -rw-r--r-- | lparser.c | 24 |
3 files changed, 26 insertions, 23 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.128 2003/10/20 12:24:34 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -61,14 +61,6 @@ void luaX_init (lua_State *L) { | |||
| 61 | #define MAXSRC 80 | 61 | #define MAXSRC 80 |
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg) { | ||
| 65 | if (val > limit) { | ||
| 66 | msg = luaO_pushfstring(ls->L, "too many %s (limit=%d)", msg, limit); | ||
| 67 | luaX_syntaxerror(ls, msg); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | const char *luaX_token2str (LexState *ls, int token) { | 64 | const char *luaX_token2str (LexState *ls, int token) { |
| 73 | if (token < FIRST_RESERVED) { | 65 | if (token < FIRST_RESERVED) { |
| 74 | lua_assert(token == (unsigned char)token); | 66 | lua_assert(token == (unsigned char)token); |
| @@ -93,11 +85,12 @@ static const char *txtToken (LexState *ls, int token) { | |||
| 93 | } | 85 | } |
| 94 | 86 | ||
| 95 | 87 | ||
| 96 | static void luaX_lexerror (LexState *ls, const char *msg, int token) { | 88 | void luaX_lexerror (LexState *ls, const char *msg, int token) { |
| 97 | char buff[MAXSRC]; | 89 | char buff[MAXSRC]; |
| 98 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); | 90 | luaO_chunkid(buff, getstr(ls->source), MAXSRC); |
| 99 | luaO_pushfstring(ls->L, "%s:%d: %s near `%s'", | 91 | msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); |
| 100 | buff, ls->linenumber, msg, txtToken(ls, token)); | 92 | if (token) |
| 93 | luaO_pushfstring(ls->L, "%s near `%s'", msg, txtToken(ls, token)); | ||
| 101 | luaD_throw(ls->L, LUA_ERRSYNTAX); | 94 | luaD_throw(ls->L, LUA_ERRSYNTAX); |
| 102 | } | 95 | } |
| 103 | 96 | ||
| @@ -123,8 +116,8 @@ static void inclinenumber (LexState *ls) { | |||
| 123 | next(ls); /* skip `\n' or `\r' */ | 116 | next(ls); /* skip `\n' or `\r' */ |
| 124 | if (currIsNewline(ls) && ls->current != old) | 117 | if (currIsNewline(ls) && ls->current != old) |
| 125 | next(ls); /* skip `\n\r' or `\r\n' */ | 118 | next(ls); /* skip `\n\r' or `\r\n' */ |
| 126 | ++ls->linenumber; | 119 | if (++ls->linenumber >= MAX_INT) |
| 127 | luaX_checklimit(ls, ls->linenumber, MAX_INT, "lines in a chunk"); | 120 | luaX_syntaxerror(ls, "chunk has too many lines"); |
| 128 | } | 121 | } |
| 129 | 122 | ||
| 130 | 123 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.h,v 1.48 2003/08/27 21:01:44 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.49 2003/10/20 12:24:34 roberto Exp roberto $ |
| 3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -67,7 +67,7 @@ void luaX_init (lua_State *L); | |||
| 67 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); | 67 | void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source); |
| 68 | TString *luaX_newstring (LexState *LS, const char *str, size_t l); | 68 | TString *luaX_newstring (LexState *LS, const char *str, size_t l); |
| 69 | int luaX_lex (LexState *LS, SemInfo *seminfo); | 69 | int luaX_lex (LexState *LS, SemInfo *seminfo); |
| 70 | void luaX_checklimit (LexState *ls, int val, int limit, const char *msg); | 70 | void luaX_lexerror (LexState *ls, const char *msg, int token); |
| 71 | void luaX_syntaxerror (LexState *ls, const char *s); | 71 | void luaX_syntaxerror (LexState *ls, const char *s); |
| 72 | const char *luaX_token2str (LexState *ls, int token); | 72 | const char *luaX_token2str (LexState *ls, int token); |
| 73 | 73 | ||
| @@ -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 | } |
