Skip to content

Commit 4c264c2

Browse files
authored
[Parse] Split incremental-extensions (#65683)
The preprocessor `IncrementalProcessing` option was being used to control whether or not to teardown the lexer or run the end of translation unit action. In D127284 this was merged with `-fincremental-extensions`, which also changes top level parsing. Split these again so that the former behavior can be achieved without the latter (ie. to allow managing lifetime without also changing parsing). Resolves rdar://113406310.
1 parent 8ee0874 commit 4c264c2

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
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: 8 additions & 2 deletions
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:
@@ -706,7 +711,8 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
706711

707712
// Late template parsing can begin.
708713
Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
709-
Actions.ActOnEndOfTranslationUnit();
714+
if (!PP.isIncrementalProcessingEnabled())
715+
Actions.ActOnEndOfTranslationUnit();
710716
//else don't tell Sema that we ended parsing: more input might come.
711717
return true;
712718

@@ -1038,7 +1044,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
10381044
ConsumeToken();
10391045
return nullptr;
10401046
}
1041-
if (PP.isIncrementalProcessingEnabled() &&
1047+
if (getLangOpts().IncrementalExtensions &&
10421048
!isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
10431049
return ParseTopLevelStmtDecl();
10441050

0 commit comments

Comments
 (0)