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"
28 /// PreprocessorOptions - This class is used for passing the various options
29 /// used in preprocessor initialization to InitializePreprocessor().
30 class PreprocessorOptions {
32 std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
33 std::vector<std::string> Includes;
34 std::vector<std::string> MacroIncludes;
36 unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
37 /// and target specific predefines.
39 unsigned DetailedRecord : 1; /// Whether we should maintain a detailed
40 /// record of all macro definitions and
43 /// The implicit PCH included at the start of the translation unit, or empty.
44 std::string ImplicitPCHInclude;
46 /// \brief When true, disables most of the normal validation performed on
47 /// precompiled headers.
48 bool DisablePCHValidation;
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.
53 /// The boolean indicates whether the preamble ends at the start of a new
55 std::pair<unsigned, bool> PrecompiledPreambleBytes;
57 /// The implicit PTH input included at the start of the translation unit, or
59 std::string ImplicitPTHInclude;
61 /// If given, a PTH cache file to use for speeding up header parsing.
62 std::string TokenCache;
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
68 std::vector<std::pair<std::string, std::string> > RemappedFiles;
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 *> >
76 /// \brief Whether the compiler instance should retain (i.e., not free)
77 /// the buffers associated with remapped files.
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;
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();
91 const_remapped_file_iterator remapped_file_begin() const {
92 return RemappedFiles.begin();
94 remapped_file_iterator remapped_file_end() {
95 return RemappedFiles.end();
97 const_remapped_file_iterator remapped_file_end() const {
98 return RemappedFiles.end();
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();
108 const_remapped_file_buffer_iterator remapped_file_buffer_begin() const {
109 return RemappedFileBuffers.begin();
111 remapped_file_buffer_iterator remapped_file_buffer_end() {
112 return RemappedFileBuffers.end();
114 const_remapped_file_buffer_iterator remapped_file_buffer_end() const {
115 return RemappedFileBuffers.end();
119 PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
120 DisablePCHValidation(false),
121 PrecompiledPreambleBytes(0, true),
122 RetainRemappedFileBuffers(false) { }
124 void addMacroDef(llvm::StringRef Name) {
125 Macros.push_back(std::make_pair(Name, false));
127 void addMacroUndef(llvm::StringRef Name) {
128 Macros.push_back(std::make_pair(Name, true));
130 void addRemappedFile(llvm::StringRef From, llvm::StringRef To) {
131 RemappedFiles.push_back(std::make_pair(From, To));
134 remapped_file_iterator eraseRemappedFile(remapped_file_iterator Remapped) {
135 return RemappedFiles.erase(Remapped);
138 void addRemappedFile(llvm::StringRef From, const llvm::MemoryBuffer * To) {
139 RemappedFileBuffers.push_back(std::make_pair(From, To));
142 remapped_file_buffer_iterator
143 eraseRemappedFile(remapped_file_buffer_iterator Remapped) {
144 return RemappedFileBuffers.erase(Remapped);
147 void clearRemappedFiles() {
148 RemappedFiles.clear();
149 RemappedFileBuffers.clear();
153 } // end namespace clang