Skip to content

Commit 68090ee

Browse files
committed
[stable/20230725] Split incremental-extensions
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 34ce72a commit 68090ee

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
@@ -281,6 +281,9 @@ class Preprocessor {
281281
/// Empty line handler.
282282
EmptylineHandler *Emptyline = nullptr;
283283

284+
/// True to avoid tearing down the lexer etc on EOF
285+
bool IncrementalProcessing = false;
286+
284287
public:
285288
/// The kind of translation unit we are processing.
286289
const TranslationUnitKind TUKind;
@@ -1925,14 +1928,11 @@ class Preprocessor {
19251928
void recomputeCurLexerKind();
19261929

19271930
/// Returns true if incremental processing is enabled
1928-
bool isIncrementalProcessingEnabled() const {
1929-
return getLangOpts().IncrementalExtensions;
1930-
}
1931+
bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
19311932

19321933
/// Enables the incremental processing
19331934
void enableIncrementalProcessing(bool value = true) {
1934-
// FIXME: Drop this interface.
1935-
const_cast<LangOptions &>(getLangOpts()).IncrementalExtensions = value;
1935+
IncrementalProcessing = value;
19361936
}
19371937

19381938
/// 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
@@ -545,7 +545,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
545545
Result.startToken();
546546
CurLexer->BufferPtr = EndPos;
547547

548-
if (isIncrementalProcessingEnabled()) {
548+
if (getLangOpts().IncrementalExtensions) {
549549
CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_repl_input_end);
550550
Result.setAnnotationEndLoc(Result.getLocation());
551551
Result.setAnnotationValue(nullptr);

clang/lib/Lex/Preprocessor.cpp

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

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

clang/lib/Parse/Parser.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,11 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
623623
Sema::ModuleImportState &ImportState) {
624624
DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
625625

626+
// Skip over the EOF token, flagging end of previous input for incremental
627+
// processing
628+
if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
629+
ConsumeToken();
630+
626631
Result = nullptr;
627632
switch (Tok.getKind()) {
628633
case tok::annot_pragma_unused:
@@ -714,7 +719,8 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
714719

715720
// Late template parsing can begin.
716721
Actions.SetLateTemplateParser(LateTemplateParserCallback, nullptr, this);
717-
Actions.ActOnEndOfTranslationUnit();
722+
if (!PP.isIncrementalProcessingEnabled())
723+
Actions.ActOnEndOfTranslationUnit();
718724
//else don't tell Sema that we ended parsing: more input might come.
719725
return true;
720726

@@ -1039,7 +1045,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
10391045
ConsumeToken();
10401046
return nullptr;
10411047
}
1042-
if (PP.isIncrementalProcessingEnabled() &&
1048+
if (getLangOpts().IncrementalExtensions &&
10431049
!isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
10441050
return ParseTopLevelStmtDecl();
10451051

0 commit comments

Comments
 (0)