Skip to content

Commit 265d48a

Browse files
authored
Re-apply "[Parse] Split incremental-extensions" (#66446)
Re-applies #65683 with a fix to always run `Actions.ActOnEndOfTranslationUnit` regardless of incremental processing.
1 parent 4bc4d51 commit 265d48a

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

clang/include/clang/Lex/Preprocessor.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ class Preprocessor {
277277
/// Empty line handler.
278278
EmptylineHandler *Emptyline = nullptr;
279279

280+
/// True to avoid tearing down the lexer etc on EOF
281+
bool IncrementalProcessing = false;
282+
280283
public:
281284
/// The kind of translation unit we are processing.
282285
const TranslationUnitKind TUKind;
@@ -1910,14 +1913,11 @@ class Preprocessor {
19101913
void recomputeCurLexerKind();
19111914

19121915
/// Returns true if incremental processing is enabled
1913-
bool isIncrementalProcessingEnabled() const {
1914-
return getLangOpts().IncrementalExtensions;
1915-
}
1916+
bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
19161917

19171918
/// Enables the incremental processing
19181919
void enableIncrementalProcessing(bool value = true) {
1919-
// FIXME: Drop this interface.
1920-
const_cast<LangOptions &>(getLangOpts()).IncrementalExtensions = value;
1920+
IncrementalProcessing = value;
19211921
}
19221922

19231923
/// Specify the point at which code-completion will be performed.

clang/lib/Lex/PPLexerChange.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
541541
Result.startToken();
542542
CurLexer->BufferPtr = EndPos;
543543

544-
if (isIncrementalProcessingEnabled()) {
544+
if (getLangOpts().IncrementalExtensions) {
545545
CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_repl_input_end);
546546
Result.setAnnotationEndLoc(Result.getLocation());
547547
Result.setAnnotationValue(nullptr);

clang/lib/Lex/Preprocessor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ Preprocessor::Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
146146
Ident_AbnormalTermination = nullptr;
147147
}
148148

149+
// Default incremental processing to -fincremental-extensions, clients can
150+
// override with `enableIncrementalProcessing` if desired.
151+
IncrementalProcessing = LangOpts.IncrementalExtensions;
152+
149153
// If using a PCH where a #pragma hdrstop is expected, start skipping tokens.
150154
if (usingPCHWithPragmaHdrStop())
151155
SkippingUntilPragmaHdrStop = true;

clang/lib/Parse/Parser.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
615615
Sema::ModuleImportState &ImportState) {
616616
DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
617617

618+
// Skip over the EOF token, flagging end of previous input for incremental
619+
// processing
620+
if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
621+
ConsumeToken();
622+
618623
Result = nullptr;
619624
switch (Tok.getKind()) {
620625
case tok::annot_pragma_unused:
@@ -1038,7 +1043,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
10381043
ConsumeToken();
10391044
return nullptr;
10401045
}
1041-
if (PP.isIncrementalProcessingEnabled() &&
1046+
if (getLangOpts().IncrementalExtensions &&
10421047
!isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
10431048
return ParseTopLevelStmtDecl();
10441049

0 commit comments

Comments
 (0)