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 /// \brief Whether the detailed preprocessing record includes nested macro
46 unsigned DetailedRecordIncludesNestedMacroInstantiations : 1;
48 /// The implicit PCH included at the start of the translation unit, or empty.
49 std::string ImplicitPCHInclude;
51 /// \brief Headers that will be converted to chained PCHs in memory.
52 std::vector<std::string> ChainedIncludes;
54 /// \brief When true, disables most of the normal validation performed on
55 /// precompiled headers.
56 bool DisablePCHValidation;
58 /// \brief When true, disables the use of the stat cache within a
59 /// precompiled header or AST file.
60 bool DisableStatCache;
62 /// \brief Dump declarations that are deserialized from PCH, for testing.
63 bool DumpDeserializedPCHDecls;
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;
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.
72 /// The boolean indicates whether the preamble ends at the start of a new
74 std::pair<unsigned, bool> PrecompiledPreambleBytes;
76 /// The implicit PTH input included at the start of the translation unit, or
78 std::string ImplicitPTHInclude;
80 /// If given, a PTH cache file to use for speeding up header parsing.
81 std::string TokenCache;
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;
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
91 std::vector<std::pair<std::string, std::string> > RemappedFiles;
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 *> >
99 /// \brief Whether the compiler instance should retain (i.e., not free)
100 /// the buffers associated with remapped files.
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;
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();
114 const_remapped_file_iterator remapped_file_begin() const {
115 return RemappedFiles.begin();
117 remapped_file_iterator remapped_file_end() {
118 return RemappedFiles.end();
120 const_remapped_file_iterator remapped_file_end() const {
121 return RemappedFiles.end();
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();
131 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
132 return RemappedFileBuffers.begin();
134 remapped_file_buffer_iterator remapped_file_buffer_end() {
135 return RemappedFileBuffers.end();
137 const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
138 return RemappedFileBuffers.end();
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) { }
150 void addMacroDef(llvm::StringRef Name) {
151 Macros.push_back(std::make_pair(Name, false));
153 void addMacroUndef(llvm::StringRef Name) {
154 Macros.push_back(std::make_pair(Name, true));
156 void addRemappedFile(llvm::StringRef From, llvm::StringRef To) {
157 RemappedFiles.push_back(std::make_pair(From, To));
160 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
161 return RemappedFiles.erase(Remapped);
164 void addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To) {
165 RemappedFileBuffers.push_back(std::make_pair(From, To));
168 remapped_file_buffer_iterator
169 eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
170 return RemappedFileBuffers.erase(Remapped);
173 void clearRemappedFiles() {
174 RemappedFiles.clear();
175 RemappedFileBuffers.clear();
179 } // end namespace clang