Fixes https://bugs.llvm.org/show_bug.cgi?id=33574
Differential Revision: https://reviews.llvm.org/D34882
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@307134
91177308-0d34-0410-b5e6-
96231b3b80d8
/// which implicitly adds the builtin defines etc.
void EnterMainSourceFile();
+ /// \brief After parser warm-up, initialize the conditional stack from
+ /// the preamble.
+ void replayPreambleConditionalStack();
+
/// \brief Inform the preprocessor callbacks that processing is complete.
void EndSourceFile();
/// \brief Return true if we're in the top-level file, not in a \#include.
bool isInPrimaryFile() const;
- /// \brief Return true if we're in the main file (specifically, if we are 0
- /// (zero) levels deep \#include. This is used by the lexer to determine if
- /// it needs to generate errors about unterminated \#if directives.
- bool isInMainFile() const;
-
/// \brief Handle cases where the \#include name is expanded
/// from a macro as multiple tokens, which need to be glued together.
///
return true;
}
- if (PP->isRecordingPreamble() && !PP->isInMainFile()) {
+ if (PP->isRecordingPreamble() && PP->isInPrimaryFile()) {
PP->setRecordedPreambleConditionalStack(ConditionalStack);
ConditionalStack.clear();
}
});
}
-bool Preprocessor::isInMainFile() const {
- if (IsFileLexer())
- return IncludeMacroStack.size() == 0;
- return true;
-}
-
/// getCurrentLexer - Return the current file lexer being lexed from. Note
/// that this ignores any potentially active macro expansions and _Pragma
/// expansions going on at the time.
// Start parsing the predefines.
EnterSourceFile(FID, nullptr, SourceLocation());
+}
+void Preprocessor::replayPreambleConditionalStack() {
// Restore the conditional stack from the preamble, if there is one.
if (PreambleConditionalStack.isReplaying()) {
CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack());
// Prime the lexer look-ahead.
ConsumeToken();
+
+ PP.replayPreambleConditionalStack();
}
void Parser::LateTemplateParserCleanupCallback(void *P) {