| 8211 | } |
| 8212 | |
| 8213 | void BfModule::CheckStaticAccess(BfTypeInstance* typeInstance) |
| 8214 | { |
| 8215 | // Note: this is not just for perf, it fixes a field var-type resolution issue |
| 8216 | if (mBfIRBuilder->mIgnoreWrites) |
| 8217 | return; |
| 8218 | if (mIsComptimeModule) |
| 8219 | return; |
| 8220 | |
| 8221 | PopulateType(typeInstance, BfPopulateType_DataAndMethods); |
| 8222 | |
| 8223 | //TODO: Create a hashset of these, we don't need to repeatedly call static ctors for a given type |
| 8224 | |
| 8225 | // When we access classes with static constructors FROM a static constructor, |
| 8226 | // we call that other class's static constructor first. Recursion cannot occur, since |
| 8227 | // we simply ignore subsequent attempts to re-enter the constructor |
| 8228 | if (!typeInstance->mHasStaticInitMethod) |
| 8229 | return; |
| 8230 | if ((mCurMethodInstance == NULL) || ((mCurMethodInstance->mMethodDef->mMethodType != BfMethodType_Ctor) || (!mCurMethodInstance->mMethodDef->mIsStatic))) |
| 8231 | return; |
| 8232 | if (mCurMethodInstance->mMethodInstanceGroup->mOwner == typeInstance) |
| 8233 | return; |
| 8234 | |
| 8235 | auto checkTypeDef = typeInstance->mTypeDef; |
| 8236 | checkTypeDef->PopulateMemberSets(); |
| 8237 | BfMethodDef* nextMethodDef = NULL; |
| 8238 | BfMemberSetEntry* entry; |
| 8239 | if (checkTypeDef->mMethodSet.TryGetWith(String("__BfStaticCtor"), &entry)) |
| 8240 | nextMethodDef = (BfMethodDef*)entry->mMemberDef; |
| 8241 | while (nextMethodDef != NULL) |
| 8242 | { |
| 8243 | auto checkMethod = nextMethodDef; |
| 8244 | nextMethodDef = nextMethodDef->mNextWithSameName; |
| 8245 | auto methodModule = GetMethodInstance(typeInstance, checkMethod, BfTypeVector()); |
| 8246 | if (methodModule) |
| 8247 | { |
| 8248 | auto methodInstance = methodModule.mMethodInstance; |
| 8249 | if ((methodInstance != NULL) && |
| 8250 | (methodInstance->mMethodDef->mIsStatic) && |
| 8251 | (methodInstance->mMethodDef->mMethodType == BfMethodType_Ctor) && |
| 8252 | ((methodInstance->mChainType == BfMethodChainType_ChainHead) || (methodInstance->mChainType == BfMethodChainType_None))) |
| 8253 | { |
| 8254 | mBfIRBuilder->CreateCall(methodModule.mFunc, SizedArray<BfIRValue, 0>()); |
| 8255 | break; |
| 8256 | } |
| 8257 | } |
| 8258 | } |
| 8259 | } |
| 8260 | |
| 8261 | BfIRFunction BfModule::GetIntrinsic(BfMethodInstance* methodInstance, bool reportFailure) |
| 8262 | { |
no test coverage detected