ASTUnit.h revision e19944c93961b7618f4f3f3185f698f46369ea54
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  bool                              tempFile;
42
43  ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
44  ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
45  ASTUnit(Diagnostic &_Diag);
46
47public:
48  ~ASTUnit();
49
50  const SourceManager &getSourceManager() const { return SourceMgr; }
51        SourceManager &getSourceManager()       { return SourceMgr; }
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; }
60        Diagnostic &getDiagnostic()       { return Diags; }
61
62  FileManager &getFileManager();
63  const std::string &getOriginalSourceFileName();
64  const std::string &getPCHFileName();
65
66  void unlinkTemporaryFile() { tempFile = true; }
67
68  /// \brief Create a ASTUnit from a PCH file.
69  ///
70  /// \param Filename - The PCH file to load.
71  ///
72  /// \param Diags - The Diagnostic implementation to use.
73  ///
74  /// \param FileMgr - The FileManager to use.
75  ///
76  /// \param ErrMsg - Error message to report if the PCH file could not be
77  /// loaded.
78  ///
79  /// \returns - The initialized ASTUnit or null if the PCH failed to load.
80  static ASTUnit *LoadFromPCHFile(const std::string &Filename,
81                                  Diagnostic &Diags,
82                                  FileManager &FileMgr,
83                                  std::string *ErrMsg = 0);
84};
85
86} // namespace clang
87
88#endif
89