ASTUnit.h revision 31b87d8006d4863dd9b17e515ac720941efc38e3
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 "clang/Basic/SourceManager.h"
18#include "llvm/ADT/OwningPtr.h"
19#include <string>
20
21namespace clang {
22  class FileManager;
23  class FileEntry;
24  class SourceManager;
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  Diagnostic                       &Diags;
36  SourceManager                     SourceMgr;
37  llvm::OwningPtr<HeaderSearch>     HeaderInfo;
38  llvm::OwningPtr<TargetInfo>       Target;
39  llvm::OwningPtr<Preprocessor>     PP;
40  llvm::OwningPtr<ASTContext>       Ctx;
41
42  ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
43  ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
44  ASTUnit(Diagnostic &_Diag);
45
46public:
47  ~ASTUnit();
48
49  const SourceManager &getSourceManager() const { return SourceMgr; }
50        SourceManager &getSourceManager()       { return SourceMgr; }
51
52  const Preprocessor &getPreprocessor() const { return *PP.get(); }
53        Preprocessor &getPreprocessor()       { return *PP.get(); }
54
55  const ASTContext &getASTContext() const { return *Ctx.get(); }
56        ASTContext &getASTContext()       { return *Ctx.get(); }
57
58  const Diagnostic &getDiagnostic() const { return Diags; }
59        Diagnostic &getDiagnostic()       { return Diags; }
60
61  FileManager &getFileManager();
62  const std::string &getOriginalSourceFileName();
63
64  /// \brief Create a ASTUnit from a PCH file.
65  ///
66  /// \param Filename - The PCH file to load.
67  ///
68  /// \param Diags - The Diagnostic implementation to use.
69  ///
70  /// \param FileMgr - The FileManager to use.
71  ///
72  /// \param ErrMsg - Error message to report if the PCH file could not be
73  /// loaded.
74  ///
75  /// \returns - The initialized ASTUnit or null if the PCH failed to load.
76  static ASTUnit *LoadFromPCHFile(const std::string &Filename,
77                                  Diagnostic &Diags,
78                                  FileManager &FileMgr,
79                                  std::string *ErrMsg = 0);
80};
81
82} // namespace clang
83
84#endif
85