1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Struct cast fix, deferred block fix

This commit is contained in:
Brian Fiete 2019-12-13 14:22:23 -08:00
parent 2fb4b14e50
commit 8b17718fed
8 changed files with 82 additions and 18 deletions

View file

@ -230,6 +230,7 @@ public:
void CheckIdentifier(BfIdentifierNode* identifierNode, bool isInExpression = false, bool isUsingDirective = false); void CheckIdentifier(BfIdentifierNode* identifierNode, bool isInExpression = false, bool isUsingDirective = false);
bool CheckMemberReference(BfAstNode* target, BfAstNode* dotToken, BfAstNode* memberName, bool onlyShowTypes = false, BfType* expectingType = NULL, bool isUsingDirective = false, bool onlyAttribute = false); bool CheckMemberReference(BfAstNode* target, BfAstNode* dotToken, BfAstNode* memberName, bool onlyShowTypes = false, BfType* expectingType = NULL, bool isUsingDirective = false, bool onlyAttribute = false);
bool CheckExplicitInterface(BfTypeInstance* interfaceType, BfAstNode* dotToken, BfAstNode* memberName);
void CheckTypeRef(BfTypeReference* typeRef, bool mayBeIdentifier, bool isInExpression = false, bool onlyAttribute = false); void CheckTypeRef(BfTypeReference* typeRef, bool mayBeIdentifier, bool isInExpression = false, bool onlyAttribute = false);
void CheckAttributeTypeRef(BfTypeReference* typeRef); void CheckAttributeTypeRef(BfTypeReference* typeRef);
void CheckInvocation(BfAstNode* invocationNode, BfTokenNode* openParen, BfTokenNode* closeParen, const BfSizedArray<BfTokenNode*>& commas); void CheckInvocation(BfAstNode* invocationNode, BfTokenNode* openParen, BfTokenNode* closeParen, const BfSizedArray<BfTokenNode*>& commas);

View file

