clang  6.0.0svn
PreprocessorOptions.h
Go to the documentation of this file.
1 //===--- PreprocessorOptions.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_LEX_PREPROCESSOROPTIONS_H_
11 #define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
12 
14 #include "llvm/ADT/IntrusiveRefCntPtr.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/StringSet.h"
17 #include <cassert>
18 #include <set>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 namespace llvm {
24  class MemoryBuffer;
25 }
26 
27 namespace clang {
28 
29 class Preprocessor;
30 class LangOptions;
31 
32 /// \brief Enumerate the kinds of standard library that
35  /// \brief libc++
37  /// \brief libstdc++
39 };
40 
41 /// PreprocessorOptions - This class is used for passing the various options
42 /// used in preprocessor initialization to InitializePreprocessor().
44 public:
45  std::vector<std::pair<std::string, bool/*isUndef*/> > Macros;
46  std::vector<std::string> Includes;
47  std::vector<std::string> MacroIncludes;
48 
49  /// \brief Initialize the preprocessor with the compiler and target specific
50  /// predefines.
51  unsigned UsePredefines : 1;
52 
53  /// \brief Whether we should maintain a detailed record of all macro
54  /// definitions and expansions.
55  unsigned DetailedRecord : 1;
56 
57  /// The implicit PCH included at the start of the translation unit, or empty.
58  std::string ImplicitPCHInclude;
59 
60  /// \brief Headers that will be converted to chained PCHs in memory.
61  std::vector<std::string> ChainedIncludes;
62 
63  /// \brief When true, disables most of the normal validation performed on
64  /// precompiled headers.
66 
67  /// \brief When true, a PCH with compiler errors will not be rejected.
69 
70  /// \brief Dump declarations that are deserialized from PCH, for testing.
72 
73  /// \brief This is a set of names for decls that we do not want to be
74  /// deserialized, and we emit an error if they are; for testing purposes.
75  std::set<std::string> DeserializedPCHDeclsToErrorOn;
76 
77  /// \brief If non-zero, the implicit PCH include is actually a precompiled
78  /// preamble that covers this number of bytes in the main source file.
79  ///
80  /// The boolean indicates whether the preamble ends at the start of a new
81  /// line.
82  std::pair<unsigned, bool> PrecompiledPreambleBytes;
83 
84  /// \brief True indicates that a preamble is being generated.
85  ///
86  /// When the lexer is done, one of the things that need to be preserved is the
87  /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when
88  /// processing the rest of the file.
90 
91  /// The implicit PTH input included at the start of the translation unit, or
92  /// empty.
93  std::string ImplicitPTHInclude;
94 
95  /// If given, a PTH cache file to use for speeding up header parsing.
96  std::string TokenCache;
97 
98  /// When enabled, preprocessor is in a mode for parsing a single file only.
99  ///
100  /// Disables #includes of other files and if there are unresolved identifiers
101  /// in preprocessor directive conditions it causes all blocks to be parsed so
102  /// that the client can get the maximum amount of information from the parser.
103  bool SingleFileParseMode = false;
104 
105  /// When enabled, the preprocessor will construct editor placeholder tokens.
106  bool LexEditorPlaceholders = true;
107 
108  /// \brief True if the SourceManager should report the original file name for
109  /// contents of files that were remapped to other files. Defaults to true.
111 
112  /// \brief The set of file remappings, which take existing files on
113  /// the system (the first part of each pair) and gives them the
114  /// contents of other files on the system (the second part of each
115  /// pair).
116  std::vector<std::pair<std::string, std::string>> RemappedFiles;
117 
118  /// \brief The set of file-to-buffer remappings, which take existing files
119  /// on the system (the first part of each pair) and gives them the contents
120  /// of the specified memory buffer (the second part of each pair).
121  std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers;
122 
123  /// \brief Whether the compiler instance should retain (i.e., not free)
124  /// the buffers associated with remapped files.
125  ///
126  /// This flag defaults to false; it can be set true only through direct
127  /// manipulation of the compiler invocation object, in cases where the
128  /// compiler invocation and its buffers will be reused.
130 
131  /// \brief The Objective-C++ ARC standard library that we should support,
132  /// by providing appropriate definitions to retrofit the standard library
133  /// with support for lifetime-qualified pointers.
135 
136  /// \brief Records the set of modules
138  llvm::StringSet<> Failed;
139 
140  public:
141  bool hasAlreadyFailed(StringRef module) {
142  return Failed.count(module) > 0;
143  }
144 
145  void addFailed(StringRef module) {
146  Failed.insert(module);
147  }
148  };
149 
150  /// \brief The set of modules that failed to build.
151  ///
152  /// This pointer will be shared among all of the compiler instances created
153  /// to (re)build modules, so that once a module fails to build anywhere,
154  /// other instances will see that the module has failed and won't try to
155  /// build it again.
156  std::shared_ptr<FailedModulesSet> FailedModules;
157 
158 public:
159  PreprocessorOptions() : UsePredefines(true), DetailedRecord(false),
160  DisablePCHValidation(false),
161  AllowPCHWithCompilerErrors(false),
162  DumpDeserializedPCHDecls(false),
163  PrecompiledPreambleBytes(0, false),
164  GeneratePreamble(false),
165  RemappedFilesKeepOriginalName(true),
166  RetainRemappedFileBuffers(false),
167  ObjCXXARCStandardLibrary(ARCXX_nolib) { }
168 
169  void addMacroDef(StringRef Name) { Macros.emplace_back(Name, false); }
170  void addMacroUndef(StringRef Name) { Macros.emplace_back(Name, true); }
171  void addRemappedFile(StringRef From, StringRef To) {
172  RemappedFiles.emplace_back(From, To);
173  }
174 
175  void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) {
176  RemappedFileBuffers.emplace_back(From, To);
177  }
178 
180  RemappedFiles.clear();
181  RemappedFileBuffers.clear();
182  }
183 
184  /// \brief Reset any options that are not considered when building a
185  /// module.
187  Includes.clear();
188  MacroIncludes.clear();
189  ChainedIncludes.clear();
190  DumpDeserializedPCHDecls = false;
191  ImplicitPCHInclude.clear();
192  ImplicitPTHInclude.clear();
193  TokenCache.clear();
194  SingleFileParseMode = false;
195  LexEditorPlaceholders = true;
196  RetainRemappedFileBuffers = true;
197  PrecompiledPreambleBytes.first = 0;
198  PrecompiledPreambleBytes.second = false;
199  }
200 };
201 
202 } // end namespace clang
203 
204 #endif
std::vector< std::pair< std::string, bool > > Macros
void addMacroUndef(StringRef Name)
bool RemappedFilesKeepOriginalName
True if the SourceManager should report the original file name for contents of files that were remapp...
ObjCXXARCStandardLibraryKind
Enumerate the kinds of standard library that.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:26
std::vector< std::string > Includes
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
std::shared_ptr< FailedModulesSet > FailedModules
The set of modules that failed to build.
std::string ImplicitPTHInclude
The implicit PTH input included at the start of the translation unit, or empty.
void addRemappedFile(StringRef From, StringRef To)
void addRemappedFile(StringRef From, llvm::MemoryBuffer *To)
unsigned DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
bool RetainRemappedFileBuffers
Whether the compiler instance should retain (i.e., not free) the buffers associated with remapped fil...
bool DisablePCHValidation
When true, disables most of the normal validation performed on precompiled headers.
std::vector< std::pair< std::string, llvm::MemoryBuffer * > > RemappedFileBuffers
The set of file-to-buffer remappings, which take existing files on the system (the first part of each...
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
unsigned UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
std::set< std::string > DeserializedPCHDeclsToErrorOn
This is a set of names for decls that we do not want to be deserialized, and we emit an error if they...
bool GeneratePreamble
True indicates that a preamble is being generated.
bool AllowPCHWithCompilerErrors
When true, a PCH with compiler errors will not be rejected.
#define false
Definition: stdbool.h:33
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
void resetNonModularOptions()
Reset any options that are not considered when building a module.
void addMacroDef(StringRef Name)
std::vector< std::string > MacroIncludes
Dataflow Directional Tag Classes.
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
Defines the clang::SourceLocation class and associated facilities.
std::vector< std::pair< std::string, std::string > > RemappedFiles
The set of file remappings, which take existing files on the system (the first part of each pair) and...
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
#define true
Definition: stdbool.h:32
bool DumpDeserializedPCHDecls
Dump declarations that are deserialized from PCH, for testing.
std::string TokenCache
If given, a PTH cache file to use for speeding up header parsing.