20
20
21
21
#include " swift/Basic/Debug.h"
22
22
#include " swift/Basic/LLVM.h"
23
+ #include " swift/AST/ASTNode.h"
23
24
#include " swift/AST/Type.h"
24
25
#include " swift/AST/Types.h"
25
26
#include " llvm/ADT/ArrayRef.h"
@@ -43,10 +44,6 @@ namespace constraints {
43
44
44
45
class ConstraintSystem ;
45
46
46
- // / An AST node that can gain type information while solving.
47
- using TypedNode = llvm::PointerUnion<const Expr *, const TypeLoc *,
48
- const VarDecl *, const Pattern *>;
49
-
50
47
// / Locates a given constraint within the expression being
51
48
// / type-checked, which may refer down into subexpressions and parts of
52
49
// / the types of those subexpressions.
@@ -310,7 +307,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
310
307
}
311
308
312
309
// / Retrieve the expression that anchors this locator.
313
- TypedNode getAnchor () const { return anchor; }
310
+ ASTNode getAnchor () const { return anchor; }
314
311
315
312
// / Retrieve the path that extends from the anchor to a specific
316
313
// / subcomponent.
@@ -384,12 +381,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
384
381
bool isForOptionalTry () const ;
385
382
386
383
// / Determine whether this locator points directly to a given expression.
387
- template <class E > bool directlyAt () const {
388
- if (auto *anchor = getAnchor ().dyn_cast <const Expr *>()) {
389
- return isa<E>(anchor) && getPath ().empty ();
390
- }
391
- return false ;
392
- }
384
+ template <typename E> bool directlyAt () const ;
393
385
394
386
// / Attempts to cast the first path element of the locator to a specific
395
387
// / \c LocatorPathElt subclass, returning \c None if either unsuccessful or
@@ -502,7 +494,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
502
494
GenericTypeParamType *getGenericParameter () const ;
503
495
504
496
// / Produce a profile of this locator, for use in a folding set.
505
- static void Profile (llvm::FoldingSetNodeID &id, TypedNode anchor,
497
+ static void Profile (llvm::FoldingSetNodeID &id, ASTNode anchor,
506
498
ArrayRef<PathElement> path);
507
499
508
500
// / Produce a profile of this locator, for use in a folding set.
@@ -518,8 +510,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
518
510
519
511
private:
520
512
// / Initialize a constraint locator with an anchor and a path.
521
- ConstraintLocator (TypedNode anchor, ArrayRef<PathElement> path,
522
- unsigned flags)
513
+ ConstraintLocator (ASTNode anchor, ArrayRef<PathElement> path, unsigned flags)
523
514
: anchor(anchor), numPathElements(path.size()), summaryFlags(flags) {
524
515
// FIXME: Alignment.
525
516
std::copy (path.begin (), path.end (),
@@ -533,7 +524,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
533
524
// / of the locator. The ConstraintSystem object is responsible for
534
525
// / uniquing via the FoldingSet.
535
526
static ConstraintLocator *create (llvm::BumpPtrAllocator &allocator,
536
- TypedNode anchor, ArrayRef<PathElement> path,
527
+ ASTNode anchor, ArrayRef<PathElement> path,
537
528
unsigned flags) {
538
529
// FIXME: Alignment.
539
530
unsigned size = sizeof (ConstraintLocator)
@@ -543,7 +534,7 @@ class ConstraintLocator : public llvm::FoldingSetNode {
543
534
}
544
535
545
536
// / The expression at which this locator is anchored.
546
- TypedNode anchor;
537
+ ASTNode anchor;
547
538
548
539
// / The number of path elements in this locator.
549
540
// /
@@ -942,7 +933,7 @@ class ConstraintLocatorBuilder {
942
933
}
943
934
944
935
// / Get anchor expression associated with this locator builder.
945
- TypedNode getAnchor () const {
936
+ ASTNode getAnchor () const {
946
937
for (auto prev = this ; prev;
947
938
prev = prev->previous .dyn_cast <ConstraintLocatorBuilder *>()) {
948
939
if (auto *locator = prev->previous .dyn_cast <ConstraintLocator *>())
@@ -954,7 +945,7 @@ class ConstraintLocatorBuilder {
954
945
955
946
// / Retrieve the components of the complete locator, which includes
956
947
// / the anchor expression and the path.
957
- TypedNode getLocatorParts (SmallVectorImpl<LocatorPathElt> &path) const {
948
+ ASTNode getLocatorParts (SmallVectorImpl<LocatorPathElt> &path) const {
958
949
for (auto prev = this ;
959
950
prev;
960
951
prev = prev->previous .dyn_cast <ConstraintLocatorBuilder *>()) {
0 commit comments