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