@@ -318,10 +318,13 @@ class alignas(1 << DeclAlignInBits) Decl {
318318 Hoisted : 1
319319 );
320320
321- SWIFT_INLINE_BITFIELD_FULL (PatternBindingDecl, Decl, 1 +2 +16 ,
321+ SWIFT_INLINE_BITFIELD_FULL (PatternBindingDecl, Decl, 1 +1 + 2 +16 ,
322322 // / Whether this pattern binding declares static variables.
323323 IsStatic : 1 ,
324324
325+ // / Whether this pattern binding is synthesized by the debugger.
326+ IsDebugger : 1 ,
327+
325328 // / Whether 'static' or 'class' was used.
326329 StaticSpelling : 2 ,
327330
@@ -1471,9 +1474,10 @@ class PatternBindingEntry {
14711474 enum class PatternFlags {
14721475 IsText = 1 << 0 ,
14731476 IsFullyValidated = 1 << 1 ,
1477+ IsFromDebugger = 1 << 2 ,
14741478 };
14751479 // / The initializer context used for this pattern binding entry.
1476- llvm::PointerIntPair<DeclContext *, 2 , OptionSet<PatternFlags>>
1480+ llvm::PointerIntPair<DeclContext *, 3 , OptionSet<PatternFlags>>
14771481 InitContextAndFlags;
14781482
14791483 // / Values captured by this initializer.
@@ -1501,6 +1505,14 @@ class PatternBindingEntry {
15011505 PatternFlags::IsFullyValidated);
15021506 }
15031507
1508+ // / Set if this pattern binding came from the debugger.
1509+ // /
1510+ // / Stay away unless you are \c PatternBindingDecl::createForDebugger
1511+ void setFromDebugger () {
1512+ InitContextAndFlags.setInt (InitContextAndFlags.getInt () |
1513+ PatternFlags::IsFromDebugger);
1514+ }
1515+
15041516public:
15051517 // / \p E is the initializer as parsed.
15061518 PatternBindingEntry (Pattern *P, SourceLoc EqualLoc, Expr *E,
@@ -1583,6 +1595,11 @@ class PatternBindingEntry {
15831595 PatternAndFlags.setInt (PatternAndFlags.getInt () | Flags::Subsumed);
15841596 }
15851597
1598+ // / Returns \c true if the debugger created this pattern binding entry.
1599+ bool isFromDebugger () const {
1600+ return InitContextAndFlags.getInt ().contains (PatternFlags::IsFromDebugger);
1601+ }
1602+
15861603 // Return the first variable initialized by this pattern.
15871604 VarDecl *getAnchoringVarDecl () const ;
15881605
@@ -1668,6 +1685,13 @@ class PatternBindingDecl final : public Decl,
16681685 unsigned NumPatternEntries,
16691686 DeclContext *Parent);
16701687
1688+ // A dedicated entrypoint that allows LLDB to create pattern bindings
1689+ // that look implicit to the compiler but contain user code.
1690+ static PatternBindingDecl *createForDebugger (ASTContext &Ctx,
1691+ StaticSpellingKind Spelling,
1692+ Pattern *Pat, Expr *E,
1693+ DeclContext *Parent);
1694+
16711695 SourceLoc getStartLoc () const {
16721696 return StaticLoc.isValid () ? StaticLoc : VarLoc;
16731697 }
@@ -1869,6 +1893,9 @@ class PatternBindingDecl final : public Decl,
18691893 return getPatternList ()[i].getInitStringRepresentation (scratch);
18701894 }
18711895
1896+ // / Returns \c true if this pattern binding was created by the debugger.
1897+ bool isDebuggerBinding () const { return Bits.PatternBindingDecl .IsDebugger ; }
1898+
18721899 static bool classof (const Decl *D) {
18731900 return D->getKind () == DeclKind::PatternBinding;
18741901 }
0 commit comments