diff --git a/IDEHelper/Compiler/BfAst.h b/IDEHelper/Compiler/BfAst.h index 67cd72d2..5b38594c 100644 --- a/IDEHelper/Compiler/BfAst.h +++ b/IDEHelper/Compiler/BfAst.h @@ -3000,11 +3000,21 @@ public: BfSizedArray 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 mGenericConstraints; + BfSizedArray mGenericConstraints; + bool mHasExpressions; }; BF_AST_DECL(BfGenericConstraintsDeclaration, BfAstNode); class BfMethodDeclaration : public BfMemberDeclaration diff --git a/IDEHelper/Compiler/BfElementVisitor.cpp b/IDEHelper/Compiler/BfElementVisitor.cpp index 40b3f692..cc97d5b0 100644 --- a/IDEHelper/Compiler/BfElementVisitor.cpp +++ b/IDEHelper/Compiler/BfElementVisitor.cpp @@ -83,15 +83,23 @@ void BfElementVisitor::Visit(BfGenericConstraintsDeclaration* genericConstraints { Visit(genericConstraints->ToBase()); - for (auto genericConstraint : genericConstraints->mGenericConstraints) + for (auto genericConstraintNode : genericConstraints->mGenericConstraints) { - VisitChild(genericConstraint->mWhereToken); - VisitChild(genericConstraint->mTypeRef); - VisitChild(genericConstraint->mColonToken); - for (auto val : genericConstraint->mConstraintTypes) - VisitChild(val); - for (auto val : genericConstraint->mCommas) - VisitChild(val); + if (auto genericConstraint = BfNodeDynCast(genericConstraintNode)) + { + VisitChild(genericConstraint->mWhereToken); + VisitChild(genericConstraint->mTypeRef); + VisitChild(genericConstraint->mColonToken); + for (auto val : genericConstraint->mConstraintTypes) + VisitChild(val); + for (auto val : genericConstraint->mCommas) + VisitChild(val); + } + else if (auto genericConstraintExpr = BfNodeDynCast(genericConstraintNode)) + { + VisitChild(genericConstraintExpr->mWhereToken); + VisitChild(genericConstraintExpr->mExpression); + } } } diff --git a/IDEHelper/Compiler/BfReducer.cpp b/IDEHelper/Compiler/BfReducer.cpp index 38da921f..7598cc62 100644 --- a/IDEHelper/Compiler/BfReducer.cpp +++ b/IDEHelper/Compiler/BfReducer.cpp @@ -9945,11 +9945,61 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration( { auto constraintsDeclaration = mAlloc->Alloc(); - BfDeferredAstSizedArray genericConstraintsArr(constraintsDeclaration->mGenericConstraints, mAlloc); + BfDeferredAstSizedArray genericConstraintsArr(constraintsDeclaration->mGenericConstraints, mAlloc); bool isDone = false; for (int constraintIdx = 0; !isDone; constraintIdx++) { +// if (auto nextToken = BfNodeDynCast(mVisitorPos.GetNext())) +// { +// if (nextToken->mToken == BfToken_LParen) +// { +// BfGenericConstraintExpression* genericConstraint = mAlloc->Alloc(); +// 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(mVisitorPos.GetNext())) +// { +// if (checkToken->mToken != BfToken_Where) +// nextWhereToken = checkToken; +// } +// +// auto nextNode = mVisitorPos.GetNext(); +// if (BfNodeDynCast(nextNode)) +// break; +// +// bool handled = false; +// if (auto tokenNode = BfNodeDynCast(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(); BfDeferredAstSizedArray constraintTypes(genericConstraint->mConstraintTypes, mAlloc); BfDeferredAstSizedArray commas(genericConstraint->mCommas, mAlloc); @@ -9957,7 +10007,7 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration( ReplaceNode(tokenNode, genericConstraint); genericConstraint->mWhereToken = tokenNode; - genericConstraintsArr.push_back(genericConstraint); + genericConstraintsArr.push_back(genericConstraint); auto genericParamName = CreateTypeRefAfter(genericConstraint); if (genericParamName != NULL) @@ -9975,7 +10025,6 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration( else isDone = true; - for (int typeIdx = 0; !isDone; typeIdx++) { if (typeIdx > 0) @@ -9987,13 +10036,14 @@ BfGenericConstraintsDeclaration* BfReducer::CreateGenericConstraintsDeclaration( break; } + bool handled = false; if (auto tokenNode = BfNodeDynCast(nextNode)) { if (tokenNode->mToken == BfToken_FatArrow) { isDone = true; break; - } + } } tokenNode = ExpectTokenAfter(genericConstraint, BfToken_Comma, BfToken_LBrace, BfToken_Where, BfToken_Semicolon);