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

Method ConstantToCurrent

IDEHelper/Compiler/BfModule.cpp:12341–12541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12339}
12340
12341BfIRValue BfModule::ConstantToCurrent(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType, bool allowUnactualized)
12342{
12343 if (constant->mTypeCode == BfTypeCode_NullPtr)
12344 {
12345 if ((wantType == NULL) && (constant->mIRType.mKind == BfIRTypeData::TypeKind_TypeId))
12346 wantType = mContext->mTypes[constant->mIRType.mId];
12347
12348 if (wantType == NULL)
12349 return mBfIRBuilder->CreateConstNull();
12350
12351 return GetDefaultValue(wantType);
12352 }
12353
12354 if ((constant->mTypeCode == BfTypeCode_StringId) || (constant->mTypeCode == BfTypeCode_CharPtr))
12355 {
12356 if (!allowUnactualized)
12357 {
12358 if ((wantType == NULL) ||
12359 (wantType->IsInstanceOf(mCompiler->mStringTypeDef)) ||
12360 ((wantType->IsPointer()) && (wantType->GetUnderlyingType() == GetPrimitiveType(BfTypeCode_Char8))))
12361 {
12362 const StringImpl& str = mContext->mStringObjectIdMap[constant->mInt32].mString;
12363 BfIRValue stringObjConst = GetStringObjectValue(str, false, true);
12364
12365 bool wantCharPtr = ((wantType != NULL) && (wantType->IsPointer()));
12366 if ((wantType == NULL) && (constant->mTypeCode == BfTypeCode_CharPtr))
12367 wantCharPtr = true;
12368 if (wantCharPtr)
12369 return GetStringCharPtr(stringObjConst, true);
12370 return stringObjConst;
12371 }
12372 }
12373 }
12374
12375 if (constant->mTypeCode == BfTypeCode_CharPtr)
12376 {
12377 if (!allowUnactualized)
12378 {
12379 if ((wantType == NULL) ||
12380 (wantType->IsInstanceOf(mCompiler->mStringTypeDef)) ||
12381 ((wantType->IsPointer()) && (wantType->GetUnderlyingType() == GetPrimitiveType(BfTypeCode_Char8))))
12382 {
12383 const StringImpl& str = mContext->mStringObjectIdMap[constant->mInt32].mString;
12384 BfIRValue stringObjConst = GetStringObjectValue(str, false, true);
12385 if ((wantType != NULL) && (wantType->IsPointer()))
12386 return GetStringCharPtr(stringObjConst, true);
12387 return stringObjConst;
12388 }
12389 }
12390 }
12391
12392 if (constant->mConstType == Beefy::BfConstType_TypeOf)
12393 {
12394 auto constTypeOf = (BfTypeOf_Const*)constant;
12395 if (mCurTypeInstance != NULL)
12396 AddDependency(constTypeOf->mType, mCurTypeInstance, BfDependencyMap::DependencyFlag_ExprTypeReference);
12397 return CreateTypeDataRef(constTypeOf->mType, true);
12398 }

Callers 7

EmitTestMethodMethod · 0.80
CreateAttributeMethod · 0.80
LookupIdentifierMethod · 0.80
LoadFieldMethod · 0.80
GetSelectedMethodMethod · 0.80

Calls 15

BfIRValueClass · 0.85
CreateConstNullMethod · 0.80
GetConstantByIdMethod · 0.80
CreatePtrToIntMethod · 0.80
MapTypeMethod · 0.80
CreateIntToPtrMethod · 0.80
GetUnionInnerTypeMethod · 0.80
CreateConstArrayZeroMethod · 0.80
CreateConstAggMethod · 0.80
IsInstanceOfMethod · 0.45
IsPointerMethod · 0.45
GetUnderlyingTypeMethod · 0.45

Tested by

no test coverage detected