ASTUnit.h revision 1eb4433ac451dc16f4133a88af2d002ac26c58ef
1//===--- ASTUnit.h - ASTUnit utility ----------------------------*- C++ -*-===//
2//
3//                     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  FileManager &getFileManager();
63  const std::string &getOriginalSourceFileName();
64
65  /// \brief Create a ASTUnit from a PCH file.
66  ///
67  /// \param Filename PCH filename
68  ///
69  /// \param FileMgr The FileManager to use
70  ///
71  /// \param ErrMsg Error message to report if the PCH file could not be loaded
72  ///
73  /// \returns the initialized ASTUnit or NULL if the PCH failed to load
74  static ASTUnit *LoadFromPCHFile(const std::string &Filename,
75                                  FileManager &FileMgr,
76                                  std::string *ErrMsg = 0);
77};
78
79} // namespace clang
80
81#endif
82