1 //===--- InitPreprocessor.cpp - PP initialization code. ---------*- 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 // This file implements the clang::InitializePreprocessor function. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/Frontend/Utils.h" 15 #include "clang/Basic/TargetInfo.h" 16 #include "clang/Frontend/FrontendDiagnostic.h" 17 #include "clang/Frontend/PreprocessorOptions.h" 18 #include "clang/Lex/Preprocessor.h" 19 #include "clang/Basic/FileManager.h" 20 #include "clang/Basic/SourceManager.h" 21 #include "llvm/ADT/APFloat.h" 22 #include "llvm/Support/MemoryBuffer.h" 23 #include "llvm/System/Path.h" 24 using namespace clang; 25 26 // Append a #define line to Buf for Macro. Macro should be of the form XXX, 27 // in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit 28 // "#define XXX Y z W". To get a #define with no value, use "XXX=". 29 static void DefineBuiltinMacro(MacroBuilder &Builder, llvm::StringRef Macro, 30 Diagnostic *Diags = 0) { 31 std::pair<llvm::StringRef, llvm::StringRef> MacroPair = Macro.split('='); 32 llvm::StringRef MacroName = MacroPair.first; 33 llvm::StringRef MacroBody = MacroPair.second; 34 if (!MacroBody.empty()) { 35 // Per GCC -D semantics, the macro ends at \n if it exists. 36 llvm::StringRef::size_type End = MacroBody.find_first_of("\n\r"); 37 if (End != llvm::StringRef::npos) { 38 assert(Diags && "Unexpected macro with embedded newline!"); 39 Diags->Report(diag::warn_fe_macro_contains_embedded_newline) 40 << MacroName; 41 } 42 43 Builder.defineMacro(MacroName, MacroBody.substr(0, End)); 44 } else { 45 // Push "macroname 1". 46 Builder.defineMacro(Macro); 47 } 48 } 49 50 std::string clang::NormalizeDashIncludePath(llvm::StringRef File) { 51 // Implicit include paths should be resolved relative to the current 52 // working directory first, and then use the regular header search 53 // mechanism. The proper way to handle this is to have the 54 // predefines buffer located at the current working directory, but 55 // it has not file entry. For now, workaround this by using an 56 // absolute path if we find the file here, and otherwise letting 57 // header search handle it. 58 llvm::sys::Path Path(File); 59 Path.makeAbsolute(); 60 if (!Path.exists()) 61 Path = File; 62 63 return Lexer::Stringify(Path.str()); 64 } 65 66 /// AddImplicitInclude - Add an implicit #include of the specified file to the 67 /// predefines buffer. 68 static void AddImplicitInclude(MacroBuilder &Builder, llvm::StringRef File) { 69 Builder.append("#include \"" + 70 llvm::Twine(NormalizeDashIncludePath(File)) + "\""); 71 } 72 73 static void AddImplicitIncludeMacros(MacroBuilder &Builder, 74 llvm::StringRef File) { 75 Builder.append("#__include_macros \"" + 76 llvm::Twine(NormalizeDashIncludePath(File)) + "\""); 77 // Marker token to stop the __include_macros fetch loop. 78 Builder.append("##"); // ##? 79 } 80 81 /// AddImplicitIncludePTH - Add an implicit #include using the original file 82 /// used to generate a PTH cache. 83 static void AddImplicitIncludePTH(MacroBuilder &Builder, Preprocessor &PP, 84 llvm::StringRef ImplicitIncludePTH) { 85 PTHManager *P = PP.getPTHManager(); 86 assert(P && "No PTHManager."); 87 const char *OriginalFile = P->getOriginalSourceFile(); 88 89 if (!OriginalFile) { 90 PP.getDiagnostics().Report(diag::err_fe_pth_file_has_no_source_header) 91 << ImplicitIncludePTH; 92 return; 93 } 94 95 AddImplicitInclude(Builder, OriginalFile); 96 } 97 98 /// PickFP - This is used to pick a value based on the FP semantics of the 99 /// specified FP model. 100 template <typename T> 101 static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal, 102 T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal, 103 T IEEEQuadVal) { 104 if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle) 105 return IEEESingleVal; 106 if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble) 107 return IEEEDoubleVal; 108 if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::x87DoubleExtended) 109 return X87DoubleExtendedVal; 110 if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::PPCDoubleDouble) 111 return PPCDoubleDoubleVal; 112 assert(Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEquad); 113 return IEEEQuadVal; 114 } 115 116 static void DefineFloatMacros(MacroBuilder &Builder, llvm::StringRef Prefix, 117 const llvm::fltSemantics *Sem) { 118 const char *DenormMin, *Epsilon, *Max, *Min; 119 DenormMin = PickFP(Sem, "1.40129846e-45F", "4.9406564584124654e-324", 120 "3.64519953188247460253e-4951L", 121 "4.94065645841246544176568792868221e-324L", 122 "6.47517511943802511092443895822764655e-4966L"); 123 int Digits = PickFP(Sem, 6, 15, 18, 31, 33); 124 Epsilon = PickFP(Sem, "1.19209290e-7F", "2.2204460492503131e-16", 125 "1.08420217248550443401e-19L", 126 "4.94065645841246544176568792868221e-324L", 127 "1.92592994438723585305597794258492732e-34L"); 128 int MantissaDigits = PickFP(Sem, 24, 53, 64, 106, 113); 129 int Min10Exp = PickFP(Sem, -37, -307, -4931, -291, -4931); 130 int Max10Exp = PickFP(Sem, 38, 308, 4932, 308, 4932); 131 int MinExp = PickFP(Sem, -125, -1021, -16381, -968, -16381); 132 int MaxExp = PickFP(Sem, 128, 1024, 16384, 1024, 16384); 133 Min = PickFP(Sem, "1.17549435e-38F", "2.2250738585072014e-308", 134 "3.36210314311209350626e-4932L", 135 "2.00416836000897277799610805135016e-292L", 136 "3.36210314311209350626267781732175260e-4932L"); 137 Max = PickFP(Sem, "3.40282347e+38F", "1.7976931348623157e+308", 138 "1.18973149535723176502e+4932L", 139 "1.79769313486231580793728971405301e+308L", 140 "1.18973149535723176508575932662800702e+4932L"); 141 142 llvm::Twine DefPrefix = "__" + Prefix + "_"; 143 144 Builder.defineMacro(DefPrefix + "DENORM_MIN__", DenormMin); 145 Builder.defineMacro(DefPrefix + "HAS_DENORM__"); 146 Builder.defineMacro(DefPrefix + "DIG__", llvm::Twine(Digits)); 147 Builder.defineMacro(DefPrefix + "EPSILON__", llvm::Twine(Epsilon)); 148 Builder.defineMacro(DefPrefix + "HAS_INFINITY__"); 149 Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__"); 150 Builder.defineMacro(DefPrefix + "MANT_DIG__", llvm::Twine(MantissaDigits)); 151 152 Builder.defineMacro(DefPrefix + "MAX_10_EXP__", llvm::Twine(Max10Exp)); 153 Builder.defineMacro(DefPrefix + "MAX_EXP__", llvm::Twine(MaxExp)); 154 Builder.defineMacro(DefPrefix + "MAX__", llvm::Twine(Max)); 155 156 Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+llvm::Twine(Min10Exp)+")"); 157 Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+llvm::Twine(MinExp)+")"); 158 Builder.defineMacro(DefPrefix + "MIN__", llvm::Twine(Min)); 159 } 160 161 162 /// DefineTypeSize - Emit a macro to the predefines buffer that declares a macro 163 /// named MacroName with the max value for a type with width 'TypeWidth' a 164 /// signedness of 'isSigned' and with a value suffix of 'ValSuffix' (e.g. LL). 165 static void DefineTypeSize(llvm::StringRef MacroName, unsigned TypeWidth, 166 llvm::StringRef ValSuffix, bool isSigned, 167 MacroBuilder& Builder) { 168 long long MaxVal; 169 if (isSigned) 170 MaxVal = (1LL << (TypeWidth - 1)) - 1; 171 else 172 MaxVal = ~0LL >> (64-TypeWidth); 173 174 Builder.defineMacro(MacroName, llvm::Twine(MaxVal) + ValSuffix); 175 } 176 177 /// DefineTypeSize - An overloaded helper that uses TargetInfo to determine 178 /// the width, suffix, and signedness of the given type 179 static void DefineTypeSize(llvm::StringRef MacroName, TargetInfo::IntType Ty, 180 const TargetInfo &TI, MacroBuilder &Builder) { 181 DefineTypeSize(MacroName, TI.getTypeWidth(Ty), TI.getTypeConstantSuffix(Ty), 182 TI.isTypeSigned(Ty), Builder); 183 } 184 185 static void DefineType(const llvm::Twine &MacroName, TargetInfo::IntType Ty, 186 MacroBuilder &Builder) { 187 Builder.defineMacro(MacroName, TargetInfo::getTypeName(Ty)); 188 } 189 190 static void DefineTypeWidth(llvm::StringRef MacroName, TargetInfo::IntType Ty, 191 const TargetInfo &TI, MacroBuilder &Builder) { 192 Builder.defineMacro(MacroName, llvm::Twine(TI.getTypeWidth(Ty))); 193 } 194 195 static void DefineExactWidthIntType(TargetInfo::IntType Ty, 196 const TargetInfo &TI, MacroBuilder &Builder) { 197 int TypeWidth = TI.getTypeWidth(Ty); 198 DefineType("__INT" + llvm::Twine(TypeWidth) + "_TYPE__", Ty, Builder); 199 200 llvm::StringRef ConstSuffix(TargetInfo::getTypeConstantSuffix(Ty)); 201 if (!ConstSuffix.empty()) 202 Builder.defineMacro("__INT" + llvm::Twine(TypeWidth) + "_C_SUFFIX__", 203 ConstSuffix); 204 } 205 206 static void InitializePredefinedMacros(const TargetInfo &TI, 207 const LangOptions &LangOpts, 208 MacroBuilder &Builder) { 209 // Compiler version introspection macros. 210 Builder.defineMacro("__llvm__"); // LLVM Backend 211 Builder.defineMacro("__clang__"); // Clang Frontend 212 213 // Currently claim to be compatible with GCC 4.2.1-5621. 214 Builder.defineMacro("__GNUC_MINOR__", "2"); 215 Builder.defineMacro("__GNUC_PATCHLEVEL__", "1"); 216 Builder.defineMacro("__GNUC__", "4"); 217 Builder.defineMacro("__GXX_ABI_VERSION", "1002"); 218 Builder.defineMacro("__VERSION__", "\"4.2.1 Compatible Clang Compiler\""); 219 220 // Initialize language-specific preprocessor defines. 221 222 // These should all be defined in the preprocessor according to the 223 // current language configuration. 224 if (!LangOpts.Microsoft) 225 Builder.defineMacro("__STDC__"); 226 if (LangOpts.AsmPreprocessor) 227 Builder.defineMacro("__ASSEMBLER__"); 228 229 if (!LangOpts.CPlusPlus) { 230 if (LangOpts.C99) 231 Builder.defineMacro("__STDC_VERSION__", "199901L"); 232 else if (!LangOpts.GNUMode && LangOpts.Digraphs) 233 Builder.defineMacro("__STDC_VERSION__", "199409L"); 234 } 235 236 // Standard conforming mode? 237 if (!LangOpts.GNUMode) 238 Builder.defineMacro("__STRICT_ANSI__"); 239 240 if (LangOpts.CPlusPlus0x) 241 Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__"); 242 243 if (LangOpts.Freestanding) 244 Builder.defineMacro("__STDC_HOSTED__", "0"); 245 else 246 Builder.defineMacro("__STDC_HOSTED__"); 247 248 if (LangOpts.ObjC1) { 249 Builder.defineMacro("__OBJC__"); 250 if (LangOpts.ObjCNonFragileABI) { 251 Builder.defineMacro("__OBJC2__"); 252 Builder.defineMacro("OBJC_ZEROCOST_EXCEPTIONS"); 253 } 254 255 if (LangOpts.getGCMode() != LangOptions::NonGC) 256 Builder.defineMacro("__OBJC_GC__"); 257 258 if (LangOpts.NeXTRuntime) 259 Builder.defineMacro("__NEXT_RUNTIME__"); 260 } 261 262 // darwin_constant_cfstrings controls this. This is also dependent 263 // on other things like the runtime I believe. This is set even for C code. 264 Builder.defineMacro("__CONSTANT_CFSTRINGS__"); 265 266 if (LangOpts.ObjC2) 267 Builder.defineMacro("OBJC_NEW_PROPERTIES"); 268 269 if (LangOpts.PascalStrings) 270 Builder.defineMacro("__PASCAL_STRINGS__"); 271 272 if (LangOpts.Blocks) { 273 Builder.defineMacro("__block", "__attribute__((__blocks__(byref)))"); 274 Builder.defineMacro("__BLOCKS__"); 275 } 276 277 if (LangOpts.Exceptions) 278 Builder.defineMacro("__EXCEPTIONS"); 279 280 if (LangOpts.CPlusPlus) { 281 Builder.defineMacro("__DEPRECATED"); 282 Builder.defineMacro("__GNUG__", "4"); 283 Builder.defineMacro("__GXX_WEAK__"); 284 if (LangOpts.GNUMode) 285 Builder.defineMacro("__cplusplus"); 286 else 287 // C++ [cpp.predefined]p1: 288 // The name_ _cplusplusis defined to the value199711Lwhen compiling a 289 // C++ translation unit. 290 Builder.defineMacro("__cplusplus", "199711L"); 291 Builder.defineMacro("__private_extern__", "extern"); 292 // Ugly hack to work with GNU libstdc++. 293 Builder.defineMacro("_GNU_SOURCE"); 294 } 295 296 if (LangOpts.Microsoft) { 297 // Filter out some microsoft extensions when trying to parse in ms-compat 298 // mode. 299 Builder.defineMacro("__int8", "__INT8_TYPE__"); 300 Builder.defineMacro("__int16", "__INT16_TYPE__"); 301 Builder.defineMacro("__int32", "__INT32_TYPE__"); 302 Builder.defineMacro("__int64", "__INT64_TYPE__"); 303 // Both __PRETTY_FUNCTION__ and __FUNCTION__ are GCC extensions, however 304 // VC++ appears to only like __FUNCTION__. 305 Builder.defineMacro("__PRETTY_FUNCTION__", "__FUNCTION__"); 306 // Work around some issues with Visual C++ headerws. 307 if (LangOpts.CPlusPlus) { 308 // Since we define wchar_t in C++ mode. 309 Builder.defineMacro("_WCHAR_T_DEFINED"); 310 Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED"); 311 // FIXME: This should be temporary until we have a __pragma 312 // solution, to avoid some errors flagged in VC++ headers. 313 Builder.defineMacro("_CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES", "0"); 314 } 315 } 316 317 if (LangOpts.Optimize) 318 Builder.defineMacro("__OPTIMIZE__"); 319 if (LangOpts.OptimizeSize) 320 Builder.defineMacro("__OPTIMIZE_SIZE__"); 321 322 // Initialize target-specific preprocessor defines. 323 324 // Define type sizing macros based on the target properties. 325 assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far"); 326 Builder.defineMacro("__CHAR_BIT__", "8"); 327 328 DefineTypeSize("__SCHAR_MAX__", TI.getCharWidth(), "", true, Builder); 329 DefineTypeSize("__SHRT_MAX__", TargetInfo::SignedShort, TI, Builder); 330 DefineTypeSize("__INT_MAX__", TargetInfo::SignedInt, TI, Builder); 331 DefineTypeSize("__LONG_MAX__", TargetInfo::SignedLong, TI, Builder); 332 DefineTypeSize("__LONG_LONG_MAX__", TargetInfo::SignedLongLong, TI, Builder); 333 DefineTypeSize("__WCHAR_MAX__", TI.getWCharType(), TI, Builder); 334 DefineTypeSize("__INTMAX_MAX__", TI.getIntMaxType(), TI, Builder); 335 336 DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Builder); 337 DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Builder); 338 DefineTypeWidth("__INTMAX_WIDTH__", TI.getIntMaxType(), TI, Builder); 339 DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Builder); 340 DefineTypeWidth("__PTRDIFF_WIDTH__", TI.getPtrDiffType(0), TI, Builder); 341 DefineType("__INTPTR_TYPE__", TI.getIntPtrType(), Builder); 342 DefineTypeWidth("__INTPTR_WIDTH__", TI.getIntPtrType(), TI, Builder); 343 DefineType("__SIZE_TYPE__", TI.getSizeType(), Builder); 344 DefineTypeWidth("__SIZE_WIDTH__", TI.getSizeType(), TI, Builder); 345 DefineType("__WCHAR_TYPE__", TI.getWCharType(), Builder); 346 DefineTypeWidth("__WCHAR_WIDTH__", TI.getWCharType(), TI, Builder); 347 DefineType("__WINT_TYPE__", TI.getWIntType(), Builder); 348 DefineTypeWidth("__WINT_WIDTH__", TI.getWIntType(), TI, Builder); 349 DefineTypeWidth("__SIG_ATOMIC_WIDTH__", TI.getSigAtomicType(), TI, Builder); 350 351 DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat()); 352 DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat()); 353 DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat()); 354 355 // Define a __POINTER_WIDTH__ macro for stdint.h. 356 Builder.defineMacro("__POINTER_WIDTH__", 357 llvm::Twine((int)TI.getPointerWidth(0))); 358 359 if (!LangOpts.CharIsSigned) 360 Builder.defineMacro("__CHAR_UNSIGNED__"); 361 362 // Define exact-width integer types for stdint.h 363 Builder.defineMacro("__INT" + llvm::Twine(TI.getCharWidth()) + "_TYPE__", 364 "char"); 365 366 if (TI.getShortWidth() > TI.getCharWidth()) 367 DefineExactWidthIntType(TargetInfo::SignedShort, TI, Builder); 368 369 if (TI.getIntWidth() > TI.getShortWidth()) 370 DefineExactWidthIntType(TargetInfo::SignedInt, TI, Builder); 371 372 if (TI.getLongWidth() > TI.getIntWidth()) 373 DefineExactWidthIntType(TargetInfo::SignedLong, TI, Builder); 374 375 if (TI.getLongLongWidth() > TI.getLongWidth()) 376 DefineExactWidthIntType(TargetInfo::SignedLongLong, TI, Builder); 377 378 // Add __builtin_va_list typedef. 379 Builder.append(TI.getVAListDeclaration()); 380 381 if (const char *Prefix = TI.getUserLabelPrefix()) 382 Builder.defineMacro("__USER_LABEL_PREFIX__", Prefix); 383 384 // Build configuration options. FIXME: these should be controlled by 385 // command line options or something. 386 Builder.defineMacro("__FINITE_MATH_ONLY__", "0"); 387 388 if (LangOpts.GNUInline) 389 Builder.defineMacro("__GNUC_GNU_INLINE__"); 390 else 391 Builder.defineMacro("__GNUC_STDC_INLINE__"); 392 393 if (LangOpts.NoInline) 394 Builder.defineMacro("__NO_INLINE__"); 395 396 if (unsigned PICLevel = LangOpts.PICLevel) { 397 Builder.defineMacro("__PIC__", llvm::Twine(PICLevel)); 398 Builder.defineMacro("__pic__", llvm::Twine(PICLevel)); 399 } 400 401 // Macros to control C99 numerics and <float.h> 402 Builder.defineMacro("__FLT_EVAL_METHOD__", "0"); 403 Builder.defineMacro("__FLT_RADIX__", "2"); 404 int Dig = PickFP(&TI.getLongDoubleFormat(), -1/*FIXME*/, 17, 21, 33, 36); 405 Builder.defineMacro("__DECIMAL_DIG__", llvm::Twine(Dig)); 406 407 if (LangOpts.getStackProtectorMode() == LangOptions::SSPOn) 408 Builder.defineMacro("__SSP__"); 409 else if (LangOpts.getStackProtectorMode() == LangOptions::SSPReq) 410 Builder.defineMacro("__SSP_ALL__", "2"); 411 412 // Get other target #defines. 413 TI.getTargetDefines(LangOpts, Builder); 414 } 415 416 // Initialize the remapping of files to alternative contents, e.g., 417 // those specified through other files. 418 static void InitializeFileRemapping(Diagnostic &Diags, 419 SourceManager &SourceMgr, 420 FileManager &FileMgr, 421 const PreprocessorOptions &InitOpts) { 422 // Remap files in the source manager. 423 for (PreprocessorOptions::remapped_file_iterator 424 Remap = InitOpts.remapped_file_begin(), 425 RemapEnd = InitOpts.remapped_file_end(); 426 Remap != RemapEnd; 427 ++Remap) { 428 // Find the file that we're mapping to. 429 const FileEntry *ToFile = FileMgr.getFile(Remap->second); 430 if (!ToFile) { 431 Diags.Report(diag::err_fe_remap_missing_to_file) 432 << Remap->first << Remap->second; 433 continue; 434 } 435 436 // Create the file entry for the file that we're mapping from. 437 const FileEntry *FromFile = FileMgr.getVirtualFile(Remap->first, 438 ToFile->getSize(), 439 0); 440 if (!FromFile) { 441 Diags.Report(diag::err_fe_remap_missing_from_file) 442 << Remap->first; 443 continue; 444 } 445 446 // Load the contents of the file we're mapping to. 447 std::string ErrorStr; 448 const llvm::MemoryBuffer *Buffer 449 = llvm::MemoryBuffer::getFile(ToFile->getName(), &ErrorStr); 450 if (!Buffer) { 451 Diags.Report(diag::err_fe_error_opening) 452 << Remap->second << ErrorStr; 453 continue; 454 } 455 456 // Override the contents of the "from" file with the contents of 457 // the "to" file. 458 SourceMgr.overrideFileContents(FromFile, Buffer); 459 } 460 } 461 462 /// InitializePreprocessor - Initialize the preprocessor getting it and the 463 /// environment ready to process a single file. This returns true on error. 464 /// 465 void clang::InitializePreprocessor(Preprocessor &PP, 466 const PreprocessorOptions &InitOpts, 467 const HeaderSearchOptions &HSOpts) { 468 std::string PredefineBuffer; 469 PredefineBuffer.reserve(4080); 470 llvm::raw_string_ostream Predefines(PredefineBuffer); 471 MacroBuilder Builder(Predefines); 472 473 InitializeFileRemapping(PP.getDiagnostics(), PP.getSourceManager(), 474 PP.getFileManager(), InitOpts); 475 476 Builder.append("# 1 \"<built-in>\" 3"); 477 478 // Install things like __POWERPC__, __GNUC__, etc into the macro table. 479 if (InitOpts.UsePredefines) 480 InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(), 481 Builder); 482 483 // Add on the predefines from the driver. Wrap in a #line directive to report 484 // that they come from the command line. 485 Builder.append("# 1 \"<command line>\" 1"); 486 487 // Process #define's and #undef's in the order they are given. 488 for (unsigned i = 0, e = InitOpts.Macros.size(); i != e; ++i) { 489 if (InitOpts.Macros[i].second) // isUndef 490 Builder.undefineMacro(InitOpts.Macros[i].first); 491 else 492 DefineBuiltinMacro(Builder, InitOpts.Macros[i].first, 493 &PP.getDiagnostics()); 494 } 495 496 // If -imacros are specified, include them now. These are processed before 497 // any -include directives. 498 for (unsigned i = 0, e = InitOpts.MacroIncludes.size(); i != e; ++i) 499 AddImplicitIncludeMacros(Builder, InitOpts.MacroIncludes[i]); 500 501 // Process -include directives. 502 for (unsigned i = 0, e = InitOpts.Includes.size(); i != e; ++i) { 503 const std::string &Path = InitOpts.Includes[i]; 504 if (Path == InitOpts.ImplicitPTHInclude) 505 AddImplicitIncludePTH(Builder, PP, Path); 506 else 507 AddImplicitInclude(Builder, Path); 508 } 509 510 // Exit the command line and go back to <built-in> (2 is LC_LEAVE). 511 Builder.append("# 1 \"<built-in>\" 2"); 512 513 // Copy PredefinedBuffer into the Preprocessor. 514 PP.setPredefines(Predefines.str()); 515 516 // Initialize the header search object. 517 ApplyHeaderSearchOptions(PP.getHeaderSearchInfo(), HSOpts, 518 PP.getLangOptions(), 519 PP.getTargetInfo().getTriple()); 520 } 521