mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Added more PreFails
This commit is contained in:
parent
af274d1790
commit
4e3442d437
2 changed files with 57 additions and 25 deletions
|
@ -8462,7 +8462,8 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
|
||||||
{
|
{
|
||||||
if ((!resolvedTypeInstance->IsStruct()) && (!resolvedTypeInstance->IsTypedPrimitive()))
|
if ((!resolvedTypeInstance->IsStruct()) && (!resolvedTypeInstance->IsTypedPrimitive()))
|
||||||
{
|
{
|
||||||
mModule->Fail("Objects must be allocated through 'new' or 'scope'", targetSrc);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail("Objects must be allocated through 'new' or 'scope'", targetSrc);
|
||||||
return BfTypedValue();
|
return BfTypedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8747,9 +8748,15 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
|
||||||
// Would have caused a parsing error
|
// Would have caused a parsing error
|
||||||
}
|
}
|
||||||
else if (target.mType != NULL)
|
else if (target.mType != NULL)
|
||||||
mModule->Fail(StrFormat("Method '%s' does not exist in type '%s'", methodName.c_str(), mModule->TypeToString(target.mType).c_str()), targetSrc);
|
{
|
||||||
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail(StrFormat("Method '%s' does not exist in type '%s'", methodName.c_str(), mModule->TypeToString(target.mType).c_str()), targetSrc);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
mModule->Fail(StrFormat("Method '%s' does not exist", methodName.c_str()), targetSrc);
|
{
|
||||||
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail(StrFormat("Method '%s' does not exist", methodName.c_str()), targetSrc);
|
||||||
|
}
|
||||||
return BfTypedValue();
|
return BfTypedValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15898,7 +15905,8 @@ void BfExprEvaluator::DoInvocation(BfAstNode* target, BfMethodBoundExpression* m
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gaveUnqualifiedDotError = true;
|
gaveUnqualifiedDotError = true;
|
||||||
mModule->Fail(StrFormat("Cannot use inferred constructor on type '%s'", mModule->TypeToString(expectingType).c_str()), memberRefExpression->mDotToken);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail(StrFormat("Cannot use inferred constructor on type '%s'", mModule->TypeToString(expectingType).c_str()), memberRefExpression->mDotToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18868,6 +18876,8 @@ void BfExprEvaluator::DoMemberReference(BfMemberReferenceExpression* memberRefEx
|
||||||
}
|
}
|
||||||
else if (memberRefExpr->mMemberName != NULL)
|
else if (memberRefExpr->mMemberName != NULL)
|
||||||
findName = memberRefExpr->mMemberName->ToString();
|
findName = memberRefExpr->mMemberName->ToString();
|
||||||
|
else if (memberRefExpr->mDotToken != NULL)
|
||||||
|
mModule->FailAfter("Member name expected", memberRefExpr->mDotToken);
|
||||||
|
|
||||||
defer
|
defer
|
||||||
(
|
(
|
||||||
|
@ -18938,13 +18948,15 @@ void BfExprEvaluator::DoMemberReference(BfMemberReferenceExpression* memberRefEx
|
||||||
{
|
{
|
||||||
if (mExpectingType == NULL)
|
if (mExpectingType == NULL)
|
||||||
{
|
{
|
||||||
mModule->Fail("Unqualified dot syntax can only be used when the result type can be inferred", nameRefNode);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail("Unqualified dot syntax can only be used when the result type can be inferred", nameRefNode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expectingTypeInst == NULL)
|
if (expectingTypeInst == NULL)
|
||||||
{
|
{
|
||||||
mModule->Fail(StrFormat("Unqualified dot syntax cannot be used with type '%s'", mModule->TypeToString(mExpectingType).c_str()), nameRefNode);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail(StrFormat("Unqualified dot syntax cannot be used with type '%s'", mModule->TypeToString(mExpectingType).c_str()), nameRefNode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18952,7 +18964,7 @@ void BfExprEvaluator::DoMemberReference(BfMemberReferenceExpression* memberRefEx
|
||||||
{
|
{
|
||||||
mResult = mModule->GetDefaultTypedValue(mExpectingType);
|
mResult = mModule->GetDefaultTypedValue(mExpectingType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BfTypedValue expectingVal(expectingTypeInst);
|
BfTypedValue expectingVal(expectingTypeInst);
|
||||||
mResult = LookupField(memberRefExpr->mMemberName, expectingVal, findName);
|
mResult = LookupField(memberRefExpr->mMemberName, expectingVal, findName);
|
||||||
|
@ -19054,7 +19066,10 @@ void BfExprEvaluator::DoMemberReference(BfMemberReferenceExpression* memberRefEx
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mResult.mType == NULL)
|
if (mResult.mType == NULL)
|
||||||
mModule->Fail("Unable to find member", nameRefNode);
|
{
|
||||||
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail("Unable to find member", nameRefNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((isNullCondLookup) && (mPropDef == NULL))
|
if ((isNullCondLookup) && (mPropDef == NULL))
|
||||||
|
@ -19064,7 +19079,7 @@ void BfExprEvaluator::DoMemberReference(BfMemberReferenceExpression* memberRefEx
|
||||||
{
|
{
|
||||||
if (outCascadeValue != NULL)
|
if (outCascadeValue != NULL)
|
||||||
*outCascadeValue = thisValue;
|
*outCascadeValue = thisValue;
|
||||||
else
|
else if (mModule->PreFail())
|
||||||
mModule->Fail("Unexpected cascade operation. Chaining can only be used for method invocations", memberRefExpr->mDotToken);
|
mModule->Fail("Unexpected cascade operation. Chaining can only be used for method invocations", memberRefExpr->mDotToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21381,7 +21396,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
(binaryOp != BfBinaryOp_LessThan) && (binaryOp != BfBinaryOp_LessThanOrEqual) &&
|
(binaryOp != BfBinaryOp_LessThan) && (binaryOp != BfBinaryOp_LessThanOrEqual) &&
|
||||||
(binaryOp != BfBinaryOp_GreaterThan) && (binaryOp != BfBinaryOp_GreaterThanOrEqual))
|
(binaryOp != BfBinaryOp_GreaterThan) && (binaryOp != BfBinaryOp_GreaterThanOrEqual))
|
||||||
{
|
{
|
||||||
mModule->Fail("Invalid operation on pointers", opToken);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail("Invalid operation on pointers", opToken);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21397,7 +21413,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
{
|
{
|
||||||
if (!BfBinOpEqualityCheck(binaryOp))
|
if (!BfBinOpEqualityCheck(binaryOp))
|
||||||
{
|
{
|
||||||
mModule->Fail(StrFormat("Invalid operation between '%s' and null", mModule->TypeToString(resultType).c_str()), opToken);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail(StrFormat("Invalid operation between '%s' and null", mModule->TypeToString(resultType).c_str()), opToken);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21634,9 +21651,12 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mModule->Fail(StrFormat("Operator '%s' cannot be applied to operands of type '%s'",
|
if (mModule->PreFail())
|
||||||
BfGetOpName(binaryOp),
|
{
|
||||||
mModule->TypeToString(leftValue.mType).c_str()), opToken);
|
mModule->Fail(StrFormat("Operator '%s' cannot be applied to operands of type '%s'",
|
||||||
|
BfGetOpName(binaryOp),
|
||||||
|
mModule->TypeToString(leftValue.mType).c_str()), opToken);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -21886,7 +21906,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfType* resultType, BfIRValue convL
|
||||||
mModule->GetPrimitiveType(BfTypeCode_Boolean));
|
mModule->GetPrimitiveType(BfTypeCode_Boolean));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mModule->Fail("Invalid operation for booleans", opToken);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail("Invalid operation for booleans", opToken);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -21895,7 +21916,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfType* resultType, BfIRValue convL
|
||||||
|
|
||||||
if ((!resultType->IsIntegral()) && (!resultType->IsFloat()))
|
if ((!resultType->IsIntegral()) && (!resultType->IsFloat()))
|
||||||
{
|
{
|
||||||
mModule->Fail(StrFormat("Cannot perform operation on type '%s'", mModule->TypeToString(resultType).c_str()), opToken);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail(StrFormat("Cannot perform operation on type '%s'", mModule->TypeToString(resultType).c_str()), opToken);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22052,7 +22074,8 @@ void BfExprEvaluator::PerformBinaryOperation(BfType* resultType, BfIRValue convL
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mModule->Fail("Invalid operation", opToken);
|
if (mModule->PreFail())
|
||||||
|
mModule->Fail("Invalid operation", opToken);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8072,7 +8072,10 @@ BfTypedValue BfModule::CreateValueFromExpression(BfExprEvaluator& exprEvaluator,
|
||||||
if ((flags & BfEvalExprFlags_InferReturnType) != 0)
|
if ((flags & BfEvalExprFlags_InferReturnType) != 0)
|
||||||
return exprEvaluator.mResult;
|
return exprEvaluator.mResult;
|
||||||
if (!mCompiler->mPassInstance->HasFailed())
|
if (!mCompiler->mPassInstance->HasFailed())
|
||||||
Fail("INTERNAL ERROR: No expression result returned but no error caught in expression evaluator", expr);
|
{
|
||||||
|
if (PreFail())
|
||||||
|
Fail("INTERNAL ERROR: No expression result returned but no error caught in expression evaluator", expr);
|
||||||
|
}
|
||||||
return BfTypedValue();
|
return BfTypedValue();
|
||||||
}
|
}
|
||||||
auto typedVal = exprEvaluator.mResult;
|
auto typedVal = exprEvaluator.mResult;
|
||||||
|
@ -12068,6 +12071,12 @@ BfTypedValue BfModule::ExtractValue(BfTypedValue typedValue, BfFieldInstance* fi
|
||||||
|
|
||||||
if (fieldInstance == wantFieldInstance)
|
if (fieldInstance == wantFieldInstance)
|
||||||
{
|
{
|
||||||
|
if (fieldInstance->mResolvedType->IsValuelessType())
|
||||||
|
{
|
||||||
|
retVal = GetDefaultTypedValue(fieldInstance->mResolvedType);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
bool isAddr = false;
|
bool isAddr = false;
|
||||||
BfIRValue val = ExtractSplatValue(typedValue, componentIdx, fieldInstance->mResolvedType, &isAddr);
|
BfIRValue val = ExtractSplatValue(typedValue, componentIdx, fieldInstance->mResolvedType, &isAddr);
|
||||||
retVal = BfTypedValue(val, fieldInstance->mResolvedType,
|
retVal = BfTypedValue(val, fieldInstance->mResolvedType,
|
||||||
|
@ -21381,13 +21390,17 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
|
||||||
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, mWantsIRIgnoreWrites || mCurMethodInstance->mIsUnspecialized || mCurTypeInstance->mResolvingVarField);
|
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, mWantsIRIgnoreWrites || mCurMethodInstance->mIsUnspecialized || mCurTypeInstance->mResolvingVarField);
|
||||||
SetAndRestoreValue<bool> prevIsCapturingMethodMatchInfo;
|
SetAndRestoreValue<bool> prevIsCapturingMethodMatchInfo;
|
||||||
SetAndRestoreValue<bool> prevAllowLockYield(mContext->mAllowLockYield, false);
|
SetAndRestoreValue<bool> prevAllowLockYield(mContext->mAllowLockYield, false);
|
||||||
SetAndRestoreValue<BfMethodState*> prevMethodState(mCurMethodState, NULL);
|
|
||||||
if (mCompiler->IsAutocomplete())
|
if (mCompiler->IsAutocomplete())
|
||||||
prevIsCapturingMethodMatchInfo.Init(mCompiler->mResolvePassData->mAutoComplete->mIsCapturingMethodMatchInfo, false);
|
prevIsCapturingMethodMatchInfo.Init(mCompiler->mResolvePassData->mAutoComplete->mIsCapturingMethodMatchInfo, false);
|
||||||
|
|
||||||
if (mCurMethodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference)
|
if (mCurMethodInstance->mMethodInstanceGroup->mOnDemandKind == BfMethodOnDemandKind_NoDecl_AwaitingReference)
|
||||||
mCurMethodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingReference;
|
mCurMethodInstance->mMethodInstanceGroup->mOnDemandKind = BfMethodOnDemandKind_Decl_AwaitingReference;
|
||||||
|
|
||||||
|
BfMethodState methodState;
|
||||||
|
SetAndRestoreValue<BfMethodState*> prevMethodState(mCurMethodState, &methodState);
|
||||||
|
methodState.mTempKind = BfMethodState::TempKind_Static;
|
||||||
|
|
||||||
defer({ mCurMethodInstance->mHasBeenDeclared = true; });
|
defer({ mCurMethodInstance->mHasBeenDeclared = true; });
|
||||||
|
|
||||||
// If we are doing this then we may end up creating methods when var types are unknown still, failing on splat/zero-sized info
|
// If we are doing this then we may end up creating methods when var types are unknown still, failing on splat/zero-sized info
|
||||||
|
@ -21889,11 +21902,7 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
|
||||||
refNode = paramDef->mParamDeclaration->mModToken;
|
refNode = paramDef->mParamDeclaration->mModToken;
|
||||||
Fail("Cannot specify a default value for a 'params' parameter", refNode);
|
Fail("Cannot specify a default value for a 'params' parameter", refNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
BfMethodState methodState;
|
|
||||||
SetAndRestoreValue<BfMethodState*> prevMethodState(mCurMethodState, &methodState);
|
|
||||||
methodState.mTempKind = BfMethodState::TempKind_Static;
|
|
||||||
|
|
||||||
BfTypedValue defaultValue;
|
BfTypedValue defaultValue;
|
||||||
if (resolvedParamType->IsConstExprValue())
|
if (resolvedParamType->IsConstExprValue())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue