** Look for an active variable with the name 'n' in the ** function 'fs'. If found, initialize 'var' with it and return ** its expression kind; otherwise return -1. While searching, ** var->u.info==-1 means that the preambular global declaration is ** active (the default while there is no other global declaration); ** var->u.info==-2 means there is no active collective declaration ** (some previou
| 412 | ** collective declaration, if there is one. |
| 413 | */ |
| 414 | static int searchvar (FuncState *fs, TString *n, expdesc *var) { |
| 415 | int i; |
| 416 | for (i = cast_int(fs->nactvar) - 1; i >= 0; i--) { |
| 417 | Vardesc *vd = getlocalvardesc(fs, i); |
| 418 | if (varglobal(vd)) { /* global declaration? */ |
| 419 | if (vd->vd.name == NULL) { /* collective declaration? */ |
| 420 | if (var->u.info < 0) /* no previous collective declaration? */ |
| 421 | var->u.info = fs->firstlocal + i; /* this is the first one */ |
| 422 | } |
| 423 | else { /* global name */ |
| 424 | if (eqstr(n, vd->vd.name)) { /* found? */ |
| 425 | init_exp(var, VGLOBAL, fs->firstlocal + i); |
| 426 | return VGLOBAL; |
| 427 | } |
| 428 | else if (var->u.info == -1) /* active preambular declaration? */ |
| 429 | var->u.info = -2; /* invalidate preambular declaration */ |
| 430 | } |
| 431 | } |
| 432 | else if (eqstr(n, vd->vd.name)) { /* found? */ |
| 433 | if (vd->vd.kind == RDKCTC) /* compile-time constant? */ |
| 434 | init_exp(var, VCONST, fs->firstlocal + i); |
| 435 | else { /* local variable */ |
| 436 | init_var(fs, var, i); |
| 437 | if (vd->vd.kind == RDKVAVAR) /* vararg parameter? */ |
| 438 | var->k = VVARGVAR; |
| 439 | } |
| 440 | return cast_int(var->k); |
| 441 | } |
| 442 | } |
| 443 | return -1; /* not found */ |
| 444 | } |
| 445 | |
| 446 | |
| 447 | /* |
no test coverage detected