| 232 | */ |
| 233 | |
| 234 | void FixLocalNames(GluaDecompileContextP ctx, Proto* f, std::string funcnumstr) { |
| 235 | int i; |
| 236 | std::string tmpname; |
| 237 | int need_arg = NEED_ARG(f); |
| 238 | int func_endpc = FUNC_BLOCK_END(f); |
| 239 | |
| 240 | if (f->sizelocvars < f->numparams + need_arg) { |
| 241 | f->locvars = luaM_reallocvector(ctx->glstate, f->locvars, f->sizelocvars, f->numparams + need_arg, LocVar); |
| 242 | for (i = 0; i < f->numparams; i++) { |
| 243 | tmpname = std::string("p_") + funcnumstr + "_" + std::to_string(i); |
| 244 | f->locvars[i].varname = luaS_new(ctx->glstate, tmpname.c_str()); |
| 245 | f->locvars[i].startpc = 0; |
| 246 | f->locvars[i].endpc = func_endpc; |
| 247 | } |
| 248 | if (need_arg) { |
| 249 | tmpname = "arg"; |
| 250 | f->locvars[i].varname = luaS_new(ctx->glstate, tmpname.c_str()); |
| 251 | f->locvars[i].startpc = 0; |
| 252 | f->locvars[i].endpc = func_endpc; |
| 253 | } |
| 254 | f->sizelocvars = f->numparams + need_arg; |
| 255 | } |
| 256 | for (i = 0; i < f->sizelocvars; i++) { |
| 257 | TString* name = f->locvars[i].varname; |
| 258 | if (name == nullptr || LUA_STRLEN(name) == 0 || |
| 259 | strlen(getstr(name)) == 0 || !isIdentifier(getstr(name))) { |
| 260 | tmpname = std::string("l_") + funcnumstr + "_" + std::to_string(i); |
| 261 | name = luaS_new(ctx->glstate, tmpname.c_str()); |
| 262 | f->locvars[i].varname = name; |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // i : index of Proto.locvars, not reg number |
| 268 | std::string getLocalName(GluaDecompileContextP ctx, const Proto* f, int i) { |
no test coverage detected