]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/PreprocessorOptions.h
Merge wpa_supplicant and hostapd 0.7.3.
[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
19 namespace llvm {
20   class MemoryBuffer;
21 }
22
23 namespace clang {
24
25 class Preprocessor;
26 class LangOptions;
27
28 /// PreprocessorOptions - This class is used for passing the various options
29 /// used in preprocessor initialization to InitializePreprocessor().
30 class PreprocessorOptions {
31 public:
32   std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
33   std::vector<std::string> Includes;
34   std::vector<std::string> MacroIncludes;
35
36   unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
37                               /// and target specific predefines.
38
39   unsigned DetailedRecord : 1; /// Whether we should maintain a detailed
40                                /// record of all macro definitions and
41                                /// instantiations.
42   
43   /// The implicit PCH included at the start of the translation unit, or empty.
44   std::string ImplicitPCHInclude;
45
46   /// \brief When true, disables most of the normal validation performed on
47   /// precompiled headers.
48   bool DisablePCHValidation;
49   
50   /// \brief If non-zero, the implicit PCH include is actually a precompiled
51   /// preamble that covers this number of bytes in the main source file.
52   ///
53   /// The boolean indicates whether the preamble ends at the start of a new
54   /// line.
55   std::pair<unsigned, bool> PrecompiledPreambleBytes;
56   
57   /// The implicit PTH input included at the start of the translation unit, or
58   /// empty.
59   std::string ImplicitPTHInclude;
60
61   /// If given, a PTH cache file to use for speeding up header parsing.
62   std::string TokenCache;
63
64   /// \brief The set of file remappings, which take existing files on
65   /// the system (the first part of each pair) and gives them the
66   /// contents of other files on the system (the second part of each
67   /// pair).
68   std::vector<std::pair<std::string, std::string> >  RemappedFiles;
69
70   /// \brief The set of file-to-buffer remappings, which take existing files
71   /// on the system (the first part of each pair) and gives them the contents
72   /// of the specified memory buffer (the second part of each pair).
73   std::vector<std::pair<std::string, const llvm::MemoryBuffer *> > 
74     RemappedFileBuffers;
75   
76   /// \brief Whether the compiler instance should retain (i.e., not free)
77   /// the buffers associated with remapped files.
78   ///
79   /// This flag defaults to false; it can be set true only through direct
80   /// manipulation of the compiler invocation object, in cases where the 
81   /// compiler invocation and its buffers will be reused.
82   bool RetainRemappedFileBuffers;
83   
84   typedef std::vector<std::pair<std::string, std::string> >::iterator
85     remapped_file_iterator;
86   typedef std::vector<std::pair<std::string, std::string> >::const_iterator
87     const_remapped_file_iterator;
88   remapped_file_iterator remapped_file_begin() { 
89     return RemappedFiles.begin();
90   }
91   const_remapped_file_iterator remapped_file_begin() const {
92     return RemappedFiles.begin();
93   }
94   remapped_file_iterator remapped_file_end() { 
95     return RemappedFiles.end();
96   }
97   const_remapped_file_iterator remapped_file_end() const { 
98     return RemappedFiles.end();
99   }
100
101   typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
102                                   iterator remapped_file_buffer_iterator;
103   typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
104                             const_iterator const_remapped_file_buffer_iterator;
105   remapped_file_buffer_iterator remapped_file_buffer_begin() {
106     return RemappedFileBuffers.begin();
107   }
108   const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
109     return RemappedFileBuffers.begin();
110   }
111   remapped_file_buffer_iterator remapped_file_buffer_end() {
112     return RemappedFileBuffers.end();
113   }
114   const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
115     return RemappedFileBuffers.end();
116   }
117   
118 public:
119   PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
120                           DisablePCHValidation(false),
121                           PrecompiledPreambleBytes(0, true),
122                           RetainRemappedFileBuffers(false) { }
123
124   void addMacroDef(llvm::StringRef Name) {
125     Macros.push_back(std::make_pair(Name, false));
126   }
127   void addMacroUndef(llvm::StringRef Name) {
128     Macros.push_back(std::make_pair(Name, true));
129   }
130   void addRemappedFile(llvm::StringRef From, llvm::StringRef To) {
131     RemappedFiles.push_back(std::make_pair(From, To));
132   }
133   
134   remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
135     return RemappedFiles.erase(Remapped);
136   }
137   
138   void addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To) {
139     RemappedFileBuffers.push_back(std::make_pair(From, To));
140   }
141   
142   remapped_file_buffer_iterator
143   eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
144     return RemappedFileBuffers.erase(Remapped);
145   }
146   
147   void clearRemappedFiles() {
148     RemappedFiles.clear();
149     RemappedFileBuffers.clear();
150   }
151 };
152
153 } // end namespace clang
154
155 #endif