mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-25 02:58:02 +02:00
Allowed more flexible attribute type lookup, supporting inner types
This commit is contained in:
parent
3509d659ea
commit
86d8f78761
5 changed files with 49 additions and 66 deletions
|
@ -4283,13 +4283,10 @@ void BfCompiler::GetSymbolReferences()
|
||||||
{
|
{
|
||||||
if (attrib->mAttributeTypeRef != NULL)
|
if (attrib->mAttributeTypeRef != NULL)
|
||||||
{
|
{
|
||||||
String attrName = attrib->mAttributeTypeRef->ToString();
|
auto attrType = module->ResolveTypeRef(attrib->mAttributeTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_Attribute);
|
||||||
BfType* attrType = NULL;
|
BfTypeDef* attrTypeDef = NULL;
|
||||||
|
if ((attrType != NULL) && (attrType->IsTypeInstance()))
|
||||||
BfAtomComposite nameComposite;
|
attrTypeDef = attrType->ToTypeInstance()->mTypeDef;
|
||||||
if (mSystem->ParseAtomComposite(attrName + "Attribute", nameComposite))
|
|
||||||
{
|
|
||||||
BfTypeDef* attrTypeDef = module->FindTypeDefRaw(nameComposite, 0, replaceTypeInst, declaringType, NULL);
|
|
||||||
if (attrTypeDef != NULL)
|
if (attrTypeDef != NULL)
|
||||||
{
|
{
|
||||||
mResolvePassData->HandleTypeReference(attrib->mAttributeTypeRef, attrTypeDef);
|
mResolvePassData->HandleTypeReference(attrib->mAttributeTypeRef, attrTypeDef);
|
||||||
|
@ -4313,7 +4310,6 @@ void BfCompiler::GetSymbolReferences()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
attrib = attrib->mNextAttribute;
|
attrib = attrib->mNextAttribute;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5063,7 +5063,9 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, const BfTypedValu
|
||||||
|
|
||||||
// Temporarily disable so we don't capture calls in params
|
// Temporarily disable so we don't capture calls in params
|
||||||
SetAndRestoreValue<BfFunctionBindResult*> prevBindResult(mFunctionBindResult, NULL);
|
SetAndRestoreValue<BfFunctionBindResult*> prevBindResult(mFunctionBindResult, NULL);
|
||||||
SetAndRestoreValue<bool> prevAllowVariableDeclarations(mModule->mCurMethodState->mCurScope->mAllowVariableDeclarations, false); // Don't allow variable declarations in arguments
|
SetAndRestoreValue<bool> prevAllowVariableDeclarations;
|
||||||
|
if (mModule->mCurMethodState != NULL)
|
||||||
|
prevAllowVariableDeclarations.Init(mModule->mCurMethodState->mCurScope->mAllowVariableDeclarations, false);
|
||||||
|
|
||||||
BfMethodInstance* methodInstance = moduleMethodInstance.mMethodInstance;
|
BfMethodInstance* methodInstance = moduleMethodInstance.mMethodInstance;
|
||||||
|
|
||||||
|
|
|
@ -9791,16 +9791,10 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String attrName = attributesDirective->mAttributeTypeRef->ToString();
|
BfType* attrType = ResolveTypeRef(attributesDirective->mAttributeTypeRef, BfPopulateType_Identity, BfResolveTypeRefFlag_Attribute);
|
||||||
BfType* attrType = NULL;
|
|
||||||
BfAtomComposite nameComposite;
|
|
||||||
BfTypeDef* attrTypeDef = NULL;
|
BfTypeDef* attrTypeDef = NULL;
|
||||||
if (mSystem->ParseAtomComposite(attrName + "Attribute", nameComposite))
|
if ((attrType != NULL) && (attrType->IsTypeInstance()))
|
||||||
{
|
attrTypeDef = attrType->ToTypeInstance()->mTypeDef;
|
||||||
BfTypeLookupError error;
|
|
||||||
error.mRefNode = attributesDirective->mAttributeTypeRef;
|
|
||||||
attrTypeDef = FindTypeDefRaw(nameComposite, 0, mCurTypeInstance, GetActiveTypeDef(NULL, true), &error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL))
|
if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL))
|
||||||
{
|
{
|
||||||
|
@ -9809,26 +9803,17 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
|
||||||
mCompiler->mResolvePassData->HandleTypeReference(attributesDirective->mAttributeTypeRef, attrTypeDef);
|
mCompiler->mResolvePassData->HandleTypeReference(attributesDirective->mAttributeTypeRef, attrTypeDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attrTypeDef == NULL)
|
|
||||||
{
|
|
||||||
TypeRefNotFound(attributesDirective->mAttributeTypeRef, "Attribute");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isBypassedAttr = false;
|
bool isBypassedAttr = false;
|
||||||
|
|
||||||
if (attrTypeDef != NULL)
|
if (attrTypeDef != NULL)
|
||||||
{
|
{
|
||||||
attrType = mContext->mUnreifiedModule->ResolveTypeDef(attrTypeDef, BfPopulateType_Identity);
|
|
||||||
|
|
||||||
// 'Object' has some dependencies on some attributes, but those attributes are classes so we have a circular dependency issue
|
// 'Object' has some dependencies on some attributes, but those attributes are classes so we have a circular dependency issue
|
||||||
// We solve it by having a 'bypass' for known attributes that Object depends on
|
// We solve it by having a 'bypass' for known attributes that Object depends on
|
||||||
if ((attributesDirective->mArguments.empty()) && (autoComplete == NULL) && (attrType != NULL) && (attrType->IsTypeInstance()))
|
if ((attributesDirective->mArguments.empty()) && (autoComplete == NULL) && (attrType != NULL) && (attrType->IsTypeInstance()))
|
||||||
{
|
{
|
||||||
if (attrTypeDef == mCompiler->mCReprAttributeTypeDef)
|
//if (attrTypeDef == mCompiler->mCReprAttributeTypeDef)
|
||||||
|
if (attrType->IsInstanceOf(mCompiler->mCReprAttributeTypeDef))
|
||||||
{
|
{
|
||||||
BfTypeInstance* attrTypeInst = attrType->ToTypeInstance();
|
|
||||||
|
|
||||||
for (auto methodDef : attrTypeDef->mMethods)
|
for (auto methodDef : attrTypeDef->mMethods)
|
||||||
{
|
{
|
||||||
if ((methodDef->mMethodType == BfMethodType_Ctor) && (methodDef->mProtection == BfProtection_Public))
|
if ((methodDef->mMethodType == BfMethodType_Ctor) && (methodDef->mProtection == BfProtection_Public))
|
||||||
|
@ -9860,17 +9845,6 @@ void BfModule::GetCustomAttributes(BfCustomAttributes* customAttributes, BfAttri
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't allow this
|
|
||||||
/*else if (mContext->mCurTypeState != NULL)
|
|
||||||
{
|
|
||||||
SetAndRestoreValue<BfTypeReference*> prevTypeRef(mContext->mCurTypeState->mCurAttributeTypeRef, attributesDirective->mAttributeTypeRef);
|
|
||||||
attrType = mContext->mUnreifiedModule->ResolveTypeRef(attributesDirective->mAttributeTypeRef, BfPopulateType_DataAndMethods);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
attrType = mContext->mUnreifiedModule->ResolveTypeRef(attributesDirective->mAttributeTypeRef);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
BfTypeInstance* attrTypeInst = NULL;
|
BfTypeInstance* attrTypeInst = NULL;
|
||||||
if (attrType == NULL)
|
if (attrType == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1276,6 +1276,7 @@ enum BfResolveTypeRefFlags
|
||||||
BfResolveTypeRefFlag_AllowGenericParamConstValue = 0x10 | 0x20,
|
BfResolveTypeRefFlag_AllowGenericParamConstValue = 0x10 | 0x20,
|
||||||
BfResolveTypeRefFlag_AutoComplete = 0x40,
|
BfResolveTypeRefFlag_AutoComplete = 0x40,
|
||||||
BfResolveTypeRefFlag_FromIndirectSource = 0x80, // Such as a type alias or a generic parameter
|
BfResolveTypeRefFlag_FromIndirectSource = 0x80, // Such as a type alias or a generic parameter
|
||||||
|
BfResolveTypeRefFlag_Attribute = 0x100
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BfSrcPosFlags
|
enum BfSrcPosFlags
|
||||||
|
@ -1689,7 +1690,7 @@ public:
|
||||||
BfTypeDef* FindTypeDefRaw(const BfAtomComposite& findName, int numGenericArgs, BfTypeInstance* typeInstance, BfTypeDef* useTypeDef, BfTypeLookupError* error);
|
BfTypeDef* FindTypeDefRaw(const BfAtomComposite& findName, int numGenericArgs, BfTypeInstance* typeInstance, BfTypeDef* useTypeDef, BfTypeLookupError* error);
|
||||||
BfTypeDef* FindTypeDef(const BfAtomComposite& findName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL);
|
BfTypeDef* FindTypeDef(const BfAtomComposite& findName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL);
|
||||||
BfTypeDef* FindTypeDef(const StringImpl& typeName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL);
|
BfTypeDef* FindTypeDef(const StringImpl& typeName, int numGenericArgs = 0, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL);
|
||||||
BfTypeDef* FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, int numGenericParams = 0);
|
BfTypeDef* FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeInstanceOverride = NULL, BfTypeLookupError* error = NULL, int numGenericParams = 0, BfResolveTypeRefFlags resolveFlags = (BfResolveTypeRefFlags)0);
|
||||||
BfTypedValue TryLookupGenericConstVaue(BfIdentifierNode* identifierNode, BfType* expectingType);
|
BfTypedValue TryLookupGenericConstVaue(BfIdentifierNode* identifierNode, BfType* expectingType);
|
||||||
void CheckTypeRefFixit(BfAstNode* typeRef, const char* appendName = NULL);
|
void CheckTypeRefFixit(BfAstNode* typeRef, const char* appendName = NULL);
|
||||||
void CheckIdentifierFixit(BfAstNode* node);
|
void CheckIdentifierFixit(BfAstNode* node);
|
||||||
|
|
|
@ -6398,7 +6398,7 @@ BfTypeDef* BfModule::FindTypeDef(const StringImpl& typeName, int numGenericArgs,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BfTypeDef* BfModule::FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeInstanceOverride, BfTypeLookupError* error, int numGenericParams)
|
BfTypeDef* BfModule::FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeInstanceOverride, BfTypeLookupError* error, int numGenericParams, BfResolveTypeRefFlags resolveFlags)
|
||||||
{
|
{
|
||||||
BP_ZONE("BfModule::FindTypeDef_5");
|
BP_ZONE("BfModule::FindTypeDef_5");
|
||||||
|
|
||||||
|
@ -6442,10 +6442,20 @@ BfTypeDef* BfModule::FindTypeDef(BfTypeReference* typeRef, BfTypeInstance* typeI
|
||||||
}
|
}
|
||||||
|
|
||||||
BfSizedAtomComposite findName;
|
BfSizedAtomComposite findName;
|
||||||
if (!mSystem->ParseAtomComposite(findNameStr, findName))
|
if ((resolveFlags & BfResolveTypeRefFlag_Attribute) != 0)
|
||||||
{
|
{
|
||||||
|
String attributeName;
|
||||||
|
attributeName += findNameStr;
|
||||||
|
attributeName += "Attribute";
|
||||||
|
if (!mSystem->ParseAtomComposite(attributeName, findName))
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!mSystem->ParseAtomComposite(findNameStr, findName))
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef BF_AST_HAS_PARENT_MEMBER
|
#ifdef BF_AST_HAS_PARENT_MEMBER
|
||||||
if (auto parentGenericTypeRef = BfNodeDynCast<BfGenericInstanceTypeRef>(typeRef->mParent))
|
if (auto parentGenericTypeRef = BfNodeDynCast<BfGenericInstanceTypeRef>(typeRef->mParent))
|
||||||
|
@ -6972,7 +6982,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
|
||||||
{
|
{
|
||||||
BfTypeLookupError error;
|
BfTypeLookupError error;
|
||||||
error.mRefNode = typeRef;
|
error.mRefNode = typeRef;
|
||||||
typeDef = FindTypeDef(typeRef, contextTypeInstance, &error);
|
typeDef = FindTypeDef(typeRef, contextTypeInstance, &error, 0, resolveFlags);
|
||||||
|
|
||||||
if (auto namedTypeRef = BfNodeDynCast<BfNamedTypeReference>(typeRef))
|
if (auto namedTypeRef = BfNodeDynCast<BfNamedTypeReference>(typeRef))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue