ASTUnit.h revision 0853a02c3b04d96a3c432b883e403175c954cd81
1#ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H
2#define LLVM_CLANG_FRONTEND_ASTUNIT_H
3
4#include "llvm/ADT/OwningPtr.h"
5#include <string>
6
7namespace clang {
8  class FileManager;
9  class FileEntry;
10  class SourceManager;
11  class DiagnosticClient;
12  class Diagnostic;
13  class HeaderSearch;
14  class TargetInfo;
15  class Preprocessor;
16  class ASTContext;
17  class Decl;
18
19/// \brief Utility class for loading a ASTContext from a PCH file.
20///
21class ASTUnit {
22  llvm::OwningPtr<SourceManager>    SourceMgr;
23  llvm::OwningPtr<DiagnosticClient> DiagClient;
24  llvm::OwningPtr<Diagnostic>       Diags;
25  llvm::OwningPtr<HeaderSearch>     HeaderInfo;
26  llvm::OwningPtr<TargetInfo>       Target;
27  llvm::OwningPtr<Preprocessor>     PP;
28  llvm::OwningPtr<ASTContext>       Ctx;
29
30  ASTUnit(const ASTUnit&); // do not implement
31  ASTUnit &operator=(const ASTUnit &); // do not implement
32  ASTUnit();
33
34public:
35  ~ASTUnit();
36
37  const SourceManager &getSourceManager() const { return *SourceMgr.get(); }
38        SourceManager &getSourceManager()       { return *SourceMgr.get(); }
39
40  const Preprocessor &getPreprocessor() const { return *PP.get(); }
41        Preprocessor &getPreprocessor()       { return *PP.get(); }
42
43  const ASTContext &getASTContext() const { return *Ctx.get(); }
44        ASTContext &getASTContext()       { return *Ctx.get(); }
45
46  /// \brief Create a ASTUnit from a PCH file.
47  ///
48  /// \param Filename PCH filename
49  ///
50  /// \param FileMgr The FileManager to use
51  ///
52  /// \param ErrMsg Error message to report if the PCH file could not be loaded
53  ///
54  /// \returns the initialized ASTUnit or NULL if the PCH failed to load
55  static ASTUnit *LoadFromPCHFile(const std::string &Filename,
56                                  FileManager &FileMgr,
57                                  std::string *ErrMsg = 0);
58};
59
60} // namespace clang
61
62#endif
63