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