|
|
|||
File indexing completed on 2026-05-10 08:36:58
0001 //===- PreprocessorOptions.h ------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_ 0010 #define LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_ 0011 0012 #include "clang/Basic/BitmaskEnum.h" 0013 #include "clang/Basic/FileEntry.h" 0014 #include "clang/Basic/LLVM.h" 0015 #include "clang/Lex/DependencyDirectivesScanner.h" 0016 #include "llvm/ADT/StringRef.h" 0017 #include "llvm/ADT/StringSet.h" 0018 #include <functional> 0019 #include <map> 0020 #include <memory> 0021 #include <optional> 0022 #include <set> 0023 #include <string> 0024 #include <utility> 0025 #include <vector> 0026 0027 namespace llvm { 0028 0029 class MemoryBuffer; 0030 0031 } // namespace llvm 0032 0033 namespace clang { 0034 0035 /// Enumerate the kinds of standard library that 0036 enum ObjCXXARCStandardLibraryKind { 0037 ARCXX_nolib, 0038 0039 /// libc++ 0040 ARCXX_libcxx, 0041 0042 /// libstdc++ 0043 ARCXX_libstdcxx 0044 }; 0045 0046 /// Whether to disable the normal validation performed on precompiled 0047 /// headers and module files when they are loaded. 0048 enum class DisableValidationForModuleKind { 0049 /// Perform validation, don't disable it. 0050 None = 0, 0051 0052 /// Disable validation for a precompiled header and the modules it depends on. 0053 PCH = 0x1, 0054 0055 /// Disable validation for module files. 0056 Module = 0x2, 0057 0058 /// Disable validation for all kinds. 0059 All = PCH | Module, 0060 0061 LLVM_MARK_AS_BITMASK_ENUM(Module) 0062 }; 0063 0064 /// PreprocessorOptions - This class is used for passing the various options 0065 /// used in preprocessor initialization to InitializePreprocessor(). 0066 class PreprocessorOptions { 0067 public: 0068 std::vector<std::pair<std::string, bool/*isUndef*/>> Macros; 0069 std::vector<std::string> Includes; 0070 std::vector<std::string> MacroIncludes; 0071 0072 /// Perform extra checks when loading PCM files for mutable file systems. 0073 bool ModulesCheckRelocated = true; 0074 0075 /// Initialize the preprocessor with the compiler and target specific 0076 /// predefines. 0077 bool UsePredefines = true; 0078 0079 /// Indicates whether to predefine target OS macros. 0080 bool DefineTargetOSMacros = false; 0081 0082 /// Whether we should maintain a detailed record of all macro 0083 /// definitions and expansions. 0084 bool DetailedRecord = false; 0085 0086 /// When true, we are creating or using a PCH where a #pragma hdrstop is 0087 /// expected to indicate the beginning or end of the PCH. 0088 bool PCHWithHdrStop = false; 0089 0090 /// When true, we are creating a PCH or creating the PCH object while 0091 /// expecting a #pragma hdrstop to separate the two. Allow for a 0092 /// missing #pragma hdrstop, which generates a PCH for the whole file, 0093 /// and creates an empty PCH object. 0094 bool PCHWithHdrStopCreate = false; 0095 0096 /// If non-empty, the filename used in an #include directive in the primary 0097 /// source file (or command-line preinclude) that is used to implement 0098 /// MSVC-style precompiled headers. When creating a PCH, after the #include 0099 /// of this header, the PCH generation stops. When using a PCH, tokens are 0100 /// skipped until after an #include of this header is seen. 0101 std::string PCHThroughHeader; 0102 0103 /// The implicit PCH included at the start of the translation unit, or empty. 0104 std::string ImplicitPCHInclude; 0105 0106 /// Headers that will be converted to chained PCHs in memory. 0107 std::vector<std::string> ChainedIncludes; 0108 0109 /// Whether to disable most of the normal validation performed on 0110 /// precompiled headers and module files. 0111 DisableValidationForModuleKind DisablePCHOrModuleValidation = 0112 DisableValidationForModuleKind::None; 0113 0114 /// When true, a PCH with compiler errors will not be rejected. 0115 bool AllowPCHWithCompilerErrors = false; 0116 0117 /// When true, a PCH with modules cache path different to the current 0118 /// compilation will not be rejected. 0119 bool AllowPCHWithDifferentModulesCachePath = false; 0120 0121 /// Dump declarations that are deserialized from PCH, for testing. 0122 bool DumpDeserializedPCHDecls = false; 0123 0124 /// This is a set of names for decls that we do not want to be 0125 /// deserialized, and we emit an error if they are; for testing purposes. 0126 std::set<std::string> DeserializedPCHDeclsToErrorOn; 0127 0128 /// If non-zero, the implicit PCH include is actually a precompiled 0129 /// preamble that covers this number of bytes in the main source file. 0130 /// 0131 /// The boolean indicates whether the preamble ends at the start of a new 0132 /// line. 0133 std::pair<unsigned, bool> PrecompiledPreambleBytes; 0134 0135 /// True indicates that a preamble is being generated. 0136 /// 0137 /// When the lexer is done, one of the things that need to be preserved is the 0138 /// conditional #if stack, so the ASTWriter/ASTReader can save/restore it when 0139 /// processing the rest of the file. Similarly, we track an unterminated 0140 /// #pragma assume_nonnull. 0141 bool GeneratePreamble = false; 0142 0143 /// Whether to write comment locations into the PCH when building it. 0144 /// Reading the comments from the PCH can be a performance hit even if the 0145 /// clients don't use them. 0146 bool WriteCommentListToPCH = true; 0147 0148 /// When enabled, preprocessor is in a mode for parsing a single file only. 0149 /// 0150 /// Disables #includes of other files and if there are unresolved identifiers 0151 /// in preprocessor directive conditions it causes all blocks to be parsed so 0152 /// that the client can get the maximum amount of information from the parser. 0153 bool SingleFileParseMode = false; 0154 0155 /// When enabled, the preprocessor will construct editor placeholder tokens. 0156 bool LexEditorPlaceholders = true; 0157 0158 /// True if the SourceManager should report the original file name for 0159 /// contents of files that were remapped to other files. Defaults to true. 0160 bool RemappedFilesKeepOriginalName = true; 0161 0162 /// The set of file remappings, which take existing files on 0163 /// the system (the first part of each pair) and gives them the 0164 /// contents of other files on the system (the second part of each 0165 /// pair). 0166 std::vector<std::pair<std::string, std::string>> RemappedFiles; 0167 0168 /// The set of file-to-buffer remappings, which take existing files 0169 /// on the system (the first part of each pair) and gives them the contents 0170 /// of the specified memory buffer (the second part of each pair). 0171 std::vector<std::pair<std::string, llvm::MemoryBuffer *>> RemappedFileBuffers; 0172 0173 /// User specified embed entries. 0174 std::vector<std::string> EmbedEntries; 0175 0176 /// Whether the compiler instance should retain (i.e., not free) 0177 /// the buffers associated with remapped files. 0178 /// 0179 /// This flag defaults to false; it can be set true only through direct 0180 /// manipulation of the compiler invocation object, in cases where the 0181 /// compiler invocation and its buffers will be reused. 0182 bool RetainRemappedFileBuffers = false; 0183 0184 /// When enabled, excluded conditional blocks retain in the main file. 0185 bool RetainExcludedConditionalBlocks = false; 0186 0187 /// The Objective-C++ ARC standard library that we should support, 0188 /// by providing appropriate definitions to retrofit the standard library 0189 /// with support for lifetime-qualified pointers. 0190 ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary = ARCXX_nolib; 0191 0192 /// Function for getting the dependency preprocessor directives of a file. 0193 /// 0194 /// These are directives derived from a special form of lexing where the 0195 /// source input is scanned for the preprocessor directives that might have an 0196 /// effect on the dependencies for a compilation unit. 0197 /// 0198 /// Enables a client to cache the directives for a file and provide them 0199 /// across multiple compiler invocations. 0200 /// FIXME: Allow returning an error. 0201 std::function<std::optional<ArrayRef<dependency_directives_scan::Directive>>( 0202 FileEntryRef)> 0203 DependencyDirectivesForFile; 0204 0205 /// Set up preprocessor for RunAnalysis action. 0206 bool SetUpStaticAnalyzer = false; 0207 0208 /// Prevents intended crashes when using #pragma clang __debug. For testing. 0209 bool DisablePragmaDebugCrash = false; 0210 0211 /// If set, the UNIX timestamp specified by SOURCE_DATE_EPOCH. 0212 std::optional<uint64_t> SourceDateEpoch; 0213 0214 public: 0215 PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {} 0216 0217 void addMacroDef(StringRef Name) { 0218 Macros.emplace_back(std::string(Name), false); 0219 } 0220 void addMacroUndef(StringRef Name) { 0221 Macros.emplace_back(std::string(Name), true); 0222 } 0223 0224 void addRemappedFile(StringRef From, StringRef To) { 0225 RemappedFiles.emplace_back(std::string(From), std::string(To)); 0226 } 0227 0228 void addRemappedFile(StringRef From, llvm::MemoryBuffer *To) { 0229 RemappedFileBuffers.emplace_back(std::string(From), To); 0230 } 0231 0232 void clearRemappedFiles() { 0233 RemappedFiles.clear(); 0234 RemappedFileBuffers.clear(); 0235 } 0236 0237 /// Reset any options that are not considered when building a 0238 /// module. 0239 void resetNonModularOptions() { 0240 Includes.clear(); 0241 MacroIncludes.clear(); 0242 ChainedIncludes.clear(); 0243 DumpDeserializedPCHDecls = false; 0244 ImplicitPCHInclude.clear(); 0245 SingleFileParseMode = false; 0246 LexEditorPlaceholders = true; 0247 RetainRemappedFileBuffers = true; 0248 PrecompiledPreambleBytes.first = 0; 0249 PrecompiledPreambleBytes.second = false; 0250 RetainExcludedConditionalBlocks = false; 0251 } 0252 }; 0253 0254 } // namespace clang 0255 0256 #endif // LLVM_CLANG_LEX_PREPROCESSOROPTIONS_H_
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|