@@ -553,14 +553,13 @@ class Parser {
553553 return Tok.getLoc ().getAdvancedLoc (-LeadingTrivia.getLength ());
554554 }
555555
556- SourceLoc consumeIdentifier (Identifier *Result = nullptr ,
557- bool allowDollarIdentifier = false ) {
556+ SourceLoc consumeIdentifier (Identifier &Result, bool diagnoseDollarPrefix) {
558557 assert (Tok.isAny (tok::identifier, tok::kw_self, tok::kw_Self));
559- if (Result)
560- * Result = Context.getIdentifier (Tok.getText ());
558+ assert (Result. empty ());
559+ Result = Context.getIdentifier (Tok.getText ());
561560
562561 if (Tok.getText ()[0 ] == ' $' )
563- diagnoseDollarIdentifier (Tok, allowDollarIdentifier );
562+ diagnoseDollarIdentifier (Tok, diagnoseDollarPrefix );
564563
565564 return consumeToken ();
566565 }
@@ -573,15 +572,17 @@ class Parser {
573572 Result = Context.getIdentifier (Tok.getText ());
574573
575574 if (Tok.getText ()[0 ] == ' $' )
576- diagnoseDollarIdentifier (Tok);
575+ diagnoseDollarIdentifier (Tok, /* diagnoseDollarPrefix= */ true );
577576 }
578577 return consumeToken ();
579578 }
580579
581580 // / When we have a token that is an identifier starting with '$',
582581 // / diagnose it if not permitted in this mode.
582+ // / \param diagnoseDollarPrefix Whether to diagnose dollar-prefixed
583+ // / identifiers in addition to a standalone '$'.
583584 void diagnoseDollarIdentifier (const Token &tok,
584- bool allowDollarIdentifier = false ) {
585+ bool diagnoseDollarPrefix ) {
585586 assert (tok.getText ()[0 ] == ' $' );
586587
587588 // If '$' is not guarded by backticks, offer
@@ -592,7 +593,7 @@ class Parser {
592593 return ;
593594 }
594595
595- if (allowDollarIdentifier )
596+ if (!diagnoseDollarPrefix )
596597 return ;
597598
598599 if (tok.getText ().size () == 1 || Context.LangOpts .EnableDollarIdentifiers ||
@@ -790,24 +791,20 @@ class Parser {
790791 // / its name in \p Result. Otherwise, emit an error.
791792 // /
792793 // / \returns false on success, true on error.
793- bool parseIdentifier (Identifier &Result, SourceLoc &Loc, const Diagnostic &D);
794-
794+ bool parseIdentifier (Identifier &Result, SourceLoc &Loc, const Diagnostic &D,
795+ bool diagnoseDollarPrefix);
796+
795797 // / Consume an identifier with a specific expected name. This is useful for
796798 // / contextually sensitive keywords that must always be present.
797799 bool parseSpecificIdentifier (StringRef expected, SourceLoc &Loc,
798800 const Diagnostic &D);
799801
800- template <typename ...DiagArgTypes, typename ...ArgTypes>
801- bool parseIdentifier (Identifier &Result, Diag<DiagArgTypes...> ID,
802- ArgTypes... Args) {
803- SourceLoc L;
804- return parseIdentifier (Result, L, Diagnostic (ID, Args...));
805- }
806-
807802 template <typename ...DiagArgTypes, typename ...ArgTypes>
808803 bool parseIdentifier (Identifier &Result, SourceLoc &L,
809- Diag<DiagArgTypes...> ID, ArgTypes... Args) {
810- return parseIdentifier (Result, L, Diagnostic (ID, Args...));
804+ bool diagnoseDollarPrefix, Diag<DiagArgTypes...> ID,
805+ ArgTypes... Args) {
806+ return parseIdentifier (Result, L, Diagnostic (ID, Args...),
807+ diagnoseDollarPrefix);
811808 }
812809
813810 template <typename ...DiagArgTypes, typename ...ArgTypes>
@@ -820,19 +817,14 @@ class Parser {
820817 // / Consume an identifier or operator if present and return its name
821818 // / in \p Result. Otherwise, emit an error and return true.
822819 bool parseAnyIdentifier (Identifier &Result, SourceLoc &Loc,
823- const Diagnostic &D);
820+ const Diagnostic &D, bool diagnoseDollarPrefix );
824821
825822 template <typename ...DiagArgTypes, typename ...ArgTypes>
826- bool parseAnyIdentifier (Identifier &Result, Diag<DiagArgTypes...> ID,
827- ArgTypes... Args) {
828- SourceLoc L;
829- return parseAnyIdentifier (Result, L, Diagnostic (ID, Args...));
830- }
831-
832- template <typename ...DiagArgTypes, typename ...ArgTypes>
833- bool parseAnyIdentifier (Identifier &Result, SourceLoc &L,
823+ bool parseAnyIdentifier (Identifier &Result, bool diagnoseDollarPrefix,
834824 Diag<DiagArgTypes...> ID, ArgTypes... Args) {
835- return parseAnyIdentifier (Result, L, Diagnostic (ID, Args...));
825+ SourceLoc L;
826+ return parseAnyIdentifier (Result, L, Diagnostic (ID, Args...),
827+ diagnoseDollarPrefix);
836828 }
837829
838830 // / \brief Parse an unsigned integer and returns it in \p Result. On failure
0 commit comments