mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
EnumType.UnderlyingType
support, generic enum constraint improvements
This commit is contained in:
parent
64161bf001
commit
1ee0a19bbf
5 changed files with 74 additions and 2 deletions
|
@ -676,6 +676,9 @@ const char* BfAutoComplete::GetTypeName(BfType* type)
|
||||||
|
|
||||||
void BfAutoComplete::AddInnerTypes(BfTypeInstance* typeInst, const StringImpl& filter, bool allowProtected, bool allowPrivate)
|
void BfAutoComplete::AddInnerTypes(BfTypeInstance* typeInst, const StringImpl& filter, bool allowProtected, bool allowPrivate)
|
||||||
{
|
{
|
||||||
|
if (typeInst->IsEnum())
|
||||||
|
AddEntry(AutoCompleteEntry("valuetype", "UnderlyingType"), filter);
|
||||||
|
|
||||||
for (auto innerType : typeInst->mTypeDef->mNestedTypes)
|
for (auto innerType : typeInst->mTypeDef->mNestedTypes)
|
||||||
{
|
{
|
||||||
if (CheckProtection(innerType->mProtection, innerType, allowProtected, allowPrivate))
|
if (CheckProtection(innerType->mProtection, innerType, allowProtected, allowPrivate))
|
||||||
|
@ -847,7 +850,7 @@ void BfAutoComplete::AddTypeMembers(BfTypeInstance* typeInst, bool addStatic, bo
|
||||||
|
|
||||||
if ((addStatic) && (mModule->mCurMethodInstance == NULL) && (typeInst->IsEnum()))
|
if ((addStatic) && (mModule->mCurMethodInstance == NULL) && (typeInst->IsEnum()))
|
||||||
{
|
{
|
||||||
AddEntry(AutoCompleteEntry("valuetype", "_"), filter);
|
AddEntry(AutoCompleteEntry("value", "_"), filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_STATIC(staticVal) ((staticVal && addStatic) || (!staticVal && addNonStatic))
|
#define CHECK_STATIC(staticVal) ((staticVal && addStatic) || (!staticVal && addNonStatic))
|
||||||
|
@ -1847,6 +1850,17 @@ bool BfAutoComplete::CheckMemberReference(BfAstNode* target, BfAstNode* dotToken
|
||||||
checkType = genericParamInstance->mTypeConstraint;
|
checkType = genericParamInstance->mTypeConstraint;
|
||||||
else
|
else
|
||||||
checkType = mModule->mContext->mBfObjectType;
|
checkType = mModule->mContext->mBfObjectType;
|
||||||
|
|
||||||
|
if ((genericParamInstance->IsEnum()))
|
||||||
|
{
|
||||||
|
if (isStatic)
|
||||||
|
AddEntry(AutoCompleteEntry("valuetype", "UnderlyingType"), filter);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddEntry(AutoCompleteEntry("value", "Underlying"), filter);
|
||||||
|
AddEntry(AutoCompleteEntry("value", "UnderlyingRef"), filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
_HandleGenericParamInstance(genericParamInstance);
|
_HandleGenericParamInstance(genericParamInstance);
|
||||||
|
|
||||||
|
|
|
@ -9757,7 +9757,16 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
||||||
prevDef = mPropDef;
|
prevDef = mPropDef;
|
||||||
prevTarget = mPropTarget;
|
prevTarget = mPropTarget;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((mPropDef == NULL) && (genericParamInst->IsEnum()))
|
||||||
|
{
|
||||||
|
if ((fieldName == "Underlying") || (fieldName == "UnderlyingRef"))
|
||||||
|
{
|
||||||
|
mResult = mModule->GetDefaultTypedValue(mModule->GetPrimitiveType(BfTypeCode_Var));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mPropDef != NULL)
|
if (mPropDef != NULL)
|
||||||
|
@ -10467,6 +10476,25 @@ bool BfExprEvaluator::LookupTypeProp(BfTypeOfExpression* typeOfExpr, BfIdentifie
|
||||||
_Int32Result((typeInstance != NULL) ? typeInstance->mInstAlign : type->mSize);
|
_Int32Result((typeInstance != NULL) ? typeInstance->mInstAlign : type->mSize);
|
||||||
else if (memberName == "InstanceStride")
|
else if (memberName == "InstanceStride")
|
||||||
_Int32Result((typeInstance != NULL) ? typeInstance->GetInstStride() : type->GetStride());
|
_Int32Result((typeInstance != NULL) ? typeInstance->GetInstStride() : type->GetStride());
|
||||||
|
else if (memberName == "UnderlyingType")
|
||||||
|
{
|
||||||
|
auto typeType = mModule->ResolveTypeDef(mModule->mCompiler->mTypeTypeDef);
|
||||||
|
if (type->IsGenericParam())
|
||||||
|
{
|
||||||
|
auto genericParamInstance = mModule->GetGenericParamInstance((BfGenericParamType*)type);
|
||||||
|
if (genericParamInstance->IsEnum())
|
||||||
|
mResult = BfTypedValue(mModule->mBfIRBuilder->GetUndefConstValue(mModule->mBfIRBuilder->MapType(typeType)), typeType);
|
||||||
|
}
|
||||||
|
else if (type->IsEnum())
|
||||||
|
{
|
||||||
|
auto underlyingType = type->GetUnderlyingType();
|
||||||
|
if (underlyingType != NULL)
|
||||||
|
{
|
||||||
|
mModule->AddDependency(underlyingType, mModule->mCurTypeInstance, BfDependencyMap::DependencyFlag_ExprTypeReference);
|
||||||
|
mResult = BfTypedValue(mModule->CreateTypeDataRef(underlyingType), typeType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else if ((memberName == "MinValue") || (memberName == "MaxValue"))
|
else if ((memberName == "MinValue") || (memberName == "MaxValue"))
|
||||||
{
|
{
|
||||||
bool isMin = memberName == "MinValue";
|
bool isMin = memberName == "MinValue";
|
||||||
|
|
|
@ -7284,6 +7284,13 @@ BfType* BfModule::ResolveInnerType(BfType* outerType, BfAstNode* typeRef, BfPopu
|
||||||
}
|
}
|
||||||
if (nestedTypeDef != NULL)
|
if (nestedTypeDef != NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if ((outerTypeInstance->IsEnum()) && (findName == "UnderlyingType"))
|
||||||
|
{
|
||||||
|
auto underlyingType = outerTypeInstance->GetUnderlyingType();
|
||||||
|
if (underlyingType != NULL)
|
||||||
|
return underlyingType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9949,6 +9956,12 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
|
||||||
auto genericParam = GetGenericParamInstance((BfGenericParamType*)leftType);
|
auto genericParam = GetGenericParamInstance((BfGenericParamType*)leftType);
|
||||||
if ((genericParam->mGenericParamFlags & BfGenericParamFlag_Var) != 0)
|
if ((genericParam->mGenericParamFlags & BfGenericParamFlag_Var) != 0)
|
||||||
return ResolveTypeResult(typeRef, GetPrimitiveType(BfTypeCode_Var), populateType, resolveFlags);
|
return ResolveTypeResult(typeRef, GetPrimitiveType(BfTypeCode_Var), populateType, resolveFlags);
|
||||||
|
if ((genericParam->IsEnum()) && (qualifiedTypeRef->mRight != NULL))
|
||||||
|
{
|
||||||
|
StringView findNameRight = qualifiedTypeRef->mRight->ToStringView();
|
||||||
|
if (findNameRight == "UnderlyingType")
|
||||||
|
return ResolveTypeResult(typeRef, GetPrimitiveType(BfTypeCode_Var), populateType, resolveFlags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto resolvedType = ResolveInnerType(leftType, qualifiedTypeRef->mRight, populateType, false, numGenericArgs);
|
auto resolvedType = ResolveInnerType(leftType, qualifiedTypeRef->mRight, populateType, false, numGenericArgs);
|
||||||
|
|
|
@ -64,6 +64,22 @@ bool BfTypedValue::CanModify() const
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool BfGenericParamInstance::IsEnum()
|
||||||
|
{
|
||||||
|
if ((mGenericParamFlags & BfGenericParamFlag_Enum) != 0)
|
||||||
|
return true;
|
||||||
|
if (mTypeConstraint != NULL)
|
||||||
|
{
|
||||||
|
auto module = mTypeConstraint->GetModule();
|
||||||
|
if ((module != NULL) && (mTypeConstraint->IsInstanceOf(module->mCompiler->mEnumTypeDef)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool BfDependencyMap::AddUsedBy(BfType* dependentType, BfDependencyMap::DependencyFlags flags)
|
bool BfDependencyMap::AddUsedBy(BfType* dependentType, BfDependencyMap::DependencyFlags flags)
|
||||||
{
|
{
|
||||||
BF_ASSERT(dependentType != NULL);
|
BF_ASSERT(dependentType != NULL);
|
||||||
|
|
|
@ -1162,6 +1162,7 @@ public:
|
||||||
virtual BfGenericParamDef* GetGenericParamDef() = 0;
|
virtual BfGenericParamDef* GetGenericParamDef() = 0;
|
||||||
virtual BfExternalConstraintDef* GetExternConstraintDef() = 0;
|
virtual BfExternalConstraintDef* GetExternConstraintDef() = 0;
|
||||||
virtual String GetName() = 0;
|
virtual String GetName() = 0;
|
||||||
|
bool IsEnum();
|
||||||
};
|
};
|
||||||
|
|
||||||
class BfGenericTypeParamInstance : public BfGenericParamInstance
|
class BfGenericTypeParamInstance : public BfGenericParamInstance
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue