Skip to content

Commit 9d5ee7a

Browse files
committed
[ConstraintLocator] Add a new element - pattern binding element
The new element points to an index of a particular pattern in a pattern binding declaration.
1 parent e4c51ba commit 9d5ee7a

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,19 @@ class LocatorPathElt::ClosureBodyElement final
10581058
}
10591059
};
10601060

1061+
class LocatorPathElt::PatternBindingElement final
1062+
: public StoredIntegerElement<1> {
1063+
public:
1064+
PatternBindingElement(unsigned index)
1065+
: StoredIntegerElement(ConstraintLocator::PatternBindingElement, index) {}
1066+
1067+
unsigned getIndex() const { return getValue(); }
1068+
1069+
static bool classof(const LocatorPathElt *elt) {
1070+
return elt->getKind() == ConstraintLocator::PatternBindingElement;
1071+
}
1072+
};
1073+
10611074
namespace details {
10621075
template <typename CustomPathElement>
10631076
class PathElement {

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ SIMPLE_LOCATOR_PATH_ELT(ImplicitDynamicMemberSubscript)
232232
/// The element of the closure body e.g. statement, declaration, or expression.
233233
CUSTOM_LOCATOR_PATH_ELT(ClosureBodyElement)
234234

235+
/// The element of the pattern binding declaration.
236+
CUSTOM_LOCATOR_PATH_ELT(PatternBindingElement)
237+
235238
#undef LOCATOR_PATH_ELT
236239
#undef CUSTOM_LOCATOR_PATH_ELT
237240
#undef SIMPLE_LOCATOR_PATH_ELT

lib/Sema/ConstraintLocator.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
9696
case ConstraintLocator::ClosureBodyElement:
9797
case ConstraintLocator::PackType:
9898
case ConstraintLocator::PackElement:
99+
case ConstraintLocator::PatternBindingElement:
99100
return 0;
100101

101102
case ConstraintLocator::FunctionArgument:
@@ -578,6 +579,14 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
578579
out << "pack element #" << llvm::utostr(packElt.getIndex());
579580
break;
580581
}
582+
583+
case PatternBindingElement: {
584+
auto patternBindingElt =
585+
elt.castTo<LocatorPathElt::PatternBindingElement>();
586+
out << "pattern binding element #"
587+
<< llvm::utostr(patternBindingElt.getIndex());
588+
break;
589+
}
581590
}
582591
}
583592
out << ']';

0 commit comments

Comments
 (0)