@@ -84,17 +84,14 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
84
84
NumElements : 32
85
85
);
86
86
87
- SWIFT_INLINE_BITFIELD_EMPTY (DeclRefTypeRepr, TypeRepr);
88
- SWIFT_INLINE_BITFIELD_EMPTY (IdentTypeRepr, DeclRefTypeRepr);
89
-
90
- SWIFT_INLINE_BITFIELD_FULL (GenericIdentTypeRepr, IdentTypeRepr, 32 ,
87
+ SWIFT_INLINE_BITFIELD_FULL (DeclRefTypeRepr, TypeRepr, 1 +32 ,
88
+ // / Whether this instance has a valid angle bracket source range.
89
+ HasAngleBrackets: 1 ,
91
90
: NumPadBits,
91
+
92
92
NumGenericArgs : 32
93
93
);
94
94
95
- SWIFT_INLINE_BITFIELD_FULL (MemberTypeRepr, DeclRefTypeRepr, 32 ,
96
- : NumPadBits, NumMemberComponents : 32 );
97
-
98
95
SWIFT_INLINE_BITFIELD_FULL (CompositionTypeRepr, TypeRepr, 32 ,
99
96
: NumPadBits,
100
97
NumTypes : 32
@@ -332,8 +329,23 @@ class IdentTypeRepr;
332
329
// / Foo.Bar<Gen>
333
330
// / \endcode
334
331
class DeclRefTypeRepr : public TypeRepr {
332
+ DeclNameLoc NameLoc;
333
+
334
+ // / Either the identifier or declaration that describes this
335
+ // / component.
336
+ // /
337
+ // / The initial parsed representation is always an identifier, and
338
+ // / name lookup will resolve this to a specific declaration.
339
+ llvm::PointerUnion<DeclNameRef, TypeDecl *> NameOrDecl;
340
+
341
+ // / The declaration context from which the bound declaration was
342
+ // / found. only valid if IdOrDecl is a TypeDecl.
343
+ DeclContext *DC;
344
+
335
345
protected:
336
- explicit DeclRefTypeRepr (TypeReprKind K) : TypeRepr(K) {}
346
+ explicit DeclRefTypeRepr (TypeReprKind K, DeclNameRef Name,
347
+ DeclNameLoc NameLoc, unsigned NumGenericArgs,
348
+ bool HasAngleBrackets);
337
349
338
350
public:
339
351
static DeclRefTypeRepr *create (const ASTContext &C, TypeRepr *Base,
@@ -356,10 +368,6 @@ class DeclRefTypeRepr : public TypeRepr {
356
368
// / qualifier of a `IdentTypeRepr` is itself.
357
369
const TypeRepr *getRoot () const ;
358
370
359
- // / Returns \c this if it is a \c IdentTypeRepr. Otherwise, \c this
360
- // / is a \c MemberTypeRepr, and the method returns its last member component.
361
- IdentTypeRepr *getLastComponent ();
362
-
363
371
DeclNameLoc getNameLoc () const ;
364
372
DeclNameRef getNameRef () const ;
365
373
@@ -387,6 +395,11 @@ class DeclRefTypeRepr : public TypeRepr {
387
395
388
396
ArrayRef<TypeRepr *> getGenericArgs () const ;
389
397
398
+ protected:
399
+ // / Returns whether this instance has a valid angle bracket source range.
400
+ bool hasAngleBrackets () const ;
401
+
402
+ public:
390
403
SourceRange getAngleBrackets () const ;
391
404
392
405
static bool classof (const TypeRepr *T) {
@@ -397,6 +410,8 @@ class DeclRefTypeRepr : public TypeRepr {
397
410
static bool classof (const DeclRefTypeRepr *T) { return true ; }
398
411
399
412
protected:
413
+ SourceLoc getLocImpl () const ;
414
+
400
415
void printImpl (ASTPrinter &Printer, const PrintOptions &Opts) const ;
401
416
402
417
friend class TypeRepr ;
@@ -408,55 +423,20 @@ class DeclRefTypeRepr : public TypeRepr {
408
423
// / Bar<Gen>
409
424
// / \endcode
410
425
class IdentTypeRepr : public DeclRefTypeRepr {
411
- DeclNameLoc Loc;
412
-
413
- // / Either the identifier or declaration that describes this
414
- // / component.
415
- // /
416
- // / The initial parsed representation is always an identifier, and
417
- // / name lookup will resolve this to a specific declaration.
418
- llvm::PointerUnion<DeclNameRef, TypeDecl *> IdOrDecl;
419
-
420
- // / The declaration context from which the bound declaration was
421
- // / found. only valid if IdOrDecl is a TypeDecl.
422
- DeclContext *DC;
423
-
424
426
protected:
425
- IdentTypeRepr (TypeReprKind K, DeclNameLoc Loc, DeclNameRef Id)
426
- : DeclRefTypeRepr(K), Loc(Loc), IdOrDecl(Id), DC(nullptr ) {}
427
+ IdentTypeRepr (TypeReprKind K, DeclNameLoc Loc, DeclNameRef Id,
428
+ unsigned NumGenericArgs, bool hasGenericArgList)
429
+ : DeclRefTypeRepr(K, Id, Loc, NumGenericArgs, hasGenericArgList) {}
427
430
428
431
public:
429
- DeclNameLoc getNameLoc () const { return Loc; }
430
- DeclNameRef getNameRef () const ;
431
-
432
- // / Replace the identifier with a new identifier, e.g., due to typo
433
- // / correction.
434
- void overwriteNameRef (DeclNameRef newId) { IdOrDecl = newId; }
435
-
436
- // / Return true if this name has been resolved to a type decl. This happens
437
- // / during type resolution.
438
- bool isBound () const { return IdOrDecl.is <TypeDecl *>(); }
439
-
440
- TypeDecl *getBoundDecl () const { return IdOrDecl.dyn_cast <TypeDecl*>(); }
441
-
442
- DeclContext *getDeclContext () const {
443
- assert (isBound ());
444
- return DC;
445
- }
446
-
447
- void setValue (TypeDecl *TD, DeclContext *DC) {
448
- IdOrDecl = TD;
449
- this ->DC = DC;
450
- }
451
-
452
432
static bool classof (const TypeRepr *T) {
453
433
return T->getKind () == TypeReprKind::SimpleIdent ||
454
434
T->getKind () == TypeReprKind::GenericIdent;
455
435
}
456
436
static bool classof (const IdentTypeRepr *T) { return true ; }
457
437
458
438
protected:
459
- SourceLoc getLocImpl () const { return Loc. getBaseNameLoc (); }
439
+ SourceLoc getStartLocImpl () const { return getNameLoc (). getStartLoc (); }
460
440
461
441
friend class TypeRepr ;
462
442
};
@@ -465,7 +445,8 @@ class IdentTypeRepr : public DeclRefTypeRepr {
465
445
class SimpleIdentTypeRepr : public IdentTypeRepr {
466
446
public:
467
447
SimpleIdentTypeRepr (DeclNameLoc Loc, DeclNameRef Id)
468
- : IdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id) {}
448
+ : IdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id, /* NumGenericArgs=*/ 0 ,
449
+ /* HasAngleBrackets=*/ false ) {}
469
450
470
451
// SmallVector::emplace_back will never need to call this because
471
452
// we reserve the right size, but it does try statically.
@@ -480,7 +461,6 @@ class SimpleIdentTypeRepr : public IdentTypeRepr {
480
461
static bool classof (const SimpleIdentTypeRepr *T) { return true ; }
481
462
482
463
private:
483
- SourceLoc getStartLocImpl () const { return getNameLoc ().getStartLoc (); }
484
464
SourceLoc getEndLocImpl () const { return getNameLoc ().getEndLoc (); }
485
465
friend class TypeRepr ;
486
466
};
@@ -497,17 +477,7 @@ class GenericIdentTypeRepr final
497
477
498
478
GenericIdentTypeRepr (DeclNameLoc Loc, DeclNameRef Id,
499
479
ArrayRef<TypeRepr *> GenericArgs,
500
- SourceRange AngleBrackets)
501
- : IdentTypeRepr(TypeReprKind::GenericIdent, Loc, Id),
502
- AngleBrackets (AngleBrackets) {
503
- Bits.GenericIdentTypeRepr .NumGenericArgs = GenericArgs.size ();
504
- #ifndef NDEBUG
505
- for (auto arg : GenericArgs)
506
- assert (arg != nullptr );
507
- #endif
508
- std::uninitialized_copy (GenericArgs.begin (), GenericArgs.end (),
509
- getTrailingObjects<TypeRepr*>());
510
- }
480
+ SourceRange AngleBrackets);
511
481
512
482
public:
513
483
static GenericIdentTypeRepr *create (const ASTContext &C,
@@ -516,13 +486,8 @@ class GenericIdentTypeRepr final
516
486
ArrayRef<TypeRepr*> GenericArgs,
517
487
SourceRange AngleBrackets);
518
488
519
- unsigned getNumGenericArgs () const {
520
- return Bits.GenericIdentTypeRepr .NumGenericArgs ;
521
- }
522
-
523
489
ArrayRef<TypeRepr*> getGenericArgs () const {
524
- return {getTrailingObjects<TypeRepr*>(),
525
- Bits.GenericIdentTypeRepr .NumGenericArgs };
490
+ return {getTrailingObjects<TypeRepr *>(), getNumGenericArgs ()};
526
491
}
527
492
SourceRange getAngleBrackets () const { return AngleBrackets; }
528
493
@@ -532,7 +497,6 @@ class GenericIdentTypeRepr final
532
497
static bool classof (const GenericIdentTypeRepr *T) { return true ; }
533
498
534
499
private:
535
- SourceLoc getStartLocImpl () const { return getNameLoc ().getStartLoc (); }
536
500
SourceLoc getEndLocImpl () const { return AngleBrackets.End ; }
537
501
friend class TypeRepr ;
538
502
};
@@ -543,25 +507,23 @@ class GenericIdentTypeRepr final
543
507
// / Foo.Bar<Gen>.Baz
544
508
// / [Int].Bar
545
509
// / \endcode
546
- class MemberTypeRepr final : public DeclRefTypeRepr,
547
- private llvm::TrailingObjects<MemberTypeRepr, IdentTypeRepr *> {
510
+ class MemberTypeRepr final
511
+ : public DeclRefTypeRepr,
512
+ private llvm::TrailingObjects<MemberTypeRepr, TypeRepr *, SourceRange> {
548
513
friend TrailingObjects;
549
514
550
- const ASTContext *C;
551
-
552
- // / The root component, which is not necessarily an identifier type.
553
- TypeRepr *Root;
515
+ // / The qualifier or base type representation. For example, `A.B` for `A.B.C`.
516
+ TypeRepr *Base;
554
517
555
- MemberTypeRepr (TypeRepr *Root, ArrayRef<IdentTypeRepr *> MemberComponents,
556
- const ASTContext &C)
557
- : DeclRefTypeRepr(TypeReprKind::Member), C(&C), Root(Root) {
558
- Bits.MemberTypeRepr .NumMemberComponents = MemberComponents.size ();
559
- assert (MemberComponents.size () > 0 &&
560
- " MemberTypeRepr requires at least 1 member component" );
561
- std::uninitialized_copy (MemberComponents.begin (), MemberComponents.end (),
562
- getTrailingObjects<IdentTypeRepr *>());
518
+ size_t numTrailingObjects (OverloadToken<TypeRepr *>) const {
519
+ return getNumGenericArgs ();
563
520
}
564
521
522
+ MemberTypeRepr (TypeRepr *Base, DeclNameRef Name, DeclNameLoc NameLoc);
523
+
524
+ MemberTypeRepr (TypeRepr *Base, DeclNameRef Name, DeclNameLoc NameLoc,
525
+ ArrayRef<TypeRepr *> GenericArgs, SourceRange AngleBrackets);
526
+
565
527
public:
566
528
static MemberTypeRepr *create (const ASTContext &C, TypeRepr *Base,
567
529
DeclNameLoc NameLoc, DeclNameRef Name);
@@ -571,37 +533,25 @@ class MemberTypeRepr final : public DeclRefTypeRepr,
571
533
ArrayRef<TypeRepr *> GenericArgs,
572
534
SourceRange AngleBrackets);
573
535
574
- static TypeRepr *create (const ASTContext &Ctx, TypeRepr *Root,
575
- ArrayRef<IdentTypeRepr *> MemberComponents);
576
-
577
- static DeclRefTypeRepr *create (const ASTContext &Ctx,
578
- ArrayRef<IdentTypeRepr *> Components);
579
-
580
536
// / Returns the qualifier or base type representation. For example, `A.B`
581
537
// / for `A.B.C`.
582
538
TypeRepr *getBase () const ;
583
539
584
540
// / Returns the root qualifier. For example, `A` for `A.B.C`.
585
- TypeRepr *getRoot () const { return Root; }
541
+ TypeRepr *getRoot () const ;
586
542
587
- ArrayRef<IdentTypeRepr *> getMemberComponents () const {
588
- return {getTrailingObjects<IdentTypeRepr *>(),
589
- Bits.MemberTypeRepr .NumMemberComponents };
590
- }
543
+ ArrayRef<TypeRepr *> getGenericArgs () const ;
591
544
592
- IdentTypeRepr *getLastComponent () const {
593
- return getMemberComponents ().back ();
594
- }
545
+ SourceRange getAngleBrackets () const ;
595
546
596
547
static bool classof (const TypeRepr *T) {
597
548
return T->getKind () == TypeReprKind::Member;
598
549
}
599
550
static bool classof (const MemberTypeRepr *T) { return true ; }
600
551
601
552
private:
602
- SourceLoc getStartLocImpl () const { return getRoot ()->getStartLoc (); }
603
- SourceLoc getEndLocImpl () const { return getLastComponent ()->getEndLoc (); }
604
- SourceLoc getLocImpl () const { return getLastComponent ()->getLoc (); }
553
+ SourceLoc getStartLocImpl () const ;
554
+ SourceLoc getEndLocImpl () const ;
605
555
606
556
friend class TypeRepr ;
607
557
};
0 commit comments