@@ -553,14 +553,13 @@ class Parser {
553
553
return Tok.getLoc ().getAdvancedLoc (-LeadingTrivia.getLength ());
554
554
}
555
555
556
- SourceLoc consumeIdentifier (Identifier *Result = nullptr ,
557
- bool allowDollarIdentifier = false ) {
556
+ SourceLoc consumeIdentifier (Identifier &Result, bool diagnoseDollarPrefix) {
558
557
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 ());
561
560
562
561
if (Tok.getText ()[0 ] == ' $' )
563
- diagnoseDollarIdentifier (Tok, allowDollarIdentifier );
562
+ diagnoseDollarIdentifier (Tok, diagnoseDollarPrefix );
564
563
565
564
return consumeToken ();
566
565
}
@@ -573,15 +572,17 @@ class Parser {
573
572
Result = Context.getIdentifier (Tok.getText ());
574
573
575
574
if (Tok.getText ()[0 ] == ' $' )
576
- diagnoseDollarIdentifier (Tok);
575
+ diagnoseDollarIdentifier (Tok, /* diagnoseDollarPrefix= */ true );
577
576
}
578
577
return consumeToken ();
579
578
}
580
579
581
580
// / When we have a token that is an identifier starting with '$',
582
581
// / diagnose it if not permitted in this mode.
582
+ // / \param diagnoseDollarPrefix Whether to diagnose dollar-prefixed
583
+ // / identifiers in addition to a standalone '$'.
583
584
void diagnoseDollarIdentifier (const Token &tok,
584
- bool allowDollarIdentifier = false ) {
585
+ bool diagnoseDollarPrefix ) {
585
586
assert (tok.getText ()[0 ] == ' $' );
586
587
587
588
// If '$' is not guarded by backticks, offer
@@ -592,7 +593,7 @@ class Parser {
592
593
return ;
593
594
}
594
595
595
- if (allowDollarIdentifier )
596
+ if (!diagnoseDollarPrefix )
596
597
return ;
597
598
598
599
if (tok.getText ().size () == 1 || Context.LangOpts .EnableDollarIdentifiers ||
@@ -790,24 +791,20 @@ class Parser {
790
791
// / its name in \p Result. Otherwise, emit an error.
791
792
// /
792
793
// / \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
+
795
797
// / Consume an identifier with a specific expected name. This is useful for
796
798
// / contextually sensitive keywords that must always be present.
797
799
bool parseSpecificIdentifier (StringRef expected, SourceLoc &Loc,
798
800
const Diagnostic &D);
799
801
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
-
807
802
template <typename ...DiagArgTypes, typename ...ArgTypes>
808
803
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);
811
808
}
812
809
813
810
template <typename ...DiagArgTypes, typename ...ArgTypes>
@@ -820,19 +817,14 @@ class Parser {
820
817
// / Consume an identifier or operator if present and return its name
821
818
// / in \p Result. Otherwise, emit an error and return true.
822
819
bool parseAnyIdentifier (Identifier &Result, SourceLoc &Loc,
823
- const Diagnostic &D);
820
+ const Diagnostic &D, bool diagnoseDollarPrefix );
824
821
825
822
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,
834
824
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);
836
828
}
837
829
838
830
// / \brief Parse an unsigned integer and returns it in \p Result. On failure
0 commit comments