| 13331 | } |
| 13332 | |
| 13333 | BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue& value, bool allowUndef) |
| 13334 | { |
| 13335 | BfVariant variant; |
| 13336 | variant.mTypeCode = BfTypeCode_None; |
| 13337 | BfType* primType = NULL; |
| 13338 | if (value.mType->IsPrimitiveType()) |
| 13339 | primType = (BfPrimitiveType*)value.mType; |
| 13340 | else if (value.mType->IsTypedPrimitive()) |
| 13341 | primType = value.mType->GetUnderlyingType(); |
| 13342 | else if (value.mType->IsInstanceOf(mCompiler->mStringTypeDef)) |
| 13343 | primType = value.mType; |
| 13344 | |
| 13345 | if (primType) |
| 13346 | { |
| 13347 | auto constant = mBfIRBuilder->GetConstant(value.mValue); |
| 13348 | if (constant != NULL) |
| 13349 | { |
| 13350 | if ((allowUndef) && (constant->mConstType == BfConstType_Undef)) |
| 13351 | { |
| 13352 | variant.mUInt64 = 0; |
| 13353 | variant.mTypeCode = BfTypeCode_Let; |
| 13354 | return variant; |
| 13355 | } |
| 13356 | |
| 13357 | if (constant->mConstType == BfConstType_GlobalVar) |
| 13358 | { |
| 13359 | int stringIdx = GetStringPoolIdx(value.mValue, mBfIRBuilder); |
| 13360 | if (stringIdx != -1) |
| 13361 | { |
| 13362 | variant.mTypeCode = BfTypeCode_StringId; |
| 13363 | variant.mInt64 = stringIdx; |
| 13364 | return variant; |
| 13365 | } |
| 13366 | } |
| 13367 | |
| 13368 | switch (constant->mTypeCode) |
| 13369 | { |
| 13370 | case BfTypeCode_Boolean: |
| 13371 | case BfTypeCode_Int8: |
| 13372 | case BfTypeCode_UInt8: |
| 13373 | case BfTypeCode_Int16: |
| 13374 | case BfTypeCode_UInt16: |
| 13375 | case BfTypeCode_Int32: |
| 13376 | case BfTypeCode_UInt32: |
| 13377 | case BfTypeCode_Int64: |
| 13378 | case BfTypeCode_UInt64: |
| 13379 | case BfTypeCode_IntPtr: |
| 13380 | case BfTypeCode_UIntPtr: |
| 13381 | case BfTypeCode_IntUnknown: |
| 13382 | case BfTypeCode_UIntUnknown: |
| 13383 | case BfTypeCode_Double: |
| 13384 | case BfTypeCode_Char8: |
| 13385 | case BfTypeCode_Char16: |
| 13386 | case BfTypeCode_Char32: |
| 13387 | case BfTypeCode_StringId: |
| 13388 | variant.mTypeCode = constant->mTypeCode; |
| 13389 | if (((variant.mTypeCode == BfTypeCode_Int64) || (variant.mTypeCode == BfTypeCode_UInt64)) && |
| 13390 | (primType->mSize > 0) && (primType->mSize < 8) && |
no test coverage detected