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 When true, disables most of the normal validation performed on
48 /// precompiled headers.
49 bool DisablePCHValidation;
51 /// \brief When true, disables the use of the stat cache within a
52 /// precompiled header or AST file.
53 bool DisableStatCache;
55 /// \brief Dump declarations that are deserialized from PCH, for testing.
56 bool DumpDeserializedPCHDecls;
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;
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.
65 /// The boolean indicates whether the preamble ends at the start of a new
67 std::pair<unsigned, bool> PrecompiledPreambleBytes;
69 /// The implicit PTH input included at the start of the translation unit, or
71 std::string ImplicitPTHInclude;
73 /// If given, a PTH cache file to use for speeding up header parsing.
74 std::string TokenCache;
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
80 std::vector<std::pair<std::string, std::string> > RemappedFiles;
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 *> >
88 /// \brief Whether the compiler instance should retain (i.e., not free)
89 /// the buffers associated with remapped files.
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;
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();
103 const_remapped_file_iterator remapped_file_begin() const {
104 return RemappedFiles.begin();
106 remapped_file_iterator remapped_file_end() {
107 return RemappedFiles.end();
109 const_remapped_file_iterator remapped_file_end() const {
110 return RemappedFiles.end();
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();
120 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
121 return RemappedFileBuffers.begin();
123 remapped_file_buffer_iterator remapped_file_buffer_end() {
124 return RemappedFileBuffers.end();
126 const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
127 return RemappedFileBuffers.end();
131 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
132 DisablePCHValidation(false), DisableStatCache(false),
133 DumpDeserializedPCHDecls(false),
134 PrecompiledPreambleBytes(0, true),
135 RetainRemappedFileBuffers(false) { }
137 void addMacroDef(llvm::StringRef Name) {
138 Macros.push_back(std::make_pair(Name, false));
140 void addMacroUndef(llvm::StringRef Name) {
141 Macros.push_back(std::make_pair(Name, true));
143 void addRemappedFile(llvm::StringRef From, llvm::StringRef To) {
144 RemappedFiles.push_back(std::make_pair(From, To));
147 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
148 return RemappedFiles.erase(Remapped);
151 void addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To) {
152 RemappedFileBuffers.push_back(std::make_pair(From, To));
155 remapped_file_buffer_iterator
156 eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
157 return RemappedFileBuffers.erase(Remapped);
160 void clearRemappedFiles() {
161 RemappedFiles.clear();
162 RemappedFileBuffers.clear();
166 } // end namespace clang