mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixed comptime emission for enums
This commit is contained in:
parent
c52ef256a5
commit
ed80a8d88b
3 changed files with 30 additions and 4 deletions
|
@ -1926,6 +1926,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
|
||||||
BfMethodDef* staticMarkMethod = NULL;
|
BfMethodDef* staticMarkMethod = NULL;
|
||||||
BfMethodDef* dynamicCastMethod = NULL;
|
BfMethodDef* dynamicCastMethod = NULL;
|
||||||
BfMethodDef* toStringMethod = NULL;
|
BfMethodDef* toStringMethod = NULL;
|
||||||
|
BfMethodDef* getUnderlyingMethod = NULL;
|
||||||
bool needsEqualsMethod = ((mCurTypeDef->mTypeCode == BfTypeCode_Struct) || (mCurTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mCurTypeDef->mIsStatic);
|
bool needsEqualsMethod = ((mCurTypeDef->mTypeCode == BfTypeCode_Struct) || (mCurTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mCurTypeDef->mIsStatic);
|
||||||
BfMethodDef* equalsOpMethod = NULL;
|
BfMethodDef* equalsOpMethod = NULL;
|
||||||
BfMethodDef* equalsMethod = NULL;
|
BfMethodDef* equalsMethod = NULL;
|
||||||
|
@ -2061,9 +2062,14 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
|
||||||
if (method->mName == BF_METHODNAME_DYNAMICCAST)
|
if (method->mName == BF_METHODNAME_DYNAMICCAST)
|
||||||
_SetMethod(dynamicCastMethod, method);
|
_SetMethod(dynamicCastMethod, method);
|
||||||
if (method->mName == BF_METHODNAME_TO_STRING)
|
if (method->mName == BF_METHODNAME_TO_STRING)
|
||||||
_SetMethod(toStringMethod, method);
|
_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) &&
|
else if ((method->mMethodType == BfMethodType_Operator) &&
|
||||||
(method->mIsStatic) &&
|
(method->mIsStatic) &&
|
||||||
(method->mParams.size() == 2))
|
(method->mParams.size() == 2))
|
||||||
|
@ -2247,7 +2253,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
|
||||||
if (toStringMethod != NULL)
|
if (toStringMethod != NULL)
|
||||||
wantsToString = false;
|
wantsToString = false;
|
||||||
|
|
||||||
if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum))
|
if ((mCurTypeDef->mTypeCode == BfTypeCode_Enum) && (!isPayloadEnum) && (getUnderlyingMethod == NULL))
|
||||||
{
|
{
|
||||||
auto methodDef = new BfMethodDef();
|
auto methodDef = new BfMethodDef();
|
||||||
mCurTypeDef->mMethods.push_back(methodDef);
|
mCurTypeDef->mMethods.push_back(methodDef);
|
||||||
|
|
|
@ -2108,7 +2108,13 @@ void BfModule::UpdateCEEmit(CeEmitContext* ceEmitContext, BfTypeInstance* typeIn
|
||||||
|
|
||||||
typeInstance->mTypeDef->ClearOldMemberSets();
|
typeInstance->mTypeDef->ClearOldMemberSets();
|
||||||
|
|
||||||
FinishCEParseContext(refNode, typeInstance, &ceParseContext);
|
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)
|
void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance* typeInstance, BfCustomAttributes* customAttributes, HashSet<BfTypeInstance*> foundAttributes)
|
||||||
|
@ -4000,7 +4006,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hadNewMembers)
|
if (hadNewMembers)
|
||||||
{
|
{
|
||||||
DoPopulateType(resolvedTypeRef, populateType);
|
DoPopulateType(resolvedTypeRef, populateType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,25 @@ namespace Tests
|
||||||
{
|
{
|
||||||
class Reflection2
|
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]
|
[Test]
|
||||||
public static void TestBasics()
|
public static void TestBasics()
|
||||||
{
|
{
|
||||||
const Type t = typeof(StringView);
|
const Type t = typeof(StringView);
|
||||||
int fieldCount = t.FieldCount;
|
int fieldCount = t.FieldCount;
|
||||||
|
|
||||||
|
Test.Assert(typeof(RemovePtr<int32>) == typeof(int32));
|
||||||
|
Test.Assert(typeof(RemovePtr<uint32*>) == typeof(uint32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue