[cfe-commits] r148135 - /cfe/trunk/lib/Sema/SemaFixItUtils.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Fri Jan 13 11:34:56 PST 2012
Author: rsmith
Date: Fri Jan 13 13:34:55 2012
New Revision: 148135
URL: http://llvm.org/viewvc/llvm-project?rev=148135&view=rev
Log:
Refactor for clarity.
Modified:
cfe/trunk/lib/Sema/SemaFixItUtils.cpp
Modified: cfe/trunk/lib/Sema/SemaFixItUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaFixItUtils.cpp?rev=148135&r1=148134&r2=148135&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaFixItUtils.cpp (original)
+++ cfe/trunk/lib/Sema/SemaFixItUtils.cpp Fri Jan 13 13:34:55 2012
@@ -159,26 +159,32 @@
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;
More information about the cfe-commits
mailing list