mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Merge pull request #2195 from aharabada/master
Fixed generated methods for enums with CRepr attribute
This commit is contained in:
commit
aa092a88ee
2 changed files with 45 additions and 4 deletions
|
@ -19465,7 +19465,7 @@ void BfModule::EmitEnumToStringBody()
|
||||||
rawPayload = ExtractValue(GetThis(), NULL, 1);
|
rawPayload = ExtractValue(GetThis(), NULL, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
enumVal = mBfIRBuilder->GetArgument(0);
|
enumVal = LoadValue(GetThis()).mValue;
|
||||||
|
|
||||||
Array<BfType*> paramTypes;
|
Array<BfType*> paramTypes;
|
||||||
paramTypes.Add(stringType);
|
paramTypes.Add(stringType);
|
||||||
|
@ -22565,7 +22565,8 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto andResult = mBfIRBuilder->CreateAnd(mCurMethodState->mLocals[0]->mValue, mCurMethodState->mLocals[1]->mValue);
|
BfIRValue thisValue = LoadValue(GetThis()).mValue;
|
||||||
|
auto andResult = mBfIRBuilder->CreateAnd(thisValue, mCurMethodState->mLocals[1]->mValue);
|
||||||
auto toBool = mBfIRBuilder->CreateCmpNE(andResult, GetDefaultValue(mCurMethodState->mLocals[0]->mResolvedType));
|
auto toBool = mBfIRBuilder->CreateCmpNE(andResult, GetDefaultValue(mCurMethodState->mLocals[0]->mResolvedType));
|
||||||
fromBool = mBfIRBuilder->CreateNumericCast(toBool, false, BfTypeCode_Boolean);
|
fromBool = mBfIRBuilder->CreateNumericCast(toBool, false, BfTypeCode_Boolean);
|
||||||
}
|
}
|
||||||
|
@ -22594,7 +22595,17 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup,
|
||||||
if ((!mCompiler->mIsResolveOnly) || (mIsComptimeModule))
|
if ((!mCompiler->mIsResolveOnly) || (mIsComptimeModule))
|
||||||
{
|
{
|
||||||
if (!mCurTypeInstance->IsValuelessType())
|
if (!mCurTypeInstance->IsValuelessType())
|
||||||
ret = mBfIRBuilder->CreateRet(GetThis().mValue);
|
{
|
||||||
|
auto thisValueOrAddr = GetThis();
|
||||||
|
|
||||||
|
BfIRValue thisValue;
|
||||||
|
if (!methodInstance->mReturnType->IsRef())
|
||||||
|
thisValue = LoadValue(thisValueOrAddr).mValue;
|
||||||
|
else
|
||||||
|
thisValue = thisValueOrAddr.mValue;
|
||||||
|
|
||||||
|
ret = mBfIRBuilder->CreateRet(thisValue);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
mBfIRBuilder->CreateRetVoid();
|
mBfIRBuilder->CreateRetVoid();
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,14 @@ namespace Tests
|
||||||
case C;
|
case C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[CRepr]
|
||||||
|
public enum EnumN
|
||||||
|
{
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
static void TestBasic()
|
static void TestBasic()
|
||||||
{
|
{
|
||||||
|
@ -276,5 +284,27 @@ namespace Tests
|
||||||
EnumL el = .A;
|
EnumL el = .A;
|
||||||
Test.Assert(el == 0);
|
Test.Assert(el == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
static void TestCrepr()
|
||||||
|
{
|
||||||
|
EnumN value = .B;
|
||||||
|
|
||||||
|
Test.Assert(sizeof(EnumN) == sizeof(System.Interop.c_int));
|
||||||
|
|
||||||
|
Test.Assert(value.HasFlag(.A) == false);
|
||||||
|
Test.Assert(value.HasFlag(.B) == true);
|
||||||
|
|
||||||
|
Test.Assert(value.Underlying == 1);
|
||||||
|
|
||||||
|
ref System.Interop.c_int valueRef = ref value.UnderlyingRef;
|
||||||
|
valueRef = 2;
|
||||||
|
Test.Assert(value == .C);
|
||||||
|
|
||||||
|
String str = scope String();
|
||||||
|
value.ToString(str);
|
||||||
|
|
||||||
|
Test.Assert(str == "C");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue