[cfe-commits] r73034 - in /cfe/trunk: include/clang/AST/ExprObjC.h lib/Sema/Sema.h lib/Sema/SemaExprObjC.cpp lib/Sema/SemaTemplateInstantiateExpr.cpp test/SemaTemplate/instantiate-objc-1.mm
Anders Carlsson
andersca at mac.com
Sun Jun 7 11:45:36 PDT 2009
Author: andersca
Date: Sun Jun 7 13:45:35 2009
New Revision: 73034
URL: http://llvm.org/viewvc/llvm-project?rev=73034&view=rev
Log:
Template instantiation support for Obj-C @encode expressions.
Added:
cfe/trunk/test/SemaTemplate/instantiate-objc-1.mm
Modified:
cfe/trunk/include/clang/AST/ExprObjC.h
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=73034&r1=73033&r2=73034&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Sun Jun 7 13:45:35 2009
@@ -64,7 +64,8 @@
public:
ObjCEncodeExpr(QualType T, QualType ET,
SourceLocation at, SourceLocation rp)
- : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {}
+ : Expr(ObjCEncodeExprClass, T, ET->isDependentType(),
+ ET->isDependentType()), EncType(ET), AtLoc(at), RParenLoc(rp) {}
explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=73034&r1=73033&r2=73034&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Jun 7 13:45:35 2009
@@ -1696,6 +1696,10 @@
virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
ExprTy **Strings,
unsigned NumStrings);
+
+ Expr *BuildObjCEncodeExpression(SourceLocation AtLoc,
+ QualType EncodedType,
+ SourceLocation RParenLoc);
virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
SourceLocation EncodeLoc,
SourceLocation LParenLoc,
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=73034&r1=73033&r2=73034&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sun Jun 7 13:45:35 2009
@@ -92,6 +92,29 @@
return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]);
}
+Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc,
+ QualType EncodedType,
+ SourceLocation RParenLoc) {
+ QualType StrTy;
+ if (EncodedType->isDependentType())
+ StrTy = Context.DependentTy;
+ else {
+ 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.
+ 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::ParseObjCEncodeExpression(SourceLocation AtLoc,
SourceLocation EncodeLoc,
SourceLocation LParenLoc,
@@ -99,19 +122,7 @@
SourceLocation RParenLoc) {
QualType EncodedType = QualType::getFromOpaquePtr(ty);
- 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);
+ return BuildObjCEncodeExpression(AtLoc, EncodedType, RParenLoc);
}
Sema::ExprResult Sema::ParseObjCSelectorExpression(Selector Sel,
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp?rev=73034&r1=73033&r2=73034&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateExpr.cpp Sun Jun 7 13:45:35 2009
@@ -1222,9 +1222,17 @@
}
Sema::OwningExprResult
-TemplateExprInstantiator::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
- assert(false && "FIXME: Template instantiations for ObjC expressions");
- return SemaRef.ExprError();
+TemplateExprInstantiator::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
+ QualType EncodedType = SemaRef.InstantiateType(E->getEncodedType(),
+ TemplateArgs,
+ /*FIXME:*/E->getAtLoc(),
+ DeclarationName());
+ if (EncodedType.isNull())
+ return SemaRef.ExprError();
+
+ return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(E->getAtLoc(),
+ EncodedType,
+ E->getRParenLoc()));
}
Sema::OwningExprResult
Added: cfe/trunk/test/SemaTemplate/instantiate-objc-1.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-objc-1.mm?rev=73034&view=auto
==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-objc-1.mm (added)
+++ cfe/trunk/test/SemaTemplate/instantiate-objc-1.mm Sun Jun 7 13:45:35 2009
@@ -0,0 +1,12 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+// @encode expressions
+
+template <typename T> struct Encode {
+ static const char *encode(T t) {
+ return @encode(T);
+ }
+};
+
+template struct Encode<int>;
+template struct Encode<double>;
More information about the cfe-commits
mailing list