]> granicus.if.org Git - clang/commitdiff
Parse @encode expressions.
authorAnders Carlsson <andersca@mac.com>
Wed, 22 Aug 2007 15:14:15 +0000 (15:14 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 22 Aug 2007 15:14:15 +0000 (15:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41273 91177308-0d34-0410-b5e6-96231b3b80d8

AST/StmtDumper.cpp
AST/StmtPrinter.cpp
Parse/ParseObjc.cpp
Sema/Sema.h
Sema/SemaExpr.cpp
include/clang/AST/Expr.h
include/clang/AST/StmtNodes.def
include/clang/Parse/Action.h
include/clang/Parse/Parser.h

index 22af23cc0e0d597be0e6083c65a1ed720d575d4a..cf1eab172e2b9b79e9b7f8c33b4f218df323f418 100644 (file)
@@ -503,6 +503,14 @@ void StmtDumper::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
   fprintf(F, ")");
 }
 
+void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
+  DumpExpr(Node);
+  fprintf(F, " ");
+  DumpType(Node->getEncodedType());
+  fprintf(F, ")");  
+}
+
 //===----------------------------------------------------------------------===//
 // Stmt method implementations
 //===----------------------------------------------------------------------===//
index 6b2fce874a44ff73550625174fc470b5e273b6f7..2c77f131d8528c22a2a0fb2530121bacc49c15c0 100644 (file)
@@ -518,6 +518,11 @@ void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
   VisitStringLiteral(Node->getString());
 }
 
+void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
+  OS << "@encode(";
+  OS << Node->getEncodedType().getAsString() << ")";
+}
+
 //===----------------------------------------------------------------------===//
 // Stmt method implementations
 //===----------------------------------------------------------------------===//
index 94a5c8d42cb0138dab8a6f9f6ff9ed7e734ab7b3..98395d192212a5527c826a52ae82480068c75cc9 100644 (file)
@@ -369,6 +369,9 @@ Parser::ExprResult Parser::ParseObjCExpression() {
     case tok::string_literal:    // primary-expression: string-literal
     case tok::wide_string_literal:
       return ParseObjCStringLiteral();
+    case tok::objc_encode:
+      return ParseObjCEncodeExpression();
+      break;
     default:
       Diag(AtLoc, diag::err_unexpected_at);
       SkipUntil(tok::semi);
@@ -385,3 +388,29 @@ Parser::ExprResult Parser::ParseObjCStringLiteral() {
 
   return Actions.ParseObjCStringLiteral(Res.Val);
 }
+
+///    objc-encode-expression:
+///      @encode ( type-name )
+Parser::ExprResult Parser::ParseObjCEncodeExpression() {
+  assert(Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_encode && 
+         "Not an @encode expression!");
+  
+  SourceLocation EncLoc = ConsumeToken();
+  
+  if (Tok.getKind() != tok::l_paren) {
+    Diag(Tok, diag::err_expected_lparen_after, "@encode");
+    return true;
+  }
+   
+  SourceLocation LParenLoc = ConsumeParen();
+  
+  TypeTy *Ty = ParseTypeName();
+  
+  if (Tok.getKind() != tok::r_paren) {
+    Diag(Tok, diag::err_expected_rparen);
+    return true;
+  }
+   
+  return Actions.ParseObjCEncodeExpression(EncLoc, LParenLoc, Ty, 
+                                           ConsumeParen());
+}
index 42beb84f385bbc050ae8ce0bb7b9eab361b48682..505633529c56a116d655e85501c2a37b63079cca 100644 (file)
@@ -326,6 +326,11 @@ public:
   
   // ParseObjCStringLiteral - Parse Objective-C string literals.
   virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
+  virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
+                                               SourceLocation LParenLoc,
+                                               TypeTy *Ty,
+                                               SourceLocation RParenLoc);
+  
 private:
   // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
   // functions and arrays to their respective pointers (C99 6.3.2.1). 
