mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Better handling of undef const expressions
This commit is contained in:
parent
071dfa8e09
commit
1a93660416
4 changed files with 42 additions and 1 deletions
|
@ -3801,6 +3801,14 @@ void BfExprEvaluator::GetLiteral(BfAstNode* refNode, const BfVariant& variant)
|
||||||
case BfTypeCode_StringId:
|
case BfTypeCode_StringId:
|
||||||
mResult = BfTypedValue(mModule->mBfIRBuilder->CreateConst(variant.mTypeCode, variant.mUInt64), mModule->ResolveTypeDef(mModule->mCompiler->mStringTypeDef));
|
mResult = BfTypedValue(mModule->mBfIRBuilder->CreateConst(variant.mTypeCode, variant.mUInt64), mModule->ResolveTypeDef(mModule->mCompiler->mStringTypeDef));
|
||||||
break;
|
break;
|
||||||
|
case BfTypeCode_Let:
|
||||||
|
if (mExpectingType != NULL)
|
||||||
|
{
|
||||||
|
mResult = BfTypedValue(mModule->mBfIRBuilder->CreateUndefValue(mModule->mBfIRBuilder->MapType(mExpectingType)), mExpectingType);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mModule->Fail("Invalid undef literal", refNode);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
mModule->Fail("Invalid literal", refNode);
|
mModule->Fail("Invalid literal", refNode);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -6903,7 +6903,19 @@ BfConstExprValueType* BfModule::CreateConstExprValueType(const BfTypedValue& typ
|
||||||
BfResolveTypeRefFlags resolveFlags = allowCreate ? BfResolveTypeRefFlag_None : BfResolveTypeRefFlag_NoCreate;
|
BfResolveTypeRefFlags resolveFlags = allowCreate ? BfResolveTypeRefFlag_None : BfResolveTypeRefFlag_NoCreate;
|
||||||
|
|
||||||
auto variant = TypedValueToVariant(NULL, typedValue);
|
auto variant = TypedValueToVariant(NULL, typedValue);
|
||||||
|
|
||||||
if (variant.mTypeCode == BfTypeCode_None)
|
if (variant.mTypeCode == BfTypeCode_None)
|
||||||
|
{
|
||||||
|
if (auto constant = mBfIRBuilder->GetConstant(typedValue.mValue))
|
||||||
|
{
|
||||||
|
if (constant->mConstType == BfConstType_Undef)
|
||||||
|
{
|
||||||
|
variant.mTypeCode = BfTypeCode_Let;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variant.mTypeCode == BfTypeCode_None)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
auto constExprValueType = mContext->mConstExprValueTypePool.Get();
|
auto constExprValueType = mContext->mConstExprValueTypePool.Get();
|
||||||
|
@ -12895,7 +12907,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
{
|
{
|
||||||
BfConstExprValueType* toConstExprValueType = (BfConstExprValueType*)toType;
|
BfConstExprValueType* toConstExprValueType = (BfConstExprValueType*)toType;
|
||||||
|
|
||||||
auto variantVal = TypedValueToVariant(srcNode, typedVal);
|
auto variantVal = TypedValueToVariant(srcNode, typedVal, true);
|
||||||
if ((mBfIRBuilder->IsIntable(variantVal.mTypeCode)) && (mBfIRBuilder->IsIntable(toConstExprValueType->mValue.mTypeCode)))
|
if ((mBfIRBuilder->IsIntable(variantVal.mTypeCode)) && (mBfIRBuilder->IsIntable(toConstExprValueType->mValue.mTypeCode)))
|
||||||
{
|
{
|
||||||
if (variantVal.mInt64 == toConstExprValueType->mValue.mInt64)
|
if (variantVal.mInt64 == toConstExprValueType->mValue.mInt64)
|
||||||
|
@ -12914,6 +12926,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
return typedVal.mValue;
|
return typedVal.mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((toConstExprValueType->mValue.mTypeCode == BfTypeCode_Let) && (constant->mConstType == BfConstType_Undef))
|
||||||
|
{
|
||||||
|
return typedVal.mValue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ignoreErrors)
|
if (!ignoreErrors)
|
||||||
{
|
{
|
||||||
String valStr;
|
String valStr;
|
||||||
|
|
|
@ -2511,6 +2511,9 @@ public:
|
||||||
|
|
||||||
virtual bool IsConstExprValue() override { return true; }
|
virtual bool IsConstExprValue() override { return true; }
|
||||||
virtual BfType* GetUnderlyingType() override { return mType; }
|
virtual BfType* GetUnderlyingType() override { return mType; }
|
||||||
|
|
||||||
|
virtual bool IsUnspecializedType() { return mValue.mTypeCode == BfTypeCode_Let; }
|
||||||
|
virtual bool IsUnspecializedTypeVariation() { return mValue.mTypeCode == BfTypeCode_Let; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*class BfCustomAttributeArgument
|
/*class BfCustomAttributeArgument
|
||||||
|
|
|
@ -121,6 +121,18 @@ namespace Tests
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int StrTest<T>(T param2)
|
||||||
|
where T : const String
|
||||||
|
{
|
||||||
|
return StrTest2(param2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int StrTest2<T>(T param1)
|
||||||
|
where T : const String
|
||||||
|
{
|
||||||
|
return param1.Length;
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public static void TestBasics()
|
public static void TestBasics()
|
||||||
{
|
{
|
||||||
|
@ -136,6 +148,7 @@ namespace Tests
|
||||||
|
|
||||||
Test.Assert(BigNum<const 3>.N == 3);
|
Test.Assert(BigNum<const 3>.N == 3);
|
||||||
Test.Assert(Test("test", 1, 2, 3) == 10);
|
Test.Assert(Test("test", 1, 2, 3) == 10);
|
||||||
|
Test.Assert(StrTest("ABCDE") == 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue