| 151 | } |
| 152 | |
| 153 | void BfContext::AssignModule(BfType* type) |
| 154 | { |
| 155 | auto typeInst = type->ToTypeInstance(); |
| 156 | if (typeInst->mModule != NULL) |
| 157 | { |
| 158 | BF_ASSERT(!typeInst->mModule->mIsReified); |
| 159 | } |
| 160 | |
| 161 | BfModule* module = NULL; |
| 162 | bool needsModuleInit = false; |
| 163 | |
| 164 | // We used to have this "IsReified" check, but we DO want to create modules for unreified types even if they remain unused. |
| 165 | // What was that IsReified check catching? |
| 166 | // It screwed up the reification of generic types- they just got switched to mScratchModule from mUnreifiedModule, but didn't ever generate code. |
| 167 | if (/*(!type->IsReified()) ||*/ (type->IsUnspecializedType()) || (type->IsVar()) || (type->IsTypeAlias()) || (type->IsFunction())) |
| 168 | { |
| 169 | if (typeInst->mIsReified) |
| 170 | module = mScratchModule; |
| 171 | else |
| 172 | module = mUnreifiedModule; |
| 173 | typeInst->mModule = module; |
| 174 | BfTypeProcessRequest* typeProcessEntry = mPopulateTypeWorkList.Alloc(); |
| 175 | typeProcessEntry->mType = type; |
| 176 | BF_ASSERT(typeProcessEntry->mType->mContext == this); |
| 177 | BfLogSysM("HandleTypeWorkItem: %p -> %p\n", type, typeProcessEntry->mType); |
| 178 | mCompiler->mStats.mTypesQueued++; |
| 179 | mCompiler->UpdateCompletion(); |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | auto typeInst = type->ToTypeInstance(); |
| 184 | BF_ASSERT(typeInst != NULL); |
| 185 | |
| 186 | auto project = typeInst->mTypeDef->mProject; |
| 187 | if ((project->mSingleModule) && (typeInst->mIsReified)) |
| 188 | { |
| 189 | BfModule** modulePtr = NULL; |
| 190 | if (mProjectModule.TryAdd(project, NULL, &modulePtr)) |
| 191 | { |
| 192 | String moduleName = project->mName; |
| 193 | module = new BfModule(this, moduleName); |
| 194 | module->mIsReified = true; |
| 195 | module->mProject = project; |
| 196 | typeInst->mModule = module; |
| 197 | BF_ASSERT(!mLockModules); |
| 198 | mModules.push_back(module); |
| 199 | *modulePtr = module; |
| 200 | needsModuleInit = true; |
| 201 | } |
| 202 | else |
| 203 | { |
| 204 | module = *modulePtr; |
| 205 | typeInst->mModule = module; |
| 206 | } |
| 207 | } |
| 208 | else |
| 209 | { |
| 210 | StringT<256> moduleName; |
nothing calls this directly
no test coverage detected