]> granicus.if.org Git - clang/commitdiff
For PPCallbacks::InclusionDirective() add a parameter for the module, whenever
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 29 Sep 2012 01:06:10 +0000 (01:06 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 29 Sep 2012 01:06:10 +0000 (01:06 +0000)
an inclusion directive was automatically turned into a module import, and
PPCallbacks::moduleImport() for an explicit module import.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164874 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/PPCallbacks.h
include/clang/Lex/PreprocessingRecord.h
lib/Frontend/DependencyFile.cpp
lib/Frontend/DependencyGraph.cpp
lib/Lex/PPDirectives.cpp
lib/Lex/PreprocessingRecord.cpp
lib/Lex/Preprocessor.cpp
lib/Rewrite/Frontend/InclusionRewriter.cpp
tools/libclang/Indexing.cpp

index ec63ff3d035e6aa6fdcf35a02ffcb6909807e8bc..8ba02cc4ea23046dd0317565bdee764304311e6f 100644 (file)
@@ -16,6 +16,7 @@
 #define LLVM_CLANG_LEX_PPCALLBACKS_H
 
 #include "clang/Lex/DirectoryLookup.h"
+#include "clang/Lex/ModuleLoader.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/DiagnosticIDs.h"
 #include "llvm/ADT/StringRef.h"
@@ -99,9 +100,6 @@ public:
   /// \param File The actual file that may be included by this inclusion 
   /// directive.
   ///
-  /// \param EndLoc The location of the last token within the inclusion
-  /// directive.
-  ///
   /// \param SearchPath Contains the search path which was used to find the file
   /// in the file system. If the file was found via an absolute include path,
   /// SearchPath will be empty. For framework includes, the SearchPath and
@@ -113,6 +111,10 @@ public:
   ///
   /// \param RelativePath The path relative to SearchPath, at which the include
   /// file was found. This is equal to FileName except for framework includes.
+  ///
+  /// \param Imported The module, whenever an inclusion directive was
+  /// automatically turned into a module import or null otherwise.
+  ///
   virtual void InclusionDirective(SourceLocation HashLoc,
                                   const Token &IncludeTok,
                                   StringRef FileName,
@@ -120,7 +122,23 @@ public:
                                   CharSourceRange FilenameRange,
                                   const FileEntry *File,
                                   StringRef SearchPath,
-                                  StringRef RelativePath) {
+                                  StringRef RelativePath,
+                                  const Module *Imported) {
+  }
+
+  /// \brief Callback invoked whenever there was an explicit module-import
+  /// syntax.
+  ///
+  /// \param ImportLoc The location of import directive token.
+  ///
+  /// \param Path The identifiers (and their locations) of the module
+  /// "path", e.g., "std.vector" would be split into "std" and "vector".
+  ///
+  /// \param Imported The imported module; can be null if importing failed.
+  ///
+  virtual void moduleImport(SourceLocation ImportLoc,
+                            ModuleIdPath Path,
+                            const Module *Imported) {
   }
 
   /// \brief Callback invoked when the end of the main file is reached.
@@ -272,11 +290,21 @@ public:
                                   CharSourceRange FilenameRange,
                                   const FileEntry *File,
                                   StringRef SearchPath,
-                                  StringRef RelativePath) {
+                                  StringRef RelativePath,
+                                  const Module *Imported) {
     First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
-                              FilenameRange, File, SearchPath, RelativePath);
+                              FilenameRange, File, SearchPath, RelativePath,
+                              Imported);
     Second->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
-                               FilenameRange, File, SearchPath, RelativePath);
+                               FilenameRange, File, SearchPath, RelativePath,
+                               Imported);
+  }
+
+  virtual void moduleImport(SourceLocation ImportLoc,
+                            ModuleIdPath Path,
+                            const Module *Imported) {
+    First->moduleImport(ImportLoc, Path, Imported);
+    Second->moduleImport(ImportLoc, Path, Imported);
   }
 
   virtual void EndOfMainFile() {
index ffff04d0bbe3f2aa821811b796c517e067a53294..c76a148af315c384ef396efb618a633d23eb77a6 100644 (file)
@@ -600,7 +600,8 @@ namespace clang {
                                     CharSourceRange FilenameRange,
                                     const FileEntry *File,
                                     StringRef SearchPath,
-                                    StringRef RelativePath);
+                                    StringRef RelativePath,
+                                    const Module *Imported);
     virtual void If(SourceLocation Loc, SourceRange ConditionRange);
     virtual void Elif(SourceLocation Loc, SourceRange ConditionRange,
                       SourceLocation IfLoc);
index adc96604e7e4b534165b29982637c822d5e433df..53ea8befbc09fff0c846344df87b6c7db8f74ad8 100644 (file)
@@ -62,7 +62,8 @@ public:
                                   CharSourceRange FilenameRange,
                                   const FileEntry *File,
                                   StringRef SearchPath,
