]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/ASTUnit.h
Upgrade libcompiler_rt from revision 117047 to 132478.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Frontend / ASTUnit.h
1 //===--- ASTUnit.h - ASTUnit utility ----------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // ASTUnit utility class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H
15 #define LLVM_CLANG_FRONTEND_ASTUNIT_H
16
17 #include "clang/Index/ASTLocation.h"
18 #include "clang/Serialization/ASTBitCodes.h"
19 #include "clang/Sema/Sema.h"
20 #include "clang/Sema/CodeCompleteConsumer.h"
21 #include "clang/Lex/PreprocessingRecord.h"
22 #include "clang/Basic/SourceManager.h"
23 #include "clang/Basic/FileManager.h"
24 #include "clang/Basic/FileSystemOptions.h"
25 #include "clang-c/Index.h"
26 #include "llvm/ADT/IntrusiveRefCntPtr.h"
27 #include "llvm/ADT/OwningPtr.h"
28 #include "llvm/ADT/SmallVector.h"
29 #include "llvm/ADT/StringMap.h"
30 #include "llvm/Support/Path.h"
31 #include <map>
32 #include <string>
33 #include <vector>
34 #include <cassert>
35 #include <utility>
36 #include <sys/types.h>
37
38 namespace llvm {
39   class MemoryBuffer;
40 }
41
42 namespace clang {
43 class ASTContext;
44 class CodeCompleteConsumer;
45 class CompilerInvocation;
46 class Decl;
47 class Diagnostic;
48 class FileEntry;
49 class FileManager;
50 class HeaderSearch;
51 class Preprocessor;
52 class SourceManager;
53 class TargetInfo;
54
55 using namespace idx;
56   
57 /// \brief Allocator for a cached set of global code completions.
58 class GlobalCodeCompletionAllocator 
59   : public CodeCompletionAllocator,
60     public llvm::RefCountedBase<GlobalCodeCompletionAllocator> 
61 {
62
63 };
64   
65 /// \brief Utility class for loading a ASTContext from an AST file.
66 ///
67 class ASTUnit {
68 public:
69   typedef std::map<FileID, std::vector<PreprocessedEntity *> > 
70     PreprocessedEntitiesByFileMap;
71   
72 private:
73   llvm::IntrusiveRefCntPtr<Diagnostic> Diagnostics;
74   llvm::IntrusiveRefCntPtr<FileManager>      FileMgr;
75   llvm::IntrusiveRefCntPtr<SourceManager>    SourceMgr;
76   llvm::OwningPtr<HeaderSearch>     HeaderInfo;
77   llvm::IntrusiveRefCntPtr<TargetInfo>       Target;
78   llvm::IntrusiveRefCntPtr<Preprocessor>     PP;
79   llvm::IntrusiveRefCntPtr<ASTContext>       Ctx;
80
81   FileSystemOptions FileSystemOpts;
82
83   /// \brief The AST consumer that received information about the translation
84   /// unit as it was parsed or loaded.
85   llvm::OwningPtr<ASTConsumer> Consumer;
86   
87   /// \brief The semantic analysis object used to type-check the translation
88   /// unit.
89   llvm::OwningPtr<Sema> TheSema;
90   
91   /// Optional owned invocation, just used to make the invocation used in
92   /// LoadFromCommandLine available.
93   llvm::IntrusiveRefCntPtr<CompilerInvocation> Invocation;
94   
95   /// \brief The set of target features.
96   ///
97   /// FIXME: each time we reparse, we need to restore the set of target
98   /// features from this vector, because TargetInfo::CreateTargetInfo()
99   /// mangles the target options in place. Yuck!
100   std::vector<std::string> TargetFeatures;
101   
102   // OnlyLocalDecls - when true, walking this AST should only visit declarations
103   // that come from the AST itself, not from included precompiled headers.
104   // FIXME: This is temporary; eventually, CIndex will always do this.
105   bool                              OnlyLocalDecls;
106
107   /// \brief Whether to capture any diagnostics produced.
108   bool CaptureDiagnostics;
109
110   /// \brief Track whether the main file was loaded from an AST or not.
111   bool MainFileIsAST;
112
113   /// \brief Whether this AST represents a complete translation unit.
114   bool CompleteTranslationUnit;
115
116   /// \brief Whether we should time each operation.
117   bool WantTiming;
118
119   /// \brief Whether the ASTUnit should delete the remapped buffers.
120   bool OwnsRemappedFileBuffers;
121   
122   /// Track the top-level decls which appeared in an ASTUnit which was loaded
123   /// from a source file.
124   //
125   // FIXME: This is just an optimization hack to avoid deserializing large parts
126   // of a PCH file when using the Index library on an ASTUnit loaded from
127   // source. In the long term we should make the Index library use efficient and
128   // more scalable search mechanisms.
129   std::vector<Decl*> TopLevelDecls;
130
131   /// \brief The list of preprocessed entities which appeared when the ASTUnit
132   /// was loaded.
133   ///
134   /// FIXME: This is just an optimization hack to avoid deserializing large
135   /// parts of a PCH file while performing a walk or search. In the long term,
136   /// we should provide more scalable search mechanisms.
137   std::vector<PreprocessedEntity *> PreprocessedEntities;
138   
139   /// The name of the original source file used to generate this ASTUnit.
140   std::string OriginalSourceFile;
141
142   // Critical optimization when using clang_getCursor().
143   ASTLocation LastLoc;
144
145   /// \brief The set of diagnostics produced when creating this
146   /// translation unit.
147   llvm::SmallVector<StoredDiagnostic, 4> StoredDiagnostics;
148
149   /// \brief The number of stored diagnostics that come from the driver
150   /// itself.
151   ///
152   /// Diagnostics that come from the driver are retained from one parse to
153   /// the next.
154   unsigned NumStoredDiagnosticsFromDriver;
155   
156   /// \brief Temporary files that should be removed when the ASTUnit is 
157   /// destroyed.
158   llvm::SmallVector<llvm::sys::Path, 4> TemporaryFiles;
159
160   /// \brief A mapping from file IDs to the set of preprocessed entities
161   /// stored in that file. 
162   ///
163   /// FIXME: This is just an optimization hack to avoid searching through
164   /// many preprocessed entities during cursor traversal in the CIndex library.
165   /// Ideally, we would just be able to perform a binary search within the
166   /// list of preprocessed entities.
167   PreprocessedEntitiesByFileMap PreprocessedEntitiesByFile;
168   
169   /// \brief Simple hack to allow us to assert that ASTUnit is not being
170   /// used concurrently, which is not supported.
171   ///
172   /// Clients should create instances of the ConcurrencyCheck class whenever
173   /// using the ASTUnit in a way that isn't intended to be concurrent, which is
174   /// just about any usage.
175   unsigned int ConcurrencyCheckValue;
176   static const unsigned int CheckLocked = 28573289;
177   static const unsigned int CheckUnlocked = 9803453;
178
179   /// \brief Counter that determines when we want to try building a
180   /// precompiled preamble.
181   ///
182   /// If zero, we will never build a precompiled preamble. Otherwise,
183   /// it's treated as a counter that decrements each time we reparse
184   /// without the benefit of a precompiled preamble. When it hits 1,
185   /// we'll attempt to rebuild the precompiled header. This way, if
186   /// building the precompiled preamble fails, we won't try again for
187   /// some number of calls.
188   unsigned PreambleRebuildCounter;
189   
190   /// \brief The file in which the precompiled preamble is stored.
191   std::string PreambleFile;
192   
193   /// \brief The contents of the preamble that has been precompiled to
194   /// \c PreambleFile.
195   std::vector<char> Preamble;
196
197   /// \brief Whether the preamble ends at the start of a new line.
198   /// 
199   /// Used to inform the lexer as to whether it's starting at the beginning of
200   /// a line after skipping the preamble.
201   bool PreambleEndsAtStartOfLine;
202   
203   /// \brief The size of the source buffer that we've reserved for the main 
204   /// file within the precompiled preamble.
205   unsigned PreambleReservedSize;
206
207   /// \brief Keeps track of the files that were used when computing the 
208   /// preamble, with both their buffer size and their modification time.
209   ///
210   /// If any of the files have changed from one compile to the next,
211   /// the preamble must be thrown away.
212   llvm::StringMap<std::pair<off_t, time_t> > FilesInPreamble;
213
214   /// \brief When non-NULL, this is the buffer used to store the contents of
215   /// the main file when it has been padded for use with the precompiled
216   /// preamble.
217   llvm::MemoryBuffer *SavedMainFileBuffer;
218
219   /// \brief When non-NULL, this is the buffer used to store the
220   /// contents of the preamble when it has been padded to build the
221   /// precompiled preamble.
222   llvm::MemoryBuffer *PreambleBuffer;
223
224   /// \brief The number of warnings that occurred while parsing the preamble.
225   ///
226   /// This value will be used to restore the state of the \c Diagnostic object
227   /// when re-using the precompiled preamble. Note that only the
228   /// number of warnings matters, since we will not save the preamble
229   /// when any errors are present.
230   unsigned NumWarningsInPreamble;
231
232   /// \brief The number of diagnostics that were stored when parsing
233   /// the precompiled preamble.
234   ///
235   /// This value is used to determine how many of the stored
236   /// diagnostics should be retained when reparsing in the presence of
237   /// a precompiled preamble.
238   unsigned NumStoredDiagnosticsInPreamble;
239
240   /// \brief A list of the serialization ID numbers for each of the top-level
241   /// declarations parsed within the precompiled preamble.
242   std::vector<serialization::DeclID> TopLevelDeclsInPreamble;
243
244   /// \brief A list of the offsets into the precompiled preamble which
245   /// correspond to preprocessed entities.
246   std::vector<uint64_t> PreprocessedEntitiesInPreamble;
247   
248   /// \brief Whether we should be caching code-completion results.
249   bool ShouldCacheCodeCompletionResults;
250   
251   static void ConfigureDiags(llvm::IntrusiveRefCntPtr<Diagnostic> &Diags,
252                              const char **ArgBegin, const char **ArgEnd,
253                              ASTUnit &AST, bool CaptureDiagnostics);
254
255 public:
256   /// \brief A cached code-completion result, which may be introduced in one of
257   /// many different contexts.
258   struct CachedCodeCompletionResult {
259     /// \brief The code-completion string corresponding to this completion
260     /// result.
261     CodeCompletionString *Completion;
262     
263     /// \brief A bitmask that indicates which code-completion contexts should
264     /// contain this completion result.
265     ///
266     /// The bits in the bitmask correspond to the values of 
267     /// CodeCompleteContext::Kind. To map from a completion context kind to a 
268     /// bit, subtract one from the completion context kind and shift 1 by that
269     /// number of bits. Many completions can occur in several different
270     /// contexts.
271     unsigned ShowInContexts;
272     
273     /// \brief The priority given to this code-completion result.
274     unsigned Priority;
275     
276     /// \brief The libclang cursor kind corresponding to this code-completion 
277     /// result.
278     CXCursorKind Kind;
279     
280     /// \brief The availability of this code-completion result.
281     CXAvailabilityKind Availability;
282     
283     /// \brief The simplified type class for a non-macro completion result.
284     SimplifiedTypeClass TypeClass;
285     
286     /// \brief The type of a non-macro completion result, stored as a unique
287     /// integer used by the string map of cached completion types.
288     ///
289     /// This value will be zero if the type is not known, or a unique value
290     /// determined by the formatted type string. Se \c CachedCompletionTypes
291     /// for more information.
292     unsigned Type;
293   };
294   
295   /// \brief Retrieve the mapping from formatted type names to unique type
296   /// identifiers.
297   llvm::StringMap<unsigned> &getCachedCompletionTypes() { 
298     return CachedCompletionTypes; 
299   }
300   
301   /// \brief Retrieve the allocator used to cache global code completions.
302   llvm::IntrusiveRefCntPtr<GlobalCodeCompletionAllocator> 
303   getCachedCompletionAllocator() {
304     return CachedCompletionAllocator;
305   }
306   
307 private:
308   /// \brief Allocator used to store cached code completions.
309   llvm::IntrusiveRefCntPtr<GlobalCodeCompletionAllocator>
310     CachedCompletionAllocator;
311
312   /// \brief The set of cached code-completion results.
313   std::vector<CachedCodeCompletionResult> CachedCompletionResults;
314   
315   /// \brief A mapping from the formatted type name to a unique number for that
316   /// type, which is used for type equality comparisons.
317   llvm::StringMap<unsigned> CachedCompletionTypes;
318   
319   /// \brief A string hash of the top-level declaration and macro definition 
320   /// names processed the last time that we reparsed the file.
321   ///
322   /// This hash value is used to determine when we need to refresh the 
323   /// global code-completion cache.
324   unsigned CompletionCacheTopLevelHashValue;
325
326   /// \brief A string hash of the top-level declaration and macro definition 
327   /// names processed the last time that we reparsed the precompiled preamble.
328   ///
329   /// This hash value is used to determine when we need to refresh the 
330   /// global code-completion cache after a rebuild of the precompiled preamble.
331   unsigned PreambleTopLevelHashValue;
332
333   /// \brief The current hash value for the top-level declaration and macro
334   /// definition names
335   unsigned CurrentTopLevelHashValue;
336   
337   /// \brief Bit used by CIndex to mark when a translation unit may be in an
338   /// inconsistent state, and is not safe to free.
339   unsigned UnsafeToFree : 1;
340
341   /// \brief Cache any "global" code-completion results, so that we can avoid
342   /// recomputing them with each completion.
343   void CacheCodeCompletionResults();
344   
345   /// \brief Clear out and deallocate 
346   void ClearCachedCompletionResults();
347   
348   ASTUnit(const ASTUnit&); // DO NOT IMPLEMENT
349   ASTUnit &operator=(const ASTUnit &); // DO NOT IMPLEMENT
350   
351   explicit ASTUnit(bool MainFileIsAST);
352
353   void CleanTemporaryFiles();
354   bool Parse(llvm::MemoryBuffer *OverrideMainBuffer);
355   
356   std::pair<llvm::MemoryBuffer *, std::pair<unsigned, bool> >
357   ComputePreamble(CompilerInvocation &Invocation, 
358                   unsigned MaxLines, bool &CreatedBuffer);
359   
360   llvm::MemoryBuffer *getMainBufferWithPrecompiledPreamble(
361                                          CompilerInvocation PreambleInvocation,
362                                                      bool AllowRebuild = true,
363                                                         unsigned MaxLines = 0);
364   void RealizeTopLevelDeclsFromPreamble();
365   void RealizePreprocessedEntitiesFromPreamble();
366   
367 public:
368   class ConcurrencyCheck {
369     volatile ASTUnit &Self;
370     
371   public:
372     explicit ConcurrencyCheck(ASTUnit &Self)
373       : Self(Self) 
374     { 
375       assert(Self.ConcurrencyCheckValue == CheckUnlocked && 
376              "Concurrent access to ASTUnit!");
377       Self.ConcurrencyCheckValue = CheckLocked;
378     }
379     
380     ~ConcurrencyCheck() {
381       Self.ConcurrencyCheckValue = CheckUnlocked;
382     }
383   };
384   friend class ConcurrencyCheck;
385   
386   ~ASTUnit();
387
388   bool isMainFileAST() const { return MainFileIsAST; }
389
390   bool isUnsafeToFree() const { return UnsafeToFree; }
391   void setUnsafeToFree(bool Value) { UnsafeToFree = Value; }
392
393   const Diagnostic &getDiagnostics() const { return *Diagnostics; }
394   Diagnostic &getDiagnostics()             { return *Diagnostics; }
395   
396   const SourceManager &getSourceManager() const { return *SourceMgr; }
397         SourceManager &getSourceManager()       { return *SourceMgr; }
398
399   const Preprocessor &getPreprocessor() const { return *PP; }
400         Preprocessor &getPreprocessor()       { return *PP; }
401
402   const ASTContext &getASTContext() const { return *Ctx; }
403         ASTContext &getASTContext()       { return *Ctx; }
404
405   bool hasSema() const { return TheSema; }
406   Sema &getSema() const { 
407     assert(TheSema && "ASTUnit does not have a Sema object!");
408     return *TheSema; 
409   }
410   
411   const FileManager &getFileManager() const { return *FileMgr; }
412         FileManager &getFileManager()       { return *FileMgr; }
413
414   const FileSystemOptions &getFileSystemOpts() const { return FileSystemOpts; }
415
416   const std::string &getOriginalSourceFileName();
417   const std::string &getASTFileName();
418
419   /// \brief Add a temporary file that the ASTUnit depends on.
420   ///
421   /// This file will be erased when the ASTUnit is destroyed.
422   void addTemporaryFile(const llvm::sys::Path &TempFile) {
423     TemporaryFiles.push_back(TempFile);
424   }
425                         
426   bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
427
428   bool getOwnsRemappedFileBuffers() const { return OwnsRemappedFileBuffers; }
429   void setOwnsRemappedFileBuffers(bool val) { OwnsRemappedFileBuffers = val; }
430
431   /// \brief Retrieve the maximum PCH level of declarations that a
432   /// traversal of the translation unit should consider.
433   unsigned getMaxPCHLevel() const;
434
435   void setLastASTLocation(ASTLocation ALoc) { LastLoc = ALoc; }
436   ASTLocation getLastASTLocation() const { return LastLoc; }
437
438
439   llvm::StringRef getMainFileName() const;
440
441   typedef std::vector<Decl *>::iterator top_level_iterator;
442
443   top_level_iterator top_level_begin() {
444     assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
445     if (!TopLevelDeclsInPreamble.empty())
446       RealizeTopLevelDeclsFromPreamble();
447     return TopLevelDecls.begin();
448   }
449
450   top_level_iterator top_level_end() {
451     assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
452     if (!TopLevelDeclsInPreamble.empty())
453       RealizeTopLevelDeclsFromPreamble();
454     return TopLevelDecls.end();
455   }
456
457   std::size_t top_level_size() const {
458     assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
459     return TopLevelDeclsInPreamble.size() + TopLevelDecls.size();
460   }
461
462   bool top_level_empty() const {
463     assert(!isMainFileAST() && "Invalid call for AST based ASTUnit!");
464     return TopLevelDeclsInPreamble.empty() && TopLevelDecls.empty();
465   }
466
467   /// \brief Add a new top-level declaration.
468   void addTopLevelDecl(Decl *D) {
469     TopLevelDecls.push_back(D);
470   }
471
472   /// \brief Add a new top-level declaration, identified by its ID in
473   /// the precompiled preamble.
474   void addTopLevelDeclFromPreamble(serialization::DeclID D) {
475     TopLevelDeclsInPreamble.push_back(D);
476   }
477
478   /// \brief Retrieve a reference to the current top-level name hash value.
479   ///
480   /// Note: This is used internally by the top-level tracking action
481   unsigned &getCurrentTopLevelHashValue() { return CurrentTopLevelHashValue; }
482   
483   typedef std::vector<PreprocessedEntity *>::iterator pp_entity_iterator;
484   
485   pp_entity_iterator pp_entity_begin();
486   pp_entity_iterator pp_entity_end();
487   
488   /// \brief Add a new preprocessed entity that's stored at the given offset
489   /// in the precompiled preamble.
490   void addPreprocessedEntityFromPreamble(uint64_t Offset) {
491     PreprocessedEntitiesInPreamble.push_back(Offset);
492   }
493   
494   /// \brief Retrieve the mapping from File IDs to the preprocessed entities
495   /// within that file.
496   PreprocessedEntitiesByFileMap &getPreprocessedEntitiesByFile() {
497     return PreprocessedEntitiesByFile;
498   }
499   
500   // Retrieve the diagnostics associated with this AST
501   typedef const StoredDiagnostic *stored_diag_iterator;
502   stored_diag_iterator stored_diag_begin() const { 
503     return StoredDiagnostics.begin(); 
504   }
505   stored_diag_iterator stored_diag_end() const { 
506     return StoredDiagnostics.end(); 
507   }
508   unsigned stored_diag_size() const { return StoredDiagnostics.size(); }
509   
510   llvm::SmallVector<StoredDiagnostic, 4> &getStoredDiagnostics() { 
511     return StoredDiagnostics; 
512   }
513
514   typedef std::vector<CachedCodeCompletionResult>::iterator
515     cached_completion_iterator;
516   
517   cached_completion_iterator cached_completion_begin() {
518     return CachedCompletionResults.begin();
519   }
520
521   cached_completion_iterator cached_completion_end() {
522     return CachedCompletionResults.end();
523   }
524
525   unsigned cached_completion_size() const { 
526     return CachedCompletionResults.size(); 
527   }
528
529   llvm::MemoryBuffer *getBufferForFile(llvm::StringRef Filename,
530                                        std::string *ErrorStr = 0);
531
532   /// \brief Whether this AST represents a complete translation unit.
533   ///
534   /// If false, this AST is only a partial translation unit, e.g., one
535   /// that might still be used as a precompiled header or preamble.
536   bool isCompleteTranslationUnit() const { return CompleteTranslationUnit; }
537
538   typedef llvm::PointerUnion<const char *, const llvm::MemoryBuffer *>
539       FilenameOrMemBuf;
540   /// \brief A mapping from a file name to the memory buffer that stores the
541   /// remapped contents of that file.
542   typedef std::pair<std::string, FilenameOrMemBuf> RemappedFile;
543
544   /// \brief Create a ASTUnit. Gets ownership of the passed CompilerInvocation. 
545   static ASTUnit *create(CompilerInvocation *CI,
546                          llvm::IntrusiveRefCntPtr<Diagnostic> Diags);
547
548   /// \brief Create a ASTUnit from an AST file.
549   ///
550   /// \param Filename - The AST file to load.
551   ///
552   /// \param Diags - The diagnostics engine to use for reporting errors; its
553   /// lifetime is expected to extend past that of the returned ASTUnit.
554   ///
555   /// \returns - The initialized ASTUnit or null if the AST failed to load.
556   static ASTUnit *LoadFromASTFile(const std::string &Filename,
557                                   llvm::IntrusiveRefCntPtr<Diagnostic> Diags,
558                                   const FileSystemOptions &FileSystemOpts,
559                                   bool OnlyLocalDecls = false,
560                                   RemappedFile *RemappedFiles = 0,
561                                   unsigned NumRemappedFiles = 0,
562                                   bool CaptureDiagnostics = false);
563
564 private:
565   /// \brief Helper function for \c LoadFromCompilerInvocation() and
566   /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation.
567   ///
568   /// \param PrecompilePreamble Whether to precompile the preamble of this
569   /// translation unit, to improve the performance of reparsing.
570   ///
571   /// \returns \c true if a catastrophic failure occurred (which means that the
572   /// \c ASTUnit itself is invalid), or \c false otherwise.
573   bool LoadFromCompilerInvocation(bool PrecompilePreamble);
574   
575 public:
576   
577   /// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a
578   /// CompilerInvocation object.
579   ///
580   /// \param CI - The compiler invocation to use; it must have exactly one input
581   /// source file. The ASTUnit takes ownership of the CompilerInvocation object.
582   ///
583   /// \param Diags - The diagnostics engine to use for reporting errors; its
584   /// lifetime is expected to extend past that of the returned ASTUnit.
585   //
586   // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
587   // shouldn't need to specify them at construction time.
588   static ASTUnit *LoadFromCompilerInvocation(CompilerInvocation *CI,
589                                      llvm::IntrusiveRefCntPtr<Diagnostic> Diags,
590                                              bool OnlyLocalDecls = false,
591                                              bool CaptureDiagnostics = false,
592                                              bool PrecompilePreamble = false,
593                                           bool CompleteTranslationUnit = true,
594                                        bool CacheCodeCompletionResults = false);
595
596   /// LoadFromCommandLine - Create an ASTUnit from a vector of command line
597   /// arguments, which must specify exactly one source file.
598   ///
599   /// \param ArgBegin - The beginning of the argument vector.
600   ///
601   /// \param ArgEnd - The end of the argument vector.
602   ///
603   /// \param Diags - The diagnostics engine to use for reporting errors; its
604   /// lifetime is expected to extend past that of the returned ASTUnit.
605   ///
606   /// \param ResourceFilesPath - The path to the compiler resource files.
607   //
608   // FIXME: Move OnlyLocalDecls, UseBumpAllocator to setters on the ASTUnit, we
609   // shouldn't need to specify them at construction time.
610   static ASTUnit *LoadFromCommandLine(const char **ArgBegin,
611                                       const char **ArgEnd,
612                                     llvm::IntrusiveRefCntPtr<Diagnostic> Diags,
613                                       llvm::StringRef ResourceFilesPath,
614                                       bool OnlyLocalDecls = false,
615                                       bool CaptureDiagnostics = false,
616                                       RemappedFile *RemappedFiles = 0,
617                                       unsigned NumRemappedFiles = 0,
618                                       bool RemappedFilesKeepOriginalName = true,
619                                       bool PrecompilePreamble = false,
620                                       bool CompleteTranslationUnit = true,
621                                       bool CacheCodeCompletionResults = false,
622                                       bool CXXPrecompilePreamble = false,
623                                       bool CXXChainedPCH = false);
624   
625   /// \brief Reparse the source files using the same command-line options that
626   /// were originally used to produce this translation unit.
627   ///
628   /// \returns True if a failure occurred that causes the ASTUnit not to
629   /// contain any translation-unit information, false otherwise.  
630   bool Reparse(RemappedFile *RemappedFiles = 0,
631                unsigned NumRemappedFiles = 0);
632
633   /// \brief Perform code completion at the given file, line, and
634   /// column within this translation unit.
635   ///
636   /// \param File The file in which code completion will occur.
637   ///
638   /// \param Line The line at which code completion will occur.
639   ///
640   /// \param Column The column at which code completion will occur.
641   ///
642   /// \param IncludeMacros Whether to include macros in the code-completion 
643   /// results.
644   ///
645   /// \param IncludeCodePatterns Whether to include code patterns (such as a 
646   /// for loop) in the code-completion results.
647   ///
648   /// FIXME: The Diag, LangOpts, SourceMgr, FileMgr, StoredDiagnostics, and
649   /// OwnedBuffers parameters are all disgusting hacks. They will go away.
650   void CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
651                     RemappedFile *RemappedFiles, unsigned NumRemappedFiles,
652                     bool IncludeMacros, bool IncludeCodePatterns,
653                     CodeCompleteConsumer &Consumer,
654                     Diagnostic &Diag, LangOptions &LangOpts,
655                     SourceManager &SourceMgr, FileManager &FileMgr,
656                     llvm::SmallVectorImpl<StoredDiagnostic> &StoredDiagnostics,
657               llvm::SmallVectorImpl<const llvm::MemoryBuffer *> &OwnedBuffers);
658
659   /// \brief Save this translation unit to a file with the given name.
660   ///
661   /// \returns True if an error occurred, false otherwise.
662   bool Save(llvm::StringRef File);
663
664   /// \brief Serialize this translation unit with the given output stream.
665   ///
666   /// \returns True if an error occurred, false otherwise.
667   bool serialize(llvm::raw_ostream &OS);
668 };
669
670 } // namespace clang
671
672 #endif