@@ -203,11 +203,11 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(
203
203
status, PackTypeRepr::create (Context, keywordLoc,
204
204
SourceRange (lbLoc, rbLoc), elements));
205
205
} else {
206
- ty = parseTypeIdentifier ();
207
- if (auto *ITR = cast_or_null<IdentTypeRepr>( ty.getPtrOrNull () )) {
206
+ ty = parseTypeIdentifier (/* Base= */ nullptr );
207
+ if (auto *repr = ty.getPtrOrNull ()) {
208
208
if (Tok.is (tok::code_complete) && !Tok.isAtStartOfLine ()) {
209
209
if (CodeCompletionCallbacks) {
210
- CodeCompletionCallbacks->completeTypeSimpleWithoutDot (ITR );
210
+ CodeCompletionCallbacks->completeTypeSimpleWithoutDot (repr );
211
211
}
212
212
213
213
ty.setHasCodeCompletionAndIsError ();
@@ -771,14 +771,14 @@ ParserResult<TypeRepr> Parser::parseQualifiedDeclNameBaseType() {
771
771
}
772
772
773
773
ParserStatus Status;
774
- SmallVector<IdentTypeRepr *, 4 > ComponentsR ;
774
+ DeclRefTypeRepr *Result = nullptr ;
775
775
SourceLoc EndLoc;
776
776
while (true ) {
777
- auto IdentResult = parseTypeIdentifier ();
778
- if (IdentResult .isParseErrorOrHasCompletion ())
779
- return IdentResult ;
777
+ auto PartialResult = parseTypeIdentifier (/* Base= */ Result );
778
+ if (PartialResult .isParseErrorOrHasCompletion ())
779
+ return PartialResult ;
780
780
781
- ComponentsR. push_back (cast<IdentTypeRepr>(IdentResult. get ()) );
781
+ Result = PartialResult. get ();
782
782
783
783
// Treat 'Foo.<anything>' as an attempt to write a dotted type
784
784
// unless <anything> is 'Type'.
@@ -811,31 +811,26 @@ ParserResult<TypeRepr> Parser::parseQualifiedDeclNameBaseType() {
811
811
break ;
812
812
}
813
813
814
- DeclRefTypeRepr *DeclRefTR = nullptr ;
815
- if (!ComponentsR.empty ()) {
816
- DeclRefTR = MemberTypeRepr::create (Context, ComponentsR);
817
- }
818
-
819
814
if (Status.hasCodeCompletion ()) {
820
815
if (Tok.isNot (tok::code_complete)) {
821
816
// We have a dot.
822
817
consumeToken ();
823
818
if (CodeCompletionCallbacks) {
824
- CodeCompletionCallbacks->completeTypeSimpleWithDot (DeclRefTR );
819
+ CodeCompletionCallbacks->completeTypeSimpleWithDot (Result );
825
820
}
826
821
} else {
827
822
if (CodeCompletionCallbacks) {
828
- CodeCompletionCallbacks->completeTypeSimpleWithoutDot (DeclRefTR );
823
+ CodeCompletionCallbacks->completeTypeSimpleWithoutDot (Result );
829
824
}
830
825
}
831
826
// Eat the code completion token because we handled it.
832
827
consumeToken (tok::code_complete);
833
828
}
834
829
835
- return makeParserResult (Status, DeclRefTR );
830
+ return makeParserResult (Status, Result );
836
831
}
837
832
838
- ParserResult<IdentTypeRepr > Parser::parseTypeIdentifier () {
833
+ ParserResult<DeclRefTypeRepr > Parser::parseTypeIdentifier (TypeRepr *Base ) {
839
834
// FIXME: We should parse e.g. 'X.var'. Almost any keyword is a valid member
840
835
// component.
841
836
DeclNameLoc Loc;
@@ -846,7 +841,7 @@ ParserResult<IdentTypeRepr> Parser::parseTypeIdentifier() {
846
841
return makeParserError ();
847
842
848
843
ParserStatus Status;
849
- IdentTypeRepr *IdTR ;
844
+ DeclRefTypeRepr *Result ;
850
845
851
846
if (startsWithLess (Tok)) {
852
847
SourceLoc LAngle, RAngle;
@@ -855,20 +850,20 @@ ParserResult<IdentTypeRepr> Parser::parseTypeIdentifier() {
855
850
if (ArgsStatus.isErrorOrHasCompletion ())
856
851
return ArgsStatus;
857
852
858
- IdTR = GenericIdentTypeRepr ::create (Context, Loc, Name, GenericArgs,
859
- SourceRange (LAngle, RAngle));
853
+ Result = DeclRefTypeRepr ::create (Context, Base , Loc, Name, GenericArgs,
854
+ SourceRange (LAngle, RAngle));
860
855
} else {
861
- IdTR = new (Context) SimpleIdentTypeRepr ( Loc, Name);
856
+ Result = DeclRefTypeRepr::create (Context, Base, Loc, Name);
862
857
}
863
858
864
- return makeParserResult (IdTR );
859
+ return makeParserResult (Result );
865
860
}
866
861
867
862
ParserResult<TypeRepr> Parser::parseTypeDotted (ParserResult<TypeRepr> Base) {
868
863
assert (Base.isNonNull ());
869
864
assert (Tok.isAny (tok::period, tok::period_prefix));
870
865
871
- SmallVector<IdentTypeRepr *, 4 > MemberComponents ;
866
+ TypeRepr *Result = Base. get () ;
872
867
873
868
while (Tok.isAny (tok::period, tok::period_prefix)) {
874
869
if (peekToken ().is (tok::code_complete)) {
@@ -881,32 +876,25 @@ ParserResult<TypeRepr> Parser::parseTypeDotted(ParserResult<TypeRepr> Base) {
881
876
882
877
if (Tok.isContextualKeyword (" Type" ) ||
883
878
Tok.isContextualKeyword (" Protocol" )) {
884
- TypeRepr *MetaBase =
885
- MemberTypeRepr::create (Context, Base.get (), MemberComponents);
886
879
if (Tok.getRawText () == " Type" ) {
887
- Base = makeParserResult (Base,
888
- new (Context) MetatypeTypeRepr (
889
- MetaBase, consumeToken (tok::identifier)));
880
+ Result = new (Context)
881
+ MetatypeTypeRepr (Result, consumeToken (tok::identifier));
890
882
} else {
891
- Base = makeParserResult (Base,
892
- new (Context) ProtocolTypeRepr (
893
- MetaBase, consumeToken (tok::identifier)));
883
+ Result = new (Context)
884
+ ProtocolTypeRepr (Result, consumeToken (tok::identifier));
894
885
}
895
886
896
- // Start anew with a metatype base.
897
- MemberComponents.clear ();
898
887
continue ;
899
888
}
900
889
901
- auto IdentResult = parseTypeIdentifier ();
902
- if (IdentResult .isParseErrorOrHasCompletion ())
903
- return IdentResult | ParserStatus (Base);
890
+ auto PartialResult = parseTypeIdentifier (/* Base= */ Result );
891
+ if (PartialResult .isParseErrorOrHasCompletion ())
892
+ return PartialResult | ParserStatus (Base);
904
893
905
- MemberComponents. push_back (cast<IdentTypeRepr>(IdentResult. get ()) );
894
+ Result = PartialResult. get ();
906
895
}
907
896
908
- return makeParserResult (
909
- Base, MemberTypeRepr::create (Context, Base.get (), MemberComponents));
897
+ return makeParserResult (Base, Result);
910
898
}
911
899
912
900
// / parseTypeSimpleOrComposition
0 commit comments