Skip to content

Re-apply "[Parse] Split incremental-extensions" #66446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clang/include/clang/Lex/Preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ class Preprocessor {
/// Empty line handler.
EmptylineHandler *Emptyline = nullptr;

/// True to avoid tearing down the lexer etc on EOF
bool IncrementalProcessing = false;

public:
/// The kind of translation unit we are processing.
const TranslationUnitKind TUKind;
Expand Down Expand Up @@ -1910,14 +1913,11 @@ class Preprocessor {
void recomputeCurLexerKind();

/// Returns true if incremental processing is enabled
bool isIncrementalProcessingEnabled() const {
return getLangOpts().IncrementalExtensions;
}
bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }

/// Enables the incremental processing
void enableIncrementalProcessing(bool value = true) {
// FIXME: Drop this interface.
const_cast<LangOptions &>(getLangOpts()).IncrementalExtensions = value;
IncrementalProcessing = value;
}

/// Specify the point at which code-completion will be performed.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Lex/PPLexerChange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) {
Result.startToken();
CurLexer->BufferPtr = EndPos;

if (isIncrementalProcessingEnabled()) {
if (getLangOpts().IncrementalExtensions) {
CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_repl_input_end);
Result.setAnnotationEndLoc(Result.getLocation());
Result.setAnnotationValue(nullptr);
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Lex/Preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ Preprocessor::Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
Ident_AbnormalTermination = nullptr;
}

// Default incremental processing to -fincremental-extensions, clients can
// override with `enableIncrementalProcessing` if desired.
IncrementalProcessing = LangOpts.IncrementalExtensions;

// If using a PCH where a #pragma hdrstop is expected, start skipping tokens.
if (usingPCHWithPragmaHdrStop())
SkippingUntilPragmaHdrStop = true;
Expand Down
7 changes: 6 additions & 1 deletion clang/lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result,
Sema::ModuleImportState &ImportState) {
DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);

// Skip over the EOF token, flagging end of previous input for incremental
// processing
if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
ConsumeToken();

Result = nullptr;
switch (Tok.getKind()) {
case tok::annot_pragma_unused:
Expand Down Expand Up @@ -1038,7 +1043,7 @@ Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
ConsumeToken();
return nullptr;
}
if (PP.isIncrementalProcessingEnabled() &&
if (getLangOpts().IncrementalExtensions &&
!isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
return ParseTopLevelStmtDecl();

Expand Down