@@ -84,17 +84,14 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
8484 NumElements : 32
8585 );
8686
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 ,
9190 : NumPadBits,
91+
9292 NumGenericArgs : 32
9393 );
9494
95- SWIFT_INLINE_BITFIELD_FULL (MemberTypeRepr, DeclRefTypeRepr, 32 ,
96- : NumPadBits, NumMemberComponents : 32 );
97-
9895 SWIFT_INLINE_BITFIELD_FULL (CompositionTypeRepr, TypeRepr, 32 ,
9996 : NumPadBits,
10097 NumTypes : 32
@@ -332,8 +329,23 @@ class IdentTypeRepr;
332329// / Foo.Bar<Gen>
333330// / \endcode
334331class 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+
335345protected:
336- explicit DeclRefTypeRepr (TypeReprKind K) : TypeRepr(K) {}
346+ explicit DeclRefTypeRepr (TypeReprKind K, DeclNameRef Name,
347+ DeclNameLoc NameLoc, unsigned NumGenericArgs,
348+ bool HasAngleBrackets);
337349
338350public:
339351 static DeclRefTypeRepr *create (const ASTContext &C, TypeRepr *Base,
@@ -356,10 +368,6 @@ class DeclRefTypeRepr : public TypeRepr {
356368 // / qualifier of a `IdentTypeRepr` is itself.
357369 const TypeRepr *getRoot () const ;
358370
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-
363371 DeclNameLoc getNameLoc () const ;
364372 DeclNameRef getNameRef () const ;
365373
@@ -387,6 +395,11 @@ class DeclRefTypeRepr : public TypeRepr {
387395
388396 ArrayRef<TypeRepr *> getGenericArgs () const ;
389397
398+ protected:
399+ // / Returns whether this instance has a valid angle bracket source range.
400+ bool hasAngleBrackets () const ;
401+
402+ public:
390403 SourceRange getAngleBrackets () const ;
391404
392405 static bool classof (const TypeRepr *T) {
@@ -397,6 +410,8 @@ class DeclRefTypeRepr : public TypeRepr {
397410 static bool classof (const DeclRefTypeRepr *T) { return true ; }
398411
399412protected:
413+ SourceLoc getLocImpl () const ;
414+
400415 void printImpl (ASTPrinter &Printer, const PrintOptions &Opts) const ;
401416
402417 friend class TypeRepr ;
@@ -408,55 +423,20 @@ class DeclRefTypeRepr : public TypeRepr {
408423// / Bar<Gen>
409424// / \endcode
410425class 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-
424426protected:
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) {}
427430
428431public:
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-
452432 static bool classof (const TypeRepr *T) {
453433 return T->getKind () == TypeReprKind::SimpleIdent ||
454434 T->getKind () == TypeReprKind::GenericIdent;
455435 }
456436 static bool classof (const IdentTypeRepr *T) { return true ; }
457437
458438protected:
459- SourceLoc getLocImpl () const { return Loc. getBaseNameLoc (); }
439+ SourceLoc getStartLocImpl () const { return getNameLoc (). getStartLoc (); }
460440
461441 friend class TypeRepr ;
462442};
@@ -465,7 +445,8 @@ class IdentTypeRepr : public DeclRefTypeRepr {
465445class SimpleIdentTypeRepr : public IdentTypeRepr {
466446public:
467447 SimpleIdentTypeRepr (DeclNameLoc Loc, DeclNameRef Id)
468- : IdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id) {}
448+ : IdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id, /* NumGenericArgs=*/ 0 ,
449+ /* HasAngleBrackets=*/ false ) {}
469450
470451 // SmallVector::emplace_back will never need to call this because
471452 // we reserve the right size, but it does try statically.
@@ -480,7 +461,6 @@ class SimpleIdentTypeRepr : public IdentTypeRepr {
480461 static bool classof (const SimpleIdentTypeRepr *T) { return true ; }
481462
482463private:
483- SourceLoc getStartLocImpl () const { return getNameLoc ().getStartLoc (); }
484464 SourceLoc getEndLocImpl () const { return getNameLoc ().getEndLoc (); }
485465 friend class TypeRepr ;
486466};
@@ -497,17 +477,7 @@ class GenericIdentTypeRepr final
497477
498478 GenericIdentTypeRepr (DeclNameLoc Loc, DeclNameRef Id,
499479 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);
511481
512482public:
513483 static GenericIdentTypeRepr *create (const ASTContext &C,
@@ -516,13 +486,8 @@ class GenericIdentTypeRepr final
516486 ArrayRef<TypeRepr*> GenericArgs,
517487 SourceRange AngleBrackets);
518488
519- unsigned getNumGenericArgs () const {
520- return Bits.GenericIdentTypeRepr .NumGenericArgs ;
521- }
522-
523489 ArrayRef<TypeRepr*> getGenericArgs () const {
524- return {getTrailingObjects<TypeRepr*>(),
525- Bits.GenericIdentTypeRepr .NumGenericArgs };
490+ return {getTrailingObjects<TypeRepr *>(), getNumGenericArgs ()};
526491 }
527492 SourceRange getAngleBrackets () const { return AngleBrackets; }
528493
@@ -532,7 +497,6 @@ class GenericIdentTypeRepr final
532497 static bool classof (const GenericIdentTypeRepr *T) { return true ; }
533498
534499private:
535- SourceLoc getStartLocImpl () const { return getNameLoc ().getStartLoc (); }
536500 SourceLoc getEndLocImpl () const { return AngleBrackets.End ; }
537501 friend class TypeRepr ;
538502};
@@ -543,25 +507,23 @@ class GenericIdentTypeRepr final
543507// / Foo.Bar<Gen>.Baz
544508// / [Int].Bar
545509// / \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> {
548513 friend TrailingObjects;
549514
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;
554517
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 ();
563520 }
564521
522+ MemberTypeRepr (TypeRepr *Base, DeclNameRef Name, DeclNameLoc NameLoc);
523+
524+ MemberTypeRepr (TypeRepr *Base, DeclNameRef Name, DeclNameLoc NameLoc,
525+ ArrayRef<TypeRepr *> GenericArgs, SourceRange AngleBrackets);
526+
565527public:
566528 static MemberTypeRepr *create (const ASTContext &C, TypeRepr *Base,
567529 DeclNameLoc NameLoc, DeclNameRef Name);
@@ -571,37 +533,25 @@ class MemberTypeRepr final : public DeclRefTypeRepr,
571533 ArrayRef<TypeRepr *> GenericArgs,
572534 SourceRange AngleBrackets);
573535
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-
580536 // / Returns the qualifier or base type representation. For example, `A.B`
581537 // / for `A.B.C`.
582538 TypeRepr *getBase () const ;
583539
584540 // / Returns the root qualifier. For example, `A` for `A.B.C`.
585- TypeRepr *getRoot () const { return Root; }
541+ TypeRepr *getRoot () const ;
586542
587- ArrayRef<IdentTypeRepr *> getMemberComponents () const {
588- return {getTrailingObjects<IdentTypeRepr *>(),
589- Bits.MemberTypeRepr .NumMemberComponents };
590- }
543+ ArrayRef<TypeRepr *> getGenericArgs () const ;
591544
592- IdentTypeRepr *getLastComponent () const {
593- return getMemberComponents ().back ();
594- }
545+ SourceRange getAngleBrackets () const ;
595546
596547 static bool classof (const TypeRepr *T) {
597548 return T->getKind () == TypeReprKind::Member;
598549 }
599550 static bool classof (const MemberTypeRepr *T) { return true ; }
600551
601552private:
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 ;
605555
606556 friend class TypeRepr ;
607557};
0 commit comments