clang API Documentation

PreprocessorOptions.h
Go to the documentation of this file.
00001 //===--- PreprocessorOptions.h ----------------------------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_
00011 #define LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_
00012 
00013 #include "llvm/ADT/SmallVector.h"
00014 #include "llvm/ADT/StringRef.h"
00015 #include <cassert>
00016 #include <string>
00017 #include <utility>
00018 #include <vector>
00019 #include <set>
00020 
00021 namespace llvm {
00022   class MemoryBuffer;
00023 }
00024 
00025 namespace clang {
00026 
00027 class Preprocessor;
00028 class LangOptions;
00029 
00030 /// \brief Enumerate the kinds of standard library that 
00031 enum ObjCXXARCStandardLibraryKind {
00032   ARCXX_nolib,
00033   /// \brief libc++
00034   ARCXX_libcxx,
00035   /// \brief libstdc++
00036   ARCXX_libstdcxx
00037 };
00038   
00039 /// PreprocessorOptions - This class is used for passing the various options
00040 /// used in preprocessor initialization to InitializePreprocessor().
00041 class PreprocessorOptions {
00042 public:
00043   std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
00044   std::vector<std::string> Includes;
00045   std::vector<std::string> MacroIncludes;
00046 
00047   unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
00048                               /// and target specific predefines.
00049 
00050   unsigned DetailedRecord : 1; /// Whether we should maintain a detailed
00051                                /// record of all macro definitions and
00052                                /// expansions.
00053   unsigned DetailedRecordConditionalDirectives : 1; /// Whether in the
00054                                /// preprocessing record we should also keep
00055                                /// track of locations of conditional directives
00056                                /// in non-system files.
00057   
00058   /// The implicit PCH included at the start of the translation unit, or empty.
00059   std::string ImplicitPCHInclude;
00060 
00061   /// \brief Headers that will be converted to chained PCHs in memory.
00062   std::vector<std::string> ChainedIncludes;
00063 
00064   /// \brief When true, disables most of the normal validation performed on
00065   /// precompiled headers.
00066   bool DisablePCHValidation;
00067 
00068   /// \brief When true, disables the use of the stat cache within a
00069   /// precompiled header or AST file.
00070   bool DisableStatCache;
00071 
00072   /// \brief When true, a PCH with compiler errors will not be rejected.
00073   bool AllowPCHWithCompilerErrors;
00074 
00075   /// \brief Dump declarations that are deserialized from PCH, for testing.
00076   bool DumpDeserializedPCHDecls;
00077 
00078   /// \brief This is a set of names for decls that we do not want to be
00079   /// deserialized, and we emit an error if they are; for testing purposes.
00080   std::set<std::string> DeserializedPCHDeclsToErrorOn;
00081 
00082   /// \brief If non-zero, the implicit PCH include is actually a precompiled
00083   /// preamble that covers this number of bytes in the main source file.
00084   ///
00085   /// The boolean indicates whether the preamble ends at the start of a new
00086   /// line.
00087   std::pair<unsigned, bool> PrecompiledPreambleBytes;
00088   
00089   /// The implicit PTH input included at the start of the translation unit, or
00090   /// empty.
00091   std::string ImplicitPTHInclude;
00092 
00093   /// If given, a PTH cache file to use for speeding up header parsing.
00094   std::string TokenCache;
00095 
00096   /// \brief True if the SourceManager should report the original file name for
00097   /// contents of files that were remapped to other files. Defaults to true.
00098   bool RemappedFilesKeepOriginalName;
00099 
00100   /// \brief The set of file remappings, which take existing files on
00101   /// the system (the first part of each pair) and gives them the
00102   /// contents of other files on the system (the second part of each
00103   /// pair).
00104   std::vector<std::pair<std::string, std::string> >  RemappedFiles;
00105 
00106   /// \brief The set of file-to-buffer remappings, which take existing files
00107   /// on the system (the first part of each pair) and gives them the contents
00108   /// of the specified memory buffer (the second part of each pair).
00109   std::vector<std::pair<std::string, const llvm::MemoryBuffer *> > 
00110     RemappedFileBuffers;
00111   
00112   /// \brief Whether the compiler instance should retain (i.e., not free)
00113   /// the buffers associated with remapped files.
00114   ///
00115   /// This flag defaults to false; it can be set true only through direct
00116   /// manipulation of the compiler invocation object, in cases where the 
00117   /// compiler invocation and its buffers will be reused.
00118   bool RetainRemappedFileBuffers;
00119   
00120   /// \brief The Objective-C++ ARC standard library that we should support,
00121   /// by providing appropriate definitions to retrofit the standard library
00122   /// with support for lifetime-qualified pointers.
00123   ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary;
00124     
00125   /// \brief The path of modules being build, which is used to detect
00126   /// cycles in the module dependency graph as modules are being built.
00127   ///
00128   /// There is no way to set this value from the command line. If we ever need
00129   /// to do so (e.g., if on-demand module construction moves out-of-process),
00130   /// we can add a cc1-level option to do so.
00131   SmallVector<std::string, 2> ModuleBuildPath;
00132   
00133   typedef std::vector<std::pair<std::string, std::string> >::iterator
00134     remapped_file_iterator;
00135   typedef std::vector<std::pair<std::string, std::string> >::const_iterator
00136     const_remapped_file_iterator;
00137   remapped_file_iterator remapped_file_begin() { 
00138     return RemappedFiles.begin();
00139   }
00140   const_remapped_file_iterator remapped_file_begin() const {
00141     return RemappedFiles.begin();
00142   }
00143   remapped_file_iterator remapped_file_end() { 
00144     return RemappedFiles.end();
00145   }
00146   const_remapped_file_iterator remapped_file_end() const { 
00147     return RemappedFiles.end();
00148   }
00149 
00150   typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
00151                                   iterator remapped_file_buffer_iterator;
00152   typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
00153                             const_iterator const_remapped_file_buffer_iterator;
00154   remapped_file_buffer_iterator remapped_file_buffer_begin() {
00155     return RemappedFileBuffers.begin();
00156   }
00157   const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
00158     return RemappedFileBuffers.begin();
00159   }
00160   remapped_file_buffer_iterator remapped_file_buffer_end() {
00161     return RemappedFileBuffers.end();
00162   }
00163   const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
00164     return RemappedFileBuffers.end();
00165   }
00166   
00167 public:
00168   PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
00169                           DetailedRecordConditionalDirectives(false),
00170                           DisablePCHValidation(false), DisableStatCache(false),
00171                           AllowPCHWithCompilerErrors(false),
00172                           DumpDeserializedPCHDecls(false),
00173                           PrecompiledPreambleBytes(0, true),
00174                           RemappedFilesKeepOriginalName(true),
00175                           RetainRemappedFileBuffers(false),
00176                           ObjCXXARCStandardLibrary(ARCXX_nolib) { }
00177 
00178   void addMacroDef(StringRef Name) {
00179     Macros.push_back(std::make_pair(Name, false));
00180   }
00181   void addMacroUndef(StringRef Name) {
00182     Macros.push_back(std::make_pair(Name, true));
00183   }
00184   void addRemappedFile(StringRef From, StringRef To) {
00185     RemappedFiles.push_back(std::make_pair(From, To));
00186   }
00187   
00188   remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
00189     return RemappedFiles.erase(Remapped);
00190   }
00191   
00192   void addRemappedFile(StringRef From, const llvm::MemoryBuffer * To) {
00193     RemappedFileBuffers.push_back(std::make_pair(From, To));
00194   }
00195   
00196   remapped_file_buffer_iterator
00197   eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
00198     return RemappedFileBuffers.erase(Remapped);
00199   }
00200   
00201   void clearRemappedFiles() {
00202     RemappedFiles.clear();
00203     RemappedFileBuffers.clear();
00204   }
00205   
00206   /// \brief Reset any options that are not considered when building a
00207   /// module.
00208   void resetNonModularOptions() {
00209     Includes.clear();
00210     MacroIncludes.clear();
00211     ChainedIncludes.clear();
00212     DumpDeserializedPCHDecls = false;
00213     ImplicitPCHInclude.clear();
00214     ImplicitPTHInclude.clear();
00215     TokenCache.clear();
00216     RetainRemappedFileBuffers = true;
00217     PrecompiledPreambleBytes.first = 0;
00218     PrecompiledPreambleBytes.second = 0;
00219   }
00220 };
00221 
00222 } // end namespace clang
00223 
00224 #endif