14
14
#define SWIFT_IDE_APIDIGESTERDATA_H
15
15
16
16
#include " swift/Basic/LLVM.h"
17
+ #include " llvm/ADT/ArrayRef.h"
17
18
#include " llvm/ADT/StringRef.h"
19
+ #include " llvm/ADT/StringSwitch.h"
18
20
#include " llvm/Support/raw_ostream.h"
19
21
20
22
namespace swift {
@@ -27,26 +29,42 @@ enum class SDKNodeKind: uint8_t {
27
29
#include " DigesterEnums.def"
28
30
};
29
31
32
+ SDKNodeKind parseSDKNodeKind (StringRef Content);
33
+
30
34
enum class NodeAnnotation : uint8_t {
31
35
#define NODE_ANNOTATION (NAME ) NAME,
32
36
#include " DigesterEnums.def"
33
37
};
34
38
39
+ NodeAnnotation parseSDKNodeAnnotation (StringRef Content);
40
+
41
+ enum class APIDiffItemKind : uint8_t {
42
+ #define DIFF_ITEM_KIND (NAME ) ADK_##NAME,
43
+ #include " DigesterEnums.def"
44
+ };
45
+
35
46
// Redefine << so that we can output the name of the annotation kind.
36
47
raw_ostream &operator <<(raw_ostream &Out, const NodeAnnotation Value);
37
48
38
49
// Redefine << so that we can output the name of the node kind.
39
50
raw_ostream &operator <<(raw_ostream &Out, const SDKNodeKind Value);
40
51
41
- // DiffItem describes how an element in SDK evolves in a way that migrator can
42
- // read conveniently. Each DiffItem corresponds to one JSON element and contains
52
+ struct APIDiffItem {
53
+ virtual void streamDef (llvm::raw_ostream &S) const = 0;
54
+ virtual APIDiffItemKind getKind () const = 0;
55
+ virtual StringRef getKey () const = 0;
56
+ virtual ~APIDiffItem () = default ;
57
+ };
58
+
59
+ // CommonDiffItem describes how an element in SDK evolves in a way that migrator can
60
+ // read conveniently. Each CommonDiffItem corresponds to one JSON element and contains
43
61
// sub fields explaining how migrator can assist client code to cope with such
44
62
// SDK change. For instance, the following first JSON element describes an unwrap
45
63
// optional change in the first parameter of function "c:@F@CTTextTabGetOptions".
46
64
// Similarly, the second JSON element describes a type parameter down cast in the
47
65
// second parameter of function "c:objc(cs)NSXMLDocument(im)insertChildren:atIndex:".
48
66
// We keep both usrs because in the future this may support auto-rename.
49
- struct DiffItem {
67
+ struct CommonDiffItem : public APIDiffItem {
50
68
SDKNodeKind NodeKind;
51
69
NodeAnnotation DiffKind;
52
70
StringRef ChildIndex;
@@ -56,15 +74,21 @@ struct DiffItem {
56
74
StringRef RightComment;
57
75
StringRef ModuleName;
58
76
59
- DiffItem (SDKNodeKind NodeKind, NodeAnnotation DiffKind, StringRef ChildIndex,
60
- StringRef LeftUsr, StringRef RightUsr, StringRef LeftComment,
61
- StringRef RightComment, StringRef ModuleName);
77
+ CommonDiffItem (SDKNodeKind NodeKind, NodeAnnotation DiffKind,
78
+ StringRef ChildIndex, StringRef LeftUsr, StringRef RightUsr,
79
+ StringRef LeftComment, StringRef RightComment,
80
+ StringRef ModuleName);
62
81
63
82
static StringRef head ();
64
- bool operator <(DiffItem Other) const ;
83
+ bool operator <(CommonDiffItem Other) const ;
84
+ static bool classof (const APIDiffItem *D);
65
85
static void describe (llvm::raw_ostream &os);
66
86
static void undef (llvm::raw_ostream &os);
67
- void streamDef (llvm::raw_ostream &S) const ;
87
+ void streamDef (llvm::raw_ostream &S) const override ;
88
+ StringRef getKey () const override { return LeftUsr; }
89
+ APIDiffItemKind getKind () const override {
90
+ return APIDiffItemKind::ADK_CommonDiffItem;
91
+ }
68
92
};
69
93
70
94
@@ -149,46 +173,95 @@ struct DiffItem {
149
173
// myColor.components
150
174
//
151
175
//
152
- struct TypeMemberDiffItem {
176
+ struct TypeMemberDiffItem : public APIDiffItem {
153
177
StringRef usr;
154
178
StringRef newTypeName;
155
179
StringRef newPrintedName;
156
180
Optional<uint8_t > selfIndex;
157
181
StringRef oldPrintedName;
158
182
183
+ TypeMemberDiffItem (StringRef usr, StringRef newTypeName,
184
+ StringRef newPrintedName, Optional<uint8_t > selfIndex,
185
+ StringRef oldPrintedName) : usr(usr),
186
+ newTypeName (newTypeName), newPrintedName(newPrintedName),
187
+ selfIndex(selfIndex), oldPrintedName(oldPrintedName) {}
159
188
static StringRef head ();
160
189
static void describe (llvm::raw_ostream &os);
161
190
static void undef (llvm::raw_ostream &os);
162
- void streamDef (llvm::raw_ostream &os) const ;
191
+ void streamDef (llvm::raw_ostream &os) const override ;
163
192
bool operator <(TypeMemberDiffItem Other) const ;
193
+ static bool classof (const APIDiffItem *D);
194
+ StringRef getKey () const override { return usr; }
195
+ APIDiffItemKind getKind () const override {
196
+ return APIDiffItemKind::ADK_TypeMemberDiffItem;
197
+ }
164
198
};
165
199
166
- struct NoEscapeFuncParam {
200
+ struct NoEscapeFuncParam : public APIDiffItem {
167
201
StringRef Usr;
168
202
unsigned Index;
169
203
170
204
NoEscapeFuncParam (StringRef Usr, unsigned Index) : Usr(Usr), Index(Index) {}
171
205
static StringRef head ();
172
206
static void describe (llvm::raw_ostream &os);
173
207
static void undef (llvm::raw_ostream &os);
174
- void streamDef (llvm::raw_ostream &os) const ;
208
+ void streamDef (llvm::raw_ostream &os) const override ;
175
209
bool operator <(NoEscapeFuncParam Other) const ;
210
+ static bool classof (const APIDiffItem *D);
211
+ StringRef getKey () const override { return Usr; }
212
+ APIDiffItemKind getKind () const override {
213
+ return APIDiffItemKind::ADK_NoEscapeFuncParam;
214
+ }
176
215
};
177
216
178
217
// / This info is about functions meet the following criteria:
179
218
// / - This function is a member function of a type.
180
219
// / - This function is overloaded.
181
- struct OverloadedFuncInfo {
220
+ struct OverloadedFuncInfo : public APIDiffItem {
182
221
StringRef Usr;
183
222
184
223
OverloadedFuncInfo (StringRef Usr) : Usr(Usr) {}
185
224
static StringRef head ();
186
225
static void describe (llvm::raw_ostream &os);
187
226
static void undef (llvm::raw_ostream &os);
188
- void streamDef (llvm::raw_ostream &os) const ;
227
+ void streamDef (llvm::raw_ostream &os) const override ;
189
228
bool operator <(OverloadedFuncInfo Other) const ;
229
+ static bool classof (const APIDiffItem *D);
230
+ StringRef getKey () const override { return Usr; }
231
+ APIDiffItemKind getKind () const override {
232
+ return APIDiffItemKind::ADK_OverloadedFuncInfo;
233
+ }
234
+ };
235
+
236
+ // / APIDiffItem store is the interface that migrator should communicates with;
237
+ // / Given a key, usually the usr of the system entity under migration, the store
238
+ // / should return a slice of related changes in the same format of
239
+ // / swift-api-digester. This struct also handles the serialization and
240
+ // / deserialization of all kinds of API diff items declared above.
241
+ struct APIDiffItemStore {
242
+ struct Implementation ;
243
+ Implementation &Impl;
244
+ static void serialize (llvm::raw_ostream &os, ArrayRef<APIDiffItem*> Items);
245
+ APIDiffItemStore ();
246
+ ~APIDiffItemStore ();
247
+ ArrayRef<APIDiffItem*> getDiffItems (StringRef Key) const ;
248
+ ArrayRef<APIDiffItem*> getAllDiffItems () const ;
249
+
250
+ // / Add a path of a JSON file dumped from swift-api-digester that contains
251
+ // / API changes we care about. Calling this can be heavy since the procedure
252
+ // / will parse and index the data inside of the given file.
253
+ void addStorePath (StringRef Path);
190
254
};
191
255
}
192
256
}
257
+ namespace json {
258
+ template <>
259
+ struct ScalarEnumerationTraits <ide::api::SDKNodeKind> {
260
+ static void enumeration (Output &out, ide::api::SDKNodeKind &value) {
261
+ #define NODE_KIND (X ) out.enumCase(value, #X, ide::api::SDKNodeKind::X);
262
+ #include " swift/IDE/DigesterEnums.def"
263
+ }
264
+ };
265
+ }
193
266
}
194
267
#endif // SWIFT_IDE_APIDIGESTERDATA_H
0 commit comments