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

Method IsType

IDEHelper/Compiler/BfExprEvaluator.cpp:2727–2762  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2725}
2726
2727bool BfMethodMatcher::IsType(BfTypedValue& typedVal, BfType* type)
2728{
2729 if (typedVal.mType == type)
2730 return true;
2731
2732 if (!typedVal)
2733 return false;
2734
2735 if (!typedVal.mType->IsPrimitiveType())
2736 return false;
2737 if (!type->IsPrimitiveType())
2738 return false;
2739
2740 auto fromPrimType = typedVal.mType->ToPrimitiveType();
2741 if ((fromPrimType->mTypeDef->mTypeCode != BfTypeCode_IntUnknown) &&
2742 (fromPrimType->mTypeDef->mTypeCode != BfTypeCode_UIntUnknown))
2743 return false;
2744
2745 auto constant = mModule->mBfIRBuilder->GetConstant(typedVal.mValue);
2746 if (constant == NULL)
2747 return false;
2748
2749 auto toPrimType = type->ToPrimitiveType();
2750 if (!mModule->mBfIRBuilder->IsInt(toPrimType->mTypeDef->mTypeCode))
2751 return false;
2752
2753 if (type->mSize == 8)
2754 return false;
2755
2756 int64 minVal = -(1LL << (8 * type->mSize - 1));
2757 int64 maxVal = (1LL << (8 * type->mSize - 1)) - 1;
2758 if ((constant->mInt64 >= minVal) && (constant->mInt64 <= maxVal))
2759 return true;
2760
2761 return false;
2762}
2763
2764// This method checks all base classes before checking interfaces. Is that correct?
2765bool BfMethodMatcher::CheckType(BfTypeInstance* typeInstance, BfTypedValue target, bool isFailurePass, bool forceOuterCheck)

Callers

nothing calls this directly

Calls 4

IsPrimitiveTypeMethod · 0.45
ToPrimitiveTypeMethod · 0.45
GetConstantMethod · 0.45
IsIntMethod · 0.45

Tested by

no test coverage detected