index da3bc3d94f9fa278b659ec3287882f9201dbf1ab..7fc6422ab7bb82134ce9bb1631bb5944e8e6a12d 100644 (file)
@@ -1658,8 +1658,7 @@ Sema::ExprResult Sema::ParseChooseExpr(SourceLocation BuiltinLoc, ExprTy *cond,
 }
 
 // TODO: Move this to SemaObjC.cpp
-Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string)
-{
+Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string) {
   StringLiteral* S = static_cast<StringLiteral *>(string);
   
   if (CheckBuiltinCFStringArgument(S))
@@ -1671,3 +1670,13 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string)
 
   return new ObjCStringLiteral(S, t);
 }
+
+Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
+                                                 SourceLocation LParenLoc,
+                                                 TypeTy *Ty,
+                                                 SourceLocation RParenLoc) {
+  QualType EncodedType = QualType::getFromOpaquePtr(Ty);
+
+  QualType t = Context.getPointerType(Context.CharTy);
+  return new ObjCEncodeExpr(t, EncodedType, AtLoc, RParenLoc);
+}
index 94cf512e30b78d6f7becca20b84d1661f3f3dc08..4136a9eb1d071fb5df0ab9909eebabb72ae7f201 100644 (file)
@@ -834,6 +834,25 @@ public:
   static bool classof(const ObjCStringLiteral *) { return true; }  
 };
   
+/// ObjCEncodeExpr, used for @encode in Objective-C.
+class ObjCEncodeExpr : public Expr {
+  QualType EncType;
+  SourceLocation EncLoc, RParenLoc;
+public:
+  ObjCEncodeExpr(QualType T, QualType ET, 
+                 SourceLocation enc, SourceLocation rp)
+    : Expr(ObjCEncodeExprClass, T), EncType(ET), EncLoc(enc), RParenLoc(rp) {}
+  
+  SourceRange getSourceRange() const { return SourceRange(EncLoc, RParenLoc); }
+
+  QualType getEncodedType() const { return EncType; }
+
+  static bool classof(const Stmt *T) {
+    return T->getStmtClass() == ObjCEncodeExprClass;
+  }
+  static bool classof(const ObjCEncodeExpr *) { return true; }
+};
+
 }  // end namespace clang
 
 #endif
index 9fa780c314e98dd8c0451ae04a8d9cb2152ead3c..6a67e76cda9f231e97d419fdd8a2feab579a0d97 100644 (file)
@@ -76,6 +76,7 @@ STMT(55, CXXBoolLiteralExpr   , Expr)
 
 // Obj-C Expressions.
 STMT(56, ObjCStringLiteral    , Expr)
+STMT(57, ObjCEncodeExpr       , Expr)
 
 LAST_EXPR(56)
 
index 668bfb6d016d0103d056b73c64a8d6ac7f8f2a94..1ddbe85fb4df535e7d09cd22a0744ec2660f0fc1 100644 (file)
@@ -409,6 +409,13 @@ public:
   virtual ExprResult ParseObjCStringLiteral(ExprTy *string) {
     return 0;
   }
+
+  virtual ExprResult ParseObjCEncodeExpression(SourceLocation EncLoc,
+                                               SourceLocation LParenLoc,
+                                               TypeTy *Ty,
+                                               SourceLocation RParenLoc) {
+    return 0;
+  }
   
 };
 
index 02c2ee70f38608fdcffa3534720e82fb2d3e9036..f0063f3748fbb301342075af34230bcf02a64bb6 100644 (file)
@@ -327,7 +327,8 @@ private:
   // Objective-C Expressions
   ExprResult ParseObjCExpression();
   ExprResult ParseObjCStringLiteral();
-  
+  ExprResult ParseObjCEncodeExpression();
+
   //===--------------------------------------------------------------------===//
   // C99 6.8: Statements and Blocks.