1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed repr for on-demand delegate types, avoiding circular Event refs

This commit is contained in:
Brian Fiete 2020-01-23 12:02:54 -08:00
parent ddc943876d
commit 95e4c1b3ca
10 changed files with 39 additions and 78 deletions

View file

@ -196,11 +196,6 @@ void BfStructuralVisitor::Visit(BfCollectionInitializerExpression* collectionIni
Visit(collectionInitExpr->ToBase());
}
void BfStructuralVisitor::Visit(BfArraySizeSpecifier* arraySizeSpecifier)
{
Visit(arraySizeSpecifier->ToBase());
}
void BfStructuralVisitor::Visit(BfTypeReference* typeRef)
{
Visit(typeRef->ToBase());

View file

@ -351,7 +351,6 @@ class BfDefaultExpression;
class BfUninitializedExpression;
class BfConditionalExpression;
class BfCollectionInitializerExpression;
class BfArraySizeSpecifier;
class BfSizedArrayCreateExpression;
class BfEmptyStatement;
class BfGenericOperatorConstraint;
@ -433,7 +432,6 @@ public:
virtual void Visit(BfMixinExpression* thisExpr);
virtual void Visit(BfSizedArrayCreateExpression* createExpr);
virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr);
virtual void Visit(BfArraySizeSpecifier* arraySizeSpecifier);
virtual void Visit(BfTypeReference* typeRef);
virtual void Visit(BfNamedTypeReference* typeRef);
virtual void Visit(BfQualifiedTypeReference* qualifiedType);
@ -2571,17 +2569,6 @@ public:
BfExpression* mExpression;
}; BF_AST_DECL(BfAttributedExpression, BfExpression);
class BfArraySizeSpecifier : public BfAstNode
{
public:
BF_AST_TYPE(BfArraySizeSpecifier, BfAstNode);
BfTokenNode* mOpenToken;
BfTokenNode* mCloseToken;
BfSizedArray<BfExpression*> mArguments;
BfSizedArray<BfTokenNode*> mCommas;
}; BF_AST_DECL(BfArraySizeSpecifier, BfAstNode);
class BfObjectCreateExpression : public BfMethodBoundExpression
{
public:

View file

@ -251,18 +251,6 @@ void BfElementVisitor::Visit(BfCollectionInitializerExpression* collectionInitEx
VisitChild(collectionInitExpr->mCloseBrace);
}
void BfElementVisitor::Visit(BfArraySizeSpecifier* arraySizeSpecifier)
{
Visit(arraySizeSpecifier->ToBase());
VisitChild(arraySizeSpecifier->mOpenToken);
for (auto& val : arraySizeSpecifier->mArguments)
VisitChild(val);
for (auto& val : arraySizeSpecifier->mCommas)
VisitChild(val);
VisitChild(arraySizeSpecifier->mCloseToken);
}
void BfElementVisitor::Visit(BfTypeReference* typeRef)
{
Visit(typeRef->ToBase());

View file

@ -44,7 +44,6 @@ public:
virtual void Visit(BfMixinExpression* thisExpr);
virtual void Visit(BfSizedArrayCreateExpression* createExpr);
virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr);
virtual void Visit(BfArraySizeSpecifier* arraySizeSpecifier);
virtual void Visit(BfTypeReference* typeRef);
virtual void Visit(BfNamedTypeReference* typeRef);
virtual void Visit(BfQualifiedTypeReference* qualifiedType);

View file

@ -15531,10 +15531,7 @@ BfTypedValue BfExprEvaluator::SetupNullConditional(BfTypedValue thisValue, BfTok
}
else
{
if (thisValue.mType->IsStruct())
mModule->Warn(0, "Struct lookups can never fail, null conditional reference is unnecessary", dotToken);
else
mModule->AssertErrorState();
mModule->Warn(0, StrFormat("Null conditional reference is unnecessary since value type '%s' can never be null", mModule->TypeToString(thisValue.mType).c_str()), dotToken);
return thisValue;
}

View file

@ -7497,6 +7497,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
delegateType->mDirectAllocNodes.push_back(directTypeRef);
directTypeRef->Init(returnType);
methodDef->mReturnTypeRef = directTypeRef;
delegateType->mReturnType = returnType;
AddDependency(directTypeRef->mType, baseDelegateType, BfDependencyMap::DependencyFlag_ParamOrReturnValue);
@ -7506,6 +7507,8 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
for (auto param : delegateTypeRef->mParams)
{
auto paramType = ResolveTypeRef(param->mTypeRef, BfPopulateType_Declaration, BfResolveTypeRefFlag_AllowRef);
if (paramType == NULL)
paramType = GetPrimitiveType(BfTypeCode_Var);
String paramName;
if (param->mNameNode != NULL)
paramName = param->mNameNode->ToString();
@ -7532,6 +7535,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
methodDef->mParams.push_back(paramDef);
paramIdx++;
delegateType->mParams.Add(paramType);
AddDependency(paramType, baseDelegateType, BfDependencyMap::DependencyFlag_ParamOrReturnValue);
}
@ -7545,7 +7549,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
delegateType->mContext = mContext;
delegateType->mTypeDef = typeDef;
InitType(delegateType, BfPopulateType_DataAndMethods);
InitType(delegateType, populateType);
resolvedEntry->mValue = delegateType;
// #ifdef _DEBUG
@ -9795,7 +9799,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
str += "delegate ";
else
str += "function ";
DoTypeToString(str, ResolveTypeRef(methodDef->mReturnTypeRef));
DoTypeToString(str, delegateType->mReturnType);
str += "(";
for (int paramIdx = 0; paramIdx < methodDef->mParams.size(); paramIdx++)
{
@ -9805,7 +9809,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
BfTypeNameFlags innerFlags = (BfTypeNameFlags)(typeNameFlags & ~(BfTypeNameFlag_OmitNamespace | BfTypeNameFlag_OmitOuterType));
if (delegateType->mIsUnspecializedTypeVariation)
innerFlags = (BfTypeNameFlags)(innerFlags & ~BfTypeNameFlag_ResolveGenericParamNames);
DoTypeToString(str, ResolveTypeRef(paramDef->mTypeRef), innerFlags, genericMethodNameOverrides);
DoTypeToString(str, delegateType->mParams[paramIdx], innerFlags, genericMethodNameOverrides);
str += " ";
str += paramDef->mName;
}

View file

@ -933,23 +933,6 @@ void BfPrinter::Visit(BfCollectionInitializerExpression* initExpr)
VisitChild(initExpr->mCloseBrace);
}
void BfPrinter::Visit(BfArraySizeSpecifier* arraySizeSpecifier)
{
Visit(arraySizeSpecifier->ToBase());
VisitChild(arraySizeSpecifier->mOpenToken);
for (int i = 0; i < (int)arraySizeSpecifier->mArguments.size(); i++)
{
if (i > 0)
{
VisitChild(arraySizeSpecifier->mCommas[i - 1]);
ExpectSpace();
}
VisitChild(arraySizeSpecifier->mArguments[i]);
}
VisitChild(arraySizeSpecifier->mCloseToken);
}
void BfPrinter::Visit(BfTypeReference* typeRef)
{
Visit(typeRef->ToBase());

View file

@ -129,7 +129,6 @@ public:
virtual void Visit(BfMixinExpression* mixinExpr) override;
virtual void Visit(BfSizedArrayCreateExpression* createExpr) override;
virtual void Visit(BfCollectionInitializerExpression* initExpr) override;
virtual void Visit(BfArraySizeSpecifier* arraySizeSpecifier) override;
virtual void Visit(BfTypeReference* typeRef) override;
virtual void Visit(BfNamedTypeReference* typeRef) override;
virtual void Visit(BfQualifiedTypeReference* qualifiedType) override;

View file

@ -2072,17 +2072,21 @@ int BfResolvedTypeSet::Hash(BfType* type, LookupContext* ctx, bool allowRef)
}
else if (type->IsDelegateFromTypeRef() || type->IsFunctionFromTypeRef())
{
auto delegateType = (BfDelegateType*)type;
int hashVal = HASH_DELEGATE;
BfMethodInstance* invokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(type->ToTypeInstance(), 0, "Invoke");
hashVal = ((hashVal ^ (Hash(delegateType->mReturnType, ctx))) << 5) - hashVal;
hashVal = ((hashVal ^ (Hash(invokeMethodInstance->mReturnType, ctx))) << 5) - hashVal;
auto methodDef = delegateType->mTypeDef->mMethods[0];
BF_ASSERT(methodDef->mName == "Invoke");
BF_ASSERT(delegateType->mParams.size() == methodDef->mParams.size());
for (int paramIdx = 0; paramIdx < invokeMethodInstance->mParams.size(); paramIdx++)
for (int paramIdx = 0; paramIdx < delegateType->mParams.size(); paramIdx++)
{
// Parse attributes?
hashVal = ((hashVal ^ (Hash(invokeMethodInstance->GetParamType(paramIdx), ctx))) << 5) - hashVal;
String paramName = invokeMethodInstance->GetParamName(paramIdx);
hashVal = ((hashVal ^ (Hash(delegateType->mParams[paramIdx], ctx))) << 5) - hashVal;
String paramName = methodDef->mParams[paramIdx]->mName;
int nameHash = (int)Hash64(paramName.c_str(), (int)paramName.length());
hashVal = ((hashVal ^ (nameHash)) << 5) - hashVal;
}
@ -2876,17 +2880,18 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx)
if (lhsDelegateType->mTypeDef->mIsDelegate != rhsDelegateType->mTypeDef->mIsDelegate)
return false;
BfMethodInstance* lhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(lhsDelegateType->ToTypeInstance(), 0, "Invoke");
BfMethodInstance* rhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(rhsDelegateType->ToTypeInstance(), 0, "Invoke");
if (lhsInvokeMethodInstance->mReturnType != rhsInvokeMethodInstance->mReturnType)
auto lhsMethodDef = lhsDelegateType->mTypeDef->mMethods[0];
auto rhsMethodDef = rhsDelegateType->mTypeDef->mMethods[0];
if (lhsDelegateType->mReturnType != rhsDelegateType->mReturnType)
return false;
if (lhsInvokeMethodInstance->GetParamCount() != rhsInvokeMethodInstance->GetParamCount())
if (lhsDelegateType->mParams.size() != rhsDelegateType->mParams.size())
return false;
for (int paramIdx = 0; paramIdx < lhsInvokeMethodInstance->GetParamCount(); paramIdx++)
for (int paramIdx = 0; paramIdx < lhsDelegateType->mParams.size(); paramIdx++)
{
if (lhsInvokeMethodInstance->GetParamType(paramIdx) != rhsInvokeMethodInstance->GetParamType(paramIdx))
if (lhsDelegateType->mParams[paramIdx] != rhsDelegateType->mParams[paramIdx])
return false;
if (lhsInvokeMethodInstance->GetParamName(paramIdx) != rhsInvokeMethodInstance->GetParamName(paramIdx))
if (lhsMethodDef->mParams[paramIdx]->mName != rhsMethodDef->mParams[paramIdx]->mName)
return false;
}
return true;

View file

@ -1921,11 +1921,15 @@ public:
bool mIsUnspecializedType;
bool mIsUnspecializedTypeVariation;
BfType* mReturnType;
Array<BfType*> mParams;
public:
BfDelegateType()
{
mIsUnspecializedType = false;
mIsUnspecializedTypeVariation = false;
mReturnType = NULL;
}
~BfDelegateType();