CompilerInstance.h revision 203955
1135446Strhodes//===-- CompilerInstance.h - Clang Compiler Instance ------------*- C++ -*-===//
2205292Sdougb//
3135446Strhodes//                     The LLVM Compiler Infrastructure
4135446Strhodes//
5193149Sdougb// This file is distributed under the University of Illinois Open Source
6135446Strhodes// License. See LICENSE.TXT for details.
7135446Strhodes//
8135446Strhodes//===----------------------------------------------------------------------===//
9135446Strhodes
10135446Strhodes#ifndef LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
11135446Strhodes#define LLVM_CLANG_FRONTEND_COMPILERINSTANCE_H_
12135446Strhodes
13135446Strhodes#include "clang/Frontend/CompilerInvocation.h"
14135446Strhodes#include "llvm/ADT/StringRef.h"
15135446Strhodes#include "llvm/ADT/OwningPtr.h"
16135446Strhodes#include <cassert>
17135446Strhodes#include <list>
18205292Sdougb#include <string>
19135446Strhodes
20135446Strhodesnamespace llvm {
21135446Strhodesclass LLVMContext;
22135446Strhodesclass raw_ostream;
23135446Strhodesclass raw_fd_ostream;
24135446Strhodesclass Timer;
25135446Strhodes}
26135446Strhodes
27193149Sdougbnamespace clang {
28170222Sdougbclass ASTContext;
29135446Strhodesclass ASTConsumer;
30135446Strhodesclass CodeCompleteConsumer;
31135446Strhodesclass Diagnostic;
32135446Strhodesclass DiagnosticClient;
33135446Strhodesclass ExternalASTSource;
34135446Strhodesclass FileManager;
35135446Strhodesclass FrontendAction;
36170222Sdougbclass Preprocessor;
37135446Strhodesclass Source;
38135446Strhodesclass SourceManager;
39170222Sdougbclass TargetInfo;
40135446Strhodes
41135446Strhodes/// CompilerInstance - Helper class for managing a single instance of the Clang
42170222Sdougb/// compiler.
43135446Strhodes///
44135446Strhodes/// The CompilerInstance serves two purposes:
45170222Sdougb///  (1) It manages the various objects which are necessary to run the compiler,
46135446Strhodes///      for example the preprocessor, the target information, and the AST
47135446Strhodes///      context.
48170222Sdougb///  (2) It provides utility routines for constructing and manipulating the
49135446Strhodes///      common Clang objects.
50135446Strhodes///
51170222Sdougb/// The compiler instance generally owns the instance of all the objects that it
52135446Strhodes/// manages. However, clients can still share objects by manually setting the
53135446Strhodes/// object and retaking ownership prior to destroying the CompilerInstance.
54135446Strhodes///
55135446Strhodes/// The compiler instance is intended to simplify clients, but not to lock them
56170222Sdougb/// in to the compiler instance for everything. When possible, utility functions
57135446Strhodes/// come in two forms; a short form that reuses the CompilerInstance objects,
58135446Strhodes/// and a long form that takes explicit instances of any required objects.
59135446Strhodesclass CompilerInstance {
60135446Strhodes  /// The LLVM context used for this instance.
61135446Strhodes  llvm::OwningPtr<llvm::LLVMContext> LLVMContext;
62170222Sdougb
63170222Sdougb  /// The options used in this compiler instance.
64170222Sdougb  llvm::OwningPtr<CompilerInvocation> Invocation;
65170222Sdougb
66170222Sdougb  /// The diagnostics engine instance.
67170222Sdougb  llvm::OwningPtr<Diagnostic> Diagnostics;
68135446Strhodes
69135446Strhodes  /// The diagnostics client instance.
70135446Strhodes  llvm::OwningPtr<DiagnosticClient> DiagClient;
71135446Strhodes
72135446Strhodes  /// The target being compiled for.
73135446Strhodes  llvm::OwningPtr<TargetInfo> Target;
74135446Strhodes
75135446Strhodes  /// The file manager.
76135446Strhodes  llvm::OwningPtr<FileManager> FileMgr;
77135446Strhodes
78135446Strhodes  /// The source manager.
79135446Strhodes  llvm::OwningPtr<SourceManager> SourceMgr;
80135446Strhodes
81193149Sdougb  /// The preprocessor.
82193149Sdougb  llvm::OwningPtr<Preprocessor> PP;
83193149Sdougb
84193149Sdougb  /// The AST context.
85193149Sdougb  llvm::OwningPtr<ASTContext> Context;
86193149Sdougb
87193149Sdougb  /// The AST consumer.
88193149Sdougb  llvm::OwningPtr<ASTConsumer> Consumer;
89170222Sdougb
90170222Sdougb  /// The code completion consumer.
91170222Sdougb  llvm::OwningPtr<CodeCompleteConsumer> CompletionConsumer;
92170222Sdougb
93170222Sdougb  /// The frontend timer
94170222Sdougb  llvm::OwningPtr<llvm::Timer> FrontendTimer;
95170222Sdougb
96170222Sdougb  /// The list of active output files.
97170222Sdougb  std::list< std::pair<std::string, llvm::raw_ostream*> > OutputFiles;
98170222Sdougb
99170222Sdougb  void operator=(const CompilerInstance &);  // DO NOT IMPLEMENT
100170222Sdougb  CompilerInstance(const CompilerInstance&); // DO NOT IMPLEMENT
101170222Sdougbpublic:
102170222Sdougb  CompilerInstance();
103170222Sdougb  ~CompilerInstance();
104170222Sdougb
105170222Sdougb  /// @name High-Level Operations
106170222Sdougb  /// {
107170222Sdougb
108170222Sdougb  /// ExecuteAction - Execute the provided action against the compiler's
109170222Sdougb  /// CompilerInvocation object.
110170222Sdougb  ///
111170222Sdougb  /// This function makes the following assumptions:
112170222Sdougb  ///
113205292Sdougb  ///  - The invocation options should be initialized. This function does not
114205292Sdougb  ///    handle the '-help' or '-version' options, clients should handle those
115205292Sdougb  ///    directly.
116135446Strhodes  ///
117135446Strhodes  ///  - The diagnostics engine should have already been created by the client.
118135446Strhodes  ///
119135446Strhodes  ///  - No other CompilerInstance state should have been initialized (this is
120135446Strhodes  ///    an unchecked error).
121170222Sdougb  ///
122135446Strhodes  ///  - Clients should have initialized any LLVM target features that may be
123135446Strhodes  ///    required.
124135446Strhodes  ///
125135446Strhodes  ///  - Clients should eventually call llvm_shutdown() upon the completion of
126135446Strhodes  ///    this routine to ensure that any managed objects are properly destroyed.
127135446Strhodes  ///
128135446Strhodes  /// Note that this routine may write output to 'stderr'.
129135446Strhodes  ///
130135446Strhodes  /// \param Act - The action to execute.
131135446Strhodes  /// \return - True on success.
132135446Strhodes  //
133135446Strhodes  // FIXME: This function should take the stream to write any debugging /
134135446Strhodes  // verbose output to as an argument.
135135446Strhodes  //
136135446Strhodes  // FIXME: Eliminate the llvm_shutdown requirement, that should either be part
137135446Strhodes  // of the context or else not CompilerInstance specific.
138135446Strhodes  bool ExecuteAction(FrontendAction &Act);
139135446Strhodes
140135446Strhodes  /// }
141135446Strhodes  /// @name LLVM Context
142135446Strhodes  /// {
143135446Strhodes
144135446Strhodes  bool hasLLVMContext() const { return LLVMContext != 0; }
145170222Sdougb
146135446Strhodes  llvm::LLVMContext &getLLVMContext() const {
147135446Strhodes    assert(LLVMContext && "Compiler instance has no LLVM context!");
148135446Strhodes    return *LLVMContext;
149135446Strhodes  }
150135446Strhodes
151135446Strhodes  llvm::LLVMContext *takeLLVMContext() { return LLVMContext.take(); }
152193149Sdougb
153193149Sdougb  /// setLLVMContext - Replace the current LLVM context and take ownership of
154193149Sdougb  /// \arg Value.
155193149Sdougb  void setLLVMContext(llvm::LLVMContext *Value);
156193149Sdougb
157170222Sdougb  /// }
158170222Sdougb  /// @name Compiler Invocation and Options
159135446Strhodes  /// {
160135446Strhodes
161135446Strhodes  bool hasInvocation() const { return Invocation != 0; }
162135446Strhodes
163135446Strhodes  CompilerInvocation &getInvocation() {
164135446Strhodes    assert(Invocation && "Compiler instance has no invocation!");
165135446Strhodes    return *Invocation;
166135446Strhodes  }
167135446Strhodes
168193149Sdougb  CompilerInvocation *takeInvocation() { return Invocation.take(); }
169170222Sdougb
170193149Sdougb  /// setInvocation - Replace the current invocation; the compiler instance
171135446Strhodes  /// takes ownership of \arg Value.
172135446Strhodes  void setInvocation(CompilerInvocation *Value);
173170222Sdougb
174170222Sdougb  /// }
175135446Strhodes  /// @name Forwarding Methods
176135446Strhodes  /// {
177170222Sdougb
178135446Strhodes  AnalyzerOptions &getAnalyzerOpts() {
179135446Strhodes    return Invocation->getAnalyzerOpts();
180170222Sdougb  }
181170222Sdougb  const AnalyzerOptions &getAnalyzerOpts() const {
182170222Sdougb    return Invocation->getAnalyzerOpts();
183135446Strhodes  }
184170222Sdougb
185153816Sdougb  CodeGenOptions &getCodeGenOpts() {
186170222Sdougb    return Invocation->getCodeGenOpts();
187170222Sdougb  }
188170222Sdougb  const CodeGenOptions &getCodeGenOpts() const {
189170222Sdougb    return Invocation->getCodeGenOpts();
190170222Sdougb  }
191170222Sdougb
192170222Sdougb  DependencyOutputOptions &getDependencyOutputOpts() {
193170222Sdougb    return Invocation->getDependencyOutputOpts();
194170222Sdougb  }
195153816Sdougb  const DependencyOutputOptions &getDependencyOutputOpts() const {
196153816Sdougb    return Invocation->getDependencyOutputOpts();
197170222Sdougb  }
198153816Sdougb
199153816Sdougb  DiagnosticOptions &getDiagnosticOpts() {
200170222Sdougb    return Invocation->getDiagnosticOpts();
201153816Sdougb  }
202170222Sdougb  const DiagnosticOptions &getDiagnosticOpts() const {
203193149Sdougb    return Invocation->getDiagnosticOpts();
204193149Sdougb  }
205193149Sdougb
206135446Strhodes  FrontendOptions &getFrontendOpts() {
207170222Sdougb    return Invocation->getFrontendOpts();
208135446Strhodes  }
209135446Strhodes  const FrontendOptions &getFrontendOpts() const {
210135446Strhodes    return Invocation->getFrontendOpts();
211135446Strhodes  }
212135446Strhodes
213135446Strhodes  HeaderSearchOptions &getHeaderSearchOpts() {
214135446Strhodes    return Invocation->getHeaderSearchOpts();
215170222Sdougb  }
216135446Strhodes  const HeaderSearchOptions &getHeaderSearchOpts() const {
217135446Strhodes    return Invocation->getHeaderSearchOpts();
218135446Strhodes  }
219170222Sdougb
220135446Strhodes  LangOptions &getLangOpts() {
221135446Strhodes    return Invocation->getLangOpts();
222170222Sdougb  }
223135446Strhodes  const LangOptions &getLangOpts() const {
224135446Strhodes    return Invocation->getLangOpts();
225135446Strhodes  }
226135446Strhodes
227170222Sdougb  PreprocessorOptions &getPreprocessorOpts() {
228135446Strhodes    return Invocation->getPreprocessorOpts();
229135446Strhodes  }
230135446Strhodes  const PreprocessorOptions &getPreprocessorOpts() const {
231170222Sdougb    return Invocation->getPreprocessorOpts();
232135446Strhodes  }
233135446Strhodes
234170222Sdougb  PreprocessorOutputOptions &getPreprocessorOutputOpts() {
235135446Strhodes    return Invocation->getPreprocessorOutputOpts();
236135446Strhodes  }
237135446Strhodes  const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
238135446Strhodes    return Invocation->getPreprocessorOutputOpts();
239135446Strhodes  }
240170222Sdougb
241135446Strhodes  TargetOptions &getTargetOpts() {
242135446Strhodes    return Invocation->getTargetOpts();
243135446Strhodes  }
244170222Sdougb  const TargetOptions &getTargetOpts() const {
245135446Strhodes    return Invocation->getTargetOpts();
246135446Strhodes  }
247135446Strhodes
248170222Sdougb  /// }
249135446Strhodes  /// @name Diagnostics Engine
250135446Strhodes  /// {
251170222Sdougb
252135446Strhodes  bool hasDiagnostics() const { return Diagnostics != 0; }
253135446Strhodes
254135446Strhodes  Diagnostic &getDiagnostics() const {
255135446Strhodes    assert(Diagnostics && "Compiler instance has no diagnostics!");
256170222Sdougb    return *Diagnostics;
257135446Strhodes  }
258135446Strhodes
259135446Strhodes  /// takeDiagnostics - Remove the current diagnostics engine and give ownership
260170222Sdougb  /// to the caller.
261135446Strhodes  Diagnostic *takeDiagnostics() { return Diagnostics.take(); }
262135446Strhodes
263170222Sdougb  /// setDiagnostics - Replace the current diagnostics engine; the compiler
264170222Sdougb  /// instance takes ownership of \arg Value.
265135446Strhodes  void setDiagnostics(Diagnostic *Value);
266135446Strhodes
267135446Strhodes  DiagnosticClient &getDiagnosticClient() const {
268135446Strhodes    assert(DiagClient && "Compiler instance has no diagnostic client!");
269135446Strhodes    return *DiagClient;
270170222Sdougb  }
271135446Strhodes
272135446Strhodes  /// takeDiagnosticClient - Remove the current diagnostics client and give
273135446Strhodes  /// ownership to the caller.
274135446Strhodes  DiagnosticClient *takeDiagnosticClient() { return DiagClient.take(); }
275170222Sdougb
276135446Strhodes  /// setDiagnosticClient - Replace the current diagnostics client; the compiler
277135446Strhodes  /// instance takes ownership of \arg Value.
278170222Sdougb  void setDiagnosticClient(DiagnosticClient *Value);
279135446Strhodes
280135446Strhodes  /// }
281170222Sdougb  /// @name Target Info
282135446Strhodes  /// {
283135446Strhodes
284135446Strhodes  bool hasTarget() const { return Target != 0; }
285135446Strhodes
286170222Sdougb  TargetInfo &getTarget() const {
287135446Strhodes    assert(Target && "Compiler instance has no target!");
288135446Strhodes    return *Target;
289135446Strhodes  }
290170222Sdougb
291135446Strhodes  /// takeTarget - Remove the current diagnostics engine and give ownership
292170222Sdougb  /// to the caller.
293135446Strhodes  TargetInfo *takeTarget() { return Target.take(); }
294135446Strhodes
295170222Sdougb  /// setTarget - Replace the current diagnostics engine; the compiler
296135446Strhodes  /// instance takes ownership of \arg Value.
297135446Strhodes  void setTarget(TargetInfo *Value);
298135446Strhodes
299135446Strhodes  /// }
300170222Sdougb  /// @name File Manager
301135446Strhodes  /// {
302135446Strhodes
303135446Strhodes  bool hasFileManager() const { return FileMgr != 0; }
304170222Sdougb
305135446Strhodes  FileManager &getFileManager() const {
306135446Strhodes    assert(FileMgr && "Compiler instance has no file manager!");
307170222Sdougb    return *FileMgr;
308135446Strhodes  }
309135446Strhodes
310135446Strhodes  /// takeFileManager - Remove the current file manager and give ownership to
311135446Strhodes  /// the caller.
312170222Sdougb  FileManager *takeFileManager() { return FileMgr.take(); }
313135446Strhodes
314135446Strhodes  /// setFileManager - Replace the current file manager; the compiler instance
315135446Strhodes  /// takes ownership of \arg Value.
316170222Sdougb  void setFileManager(FileManager *Value);
317135446Strhodes
318135446Strhodes  /// }
319170222Sdougb  /// @name Source Manager
320170222Sdougb  /// {
321135446Strhodes
322135446Strhodes  bool hasSourceManager() const { return SourceMgr != 0; }
323135446Strhodes
324135446Strhodes  SourceManager &getSourceManager() const {
325170222Sdougb    assert(SourceMgr && "Compiler instance has no source manager!");
326135446Strhodes    return *SourceMgr;
327135446Strhodes  }
328135446Strhodes
329170222Sdougb  /// takeSourceManager - Remove the current source manager and give ownership
330135446Strhodes  /// to the caller.
331135446Strhodes  SourceManager *takeSourceManager() { return SourceMgr.take(); }
332170222Sdougb
333170222Sdougb  /// setSourceManager - Replace the current source manager; the compiler
334135446Strhodes  /// instance takes ownership of \arg Value.
335135446Strhodes  void setSourceManager(SourceManager *Value);
336135446Strhodes
337135446Strhodes  /// }
338170222Sdougb  /// @name Preprocessor
339135446Strhodes  /// {
340135446Strhodes
341135446Strhodes  bool hasPreprocessor() const { return PP != 0; }
342135446Strhodes
343170222Sdougb  Preprocessor &getPreprocessor() const {
344135446Strhodes    assert(PP && "Compiler instance has no preprocessor!");
345135446Strhodes    return *PP;
346135446Strhodes  }
347135446Strhodes
348170222Sdougb  /// takePreprocessor - Remove the current preprocessor and give ownership to
349135446Strhodes  /// the caller.
350170222Sdougb  Preprocessor *takePreprocessor() { return PP.take(); }
351135446Strhodes
352135446Strhodes  /// setPreprocessor - Replace the current preprocessor; the compiler instance
353135446Strhodes  /// takes ownership of \arg Value.
354170222Sdougb  void setPreprocessor(Preprocessor *Value);
355170222Sdougb
356135446Strhodes  /// }
357135446Strhodes  /// @name ASTContext
358135446Strhodes  /// {
359135446Strhodes
360135446Strhodes  bool hasASTContext() const { return Context != 0; }
361135446Strhodes
362135446Strhodes  ASTContext &getASTContext() const {
363135446Strhodes    assert(Context && "Compiler instance has no AST context!");
364170222Sdougb    return *Context;
365135446Strhodes  }
366135446Strhodes
367135446Strhodes  /// takeASTContext - Remove the current AST context and give ownership to the
368170222Sdougb  /// caller.
369135446Strhodes  ASTContext *takeASTContext() { return Context.take(); }
370193149Sdougb
371193149Sdougb  /// setASTContext - Replace the current AST context; the compiler instance
372135446Strhodes  /// takes ownership of \arg Value.
373135446Strhodes  void setASTContext(ASTContext *Value);
374170222Sdougb
375135446Strhodes  /// }
376135446Strhodes  /// @name ASTConsumer
377135446Strhodes  /// {
378170222Sdougb
379135446Strhodes  bool hasASTConsumer() const { return Consumer != 0; }
380170222Sdougb
381135446Strhodes  ASTConsumer &getASTConsumer() const {
382135446Strhodes    assert(Consumer && "Compiler instance has no AST consumer!");
383135446Strhodes    return *Consumer;
384135446Strhodes  }
385135446Strhodes
386135446Strhodes  /// takeASTConsumer - Remove the current AST consumer and give ownership to
387135446Strhodes  /// the caller.
388135446Strhodes  ASTConsumer *takeASTConsumer() { return Consumer.take(); }
389135446Strhodes
390170222Sdougb  /// setASTConsumer - Replace the current AST consumer; the compiler instance
391135446Strhodes  /// takes ownership of \arg Value.
392135446Strhodes  void setASTConsumer(ASTConsumer *Value);
393135446Strhodes
394135446Strhodes  /// }
395170222Sdougb  /// @name Code Completion
396135446Strhodes  /// {
397170222Sdougb
398135446Strhodes  bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; }
399135446Strhodes
400170222Sdougb  CodeCompleteConsumer &getCodeCompletionConsumer() const {
401135446Strhodes    assert(CompletionConsumer &&
402170222Sdougb           "Compiler instance has no code completion consumer!");
403135446Strhodes    return *CompletionConsumer;
404170222Sdougb  }
405135446Strhodes
406135446Strhodes  /// takeCodeCompletionConsumer - Remove the current code completion consumer
407170222Sdougb  /// and give ownership to the caller.
408135446Strhodes  CodeCompleteConsumer *takeCodeCompletionConsumer() {
409135446Strhodes    return CompletionConsumer.take();
410135446Strhodes  }
411170222Sdougb
412135446Strhodes  /// setCodeCompletionConsumer - Replace the current code completion consumer;
413135446Strhodes  /// the compiler instance takes ownership of \arg Value.
414135446Strhodes  void setCodeCompletionConsumer(CodeCompleteConsumer *Value);
415170222Sdougb
416170222Sdougb  /// }
417135446Strhodes  /// @name Frontend timer
418170222Sdougb  /// {
419135446Strhodes
420135446Strhodes  bool hasFrontendTimer() const { return FrontendTimer != 0; }
421135446Strhodes
422135446Strhodes  llvm::Timer &getFrontendTimer() const {
423135446Strhodes    assert(FrontendTimer && "Compiler instance has no frontend timer!");
424165071Sdougb    return *FrontendTimer;
425135446Strhodes  }
426135446Strhodes
427135446Strhodes  /// }
428165071Sdougb  /// @name Output Files
429135446Strhodes  /// {
430135446Strhodes
431170222Sdougb  /// getOutputFileList - Get the list of (path, output stream) pairs of output
432135446Strhodes  /// files; the path may be empty but the stream will always be non-null.
433193149Sdougb  const std::list< std::pair<std::string,
434135446Strhodes                             llvm::raw_ostream*> > &getOutputFileList() const;
435135446Strhodes
436135446Strhodes  /// addOutputFile - Add an output file onto the list of tracked output files.
437170222Sdougb  ///
438135446Strhodes  /// \param Path - The path to the output file, or empty.
439135446Strhodes  /// \param OS - The output stream, which should be non-null.
440135446Strhodes  void addOutputFile(llvm::StringRef Path, llvm::raw_ostream *OS);
441135446Strhodes
442135446Strhodes  /// ClearOutputFiles - Clear the output file list, destroying the contained
443165071Sdougb  /// output streams.
444135446Strhodes  ///
445135446Strhodes  /// \param EraseFiles - If true, attempt to erase the files from disk.
446135446Strhodes  void ClearOutputFiles(bool EraseFiles);
447165071Sdougb
448135446Strhodes  /// }
449135446Strhodes  /// @name Construction Utility Methods
450135446Strhodes  /// {
451170222Sdougb
452135446Strhodes  /// Create the diagnostics engine using the invocation's diagnostic options
453135446Strhodes  /// and replace any existing one with it.
454135446Strhodes  ///
455135446Strhodes  /// Note that this routine also replaces the diagnostic client.
456170222Sdougb  void createDiagnostics(int Argc, char **Argv);
457135446Strhodes
458135446Strhodes  /// Create a Diagnostic object with a the TextDiagnosticPrinter.
459135446Strhodes  ///
460135446Strhodes  /// The \arg Argc and \arg Argv arguments are used only for logging purposes,
461135446Strhodes  /// when the diagnostic options indicate that the compiler should output
462135446Strhodes  /// logging information.
463170222Sdougb  ///
464170222Sdougb  /// Note that this creates an unowned DiagnosticClient, if using directly the
465135446Strhodes  /// caller is responsible for releasing the returned Diagnostic's client
466135446Strhodes  /// eventually.
467135446Strhodes  ///
468135446Strhodes  /// \param Opts - The diagnostic options; note that the created text
469135446Strhodes  /// diagnostic object contains a reference to these options and its lifetime
470135446Strhodes  /// must extend past that of the diagnostic engine.
471135446Strhodes  ///
472170222Sdougb  /// \return The new object on success, or null on failure.
473135446Strhodes  static Diagnostic *createDiagnostics(const DiagnosticOptions &Opts,
474135446Strhodes                                       int Argc, char **Argv);
475135446Strhodes
476135446Strhodes  /// Create the file manager and replace any existing one with it.
477135446Strhodes  void createFileManager();
478170222Sdougb
479135446Strhodes  /// Create the source manager and replace any existing one with it.
480170222Sdougb  void createSourceManager();
481135446Strhodes
482135446Strhodes  /// Create the preprocessor, using the invocation, file, and source managers,
483135446Strhodes  /// and replace any existing one with it.
484170222Sdougb  void createPreprocessor();
485135446Strhodes
486135446Strhodes  /// Create a Preprocessor object.
487170222Sdougb  ///
488135446Strhodes  /// Note that this also creates a new HeaderSearch object which will be owned
489135446Strhodes  /// by the resulting Preprocessor.
490135446Strhodes  ///
491135446Strhodes  /// \return The new object on success, or null on failure.
492170222Sdougb  static Preprocessor *createPreprocessor(Diagnostic &, const LangOptions &,
493135446Strhodes                                          const PreprocessorOptions &,
494170222Sdougb                                          const HeaderSearchOptions &,
495135446Strhodes                                          const DependencyOutputOptions &,
496135446Strhodes                                          const TargetInfo &,
497135446Strhodes                                          const FrontendOptions &,
498135446Strhodes                                          SourceManager &, FileManager &);
499193149Sdougb
500170222Sdougb  /// Create the AST context.
501135446Strhodes  void createASTContext();
502135446Strhodes
503135446Strhodes  /// Create an external AST source to read a PCH file and attach it to the AST
504170222Sdougb  /// context.
505170222Sdougb  void createPCHExternalASTSource(llvm::StringRef Path);
506193149Sdougb
507135446Strhodes  /// Create an external AST source to read a PCH file.
508135446Strhodes  ///
509135446Strhodes  /// \return - The new object on success, or null on failure.
510135446Strhodes  static ExternalASTSource *
511170222Sdougb  createPCHExternalASTSource(llvm::StringRef Path, const std::string &Sysroot,
512135446Strhodes                             Preprocessor &PP, ASTContext &Context);
513170222Sdougb
514135446Strhodes  /// Create a code completion consumer using the invocation; note that this
515193149Sdougb  /// will cause the source manager to truncate the input source file at the
516135446Strhodes  /// completion point.
517135446Strhodes  void createCodeCompletionConsumer();
518170222Sdougb
519193149Sdougb  /// Create a code completion consumer to print code completion results, at
520193149Sdougb  /// \arg Filename, \arg Line, and \arg Column, to the given output stream \arg
521135446Strhodes  /// OS.
522135446Strhodes  static CodeCompleteConsumer *
523170222Sdougb  createCodeCompletionConsumer(Preprocessor &PP, const std::string &Filename,
524193149Sdougb                               unsigned Line, unsigned Column,
525193149Sdougb                               bool UseDebugPrinter, bool ShowMacros,
526193149Sdougb                               llvm::raw_ostream &OS);
527193149Sdougb
528193149Sdougb  /// Create the frontend timer and replace any existing one with it.
529193149Sdougb  void createFrontendTimer();
530193149Sdougb
531193149Sdougb  /// Create the default output file (from the invocation's options) and add it
532193149Sdougb  /// to the list of tracked output files.
533193149Sdougb  ///
534193149Sdougb  /// \return - Null on error.
535193149Sdougb  llvm::raw_fd_ostream *
536193149Sdougb  createDefaultOutputFile(bool Binary = true, llvm::StringRef BaseInput = "",
537193149Sdougb                          llvm::StringRef Extension = "");
538193149Sdougb
539193149Sdougb  /// Create a new output file and add it to the list of tracked output files,
540193149Sdougb  /// optionally deriving the output path name.
541193149Sdougb  ///
542193149Sdougb  /// \return - Null on error.
543193149Sdougb  llvm::raw_fd_ostream *
544193149Sdougb  createOutputFile(llvm::StringRef OutputPath, bool Binary = true,
545193149Sdougb                   llvm::StringRef BaseInput = "",
546193149Sdougb                   llvm::StringRef Extension = "");
547193149Sdougb
548193149Sdougb  /// Create a new output file, optionally deriving the output path name.
549170222Sdougb  ///
550170222Sdougb  /// If \arg OutputPath is empty, then createOutputFile will derive an output
551170222Sdougb  /// path location as \arg BaseInput, with any suffix removed, and \arg
552170222Sdougb  /// Extension appended.
553170222Sdougb  ///
554170222Sdougb  /// \param OutputPath - If given, the path to the output file.
555170222Sdougb  /// \param Error [out] - On failure, the error message.
556170222Sdougb  /// \param BaseInput - If \arg OutputPath is empty, the input path name to use
557170222Sdougb  /// for deriving the output path.
558170222Sdougb  /// \param Extension - The extension to use for derived output names.
559170222Sdougb  /// \param Binary - The mode to open the file in.
560170222Sdougb  /// \param ResultPathName [out] - If given, the result path name will be
561170222Sdougb  /// stored here on success.
562170222Sdougb  static llvm::raw_fd_ostream *
563170222Sdougb  createOutputFile(llvm::StringRef OutputPath, std::string &Error,
564170222Sdougb                   bool Binary = true, llvm::StringRef BaseInput = "",
565170222Sdougb                   llvm::StringRef Extension = "",
566170222Sdougb                   std::string *ResultPathName = 0);
567170222Sdougb
568170222Sdougb  /// }
569170222Sdougb  /// @name Initialization Utility Methods
570170222Sdougb  /// {
571170222Sdougb
572170222Sdougb  /// InitializeSourceManager - Initialize the source manager to set InputFile
573170222Sdougb  /// as the main file.
574170222Sdougb  ///
575170222Sdougb  /// \return True on success.
576170222Sdougb  bool InitializeSourceManager(llvm::StringRef InputFile);
577170222Sdougb
578170222Sdougb  /// InitializeSourceManager - Initialize the source manager to set InputFile
579170222Sdougb  /// as the main file.
580170222Sdougb  ///
581170222Sdougb  /// \return True on success.
582170222Sdougb  static bool InitializeSourceManager(llvm::StringRef InputFile,
583170222Sdougb                                      Diagnostic &Diags,
584170222Sdougb                                      FileManager &FileMgr,
585170222Sdougb                                      SourceManager &SourceMgr,
586170222Sdougb                                      const FrontendOptions &Opts);
587170222Sdougb
588170222Sdougb  /// }
589170222Sdougb};
590170222Sdougb
591170222Sdougb} // end namespace clang
592170222Sdougb
593170222Sdougb#endif
594170222Sdougb