24
24
#include " llvm/ADT/ArrayRef.h"
25
25
#include " llvm/ADT/SmallVector.h"
26
26
#include " llvm/Support/TrailingObjects.h"
27
+ #include < string>
27
28
28
29
namespace llvm {
29
30
class raw_ostream ;
30
31
}
31
32
32
33
namespace swift {
34
+
35
+ class SourceManager ;
36
+
33
37
namespace constraints {
34
38
35
39
class ConstraintSystem ;
@@ -78,12 +82,16 @@ class ConstraintFix {
78
82
79
83
FixKind getKind () const { return Kind; }
80
84
85
+ virtual std::string getName () const = 0;
86
+
81
87
// / Diagnose a failure associated with this fix given
82
88
// / root expression and information from well-formed solution.
83
89
virtual bool diagnose (Expr *root, const Solution &solution) const = 0;
84
- virtual void print (llvm::raw_ostream &Out) const = 0;
85
90
86
- LLVM_ATTRIBUTE_DEPRECATED (void dump () const LLVM_ATTRIBUTE_USED,
91
+ void print (llvm::raw_ostream &Out, SourceManager *sm) const ;
92
+
93
+ LLVM_ATTRIBUTE_DEPRECATED (void dump (SourceManager *sm)
94
+ const LLVM_ATTRIBUTE_USED,
87
95
"only for use within the debugger");
88
96
89
97
// / Retrieve anchor expression associated with this fix.
@@ -101,8 +109,8 @@ class ForceDowncast final : public ConstraintFix {
101
109
: ConstraintFix(FixKind::ForceDowncast, locator), DowncastTo(toType) {}
102
110
103
111
public:
112
+ std::string getName () const override ;
104
113
bool diagnose (Expr *root, const Solution &solution) const override ;
105
- void print (llvm::raw_ostream &Out) const override ;
106
114
107
115
static ForceDowncast *create (ConstraintSystem &cs, Type toType,
108
116
ConstraintLocator *locator);
@@ -114,10 +122,9 @@ class ForceOptional final : public ConstraintFix {
114
122
: ConstraintFix(FixKind::ForceOptional, locator) {}
115
123
116
124
public:
125
+ std::string getName () const override { return " force optional" ; }
126
+
117
127
bool diagnose (Expr *root, const Solution &solution) const override ;
118
- void print (llvm::raw_ostream &Out) const override {
119
- Out << " [fix: force optional]" ;
120
- }
121
128
122
129
static ForceOptional *create (ConstraintSystem &cs,
123
130
ConstraintLocator *locator);
@@ -134,11 +141,12 @@ class UnwrapOptionalBase final : public ConstraintFix {
134
141
}
135
142
136
143
public:
137
- bool diagnose (Expr *root, const Solution &solution) const override ;
138
- void print (llvm::raw_ostream &Out) const override {
139
- Out << " [fix: unwrap optional base of member lookup]" ;
144
+ std::string getName () const override {
145
+ return " unwrap optional base of member lookup" ;
140
146
}
141
147
148
+ bool diagnose (Expr *root, const Solution &solution) const override ;
149
+
142
150
static UnwrapOptionalBase *create (ConstraintSystem &cs, DeclName member,
143
151
ConstraintLocator *locator);
144
152
@@ -153,10 +161,9 @@ class AddAddressOf final : public ConstraintFix {
153
161
: ConstraintFix(FixKind::AddressOf, locator) {}
154
162
155
163
public:
164
+ std::string getName () const override { return " add address-of" ; }
165
+
156
166
bool diagnose (Expr *root, const Solution &solution) const override ;
157
- void print (llvm::raw_ostream &Out) const override {
158
- Out << " [fix: add address-of]" ;
159
- }
160
167
161
168
static AddAddressOf *create (ConstraintSystem &cs, ConstraintLocator *locator);
162
169
};
@@ -167,10 +174,9 @@ class CoerceToCheckedCast final : public ConstraintFix {
167
174
: ConstraintFix(FixKind::CoerceToCheckedCast, locator) {}
168
175
169
176
public:
177
+ std::string getName () const override { return " as to as!" ; }
178
+
170
179
bool diagnose (Expr *root, const Solution &solution) const override ;
171
- void print (llvm::raw_ostream &Out) const override {
172
- Out << " [fix: as to as!]" ;
173
- }
174
180
175
181
static CoerceToCheckedCast *create (ConstraintSystem &cs,
176
182
ConstraintLocator *locator);
@@ -187,10 +193,9 @@ class MarkExplicitlyEscaping final : public ConstraintFix {
187
193
ConvertTo (convertingTo) {}
188
194
189
195
public:
196
+ std::string getName () const override { return " add @escaping" ; }
197
+
190
198
bool diagnose (Expr *root, const Solution &solution) const override ;
191
- void print (llvm::raw_ostream &Out) const override {
192
- Out << " [fix: add @escaping]" ;
193
- }
194
199
195
200
static MarkExplicitlyEscaping *create (ConstraintSystem &cs,
196
201
ConstraintLocator *locator,
@@ -215,14 +220,13 @@ class RelabelArguments final
215
220
}
216
221
217
222
public:
223
+ std::string getName () const override { return " re-label argument(s)" ; }
224
+
218
225
ArrayRef<Identifier> getLabels () const {
219
226
return {getTrailingObjects<Identifier>(), NumLabels};
220
227
}
221
228
222
229
bool diagnose (Expr *root, const Solution &solution) const override ;
223
- void print (llvm::raw_ostream &Out) const override {
224
- Out << " [fix: re-label argument(s)]" ;
225
- }
226
230
227
231
static RelabelArguments *create (ConstraintSystem &cs,
228
232
llvm::ArrayRef<Identifier> correctLabels,
@@ -245,11 +249,12 @@ class MissingConformance final : public ConstraintFix {
245
249
NonConformingType (type), Protocol(protocol) {}
246
250
247
251
public:
248
- bool diagnose (Expr *root, const Solution &solution) const override ;
249
- void print (llvm::raw_ostream &Out) const override {
250
- Out << " [fix: add missing protocol conformance]" ;
252
+ std::string getName () const override {
253
+ return " add missing protocol conformance" ;
251
254
}
252
255
256
+ bool diagnose (Expr *root, const Solution &solution) const override ;
257
+
253
258
static MissingConformance *create (ConstraintSystem &cs, Type type,
254
259
ProtocolDecl *protocol,
255
260
ConstraintLocator *locator);
0 commit comments