1f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===--- ASTUnit.h - ASTUnit utility ----------------------------*- C++ -*-===//
2f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
3f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//                     The LLVM Compiler Infrastructure
4f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
5f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// This file is distributed under the University of Illinois Open Source
6f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// License. See LICENSE.TXT for details.
7f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
8f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
9f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
10f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot// ASTUnit utility class.
11f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//
12f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot//===----------------------------------------------------------------------===//
13f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
14f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H
15f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#define LLVM_CLANG_FRONTEND_ASTUNIT_H
16f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
17f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang-c/Index.h"
18f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/AST/ASTContext.h"
19f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Basic/FileSystemOptions.h"
20f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Basic/LangOptions.h"
21f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Basic/SourceManager.h"
22f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Basic/TargetOptions.h"
23f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Lex/HeaderSearchOptions.h"
24f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Lex/ModuleLoader.h"
25f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Lex/PreprocessingRecord.h"
26f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Sema/CodeCompleteConsumer.h"
27f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "clang/Serialization/ASTBitCodes.h"
28f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/IntrusiveRefCntPtr.h"
29f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/SmallVector.h"
30f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/ADT/StringMap.h"
31f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include "llvm/Support/MD5.h"
32f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <cassert>
33f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <memory>
34f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <string>
35f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <sys/types.h>
36f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <utility>
37f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#include <vector>
38f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
39f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace llvm {
40f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class MemoryBuffer;
41f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
42f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
43f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace clang {
44f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass Sema;
45f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ASTContext;
46f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ASTReader;
47f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass CompilerInvocation;
48f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass CompilerInstance;
49f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass Decl;
50f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass DiagnosticsEngine;
51f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass FileEntry;
52f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass FileManager;
53f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass HeaderSearch;
54f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass InputKind;
55f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass MemoryBufferCache;
56f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass Preprocessor;
57f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass PreprocessorOptions;
58f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass PCHContainerOperations;
59f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass PCHContainerReader;
60f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass TargetInfo;
61f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass FrontendAction;
62f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ASTDeserializationListener;
63f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
64f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotnamespace vfs {
65f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass FileSystem;
66f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot}
67f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
68f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot/// \brief Utility class for loading a ASTContext from an AST file.
69f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot///
70f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotclass ASTUnit {
71f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
72f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  struct StandaloneFixIt {
73f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::pair<unsigned, unsigned> RemoveRange;
74f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::pair<unsigned, unsigned> InsertFromRange;
75f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::string CodeToInsert;
76f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool BeforePreviousInsertions;
77f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
78f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
79f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  struct StandaloneDiagnostic {
80f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unsigned ID;
81f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    DiagnosticsEngine::Level Level;
82f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::string Message;
83f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::string Filename;
84f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unsigned LocOffset;
85f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::vector<std::pair<unsigned, unsigned> > Ranges;
86f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::vector<StandaloneFixIt> FixIts;
87f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
88f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
89f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
90f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<LangOptions>            LangOpts;
91f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntrusiveRefCntPtr<DiagnosticsEngine>   Diagnostics;
92f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntrusiveRefCntPtr<FileManager>         FileMgr;
93f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntrusiveRefCntPtr<SourceManager>       SourceMgr;
94f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntrusiveRefCntPtr<MemoryBufferCache>   PCMCache;
95f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<HeaderSearch>           HeaderInfo;
96f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntrusiveRefCntPtr<TargetInfo>          Target;
97f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<Preprocessor>           PP;
98f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntrusiveRefCntPtr<ASTContext>          Ctx;
99f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<TargetOptions>          TargetOpts;
100f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<HeaderSearchOptions>    HSOpts;
101f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<PreprocessorOptions>    PPOpts;
102f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntrusiveRefCntPtr<ASTReader> Reader;
103f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool HadModuleLoaderFatalFailure;
104f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
105f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  struct ASTWriterData;
106f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<ASTWriterData> WriterData;
107f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
108f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  FileSystemOptions FileSystemOpts;
109f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
110f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The AST consumer that received information about the translation
111f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// unit as it was parsed or loaded.
112f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<ASTConsumer> Consumer;
113f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
114f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The semantic analysis object used to type-check the translation
115f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// unit.
116f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<Sema> TheSema;
117f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
118f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Optional owned invocation, just used to make the invocation used in
119f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// LoadFromCommandLine available.
120f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<CompilerInvocation> Invocation;
121f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
122f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Fake module loader: the AST unit doesn't need to load any modules.
123f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  TrivialModuleLoader ModuleLoader;
124f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
125f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // OnlyLocalDecls - when true, walking this AST should only visit declarations
126f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // that come from the AST itself, not from included precompiled headers.
127f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // FIXME: This is temporary; eventually, CIndex will always do this.
128f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool OnlyLocalDecls;
129f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
130f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Whether to capture any diagnostics produced.
131f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool CaptureDiagnostics;
132f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
133f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Track whether the main file was loaded from an AST or not.
134f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool MainFileIsAST;
135f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
136f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief What kind of translation unit this AST represents.
137f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  TranslationUnitKind TUKind;
138f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
139f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Whether we should time each operation.
140f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool WantTiming;
141f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
142f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Whether the ASTUnit should delete the remapped buffers.
143f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool OwnsRemappedFileBuffers;
144f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
145f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Track the top-level decls which appeared in an ASTUnit which was loaded
146f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// from a source file.
147f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  //
148f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // FIXME: This is just an optimization hack to avoid deserializing large parts
149f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // of a PCH file when using the Index library on an ASTUnit loaded from
150f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // source. In the long term we should make the Index library use efficient and
151f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // more scalable search mechanisms.
152f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::vector<Decl*> TopLevelDecls;
153f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
154f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Sorted (by file offset) vector of pairs of file offset/Decl.
155f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  typedef SmallVector<std::pair<unsigned, Decl *>, 64> LocDeclsTy;
156f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  typedef llvm::DenseMap<FileID, LocDeclsTy *> FileDeclsTy;
157f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
158f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Map from FileID to the file-level declarations that it contains.
159f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// The files and decls are only local (and non-preamble) ones.
160f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  FileDeclsTy FileDecls;
161f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
162f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// The name of the original source file used to generate this ASTUnit.
163f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::string OriginalSourceFile;
164f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
165f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The set of diagnostics produced when creating the preamble.
166f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SmallVector<StandaloneDiagnostic, 4> PreambleDiagnostics;
167f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
168f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The set of diagnostics produced when creating this
169f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// translation unit.
170f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
171f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
172f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The set of diagnostics produced when failing to parse, e.g. due
173f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// to failure to load the PCH.
174f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SmallVector<StoredDiagnostic, 4> FailedParseDiagnostics;
175f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
176f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The number of stored diagnostics that come from the driver
177f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// itself.
178f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
179f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Diagnostics that come from the driver are retained from one parse to
180f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// the next.
181f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned NumStoredDiagnosticsFromDriver;
182f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
183f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Counter that determines when we want to try building a
184f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// precompiled preamble.
185f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
186f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// If zero, we will never build a precompiled preamble. Otherwise,
187f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// it's treated as a counter that decrements each time we reparse
188f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// without the benefit of a precompiled preamble. When it hits 1,
189f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// we'll attempt to rebuild the precompiled header. This way, if
190f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// building the precompiled preamble fails, we won't try again for
191f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// some number of calls.
192f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned PreambleRebuildCounter;
193f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
194f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Cache pairs "filename - source location"
195f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
196f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Cache contains only source locations from preamble so it is
197f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// guaranteed that they stay valid when the SourceManager is recreated.
198f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This cache is used when loading preambule to increase performance
199f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// of that loading. It must be cleared when preamble is recreated.
200f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  llvm::StringMap<SourceLocation> PreambleSrcLocCache;
201f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
202f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
203f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class PreambleData {
204f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    const FileEntry *File;
205f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::vector<char> Buffer;
206f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    mutable unsigned NumLines;
207f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
208f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  public:
209f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    PreambleData() : File(nullptr), NumLines(0) { }
210f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
211f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void assign(const FileEntry *F, const char *begin, const char *end) {
212f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      File = F;
213f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Buffer.assign(begin, end);
214f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      NumLines = 0;
215f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
216f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
217f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void clear() { Buffer.clear(); File = nullptr; NumLines = 0; }
218f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
219f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    size_t size() const { return Buffer.size(); }
220f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool empty() const { return Buffer.empty(); }
221f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
222f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    const char *getBufferStart() const { return &Buffer[0]; }
223f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
224f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unsigned getNumLines() const {
225f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      if (NumLines)
226f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        return NumLines;
227f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      countLines();
228f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return NumLines;
229f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
230f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
231f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    SourceRange getSourceRange(const SourceManager &SM) const {
232f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      SourceLocation FileLoc = SM.getLocForStartOfFile(SM.getPreambleFileID());
233f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return SourceRange(FileLoc, FileLoc.getLocWithOffset(size()-1));
234f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
235f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
236f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  private:
237f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void countLines() const;
238f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
239f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
240f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const PreambleData &getPreambleData() const {
241f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return Preamble;
242f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
243f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
244f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Data used to determine if a file used in the preamble has been changed.
245f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  struct PreambleFileHash {
246f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// All files have size set.
247f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    off_t Size;
248f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
249f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Modification time is set for files that are on disk.  For memory
250f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// buffers it is zero.
251f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    time_t ModTime;
252f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
253f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// Memory buffers have MD5 instead of modification time.  We don't
254f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// compute MD5 for on-disk files because we hope that modification time is
255f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// enough to tell if the file was changed.
256f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm::MD5::MD5Result MD5;
257f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
258f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    static PreambleFileHash createForFile(off_t Size, time_t ModTime);
259f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    static PreambleFileHash
260f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    createForMemoryBuffer(const llvm::MemoryBuffer *Buffer);
261f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
262f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    friend bool operator==(const PreambleFileHash &LHS,
263f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                           const PreambleFileHash &RHS);
264f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
265f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    friend bool operator!=(const PreambleFileHash &LHS,
266f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                           const PreambleFileHash &RHS) {
267f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      return !(LHS == RHS);
268f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
269f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
270f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
271f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
272f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The contents of the preamble that has been precompiled to
273f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \c PreambleFile.
274f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  PreambleData Preamble;
275f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
276f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Whether the preamble ends at the start of a new line.
277f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
278f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Used to inform the lexer as to whether it's starting at the beginning of
279f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// a line after skipping the preamble.
280f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool PreambleEndsAtStartOfLine;
281f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
282f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Keeps track of the files that were used when computing the
283f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// preamble, with both their buffer size and their modification time.
284f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
285f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// If any of the files have changed from one compile to the next,
286f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// the preamble must be thrown away.
287f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  llvm::StringMap<PreambleFileHash> FilesInPreamble;
288f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
289f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief When non-NULL, this is the buffer used to store the contents of
290f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// the main file when it has been padded for use with the precompiled
291f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// preamble.
292f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<llvm::MemoryBuffer> SavedMainFileBuffer;
293f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
294f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief When non-NULL, this is the buffer used to store the
295f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// contents of the preamble when it has been padded to build the
296f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// precompiled preamble.
297f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<llvm::MemoryBuffer> PreambleBuffer;
298f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
299f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The number of warnings that occurred while parsing the preamble.
300f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
301f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This value will be used to restore the state of the \c DiagnosticsEngine
302f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// object when re-using the precompiled preamble. Note that only the
303f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// number of warnings matters, since we will not save the preamble
304f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// when any errors are present.
305f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned NumWarningsInPreamble;
306f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
307f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief A list of the serialization ID numbers for each of the top-level
308f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// declarations parsed within the precompiled preamble.
309f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::vector<serialization::DeclID> TopLevelDeclsInPreamble;
310f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
311f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Whether we should be caching code-completion results.
312f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool ShouldCacheCodeCompletionResults : 1;
313f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
314f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Whether to include brief documentation within the set of code
315f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// completions cached.
316f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool IncludeBriefCommentsInCodeCompletion : 1;
317f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
318f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief True if non-system source files should be treated as volatile
319f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// (likely to change while trying to use them).
320f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool UserFilesAreVolatile : 1;
321f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
322f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static void ConfigureDiags(IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
323f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                             ASTUnit &AST, bool CaptureDiagnostics);
324f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
325f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void TranslateStoredDiagnostics(FileManager &FileMgr,
326f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                  SourceManager &SrcMan,
327f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                      const SmallVectorImpl<StandaloneDiagnostic> &Diags,
328f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                            SmallVectorImpl<StoredDiagnostic> &Out);
329f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
330f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void clearFileLevelDecls();
331f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
332f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
333f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief A cached code-completion result, which may be introduced in one of
334f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// many different contexts.
335f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  struct CachedCodeCompletionResult {
336f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The code-completion string corresponding to this completion
337f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// result.
338f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    CodeCompletionString *Completion;
339f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
340f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief A bitmask that indicates which code-completion contexts should
341f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// contain this completion result.
342f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
343f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// The bits in the bitmask correspond to the values of
344f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// CodeCompleteContext::Kind. To map from a completion context kind to a
345f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// bit, shift 1 by that number of bits. Many completions can occur in
346f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// several different contexts.
347f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    uint64_t ShowInContexts;
348f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
349f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The priority given to this code-completion result.
350f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unsigned Priority;
351f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
352f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The libclang cursor kind corresponding to this code-completion
353f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// result.
354f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    CXCursorKind Kind;
355f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
356f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The availability of this code-completion result.
357f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    CXAvailabilityKind Availability;
358f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
359f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The simplified type class for a non-macro completion result.
360f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    SimplifiedTypeClass TypeClass;
361f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
362f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// \brief The type of a non-macro completion result, stored as a unique
363f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// integer used by the string map of cached completion types.
364f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ///
365f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// This value will be zero if the type is not known, or a unique value
366f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// determined by the formatted type string. Se \c CachedCompletionTypes
367f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    /// for more information.
368f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unsigned Type;
369f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
370f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
371f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Retrieve the mapping from formatted type names to unique type
372f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// identifiers.
373f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  llvm::StringMap<unsigned> &getCachedCompletionTypes() {
374f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CachedCompletionTypes;
375f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
376f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
377f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Retrieve the allocator used to cache global code completions.
378f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<GlobalCodeCompletionAllocator>
379f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getCachedCompletionAllocator() {
380f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CachedCompletionAllocator;
381f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
382f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
383f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  CodeCompletionTUInfo &getCodeCompletionTUInfo() {
384f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!CCTUInfo)
385f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      CCTUInfo = llvm::make_unique<CodeCompletionTUInfo>(
386f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          std::make_shared<GlobalCodeCompletionAllocator>());
387f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return *CCTUInfo;
388f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
389f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
390f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
391f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Allocator used to store cached code completions.
392f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<GlobalCodeCompletionAllocator> CachedCompletionAllocator;
393f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
394f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<CodeCompletionTUInfo> CCTUInfo;
395f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
396f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The set of cached code-completion results.
397f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::vector<CachedCodeCompletionResult> CachedCompletionResults;
398f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
399f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief A mapping from the formatted type name to a unique number for that
400f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// type, which is used for type equality comparisons.
401f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  llvm::StringMap<unsigned> CachedCompletionTypes;
402f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
403f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief A string hash of the top-level declaration and macro definition
404f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// names processed the last time that we reparsed the file.
405f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
406f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This hash value is used to determine when we need to refresh the
407f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// global code-completion cache.
408f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned CompletionCacheTopLevelHashValue;
409f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
410f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief A string hash of the top-level declaration and macro definition
411f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// names processed the last time that we reparsed the precompiled preamble.
412f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
413f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This hash value is used to determine when we need to refresh the
414f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// global code-completion cache after a rebuild of the precompiled preamble.
415f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned PreambleTopLevelHashValue;
416f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
417f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief The current hash value for the top-level declaration and macro
418f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// definition names
419f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned CurrentTopLevelHashValue;
420f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
421f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Bit used by CIndex to mark when a translation unit may be in an
422f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// inconsistent state, and is not safe to free.
423f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned UnsafeToFree : 1;
424f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
425f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Cache any "global" code-completion results, so that we can avoid
426f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// recomputing them with each completion.
427f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void CacheCodeCompletionResults();
428f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
429f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Clear out and deallocate
430f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void ClearCachedCompletionResults();
431f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
432f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ASTUnit(const ASTUnit &) = delete;
433f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void operator=(const ASTUnit &) = delete;
434f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
435f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  explicit ASTUnit(bool MainFileIsAST);
436f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
437f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool Parse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
438f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot             std::unique_ptr<llvm::MemoryBuffer> OverrideMainBuffer,
439f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot             IntrusiveRefCntPtr<vfs::FileSystem> VFS);
440f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
441f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  struct ComputedPreamble {
442f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    llvm::MemoryBuffer *Buffer;
443f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    std::unique_ptr<llvm::MemoryBuffer> Owner;
444f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    unsigned Size;
445f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    bool PreambleEndsAtStartOfLine;
446f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ComputedPreamble(llvm::MemoryBuffer *Buffer,
447f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                     std::unique_ptr<llvm::MemoryBuffer> Owner, unsigned Size,
448f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                     bool PreambleEndsAtStartOfLine)
449f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        : Buffer(Buffer), Owner(std::move(Owner)), Size(Size),
450f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot          PreambleEndsAtStartOfLine(PreambleEndsAtStartOfLine) {}
451f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
452f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ComputedPreamble ComputePreamble(CompilerInvocation &Invocation,
453f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                   unsigned MaxLines,
454f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                                   IntrusiveRefCntPtr<vfs::FileSystem> VFS);
455f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
456f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<llvm::MemoryBuffer> getMainBufferWithPrecompiledPreamble(
457f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::shared_ptr<PCHContainerOperations> PCHContainerOps,
458f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      const CompilerInvocation &PreambleInvocationIn,
459f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      IntrusiveRefCntPtr<vfs::FileSystem> VFS, bool AllowRebuild = true,
460f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      unsigned MaxLines = 0);
461f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void RealizeTopLevelDeclsFromPreamble();
462f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
463f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Transfers ownership of the objects (like SourceManager) from
464f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param CI to this ASTUnit.
465f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void transferASTDataFromCompilerInstance(CompilerInstance &CI);
466f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
467f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Allows us to assert that ASTUnit is not being used concurrently,
468f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// which is not supported.
469f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
470f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Clients should create instances of the ConcurrencyCheck class whenever
471f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// using the ASTUnit in a way that isn't intended to be concurrent, which is
472f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// just about any usage.
473f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Becomes a noop in release mode; only useful for debug mode checking.
474f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class ConcurrencyState {
475f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void *Mutex; // a llvm::sys::MutexImpl in debug;
476f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
477f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  public:
478f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ConcurrencyState();
479f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ~ConcurrencyState();
480f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
481f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void start();
482f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    void finish();
483f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
484f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ConcurrencyState ConcurrencyCheckValue;
485f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
486f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
487f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  class ConcurrencyCheck {
488f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ASTUnit &Self;
489f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
490f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  public:
491f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    explicit ConcurrencyCheck(ASTUnit &Self)
492f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      : Self(Self)
493f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    {
494f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Self.ConcurrencyCheckValue.start();
495f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
496f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    ~ConcurrencyCheck() {
497f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      Self.ConcurrencyCheckValue.finish();
498f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    }
499f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  };
500f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  friend class ConcurrencyCheck;
501f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
502f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ~ASTUnit();
503f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
504f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isMainFileAST() const { return MainFileIsAST; }
505f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
506f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isUnsafeToFree() const { return UnsafeToFree; }
507f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void setUnsafeToFree(bool Value) { UnsafeToFree = Value; }
508f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
509f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const DiagnosticsEngine &getDiagnostics() const { return *Diagnostics; }
510f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  DiagnosticsEngine &getDiagnostics()             { return *Diagnostics; }
511f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
512f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const SourceManager &getSourceManager() const { return *SourceMgr; }
513f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        SourceManager &getSourceManager()       { return *SourceMgr; }
514f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
515f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const Preprocessor &getPreprocessor() const { return *PP; }
516f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        Preprocessor &getPreprocessor()       { return *PP; }
517f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::shared_ptr<Preprocessor> getPreprocessorPtr() const { return PP; }
518f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
519f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const ASTContext &getASTContext() const { return *Ctx; }
520f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        ASTContext &getASTContext()       { return *Ctx; }
521f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
522f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void setASTContext(ASTContext *ctx) { Ctx = ctx; }
523f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void setPreprocessor(std::shared_ptr<Preprocessor> pp);
524f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
525f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool hasSema() const { return (bool)TheSema; }
526f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  Sema &getSema() const {
527f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(TheSema && "ASTUnit does not have a Sema object!");
528f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return *TheSema;
529f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
530f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
531f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const LangOptions &getLangOpts() const {
532f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(LangOpts && "ASTUnit does not have language options");
533f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return *LangOpts;
534f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
535f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
536f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const HeaderSearchOptions &getHeaderSearchOpts() const {
537f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(HSOpts && "ASTUnit does not have header search options");
538f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return *HSOpts;
539f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
540f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
541f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const PreprocessorOptions &getPreprocessorOpts() const {
542f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(PPOpts && "ASTUnit does not have preprocessor options");
543f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return *PPOpts;
544f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
545f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
546f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const FileManager &getFileManager() const { return *FileMgr; }
547f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot        FileManager &getFileManager()       { return *FileMgr; }
548f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
549f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
550f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
551f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  IntrusiveRefCntPtr<ASTReader> getASTReader() const;
552f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
553f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  StringRef getOriginalSourceFileName() {
554f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return OriginalSourceFile;
555f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
556f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
557f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ASTMutationListener *getASTMutationListener();
558f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ASTDeserializationListener *getDeserializationListener();
559f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
560f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
561f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
562f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool getOwnsRemappedFileBuffers() const { return OwnsRemappedFileBuffers; }
563f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void setOwnsRemappedFileBuffers(bool val) { OwnsRemappedFileBuffers = val; }
564f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
565f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  StringRef getMainFileName() const;
566f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
567f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief If this ASTUnit came from an AST file, returns the filename for it.
568f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  StringRef getASTFileName() const;
569f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
570f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  typedef std::vector<Decl *>::iterator top_level_iterator;
571f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
572f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  top_level_iterator top_level_begin() {
573f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
574f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!TopLevelDeclsInPreamble.empty())
575f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      RealizeTopLevelDeclsFromPreamble();
576f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return TopLevelDecls.begin();
577f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
578f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
579f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  top_level_iterator top_level_end() {
580f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
581f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (!TopLevelDeclsInPreamble.empty())
582f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      RealizeTopLevelDeclsFromPreamble();
583f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return TopLevelDecls.end();
584f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
585f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
586f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::size_t top_level_size() const {
587f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
588f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return TopLevelDeclsInPreamble.size() + TopLevelDecls.size();
589f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
590f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
591f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool top_level_empty() const {
592f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
593f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return TopLevelDeclsInPreamble.empty() && TopLevelDecls.empty();
594f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
595f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
596f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Add a new top-level declaration.
597f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void addTopLevelDecl(Decl *D) {
598f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    TopLevelDecls.push_back(D);
599f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
600f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
601f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Add a new local file-level declaration.
602f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void addFileLevelDecl(Decl *D);
603f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
604f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Get the decls that are contained in a file in the Offset/Length
605f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
606f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// a range.
607f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void findFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
608f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                           SmallVectorImpl<Decl *> &Decls);
609f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
610f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Add a new top-level declaration, identified by its ID in
611f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// the precompiled preamble.
612f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void addTopLevelDeclFromPreamble(serialization::DeclID D) {
613f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    TopLevelDeclsInPreamble.push_back(D);
614f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
615f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
616f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Retrieve a reference to the current top-level name hash value.
617f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
618f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Note: This is used internally by the top-level tracking action
619f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned &getCurrentTopLevelHashValue() { return CurrentTopLevelHashValue; }
620f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
621f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Get the source location for the given file:line:col triplet.
622f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
623f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// The difference with SourceManager::getLocation is that this method checks
624f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// whether the requested location points inside the precompiled preamble
625f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// in which case the returned source location will be a "loaded" one.
626f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SourceLocation getLocation(const FileEntry *File,
627f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                             unsigned Line, unsigned Col) const;
628f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
629f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Get the source location for the given file:offset pair.
630f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SourceLocation getLocation(const FileEntry *File, unsigned Offset) const;
631f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
632f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief If \p Loc is a loaded location from the preamble, returns
633f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// the corresponding local location of the main file, otherwise it returns
634f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \p Loc.
635f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SourceLocation mapLocationFromPreamble(SourceLocation Loc);
636f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
637f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief If \p Loc is a local location of the main file but inside the
638f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// preamble chunk, returns the corresponding loaded location from the
639f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// preamble, otherwise it returns \p Loc.
640f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SourceLocation mapLocationToPreamble(SourceLocation Loc);
641f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
642f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isInPreambleFileID(SourceLocation Loc);
643f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isInMainFileID(SourceLocation Loc);
644f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SourceLocation getStartOfMainFileID();
645f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SourceLocation getEndOfPreambleFileID();
646f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
647f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \see mapLocationFromPreamble.
648f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SourceRange mapRangeFromPreamble(SourceRange R) {
649f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return SourceRange(mapLocationFromPreamble(R.getBegin()),
650f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                       mapLocationFromPreamble(R.getEnd()));
651f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
652f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
653f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \see mapLocationToPreamble.
654f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  SourceRange mapRangeToPreamble(SourceRange R) {
655f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return SourceRange(mapLocationToPreamble(R.getBegin()),
656f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                       mapLocationToPreamble(R.getEnd()));
657f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
658f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
659f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // Retrieve the diagnostics associated with this AST
660f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  typedef StoredDiagnostic *stored_diag_iterator;
661f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  typedef const StoredDiagnostic *stored_diag_const_iterator;
662f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  stored_diag_const_iterator stored_diag_begin() const {
663f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return StoredDiagnostics.begin();
664f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
665f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  stored_diag_iterator stored_diag_begin() {
666f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return StoredDiagnostics.begin();
667f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
668f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  stored_diag_const_iterator stored_diag_end() const {
669f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return StoredDiagnostics.end();
670f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
671f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  stored_diag_iterator stored_diag_end() {
672f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return StoredDiagnostics.end();
673f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
674f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
675f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
676f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  stored_diag_iterator stored_diag_afterDriver_begin() {
677f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    if (NumStoredDiagnosticsFromDriver > StoredDiagnostics.size())
678f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      NumStoredDiagnosticsFromDriver = 0;
679f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return StoredDiagnostics.begin() + NumStoredDiagnosticsFromDriver;
680f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
681f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
682f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  typedef std::vector<CachedCodeCompletionResult>::iterator
683f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    cached_completion_iterator;
684f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
685f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  cached_completion_iterator cached_completion_begin() {
686f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CachedCompletionResults.begin();
687f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
688f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
689f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  cached_completion_iterator cached_completion_end() {
690f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CachedCompletionResults.end();
691f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
692f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
693f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  unsigned cached_completion_size() const {
694f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot    return CachedCompletionResults.size();
695f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  }
696f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
697f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Returns an iterator range for the local preprocessing entities
698f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// of the local Preprocessor, if this is a parsed source file, or the loaded
699f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// preprocessing entities of the primary module if this is an AST file.
700f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  llvm::iterator_range<PreprocessingRecord::iterator>
701f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getLocalPreprocessingEntities() const;
702f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
703f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Type for a function iterating over a number of declarations.
704f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns true to continue iteration and false to abort.
705f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  typedef bool (*DeclVisitorFn)(void *context, const Decl *D);
706f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
707f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Iterate over local declarations (locally parsed if this is a parsed
708f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// source file or the loaded declarations of the primary module if this is an
709f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// AST file).
710f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns true if the iteration was complete or false if it was aborted.
711f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn);
712f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
713f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Get the PCH file if one was included.
714f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  const FileEntry *getPCHFile();
715f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
716f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Returns true if the ASTUnit was constructed from a serialized
717f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// module file.
718f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool isModuleFile();
719f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
720f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  std::unique_ptr<llvm::MemoryBuffer>
721f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  getBufferForFile(StringRef Filename, std::string *ErrorStr = nullptr);
722f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
723f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Determine what kind of translation unit this AST represents.
724f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  TranslationUnitKind getTranslationUnitKind() const { return TUKind; }
725f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
726f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Determine the input kind this AST unit represents.
727f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  InputKind getInputKind() const;
728f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
729f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief A mapping from a file name to the memory buffer that stores the
730f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// remapped contents of that file.
731f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  typedef std::pair<std::string, llvm::MemoryBuffer *> RemappedFile;
732f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
733f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Create a ASTUnit. Gets ownership of the passed CompilerInvocation.
734f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static std::unique_ptr<ASTUnit>
735f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  create(std::shared_ptr<CompilerInvocation> CI,
736f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot         IntrusiveRefCntPtr<DiagnosticsEngine> Diags, bool CaptureDiagnostics,
737f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot         bool UserFilesAreVolatile);
738f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
739f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Create a ASTUnit from an AST file.
740f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
741f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Filename - The AST file to load.
742f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
743f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param PCHContainerRdr - The PCHContainerOperations to use for loading and
744f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// creating modules.
745f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Diags - The diagnostics engine to use for reporting errors; its
746f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// lifetime is expected to extend past that of the returned ASTUnit.
747f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
748f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns - The initialized ASTUnit or null if the AST failed to load.
749f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static std::unique_ptr<ASTUnit> LoadFromASTFile(
750f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      const std::string &Filename, const PCHContainerReader &PCHContainerRdr,
751f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
752f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false,
753f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool OnlyLocalDecls = false, ArrayRef<RemappedFile> RemappedFiles = None,
754f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false,
755f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool UserFilesAreVolatile = false);
756f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
757f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotprivate:
758f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Helper function for \c LoadFromCompilerInvocation() and
759f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation.
760f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
761f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param PrecompilePreambleAfterNParses After how many parses the preamble
762f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// of this translation unit should be precompiled, to improve the performance
763f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// of reparsing. Set to zero to disable preambles.
764f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
765f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param VFS - A vfs::FileSystem to be used for all file accesses. Note that
766f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// preamble is saved to a temporary directory on a RealFileSystem, so in order
767f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// for it to be loaded correctly, VFS should have access to it(i.e., be an
768f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// overlay over RealFileSystem).
769f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
770f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns \c true if a catastrophic failure occurred (which means that the
771f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \c ASTUnit itself is invalid), or \c false otherwise.
772f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool LoadFromCompilerInvocation(
773f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::shared_ptr<PCHContainerOperations> PCHContainerOps,
774f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      unsigned PrecompilePreambleAfterNParses,
775f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      IntrusiveRefCntPtr<vfs::FileSystem> VFS);
776f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
777f3014761c955345d6e05491608e73228d014afbandroid-build-team Robotpublic:
778f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
779f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Create an ASTUnit from a source file, via a CompilerInvocation
780f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// object, by invoking the optionally provided ASTFrontendAction.
781f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
782f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param CI - The compiler invocation to use; it must have exactly one input
783f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// source file. The ASTUnit takes ownership of the CompilerInvocation object.
784f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
785f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
786f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// creating modules.
787f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
788f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Diags - The diagnostics engine to use for reporting errors; its
789f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// lifetime is expected to extend past that of the returned ASTUnit.
790f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
791f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Action - The ASTFrontendAction to invoke. Its ownership is not
792f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// transferred.
793f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
794f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Unit - optionally an already created ASTUnit. Its ownership is not
795f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// transferred.
796f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
797f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Persistent - if true the returned ASTUnit will be complete.
798f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// false means the caller is only interested in getting info through the
799f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// provided \see Action.
800f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
801f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param ErrAST - If non-null and parsing failed without any AST to return
802f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// (e.g. because the PCH could not be loaded), this accepts the ASTUnit
803f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// mainly to allow the caller to see the diagnostics.
804f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// This will only receive an ASTUnit if a new one was created. If an already
805f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// created ASTUnit was passed in \p Unit then the caller can check that.
806f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
807f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static ASTUnit *LoadFromCompilerInvocationAction(
808f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::shared_ptr<CompilerInvocation> CI,
809f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::shared_ptr<PCHContainerOperations> PCHContainerOps,
810f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
811f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      FrontendAction *Action = nullptr, ASTUnit *Unit = nullptr,
812f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool Persistent = true, StringRef ResourceFilesPath = StringRef(),
813f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool OnlyLocalDecls = false, bool CaptureDiagnostics = false,
814f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      unsigned PrecompilePreambleAfterNParses = 0,
815f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool CacheCodeCompletionResults = false,
816f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool IncludeBriefCommentsInCodeCompletion = false,
817f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool UserFilesAreVolatile = false,
818f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::unique_ptr<ASTUnit> *ErrAST = nullptr);
819f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
820f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a
821f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// CompilerInvocation object.
822f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
823f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param CI - The compiler invocation to use; it must have exactly one input
824f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// source file. The ASTUnit takes ownership of the CompilerInvocation object.
825f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
826f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
827f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// creating modules.
828f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
829f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Diags - The diagnostics engine to use for reporting errors; its
830f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// lifetime is expected to extend past that of the returned ASTUnit.
831f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  //
832f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
833f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // shouldn't need to specify them at construction time.
834f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static std::unique_ptr<ASTUnit> LoadFromCompilerInvocation(
835f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::shared_ptr<CompilerInvocation> CI,
836f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::shared_ptr<PCHContainerOperations> PCHContainerOps,
837f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      IntrusiveRefCntPtr<DiagnosticsEngine> Diags, FileManager *FileMgr,
838f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool OnlyLocalDecls = false, bool CaptureDiagnostics = false,
839f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      unsigned PrecompilePreambleAfterNParses = 0,
840f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      TranslationUnitKind TUKind = TU_Complete,
841f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool CacheCodeCompletionResults = false,
842f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool IncludeBriefCommentsInCodeCompletion = false,
843f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool UserFilesAreVolatile = false);
844f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
845f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// LoadFromCommandLine - Create an ASTUnit from a vector of command line
846f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// arguments, which must specify exactly one source file.
847f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
848f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param ArgBegin - The beginning of the argument vector.
849f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
850f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param ArgEnd - The end of the argument vector.
851f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
852f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param PCHContainerOps - The PCHContainerOperations to use for loading and
853f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// creating modules.
854f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
855f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Diags - The diagnostics engine to use for reporting errors; its
856f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// lifetime is expected to extend past that of the returned ASTUnit.
857f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
858f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param ResourceFilesPath - The path to the compiler resource files.
859f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
860f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param ModuleFormat - If provided, uses the specific module format.
861f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
862f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param ErrAST - If non-null and parsing failed without any AST to return
863f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// (e.g. because the PCH could not be loaded), this accepts the ASTUnit
864f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// mainly to allow the caller to see the diagnostics.
865f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
866f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param VFS - A vfs::FileSystem to be used for all file accesses. Note that
867f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// preamble is saved to a temporary directory on a RealFileSystem, so in order
868f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// for it to be loaded correctly, VFS should have access to it(i.e., be an
869f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// overlay over RealFileSystem). RealFileSystem will be used if \p VFS is nullptr.
870f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
871f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
872f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  // shouldn't need to specify them at construction time.
873f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  static ASTUnit *LoadFromCommandLine(
874f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      const char **ArgBegin, const char **ArgEnd,
875f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::shared_ptr<PCHContainerOperations> PCHContainerOps,
876f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      IntrusiveRefCntPtr<DiagnosticsEngine> Diags, StringRef ResourceFilesPath,
877f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool OnlyLocalDecls = false, bool CaptureDiagnostics = false,
878f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      ArrayRef<RemappedFile> RemappedFiles = None,
879f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool RemappedFilesKeepOriginalName = true,
880f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      unsigned PrecompilePreambleAfterNParses = 0,
881f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      TranslationUnitKind TUKind = TU_Complete,
882f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool CacheCodeCompletionResults = false,
883f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool IncludeBriefCommentsInCodeCompletion = false,
884f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool AllowPCHWithCompilerErrors = false, bool SkipFunctionBodies = false,
885f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool SingleFileParse = false,
886f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      bool UserFilesAreVolatile = false, bool ForSerialization = false,
887f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      llvm::Optional<StringRef> ModuleFormat = llvm::None,
888f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      std::unique_ptr<ASTUnit> *ErrAST = nullptr,
889f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot      IntrusiveRefCntPtr<vfs::FileSystem> VFS = nullptr);
890f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
891f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Reparse the source files using the same command-line options that
892f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// were originally used to produce this translation unit.
893f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
894f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param VFS - A vfs::FileSystem to be used for all file accesses. Note that
895f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// preamble is saved to a temporary directory on a RealFileSystem, so in order
896f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// for it to be loaded correctly, VFS should give an access to this(i.e. be an
897f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// overlay over RealFileSystem). FileMgr->getVirtualFileSystem() will be used if
898f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \p VFS is nullptr.
899f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
900f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns True if a failure occurred that causes the ASTUnit not to
901f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// contain any translation-unit information, false otherwise.
902f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool Reparse(std::shared_ptr<PCHContainerOperations> PCHContainerOps,
903f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot               ArrayRef<RemappedFile> RemappedFiles = None,
904f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot               IntrusiveRefCntPtr<vfs::FileSystem> VFS = nullptr);
905f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
906f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Free data that will be re-generated on the next parse.
907f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
908f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// Preamble-related data is not affected.
909f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void ResetForParse();
910f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
911f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Perform code completion at the given file, line, and
912f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// column within this translation unit.
913f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
914f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param File The file in which code completion will occur.
915f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
916f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Line The line at which code completion will occur.
917f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
918f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param Column The column at which code completion will occur.
919f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
920f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param IncludeMacros Whether to include macros in the code-completion
921f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// results.
922f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
923f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param IncludeCodePatterns Whether to include code patterns (such as a
924f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// for loop) in the code-completion results.
925f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
926f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \param IncludeBriefComments Whether to include brief documentation within
927f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// the set of code completions returned.
928f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
929f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and
930f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// OwnedBuffers parameters are all disgusting hacks. They will go away.
931f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  void CodeComplete(StringRef File, unsigned Line, unsigned Column,
932f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    ArrayRef<RemappedFile> RemappedFiles, bool IncludeMacros,
933f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    bool IncludeCodePatterns, bool IncludeBriefComments,
934f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    CodeCompleteConsumer &Consumer,
935f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    std::shared_ptr<PCHContainerOperations> PCHContainerOps,
936f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    DiagnosticsEngine &Diag, LangOptions &LangOpts,
937f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    SourceManager &SourceMgr, FileManager &FileMgr,
938f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
939f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot                    SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers);
940f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
941f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Save this translation unit to a file with the given name.
942f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
943f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns true if there was a file error or false if the save was
944f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// successful.
945f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool Save(StringRef File);
946f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
947f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \brief Serialize this translation unit with the given output stream.
948f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  ///
949f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  /// \returns True if an error occurred, false otherwise.
950f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot  bool serialize(raw_ostream &OS);
951f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot};
952f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
953f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot} // namespace clang
954f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot
955f3014761c955345d6e05491608e73228d014afbandroid-build-team Robot#endif
956