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

Method AppendedObjectInit

IDEHelper/Compiler/BfModule.cpp:4889–4985  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4887}
4888
4889void BfModule::AppendedObjectInit(BfFieldInstance* fieldInst)
4890{
4891 BfExprEvaluator exprEvaluator(this);
4892
4893 bool failed = false;
4894
4895 auto fieldDef = fieldInst->GetFieldDef();
4896 auto initializer = fieldDef->GetInitializer();
4897
4898 BfResolvedArgs resolvedArgs;
4899 if (auto invocationExpr = BfNodeDynCast<BfInvocationExpression>(initializer))
4900 {
4901 bool isDot = false;
4902
4903 if (auto memberRefExpr = BfNodeDynCast<BfMemberReferenceExpression>(invocationExpr->mTarget))
4904 isDot = (memberRefExpr->mTarget == NULL) && (memberRefExpr->mMemberName == NULL);
4905
4906 if (!isDot)
4907 {
4908 auto resolvedType = ResolveTypeRef(invocationExpr->mTarget, {});
4909 if ((resolvedType == NULL) || (resolvedType != fieldInst->mResolvedType))
4910 failed = true;
4911 }
4912
4913 SetAndRestoreValue<BfType*> prevExpectingType(exprEvaluator.mExpectingType, fieldInst->mResolvedType);
4914
4915 resolvedArgs.Init(invocationExpr->mOpenParen, &invocationExpr->mArguments, &invocationExpr->mCommas, invocationExpr->mCloseParen);
4916 exprEvaluator.ResolveArgValues(resolvedArgs, BfResolveArgsFlag_DeferParamEval);
4917 }
4918 else if (initializer != NULL)
4919 {
4920 GetFieldInitializerValue(fieldInst);
4921 failed = true;
4922 }
4923
4924 if (failed)
4925 Fail("Append fields can only be initialized with a call to their constructor", initializer);
4926
4927 auto intType = GetPrimitiveType(BfTypeCode_IntPtr);
4928 auto int8Type = mBfIRBuilder->GetPrimitiveType(BfTypeCode_Int8);
4929 auto ptrType = mBfIRBuilder->GetPointerTo(int8Type);
4930 auto ptrPtrType = mBfIRBuilder->GetPointerTo(ptrType);
4931
4932 auto fieldTypeInst = fieldInst->mResolvedType->ToTypeInstance();
4933
4934 BfIRValue fieldAddr;
4935 if (fieldDef->mIsStatic)
4936 {
4937 auto fieldTypedValue = ReferenceStaticField(fieldInst);
4938
4939 int dataSize = 1;
4940 int alignSize = 1;
4941 TryGetAppendedObjectInfo(fieldInst, dataSize, alignSize);
4942
4943 String dataName;
4944 BfMangler::MangleStaticFieldName(dataName, mCompiler->GetMangleKind(), mCurTypeInstance, fieldDef->mName, fieldInst->mResolvedType);
4945 dataName += "__DATA";
4946

Callers

nothing calls this directly

Calls 15

FailFunction · 0.85
BfTypedValueClass · 0.85
GetFieldDefMethod · 0.80
GetInitializerMethod · 0.80
GetMangleKindMethod · 0.80
CreateGlobalVariableMethod · 0.80
CreateConstArrayZeroMethod · 0.80
MapTypeMethod · 0.80
CreateInBoundsGEPMethod · 0.80
CreatePtrToIntMethod · 0.80

Tested by

no test coverage detected