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:
parent
ddc943876d
commit
95e4c1b3ca
10 changed files with 39 additions and 78 deletions
|
@ -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());
|
||||
|
|
|
@ -351,7 +351,6 @@ class BfDefaultExpression;
|
|||
class BfUninitializedExpression;
|
||||
class BfConditionalExpression;
|
||||
class BfCollectionInitializerExpression;
|
||||
class BfArraySizeSpecifier;
|
||||
class BfSizedArrayCreateExpression;
|
||||
class BfEmptyStatement;
|
||||
class BfGenericOperatorConstraint;
|
||||
|
@ -432,8 +431,7 @@ public:
|
|||
virtual void Visit(BfBaseExpression* baseExpr);
|
||||
virtual void Visit(BfMixinExpression* thisExpr);
|
||||
virtual void Visit(BfSizedArrayCreateExpression* createExpr);
|
||||
virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr);
|
||||
virtual void Visit(BfArraySizeSpecifier* arraySizeSpecifier);
|
||||
virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr);
|
||||
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:
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -43,8 +43,7 @@ public:
|
|||
virtual void Visit(BfBaseExpression* baseExpr);
|
||||
virtual void Visit(BfMixinExpression* thisExpr);
|
||||
virtual void Visit(BfSizedArrayCreateExpression* createExpr);
|
||||
virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr);
|
||||
virtual void Visit(BfArraySizeSpecifier* arraySizeSpecifier);
|
||||
virtual void Visit(BfCollectionInitializerExpression* collectionInitExpr);
|
||||
virtual void Visit(BfTypeReference* typeRef);
|
||||
virtual void Visit(BfNamedTypeReference* typeRef);
|
||||
virtual void Visit(BfQualifiedTypeReference* qualifiedType);
|
||||
|
|
|
@ -15530,11 +15530,8 @@ BfTypedValue BfExprEvaluator::SetupNullConditional(BfTypedValue thisValue, BfTok
|
|||
// Also good
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -7459,7 +7459,7 @@ BfType* BfModule::ResolveTypeRef(BfTypeReference* typeRef, BfPopulateType popula
|
|||
|
||||
auto baseDelegateType = ResolveTypeDef(mCompiler->mDelegateTypeDef)->ToTypeInstance();
|
||||
|
||||
BfDelegateType* delegateType = new BfDelegateType();
|
||||
BfDelegateType* delegateType = new BfDelegateType();
|
||||
|
||||
Val128 hashContext;
|
||||
|
||||
|
@ -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
|
||||
|
@ -9775,7 +9779,7 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
|
|||
}
|
||||
str += ")";
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (resolvedType->IsDelegateFromTypeRef() || resolvedType->IsFunctionFromTypeRef())
|
||||
{
|
||||
SetAndRestoreValue<BfTypeInstance*> prevTypeInstance(mCurTypeInstance);
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -128,8 +128,7 @@ public:
|
|||
virtual void Visit(BfBaseExpression* baseExpr) override;
|
||||
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(BfCollectionInitializerExpression* initExpr) override;
|
||||
virtual void Visit(BfTypeReference* typeRef) override;
|
||||
virtual void Visit(BfNamedTypeReference* typeRef) override;
|
||||
virtual void Visit(BfQualifiedTypeReference* qualifiedType) override;
|
||||
|
|
|
@ -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;
|
||||
|
||||
hashVal = ((hashVal ^ (Hash(delegateType->mReturnType, ctx))) << 5) - hashVal;
|
||||
|
||||
BfMethodInstance* invokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(type->ToTypeInstance(), 0, "Invoke");
|
||||
auto methodDef = delegateType->mTypeDef->mMethods[0];
|
||||
BF_ASSERT(methodDef->mName == "Invoke");
|
||||
BF_ASSERT(delegateType->mParams.size() == methodDef->mParams.size());
|
||||
|
||||
hashVal = ((hashVal ^ (Hash(invokeMethodInstance->mReturnType, ctx))) << 5) - hashVal;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -2875,18 +2879,19 @@ bool BfResolvedTypeSet::Equals(BfType* lhs, BfType* rhs, LookupContext* ctx)
|
|||
BfDelegateType* rhsDelegateType = (BfDelegateType*)rhs;
|
||||
if (lhsDelegateType->mTypeDef->mIsDelegate != rhsDelegateType->mTypeDef->mIsDelegate)
|
||||
return false;
|
||||
|
||||
auto lhsMethodDef = lhsDelegateType->mTypeDef->mMethods[0];
|
||||
auto rhsMethodDef = rhsDelegateType->mTypeDef->mMethods[0];
|
||||
|
||||
BfMethodInstance* lhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(lhsDelegateType->ToTypeInstance(), 0, "Invoke");
|
||||
BfMethodInstance* rhsInvokeMethodInstance = ctx->mModule->GetRawMethodInstanceAtIdx(rhsDelegateType->ToTypeInstance(), 0, "Invoke");
|
||||
if (lhsInvokeMethodInstance->mReturnType != rhsInvokeMethodInstance->mReturnType)
|
||||
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;
|
||||
|
|
|
@ -461,7 +461,7 @@ public:
|
|||
virtual bool IsString() { return false; }
|
||||
virtual bool IsSizedArray() { return false; }
|
||||
virtual bool IsUnknownSizedArray() { return false; }
|
||||
virtual bool IsArray() { return false; }
|
||||
virtual bool IsArray() { return false; }
|
||||
virtual bool IsDelegate() { return false; }
|
||||
virtual bool IsFunction() { return false; }
|
||||
virtual bool IsDelegateFromTypeRef() { return false; }
|
||||
|
@ -1920,16 +1920,20 @@ public:
|
|||
// These depend on the params in Invoke
|
||||
bool mIsUnspecializedType;
|
||||
bool mIsUnspecializedTypeVariation;
|
||||
|
||||
BfType* mReturnType;
|
||||
Array<BfType*> mParams;
|
||||
|
||||
public:
|
||||
BfDelegateType()
|
||||
{
|
||||
mIsUnspecializedType = false;
|
||||
mIsUnspecializedTypeVariation = false;
|
||||
mReturnType = NULL;
|
||||
}
|
||||
~BfDelegateType();
|
||||
|
||||
virtual bool IsOnDemand() override { return true; }
|
||||
|
||||
virtual bool IsOnDemand() override { return true; }
|
||||
|
||||
virtual bool IsDelegate() override { return mTypeDef->mIsDelegate; }
|
||||
virtual bool IsDelegateFromTypeRef() override { return mTypeDef->mIsDelegate; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue