@@ -192,7 +192,7 @@ namespace llvm {
192
192
class PointerLikeTypeTraits <swift::Identifier> {
193
193
public:
194
194
static inline void *getAsVoidPointer (swift::Identifier I) {
195
- return ( void *)I. get ( );
195
+ return const_cast < void *>(I. getAsOpaquePointer () );
196
196
}
197
197
static inline swift::Identifier getFromVoidPointer (void *P) {
198
198
return swift::Identifier::getFromOpaquePointer (P);
@@ -203,7 +203,54 @@ namespace llvm {
203
203
} // end namespace llvm
204
204
205
205
namespace swift {
206
-
206
+
207
+ // / Wrapper that may either be an Identifier or a special name
208
+ // / (e.g. for subscripts)
209
+ class DeclBaseName {
210
+ Identifier Ident;
211
+
212
+ public:
213
+ DeclBaseName (Identifier I) : Ident(I) {}
214
+
215
+ bool isSpecial () const { return false ; }
216
+
217
+ // / Return the identifier backing the name. Assumes that the name is not
218
+ // / special.
219
+ Identifier getIdentifier () const {
220
+ assert (!isSpecial () && " Cannot retrieve identifier from special names" );
221
+ return Ident;
222
+ }
223
+
224
+ bool empty () const { return !isSpecial () && getIdentifier ().empty (); }
225
+
226
+ const void *getAsOpaquePointer () const { return Ident.get (); }
227
+
228
+ static DeclBaseName getFromOpaquePointer (void *P) {
229
+ return Identifier::getFromOpaquePointer (P);
230
+ }
231
+ };
232
+
233
+ } // end namespace swift
234
+
235
+ namespace llvm {
236
+
237
+ // A DeclBaseName is "pointer like".
238
+ template <typename T> class PointerLikeTypeTraits ;
239
+ template <> class PointerLikeTypeTraits <swift::DeclBaseName> {
240
+ public:
241
+ static inline void *getAsVoidPointer (swift::DeclBaseName D) {
242
+ return const_cast <void *>(D.getAsOpaquePointer ());
243
+ }
244
+ static inline swift::DeclBaseName getFromVoidPointer (void *P) {
245
+ return swift::DeclBaseName::getFromOpaquePointer (P);
246
+ }
247
+ enum { NumLowBitsAvailable = PointerLikeTypeTraits<swift::Identifier>::NumLowBitsAvailable };
248
+ };
249
+
250
+ } // end namespace llvm
251
+
252
+ namespace swift {
253
+
207
254
// / A declaration name, which may comprise one or more identifier pieces.
208
255
class DeclName {
209
256
friend class ASTContext ;
@@ -214,12 +261,11 @@ class DeclName {
214
261
friend TrailingObjects;
215
262
friend class DeclName ;
216
263
217
- Identifier BaseName;
264
+ DeclBaseName BaseName;
218
265
size_t NumArgs;
219
-
220
- explicit CompoundDeclName (Identifier BaseName, size_t NumArgs)
221
- : BaseName (BaseName), NumArgs (NumArgs)
222
- {
266
+
267
+ explicit CompoundDeclName (DeclBaseName BaseName, size_t NumArgs)
268
+ : BaseName (BaseName), NumArgs (NumArgs) {
223
269
assert (NumArgs > 0 && " Should use IdentifierAndCompound" );
224
270
}
225
271
@@ -231,56 +277,61 @@ class DeclName {
231
277
}
232
278
233
279
// / Uniquing for the ASTContext.
234
- static void Profile (llvm::FoldingSetNodeID &id,
235
- Identifier baseName,
280
+ static void Profile (llvm::FoldingSetNodeID &id, DeclBaseName baseName,
236
281
ArrayRef<Identifier> argumentNames);
237
-
282
+
238
283
void Profile (llvm::FoldingSetNodeID &id) {
239
284
Profile (id, BaseName, getArgumentNames ());
240
285
}
241
286
};
242
287
243
288
// A single stored identifier, along with a bit stating whether it is the
244
289
// base name for a zero-argument compound name.
245
- typedef llvm::PointerIntPair<Identifier , 1 , bool > IdentifierAndCompound ;
290
+ typedef llvm::PointerIntPair<DeclBaseName , 1 , bool > BaseNameAndCompound ;
246
291
247
292
// Either a single identifier piece stored inline (with a bit to say whether
248
293
// it is simple or compound), or a reference to a compound declaration name.
249
- llvm::PointerUnion<IdentifierAndCompound , CompoundDeclName*> SimpleOrCompound;
250
-
294
+ llvm::PointerUnion<BaseNameAndCompound , CompoundDeclName *> SimpleOrCompound;
295
+
251
296
DeclName (void *Opaque)
252
297
: SimpleOrCompound(decltype (SimpleOrCompound)::getFromOpaqueValue(Opaque))
253
298
{}
254
299
255
- void initialize (ASTContext &C, Identifier baseName,
300
+ void initialize (ASTContext &C, DeclBaseName baseName,
256
301
ArrayRef<Identifier> argumentNames);
257
-
302
+
258
303
public:
259
304
// / Build a null name.
260
- DeclName () : SimpleOrCompound(IdentifierAndCompound ()) {}
261
-
305
+ DeclName () : SimpleOrCompound(BaseNameAndCompound ()) {}
306
+
262
307
// / Build a simple value name with one component.
308
+ /* implicit*/ DeclName(DeclBaseName simpleName)
309
+ : SimpleOrCompound(BaseNameAndCompound(simpleName, false )) {}
310
+
263
311
/* implicit*/ DeclName(Identifier simpleName)
264
- : SimpleOrCompound(IdentifierAndCompound (simpleName, false )) {}
265
-
312
+ : DeclName(DeclBaseName (simpleName)) {}
313
+
266
314
// / Build a compound value name given a base name and a set of argument names.
267
- DeclName (ASTContext &C, Identifier baseName,
315
+ DeclName (ASTContext &C, DeclBaseName baseName,
268
316
ArrayRef<Identifier> argumentNames) {
269
317
initialize (C, baseName, argumentNames);
270
318
}
271
319
272
320
// / Build a compound value name given a base name and a set of argument names
273
321
// / extracted from a parameter list.
274
- DeclName (ASTContext &C, Identifier baseName, ParameterList *paramList);
275
-
322
+ DeclName (ASTContext &C, DeclBaseName baseName, ParameterList *paramList);
323
+
276
324
// / Retrieve the 'base' name, i.e., the name that follows the introducer,
277
325
// / such as the 'foo' in 'func foo(x:Int, y:Int)' or the 'bar' in
278
326
// / 'var bar: Int'.
327
+ // TODO: Return DeclBaseName (remove two calls to getIdentifier)
279
328
Identifier getBaseName () const {
280
329
if (auto compound = SimpleOrCompound.dyn_cast <CompoundDeclName*>())
281
- return compound->BaseName ;
282
-
283
- return SimpleOrCompound.get <IdentifierAndCompound>().getPointer ();
330
+ return compound->BaseName .getIdentifier ();
331
+
332
+ return SimpleOrCompound.get <BaseNameAndCompound>()
333
+ .getPointer ()
334
+ .getIdentifier ();
284
335
}
285
336
286
337
// / Retrieve the names of the arguments, if there are any.
@@ -294,23 +345,23 @@ class DeclName {
294
345
explicit operator bool () const {
295
346
if (SimpleOrCompound.dyn_cast <CompoundDeclName*>())
296
347
return true ;
297
- return !SimpleOrCompound.get <IdentifierAndCompound >().getPointer ().empty ();
348
+ return !SimpleOrCompound.get <BaseNameAndCompound >().getPointer ().empty ();
298
349
}
299
350
300
351
// / True if this is a simple one-component name.
301
352
bool isSimpleName () const {
302
353
if (SimpleOrCompound.dyn_cast <CompoundDeclName*>())
303
354
return false ;
304
355
305
- return !SimpleOrCompound.get <IdentifierAndCompound >().getInt ();
356
+ return !SimpleOrCompound.get <BaseNameAndCompound >().getInt ();
306
357
}
307
358
308
359
// / True if this is a compound name.
309
360
bool isCompoundName () const {
310
361
if (SimpleOrCompound.dyn_cast <CompoundDeclName*>())
311
362
return true ;
312
363
313
- return SimpleOrCompound.get <IdentifierAndCompound >().getInt ();
364
+ return SimpleOrCompound.get <BaseNameAndCompound >().getInt ();
314
365
}
315
366
316
367
// / True if this name is a simple one-component name identical to the
0 commit comments