mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[NFC] Introduce DiagRef and use it throughout the parser
The goal is to have a lightweight way to pass an unapplied diagnostic to general routines. Constructing a Diagnostic is quite expensive as something we're potentially doing in hot paths, as opposed to just when we're actually emitting the diagnostic. This design allows the expense to be delayed until we need it. I've also optimized the Diagnostic constructor to avoid copying arguments unnecessarily; this is a relatively small expense, since arguments are POD, but there's really no good reason not to do it.
This commit is contained in:
@@ -868,7 +868,7 @@ Parser::StructureMarkerRAII::StructureMarkerRAII(Parser &parser,
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
bool Parser::parseIdentifier(Identifier &Result, SourceLoc &Loc,
|
||||
const Diagnostic &D, bool diagnoseDollarPrefix) {
|
||||
DiagRef D, bool diagnoseDollarPrefix) {
|
||||
switch (Tok.getKind()) {
|
||||
case tok::kw_self:
|
||||
case tok::kw_Self:
|
||||
@@ -883,7 +883,7 @@ bool Parser::parseIdentifier(Identifier &Result, SourceLoc &Loc,
|
||||
}
|
||||
|
||||
bool Parser::parseSpecificIdentifier(StringRef expected, SourceLoc &loc,
|
||||
const Diagnostic &D) {
|
||||
DiagRef D) {
|
||||
if (Tok.getText() != expected) {
|
||||
diagnose(Tok, D);
|
||||
return true;
|
||||
@@ -895,8 +895,7 @@ bool Parser::parseSpecificIdentifier(StringRef expected, SourceLoc &loc,
|
||||
/// parseAnyIdentifier - Consume an identifier or operator if present and return
|
||||
/// its name in Result. Otherwise, emit an error and return true.
|
||||
bool Parser::parseAnyIdentifier(Identifier &Result, SourceLoc &Loc,
|
||||
const Diagnostic &D,
|
||||
bool diagnoseDollarPrefix) {
|
||||
DiagRef D, bool diagnoseDollarPrefix) {
|
||||
if (Tok.is(tok::identifier)) {
|
||||
Loc = consumeIdentifier(Result, diagnoseDollarPrefix);
|
||||
return false;
|
||||
@@ -935,7 +934,7 @@ bool Parser::parseAnyIdentifier(Identifier &Result, SourceLoc &Loc,
|
||||
/// consumed and false is returned.
|
||||
///
|
||||
/// If the input is malformed, this emits the specified error diagnostic.
|
||||
bool Parser::parseToken(tok K, SourceLoc &TokLoc, const Diagnostic &D) {
|
||||
bool Parser::parseToken(tok K, SourceLoc &TokLoc, DiagRef D) {
|
||||
if (Tok.is(K)) {
|
||||
TokLoc = consumeToken(K);
|
||||
return false;
|
||||
@@ -946,7 +945,7 @@ bool Parser::parseToken(tok K, SourceLoc &TokLoc, const Diagnostic &D) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parser::parseMatchingToken(tok K, SourceLoc &TokLoc, Diagnostic ErrorDiag,
|
||||
bool Parser::parseMatchingToken(tok K, SourceLoc &TokLoc, DiagRef ErrorDiag,
|
||||
SourceLoc OtherLoc) {
|
||||
Diag<> OtherNote;
|
||||
switch (K) {
|
||||
@@ -966,7 +965,7 @@ bool Parser::parseMatchingToken(tok K, SourceLoc &TokLoc, Diagnostic ErrorDiag,
|
||||
}
|
||||
|
||||
bool Parser::parseUnsignedInteger(unsigned &Result, SourceLoc &Loc,
|
||||
const Diagnostic &D) {
|
||||
DiagRef D) {
|
||||
auto IntTok = Tok;
|
||||
if (parseToken(tok::integer_literal, Loc, D))
|
||||
return true;
|
||||
@@ -1058,7 +1057,7 @@ Parser::parseListItem(ParserStatus &Status, tok RightK, SourceLoc LeftLoc,
|
||||
|
||||
ParserStatus
|
||||
Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
|
||||
bool AllowSepAfterLast, Diag<> ErrorDiag,
|
||||
bool AllowSepAfterLast, DiagRef ErrorDiag,
|
||||
llvm::function_ref<ParserStatus()> callback) {
|
||||
if (Tok.is(RightK)) {
|
||||
RightLoc = consumeToken(RightK);
|
||||
|
||||
Reference in New Issue
Block a user