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

Method EvaluateToVariant

IDEHelper/Compiler/BfResolvedTypeUtils.cpp:3319–3357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3317#define HASH_TAG 15
3318
3319BfVariant BfResolvedTypeSet::EvaluateToVariant(LookupContext* ctx, BfExpression* expr, BfType*& outType)
3320{
3321 outType = NULL;
3322
3323 BfMethodState methodState;
3324 methodState.mTempKind = BfMethodState::TempKind_Static;
3325 SetAndRestoreValue<BfMethodState*> prevMethodState;
3326 if (ctx->mModule->mCurMethodState == NULL)
3327 prevMethodState.Init(ctx->mModule->mCurMethodState, &methodState);
3328
3329 BfConstResolver constResolver(ctx->mModule);
3330 BfVariant variant;
3331 constResolver.mBfEvalExprFlags = BfEvalExprFlags_NoCast;
3332 constResolver.mBfEvalExprFlags = (BfEvalExprFlags)(constResolver.mBfEvalExprFlags | BfEvalExprFlags_AllowGenericConstValue);
3333 constResolver.mExpectingType = ctx->mModule->GetPrimitiveType(BfTypeCode_Int64);
3334 auto result = constResolver.Resolve(expr);
3335 if (result)
3336 {
3337 // Limit the types of constants to prevent duplicate values with different types - we don't want to hash a typeref with an int32
3338 // when the constraint requirement is int64 (but we don't know that at hash time)
3339 if ((result.mType->IsInteger()) && ((result.mType->mSize < 8) || (result.mType->GetTypeCode() == BfTypeCode_IntPtr)))
3340 result = ctx->mModule->Cast(expr, result, ctx->mModule->GetPrimitiveType(BfTypeCode_Int64));
3341 else if ((result.mType->IsFloat()) && (result.mType->mSize < 8))
3342 result = ctx->mModule->Cast(expr, result, ctx->mModule->GetPrimitiveType(BfTypeCode_Double));
3343 else if ((result.mType->IsChar()) && (result.mType->mSize < 4))
3344 result = ctx->mModule->Cast(expr, result, ctx->mModule->GetPrimitiveType(BfTypeCode_Char32));
3345 outType = result.mType;
3346
3347 if (result.mKind == BfTypedValueKind_GenericConstValue)
3348 {
3349 return variant;
3350 }
3351 else
3352 {
3353 variant = ctx->mModule->TypedValueToVariant(expr, result, true);
3354 }
3355 }
3356 return variant;
3357}
3358
3359int BfResolvedTypeSet::DoHash(BfType* type, LookupContext* ctx, bool allowRef, int hashSeed)
3360{

Callers 1

ResolveTypeRef_RefMethod · 0.80

Calls 9

TypedValueToVariantMethod · 0.80
InitMethod · 0.45
GetPrimitiveTypeMethod · 0.45
ResolveMethod · 0.45
IsIntegerMethod · 0.45
GetTypeCodeMethod · 0.45
CastMethod · 0.45
IsFloatMethod · 0.45
IsCharMethod · 0.45

Tested by

no test coverage detected