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

Method CreateStaticField

IDEHelper/Compiler/BfModule.cpp:4232–4297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4230}
4231
4232void BfModule::CreateStaticField(BfFieldInstance* fieldInstance, bool isThreadLocal)
4233{
4234 auto fieldType = fieldInstance->GetResolvedType();
4235 auto field = fieldInstance->GetFieldDef();
4236 if (fieldType->IsVar())
4237 return;
4238
4239 BfIRValue initValue;
4240
4241 if (field->mIsConst)
4242 {
4243 if (fieldType->IsPointer())
4244 fieldType = fieldType->GetUnderlyingType();
4245 }
4246
4247 BfIRStorageKind storageKind = BfIRStorageKind_Normal;
4248 if ((fieldInstance->mCustomAttributes != NULL) && (fieldInstance->mCustomAttributes->Get(mCompiler->mExportAttributeTypeDef)))
4249 storageKind = BfIRStorageKind_Export;
4250 else if ((fieldInstance->mCustomAttributes != NULL) && (fieldInstance->mCustomAttributes->Get(mCompiler->mImportAttributeTypeDef)))
4251 storageKind = BfIRStorageKind_Import;
4252
4253 if ((!field->mIsExtern) && (storageKind != BfIRStorageKind_Import))
4254 initValue = GetDefaultValue(fieldType);
4255
4256 if (fieldInstance->mOwner->IsUnspecializedType())
4257 {
4258 // Placeholder
4259 auto ptrVal = CreatePointerType(fieldType);
4260 mStaticFieldRefs[fieldInstance] = GetDefaultValue(ptrVal);
4261 }
4262 else
4263 {
4264 BfLogSysM("Creating static field Module:%p Type:%p\n", this, fieldType);
4265 StringT<4096> staticVarName;
4266 BfMangler::Mangle(staticVarName, mCompiler->GetMangleKind(), fieldInstance);
4267 if ((!fieldType->IsValuelessType()) && (!staticVarName.StartsWith("#")))
4268 {
4269 BfIRType irType;
4270
4271 if ((fieldInstance->IsAppendedObject()) && (!field->mIsStatic))
4272 {
4273 irType = mBfIRBuilder->MapTypeInst(fieldType->ToTypeInstance(), BfIRPopulateType_Eventually_Full);
4274 initValue = mBfIRBuilder->CreateConstAggZero(irType);
4275 }
4276 else
4277 irType = mBfIRBuilder->MapType(fieldType, BfIRPopulateType_Eventually_Full);
4278
4279 if (fieldType->mSize > 0)
4280 {
4281 BfIRValue globalVar = mBfIRBuilder->CreateGlobalVariable(
4282 irType,
4283 false,
4284 BfIRLinkageType_External,
4285 initValue,
4286 staticVarName,
4287 isThreadLocal);
4288 mBfIRBuilder->GlobalVar_SetAlignment(globalVar, fieldType->mAlign);
4289 if (storageKind != BfIRStorageKind_Normal)

Callers 1

CreateTypeDefinitionMethod · 0.80

Calls 15

GetResolvedTypeMethod · 0.80
GetFieldDefMethod · 0.80
GetMangleKindMethod · 0.80
IsAppendedObjectMethod · 0.80
MapTypeInstMethod · 0.80
CreateConstAggZeroMethod · 0.80
MapTypeMethod · 0.80
CreateGlobalVariableMethod · 0.80
IsVarMethod · 0.45
IsPointerMethod · 0.45

Tested by

no test coverage detected