aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaInit.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-24 22:41:04 +0000
committerChris Lattner <sabre@nondot.org>2009-02-24 22:41:04 +0000
commitf71ae8d8024561f92dd7916363e7a791684563cc (patch)
treee12e1822af35fecf7edb9730af1e2aea9db91f04 /lib/Sema/SemaInit.cpp
parent6c291a88bce9852225328b7b37a7ce1d1edec3c1 (diff)
make CheckStringLiteralInit a static function in SemaInit.cpp
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65396 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r--lib/Sema/SemaInit.cpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index fe2ff754a9..8f3a210efc 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -57,28 +57,29 @@ bool Sema::CheckSingleInitializer(Expr *&Init, QualType DeclType,
InitType, Init, "initializing");
}
-bool Sema::CheckStringLiteralInit(StringLiteral *strLiteral, QualType &DeclT) {
- const ArrayType *AT = Context.getAsArrayType(DeclT);
+static bool CheckStringLiteralInit(StringLiteral *Str, QualType &DeclT,
+ Sema &S) {
+ const ArrayType *AT = S.Context.getAsArrayType(DeclT);
if (const IncompleteArrayType *IAT = dyn_cast<IncompleteArrayType>(AT)) {
// C99 6.7.8p14. We have an array of character type with unknown size
// being initialized to a string literal.
llvm::APSInt ConstVal(32);
- ConstVal = strLiteral->getByteLength() + 1;
+ ConstVal = Str->getByteLength() + 1;
// Return a new array type (C99 6.7.8p22).
- DeclT = Context.getConstantArrayType(IAT->getElementType(), ConstVal,
- ArrayType::Normal, 0);
+ DeclT = S.Context.getConstantArrayType(IAT->getElementType(), ConstVal,
+ ArrayType::Normal, 0);
} else {
const ConstantArrayType *CAT = cast<ConstantArrayType>(AT);
// C99 6.7.8p14. We have an array of character type with known size.
// FIXME: Avoid truncation for 64-bit length strings.
- if (strLiteral->getByteLength() > (unsigned)CAT->getSize().getZExtValue())
- Diag(strLiteral->getSourceRange().getBegin(),
- diag::warn_initializer_string_for_char_array_too_long)
- << strLiteral->getSourceRange();
+ if (Str->getByteLength() > (unsigned)CAT->getSize().getZExtValue())
+ S.Diag(Str->getSourceRange().getBegin(),
+ diag::warn_initializer_string_for_char_array_too_long)
+ << Str->getSourceRange();
}
// Set type from "char *" to "constant array of char".
- strLiteral->setType(DeclT);
+ Str->setType(DeclT);
// For now, we always return false (meaning success).
return false;
}
@@ -106,8 +107,8 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
InitListExpr *InitList = dyn_cast<InitListExpr>(Init);
if (!InitList) {
// FIXME: Handle wide strings
- if (StringLiteral *StrLiteral = IsStringInit(Init, DeclType, Context))
- return CheckStringLiteralInit(StrLiteral, DeclType);
+ if (StringLiteral *Str = IsStringInit(Init, DeclType, Context))
+ return CheckStringLiteralInit(Str, DeclType, *this);
// C++ [dcl.init]p14:
// -- If the destination type is a (possibly cv-qualified) class
@@ -580,10 +581,10 @@ void InitListChecker::CheckSubElementType(InitListExpr *IList,
newStructuredList, newStructuredIndex);
++StructuredIndex;
++Index;
- } else if (StringLiteral *lit = IsStringInit(expr, ElemType,
+ } else if (StringLiteral *Str = IsStringInit(expr, ElemType,
SemaRef->Context)) {
- SemaRef->CheckStringLiteralInit(lit, ElemType);
- UpdateStructuredListElement(StructuredList, StructuredIndex, lit);
+ CheckStringLiteralInit(Str, ElemType, *SemaRef);
+ UpdateStructuredListElement(StructuredList, StructuredIndex, Str);
++Index;
} else if (ElemType->isScalarType()) {
CheckScalarType(IList, ElemType, Index, StructuredList, StructuredIndex);
@@ -766,15 +767,15 @@ void InitListChecker::CheckArrayType(InitListExpr *IList, QualType &DeclType,
unsigned &StructuredIndex) {
// Check for the special-case of initializing an array with a string.
if (Index < IList->getNumInits()) {
- if (StringLiteral *lit = IsStringInit(IList->getInit(Index), DeclType,
+ if (StringLiteral *Str = IsStringInit(IList->getInit(Index), DeclType,
SemaRef->Context)) {
- SemaRef->CheckStringLiteralInit(lit, DeclType);
+ CheckStringLiteralInit(Str, DeclType, *SemaRef);
// We place the string literal directly into the resulting
// initializer list. This is the only place where the structure
// of the structured initializer list doesn't match exactly,
// because doing so would involve allocating one character
// constant for each string.
- UpdateStructuredListElement(StructuredList, StructuredIndex, lit);
+ UpdateStructuredListElement(StructuredList, StructuredIndex, Str);
StructuredList->resizeInits(SemaRef->Context, StructuredIndex);
++Index;
return;