Restores previous number of defined variables and functions to hide those that lost visibility
| 408 | } |
| 409 | // Restores previous number of defined variables and functions to hide those that lost visibility |
| 410 | void EndBlock(bool hideFunctions, bool saveLocals) |
| 411 | { |
| 412 | if(currDefinedFunc.size() > 0 && currDefinedFunc.back()->closeUpvals && (varInfoTop.size() - currDefinedFunc.back()->vTopSize - 1) < currDefinedFunc.back()->maxBlockDepth) |
| 413 | CodeInfo::nodeList.push_back(new NodeBlock(currDefinedFunc.back(), varInfoTop.size() - currDefinedFunc.back()->vTopSize - 1)); |
| 414 | |
| 415 | if(currDefinedFunc.size() > 0 && saveLocals) |
| 416 | { |
| 417 | FunctionInfo &lastFunc = *currDefinedFunc.back(); |
| 418 | for(unsigned int i = varInfoTop.back().activeVarCnt; i < CodeInfo::varInfo.size(); i++) |
| 419 | { |
| 420 | VariableInfo *firstNext = lastFunc.firstLocal; |
| 421 | lastFunc.firstLocal = CodeInfo::varInfo[i]; |
| 422 | if(!lastFunc.lastLocal) |
| 423 | lastFunc.lastLocal = lastFunc.firstLocal; |
| 424 | lastFunc.firstLocal->next = firstNext; |
| 425 | if(lastFunc.firstLocal->next) |
| 426 | lastFunc.firstLocal->next->prev = lastFunc.firstLocal; |
| 427 | lastFunc.localCount++; |
| 428 | } |
| 429 | }else if(currDefinedFunc.size() == 0 && saveLocals){ |
| 430 | for(unsigned int i = varInfoTop.back().activeVarCnt; i < CodeInfo::varInfo.size(); i++) |
| 431 | { |
| 432 | CodeInfo::varInfo[i]->next = lostGlobalList; |
| 433 | lostGlobalList = CodeInfo::varInfo[i]; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | // Remove variable information from hash map |
| 438 | for(int i = (int)CodeInfo::varInfo.size() - 1; i >= (int)varInfoTop.back().activeVarCnt; i--) |
| 439 | varMap.remove(CodeInfo::varInfo[i]->nameHash, CodeInfo::varInfo[i]); |
| 440 | // Remove variable information from array |
| 441 | CodeInfo::varInfo.shrink(varInfoTop.back().activeVarCnt); |
| 442 | varInfoTop.pop_back(); |
| 443 | |
| 444 | if(hideFunctions) |
| 445 | { |
| 446 | for(unsigned int i = funcInfoTop.back(); i < CodeInfo::funcInfo.size(); i++) |
| 447 | { |
| 448 | // Check that local function prototypes have implementation before they go out of scope |
| 449 | // Skip generic functions and function prototypes for generic function instances |
| 450 | if(!CodeInfo::funcInfo[i]->implemented && !(CodeInfo::funcInfo[i]->address & 0x80000000) && !CodeInfo::funcInfo[i]->generic && !CodeInfo::funcInfo[i]->genericBase) |
| 451 | ThrowError(CodeInfo::lastKnownStartPos, "ERROR: local function '%s' went out of scope unimplemented", CodeInfo::funcInfo[i]->name); |
| 452 | // generic function instance will go out of scope only when base function goes out of scope |
| 453 | // member function of a generic type will never go out of scope |
| 454 | CodeInfo::funcInfo[i]->visible = CodeInfo::funcInfo[i]->parentClass ? true : (CodeInfo::funcInfo[i]->genericBase ? CodeInfo::funcInfo[i]->genericBase->parent->visible : false); |
| 455 | } |
| 456 | } |
| 457 | funcInfoTop.pop_back(); |
| 458 | |
| 459 | // Check delayed function instances |
| 460 | for(unsigned i = 0; i < delayedInstance.size(); i++) |
| 461 | { |
| 462 | // If the current scope is equal to generic function scope, instantiate it |
| 463 | if(delayedInstance[i] && delayedInstance[i]->vTopSize == varInfoTop.size()) |
| 464 | { |
| 465 | // Take prototype info |
| 466 | FunctionInfo *fProto = delayedInstance[i]; |
| 467 | // Mark function as instanced |
no test coverage detected