Home | History | Annotate | Download | only in Frontend
      1 //===--- PreprocessorOptions.h ----------------------------------*- 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 #ifndef LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_
     11 #define LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_
     12 
     13 #include "llvm/ADT/StringRef.h"
     14 #include <cassert>
     15 #include <string>
     16 #include <utility>
     17 #include <vector>
     18 #include <set>
     19 
     20 namespace llvm {
     21   class MemoryBuffer;
     22 }
     23 
     24 namespace clang {
     25 
     26 class Preprocessor;
     27 class LangOptions;
     28 
     29 /// \brief Enumerate the kinds of standard library that
     30 enum ObjCXXARCStandardLibraryKind {
     31   ARCXX_nolib,
     32   /// \brief libc++
     33   ARCXX_libcxx,
     34   /// \brief libstdc++
     35   ARCXX_libstdcxx
     36 };
     37 
     38 /// PreprocessorOptions - This class is used for passing the various options
     39 /// used in preprocessor initialization to InitializePreprocessor().
     40 class PreprocessorOptions {
     41 public:
     42   std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
     43   std::vector<std::string> Includes;
     44   std::vector<std::string> MacroIncludes;
     45 
     46   unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
     47                               /// and target specific predefines.
     48 
     49   unsigned DetailedRecord : 1; /// Whether we should maintain a detailed
     50                                /// record of all macro definitions and
     51                                /// expansions.
     52 
     53   /// \brief Whether we should automatically translate #include or #import
     54   /// operations into module imports when possible.
     55   unsigned AutoModuleImport : 1;
     56 
     57   /// \brief Whether the detailed preprocessing record includes nested macro
     58   /// expansions.
     59   unsigned DetailedRecordIncludesNestedMacroExpansions : 1;
     60 
     61   /// The implicit PCH included at the start of the translation unit, or empty.
     62   std::string ImplicitPCHInclude;
     63 
     64   /// \brief Headers that will be converted to chained PCHs in memory.
     65   std::vector<std::string> ChainedIncludes;
     66 
     67   /// \brief When true, disables most of the normal validation performed on
     68   /// precompiled headers.
     69   bool DisablePCHValidation;
     70 
     71   /// \brief When true, disables the use of the stat cache within a
     72   /// precompiled header or AST file.
     73   bool DisableStatCache;
     74 
     75   /// \brief Dump declarations that are deserialized from PCH, for testing.
     76   bool DumpDeserializedPCHDecls;
     77 
     78   /// \brief This is a set of names for decls that we do not want to be
     79   /// deserialized, and we emit an error if they are; for testing purposes.
     80   std::set<std::string> DeserializedPCHDeclsToErrorOn;
     81 
     82   /// \brief If non-zero, the implicit PCH include is actually a precompiled
     83   /// preamble that covers this number of bytes in the main source file.
     84   ///
     85   /// The boolean indicates whether the preamble ends at the start of a new
     86   /// line.
     87   std::pair<unsigned, bool> PrecompiledPreambleBytes;
     88 
     89   /// The implicit PTH input included at the start of the translation unit, or
     90   /// empty.
     91   std::string ImplicitPTHInclude;
     92 
     93   /// If given, a PTH cache file to use for speeding up header parsing.
     94   std::string TokenCache;
     95 
     96   /// \brief True if the SourceManager should report the original file name for
     97   /// contents of files that were remapped to other files. Defaults to true.
     98   bool RemappedFilesKeepOriginalName;
     99 
    100   /// \brief The set of file remappings, which take existing files on
    101   /// the system (the first part of each pair) and gives them the
    102   /// contents of other files on the system (the second part of each
    103   /// pair).
    104   std::vector<std::pair<std::string, std::string> >  RemappedFiles;
    105 
    106   /// \brief The set of file-to-buffer remappings, which take existing files
    107   /// on the system (the first part of each pair) and gives them the contents
    108   /// of the specified memory buffer (the second part of each pair).
    109   std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >
    110     RemappedFileBuffers;
    111 
    112   /// \brief Whether the compiler instance should retain (i.e., not free)
    113   /// the buffers associated with remapped files.
    114   ///
    115   /// This flag defaults to false; it can be set true only through direct
    116   /// manipulation of the compiler invocation object, in cases where the
    117   /// compiler invocation and its buffers will be reused.
    118   bool RetainRemappedFileBuffers;
    119 
    120   /// \brief The Objective-C++ ARC standard library that we should support,
    121   /// by providing appropriate definitions to retrofit the standard library
    122   /// with support for lifetime-qualified pointers.
    123   ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary;
    124 
    125   /// \brief The path of modules being build, which is used to detect
    126   /// cycles in the module dependency graph as modules are being built.
    127   ///
    128   /// There is no way to set this value from the command line. If we ever need
    129   /// to do so (e.g., if on-demand module construction moves out-of-process),
    130   /// we can add a cc1-level option to do so.
    131   SmallVector<std::string, 2> ModuleBuildPath;
    132 
    133   typedef std::vector<std::pair<std::string, std::string> >::iterator
    134     remapped_file_iterator;
    135   typedef std::vector<std::pair<std::string, std::string> >::const_iterator
    136     const_remapped_file_iterator;
    137   remapped_file_iterator remapped_file_begin() {
    138     return RemappedFiles.begin();
    139   }
    140   const_remapped_file_iterator remapped_file_begin() const {
    141     return RemappedFiles.begin();
    142   }
    143   remapped_file_iterator remapped_file_end() {
    144     return RemappedFiles.end();
    145   }
    146   const_remapped_file_iterator remapped_file_end() const {
    147     return RemappedFiles.end();
    148   }
    149 
    150   typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
    151                                   iterator remapped_file_buffer_iterator;
    152   typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
    153                             const_iterator const_remapped_file_buffer_iterator;
    154   remapped_file_buffer_iterator remapped_file_buffer_begin() {
    155     return RemappedFileBuffers.begin();
    156   }
    157   const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
    158     return RemappedFileBuffers.begin();
    159   }
    160   remapped_file_buffer_iterator remapped_file_buffer_end() {
    161     return RemappedFileBuffers.end();
    162   }
    163   const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
    164     return RemappedFileBuffers.end();
    165   }
    166 
    167 public:
    168   PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
    169                           AutoModuleImport(false),
    170                           DetailedRecordIncludesNestedMacroExpansions(true),
    171                           DisablePCHValidation(false), DisableStatCache(false),
    172                           DumpDeserializedPCHDecls(false),
    173                           PrecompiledPreambleBytes(0, true),
    174                           RemappedFilesKeepOriginalName(true),
    175                           RetainRemappedFileBuffers(false),
    176                           ObjCXXARCStandardLibrary(ARCXX_nolib) { }
    177 
    178   void addMacroDef(StringRef Name) {
    179     Macros.push_back(std::make_pair(Name, false));
    180   }
    181   void addMacroUndef(StringRef Name) {
    182     Macros.push_back(std::make_pair(Name, true));
    183   }
    184   void addRemappedFile(StringRef From, StringRef To) {
    185     RemappedFiles.push_back(std::make_pair(From, To));
    186   }
    187 
    188   remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
    189     return RemappedFiles.erase(Remapped);
    190   }
    191 
    192   void addRemappedFile(StringRef From, const llvm::MemoryBuffer * To) {
    193     RemappedFileBuffers.push_back(std::make_pair(From, To));
    194   }
    195 
    196   remapped_file_buffer_iterator
    197   eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
    198     return RemappedFileBuffers.erase(Remapped);
    199   }
    200 
    201   void clearRemappedFiles() {
    202     RemappedFiles.clear();
    203     RemappedFileBuffers.clear();
    204   }
    205 
    206   /// \brief Reset any options that are not considered when building a
    207   /// module.
    208   void resetNonModularOptions() {
    209     Includes.clear();
    210     MacroIncludes.clear();
    211     ChainedIncludes.clear();
    212     DumpDeserializedPCHDecls = false;
    213     ImplicitPCHInclude.clear();
    214     ImplicitPTHInclude.clear();
    215     TokenCache.clear();
    216     RetainRemappedFileBuffers = true;
    217     PrecompiledPreambleBytes.first = 0;
    218     PrecompiledPreambleBytes.second = 0;
    219   }
    220 };
    221 
    222 } // end namespace clang
    223 
    224 #endif
    225