r179144 - [frontend] When preprocessing, turn implicit module imports into @imports.

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Apr 9 18:53:46 PDT 2013


Author: akirtzidis
Date: Tue Apr  9 20:53:46 2013
New Revision: 179144

URL: http://llvm.org/viewvc/llvm-project?rev=179144&view=rev
Log:
[frontend] When preprocessing, turn implicit module imports into @imports.

part of rdar://13610250

Added:
    cfe/trunk/test/Preprocessor/pp-modules.c
Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=179144&r1=179143&r2=179144&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Tue Apr  9 20:53:46 2013
@@ -127,6 +127,15 @@ public:
   virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
                            SrcMgr::CharacteristicKind FileType,
                            FileID PrevFID);
+  virtual void InclusionDirective(SourceLocation HashLoc,
+                                  const Token &IncludeTok,
+                                  StringRef FileName,
+                                  bool IsAngled,
+                                  CharSourceRange FilenameRange,
+                                  const FileEntry *File,
+                                  StringRef SearchPath,
+                                  StringRef RelativePath,
+                                  const Module *Imported);
   virtual void Ident(SourceLocation Loc, const std::string &str);
   virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
                              const std::string &Str);
@@ -305,6 +314,26 @@ void PrintPPOutputPPCallbacks::FileChang
   }
 }
 
+void PrintPPOutputPPCallbacks::InclusionDirective(SourceLocation HashLoc,
+                                                  const Token &IncludeTok,
+                                                  StringRef FileName,
+                                                  bool IsAngled,
+                                                  CharSourceRange FilenameRange,
+                                                  const FileEntry *File,
+                                                  StringRef SearchPath,
+                                                  StringRef RelativePath,
+                                                  const Module *Imported) {
+  // When preprocessing, turn implicit imports into @imports.
+  // FIXME: This is a stop-gap until a more comprehensive "preprocessing with
+  // modules" solution is introduced.
+  if (Imported) {
+    startNewLineIfNeeded();
+    MoveToLine(HashLoc);
+    OS << "@import " << Imported->getFullModuleName() << ";"
+       << " /* clang -E: implicit import for \"" << File->getName() << "\" */";
+  }
+}
+
 /// Ident - Handle #ident directives when read by the preprocessor.
 ///
 void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, const std::string &S) {

Added: cfe/trunk/test/Preprocessor/pp-modules.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pp-modules.c?rev=179144&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/pp-modules.c (added)
+++ cfe/trunk/test/Preprocessor/pp-modules.c Tue Apr  9 20:53:46 2013
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -x objective-c %s -F %S/../Modules/Inputs -E -o - | FileCheck %s
+
+// CHECK: int bar();
+int bar();
+// CHECK: @import Module; /* clang -E: implicit import for "{{.*Headers[/\\]Module.h}}" */
+#include <Module/Module.h>
+// CHECK: int foo();
+int foo();
+// CHECK: @import Module; /* clang -E: implicit import for "{{.*Headers[/\\]Module.h}}" */
+#include <Module/Module.h>





More information about the cfe-commits mailing list