[cfe-commits] r69780 - in /cfe/trunk: include/clang/AST/ExprObjC.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/objc_exprs.h test/PCH/objc_exprs.m

Chris Lattner sabre at nondot.org
Tue Apr 21 23:29:42 PDT 2009


Author: lattner
Date: Wed Apr 22 01:29:42 2009
New Revision: 69780

URL: http://llvm.org/viewvc/llvm-project?rev=69780&view=rev
Log:
add three new objc expression types.  @selector doesn't work because we have no 
way to serialize selectors yet.

Modified:
    cfe/trunk/include/clang/AST/ExprObjC.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/test/PCH/objc_exprs.h
    cfe/trunk/test/PCH/objc_exprs.m

Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=69780&r1=69779&r2=69780&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Wed Apr 22 01:29:42 2009
@@ -31,11 +31,15 @@
 public:
   ObjCStringLiteral(StringLiteral *SL, QualType T, SourceLocation L)
     : Expr(ObjCStringLiteralClass, T), String(SL), AtLoc(L) {}
-  
-  StringLiteral* getString() { return cast<StringLiteral>(String); }
-  const StringLiteral* getString() const { return cast<StringLiteral>(String); }
+  explicit ObjCStringLiteral(EmptyShell Empty)
+    : Expr(ObjCStringLiteralClass, Empty) {}
+
+  StringLiteral *getString() { return cast<StringLiteral>(String); }
+  const StringLiteral *getString() const { return cast<StringLiteral>(String); }
+  void setString(StringLiteral *S) { String = S; }
 
   SourceLocation getAtLoc() const { return AtLoc; }
+  void setAtLoc(SourceLocation L) { AtLoc = L; }
 
   virtual SourceRange getSourceRange() const { 
     return SourceRange(AtLoc, String->getLocEnd());
@@ -65,7 +69,6 @@
                  SourceLocation at, SourceLocation rp)
     : Expr(ObjCEncodeExprClass, T), EncType(ET), AtLoc(at), RParenLoc(rp) {}
   
-  /// \brief Build an empty block expression.
   explicit ObjCEncodeExpr(EmptyShell Empty) : Expr(ObjCEncodeExprClass, Empty){}
 
   
@@ -102,13 +105,17 @@
 public:
   ObjCSelectorExpr(QualType T, Selector selInfo,
                    SourceLocation at, SourceLocation rp)
-  : Expr(ObjCSelectorExprClass, T), SelName(selInfo), 
-  AtLoc(at), RParenLoc(rp) {}
-  
+  : Expr(ObjCSelectorExprClass, T), SelName(selInfo), AtLoc(at), RParenLoc(rp){}
+  explicit ObjCSelectorExpr(EmptyShell Empty)
+   : Expr(ObjCSelectorExprClass, Empty) {}
+
   Selector getSelector() const { return SelName; }
+  void setSelector(Selector S) { SelName = S; }
   
   SourceLocation getAtLoc() const { return AtLoc; }
   SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setAtLoc(SourceLocation L) { AtLoc = L; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
   virtual SourceRange getSourceRange() const {
     return SourceRange(AtLoc, RParenLoc);
@@ -130,20 +137,28 @@
   static ObjCSelectorExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
 };
   
-/// ObjCProtocolExpr used for protocol in Objective-C.
+/// ObjCProtocolExpr used for protocol expression in Objective-C.  This is used
+/// as: @protocol(foo), as in:
+///   obj conformsToProtocol:@protocol(foo)]
+/// The return type is "Protocol*".
 class ObjCProtocolExpr : public Expr {    
   ObjCProtocolDecl *Protocol;    
   SourceLocation AtLoc, RParenLoc;
 public:
   ObjCProtocolExpr(QualType T, ObjCProtocolDecl *protocol,
                    SourceLocation at, SourceLocation rp)
-  : Expr(ObjCProtocolExprClass, T), Protocol(protocol), 
-  AtLoc(at), RParenLoc(rp) {}
-    
+  : Expr(ObjCProtocolExprClass, T), Protocol(protocol),
+    AtLoc(at), RParenLoc(rp) {}
+  explicit ObjCProtocolExpr(EmptyShell Empty)
+    : Expr(ObjCProtocolExprClass, Empty) {}
+
   ObjCProtocolDecl *getProtocol() const { return Protocol; }
+  void setProtocol(ObjCProtocolDecl *P) { Protocol = P; }
     
   SourceLocation getAtLoc() const { return AtLoc; }
   SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setAtLoc(SourceLocation L) { AtLoc = L; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
   virtual SourceRange getSourceRange() const {
     return SourceRange(AtLoc, RParenLoc);

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69780&r1=69779&r2=69780&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 22 01:29:42 2009
@@ -523,8 +523,15 @@
       EXPR_BLOCK_DECL_REF,
       
       // Objective-C
+      
+      /// \brief A ObjCStringLiteral record.
+      EXPR_OBJC_STRING_LITERAL,
       /// \brief A ObjCEncodeExpr record.
-      EXPR_OBJC_ENCODE
+      EXPR_OBJC_ENCODE,
+      /// \brief A ObjCSelectorExpr record.
+      EXPR_OBJC_SELECTOR_EXPR,
+      /// \brief A ObjCProtocolExpr record.
+      EXPR_OBJC_PROTOCOL_EXPR
 
     };
 

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69780&r1=69779&r2=69780&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 22 01:29:42 2009
@@ -466,7 +466,10 @@
     unsigned VisitShuffleVectorExpr(ShuffleVectorExpr *E);
     unsigned VisitBlockExpr(BlockExpr *E);
     unsigned VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
+    unsigned VisitObjCStringLiteral(ObjCStringLiteral *E);
     unsigned VisitObjCEncodeExpr(ObjCEncodeExpr *E);
+    unsigned VisitObjCSelectorExpr(ObjCSelectorExpr *E);
+    unsigned VisitObjCProtocolExpr(ObjCProtocolExpr *E);
   };
 }
 
@@ -1016,6 +1019,16 @@
   return 0;
 }
 
