@@ -22,76 +22,52 @@ using namespace SourceKit;
22
22
using namespace sourcekitd ;
23
23
24
24
struct DeclarationsArrayBuilder ::Implementation {
25
- CompactArrayBuilder<UIdent,
26
- unsigned ,
27
- unsigned ,
28
- StringRef> Builder;
25
+ CompactArrayBuilder<UIdent, unsigned , unsigned , StringRef> Builder;
29
26
};
30
27
31
28
DeclarationsArrayBuilder::DeclarationsArrayBuilder ()
32
- : Impl(*new Implementation()) {
29
+ : Impl(*new Implementation()) {}
33
30
34
- }
35
-
36
- DeclarationsArrayBuilder::~DeclarationsArrayBuilder () {
37
- delete &Impl;
38
- }
31
+ DeclarationsArrayBuilder::~DeclarationsArrayBuilder () { delete &Impl; }
39
32
40
- void DeclarationsArrayBuilder::add (
41
- UIdent Kind,
42
- unsigned Offset,
43
- unsigned Length,
44
- StringRef USR) {
33
+ void DeclarationsArrayBuilder::add (UIdent Kind, unsigned Offset,
34
+ unsigned Length, StringRef USR) {
45
35
46
- Impl.Builder .addEntry (Kind,
47
- Offset,
48
- Length,
49
- USR);
36
+ Impl.Builder .addEntry (Kind, Offset, Length, USR);
50
37
}
51
38
52
- bool DeclarationsArrayBuilder::empty () const {
53
- return Impl.Builder .empty ();
54
- }
39
+ bool DeclarationsArrayBuilder::empty () const { return Impl.Builder .empty (); }
55
40
56
- std::unique_ptr<llvm::MemoryBuffer>
57
- DeclarationsArrayBuilder::createBuffer () {
41
+ std::unique_ptr<llvm::MemoryBuffer> DeclarationsArrayBuilder::createBuffer () {
58
42
return Impl.Builder .createBuffer (CustomBufferKind::DeclarationsArray);
59
43
}
60
44
61
45
namespace {
62
46
63
47
class DeclarationsArray {
64
48
public:
65
- typedef CompactArrayReader<sourcekitd_uid_t ,
66
- unsigned ,
67
- unsigned ,
68
- const char *> CompactArrayReaderTy;
69
-
70
- static void readElements (void *Buf, size_t Index,
71
- sourcekitd_uid_t &Kind,
72
- unsigned &Offset,
73
- unsigned &Length,
74
- const char * &USR) {
49
+ typedef CompactArrayReader<sourcekitd_uid_t , unsigned , unsigned , const char *>
50
+ CompactArrayReaderTy;
51
+
52
+ static void readElements (void *Buf, size_t Index, sourcekitd_uid_t &Kind,
53
+ unsigned &Offset, unsigned &Length,
54
+ const char *&USR) {
75
55
CompactArrayReaderTy Reader (Buf);
76
- Reader.readEntries (Index,
77
- Kind,
78
- Offset,
79
- Length,
80
- USR);
56
+ Reader.readEntries (Index, Kind, Offset, Length, USR);
81
57
}
82
58
83
- static bool apply ( sourcekitd_uid_t Kind,
84
- unsigned Offset ,
85
- unsigned Length ,
86
- const char * USR,
87
- llvm::function_ref< bool ( sourcekitd_uid_t ,
88
- sourcekitd_variant_t )> applier) {
89
-
90
- # define APPLY ( K, Ty, Field ) \
91
- do { \
92
- sourcekitd_uid_t key = SKDUIDFromUIdent (K); \
93
- sourcekitd_variant_t var = make##Ty## Variant (Field); \
94
- if (! applier (key, var)) return false ; \
59
+ static bool
60
+ apply ( sourcekitd_uid_t Kind, unsigned Offset, unsigned Length ,
61
+ const char *USR ,
62
+ llvm::function_ref< bool ( sourcekitd_uid_t , sourcekitd_variant_t )>
63
+ applier) {
64
+
65
+ # define APPLY ( K, Ty, Field ) \
66
+ do { \
67
+ sourcekitd_uid_t key = SKDUIDFromUIdent (K); \
68
+ sourcekitd_variant_t var = make##Ty## Variant (Field); \
69
+ if (! applier (key, var)) \
70
+ return false ; \
95
71
} while (0 )
96
72
97
73
APPLY (KeyKind, UID, Kind);
@@ -103,33 +79,26 @@ class DeclarationsArray {
103
79
return true ;
104
80
}
105
81
106
- static int64_t getInt (sourcekitd_uid_t Key,
107
- sourcekitd_uid_t Kind,
108
- unsigned Offset,
109
- unsigned Length,
110
- const char * USR) {
82
+ static int64_t getInt (sourcekitd_uid_t Key, sourcekitd_uid_t Kind,
83
+ unsigned Offset, unsigned Length, const char *USR) {
111
84
if (Key == SKDUIDFromUIdent (KeyOffset))
112
85
return Offset;
113
86
if (Key == SKDUIDFromUIdent (KeyLength))
114
87
return Length;
115
88
return 0 ;
116
89
}
117
90
118
- static sourcekitd_uid_t getUID (sourcekitd_uid_t Key,
119
- sourcekitd_uid_t Kind,
120
- unsigned Offset,
121
- unsigned Length,
122
- const char * USR) {
91
+ static sourcekitd_uid_t getUID (sourcekitd_uid_t Key, sourcekitd_uid_t Kind,
92
+ unsigned Offset, unsigned Length,
93
+ const char *USR) {
123
94
if (Key == SKDUIDFromUIdent (KeyKind))
124
95
return Kind;
125
96
return nullptr ;
126
97
}
127
98
128
- static const char * getString (sourcekitd_uid_t Key,
129
- sourcekitd_uid_t Kind,
130
- unsigned Offset,
131
- unsigned Length,
132
- const char * USR) {
99
+ static const char *getString (sourcekitd_uid_t Key, sourcekitd_uid_t Kind,
100
+ unsigned Offset, unsigned Length,
101
+ const char *USR) {
133
102
if (Key == SKDUIDFromUIdent (KeyUSR))
134
103
return USR;
135
104
return nullptr ;
@@ -148,34 +117,32 @@ struct CompactVariantFuncs<DeclarationsArray> {
148
117
149
118
template <typename FnTy>
150
119
static auto getElement (sourcekitd_variant_t dict, sourcekitd_uid_t key,
151
- const FnTy &Fn) -> decltype(Fn(nullptr , nullptr , 0 , 0 ,
152
- nullptr )) {
153
- void *Buf = (void *)dict.data [1 ];
120
+ const FnTy &Fn) -> decltype(Fn(nullptr , nullptr , 0 , 0 ,
121
+ nullptr )) {
122
+ void *Buf = (void *)dict.data [1 ];
154
123
size_t Index = dict.data [2 ];
155
124
156
125
sourcekitd_uid_t Kind;
157
126
unsigned Offset;
158
127
unsigned Length;
159
- const char * USR;
160
- DeclarationsArray::readElements (Buf, Index,
161
- Kind, Offset, Length, USR);
128
+ const char *USR;
129
+ DeclarationsArray::readElements (Buf, Index, Kind, Offset, Length, USR);
162
130
163
131
return Fn (key, Kind, Offset, Length, USR);
164
132
}
165
-
166
- static bool
167
- dictionary_apply ( sourcekitd_variant_t dict,
168
- llvm::function_ref<bool (sourcekitd_uid_t ,
169
- sourcekitd_variant_t )> applier) {
170
- void *Buf = (void *)dict.data [1 ];
133
+
134
+ static bool dictionary_apply (
135
+ sourcekitd_variant_t dict,
136
+ llvm::function_ref<bool (sourcekitd_uid_t , sourcekitd_variant_t )>
137
+ applier) {
138
+ void *Buf = (void *)dict.data [1 ];
171
139
size_t Index = dict.data [2 ];
172
140
173
141
sourcekitd_uid_t Kind;
174
142
unsigned Offset;
175
143
unsigned Length;
176
- const char * USR;
177
- DeclarationsArray::readElements (Buf, Index,
178
- Kind, Offset, Length, USR);
144
+ const char *USR;
145
+ DeclarationsArray::readElements (Buf, Index, Kind, Offset, Length, USR);
179
146
return DeclarationsArray::apply (Kind, Offset, Length, USR, applier);
180
147
}
181
148
@@ -191,8 +158,8 @@ struct CompactVariantFuncs<DeclarationsArray> {
191
158
return getElement (dict, key, DeclarationsArray::getUID);
192
159
}
193
160
194
- static const char * dictionary_get_string (sourcekitd_variant_t dict,
195
- sourcekitd_uid_t key) {
161
+ static const char * dictionary_get_string (sourcekitd_variant_t dict,
162
+ sourcekitd_uid_t key) {
196
163
197
164
return getElement (dict, key, DeclarationsArray::getString);
198
165
}
@@ -201,32 +168,31 @@ struct CompactVariantFuncs<DeclarationsArray> {
201
168
};
202
169
203
170
VariantFunctions CompactVariantFuncs<DeclarationsArray>::Funcs = {
204
- get_type,
205
- nullptr /* Annot_array_apply*/ ,
206
- nullptr /* Annot_array_get_bool*/ ,
207
- nullptr /* Annot_array_get_count*/ ,
208
- nullptr /* Annot_array_get_int64*/ ,
209
- nullptr /* Annot_array_get_string*/ ,
210
- nullptr /* Annot_array_get_uid*/ ,
211
- nullptr /* Annot_array_get_value*/ ,
212
- nullptr /* Annot_bool_get_value*/ ,
213
- dictionary_apply,
214
- nullptr /* Annot_dictionary_get_bool*/ ,
215
- dictionary_get_int64,
216
- dictionary_get_string,
217
- nullptr /* Annot_dictionary_get_value*/ ,
218
- dictionary_get_uid,
219
- nullptr /* Annot_string_get_length*/ ,
220
- nullptr /* Annot_string_get_ptr*/ ,
221
- nullptr /* Annot_int64_get_value*/ ,
222
- nullptr /* Annot_uid_get_value*/ ,
223
- nullptr /* Annot_data_get_size*/ ,
224
- nullptr /* Annot_data_get_ptr*/ ,
171
+ get_type,
172
+ nullptr /* Annot_array_apply*/ ,
173
+ nullptr /* Annot_array_get_bool*/ ,
174
+ nullptr /* Annot_array_get_count*/ ,
175
+ nullptr /* Annot_array_get_int64*/ ,
176
+ nullptr /* Annot_array_get_string*/ ,
177
+ nullptr /* Annot_array_get_uid*/ ,
178
+ nullptr /* Annot_array_get_value*/ ,
179
+ nullptr /* Annot_bool_get_value*/ ,
180
+ dictionary_apply,
181
+ nullptr /* Annot_dictionary_get_bool*/ ,
182
+ dictionary_get_int64,
183
+ dictionary_get_string,
184
+ nullptr /* Annot_dictionary_get_value*/ ,
185
+ dictionary_get_uid,
186
+ nullptr /* Annot_string_get_length*/ ,
187
+ nullptr /* Annot_string_get_ptr*/ ,
188
+ nullptr /* Annot_int64_get_value*/ ,
189
+ nullptr /* Annot_uid_get_value*/ ,
190
+ nullptr /* Annot_data_get_size*/ ,
191
+ nullptr /* Annot_data_get_ptr*/ ,
225
192
};
226
193
227
194
} // namespace sourcekitd
228
195
229
- VariantFunctions *
230
- sourcekitd::getVariantFunctionsForDeclarationsArray () {
196
+ VariantFunctions *sourcekitd::getVariantFunctionsForDeclarationsArray () {
231
197
return &CompactArrayFuncs<DeclarationsArray>::Funcs;
232
198
}
0 commit comments