1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 12:02:21 +02:00

Fixed comptime emission for enums

This commit is contained in:
Brian Fiete 2021-11-24 13:27:39 -08:00
parent c52ef256a5
commit ed80a8d88b
3 changed files with 30 additions and 4 deletions

View file

@ -1926,6 +1926,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
BfMethodDef* staticMarkMethod = NULL;
BfMethodDef* dynamicCastMethod = NULL;
BfMethodDef* toStringMethod = NULL;
BfMethodDef* getUnderlyingMethod = NULL;
bool needsEqualsMethod = ((mCurTypeDef->mTypeCode == BfTypeCode_Struct) || (mCurTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mCurTypeDef->mIsStatic);
BfMethodDef* equalsOpMethod = NULL;
BfMethodDef* equalsMethod = NULL;
@ -2064,6 +2065,11 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
_SetMethod(toStringMethod, method);
}
}
else if (method->mMethodType == BfMethodType_PropertyGetter)
{
if (method->mName == BF_METHODNAME_ENUM_GETUNDERLYING)
_SetMethod(getUnderlyingMethod, method);
}
else if ((method->mMethodType == BfMethodType_Operator) &&
(method->mIsStatic) &&
(method->mParams.size() == 2))
@ -2247,7 +2253,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
if (toStringMethod != NULL)
wantsToString = false;
if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum))
if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum) && (getUnderlyingMethod == NULL))
{
auto methodDef = new BfMethodDef();
mCurTypeDef->mMethods.push_back(methodDef);

View file

@ -2109,6 +2109,12 @@ void BfModule::UpdateCEEmit(CeEmitContext* ceEmitContext, BfTypeInstance* typeIn
typeInstance->mTypeDef->ClearOldMemberSets();
FinishCEParseContext(refNode, typeInstance, &ceParseContext);
if (typeInstance->mTypeDef->mEmitParent != NULL)
{
// Remove generated fields like the 'underlying type' enum field
typeInstance->mFieldInstances.Resize(typeInstance->mTypeDef->mEmitParent->mFields.mSize);
}
}
void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* typeInstance, BfCustomAttributes* customAttributes, HashSet<BfTypeInstance*> foundAttributes)

View file

@ -6,11 +6,25 @@ namespace Tests
{
class Reflection2
{
public typealias RemovePtr<T> = comptype(RemovePtr(typeof(T)));
[Comptime]
public static Type RemovePtr(Type type)
{
if (type.IsPointer)
return type.UnderlyingType;
return type;
}
[Test]
public static void TestBasics()
{
const Type t = typeof(StringView);
int fieldCount = t.FieldCount;
Test.Assert(typeof(RemovePtr<int32>) == typeof(int32));
Test.Assert(typeof(RemovePtr<uint32*>) == typeof(uint32));
}
}
}