| 5228 | } |
| 5229 | |
| 5230 | void BfModule::CreateDelegateEqualsMethod() |
| 5231 | { |
| 5232 | if (mBfIRBuilder->mIgnoreWrites) |
| 5233 | return; |
| 5234 | |
| 5235 | auto refNode = mCurTypeInstance->mTypeDef->GetRefNode(); |
| 5236 | if (refNode == NULL) |
| 5237 | refNode = mCompiler->mValueTypeTypeDef->GetRefNode(); |
| 5238 | UpdateSrcPos(refNode); |
| 5239 | SetIllegalSrcPos(); |
| 5240 | |
| 5241 | auto boolType = GetPrimitiveType(BfTypeCode_Boolean); |
| 5242 | auto resultVal = CreateAlloca(boolType); |
| 5243 | mBfIRBuilder->CreateStore(GetConstValue(0, boolType), resultVal); |
| 5244 | |
| 5245 | auto exitBB = mBfIRBuilder->CreateBlock("exit"); |
| 5246 | |
| 5247 | auto delegateType = ResolveTypeDef(mCompiler->mDelegateTypeDef)->ToTypeInstance(); |
| 5248 | mBfIRBuilder->PopulateType(delegateType); |
| 5249 | |
| 5250 | BfExprEvaluator exprEvaluator(this); |
| 5251 | BfTypedValue leftTypedVal = exprEvaluator.LoadLocal(mCurMethodState->mLocals[0]); |
| 5252 | BfTypedValue lhsDelegate = BfTypedValue(mBfIRBuilder->CreateBitCast(leftTypedVal.mValue, mBfIRBuilder->MapType(delegateType)), delegateType); |
| 5253 | |
| 5254 | BfTypedValue rhsDelegate = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]); |
| 5255 | rhsDelegate = LoadValue(rhsDelegate); |
| 5256 | BfTypedValue rightTypedVal = BfTypedValue(mBfIRBuilder->CreateBitCast(rhsDelegate.mValue, mBfIRBuilder->MapType(mCurTypeInstance)), mCurTypeInstance); |
| 5257 | |
| 5258 | auto& targetFieldInstance = delegateType->mFieldInstances[0]; |
| 5259 | |
| 5260 | BfTypedValue leftValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(lhsDelegate.mValue, 0, targetFieldInstance.mDataIdx), targetFieldInstance.mResolvedType, true); |
| 5261 | BfTypedValue rightValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(rhsDelegate.mValue, 0, targetFieldInstance.mDataIdx), targetFieldInstance.mResolvedType, true); |
| 5262 | leftValue = LoadValue(leftValue); |
| 5263 | rightValue = LoadValue(rightValue); |
| 5264 | EmitEquals(leftValue, rightValue, exitBB, false); |
| 5265 | |
| 5266 | bool hadComparison = false; |
| 5267 | for (auto& fieldRef : mCurTypeInstance->mFieldInstances) |
| 5268 | { |
| 5269 | BfFieldInstance* fieldInstance = &fieldRef; |
| 5270 | if (fieldInstance->mDataOffset == -1) |
| 5271 | continue; |
| 5272 | |
| 5273 | auto fieldType = fieldInstance->mResolvedType; |
| 5274 | if (fieldType->IsValuelessType()) |
| 5275 | continue; |
| 5276 | if (fieldType->IsVar()) |
| 5277 | continue; |
| 5278 | if (fieldType->IsMethodRef()) |
| 5279 | continue; |
| 5280 | |
| 5281 | if (fieldType->IsRef()) |
| 5282 | fieldType = CreatePointerType(fieldType->GetUnderlyingType()); |
| 5283 | |
| 5284 | BfTypedValue leftValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(leftTypedVal.mValue, 0, fieldInstance->mDataIdx), fieldType, true); |
| 5285 | BfTypedValue rightValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(rightTypedVal.mValue, 0, fieldInstance->mDataIdx), fieldType, true); |
| 5286 | |
| 5287 | if (!fieldInstance->mResolvedType->IsComposite()) |
nothing calls this directly
no test coverage detected