diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index a95837653f37..999ba3b4f3db 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -598,23 +598,6 @@ private: bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir); - - static bool IsNonPragmaNonMacroLexer(const Lexer* L, - const PreprocessorLexer* P) { - if (L) - return !L->isPragmaLexer(); - else - return P != 0; - } - - static bool IsNonPragmaNonMacroLexer(const IncludeStackInfo& I) { - return IsNonPragmaNonMacroLexer(I.TheLexer, I.ThePPLexer); - } - - bool IsNonPragmaNonMacroLexer() const { - return IsNonPragmaNonMacroLexer(CurLexer.get(), CurPPLexer); - } - //===--------------------------------------------------------------------===// // Caching stuff. void CachingLex(Token &Result); diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index cee2f406cdbc..07c5f8ea68e7 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -317,7 +317,7 @@ const FileEntry *Preprocessor::LookupFile(const char *FilenameStart, // Otherwise, see if this is a subframework header. If so, this is relative // to one of the headers on the #include stack. Walk the list of the current // headers on the #include stack and pass them to HeaderInfo. - if (IsNonPragmaNonMacroLexer()) { + if (CurLexer && !CurLexer->Is_PragmaLexer) { if ((CurFileEnt = SourceMgr.getFileEntryForLoc(CurLexer->getFileLoc()))) if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart, FilenameEnd, CurFileEnt))) @@ -326,7 +326,7 @@ const FileEntry *Preprocessor::LookupFile(const char *FilenameStart, for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) { IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1]; - if (IsNonPragmaNonMacroLexer(ISEntry)) { + if (ISEntry.TheLexer && !ISEntry.TheLexer->Is_PragmaLexer) { if ((CurFileEnt = SourceMgr.getFileEntryForLoc(ISEntry.TheLexer->getFileLoc()))) if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart, diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index c16abf431306..87330983d658 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -25,19 +25,28 @@ PPCallbacks::~PPCallbacks() {} // Miscellaneous Methods. //===----------------------------------------------------------------------===// +static inline bool IsNonPragmaNonMacroLexer(const Lexer* L, + const PreprocessorLexer* P) { + if (L) + return !L->isPragmaLexer(); + else + return P != 0; +} + /// isInPrimaryFile - Return true if we're in the top-level file, not in a /// #include. This looks through macro expansions and active _Pragma lexers. bool Preprocessor::isInPrimaryFile() const { - if (IsNonPragmaNonMacroLexer()) + if (IsNonPragmaNonMacroLexer(CurLexer.get(), CurPPLexer)) return IncludeMacroStack.empty(); // If there are any stacked lexers, we're in a #include. - assert(IsNonPragmaNonMacroLexer(IncludeMacroStack[0]) && + assert(IsNonPragmaNonMacroLexer(IncludeMacroStack[0].TheLexer, + IncludeMacroStack[0].ThePPLexer) && "Top level include stack isn't our primary lexer?"); for (unsigned i = 1, e = IncludeMacroStack.size(); i != e; ++i) - if (IsNonPragmaNonMacroLexer(IncludeMacroStack[i])) + if (IsNonPragmaNonMacroLexer(IncludeMacroStack[i].TheLexer, + IncludeMacroStack[i].ThePPLexer)) return false; - return true; } @@ -82,7 +91,7 @@ void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *CurDir) { // Add the current lexer to the include stack. - if (CurPPLexer || CurTokenLexer) + if (CurLexer || CurTokenLexer) PushIncludeMacroStack(); CurLexer.reset(TheLexer);