+//===----------------------------------------------------------------------===//
+// Objective-C Expressions and Statements
+
+unsigned PCHStmtReader::VisitObjCStringLiteral(ObjCStringLiteral *E) {
+  VisitExpr(E);
+  E->setString(cast<StringLiteral>(StmtStack.back()));
+  E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 1;
+}
+
 unsigned PCHStmtReader::VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
   VisitExpr(E);
   E->setEncodedType(Reader.GetType(Record[Idx++]));
@@ -1024,6 +1037,22 @@
   return 0;
 }
 
+unsigned PCHStmtReader::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
+  VisitExpr(E);
+  // FIXME: Selectors.
+  E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 0;
+}
+
+unsigned PCHStmtReader::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
+  VisitExpr(E);
+  E->setProtocol(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
+  E->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 0;
+}
+
 
 //===----------------------------------------------------------------------===//
 // PCH reader implementation
@@ -2946,9 +2975,18 @@
       S = new (Context) BlockDeclRefExpr(Empty);
       break;
         
+    case pch::EXPR_OBJC_STRING_LITERAL:
+      S = new (Context) ObjCStringLiteral(Empty);
+      break;
     case pch::EXPR_OBJC_ENCODE:
       S = new (Context) ObjCEncodeExpr(Empty);
       break;
+    case pch::EXPR_OBJC_SELECTOR_EXPR:
+      S = new (Context) ObjCSelectorExpr(Empty);
+      break;
+    case pch::EXPR_OBJC_PROTOCOL_EXPR:
+      S = new (Context) ObjCProtocolExpr(Empty);
+      break;
     }
 
     // We hit a STMT_STOP, so we're done with this expression.

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69780&r1=69779&r2=69780&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 22 01:29:42 2009
@@ -658,9 +658,10 @@
     void VisitBlockDeclRefExpr(BlockDeclRefExpr *E);
       
     // Objective-C
+    void VisitObjCStringLiteral(ObjCStringLiteral *E);
     void VisitObjCEncodeExpr(ObjCEncodeExpr *E);
-
-      
+    void VisitObjCSelectorExpr(ObjCSelectorExpr *E);
+    void VisitObjCProtocolExpr(ObjCProtocolExpr *E);
   };
 }
 
@@ -1156,6 +1157,13 @@
 // Objective-C Expressions and Statements.
 //===----------------------------------------------------------------------===//
 
+void PCHStmtWriter::VisitObjCStringLiteral(ObjCStringLiteral *E) {
+  VisitExpr(E);
+  Writer.WriteSubStmt(E->getString());
+  Writer.AddSourceLocation(E->getAtLoc(), Record);
+  Code = pch::EXPR_OBJC_STRING_LITERAL;
+}
+
 void PCHStmtWriter::VisitObjCEncodeExpr(ObjCEncodeExpr *E) { 
   VisitExpr(E);
   Writer.AddTypeRef(E->getEncodedType(), Record);
@@ -1164,6 +1172,23 @@
   Code = pch::EXPR_OBJC_ENCODE;
 }
 
+void PCHStmtWriter::VisitObjCSelectorExpr(ObjCSelectorExpr *E) {
+  VisitExpr(E);
+  // FIXME!  Write selectors.
+  //Writer.WriteSubStmt(E->getSelector());
+  Writer.AddSourceLocation(E->getAtLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_OBJC_SELECTOR_EXPR;
+}
+
+void PCHStmtWriter::VisitObjCProtocolExpr(ObjCProtocolExpr *E) {
+  VisitExpr(E);
+  Writer.AddDeclRef(E->getProtocol(), Record);
+  Writer.AddSourceLocation(E->getAtLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_OBJC_PROTOCOL_EXPR;
+}
+
 
 //===----------------------------------------------------------------------===//
 // PCHWriter Implementation

Modified: cfe/trunk/test/PCH/objc_exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/objc_exprs.h?rev=69780&r1=69779&r2=69780&view=diff

==============================================================================
--- cfe/trunk/test/PCH/objc_exprs.h (original)
+++ cfe/trunk/test/PCH/objc_exprs.h Wed Apr 22 01:29:42 2009
@@ -1,5 +1,11 @@
 
-inline const char *foo() {
-  return @encode(int);
-}
+ at protocol foo;
 
+typedef typeof(@"foo" "bar") objc_string;
+
+typedef typeof(@encode(int)) objc_encode;
+
+
+typedef typeof(@protocol(foo)) objc_protocol;
+
+//const char *X;

Modified: cfe/trunk/test/PCH/objc_exprs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/objc_exprs.m?rev=69780&r1=69779&r2=69780&view=diff

==============================================================================
--- cfe/trunk/test/PCH/objc_exprs.m (original)
+++ cfe/trunk/test/PCH/objc_exprs.m Wed Apr 22 01:29:42 2009
@@ -5,3 +5,14 @@
 // RUN: clang-cc -x objective-c-header -emit-pch -fblocks -o %t %S/objc_exprs.h &&
 // RUN: clang-cc -fblocks -include-pch %t -fsyntax-only -verify %s 
 
+
+
+int *A1 = (objc_string)0;   // expected-warning {{'struct objc_object *'}}
+
+char A2 = (objc_encode){};  // expected-error {{initializer element is not a compile-time constant}} \
+                               expected-warning {{char [2]}}
+
+int *A3 = (objc_protocol)0; // expected-warning {{aka 'Protocol *'}}
+
+
+





More information about the cfe-commits mailing list