]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/PreprocessorOptions.h
Upgrade our copy of llvm/clang to r132879, from upstream's trunk.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Frontend / PreprocessorOptions.h
1 //===--- PreprocessorOptionms.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 /// PreprocessorOptions - This class is used for passing the various options
30 /// used in preprocessor initialization to InitializePreprocessor().
31 class PreprocessorOptions {
32 public:
33   std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
34   std::vector<std::string> Includes;
35   std::vector<std::string> MacroIncludes;
36
37   unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
38                               /// and target specific predefines.
39
40   unsigned DetailedRecord : 1; /// Whether we should maintain a detailed
41                                /// record of all macro definitions and
42                                /// instantiations.
43   
44   /// \brief Whether the detailed preprocessing record includes nested macro 
45   /// instantiations.
46   unsigned DetailedRecordIncludesNestedMacroInstantiations : 1;
47   
48   /// The implicit PCH included at the start of the translation unit, or empty.
49   std::string ImplicitPCHInclude;
50
51   /// \brief Headers that will be converted to chained PCHs in memory.
52   std::vector<std::string> ChainedIncludes;
53
54   /// \brief When true, disables most of the normal validation performed on
55   /// precompiled headers.
56   bool DisablePCHValidation;
57
58   /// \brief When true, disables the use of the stat cache within a
59   /// precompiled header or AST file.
60   bool DisableStatCache;
61
62   /// \brief Dump declarations that are deserialized from PCH, for testing.
63   bool DumpDeserializedPCHDecls;
64
65   /// \brief This is a set of names for decls that we do not want to be
66   /// deserialized, and we emit an error if they are; for testing purposes.
67   std::set<std::string> DeserializedPCHDeclsToErrorOn;
68
69   /// \brief If non-zero, the implicit PCH include is actually a precompiled
70   /// preamble that covers this number of bytes in the main source file.
71   ///
72   /// The boolean indicates whether the preamble ends at the start of a new
73   /// line.
74   std::pair<unsigned, bool> PrecompiledPreambleBytes;
75   
76   /// The implicit PTH input included at the start of the translation unit, or
77   /// empty.
78   std::string ImplicitPTHInclude;
79
80   /// If given, a PTH cache file to use for speeding up header parsing.
81   std::string TokenCache;
82
83   /// \brief True if the SourceManager should report the original file name for
84   /// contents of files that were remapped to other files. Defaults to true.
85   bool RemappedFilesKeepOriginalName;
86
87   /// \brief The set of file remappings, which take existing files on
88   /// the system (the first part of each pair) and gives them the
89   /// contents of other files on the system (the second part of each
90   /// pair).
91   std::vector<std::pair<std::string, std::string> >  RemappedFiles;
92
93   /// \brief The set of file-to-buffer remappings, which take existing files
94   /// on the system (the first part of each pair) and gives them the contents
95   /// of the specified memory buffer (the second part of each pair).
96   std::vector<std::pair<std::string, const llvm::MemoryBuffer *> > 
97     RemappedFileBuffers;
98   
99   /// \brief Whether the compiler instance should retain (i.e., not free)
100   /// the buffers associated with remapped files.
101   ///
102   /// This flag defaults to false; it can be set true only through direct
103   /// manipulation of the compiler invocation object, in cases where the 
104   /// compiler invocation and its buffers will be reused.
105   bool RetainRemappedFileBuffers;
106   
107   typedef std::vector<std::pair<std::string, std::string> >::iterator
108     remapped_file_iterator;
109   typedef std::vector<std::pair<std::string, std::string> >::const_iterator
110     const_remapped_file_iterator;
111   remapped_file_iterator remapped_file_begin() { 
112     return RemappedFiles.begin();
113   }
114   const_remapped_file_iterator remapped_file_begin() const {
115     return RemappedFiles.begin();
116   }
117   remapped_file_iterator remapped_file_end() { 
118     return RemappedFiles.end();
119   }
120   const_remapped_file_iterator remapped_file_end() const { 
121     return RemappedFiles.end();
122   }
123
124   typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
125                                   iterator remapped_file_buffer_iterator;
126   typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
127                             const_iterator const_remapped_file_buffer_iterator;
128   remapped_file_buffer_iterator remapped_file_buffer_begin() {
129     return RemappedFileBuffers.begin();
130   }
131   const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
132     return RemappedFileBuffers.begin();
133   }
134   remapped_file_buffer_iterator remapped_file_buffer_end() {
135     return RemappedFileBuffers.end();
136   }
137   const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
138     return RemappedFileBuffers.end();
139   }
140   
141 public:
142   PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
143                           DetailedRecordIncludesNestedMacroInstantiations(true),
144                           DisablePCHValidation(false), DisableStatCache(false),
145                           DumpDeserializedPCHDecls(false),
146                           PrecompiledPreambleBytes(0, true),
147                           RemappedFilesKeepOriginalName(true),
148                           RetainRemappedFileBuffers(false) { }
149
150   void addMacroDef(llvm::StringRef Name) {
151     Macros.push_back(std::make_pair(Name, false));
152   }
153   void addMacroUndef(llvm::StringRef Name) {
154     Macros.push_back(std::make_pair(Name, true));
155   }
156   void addRemappedFile(llvm::StringRef From, llvm::StringRef To) {
157     RemappedFiles.push_back(std::make_pair(From, To));
158   }
159   
160   remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
161     return RemappedFiles.erase(Remapped);
162   }
163   
164   void addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To) {
165     RemappedFileBuffers.push_back(std::make_pair(From, To));
166   }
167   
168   remapped_file_buffer_iterator
169   eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
170     return RemappedFileBuffers.erase(Remapped);
171   }
172   
173   void clearRemappedFiles() {
174     RemappedFiles.clear();
175     RemappedFileBuffers.clear();
176   }
177 };
178
179 } // end namespace clang
180
181 #endif