MCPcopy Create free account
hub / github.com/beefytech/Beef / EmitTupleToStringBody

Method EmitTupleToStringBody

IDEHelper/Compiler/BfModule.cpp:19587–19733  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19585}
19586
19587void BfModule::EmitTupleToStringBody()
19588{
19589 auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef);
19590
19591 BfExprEvaluator exprEvaluator(this);
19592
19593 auto stringDestRef = exprEvaluator.LoadLocal(mCurMethodState->mLocals[1]);
19594
19595 Array<BfType*> paramTypes;
19596 paramTypes.Add(GetPrimitiveType(BfTypeCode_Char8));
19597 auto appendCharModuleMethodInstance = GetMethodByName(stringType->ToTypeInstance(), "Append", paramTypes);
19598
19599 paramTypes.Clear();
19600 paramTypes.Add(stringType);
19601 auto appendModuleMethodInstance = GetMethodByName(stringType->ToTypeInstance(), "Append", paramTypes);
19602
19603 auto _AppendChar = [&](char c)
19604 {
19605 SizedArray<BfIRValue, 2> args;
19606 auto stringDestVal = LoadValue(stringDestRef);
19607 args.Add(stringDestVal.mValue);
19608 args.Add(mBfIRBuilder->CreateConst(BfTypeCode_Char8, (int)c));
19609 exprEvaluator.CreateCall(NULL, appendCharModuleMethodInstance.mMethodInstance, appendCharModuleMethodInstance.mFunc, false, args);
19610 };
19611
19612 int fieldIdx = 0;
19613
19614 auto thisValue = GetThis();
19615
19616 auto toStringModuleMethodInstance = GetMethodByName(mContext->mBfObjectType, "ToString", 1);
19617 auto toStringSafeModuleMethodInstance = GetMethodByName(mContext->mBfObjectType, "ToString", 2);
19618 BfIRValue commaStr;
19619
19620 auto iPrintableType = ResolveTypeDef(mCompiler->mIPrintableTypeDef)->ToTypeInstance();
19621 auto printModuleMethodInstance = GetMethodByName(iPrintableType, "Print");
19622
19623 _AppendChar('(');
19624 for (auto& fieldInstance : mCurTypeInstance->mFieldInstances)
19625 {
19626 if (fieldInstance.mDataIdx == -1)
19627 continue;
19628
19629 if (fieldIdx > 0)
19630 {
19631 if (!commaStr)
19632 commaStr = GetStringObjectValue(", ");
19633 SizedArray<BfIRValue, 2> args;
19634 auto stringDestVal = LoadValue(stringDestRef);
19635 args.Add(stringDestVal.mValue);
19636 args.Add(commaStr);
19637 exprEvaluator.CreateCall(NULL, appendModuleMethodInstance.mMethodInstance, appendModuleMethodInstance.mFunc, false, args);
19638 }
19639 fieldIdx++;
19640
19641 if (fieldInstance.mResolvedType->IsValuelessType())
19642 continue;
19643
19644 BfTypedValue fieldValue = ExtractValue(thisValue, &fieldInstance, fieldInstance.mDataIdx);

Callers

nothing calls this directly

Calls 15

TypeToStringFunction · 0.85
LoadLocalMethod · 0.80
MapTypeInstPtrMethod · 0.80
TryDevirtualizeCallMethod · 0.80
IsAddrMethod · 0.80
MapTypeMethod · 0.80
AddMethod · 0.45
ToTypeInstanceMethod · 0.45
ClearMethod · 0.45
CreateConstMethod · 0.45
CreateCallMethod · 0.45

Tested by

no test coverage detected