diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-06 05:04:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-06 05:04:11 +0000 |
commit | 2b5abf515f9696912452f431c7738691cf97f4f1 (patch) | |
tree | bb222dd6e8d260561f90765c9673489563526bd3 /lib/Lex/Preprocessor.cpp | |
parent | 86d85b8e5e55db3079c9c22aecdb30d830793a50 (diff) |
simplify and refactor a bunch of type definition code in Preprocessor
predefines buffer initialization.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63919 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/Preprocessor.cpp')
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 73 |
1 files changed, 13 insertions, 60 deletions
diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 69761c824a..c1e852cd2a 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -428,6 +428,14 @@ static void DefineTypeSize(const char *MacroName, unsigned TypeWidth, DefineBuiltinMacro(Buf, MacroBuf); } +static void DefineType(const char *MacroName, TargetInfo::IntType Ty, + std::vector<char> &Buf) { + char MacroBuf[60]; + sprintf(MacroBuf, "%s=%s", MacroName, TargetInfo::getTypeName(Ty)); + DefineBuiltinMacro(Buf, MacroBuf); +} + + static void InitializePredefinedMacros(Preprocessor &PP, std::vector<char> &Buf) { // Compiler version introspection macros. @@ -520,8 +528,6 @@ static void InitializePredefinedMacros(Preprocessor &PP, DefineBuiltinMacro(Buf, "__WCHAR_TYPE__=int"); DefineBuiltinMacro(Buf, "__WINT_TYPE__=int"); - - unsigned IntMaxWidth; const char *IntMaxSuffix; if (TI.getIntMaxType() == TargetInfo::SignedLongLong) { @@ -544,64 +550,11 @@ static void InitializePredefinedMacros(Preprocessor &PP, DefineTypeSize("__WCHAR_MAX__", TI.getWCharWidth(), "", true, Buf); DefineTypeSize("__INTMAX_MAX__", IntMaxWidth, IntMaxSuffix, true, Buf); - if (TI.getIntMaxType() == TargetInfo::UnsignedLongLong) - DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned long long int"); - else if (TI.getIntMaxType() == TargetInfo::SignedLongLong) - DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long long int"); - else if (TI.getIntMaxType() == TargetInfo::UnsignedLong) - DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned long int"); - else if (TI.getIntMaxType() == TargetInfo::SignedLong) - DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=long int"); - else if (TI.getIntMaxType() == TargetInfo::UnsignedInt) - DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=unsigned int"); - else - DefineBuiltinMacro(Buf, "__INTMAX_TYPE__=int"); - - if (TI.getUIntMaxType() == TargetInfo::UnsignedLongLong) - DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned long long int"); - else if (TI.getUIntMaxType() == TargetInfo::SignedLongLong) - DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long long int"); - else if (TI.getUIntMaxType() == TargetInfo::UnsignedLong) - DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned long int"); - else if (TI.getUIntMaxType() == TargetInfo::SignedLong) - DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=long int"); - else if (TI.getUIntMaxType() == TargetInfo::UnsignedInt) - DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=unsigned int"); - else - DefineBuiltinMacro(Buf, "__UINTMAX_TYPE__=int"); - - if (TI.getPtrDiffType(0) == TargetInfo::UnsignedLongLong) - DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned long long int"); - else if (TI.getPtrDiffType(0) == TargetInfo::SignedLongLong) - DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long long int"); - else if (TI.getPtrDiffType(0) == TargetInfo::UnsignedLong) - DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned long int"); - else if (TI.getPtrDiffType(0) == TargetInfo::SignedLong) - DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=long int"); - else if (TI.getPtrDiffType(0) == TargetInfo::UnsignedInt) - DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=unsigned int"); - else { - assert(TI.getPtrDiffType(0) == TargetInfo::SignedInt); - DefineBuiltinMacro(Buf, "__PTRDIFF_TYPE__=int"); - } - - if (TI.getSizeType() == TargetInfo::UnsignedLongLong) - DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned long long int"); - else if (TI.getSizeType() == TargetInfo::SignedLongLong) - DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long long int"); - else if (TI.getSizeType() == TargetInfo::UnsignedLong) - DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned long int"); - else if (TI.getSizeType() == TargetInfo::SignedLong) - DefineBuiltinMacro(Buf, "__SIZE_TYPE__=long int"); - else if (TI.getSizeType() == TargetInfo::UnsignedInt) - DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned int"); - else if (TI.getSizeType() == TargetInfo::SignedInt) - DefineBuiltinMacro(Buf, "__SIZE_TYPE__=int"); - else { - assert(TI.getPtrDiffType(0) == TargetInfo::UnsignedShort); - DefineBuiltinMacro(Buf, "__SIZE_TYPE__=unsigned short"); - } - + DefineType("__INTMAX_TYPE__", TI.getIntMaxType(), Buf); + DefineType("__UINTMAX_TYPE__", TI.getUIntMaxType(), Buf); + DefineType("__PTRDIFF_TYPE__", TI.getPtrDiffType(0), Buf); + DefineType("__SIZE_TYPE__", TI.getSizeType(), Buf); + DefineFloatMacros(Buf, "FLT", &TI.getFloatFormat()); DefineFloatMacros(Buf, "DBL", &TI.getDoubleFormat()); DefineFloatMacros(Buf, "LDBL", &TI.getLongDoubleFormat()); |