@ -752,7 +752,7 @@ void BfElementVisitor::Visit(BfDeferStatement* deferStmt)
void BfElementVisitor::Visit(BfReturnStatement* returnStmt) void BfElementVisitor::Visit(BfReturnStatement* returnStmt)
{ {
Visit(returnStmt->ToBase()); Visit(returnStmt->ToBase());
VisitChild(returnStmt->mReturnToken); VisitChild(returnStmt->mReturnToken);
VisitChild(returnStmt->mExpression); VisitChild(returnStmt->mExpression);

View file

@ -223,7 +223,9 @@ bool BfMethodMatcher::InferGenericArgument(BfMethodInstance* methodInstance, BfT
BfType* methodGenericTypeConstraint = NULL; BfType* methodGenericTypeConstraint = NULL;
auto _SetGeneric = [&]() auto _SetGeneric = [&]()
{ {
BF_ASSERT((argType == NULL) || (!argType->IsVar()));
if (mCheckMethodGenericArguments[wantGenericParam->mGenericParamIdx] != argType) if (mCheckMethodGenericArguments[wantGenericParam->mGenericParamIdx] != argType)
{ {
if (methodGenericTypeConstraint != NULL) if (methodGenericTypeConstraint != NULL)
@ -271,7 +273,7 @@ bool BfMethodMatcher::InferGenericArgument(BfMethodInstance* methodInstance, BfT
} }
} }
} }
mInferGenericProgressIdx++; mInferGenericProgressIdx++;
mCheckMethodGenericArguments[wantGenericParam->mGenericParamIdx] = argType; mCheckMethodGenericArguments[wantGenericParam->mGenericParamIdx] = argType;
} }
@ -1090,6 +1092,8 @@ bool BfMethodMatcher::InferFromGenericConstraints(BfGenericParamInstance* generi
if (checkArgType == NULL) if (checkArgType == NULL)
return false; return false;
if (checkArgType->IsVar())
return false;
(*methodGenericArgs)[genericParamType->mGenericParamIdx] = checkArgType; (*methodGenericArgs)[genericParamType->mGenericParamIdx] = checkArgType;
return true; return true;
@ -1572,7 +1576,13 @@ NoMatch:
if (genericArgumentsSubstitute != &mBestMethodGenericArguments) if (genericArgumentsSubstitute != &mBestMethodGenericArguments)
{ {
if (genericArgumentsSubstitute != NULL) if (genericArgumentsSubstitute != NULL)
{
mBestMethodGenericArguments = *genericArgumentsSubstitute; mBestMethodGenericArguments = *genericArgumentsSubstitute;
#ifdef _DEBUG
for (auto arg : mBestMethodGenericArguments)
BF_ASSERT((arg == NULL) || (!arg->IsVar()));
#endif
}
else else
mBestMethodGenericArguments.clear(); mBestMethodGenericArguments.clear();
} }
@ -3020,12 +3030,16 @@ BfTypedValue BfExprEvaluator::LookupIdentifier(BfIdentifierNode* identifierNode,
void BfExprEvaluator::Visit(BfIdentifierNode* identifierNode) void BfExprEvaluator::Visit(BfIdentifierNode* identifierNode)
{ {
if (GetAutoComplete() != NULL) auto autoComplete = GetAutoComplete();
GetAutoComplete()->CheckIdentifier(identifierNode, true); if (autoComplete != NULL)
autoComplete->CheckIdentifier(identifierNode, true);
mResult = LookupIdentifier(identifierNode); mResult = LookupIdentifier(identifierNode);
if ((!mResult) && (mPropDef == NULL)) if ((!mResult) && (mPropDef == NULL))
{
mModule->CheckTypeRefFixit(identifierNode);
mModule->Fail("Identifier not found", identifierNode); mModule->Fail("Identifier not found", identifierNode);
}
} }
void BfExprEvaluator::Visit(BfAttributedIdentifierNode* attrIdentifierNode) void BfExprEvaluator::Visit(BfAttributedIdentifierNode* attrIdentifierNode)

View file

@ -9065,8 +9065,9 @@ String BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags
BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None; BfTypeNameFlags typeNameFlags = BfTypeNameFlags_None;
if (!methodInst->mIsUnspecializedVariation && allowResolveGenericParamNames) if (!methodInst->mIsUnspecializedVariation && allowResolveGenericParamNames)
typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames; typeNameFlags = BfTypeNameFlag_ResolveGenericParamNames;
methodName += "[";
methodName += TypeToString(methodInst->mMethodInfoEx->mExplicitInterface, typeNameFlags); methodName += TypeToString(methodInst->mMethodInfoEx->mExplicitInterface, typeNameFlags);
methodName += "."; methodName += "].";
} }
if (methodDef->mMethodType == BfMethodType_Operator) if (methodDef->mMethodType == BfMethodType_Operator)
@ -9103,13 +9104,17 @@ String BfModule::MethodToString(BfMethodInstance* methodInst, BfMethodNameFlags
} }
else if (methodDef->mMethodType == BfMethodType_PropertyGetter) else if (methodDef->mMethodType == BfMethodType_PropertyGetter)
{ {
methodDef->GetRefNode()->ToString(methodName); auto propertyDecl = methodDef->GetPropertyDeclaration();
if ((propertyDecl != NULL) && (propertyDecl->mNameNode != NULL))
propertyDecl->mNameNode->ToString(methodName);
methodName += " get accessor"; methodName += " get accessor";
return methodName; return methodName;
} }
else if (methodDef->mMethodType == BfMethodType_PropertySetter) else if (methodDef->mMethodType == BfMethodType_PropertySetter)
{ {
methodDef->GetRefNode()->ToString(methodName); auto propertyDecl = methodDef->GetPropertyDeclaration();
if ((propertyDecl != NULL) && (propertyDecl->mNameNode != NULL))
propertyDecl->mNameNode->ToString(methodName);
methodName += " set accessor"; methodName += " set accessor";
return methodName; return methodName;
} }
@ -19037,11 +19042,30 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
if (methodDef->mExplicitInterface != NULL) if (methodDef->mExplicitInterface != NULL)
{ {
if ((mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL)) auto autoComplete = mCompiler->GetAutoComplete();
mCompiler->mResolvePassData->mAutoComplete->CheckTypeRef(methodDef->mExplicitInterface, false);
auto explicitInterface = ResolveTypeRef(methodDef->mExplicitInterface, BfPopulateType_Declaration); if (autoComplete != NULL)
autoComplete->CheckTypeRef(methodDef->mExplicitInterface, false);
auto explicitType = ResolveTypeRef(methodDef->mExplicitInterface, BfPopulateType_Declaration);
BfTypeInstance* explicitInterface = NULL;
if (explicitType != NULL)
explicitInterface = explicitType->ToTypeInstance();
if (explicitInterface != NULL) if (explicitInterface != NULL)
{
mCurMethodInstance->GetMethodInfoEx()->mExplicitInterface = explicitInterface->ToTypeInstance(); mCurMethodInstance->GetMethodInfoEx()->mExplicitInterface = explicitInterface->ToTypeInstance();
if (autoComplete != NULL)
{
BfTokenNode* dotToken = NULL;
BfAstNode* nameNode = NULL;
if (auto methodDeclaration = BfNodeDynCast<BfMethodDeclaration>(methodDef->mMethodDeclaration))
{
dotToken = methodDeclaration->mExplicitInterfaceDotToken;
nameNode = methodDeclaration->mNameNode;
}
autoComplete->CheckExplicitInterface(explicitInterface, dotToken, nameNode);
}
}
if ((mCurMethodInstance->mMethodInfoEx != NULL) && (mCurMethodInstance->mMethodInfoEx->mExplicitInterface != NULL)) if ((mCurMethodInstance->mMethodInfoEx != NULL) && (mCurMethodInstance->mMethodInfoEx->mExplicitInterface != NULL))
{ {
bool interfaceFound = false; bool interfaceFound = false;
@ -20357,7 +20381,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo
continue; continue;
bool hadMatch = false; bool hadMatch = false;
bool hadNameMatch = false; BfMethodInstance* hadNameMatch = NULL;
BfType* expectedReturnType = NULL; BfType* expectedReturnType = NULL;
bool showedError = false; bool showedError = false;
@ -20394,7 +20418,7 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo
continue; continue;
} }
if (iMethodInst->mMethodDef->mName == methodInstance->mMethodDef->mName) if (iMethodInst->mMethodDef->mName == methodInstance->mMethodDef->mName)
hadNameMatch = true; hadNameMatch = iMethodInst;
bool doesMethodSignatureMatch = CompareMethodSignatures(iMethodInst, methodInstance); bool doesMethodSignatureMatch = CompareMethodSignatures(iMethodInst, methodInstance);
@ -20467,16 +20491,31 @@ bool BfModule::SlotVirtualMethod(BfMethodInstance* methodInstance, BfAmbiguityCo
} }
checkMethodDef = checkMethodDef->mNextWithSameName; checkMethodDef = checkMethodDef->mNextWithSameName;
} }
if ((methodInstance->mMethodInfoEx != NULL) && (methodInstance->mMethodInfoEx->mExplicitInterface == ifaceInst) && (!hadMatch) && (!showedError)) if ((methodInstance->mMethodInfoEx != NULL) && (methodInstance->mMethodInfoEx->mExplicitInterface == ifaceInst) && (!hadMatch) && (!showedError))
{ {
if (expectedReturnType != NULL) if (expectedReturnType != NULL)
Fail(StrFormat("Wrong return type, expected '%s'", TypeToString(expectedReturnType).c_str()), declaringNode, true); Fail(StrFormat("Wrong return type, expected '%s'", TypeToString(expectedReturnType).c_str()), declaringNode, true);
else if (hadNameMatch) else if (hadNameMatch != NULL)
Fail("Method parameters don't match interface method", declaringNode, true); {
auto error = Fail("Method parameters don't match interface method", declaringNode, true);
if (error != NULL)
mCompiler->mPassInstance->MoreInfo("See interface method declaration", hadNameMatch->mMethodDef->GetRefNode());
}
else else
Fail("Method name not found in interface", methodDef->GetRefNode(), true); {
auto propertyDecl = methodDef->GetPropertyDeclaration();
if (propertyDecl != NULL)
{
auto propertyMethodDecl = methodDef->GetPropertyMethodDeclaration();
Fail(StrFormat("Property '%s' %s accessor not defined in interface '%s'", propertyDecl->mNameNode->ToString().c_str(),
(methodDef->mMethodType == BfMethodType_PropertyGetter) ? "get" : "set", TypeToString(ifaceInst).c_str()), methodDef->GetRefNode(), true);
}
else
Fail(StrFormat("Method '%s' not found in interface '%s'", methodDef->mName.c_str(), TypeToString(ifaceInst).c_str()), methodDef->GetRefNode(), true);
}
} }
} }

