Deleted Added
full compact
SemaFixItUtils.cpp (234353) SemaFixItUtils.cpp (239462)
1//===--- SemaFixItUtils.cpp - Sema FixIts ---------------------------------===//
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 defines helper classes for generation of Sema FixItHints.
11//
12//===----------------------------------------------------------------------===//
13
1//===--- SemaFixItUtils.cpp - Sema FixIts ---------------------------------===//
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 defines helper classes for generation of Sema FixItHints.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/ASTContext.h"
14#include "clang/AST/ExprCXX.h"
15#include "clang/AST/ExprObjC.h"
16#include "clang/Lex/Preprocessor.h"
17#include "clang/Sema/Sema.h"
18#include "clang/Sema/SemaFixItUtils.h"
19
20using namespace clang;
21

--- 136 unchanged lines hidden (view full) ---

158
159 return false;
160}
161
162static bool isMacroDefined(const Sema &S, StringRef Name) {
163 return S.PP.getMacroInfo(&S.getASTContext().Idents.get(Name));
164}
165
15#include "clang/AST/ExprCXX.h"
16#include "clang/AST/ExprObjC.h"
17#include "clang/Lex/Preprocessor.h"
18#include "clang/Sema/Sema.h"
19#include "clang/Sema/SemaFixItUtils.h"
20
21using namespace clang;
22

--- 136 unchanged lines hidden (view full) ---

159
160 return false;
161}
162
163static bool isMacroDefined(const Sema &S, StringRef Name) {
164 return S.PP.getMacroInfo(&S.getASTContext().Idents.get(Name));
165}
166
166const char *Sema::getFixItZeroInitializerForType(QualType T) const {
167static std::string getScalarZeroExpressionForType(const Type& T, const Sema& S) {
168 assert(T.isScalarType() && "use scalar types only");
169 // Suggest "0" for non-enumeration scalar types, unless we can find a
170 // better initializer.
171 if (T.isEnumeralType())
172 return std::string();
173 if ((T.isObjCObjectPointerType() || T.isBlockPointerType()) &&
174 isMacroDefined(S, "nil"))
175 return "nil";
176 if (T.isRealFloatingType())
177 return "0.0";
178 if (T.isBooleanType() && S.LangOpts.CPlusPlus)
179 return "false";
180 if (T.isPointerType() || T.isMemberPointerType()) {
181 if (S.LangOpts.CPlusPlus0x)
182 return "nullptr";
183 if (isMacroDefined(S, "NULL"))
184 return "NULL";
185 }
186 if (T.isCharType())
187 return "'\\0'";
188 if (T.isWideCharType())
189 return "L'\\0'";
190 if (T.isChar16Type())
191 return "u'\\0'";
192 if (T.isChar32Type())
193 return "U'\\0'";
194 return "0";
195}
196
197std::string Sema::getFixItZeroInitializerForType(QualType T) const {
167 if (T->isScalarType()) {
198 if (T->isScalarType()) {
168 // Suggest " = 0" for non-enumeration scalar types, unless we can find a
169 // better initializer.
170 if (T->isEnumeralType())
171 return 0;
172 if ((T->isObjCObjectPointerType() || T->isBlockPointerType()) &&
173 isMacroDefined(*this, "nil"))
174 return " = nil";
175 if (T->isRealFloatingType())
176 return " = 0.0";
177 if (T->isBooleanType() && LangOpts.CPlusPlus)
178 return " = false";
179 if (T->isPointerType() || T->isMemberPointerType()) {
180 if (LangOpts.CPlusPlus0x)
181 return " = nullptr";
182 else if (isMacroDefined(*this, "NULL"))
183 return " = NULL";
184 }
185 if (T->isCharType())
186 return " = '\\0'";
187 if (T->isWideCharType())
188 return " = L'\\0'";
189 if (T->isChar16Type())
190 return " = u'\\0'";
191 if (T->isChar32Type())
192 return " = U'\\0'";
193 return " = 0";
199 std::string s = getScalarZeroExpressionForType(*T, *this);
200 if (!s.empty())
201 s = " = " + s;
202 return s;
194 }
195
196 const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
197 if (!RD || !RD->hasDefinition())
203 }
204
205 const CXXRecordDecl *RD = T->getAsCXXRecordDecl();
206 if (!RD || !RD->hasDefinition())
198 return 0;
207 return std::string();
199 if (LangOpts.CPlusPlus0x && !RD->hasUserProvidedDefaultConstructor())
200 return "{}";
201 if (RD->isAggregate())
202 return " = {}";
208 if (LangOpts.CPlusPlus0x && !RD->hasUserProvidedDefaultConstructor())
209 return "{}";
210 if (RD->isAggregate())
211 return " = {}";
203 return 0;
212 return std::string();
204}
213}
214
215std::string Sema::getFixItZeroLiteralForType(QualType T) const {
216 return getScalarZeroExpressionForType(*T, *this);
217}