r200573 - Track the currently-being-built submodule inside the preprocessor (rather than

Richard Smith richard-llvm at metafoo.co.uk
Fri Jan 31 12:47:45 PST 2014


Author: rsmith
Date: Fri Jan 31 14:47:44 2014
New Revision: 200573

URL: http://llvm.org/viewvc/llvm-project?rev=200573&view=rev
Log:
Track the currently-being-built submodule inside the preprocessor (rather than
just storing a flag indicating if there was one), and include it in the 'end of
module' annotation. No functionality change.

Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PPLexerChange.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=200573&r1=200572&r2=200573&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Jan 31 14:47:44 2014
@@ -286,25 +286,26 @@ class Preprocessor : public RefCountedBa
     CLK_LexAfterModuleImport
   } CurLexerKind;
 
-  /// \brief True if the current lexer is for a submodule.
-  bool CurIsSubmodule;
+  /// \brief If the current lexer is for a submodule that is being built, this
+  /// is that submodule.
+  Module *CurSubmodule;
 
   /// \brief Keeps track of the stack of files currently
   /// \#included, and macros currently being expanded from, not counting
   /// CurLexer/CurTokenLexer.
   struct IncludeStackInfo {
     enum CurLexerKind     CurLexerKind;
-    bool                  IsSubmodule;
+    Module                *TheSubmodule;
     Lexer                 *TheLexer;
     PTHLexer              *ThePTHLexer;
     PreprocessorLexer     *ThePPLexer;
     TokenLexer            *TheTokenLexer;
     const DirectoryLookup *TheDirLookup;
 
-    IncludeStackInfo(enum CurLexerKind K, bool SM, Lexer *L, PTHLexer *P,
+    IncludeStackInfo(enum CurLexerKind K, Module *M, Lexer *L, PTHLexer *P,
                      PreprocessorLexer *PPL, TokenLexer *TL,
                      const DirectoryLookup *D)
-        : CurLexerKind(K), IsSubmodule(SM), TheLexer(L), ThePTHLexer(P),
+        : CurLexerKind(K), TheSubmodule(M), TheLexer(L), ThePTHLexer(P),
           ThePPLexer(PPL), TheTokenLexer(TL), TheDirLookup(D) {}
   };
   std::vector<IncludeStackInfo> IncludeMacroStack;
@@ -686,14 +687,14 @@ public:
   void EndSourceFile();
 
   /// \brief Add a source file to the top of the include stack and
-  /// start lexing tokens from it instead of the current buffer. 
+  /// start lexing tokens from it instead of the current buffer.
   ///
-  /// Emit an error and don't enter the file on error.
-  void EnterSourceFile(FileID CurFileID, const DirectoryLookup *Dir,
-                       SourceLocation Loc, bool IsSubmodule = false);
+  /// Emits a diagnostic, doesn't enter the file, and returns true on error.
+  bool EnterSourceFile(FileID CurFileID, const DirectoryLookup *Dir,
+                       SourceLocation Loc);
 
   /// \brief Add a Macro to the top of the include stack and start lexing
-  /// tokens from it instead of the current buffer. 
+  /// tokens from it instead of the current buffer.
   ///
   /// \param Args specifies the tokens input to a function-like macro.
   /// \param ILEnd specifies the location of the ')' for a function-like macro
@@ -1317,7 +1318,7 @@ private:
 
   void PushIncludeMacroStack() {
     IncludeMacroStack.push_back(IncludeStackInfo(CurLexerKind,
-                                                 CurIsSubmodule,
+                                                 CurSubmodule,
                                                  CurLexer.take(),
                                                  CurPTHLexer.take(),
                                                  CurPPLexer,
@@ -1332,8 +1333,8 @@ private:
     CurPPLexer = IncludeMacroStack.back().ThePPLexer;
     CurTokenLexer.reset(IncludeMacroStack.back().TheTokenLexer);
     CurDirLookup  = IncludeMacroStack.back().TheDirLookup;
+    CurSubmodule = IncludeMacroStack.back().TheSubmodule;
     CurLexerKind = IncludeMacroStack.back().CurLexerKind;
-    CurIsSubmodule = IncludeMacroStack.back().IsSubmodule;
     IncludeMacroStack.pop_back();
   }
 
@@ -1435,13 +1436,11 @@ private:
 
   /// \brief Add a lexer to the top of the include stack and
   /// start lexing tokens from it instead of the current buffer.
-  void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir,
-                                bool IsSubmodule = false);
+  void EnterSourceFileWithLexer(Lexer *TheLexer, const DirectoryLookup *Dir);
 
   /// \brief Add a lexer to the top of the include stack and
   /// start getting tokens from it using the PTH cache.
-  void EnterSourceFileWithPTH(PTHLexer *PL, const DirectoryLookup *Dir,
-                              bool IsSubmodule = false);
+  void EnterSourceFileWithPTH(PTHLexer *PL, const DirectoryLookup *Dir);
 
   /// \brief Set the FileID for the preprocessor predefines.
   void setPredefinesFileID(FileID FID) {

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=200573&r1=200572&r2=200573&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Jan 31 14:47:44 2014
@@ -1660,14 +1660,18 @@ void Preprocessor::HandleIncludeDirectiv
   }
 
   // If all is good, enter the new file!
-  EnterSourceFile(FID, CurDir, FilenameTok.getLocation(),
-                  static_cast<bool>(BuildingModule));
+  if (EnterSourceFile(FID, CurDir, FilenameTok.getLocation()))
+    return;
 
   // If we're walking into another part of the same module, let the parser
   // know that any future declarations are within that other submodule.
-  if (BuildingModule)
+  if (BuildingModule) {
+    assert(!CurSubmodule && "should not have marked this as a module yet");
+    CurSubmodule = BuildingModule.getModule();
+
     EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_begin,
-                         BuildingModule.getModule());
+                         CurSubmodule);
+  }
 }
 
 /// HandleIncludeNextDirective - Implements \#include_next.

Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=200573&r1=200572&r2=200573&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Fri Jan 31 14:47:44 2014
@@ -68,8 +68,8 @@ PreprocessorLexer *Preprocessor::getCurr
 
 /// EnterSourceFile - Add a source file to the top of the include stack and
 /// start lexing tokens from it instead of the current buffer.