View file

@ -249,6 +249,7 @@ public:
SizedArray<BfIRValue, 1> mScopeArgs; SizedArray<BfIRValue, 1> mScopeArgs;
Array<BfDeferredCapture> mCaptures; Array<BfDeferredCapture> mCaptures;
BfBlock* mDeferredBlock; BfBlock* mDeferredBlock;
int64 mBlockId;
int mHandlerCount; int mHandlerCount;
bool mBypassVirtual; bool mBypassVirtual;
bool mDoNullCheck; bool mDoNullCheck;
@ -267,6 +268,7 @@ public:
mNext = NULL; mNext = NULL;
mSrcNode = NULL; mSrcNode = NULL;
mDeferredBlock = NULL; mDeferredBlock = NULL;
mBlockId = -1;
mHandlerCount = 0; mHandlerCount = 0;
mArgsNeedLoad = false; mArgsNeedLoad = false;
mCastThis = false; mCastThis = false;

View file

@ -8079,6 +8079,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
{ {
if (toType->IsValuelessType()) if (toType->IsValuelessType())
return BfIRValue::sValueless; return BfIRValue::sValueless;
if (ignoreWrites)
return mBfIRBuilder->GetFakeVal();
typedVal = MakeAddressable(typedVal);
return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapTypeInstPtr(toTypeInstance));
} }
} }

