1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Placeholder implementation for constraint expressions

This commit is contained in:
Brian Fiete 2022-03-23 09:35:02 -07:00
parent dead14fac6
commit 6e38c1c3b6
3 changed files with 81 additions and 13 deletions

View file

@ -3000,11 +3000,21 @@ public:
BfSizedArray<ASTREF(BfTokenNode*)> mCommas;
}; BF_AST_DECL(BfGenericConstraint, BfAstNode);
class BfGenericConstraintExpression : public BfAstNode
{
public:
BF_AST_TYPE(BfGenericConstraintExpression, BfAstNode);
BfTokenNode* mWhereToken;
BfExpression* mExpression;
}; BF_AST_DECL(BfGenericConstraintExpression, BfAstNode);
class BfGenericConstraintsDeclaration : public BfAstNode
{
public:
BF_AST_TYPE(BfGenericConstraintsDeclaration, BfAstNode);
BfSizedArray<BfGenericConstraint*> mGenericConstraints;
BfSizedArray<BfAstNode*> mGenericConstraints;
bool mHasExpressions;
}; BF_AST_DECL(BfGenericConstraintsDeclaration, BfAstNode);
class BfMethodDeclaration : public BfMemberDeclaration

View file

@ -83,7 +83,9 @@ void BfElementVisitor::Visit(BfGenericConstraintsDeclaration* genericConstraints
{
Visit(genericConstraints->ToBase());
for (auto genericConstraint : genericConstraints->mGenericConstraints)
for (auto genericConstraintNode : genericConstraints->mGenericConstraints)
{
if (auto genericConstraint = BfNodeDynCast<BfGenericConstraint>(genericConstraintNode))
{
VisitChild(genericConstraint->mWhereToken);
VisitChild(genericConstraint->mTypeRef);
@ -93,6 +95,12 @@ void BfElementVisitor::Visit(BfGenericConstraintsDeclaration* genericConstraints
for (auto val : genericConstraint->mCommas)
VisitChild(val);
}
else if (auto genericConstraintExpr = BfNodeDynCast<BfGenericConstraintExpression>(genericConstraintNode))
{
VisitChild(genericConstraintExpr->mWhereToken);
VisitChild(genericConstraintExpr->mExpression);
}
}
}
void BfElementVisitor::Visit(BfGenericArgumentsNode* genericArgumentsNode)

View file

@ -9945,11 +9945,61 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration(
{
auto constraintsDeclaration = mAlloc->Alloc<BfGenericConstraintsDeclaration>();
BfDeferredAstSizedArray<BfGenericConstraint*> genericConstraintsArr(constraintsDeclaration->mGenericConstraints, mAlloc);
BfDeferredAstSizedArray<BfAstNode*> genericConstraintsArr(constraintsDeclaration->mGenericConstraints, mAlloc);
bool isDone = false;
for (int constraintIdx = 0; !isDone; constraintIdx++)
{
// if (auto nextToken = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext()))
// {
// if (nextToken->mToken == BfToken_LParen)
// {
// BfGenericConstraintExpression* genericConstraint = mAlloc->Alloc<BfGenericConstraintExpression>();
// ReplaceNode(tokenNode, genericConstraint);
// genericConstraint->mWhereToken = tokenNode;
// constraintsDeclaration->mHasExpressions = true;
//
// genericConstraintsArr.push_back(genericConstraint);
//
// auto expr = CreateExpressionAfter(genericConstraint, CreateExprFlags_EarlyExit);
// if (expr == NULL)
// break;
//
// MEMBER_SET(genericConstraint, mExpression, expr);
//
// BfTokenNode* nextWhereToken = NULL;
// if (auto checkToken = BfNodeDynCast<BfTokenNode>(mVisitorPos.GetNext()))
// {
// if (checkToken->mToken != BfToken_Where)
// nextWhereToken = checkToken;
// }
//
// auto nextNode = mVisitorPos.GetNext();
// if (BfNodeDynCast<BfBlock>(nextNode))
// break;
//
// bool handled = false;
// if (auto tokenNode = BfNodeDynCast<BfTokenNode>(nextNode))
// {
// if (tokenNode->mToken == BfToken_FatArrow)
// break;
// }
//
// tokenNode = ExpectTokenAfter(genericConstraint, BfToken_LBrace, BfToken_Where, BfToken_Semicolon);
// if (tokenNode == NULL)
// break;
//
// BfToken token = tokenNode->GetToken();
// if (token != BfToken_Where)
// {
// mVisitorPos.mReadPos--;
// break;
// }
//
// continue;
// }
// }
BfGenericConstraint* genericConstraint = mAlloc->Alloc<BfGenericConstraint>();
BfDeferredAstSizedArray<BfAstNode*> constraintTypes(genericConstraint->mConstraintTypes, mAlloc);
BfDeferredAstSizedArray<BfTokenNode*> commas(genericConstraint->mCommas, mAlloc);
@ -9975,7 +10025,6 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration(
else
isDone = true;
for (int typeIdx = 0; !isDone; typeIdx++)
{
if (typeIdx > 0)
@ -9987,6 +10036,7 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration(
break;
}
bool handled = false;
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(nextNode))
{
if (tokenNode->mToken == BfToken_FatArrow)