Skip to content

Commit 4f5bf99

Browse files
committed
[Parse] NFC: Allow sub-lexers to disable diagnostics
And `const` qualify a couple of params/methods.
1 parent 18caf45 commit 4f5bf99

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

include/swift/AST/DiagnosticEngine.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ namespace swift {
13901390
DiagnosticEngine &getDiags() { return QueueEngine; }
13911391

13921392
/// Retrieve the underlying engine which will receive the diagnostics.
1393-
DiagnosticEngine &getUnderlyingDiags() { return UnderlyingEngine; }
1393+
DiagnosticEngine &getUnderlyingDiags() const { return UnderlyingEngine; }
13941394

13951395
/// Clear this queue and erase all diagnostics recorded.
13961396
void clear() {

include/swift/Parse/Lexer.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class Lexer {
180180
/// Retrieve the underlying diagnostic engine we emit diagnostics to. Note
181181
/// this should only be used for diagnostics not concerned with the current
182182
/// token.
183-
DiagnosticEngine *getUnderlyingDiags() {
183+
DiagnosticEngine *getUnderlyingDiags() const {
184184
return DiagQueue ? &DiagQueue->getUnderlyingDiags() : nullptr;
185185
}
186186

@@ -218,7 +218,10 @@ class Lexer {
218218
/// \param Parent the parent lexer that scans the whole buffer
219219
/// \param BeginState start of the subrange
220220
/// \param EndState end of the subrange
221-
Lexer(Lexer &Parent, State BeginState, State EndState);
221+
/// \param EnableDiagnostics Whether to inherit the diagnostic engine of
222+
/// \p Parent. If \c false, diagnostics will be disabled.
223+
Lexer(const Lexer &Parent, State BeginState, State EndState,
224+
bool EnableDiagnostics = true);
222225

223226
/// Returns true if this lexer will produce a code completion token.
224227
bool isCodeCompletion() const {

lib/Parse/Lexer.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,11 @@ Lexer::Lexer(const LangOptions &Options, const SourceManager &SourceMgr,
246246
initialize(Offset, EndOffset);
247247
}
248248

249-
Lexer::Lexer(Lexer &Parent, State BeginState, State EndState)
249+
Lexer::Lexer(const Lexer &Parent, State BeginState, State EndState,
250+
bool EnableDiagnostics)
250251
: Lexer(PrincipalTag(), Parent.LangOpts, Parent.SourceMgr, Parent.BufferID,
251-
Parent.getUnderlyingDiags(), Parent.LexMode,
252+
EnableDiagnostics ? Parent.getUnderlyingDiags() : nullptr,
253+
Parent.LexMode,
252254
Parent.IsHashbangAllowed
253255
? HashbangMode::Allowed
254256
: HashbangMode::Disallowed,

0 commit comments

Comments
 (0)