| 19442 | } |
| 19443 | |
| 19444 | void BfModule::EmitEnumToStringBody() |
| 19445 | { |
| 19446 | auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef); |
| 19447 | auto strVal = CreateAlloca(stringType); |
| 19448 | |
| 19449 | auto int64StructType = GetPrimitiveStructType(BfTypeCode_Int64); |
| 19450 | |
| 19451 | BfExprEvaluator exprEvaluator(this); |
| 19452 | auto stringDestAddr = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]); |
| 19453 | |
| 19454 | BfIRBlock appendBlock = mBfIRBuilder->CreateBlock("append"); |
| 19455 | BfIRBlock noMatchBlock = mBfIRBuilder->CreateBlock("noMatch"); |
| 19456 | BfIRBlock endBlock = mBfIRBuilder->CreateBlock("end"); |
| 19457 | |
| 19458 | BfType* discriminatorType = NULL; |
| 19459 | |
| 19460 | BfTypedValue rawPayload; |
| 19461 | BfIRValue enumVal; |
| 19462 | if (mCurTypeInstance->IsPayloadEnum()) |
| 19463 | { |
| 19464 | discriminatorType = mCurTypeInstance->GetDiscriminatorType(); |
| 19465 | auto enumTypedValue = ExtractValue(GetThis(), NULL, 2); |
| 19466 | enumTypedValue = LoadValue(enumTypedValue); |
| 19467 | enumVal = enumTypedValue.mValue; |
| 19468 | rawPayload = ExtractValue(GetThis(), NULL, 1); |
| 19469 | } |
| 19470 | else |
| 19471 | enumVal = LoadValue(GetThis()).mValue; |
| 19472 | |
| 19473 | Array<BfType*> paramTypes; |
| 19474 | paramTypes.Add(stringType); |
| 19475 | auto appendModuleMethodInstance = GetMethodByName(stringType->ToTypeInstance(), "Append", paramTypes); |
| 19476 | |
| 19477 | BfIRValue switchVal; |
| 19478 | if (!mCurTypeInstance->IsValuelessType()) |
| 19479 | switchVal = mBfIRBuilder->CreateSwitch(enumVal, noMatchBlock, (int)mCurTypeInstance->mFieldInstances.size()); |
| 19480 | |
| 19481 | HashSet<int64> handledCases; |
| 19482 | for (auto& fieldInstance : mCurTypeInstance->mFieldInstances) |
| 19483 | { |
| 19484 | if (fieldInstance.mIsEnumPayloadCase) |
| 19485 | { |
| 19486 | int tagId = -fieldInstance.mDataIdx - 1; |
| 19487 | |
| 19488 | BfIRBlock caseBlock = mBfIRBuilder->CreateBlock("case"); |
| 19489 | mBfIRBuilder->AddBlock(caseBlock); |
| 19490 | mBfIRBuilder->SetInsertPoint(caseBlock); |
| 19491 | BF_ASSERT(discriminatorType->IsPrimitiveType()); |
| 19492 | auto constVal = mBfIRBuilder->CreateConst(((BfPrimitiveType*)discriminatorType)->mTypeDef->mTypeCode, tagId); |
| 19493 | mBfIRBuilder->AddSwitchCase(switchVal, constVal, caseBlock); |
| 19494 | |
| 19495 | auto caseStr = GetStringObjectValue(fieldInstance.GetFieldDef()->mName); |
| 19496 | |
| 19497 | auto stringDestVal = LoadValue(stringDestAddr); |
| 19498 | SizedArray<BfIRValue, 2> args; |
| 19499 | args.Add(stringDestVal.mValue); |
| 19500 | args.Add(caseStr); |
| 19501 | exprEvaluator.CreateCall(NULL, appendModuleMethodInstance.mMethodInstance, appendModuleMethodInstance.mFunc, false, args); |
nothing calls this directly
no test coverage detected