37
37
#include " llvm/ADT/SetOperations.h"
38
38
#include " llvm/ADT/SetVector.h"
39
39
#include " llvm/ADT/SmallPtrSet.h"
40
+ #include " llvm/ADT/STLExtras.h"
40
41
#include " llvm/Support/ErrorHandling.h"
41
42
#include " llvm/Support/Timer.h"
42
43
#include " llvm/Support/raw_ostream.h"
@@ -3485,13 +3486,35 @@ class TypeVariableBinding : public TypeBinding {
3485
3486
}
3486
3487
};
3487
3488
3488
- class TypeVarBindingProducer {
3489
+ template <typename Choice>
3490
+ class BindingProducer {
3491
+ ConstraintLocator *Locator;
3492
+
3493
+ protected:
3494
+ ConstraintSystem &CS;
3495
+
3496
+ public:
3497
+ BindingProducer (ConstraintSystem &cs, ConstraintLocator *locator)
3498
+ : Locator(locator), CS(cs) {}
3499
+
3500
+ virtual ~BindingProducer () {}
3501
+ virtual Optional<Choice> operator ()() = 0;
3502
+
3503
+ ConstraintLocator *getLocator () const { return Locator; }
3504
+
3505
+ // / Check whether generator would have to compute next
3506
+ // / batch of bindings because it freshly ran out of current one.
3507
+ // / This is useful to be able to exhaustively attempt bindings
3508
+ // / for type variables found at one level, before proceeding to
3509
+ // / supertypes or literal defaults etc.
3510
+ virtual bool needsToComputeNext () const { return false ; }
3511
+ };
3512
+
3513
+ class TypeVarBindingProducer : public BindingProducer <TypeVariableBinding> {
3489
3514
using BindingKind = ConstraintSystem::AllowedBindingKind;
3490
3515
using Binding = ConstraintSystem::PotentialBinding;
3491
3516
3492
- ConstraintSystem &CS;
3493
3517
TypeVariableType *TypeVar;
3494
-
3495
3518
llvm::SmallVector<Binding, 8 > Bindings;
3496
3519
3497
3520
// The index pointing to the offset in the bindings
@@ -3505,10 +3528,10 @@ class TypeVarBindingProducer {
3505
3528
public:
3506
3529
TypeVarBindingProducer (ConstraintSystem &cs, TypeVariableType *typeVar,
3507
3530
ArrayRef<Binding> initialBindings)
3508
- : CS (cs), TypeVar(typeVar),
3531
+ : BindingProducer (cs, typeVar-> getImpl ().getLocator() ), TypeVar(typeVar),
3509
3532
Bindings(initialBindings.begin(), initialBindings.end()) {}
3510
3533
3511
- Optional<TypeVariableBinding> operator ()() {
3534
+ Optional<TypeVariableBinding> operator ()() override {
3512
3535
// Once we reach the end of the current bindings
3513
3536
// let's try to compute new ones, e.g. supertypes,
3514
3537
// literal defaults, if that fails, we are done.
@@ -3519,12 +3542,7 @@ class TypeVarBindingProducer {
3519
3542
return TypeVariableBinding (currIndex, TypeVar, Bindings[currIndex]);
3520
3543
}
3521
3544
3522
- // / Check whether generator would have to compute next
3523
- // / batch of bindings because it freshly ran out of current one.
3524
- // / This is useful to be able to exhaustively attempt bindings
3525
- // / found at one level, before proceeding to supertypes or
3526
- // / literal defaults etc.
3527
- bool needsToComputeNext () const { return Index >= Bindings.size (); }
3545
+ bool needsToComputeNext () const override { return Index >= Bindings.size (); }
3528
3546
3529
3547
private:
3530
3548
// / Compute next batch of bindings if possible, this could
@@ -3539,20 +3557,20 @@ class TypeVarBindingProducer {
3539
3557
// / Iterator over disjunction choices, makes it
3540
3558
// / easy to work with disjunction and encapsulates
3541
3559
// / some other important information such as locator.
3542
- class DisjunctionChoiceProducer {
3560
+ class DisjunctionChoiceProducer : public BindingProducer <DisjunctionChoice> {
3543
3561
ArrayRef<Constraint *> Choices;
3544
- ConstraintLocator *Locator;
3545
3562
bool IsExplicitConversion;
3546
3563
3547
3564
unsigned Index = 0 ;
3548
3565
3549
3566
public:
3550
- DisjunctionChoiceProducer (ArrayRef<Constraint *> choices,
3567
+ DisjunctionChoiceProducer (ConstraintSystem &cs,
3568
+ ArrayRef<Constraint *> choices,
3551
3569
ConstraintLocator *locator, bool explicitConversion)
3552
- : Choices(choices ), Locator(locator ),
3570
+ : BindingProducer(cs, locator ), Choices(choices ),
3553
3571
IsExplicitConversion (explicitConversion) {}
3554
3572
3555
- Optional<DisjunctionChoice> operator ()() {
3573
+ Optional<DisjunctionChoice> operator ()() override {
3556
3574
unsigned currIndex = Index;
3557
3575
if (currIndex >= Choices.size ())
3558
3576
return None;
@@ -3561,8 +3579,6 @@ class DisjunctionChoiceProducer {
3561
3579
return DisjunctionChoice (currIndex, Choices[currIndex],
3562
3580
IsExplicitConversion);
3563
3581
}
3564
-
3565
- ConstraintLocator *getLocator () const { return Locator; }
3566
3582
};
3567
3583
3568
3584
// / \brief Constraint System "component" represents
0 commit comments