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

Method GetTypedValueFromConstant

IDEHelper/Compiler/BfModule.cpp:12197–12277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12195}
12196
12197BfTypedValue BfModule::GetTypedValueFromConstant(BfConstant* constant, BfIRConstHolder* constHolder, BfType* wantType)
12198{
12199 switch (constant->mTypeCode)
12200 {
12201 case BfTypeCode_StringId:
12202 case BfTypeCode_Boolean:
12203 case BfTypeCode_Int8:
12204 case BfTypeCode_UInt8:
12205 case BfTypeCode_Int16:
12206 case BfTypeCode_UInt16:
12207 case BfTypeCode_Int32:
12208 case BfTypeCode_UInt32:
12209 case BfTypeCode_Int64:
12210 case BfTypeCode_UInt64:
12211 case BfTypeCode_IntPtr:
12212 case BfTypeCode_UIntPtr:
12213 case BfTypeCode_IntUnknown:
12214 case BfTypeCode_UIntUnknown:
12215 case BfTypeCode_Char8:
12216 case BfTypeCode_Char16:
12217 case BfTypeCode_Char32:
12218 case BfTypeCode_Float:
12219 case BfTypeCode_Double:
12220 {
12221 auto constVal = mBfIRBuilder->CreateConst(constant, constHolder);
12222 BfTypedValue typedValue;
12223
12224 bool allowUnactualized = mBfIRBuilder->mIgnoreWrites;
12225 if (constant->mTypeCode == BfTypeCode_StringId)
12226 {
12227 if ((wantType->IsInstanceOf(mCompiler->mStringTypeDef)) ||
12228 ((wantType->IsPointer()) && (wantType->GetUnderlyingType() == GetPrimitiveType(BfTypeCode_Char8))))
12229 {
12230 typedValue = BfTypedValue(ConstantToCurrent(constant, constHolder, wantType, allowUnactualized), wantType);
12231 return typedValue;
12232 }
12233
12234 auto stringType = ResolveTypeDef(mCompiler->mStringTypeDef);
12235 typedValue = BfTypedValue(ConstantToCurrent(constant, constHolder, stringType, allowUnactualized), stringType);
12236 }
12237
12238 if (!typedValue)
12239 {
12240 auto constVal = mBfIRBuilder->CreateConst(constant, constHolder);
12241 typedValue = BfTypedValue(constVal, GetPrimitiveType(constant->mTypeCode));
12242 }
12243
12244 if (typedValue.mType == wantType)
12245 return typedValue;
12246 if (wantType->IsTypedPrimitive())
12247 {
12248 if (typedValue.mType == wantType->GetUnderlyingType())
12249 {
12250 typedValue.mType = wantType;
12251 return typedValue;
12252 }
12253 }
12254 auto castedTypedValue = Cast(NULL, typedValue, wantType, (BfCastFlags)(BfCastFlags_SilentFail | BfCastFlags_Explicit));

Callers 2

CreateCallMethod · 0.80

Calls 8

BfTypedValueClass · 0.85
CreateConstMethod · 0.45
IsInstanceOfMethod · 0.45
IsPointerMethod · 0.45
GetUnderlyingTypeMethod · 0.45
IsTypedPrimitiveMethod · 0.45
PopulateTypeMethod · 0.45
IsCompositeMethod · 0.45

Tested by

no test coverage detected