diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-13 19:34:55 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-01-13 19:34:55 +0000 |
commit | e40141542d96f556b5c1b5e3b8acca8f11c27527 (patch) | |
tree | 477484913431a0f9fec417b878405f1733590565 /lib/Sema/SemaFixItUtils.cpp | |
parent | fdf187c4cb7ebfaeebe96ddba189da34027e0b22 (diff) |
Refactor for clarity.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148135 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaFixItUtils.cpp')
-rw-r--r-- | lib/Sema/SemaFixItUtils.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/lib/Sema/SemaFixItUtils.cpp b/lib/Sema/SemaFixItUtils.cpp index 0f7530b415..3b76213e20 100644 --- a/lib/Sema/SemaFixItUtils.cpp +++ b/lib/Sema/SemaFixItUtils.cpp @@ -159,26 +159,32 @@ bool ConversionFixItGenerator::tryToFixConversion(const Expr *FullExpr, return false; } +static bool isMacroDefined(const Sema &S, StringRef Name) { + return S.PP.getMacroInfo(&S.getASTContext().Idents.get(Name)); +} + const char *Sema::getFixItZeroInitializerForType(QualType T) const { - // Suggest 'nil' if it's defined and appropriate. - if ((T->isObjCObjectPointerType() || T->isBlockPointerType()) && - PP.getMacroInfo(&getASTContext().Idents.get("nil"))) - return " = nil"; - if (T->isRealFloatingType()) - return " = 0.0"; - if (T->isBooleanType() && LangOpts.CPlusPlus) - return " = false"; - if (T->isPointerType() || T->isMemberPointerType()) { - if (LangOpts.CPlusPlus0x) - return " = nullptr"; - // Check if 'NULL' is defined. - else if (PP.getMacroInfo(&getASTContext().Idents.get("NULL"))) - return " = NULL"; - } - if (T->isEnumeralType()) - return 0; - if (T->isScalarType()) + if (T->isScalarType()) { + // Suggest " = 0" for non-enumeration scalar types, unless we can find a + // better initializer. + if (T->isEnumeralType()) + return 0; + if ((T->isObjCObjectPointerType() || T->isBlockPointerType()) && + isMacroDefined(*this, "nil")) + return " = nil"; + if (T->isRealFloatingType()) + return " = 0.0"; + if (T->isBooleanType() && LangOpts.CPlusPlus) + return " = false"; + if (T->isPointerType() || T->isMemberPointerType()) { + if (LangOpts.CPlusPlus0x) + return " = nullptr"; + else if (isMacroDefined(*this, "NULL")) + return " = NULL"; + } return " = 0"; + } + const CXXRecordDecl *RD = T->getAsCXXRecordDecl(); if (!RD || !RD->hasDefinition()) return 0; |