aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-24 22:18:39 +0000
committerChris Lattner <sabre@nondot.org>2009-02-24 22:18:39 +0000
commiteaf2bb89eb2aad3b80673de30febe52df43c10ec (patch)
treef6b8b9fd6f0e42047f23937bb34139ddface6a4b /lib/Sema
parent8459132b0302cde7eb2a21eb2c6ffca9e66e3aea (diff)
first wave of fixes for @encode sema support. This is part of PR3648.
The big difference here is that (like string literal) @encode has array type, not pointer type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65391 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/SemaDecl.cpp4
-rw-r--r--lib/Sema/SemaExprObjC.cpp15
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 2af6ab1bb3..373296fb58 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -1178,8 +1178,8 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType,
InitListExpr *InitList = dyn_cast<InitListExpr>(Init);
if (!InitList) {
// FIXME: Handle wide strings
- if (StringLiteral *strLiteral = IsStringLiteralInit(Init, DeclType))
- return CheckStringLiteralInit(strLiteral, DeclType);
+ if (StringLiteral *StrLiteral = IsStringLiteralInit(Init, DeclType))
+ return CheckStringLiteralInit(StrLiteral, DeclType);
// C++ [dcl.init]p14:
// -- If the destination type is a (possibly cv-qualified) class
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 9bcc81028d..7696cf0608 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -95,8 +95,19 @@ Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
SourceLocation RParenLoc) {
QualType EncodedType = QualType::getFromOpaquePtr(ty);
- QualType Ty = Context.getPointerType(Context.CharTy);
- return new (Context) ObjCEncodeExpr(Ty, EncodedType, AtLoc, RParenLoc);
+ std::string Str;
+ Context.getObjCEncodingForType(EncodedType, Str);
+
+ // The type of @encode is the same as the type of the corresponding string,
+ // which is an array type.
+ QualType StrTy = Context.CharTy;
+ // A C++ string literal has a const-qualified element type (C++ 2.13.4p1).
+ if (getLangOptions().CPlusPlus)
+ StrTy.addConst();
+ StrTy = Context.getConstantArrayType(StrTy, llvm::APInt(32, Str.size()+1),
+ ArrayType::Normal, 0);
+
+ return new (Context) ObjCEncodeExpr(StrTy, EncodedType, AtLoc, RParenLoc);
}
Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,