View file

@ -250,12 +250,14 @@ void BfSourceClassifier::Visit(BfThisExpression* thisExpr)
{ {
HandleLeafNode(thisExpr); HandleLeafNode(thisExpr);
Visit((BfAstNode*)thisExpr); Visit((BfAstNode*)thisExpr);
SetElementType(thisExpr, BfSourceElementType_Keyword);
} }
void BfSourceClassifier::Visit(BfBaseExpression* baseExpr) void BfSourceClassifier::Visit(BfBaseExpression* baseExpr)
{ {
HandleLeafNode(baseExpr); HandleLeafNode(baseExpr);
Visit((BfAstNode*)baseExpr); Visit((BfAstNode*)baseExpr);
SetElementType(baseExpr, BfSourceElementType_Keyword);
} }
void BfSourceClassifier::Visit(BfMemberReferenceExpression* memberRefExpr) void BfSourceClassifier::Visit(BfMemberReferenceExpression* memberRefExpr)

View file

@ -186,6 +186,7 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
hashCtx.MixinStr(parserData->mFileName); hashCtx.MixinStr(parserData->mFileName);
int64 blockId = BfDeferredMethodCallData::GenerateMethodId(this, hashCtx.Finish64()); int64 blockId = BfDeferredMethodCallData::GenerateMethodId(this, hashCtx.Finish64());
deferredCallEntry->mBlockId = blockId;
auto deferType = deferredCallEntryType; auto deferType = deferredCallEntryType;
@ -797,7 +798,7 @@ void BfModule::EmitDeferredCallProcessor(SLIList<BfDeferredCallEntry*>& callEntr
deferredCallEntry = deferredCallEntry->mNext; deferredCallEntry = deferredCallEntry->mNext;
continue; continue;
} }
int blockId = -block->GetSrcStart(); int64 blockId = deferredCallEntry->mBlockId;
//auto itr = handledSet.insert(deferredCallEntry); //auto itr = handledSet.insert(deferredCallEntry);
//if (!itr.second) //if (!itr.second)