Instantiation support for more Obj-C expressions, string literals, @selector and @protocol expressions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73036 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/ExprObjC.h b/include/clang/AST/ExprObjC.h
index a573025..ef78c40 100644
--- a/include/clang/AST/ExprObjC.h
+++ b/include/clang/AST/ExprObjC.h
@@ -34,6 +34,8 @@
   explicit ObjCStringLiteral(EmptyShell Empty)
     : Expr(ObjCStringLiteralClass, Empty) {}
 
+  ObjCStringLiteral* Clone(ASTContext &C) const;
+
   StringLiteral *getString() { return cast<StringLiteral>(String); }
   const StringLiteral *getString() const { return cast<StringLiteral>(String); }
   void setString(StringLiteral *S) { String = S; }
@@ -104,6 +106,8 @@
   explicit ObjCSelectorExpr(EmptyShell Empty)
    : Expr(ObjCSelectorExprClass, Empty) {}
 
+  ObjCSelectorExpr *Clone(ASTContext &C) const;
+  
   Selector getSelector() const { return SelName; }
   void setSelector(Selector S) { SelName = S; }
   
@@ -144,6 +148,8 @@
   explicit ObjCProtocolExpr(EmptyShell Empty)
     : Expr(ObjCProtocolExprClass, Empty) {}
 
+  ObjCProtocolExpr *Clone(ASTContext &C) const;
+  
   ObjCProtocolDecl *getProtocol() const { return Protocol; }
   void setProtocol(ObjCProtocolDecl *P) { Protocol = P; }
     
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 4a53a41..c12dd67 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -1556,6 +1556,22 @@
   RBracloc = RBrac;
 }
 
+ObjCStringLiteral* ObjCStringLiteral::Clone(ASTContext &C) const {
+  // Clone the string literal.
+  StringLiteral *NewString = 
+    String ? cast<StringLiteral>(String)->Clone(C) : 0;
+  
+  return new (C) ObjCStringLiteral(NewString, getType(), AtLoc);
+}
+
+ObjCSelectorExpr *ObjCSelectorExpr::Clone(ASTContext &C) const {
+  return new (C) ObjCSelectorExpr(getType(), SelName, AtLoc, RParenLoc);
+}
+
+ObjCProtocolExpr *ObjCProtocolExpr::Clone(ASTContext &C) const {
+  return new (C) ObjCProtocolExpr(getType(), Protocol, AtLoc, RParenLoc);
+}
+
 // constructor for class messages. 
 // FIXME: clsName should be typed to ObjCInterfaceType
 ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp
index 9576627..fa5fdee 100644
--- a/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -1216,9 +1216,8 @@
 // Objective-C Expressions
 //----------------------------------------------------------------------------
 Sema::OwningExprResult 
-TemplateExprInstantiator::VisitObjCStringLiteral(ObjCStringLiteral *E) { 
-  assert(false && "FIXME: Template instantiations for ObjC expressions");
-  return SemaRef.ExprError();
+TemplateExprInstantiator::VisitObjCStringLiteral(ObjCStringLiteral *E) {
+  return SemaRef.Owned(E->Clone(SemaRef.Context));
 }
 
 Sema::OwningExprResult 
@@ -1243,14 +1242,12 @@
 
 Sema::OwningExprResult 
 TemplateExprInstantiator::VisitObjCSelectorExpr(ObjCSelectorExpr *E) { 
-  assert(false && "FIXME: Template instantiations for ObjC expressions");
-  return SemaRef.ExprError();
+  return SemaRef.Owned(E->Clone(SemaRef.Context));
 }
 
 Sema::OwningExprResult 
 TemplateExprInstantiator::VisitObjCProtocolExpr(ObjCProtocolExpr *E) { 
-  assert(false && "FIXME: Template instantiations for ObjC expressions");
-  return SemaRef.ExprError();
+  return SemaRef.Owned(E->Clone(SemaRef.Context));
 }
 
 Sema::OwningExprResult 
diff --git a/test/SemaTemplate/instantiate-objc-1.mm b/test/SemaTemplate/instantiate-objc-1.mm
index d0321e9..829acb2 100644
--- a/test/SemaTemplate/instantiate-objc-1.mm
+++ b/test/SemaTemplate/instantiate-objc-1.mm
@@ -1,12 +1,47 @@
 // RUN: clang-cc -fsyntax-only -verify %s
 
-// @encode expressions
+// Obj-C string literal expressions
+template <typename T> struct StringTest {
+  void f() {
+    (void)@"Hello";
+  }
+};
 
-template <typename T> struct Encode {
+template struct StringTest<int>;
+template struct StringTest<double>;
+
+// @selector expressions
+template <typename T> struct SelectorTest {
+  SEL f() {
+    return @selector(multiple:arguments:);
+  }
+  SEL f2() {
+    return @selector(multiple:arguments:);
+  }
+};
+
+template struct SelectorTest<int>;
+template struct SelectorTest<double>;
+
+// @protocol expressions
+@protocol P
+@end
+
+template <typename T> struct ProtocolTest {
+  void f() {
+    (void)@protocol(P);
+  }
+};
+
+template struct ProtocolTest<int>;
+template struct ProtocolTest<double>;
+
+// @encode expressions
+template <typename T> struct EncodeTest {
   static const char *encode(T t) { 
     return @encode(T);
   }
 };
 
-template struct Encode<int>;
-template struct Encode<double>;
+template struct EncodeTest<int>;
+template struct EncodeTest<double>;