[cfe-commits] r90311 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp

Daniel Dunbar daniel at zuster.org
Wed Dec 2 00:44:17 PST 2009


Author: ddunbar
Date: Wed Dec  2 02:44:16 2009
New Revision: 90311

URL: http://llvm.org/viewvc/llvm-project?rev=90311&view=rev
Log:
Fix ASTUnit::getOriginalSourceFileName() when using ASTUnit's derived from
source files.

Modified:
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=90311&r1=90310&r2=90311&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Wed Dec  2 02:44:16 2009
@@ -54,6 +54,9 @@
   // FIXME: This is temporary; eventually, CIndex will always do this.
   bool                              OnlyLocalDecls;
   
+  /// The name of the original source file used to generate this ASTUnit.
+  std::string OriginalSourceFile;
+
   // Critical optimization when using clang_getCursor().
   ASTLocation LastLoc;
   

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=90311&r1=90310&r2=90311&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Dec  2 02:44:16 2009
@@ -95,10 +95,11 @@
 } // anonymous namespace
 
 const std::string &ASTUnit::getOriginalSourceFileName() {
-  return dyn_cast<PCHReader>(Ctx->getExternalSource())->getOriginalSourceFile();
+  return OriginalSourceFile;
 }
 
 const std::string &ASTUnit::getPCHFileName() {
+  assert(Ctx->getExternalSource() && "Not an ASTUnit from a PCH file!");
   return dyn_cast<PCHReader>(Ctx->getExternalSource())->getFileName();
 }
 
@@ -138,6 +139,8 @@
     return NULL;
   }
 
+  AST->OriginalSourceFile = Reader->getOriginalSourceFile();
+
   // PCH loaded successfully. Now create the preprocessor.
 
   // Get information about the target being compiled for.
@@ -230,6 +233,8 @@
   // FIXME: Use the provided diagnostic client.
   AST.reset(new ASTUnit());
 
+  AST->OriginalSourceFile = Clang.getFrontendOpts().Inputs[0].second;
+
   // Create a file manager object to provide access to and cache the filesystem.
   Clang.setFileManager(&AST->getFileManager());
 





More information about the cfe-commits mailing list