| 430 | |
| 431 | |
| 432 | static const char *getobjname (Proto *p, int lastpc, int reg, |
| 433 | const char **name) { |
| 434 | int pc; |
| 435 | *name = luaF_getlocalname(p, reg + 1, lastpc); |
| 436 | if (*name) /* is a local? */ |
| 437 | return "local"; |
| 438 | /* else try symbolic execution */ |
| 439 | pc = findsetreg(p, lastpc, reg); |
| 440 | if (pc != -1) { /* could find instruction? */ |
| 441 | Instruction i = p->code[pc]; |
| 442 | OpCode op = GET_OPCODE(i); |
| 443 | switch (op) { |
| 444 | case OP_MOVE: { |
| 445 | int b = GETARG_B(i); /* move from 'b' to 'a' */ |
| 446 | if (b < GETARG_A(i)) |
| 447 | return getobjname(p, pc, b, name); /* get name for 'b' */ |
| 448 | break; |
| 449 | } |
| 450 | case OP_GETTABUP: |
| 451 | case OP_GETTABLE: { |
| 452 | int k = GETARG_C(i); /* key index */ |
| 453 | int t = GETARG_B(i); /* table index */ |
| 454 | const char *vn = (op == OP_GETTABLE) /* name of indexed variable */ |
| 455 | ? luaF_getlocalname(p, t + 1, pc) |
| 456 | : upvalname(p, t); |
| 457 | kname(p, pc, k, name); |
| 458 | return (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field"; |
| 459 | } |
| 460 | case OP_GETUPVAL: { |
| 461 | *name = upvalname(p, GETARG_B(i)); |
| 462 | return "upvalue"; |
| 463 | } |
| 464 | case OP_LOADK: |
| 465 | case OP_LOADKX: { |
| 466 | int b = (op == OP_LOADK) ? GETARG_Bx(i) |
| 467 | : GETARG_Ax(p->code[pc + 1]); |
| 468 | if (ttisstring(&p->k[b])) { |
| 469 | *name = svalue(&p->k[b]); |
| 470 | return "constant"; |
| 471 | } |
| 472 | break; |
| 473 | } |
| 474 | case OP_SELF: { |
| 475 | int k = GETARG_C(i); /* key index */ |
| 476 | kname(p, pc, k, name); |
| 477 | return "method"; |
| 478 | } |
| 479 | default: break; /* go through to return NULL */ |
| 480 | } |
| 481 | } |
| 482 | return NULL; /* could not find reasonable name */ |
| 483 | } |
| 484 | |
| 485 | |
| 486 | /* |
no test coverage detected