diff options
Diffstat (limited to 'lib/Frontend/InitPreprocessor.cpp')
-rw-r--r-- | lib/Frontend/InitPreprocessor.cpp | 86 |
1 files changed, 51 insertions, 35 deletions
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index 1440da6..4bbd033 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -17,11 +17,12 @@ #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Frontend/FrontendOptions.h" -#include "clang/Frontend/PreprocessorOptions.h" #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Lex/PreprocessorOptions.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" +#include "clang/Serialization/ASTReader.h" #include "llvm/ADT/APFloat.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBuffer.h" @@ -83,6 +84,19 @@ static void AddImplicitIncludePTH(MacroBuilder &Builder, Preprocessor &PP, AddImplicitInclude(Builder, OriginalFile, PP.getFileManager()); } +/// \brief Add an implicit \#include using the original file used to generate +/// a PCH file. +static void AddImplicitIncludePCH(MacroBuilder &Builder, Preprocessor &PP, + StringRef ImplicitIncludePCH) { + std::string OriginalFile = + ASTReader::getOriginalSourceFile(ImplicitIncludePCH, PP.getFileManager(), + PP.getDiagnostics()); + if (OriginalFile.empty()) + return; + + AddImplicitInclude(Builder, OriginalFile, PP.getFileManager()); +} + /// PickFP - This is used to pick a value based on the FP semantics of the /// specified FP model. template <typename T> @@ -102,51 +116,51 @@ static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal, } static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix, - const llvm::fltSemantics *Sem) { + const llvm::fltSemantics *Sem, StringRef Ext) { const char *DenormMin, *Epsilon, *Max, *Min; - DenormMin = PickFP(Sem, "1.40129846e-45F", "4.9406564584124654e-324", - "3.64519953188247460253e-4951L", - "4.94065645841246544176568792868221e-324L", - "6.47517511943802511092443895822764655e-4966L"); + DenormMin = PickFP(Sem, "1.40129846e-45", "4.9406564584124654e-324", + "3.64519953188247460253e-4951", + "4.94065645841246544176568792868221e-324", + "6.47517511943802511092443895822764655e-4966"); int Digits = PickFP(Sem, 6, 15, 18, 31, 33); - Epsilon = PickFP(Sem, "1.19209290e-7F", "2.2204460492503131e-16", - "1.08420217248550443401e-19L", - "4.94065645841246544176568792868221e-324L", - "1.92592994438723585305597794258492732e-34L"); + Epsilon = PickFP(Sem, "1.19209290e-7", "2.2204460492503131e-16", + "1.08420217248550443401e-19", + "4.94065645841246544176568792868221e-324", + "1.92592994438723585305597794258492732e-34"); int MantissaDigits = PickFP(Sem, 24, 53, 64, 106, 113); int Min10Exp = PickFP(Sem, -37, -307, -4931, -291, -4931); int Max10Exp = PickFP(Sem, 38, 308, 4932, 308, 4932); int MinExp = PickFP(Sem, -125, -1021, -16381, -968, -16381); int MaxExp = PickFP(Sem, 128, 1024, 16384, 1024, 16384); - Min = PickFP(Sem, "1.17549435e-38F", "2.2250738585072014e-308", - "3.36210314311209350626e-4932L", - "2.00416836000897277799610805135016e-292L", - "3.36210314311209350626267781732175260e-4932L"); - Max = PickFP(Sem, "3.40282347e+38F", "1.7976931348623157e+308", - "1.18973149535723176502e+4932L", - "1.79769313486231580793728971405301e+308L", - "1.18973149535723176508575932662800702e+4932L"); + Min = PickFP(Sem, "1.17549435e-38", "2.2250738585072014e-308", + "3.36210314311209350626e-4932", + "2.00416836000897277799610805135016e-292", + "3.36210314311209350626267781732175260e-4932"); + Max = PickFP(Sem, "3.40282347e+38", "1.7976931348623157e+308", + "1.18973149535723176502e+4932", + "1.79769313486231580793728971405301e+308", + "1.18973149535723176508575932662800702e+4932"); SmallString<32> DefPrefix; DefPrefix = "__"; DefPrefix += Prefix; DefPrefix += "_"; - Builder.defineMacro(DefPrefix + "DENORM_MIN__", DenormMin); + Builder.defineMacro(DefPrefix + "DENORM_MIN__", Twine(DenormMin)+Ext); Builder.defineMacro(DefPrefix + "HAS_DENORM__"); Builder.defineMacro(DefPrefix + "DIG__", Twine(Digits)); - Builder.defineMacro(DefPrefix + "EPSILON__", Twine(Epsilon)); + Builder.defineMacro(DefPrefix + "EPSILON__", Twine(Epsilon)+Ext); Builder.defineMacro(DefPrefix + "HAS_INFINITY__"); Builder.defineMacro(DefPrefix + "HAS_QUIET_NAN__"); Builder.defineMacro(DefPrefix + "MANT_DIG__", Twine(MantissaDigits)); Builder.defineMacro(DefPrefix + "MAX_10_EXP__", Twine(Max10Exp)); Builder.defineMacro(DefPrefix + "MAX_EXP__", Twine(MaxExp)); - Builder.defineMacro(DefPrefix + "MAX__", Twine(Max)); + Builder.defineMacro(DefPrefix + "MAX__", Twine(Max)+Ext); Builder.defineMacro(DefPrefix + "MIN_10_EXP__","("+Twine(Min10Exp)+")"); Builder.defineMacro(DefPrefix + "MIN_EXP__", "("+Twine(MinExp)+")"); - Builder.defineMacro(DefPrefix + "MIN__", Twine(Min)); + Builder.defineMacro(DefPrefix + "MIN__", Twine(Min)+Ext); } @@ -247,7 +261,7 @@ static void AddObjCXXARCLibstdcxxDefines(const LangOptions &LangOpts, << "};\n" << "\n"; - if (LangOpts.ObjCRuntimeHasWeak) { + if (LangOpts.ObjCARCWeak) { Out << "template<typename _Tp>\n" << "struct __is_scalar<__attribute__((objc_ownership(weak))) _Tp> {\n" << " enum { __value = 0 };\n" @@ -288,6 +302,8 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI, else if (!LangOpts.GNUMode && LangOpts.Digraphs) Builder.defineMacro("__STDC_VERSION__", "199409L"); } else { + // FIXME: LangOpts.CPlusPlus1y + // C++11 [cpp.predefined]p1: // The name __cplusplus is defined to the value 201103L when compiling a // C++ translation unit. @@ -325,8 +341,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI, Builder.defineMacro("__clang_patchlevel__", "0"); #endif Builder.defineMacro("__clang_version__", - "\"" CLANG_VERSION_STRING " (" - + getClangFullRepositoryVersion() + ")\""); + "\"" CLANG_VERSION_STRING " " + + getClangFullRepositoryVersion() + "\""); #undef TOSTR #undef TOSTR2 if (!LangOpts.MicrosoftMode) { @@ -420,19 +436,17 @@ static void InitializePredefinedMacros(const TargetInfo &TI, // Both __PRETTY_FUNCTION__ and __FUNCTION__ are GCC extensions, however // VC++ appears to only like __FUNCTION__. Builder.defineMacro("__PRETTY_FUNCTION__", "__FUNCTION__"); - // Work around some issues with Visual C++ headerws. - if (LangOpts.CPlusPlus) { - // Since we define wchar_t in C++ mode. + // Work around some issues with Visual C++ headers. + if (LangOpts.WChar) { + // wchar_t supported as a keyword. Builder.defineMacro("_WCHAR_T_DEFINED"); Builder.defineMacro("_NATIVE_WCHAR_T_DEFINED"); + } + if (LangOpts.CPlusPlus) { // FIXME: Support Microsoft's __identifier extension in the lexer. Builder.append("#define __identifier(x) x"); Builder.append("class type_info;"); } - - if (LangOpts.CPlusPlus0x) { - Builder.defineMacro("_HAS_CHAR16_T_LANGUAGE_SUPPORT", "1"); - } } if (LangOpts.Optimize) @@ -511,9 +525,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI, DefineType("__CHAR16_TYPE__", TI.getChar16Type(), Builder); DefineType("__CHAR32_TYPE__", TI.getChar32Type(), Builder); - DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat()); - DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat()); - DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat()); + DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F"); + DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), ""); + DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L"); // Define a __POINTER_WIDTH__ macro for stdint.h. Builder.defineMacro("__POINTER_WIDTH__", @@ -763,6 +777,8 @@ void clang::InitializePreprocessor(Preprocessor &PP, const std::string &Path = InitOpts.Includes[i]; if (Path == InitOpts.ImplicitPTHInclude) AddImplicitIncludePTH(Builder, PP, Path); + else if (Path == InitOpts.ImplicitPCHInclude) + AddImplicitIncludePCH(Builder, PP, Path); else AddImplicitInclude(Builder, Path, PP.getFileManager()); } |