]> granicus.if.org Git - clang/commitdiff
- Move static function IsNonPragmaNonMacroLexer into Preprocessor.h.
authorTed Kremenek <kremenek@apple.com>
Wed, 19 Nov 2008 00:46:18 +0000 (00:46 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 19 Nov 2008 00:46:18 +0000 (00:46 +0000)
- Add variants of IsNonPragmaNonMacroLexer to accept an IncludeMacroStack entry
  (simplifies some uses).
- Use IsNonPragmaNonMacroLexer in Preprocessor::LookupFile.

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@59574 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Preprocessor.h
lib/Lex/PPDirectives.cpp
lib/Lex/PPLexerChange.cpp

index 999ba3b4f3db0c6a1f609f12c520840fd42d8be8..a95837653f377e973789a9114792e7bc4dbc1592 100644 (file)
@@ -598,6 +598,23 @@ 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);
index 07c5f8ea68e74284bfec94a86e9dfbe82a8756ea..cee2f406cdbc6bc71cf25b0c2108fdacf962e875 100644 (file)
@@ -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 (CurLexer && !CurLexer->Is_PragmaLexer) {
+  if (IsNonPragmaNonMacroLexer()) {
     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 (ISEntry.TheLexer && !ISEntry.TheLexer->Is_PragmaLexer) {
+    if (IsNonPragmaNonMacroLexer(ISEntry)) {
       if ((CurFileEnt = 
            SourceMgr.getFileEntryForLoc(ISEntry.TheLexer->getFileLoc())))
         if ((FE = HeaderInfo.LookupSubframeworkHeader(FilenameStart,
index 87330983d658ff5b0bf9d1084bac9a8db825a75e..c16abf43130633cebbf55fcf7db655b4dd7f6b72 100644 (file)
@@ -25,28 +25,19 @@ 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(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 +82,7 @@ void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
                                             const DirectoryLookup *CurDir) {
     
   // Add the current lexer to the include stack.
-  if (CurLexer || CurTokenLexer)
+  if (CurPPLexer || CurTokenLexer)
     PushIncludeMacroStack();
 
   CurLexer.reset(TheLexer);