| 12339 | } |
| 12340 | |
| 12341 | BfIRValue 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 | } |
no test coverage detected