MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / FixLocalNames

Function FixLocalNames

src/Chain/libraries/glua/glua_decompile.cpp:234–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232*/
233
234void 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
268std::string getLocalName(GluaDecompileContextP ctx, const Proto* f, int i) {

Callers 1

ProcessCodeFunction · 0.85

Calls 5

luaS_newFunction · 0.85
isIdentifierFunction · 0.85
stringClass · 0.50
to_stringFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected