1 //===--- PreprocessorOptionms.h ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_
11 #define LLVM_CLANG_FRONTEND_PREPROCESSOROPTIONS_H_
13 #include "llvm/ADT/StringRef.h"
29 /// PreprocessorOptions - This class is used for passing the various options
30 /// used in preprocessor initialization to InitializePreprocessor().
31 class PreprocessorOptions {
33 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
34 std::vector<std::string> Includes;
35 std::vector<std::string> MacroIncludes;
37 unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
38 /// and target specific predefines.
40 unsigned DetailedRecord : 1; /// Whether we should maintain a detailed
41 /// record of all macro definitions and
44 /// The implicit PCH included at the start of the translation unit, or empty.
45 std::string ImplicitPCHInclude;
47 /// \brief Headers that will be converted to chained PCHs in memory.
48 std::vector<std::string> ChainedIncludes;
50 /// \brief When true, disables most of the normal validation performed on
51 /// precompiled headers.
52 bool DisablePCHValidation;
54 /// \brief When true, disables the use of the stat cache within a
55 /// precompiled header or AST file.
56 bool DisableStatCache;
58 /// \brief Dump declarations that are deserialized from PCH, for testing.
59 bool DumpDeserializedPCHDecls;
61 /// \brief This is a set of names for decls that we do not want to be
62 /// deserialized, and we emit an error if they are; for testing purposes.
63 std::set<std::string> DeserializedPCHDeclsToErrorOn;
65 /// \brief If non-zero, the implicit PCH include is actually a precompiled
66 /// preamble that covers this number of bytes in the main source file.
68 /// The boolean indicates whether the preamble ends at the start of a new
70 std::pair<unsigned, bool> PrecompiledPreambleBytes;
72 /// The implicit PTH input included at the start of the translation unit, or
74 std::string ImplicitPTHInclude;
76 /// If given, a PTH cache file to use for speeding up header parsing.
77 std::string TokenCache;
79 /// \brief True if the SourceManager should report the original file name for
80 /// contents of files that were remapped to other files. Defaults to true.
81 bool RemappedFilesKeepOriginalName;
83 /// \brief The set of file remappings, which take existing files on
84 /// the system (the first part of each pair) and gives them the
85 /// contents of other files on the system (the second part of each
87 std::vector<std::pair<std::string, std::string> > RemappedFiles;
89 /// \brief The set of file-to-buffer remappings, which take existing files
90 /// on the system (the first part of each pair) and gives them the contents
91 /// of the specified memory buffer (the second part of each pair).
92 std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >
95 /// \brief Whether the compiler instance should retain (i.e., not free)
96 /// the buffers associated with remapped files.
98 /// This flag defaults to false; it can be set true only through direct
99 /// manipulation of the compiler invocation object, in cases where the
100 /// compiler invocation and its buffers will be reused.
101 bool RetainRemappedFileBuffers;
103 typedef std::vector<std::pair<std::string, std::string> >::iterator
104 remapped_file_iterator;
105 typedef std::vector<std::pair<std::string, std::string> >::const_iterator
106 const_remapped_file_iterator;
107 remapped_file_iterator remapped_file_begin() {
108 return RemappedFiles.begin();
110 const_remapped_file_iterator remapped_file_begin() const {
111 return RemappedFiles.begin();
113 remapped_file_iterator remapped_file_end() {
114 return RemappedFiles.end();
116 const_remapped_file_iterator remapped_file_end() const {
117 return RemappedFiles.end();
120 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
121 iterator remapped_file_buffer_iterator;
122 typedef std::vector<std::pair<std::string, const llvm::MemoryBuffer *> >::
123 const_iterator const_remapped_file_buffer_iterator;
124 remapped_file_buffer_iterator remapped_file_buffer_begin() {
125 return RemappedFileBuffers.begin();
127 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
128 return RemappedFileBuffers.begin();
130 remapped_file_buffer_iterator remapped_file_buffer_end() {
131 return RemappedFileBuffers.end();
133 const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
134 return RemappedFileBuffers.end();
138 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
139 DisablePCHValidation(false), DisableStatCache(false),
140 DumpDeserializedPCHDecls(false),
141 PrecompiledPreambleBytes(0, true),
142 RemappedFilesKeepOriginalName(true),
143 RetainRemappedFileBuffers(false) { }
145 void addMacroDef(llvm::StringRef Name) {
146 Macros.push_back(std::make_pair(Name, false));
148 void addMacroUndef(llvm::StringRef Name) {
149 Macros.push_back(std::make_pair(Name, true));
151 void addRemappedFile(llvm::StringRef From, llvm::StringRef To) {
152 RemappedFiles.push_back(std::make_pair(From, To));
155 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
156 return RemappedFiles.erase(Remapped);
159 void addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To) {
160 RemappedFileBuffers.push_back(std::make_pair(From, To));
163 remapped_file_buffer_iterator
164 eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
165 return RemappedFileBuffers.erase(Remapped);
168 void clearRemappedFiles() {
169 RemappedFiles.clear();
170 RemappedFileBuffers.clear();
174 } // end namespace clang