-void Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
-                                   SourceLocation Loc, bool IsSubmodule) {
+bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
+                                   SourceLocation Loc) {
   assert(!CurTokenLexer && "Cannot #include a file inside a macro!");
   ++NumEnteredSourceFiles;
 
@@ -78,8 +78,8 @@ void Preprocessor::EnterSourceFile(FileI
 
   if (PTH) {
     if (PTHLexer *PL = PTH->CreateLexer(FID)) {
-      EnterSourceFileWithPTH(PL, CurDir, IsSubmodule);
-      return;
+      EnterSourceFileWithPTH(PL, CurDir);
+      return false;
     }
   }
   
@@ -91,7 +91,7 @@ void Preprocessor::EnterSourceFile(FileI
     SourceLocation FileStart = SourceMgr.getLocForStartOfFile(FID);
     Diag(Loc, diag::err_pp_error_opening_file)
       << std::string(SourceMgr.getBufferName(FileStart)) << "";
-    return;
+    return true;
   }
 
   if (isCodeCompletionEnabled() &&
@@ -101,16 +101,14 @@ void Preprocessor::EnterSourceFile(FileI
         CodeCompletionFileLoc.getLocWithOffset(CodeCompletionOffset);
   }
 
-  EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir,
-                           IsSubmodule);
-  return;
+  EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir);
+  return false;
 }
 
 /// EnterSourceFileWithLexer - Add a source file to the top of the include stack
 ///  and start lexing tokens from it instead of the current buffer.
 void Preprocessor::EnterSourceFileWithLexer(Lexer *TheLexer,
-                                            const DirectoryLookup *CurDir,
-                                            bool IsSubmodule) {
+                                            const DirectoryLookup *CurDir) {
 
   // Add the current lexer to the include stack.
   if (CurPPLexer || CurTokenLexer)
@@ -119,7 +117,7 @@ void Preprocessor::EnterSourceFileWithLe
   CurLexer.reset(TheLexer);
   CurPPLexer = TheLexer;
   CurDirLookup = CurDir;
-  CurIsSubmodule = IsSubmodule;
+  CurSubmodule = 0;
   if (CurLexerKind != CLK_LexAfterModuleImport)
     CurLexerKind = CLK_Lexer;
   
@@ -136,8 +134,7 @@ void Preprocessor::EnterSourceFileWithLe
 /// EnterSourceFileWithPTH - Add a source file to the top of the include stack
 /// and start getting tokens from it using the PTH cache.
 void Preprocessor::EnterSourceFileWithPTH(PTHLexer *PL,
-                                          const DirectoryLookup *CurDir,
-                                          bool IsSubmodule) {
+                                          const DirectoryLookup *CurDir) {
 
   if (CurPPLexer || CurTokenLexer)
     PushIncludeMacroStack();
@@ -145,7 +142,7 @@ void Preprocessor::EnterSourceFileWithPT
   CurDirLookup = CurDir;
   CurPTHLexer.reset(PL);
   CurPPLexer = CurPTHLexer.get();
-  CurIsSubmodule = IsSubmodule;
+  CurSubmodule = 0;
   if (CurLexerKind != CLK_LexAfterModuleImport)
     CurLexerKind = CLK_PTHLexer;
   
@@ -371,16 +368,15 @@ bool Preprocessor::HandleEndOfFile(Token
     if (Callbacks && !isEndOfMacro && CurPPLexer)
       ExitedFID = CurPPLexer->getFileID();
 
-    // If this file corresponded to a submodule, notify the parser that we've
-    // left that submodule.
-    bool LeavingSubmodule = CurIsSubmodule && CurLexer;
+    bool LeavingSubmodule = CurSubmodule && CurLexer;
     if (LeavingSubmodule) {
+      // Notify the parser that we've left the module.
       const char *EndPos = getCurLexerEndPos();
       Result.startToken();
       CurLexer->BufferPtr = EndPos;
       CurLexer->FormTokenWithChars(Result, EndPos, tok::annot_module_end);
       Result.setAnnotationEndLoc(Result.getLocation());
-      Result.setAnnotationValue(0);
+      Result.setAnnotationValue(CurSubmodule);
     }
 
     // We're done with the #included file.

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=200573&r1=200572&r2=200573&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Jan 31 14:47:44 2014
@@ -67,7 +67,7 @@ Preprocessor::Preprocessor(IntrusiveRefC
       CodeComplete(0), CodeCompletionFile(0), CodeCompletionOffset(0),
       LastTokenWasAt(false), ModuleImportExpectsIdentifier(false),
       CodeCompletionReached(0), SkipMainFilePreamble(0, true), CurPPLexer(0),
-      CurDirLookup(0), CurLexerKind(CLK_Lexer), CurIsSubmodule(false),
+      CurDirLookup(0), CurLexerKind(CLK_Lexer), CurSubmodule(0),
       Callbacks(0), MacroArgCache(0), Record(0), MIChainHead(0), MICache(0),
       DeserialMIChainHead(0) {
   OwnsHeaderSearch = OwnsHeaders;





More information about the cfe-commits mailing list