[cfe-commits] r38784 - in /cfe/cfe/trunk/Driver: PrintPreprocessedOutput.cpp clang.cpp clang.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:24:35 PDT 2007


Author: sabre
Date: Wed Jul 11 11:24:35 2007
New Revision: 38784

URL: http://llvm.org/viewvc/llvm-project?rev=38784&view=rev
Log:
Fix -E mode to enter the main file *after* -E mode configures the preprocessor.

Modified:
    cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp
    cfe/cfe/trunk/Driver/clang.cpp
    cfe/cfe/trunk/Driver/clang.h

Modified: cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=38784&r1=38783&r2=38784&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/cfe/trunk/Driver/PrintPreprocessedOutput.cpp Wed Jul 11 11:24:35 2007
@@ -362,7 +362,8 @@
 
 /// DoPrintPreprocessedInput - This implements -E mode.
 ///
-void clang::DoPrintPreprocessedInput(Preprocessor &PP, LangOptions &Options) {
+void clang::DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP,
+                                     LangOptions &Options) {
   if (EnableCommentOutput)          // -C specified?
     Options.KeepComments = 1;
   if (EnableMacroCommentOutput)     // -CC specified?
@@ -381,6 +382,12 @@
   
   PP.AddPragmaHandler(0, new UnknownPragmaHandler("#pragma"));
   PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC"));
+
+  // After we have configured the preprocessor, enter the main file.
+  
+  // Start parsing the specified input file.
+  PP.EnterSourceFile(MainFileID, 0, true);
+  
   do {
     PrevTok = Tok;
     PP.Lex(Tok);

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=38784&r1=38783&r2=38784&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:24:35 2007
@@ -649,6 +649,24 @@
   // Set up keywords.
   PP.AddKeywords();
   
+  // Figure out where to get and map in the main file.
+  unsigned MainFileID = 0;
+  if (InputFilename != "-") {
+    const FileEntry *File = FileMgr.getFile(InputFilename);
+    if (File) MainFileID = SourceMgr.createFileID(File, SourceLocation());
+    if (MainFileID == 0) {
+      std::cerr << "Error reading '" << InputFilename << "'!\n";
+      return 1;
+    }
+  } else {
+    SourceBuffer *SB = SourceBuffer::getSTDIN();
+    if (SB) MainFileID = SourceMgr.createFileIDForMemBuffer(SB);
+    if (MainFileID == 0) {
+      std::cerr << "Error reading standard input!  Empty?\n";
+      return 1;
+    }
+  }
+  
   // Now that we have emitted the predefined macros, #includes, etc into
   // PrologMacros, preprocess it to populate the initial preprocessor state.
   {
@@ -673,29 +691,11 @@
     // Once we've read this, we're done.
   }
   
-  unsigned MainFileID = 0;
-  if (InputFilename != "-") {
-    const FileEntry *File = FileMgr.getFile(InputFilename);
-    if (File) MainFileID = SourceMgr.createFileID(File, SourceLocation());
-    if (MainFileID == 0) {
-      std::cerr << "Error reading '" << InputFilename << "'!\n";
-      return 1;
-    }
-  } else {
-    SourceBuffer *SB = SourceBuffer::getSTDIN();
-    if (SB) MainFileID = SourceMgr.createFileIDForMemBuffer(SB);
-    if (MainFileID == 0) {
-      std::cerr << "Error reading standard input!  Empty?\n";
-      return 1;
-    }
-  }
-  
-  // Start parsing the specified input file.
-  PP.EnterSourceFile(MainFileID, 0, true);
-  
   switch (ProgAction) {
   case RunPreprocessorOnly: {        // Just lex as fast as we can, no output.
     LexerToken Tok;
+    // Start parsing the specified input file.
+    PP.EnterSourceFile(MainFileID, 0, true);
     do {
       PP.Lex(Tok);
     } while (Tok.getKind() != tok::eof);
@@ -703,11 +703,13 @@
   }
     
   case PrintPreprocessedInput:       // -E mode.
-    DoPrintPreprocessedInput(PP, Options);
+    DoPrintPreprocessedInput(MainFileID, PP, Options);
     break;
                   
   case DumpTokens: {                 // Token dump mode.
     LexerToken Tok;
+    // Start parsing the specified input file.
+    PP.EnterSourceFile(MainFileID, 0, true);
     do {
       PP.Lex(Tok);
       PP.DumpToken(Tok, true);

Modified: cfe/cfe/trunk/Driver/clang.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.h?rev=38784&r1=38783&r2=38784&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.h (original)
+++ cfe/cfe/trunk/Driver/clang.h Wed Jul 11 11:24:35 2007
@@ -20,7 +20,8 @@
 class LangOptions;
 
 /// DoPrintPreprocessedInput - Implement -E mode.
-void DoPrintPreprocessedInput(Preprocessor &PP, LangOptions &Options);
+void DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP,
+                              LangOptions &Options);
 
 }  // end namespace clang
 }  // end namespace llvm





More information about the cfe-commits mailing list