-                                  StringRef RelativePath);
+                                  StringRef RelativePath,
+                                  const Module *Imported);
 
   virtual void EndOfMainFile() {
     OutputDependencyFile();
@@ -135,7 +136,8 @@ void DependencyFileCallback::InclusionDirective(SourceLocation HashLoc,
                                                 CharSourceRange FilenameRange,
                                                 const FileEntry *File,
                                                 StringRef SearchPath,
-                                                StringRef RelativePath) {
+                                                StringRef RelativePath,
+                                                const Module *Imported) {
   if (!File) {
     if (AddMissingHeaderDeps)
       AddFilename(FileName);
index 7fb4ad72506a563300dbf473951da006a4b44549..28d9c5d320e25b05e276d14c0f7dafa6bb0e21dd 100644 (file)
@@ -54,7 +54,8 @@ public:
                                   CharSourceRange FilenameRange,
                                   const FileEntry *File,
                                   StringRef SearchPath,
-                                  StringRef RelativePath);
+                                  StringRef RelativePath,
+                                  const Module *Imported);
 
   virtual void EndOfMainFile() {
     OutputGraphFile();
@@ -75,7 +76,8 @@ void DependencyGraphCallback::InclusionDirective(SourceLocation HashLoc,
                                                  CharSourceRange FilenameRange,
                                                  const FileEntry *File,
                                                  StringRef SearchPath,
-                                                 StringRef RelativePath) {
+                                                 StringRef RelativePath,
+                                                 const Module *Imported) {
   if (!File)
     return;
   
index 5cff2fc48f392f6e684c0e92a6d18dc4e226036d..23cbef63edf4d9511c57c1a647ce8cfe41cbf7da 100644 (file)
@@ -1314,6 +1314,8 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
     return;
   }
 
+  CharSourceRange FilenameRange
+    = CharSourceRange::getCharRange(FilenameTok.getLocation(), CharEnd);
   StringRef OriginalFilename = Filename;
   bool isAngled =
     GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename);
@@ -1384,10 +1386,13 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
       }
     }
     
-    // Notify the callback object that we've seen an inclusion directive.
-    Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled,
-              CharSourceRange::getCharRange(FilenameTok.getLocation(), CharEnd),
-                                  File, SearchPath, RelativePath);
+    if (!SuggestedModule) {
+      // Notify the callback object that we've seen an inclusion directive.
+      Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled,
+                                    FilenameRange, File,
+                                    SearchPath, RelativePath,
+                                    /*ImportedModule=*/0);
+    }
   }
   
   if (File == 0) {
@@ -1485,8 +1490,24 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
            "the imported module is different than the suggested one");
     
     // If this header isn't part of the module we're building, we're done.
-    if (!BuildingImportedModule && Imported)
+    if (!BuildingImportedModule && Imported) {
+      if (Callbacks) {
+        Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled,
+                                      FilenameRange, File,
+                                      SearchPath, RelativePath, Imported);
+      }
       return;
+    }
+  }
+
+  if (Callbacks && SuggestedModule) {
+    // We didn't notify the callback object that we've seen an inclusion
+    // directive before. Now that we are parsing the include normally and not
+    // turning it to a module import, notify the callback object.
+    Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled,
+                                  FilenameRange, File,
+                                  SearchPath, RelativePath,
+                                  /*ImportedModule=*/0);
   }
   
   // The #included file will be considered to be a system header if either it is
index 40250f67862b04a79ab3a750514a798f52e85e3e..4f4ff4b51e43fd1a4772e88cdec4f48626e2178e 100644 (file)
@@ -392,7 +392,8 @@ void PreprocessingRecord::InclusionDirective(
     CharSourceRange FilenameRange,
     const FileEntry *File,
     StringRef SearchPath,
-    StringRef RelativePath) {
+    StringRef RelativePath,
+    const Module *Imported) {
   InclusionDirective::InclusionKind Kind = InclusionDirective::Include;
   
   switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) {
index 9fa3aabe4c8f31e29c3ef29cb957b97f487fe178..872cda390aa44b26ceec83f9cdb10c8ff7233d9b 100644 (file)
@@ -641,10 +641,14 @@ void Preprocessor::LexAfterModuleImport(Token &Result) {
   }
 
   // If we have a non-empty module path, load the named module.
-  if (!ModuleImportPath.empty())
-    (void)TheModuleLoader.loadModule(ModuleImportLoc, ModuleImportPath,
-                                     Module::MacrosVisible,
-                                     /*IsIncludeDirective=*/false);
+  if (!ModuleImportPath.empty()) {
+    Module *Imported = TheModuleLoader.loadModule(ModuleImportLoc,
+                                                  ModuleImportPath,
+                                                  Module::MacrosVisible,
+                                                  /*IsIncludeDirective=*/false);
+    if (Callbacks)
+      Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported);
+  }
 }
 
 void Preprocessor::addCommentHandler(CommentHandler *Handler) {
index 9c3c43bb514e473a23aad46bf5a6a03149b98efa..cecc8672c5c2097e4c12e736c06c59b81486a181 100644 (file)
@@ -60,7 +60,8 @@ private:
                                   CharSourceRange FilenameRange,
                                   const FileEntry *File,
                                   StringRef SearchPath,
-                                  StringRef RelativePath);
+                                  StringRef RelativePath,
+                                  const Module *Imported);
   void WriteLineInfo(const char *Filename, int Line,
                      SrcMgr::CharacteristicKind FileType,
                      StringRef EOL, StringRef Extra = StringRef());
@@ -155,7 +156,8 @@ void InclusionRewriter::InclusionDirective(SourceLocation HashLoc,
                                            CharSourceRange /*FilenameRange*/,
                                            const FileEntry * /*File*/,
                                            StringRef /*SearchPath*/,
-                                           StringRef /*RelativePath*/) {
+                                           StringRef /*RelativePath*/,
+                                           const Module */*Imported*/) {
   assert(LastInsertedFileChange == FileChanges.end() && "Another inclusion "
     "directive was found before the previous one was processed");
   std::pair<FileChangeMap::iterator, bool> p = FileChanges.insert(
index 7e65483769b621fa2049e052d2301e4992ea3d8d..c4fba968492fc34db80f1d24785a81e59730fa10 100644 (file)
@@ -71,7 +71,8 @@ public:
                                   CharSourceRange FilenameRange,
                                   const FileEntry *File,
                                   StringRef SearchPath,
-                                  StringRef RelativePath) {
+                                  StringRef RelativePath,
+                                  const Module *Imported) {
     bool isImport = (IncludeTok.is(tok::identifier) &&
             IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
     IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled);