| 20327 | } |
| 20328 | |
| 20329 | void BfModule::ProcessMethod_ProcessDeferredLocals(int startIdx) |
| 20330 | { |
| 20331 | // if (mCurMethodState->mPrevMethodState != NULL) // Re-entry |
| 20332 | // return; |
| 20333 | |
| 20334 | auto startMethodState = mCurMethodState; |
| 20335 | |
| 20336 | auto _ClearState = [&]() |
| 20337 | { |
| 20338 | mCurMethodState->mLocalMethods.Clear(); |
| 20339 | |
| 20340 | for (auto& local : mCurMethodState->mLocals) |
| 20341 | { |
| 20342 | if (local->mIsBumpAlloc) |
| 20343 | local->~BfLocalVariable(); |
| 20344 | else |
| 20345 | delete local; |
| 20346 | } |
| 20347 | mCurMethodState->mLocals.Clear(); |
| 20348 | mCurMethodState->mLocalVarSet.Clear(); |
| 20349 | }; |
| 20350 | |
| 20351 | while (true) |
| 20352 | { |
| 20353 | bool didWork = false; |
| 20354 | // Don't process local methods if we had a build error - this isn't just an optimization, it keeps us from showing the same error twice since |
| 20355 | // we show errors in the capture phase. If we somehow pass the capture phase without error then this method WILL show any errors here, |
| 20356 | // however (compiler bug), so this is the safest way |
| 20357 | if (!mCurMethodState->mDeferredLocalMethods.IsEmpty()) |
| 20358 | { |
| 20359 | for (int deferredLocalMethodIdx = 0; deferredLocalMethodIdx < (int)mCurMethodState->mDeferredLocalMethods.size(); deferredLocalMethodIdx++) |
| 20360 | { |
| 20361 | auto deferredLocalMethod = mCurMethodState->mDeferredLocalMethods[deferredLocalMethodIdx]; |
| 20362 | |
| 20363 | BfLogSysM("Processing deferred local method %p\n", deferredLocalMethod); |
| 20364 | |
| 20365 | if (!mHadBuildError) |
| 20366 | { |
| 20367 | // Process as a closure - that allows us to look back and see the const locals and stuff |
| 20368 | BfClosureState closureState; |
| 20369 | mCurMethodState->mClosureState = &closureState; |
| 20370 | closureState.mConstLocals = deferredLocalMethod->mConstLocals; |
| 20371 | closureState.mReturnType = deferredLocalMethod->mMethodInstance->mReturnType; |
| 20372 | closureState.mActiveDeferredLocalMethod = deferredLocalMethod; |
| 20373 | closureState.mLocalMethod = deferredLocalMethod->mLocalMethod; |
| 20374 | if (deferredLocalMethod->mMethodInstance->mMethodInfoEx != NULL) |
| 20375 | closureState.mClosureInstanceInfo = deferredLocalMethod->mMethodInstance->mMethodInfoEx->mClosureInstanceInfo; |
| 20376 | mCurMethodState->mMixinState = deferredLocalMethod->mLocalMethod->mDeclMixinState; |
| 20377 | |
| 20378 | _ClearState(); |
| 20379 | |
| 20380 | for (auto& constLocal : deferredLocalMethod->mConstLocals) |
| 20381 | { |
| 20382 | auto localVar = new BfLocalVariable(); |
| 20383 | *localVar = constLocal; |
| 20384 | DoAddLocalVariable(localVar); |
| 20385 | } |
| 20386 | |