diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-10-03 13:04:24 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-10-03 13:04:24 -0300 |
| commit | 3a508b8bd70405067c07ba82ded57a7a177eaa48 (patch) | |
| tree | bc64babc89e941b742d643e3084e6541243a467d | |
| parent | 6becdb3e7070cb44f9ea9fd88fbf23719c9b58d5 (diff) | |
| download | lua-3a508b8bd70405067c07ba82ded57a7a177eaa48.tar.gz lua-3a508b8bd70405067c07ba82ded57a7a177eaa48.tar.bz2 lua-3a508b8bd70405067c07ba82ded57a7a177eaa48.zip | |
avoid the use of `strlen' (strings are literals)
| -rw-r--r-- | lparser.c | 28 |
1 files changed, 13 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.218 2003/09/05 14:00:27 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.219 2003/09/29 16:41:35 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 | */ |
| @@ -156,6 +156,10 @@ static int luaI_registerlocalvar (LexState *ls, TString *varname) { | |||
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | 158 | ||
| 159 | #define new_localvarliteral(ls,v,n) \ | ||
| 160 | new_localvar(ls, luaX_newstring(ls, "" v, (sizeof(v)/sizeof(char))-1), n) | ||
| 161 | |||
| 162 | |||
| 159 | static void new_localvar (LexState *ls, TString *name, int n) { | 163 | static void new_localvar (LexState *ls, TString *name, int n) { |
| 160 | FuncState *fs = ls->fs; | 164 | FuncState *fs = ls->fs; |
| 161 | luaX_checklimit(ls, fs->nactvar+n+1, MAXVARS, "local variables"); | 165 | luaX_checklimit(ls, fs->nactvar+n+1, MAXVARS, "local variables"); |
| @@ -180,12 +184,6 @@ static void removevars (LexState *ls, int tolevel) { | |||
| 180 | } | 184 | } |
| 181 | 185 | ||
| 182 | 186 | ||
| 183 | static void new_localvarstr (LexState *ls, const char *name, int n) { | ||
| 184 | TString *ts = luaX_newstring(ls, name, strlen(name)); | ||
| 185 | new_localvar(ls, ts, n); | ||
| 186 | } | ||
| 187 | |||
| 188 | |||
| 189 | static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { | 187 | static int indexupvalue (FuncState *fs, TString *name, expdesc *v) { |
| 190 | int i; | 188 | int i; |
| 191 | Proto *f = fs->f; | 189 | Proto *f = fs->f; |
| @@ -556,7 +554,7 @@ static void parlist (LexState *ls) { | |||
| 556 | case TK_DOTS: { /* param -> `...' */ | 554 | case TK_DOTS: { /* param -> `...' */ |
| 557 | next(ls); | 555 | next(ls); |
| 558 | /* use `arg' as default name */ | 556 | /* use `arg' as default name */ |
| 559 | new_localvarstr(ls, "arg", nparams++); | 557 | new_localvarliteral(ls, "arg", nparams++); |
| 560 | f->is_vararg = 1; | 558 | f->is_vararg = 1; |
| 561 | break; | 559 | break; |
| 562 | } | 560 | } |
| @@ -577,7 +575,7 @@ static void body (LexState *ls, expdesc *e, int needself, int line) { | |||
| 577 | new_fs.f->lineDefined = line; | 575 | new_fs.f->lineDefined = line; |
| 578 | check(ls, '('); | 576 | check(ls, '('); |
| 579 | if (needself) { | 577 | if (needself) { |
| 580 | new_localvarstr(ls, "self", 0); | 578 | new_localvarliteral(ls, "self", 0); |
| 581 | adjustlocalvars(ls, 1); | 579 | adjustlocalvars(ls, 1); |
| 582 | } | 580 | } |
| 583 | parlist(ls); | 581 | parlist(ls); |
| @@ -1071,9 +1069,9 @@ static void fornum (LexState *ls, TString *varname, int line) { | |||
| 1071 | /* fornum -> NAME = exp1,exp1[,exp1] forbody */ | 1069 | /* fornum -> NAME = exp1,exp1[,exp1] forbody */ |
| 1072 | FuncState *fs = ls->fs; | 1070 | FuncState *fs = ls->fs; |
| 1073 | int base = fs->freereg; | 1071 | int base = fs->freereg; |
| 1074 | new_localvarstr(ls, "(for index)", 0); | 1072 | new_localvarliteral(ls, "(for index)", 0); |
| 1075 | new_localvarstr(ls, "(for limit)", 1); | 1073 | new_localvarliteral(ls, "(for limit)", 1); |
| 1076 | new_localvarstr(ls, "(for step)", 2); | 1074 | new_localvarliteral(ls, "(for step)", 2); |
| 1077 | new_localvar(ls, varname, 3); | 1075 | new_localvar(ls, varname, 3); |
| 1078 | check(ls, '='); | 1076 | check(ls, '='); |
| 1079 | exp1(ls); /* initial value */ | 1077 | exp1(ls); /* initial value */ |
| @@ -1097,9 +1095,9 @@ static void forlist (LexState *ls, TString *indexname) { | |||
| 1097 | int line; | 1095 | int line; |
| 1098 | int base = fs->freereg; | 1096 | int base = fs->freereg; |
| 1099 | /* create control variables */ | 1097 | /* create control variables */ |
| 1100 | new_localvarstr(ls, "(for generator)", nvars++); | 1098 | new_localvarliteral(ls, "(for generator)", nvars++); |
| 1101 | new_localvarstr(ls, "(for state)", nvars++); | 1099 | new_localvarliteral(ls, "(for state)", nvars++); |
| 1102 | new_localvarstr(ls, "(for control)", nvars++); | 1100 | new_localvarliteral(ls, "(for control)", nvars++); |
| 1103 | /* create declared variables */ | 1101 | /* create declared variables */ |
| 1104 | new_localvar(ls, indexname, nvars++); | 1102 | new_localvar(ls, indexname, nvars++); |
| 1105 | while (testnext(ls, ',')) | 1103 | while (testnext(ls, ',')) |
