Skip to content

Commit 107780c

Browse files
authored
Merge pull request #37720 from hamishknight/all-the-patter
2 parents b3518aa + 2dac5b2 commit 107780c

File tree

8 files changed

+947
-88
lines changed

8 files changed

+947
-88
lines changed

include/swift/AST/DiagnosticsRefactoring.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,7 @@ ERROR(callback_multiple_case_items, none, "cannot refactor switch using a case w
7070

7171
ERROR(callback_where_case_item, none, "cannot refactor switch using a case with where clause", ())
7272

73+
ERROR(unknown_callback_case_item, none, "cannot refactor complex case conditions", ())
74+
7375
#define UNDEFINE_DIAGNOSTIC_MACROS
7476
#include "DefineDiagnosticMacros.h"

include/swift/AST/Pattern.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ class alignas(8) Pattern {
202202
/// Does this binding declare something that requires storage?
203203
bool hasStorage() const;
204204

205+
/// Does this pattern have any mutable 'var' bindings?
206+
bool hasAnyMutableBindings() const;
207+
205208
static bool classof(const Pattern *P) { return true; }
206209

207210
//*** Allocation Routines ************************************************/

include/swift/IDE/SourceEntityWalker.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class SourceEntityWalker {
7373
/// Walks the provided Expr.
7474
/// \returns true if traversal was aborted, false otherwise.
7575
bool walk(Expr *E);
76+
/// Walks the provided Pattern.
77+
/// \returns true if traversal was aborted, false otherwise.
78+
bool walk(Pattern *P);
7679
/// Walks the provided ASTNode.
7780
/// \returns true if traversal was aborted, false otherwise.
7881
bool walk(ASTNode N);
@@ -101,6 +104,14 @@ class SourceEntityWalker {
101104
/// returns false, the remaining traversal is terminated and returns failure.
102105
virtual bool walkToExprPost(Expr *E) { return true; }
103106

107+
/// This method is called when first visiting a pattern, before walking
108+
/// into its children. If it returns false, the subtree is skipped.
109+
virtual bool walkToPatternPre(Pattern *P) { return true; }
110+
111+
/// This method is called after visiting the children of a pattern. If it
112+
/// returns false, the remaining traversal is terminated and returns failure.
113+
virtual bool walkToPatternPost(Pattern *P) { return true; }
114+
104115
/// This method is called when a ValueDecl is referenced in source. If it
105116
/// returns false, the remaining traversal is terminated and returns failure.
106117
///

lib/AST/Pattern.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ bool Pattern::hasStorage() const {
291291
return HasStorage;
292292
}
293293

294+
bool Pattern::hasAnyMutableBindings() const {
295+
auto HasMutable = false;
296+
forEachVariable([&](VarDecl *VD) {
297+
if (!VD->isLet())
298+
HasMutable = true;
299+
});
300+
return HasMutable;
301+
}
302+
294303
/// Return true if this is a non-resolved ExprPattern which is syntactically
295304
/// irrefutable.
296305
static bool isIrrefutableExprPattern(const ExprPattern *EP) {

0 commit comments

Comments
 (0)