-------------------------------------------------------------- find the scope of a variable in relative to the current context * return: -1 if is global variable * 0 if from current function parameters * 1 if from top level block of same function * ... * n if from block of depth n * INVISIBLE if not visible in current context * IN
| 480 | * active on stack frame neither |
| 481 | **************************************************************/ |
| 482 | int |
| 483 | CGContext::find_variable_scope(const Variable* var) const |
| 484 | { |
| 485 | if (var->is_global()) { |
| 486 | return -1; |
| 487 | } |
| 488 | Function *func = get_current_func(); |
| 489 | assert(func); |
| 490 | |
| 491 | int i; |
| 492 | for (i=0; i<(int)func->param.size(); i++) { |
| 493 | if (func->param[i]->match(var)) { |
| 494 | return 0; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | // check if visible in current function |
| 499 | const Block* b = get_current_block(); |
| 500 | i = 1; |
| 501 | do { |
| 502 | if (find_variable_in_set(b->local_vars, var) != -1) { |
| 503 | return i; |
| 504 | } |
| 505 | b = b->parent; |
| 506 | i++; |
| 507 | } while (b); |
| 508 | |
| 509 | // check if exist on one of the stack frames |
| 510 | for (i=call_chain.size()-1; i>=0; i--) { |
| 511 | b = call_chain[i]; |
| 512 | do { |
| 513 | if (find_variable_in_set(b->local_vars, var) != -1) { |
| 514 | return INVISIBLE; |
| 515 | } |
| 516 | b = b->parent; |
| 517 | i++; |
| 518 | } while (b); |
| 519 | } |
| 520 | |
| 521 | return INACTIVE; |
| 522 | } |
| 523 | |
| 524 | void CGContext::extend_call_chain(const CGContext& cg_context) |
| 525 | { |
nothing calls this directly
no test coverage detected