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

Daniel Dunbar daniel at zuster.org
Wed Dec 2 13:47:44 PST 2009


Author: ddunbar
Date: Wed Dec  2 15:47:43 2009
New Revision: 90349

URL: http://llvm.org/viewvc/llvm-project?rev=90349&view=rev
Log:
ASTUnit: Explicitly track whether the ASTUnit came from an actual AST or not.

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=90349&r1=90348&r2=90349&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Wed Dec  2 15:47:43 2009
@@ -53,7 +53,10 @@
   // that come from the AST itself, not from included precompiled headers.
   // FIXME: This is temporary; eventually, CIndex will always do this.
   bool                              OnlyLocalDecls;
-  
+
+  // Track whether the main file was loaded from an AST or not.
+  bool MainFileIsAST;
+
   /// The name of the original source file used to generate this ASTUnit.
   std::string OriginalSourceFile;
 
@@ -64,9 +67,11 @@
   ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
 
 public:
-  ASTUnit(DiagnosticClient *diagClient = NULL);
+  ASTUnit(bool MainFileIsAST, DiagnosticClient *diagClient = NULL);
   ~ASTUnit();
 
+  bool isMainFileAST() const { return MainFileIsAST; }
+
   const SourceManager &getSourceManager() const { return SourceMgr; }
         SourceManager &getSourceManager()       { return SourceMgr; }
 

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

==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Dec  2 15:47:43 2009
@@ -34,7 +34,10 @@
 #include "llvm/System/Path.h"
 using namespace clang;
 
-ASTUnit::ASTUnit(DiagnosticClient *diagClient) : tempFile(false) {
+ASTUnit::ASTUnit(bool _MainFileIsAST,
+                 DiagnosticClient *diagClient)
+  : tempFile(false), MainFileIsAST(_MainFileIsAST)
+{
   Diags.setClient(diagClient ? diagClient : new TextDiagnosticBuffer());
 }
 ASTUnit::~ASTUnit() {
@@ -99,7 +102,7 @@
 }
 
 const std::string &ASTUnit::getPCHFileName() {
-  assert(Ctx->getExternalSource() && "Not an ASTUnit from a PCH file!");
+  assert(isMainFileAST() && "Not an ASTUnit from a PCH file!");
   return dyn_cast<PCHReader>(Ctx->getExternalSource())->getFileName();
 }
 
@@ -108,7 +111,7 @@
                                   DiagnosticClient *diagClient,
                                   bool OnlyLocalDecls,
                                   bool UseBumpAllocator) {
-  llvm::OwningPtr<ASTUnit> AST(new ASTUnit(diagClient));
+  llvm::OwningPtr<ASTUnit> AST(new ASTUnit(true, diagClient));
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->HeaderInfo.reset(new HeaderSearch(AST->getFileManager()));
 
@@ -230,7 +233,7 @@
   // Create the AST unit.
   //
   // FIXME: Use the provided diagnostic client.
-  AST.reset(new ASTUnit());
+  AST.reset(new ASTUnit(false));
 
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->OriginalSourceFile = Clang.getFrontendOpts().Inputs[0].second;





More information about the cfe-commits mailing list