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