ASTUnit.h revision b85bca2676b433ae555db09de4dd2823ff13b856
1c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//===--- ASTUnit.h - ASTUnit utility ----------------------------*- C++ -*-===// 2c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// 3c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// ASTUnit utility class. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H 15#define LLVM_CLANG_FRONTEND_ASTUNIT_H 16 17#include "llvm/ADT/OwningPtr.h" 18#include <string> 19 20namespace clang { 21 class FileManager; 22 class FileEntry; 23 class SourceManager; 24 class DiagnosticClient; 25 class Diagnostic; 26 class HeaderSearch; 27 class TargetInfo; 28 class Preprocessor; 29 class ASTContext; 30 class Decl; 31 32/// \brief Utility class for loading a ASTContext from a PCH file. 33/// 34class ASTUnit { 35 llvm::OwningPtr<SourceManager> SourceMgr; 36 llvm::OwningPtr<DiagnosticClient> DiagClient; 37 llvm::OwningPtr<Diagnostic> Diags; 38 llvm::OwningPtr<HeaderSearch> HeaderInfo; 39 llvm::OwningPtr<TargetInfo> Target; 40 llvm::OwningPtr<Preprocessor> PP; 41 llvm::OwningPtr<ASTContext> Ctx; 42 43 ASTUnit(const ASTUnit&); // do not implement 44 ASTUnit &operator=(const ASTUnit &); // do not implement 45 ASTUnit(); 46 47public: 48 ~ASTUnit(); 49 50 const SourceManager &getSourceManager() const { return *SourceMgr.get(); } 51 SourceManager &getSourceManager() { return *SourceMgr.get(); } 52 53 const Preprocessor &getPreprocessor() const { return *PP.get(); } 54 Preprocessor &getPreprocessor() { return *PP.get(); } 55 56 const ASTContext &getASTContext() const { return *Ctx.get(); } 57 ASTContext &getASTContext() { return *Ctx.get(); } 58 59 const Diagnostic &getDiagnostic() const { return *Diags.get(); } 60 Diagnostic &getDiagnostic() { return *Diags.get(); } 61 62 /// \brief Create a ASTUnit from a PCH file. 63 /// 64 /// \param Filename PCH filename 65 /// 66 /// \param FileMgr The FileManager to use 67 /// 68 /// \param ErrMsg Error message to report if the PCH file could not be loaded 69 /// 70 /// \returns the initialized ASTUnit or NULL if the PCH failed to load 71 static ASTUnit *LoadFromPCHFile(const std::string &Filename, 72 FileManager &FileMgr, 73 std::string *ErrMsg = 0); 74}; 75 76} // namespace clang 77 78#endif 79