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