- Move static function IsNonPragmaNonMacroLexer into Preprocessor.h.
- Add variants of IsNonPragmaNonMacroLexer to accept an IncludeMacroStack entry
(simplifies some uses).
- Use IsNonPragmaNonMacroLexer in Preprocessor::LookupFile.
- Add 'FileID' to PreprocessorLexer, and have Preprocessor query this fileid
when looking up the FileEntry for a file
Performance testing of -Eonly on Cocoa.h shows no performance regression because
of this patch.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59666 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp
index 8ddd62f..eebdd1e 100644
--- a/lib/Lex/Lexer.cpp
+++ b/lib/Lex/Lexer.cpp
@@ -63,7 +63,8 @@
/// outlive it, so it doesn't take ownership of either of them.
Lexer::Lexer(SourceLocation fileloc, Preprocessor &pp,
const char *BufStart, const char *BufEnd)
- : PreprocessorLexer(&pp), FileLoc(fileloc), Features(pp.getLangOptions()) {
+ : PreprocessorLexer(&pp, fileloc), FileLoc(fileloc),
+ Features(pp.getLangOptions()) {
SourceManager &SourceMgr = PP->getSourceManager();
unsigned InputFileID = SourceMgr.getPhysicalLoc(FileLoc).getFileID();
@@ -110,7 +111,9 @@
Lexer::Lexer(SourceLocation fileloc, const LangOptions &features,
const char *BufStart, const char *BufEnd,
const llvm::MemoryBuffer *FromFile)
- : PreprocessorLexer(0), FileLoc(fileloc), Features(features) {
+ : PreprocessorLexer(), FileLoc(fileloc),
+ Features(features) {
+
Is_PragmaLexer = false;
InitCharacterInfo();
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index ced7673..a1216b1 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -303,8 +303,8 @@
// info about where the current file is.
const FileEntry *CurFileEnt = 0;
if (!FromDir) {
- SourceLocation FileLoc = getCurrentFileLexer()->getFileLoc();
- CurFileEnt = SourceMgr.getFileEntryForLoc(FileLoc);
+ unsigned FileID = getCurrentFileLexer()->getFileID();
+ CurFileEnt = SourceMgr.getFileEntryForID(FileID);
}
// Do a standard file entry lookup.
@@ -317,8 +317,8 @@
// 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 (CurLexer && !CurLexer->Is_PragmaLexer) {
- if ((CurFileEnt = SourceMgr.getFileEntryForLoc(CurLexer->getFileLoc())))
+ if (IsNonPragmaNonMacroLexer()) {
+ if ((CurFileEnt = SourceMgr.getFileEntryForID(CurPPLexer->getFileID())))
if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart, FilenameEnd,
CurFileEnt)))
return FE;
@@ -326,9 +326,9 @@
for (unsigned i = 0, e = IncludeMacroStack.size(); i != e; ++i) {
IncludeStackInfo &ISEntry = IncludeMacroStack[e-i-1];
- if (ISEntry.TheLexer && !ISEntry.TheLexer->Is_PragmaLexer) {
+ if (IsNonPragmaNonMacroLexer(ISEntry)) {
if ((CurFileEnt =
- SourceMgr.getFileEntryForLoc(ISEntry.TheLexer->getFileLoc())))
+ SourceMgr.getFileEntryForID(ISEntry.ThePPLexer->getFileID())))
if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart,
FilenameEnd, CurFileEnt)))
return FE;
diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp
index 8733098..3a2ed65 100644
--- a/lib/Lex/PPLexerChange.cpp
+++ b/lib/Lex/PPLexerChange.cpp
@@ -25,27 +25,17 @@
// 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(CurLexer.get(), CurPPLexer))
+ if (IsNonPragmaNonMacroLexer())
return IncludeMacroStack.empty();
// If there are any stacked lexers, we're in a #include.
- assert(IsNonPragmaNonMacroLexer(IncludeMacroStack[0].TheLexer,
- IncludeMacroStack[0].ThePPLexer) &&
+ assert(IsNonPragmaNonMacroLexer(IncludeMacroStack[0]) &&
"Top level include stack isn't our primary lexer?");
for (unsigned i = 1, e = IncludeMacroStack.size(); i != e; ++i)
- if (IsNonPragmaNonMacroLexer(IncludeMacroStack[i].TheLexer,
- IncludeMacroStack[i].ThePPLexer))
+ if (IsNonPragmaNonMacroLexer(IncludeMacroStack[i]))
return false;
return true;
}
@@ -91,7 +81,7 @@
const DirectoryLookup *CurDir) {
// Add the current lexer to the include stack.
- if (CurLexer || CurTokenLexer)
+ if (CurPPLexer || CurTokenLexer)
PushIncludeMacroStack();
CurLexer.reset(TheLexer);
@@ -212,6 +202,7 @@
// We're done with the #included file.
CurLexer.reset();
+ CurPPLexer = 0;
// This is the end of the top-level file. If the diag::pp_macro_not_used
// diagnostic is enabled, look for macros that have not been used.
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index 8062102..d22285c 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -18,8 +18,8 @@
PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc,
const Token *TokArray, unsigned NumToks)
- : PreprocessorLexer(&pp), FileLoc(fileloc), Tokens(TokArray),
- NumTokens(NumToks), CurToken(0) {
+ : PreprocessorLexer(&pp, fileloc), FileLoc(fileloc),
+ Tokens(TokArray), NumTokens(NumToks), CurToken(0) {
assert (Tokens[NumTokens-1].is(tok::eof));
--NumTokens;
diff --git a/lib/Lex/PreprocessorLexer.cpp b/lib/Lex/PreprocessorLexer.cpp
index 20bce41..2ce181e 100644
--- a/lib/Lex/PreprocessorLexer.cpp
+++ b/lib/Lex/PreprocessorLexer.cpp
@@ -18,6 +18,9 @@
using namespace clang;
+PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L)
+ : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()) {}
+
PreprocessorLexer::~PreprocessorLexer() {}
void PreprocessorLexer::Diag(SourceLocation Loc, unsigned DiagID,