Hello,
I'm working on a change that will enable a client to build an AST from
an input file, and then, based on the contents of that AST, add
additional tokens to be parsed. Richard Smith recommended adding a
feature to the parser to do this, but it turns out that there is
something quite close already: the IncrementalProcessing option, added
in r152914.
The enclosed patch moves the IncrementalProcessing from a Preprocessor
field--which is only accessible once the preprocessor is actually
built--into the PreprocessorOptions which is available to other
interfaces which don't expose the preprocessor itself, such as the
compiler invocation.
There is only minimal testing of this feature inside
FrontendActionTest.cpp, but I have updated that as well. I will add
tests to exercise it more thoroughly once I know that this direction
is acceptable. The test itself uses two terms, calling it both
"IncrementalParsing" and "IncrementalProcessing". Not sure if that is
intentional or not.
Sterling
[with cc's to original contributor of the IncrmentalProcessing Axel Naumann]
Index: include/clang/Lex/Preprocessor.h
===================================================================
--- include/clang/Lex/Preprocessor.h (revision 229431)
+++ include/clang/Lex/Preprocessor.h (working copy)
@@ -211,10 +211,6 @@
/// with this preprocessor.
std::vector<CommentHandler *> CommentHandlers;
- /// \brief True if we want to ignore EOF token and continue later on (thus
- /// avoid tearing the Lexer and etc. down).
- bool IncrementalProcessing;
-
/// The kind of translation unit we are processing.
TranslationUnitKind TUKind;
@@ -952,14 +948,6 @@
/// CurTokenLexer pointers.
void recomputeCurLexerKind();
- /// \brief Returns true if incremental processing is enabled
- bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
-
- /// \brief Enables the incremental processing
- void enableIncrementalProcessing(bool value = true) {
- IncrementalProcessing = value;
- }
-
/// \brief Specify the point at which code-completion will be performed.
///
/// \param File the file in which code completion should occur. If
Index: include/clang/Lex/PreprocessorOptions.h
===================================================================
--- include/clang/Lex/PreprocessorOptions.h (revision 229431)
+++ include/clang/Lex/PreprocessorOptions.h (working copy)
@@ -55,6 +55,10 @@
/// definitions and expansions.
unsigned DetailedRecord : 1;
+ /// \brief Whether to ignore EOF token and continue later on (thus
+ /// avoid tearing the Lexer and etc. down).
+ unsigned IncrementalProcessing : 1;
+
/// The implicit PCH included at the start of the translation unit, or empty.
std::string ImplicitPCHInclude;
@@ -141,6 +145,7 @@
public:
PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
+ IncrementalProcessing(false),
DisablePCHValidation(false),
AllowPCHWithCompilerErrors(false),
DumpDeserializedPCHDecls(false),
Index: lib/Lex/PPLexerChange.cpp
===================================================================
--- lib/Lex/PPLexerChange.cpp (revision 229431)
+++ lib/Lex/PPLexerChange.cpp (working copy)
@@ -18,6 +18,7 @@
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/LexDiagnostic.h"
#include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/PreprocessorOptions.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -438,7 +439,7 @@
Result.setLocation(Result.getLocation().getLocWithOffset(-1));
}
- if (!isIncrementalProcessingEnabled())
+ if (!PPOpts->IncrementalProcessing)
// We're done with lexing.
CurLexer.reset();
} else {
@@ -447,7 +448,7 @@
CurPTHLexer.reset();
}
- if (!isIncrementalProcessingEnabled())
+ if (!PPOpts->IncrementalProcessing)
CurPPLexer = nullptr;
if (TUKind == TU_Complete) {
Index: lib/Lex/Preprocessor.cpp
===================================================================
--- lib/Lex/Preprocessor.cpp (revision 229431)
+++ lib/Lex/Preprocessor.cpp (working copy)
@@ -67,8 +67,7 @@
TheModuleLoader(TheModuleLoader), ExternalSource(nullptr),
Identifiers(opts, IILookup),
PragmaHandlers(new PragmaNamespace(StringRef())),
- IncrementalProcessing(false), TUKind(TUKind),
- CodeComplete(nullptr), CodeCompletionFile(nullptr),
+ TUKind(TUKind), CodeComplete(nullptr), CodeCompletionFile(nullptr),
CodeCompletionOffset(0), LastTokenWasAt(false),
ModuleImportExpectsIdentifier(false), CodeCompletionReached(0),
MainFileDir(nullptr), SkipMainFilePreamble(0, true), CurPPLexer(nullptr),
Index: lib/Parse/Parser.cpp
===================================================================
--- lib/Parse/Parser.cpp (revision 229431)
+++ lib/Parse/Parser.cpp (working copy)
@@ -16,6 +16,7 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclTemplate.h"
+#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Parse/ParseDiagnostic.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/ParsedTemplate.h"
@@ -524,7 +525,7 @@
// Skip over the EOF token, flagging end of previous input for incremental
// processing
- if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
+ if (PP.getPreprocessorOpts().IncrementalProcessing && Tok.is(tok::eof))
ConsumeToken();
Result = DeclGroupPtrTy();
@@ -549,11 +550,12 @@
case tok::eof:
// Late template parsing can begin.
if (getLangOpts().DelayedTemplateParsing)
- Actions.SetLateTemplateParser(LateTemplateParserCallback,
- PP.isIncrementalProcessingEnabled() ?
- LateTemplateParserCleanupCallback : nullptr,
- this);
- if (!PP.isIncrementalProcessingEnabled())
+ Actions.SetLateTemplateParser(
+ LateTemplateParserCallback,
+ PP.getPreprocessorOpts().IncrementalProcessing ?
+ LateTemplateParserCleanupCallback : nullptr,
+ this);
+ if (!PP.getPreprocessorOpts().IncrementalProcessing)
Actions.ActOnEndOfTranslationUnit();
//else don't tell Sema that we ended parsing: more input might come.
return true;
Index: unittests/Frontend/FrontendActionTest.cpp
===================================================================
--- unittests/Frontend/FrontendActionTest.cpp (revision 229431)
+++ unittests/Frontend/FrontendActionTest.cpp (working copy)
@@ -37,7 +37,7 @@
virtual bool BeginSourceFileAction(CompilerInstance &ci, StringRef filename) {
if (EnableIncrementalProcessing)
- ci.getPreprocessor().enableIncrementalProcessing();
+ ci.getPreprocessorOpts().IncrementalProcessing = true;
return ASTFrontendAction::BeginSourceFileAction(ci, filename);
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits