[cfe-commits] r44172 - in /cfe/trunk: AST/Expr.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/Parse/Action.h

Steve Naroff snaroff at apple.com
Thu Nov 15 05:05:44 PST 2007


Author: snaroff
Date: Thu Nov 15 07:05:42 2007
New Revision: 44172

URL: http://llvm.org/viewvc/llvm-project?rev=44172&view=rev
Log:

Finish up variadic methods/messages.


Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=44172&r1=44171&r2=44172&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Thu Nov 15 07:05:42 2007
@@ -898,14 +898,14 @@
 ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
                 QualType retType, ObjcMethodDecl *mproto,
                 SourceLocation LBrac, SourceLocation RBrac,
-                Expr **ArgExprs)
+                Expr **ArgExprs, unsigned nargs)
   : Expr(ObjCMessageExprClass, retType), SelName(selInfo), 
     MethodProto(mproto), ClassName(0) {
-  unsigned numArgs = selInfo.getNumArgs();
-  SubExprs = new Expr*[numArgs+1];
+  NumArgs = nargs;
+  SubExprs = new Expr*[NumArgs+1];
   SubExprs[RECEIVER] = receiver;
-  if (numArgs) {
-    for (unsigned i = 0; i != numArgs; ++i)
+  if (NumArgs) {
+    for (unsigned i = 0; i != NumArgs; ++i)
       SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
   }
   LBracloc = LBrac;
@@ -917,14 +917,14 @@
 ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
                 QualType retType, ObjcMethodDecl *mproto,
                 SourceLocation LBrac, SourceLocation RBrac,
-                Expr **ArgExprs)
+                Expr **ArgExprs, unsigned nargs)
   : Expr(ObjCMessageExprClass, retType), SelName(selInfo), 
     MethodProto(mproto), ClassName(clsName) {
-  unsigned numArgs = selInfo.getNumArgs();
-  SubExprs = new Expr*[numArgs+1];
+  NumArgs = nargs;
+  SubExprs = new Expr*[NumArgs+1];
   SubExprs[RECEIVER] = 0;
-  if (numArgs) {
-    for (unsigned i = 0; i != numArgs; ++i)
+  if (NumArgs) {
+    for (unsigned i = 0; i != NumArgs; ++i)
       SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
   }
   LBracloc = LBrac;

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=44172&r1=44171&r2=44172&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Thu Nov 15 07:05:42 2007
@@ -1291,9 +1291,15 @@
     }
     // Parse the, optional, argument list, comma separated.
     while (Tok.is(tok::comma)) {
-      ConsumeToken();
-      /// Parse the expression after ','
-      ParseAssignmentExpression();
+      ConsumeToken(); // Eat the ','.
+      ///  Parse the expression after ',' 
+      ExprResult Res = ParseAssignmentExpression();
+      if (Res.isInvalid) {
+        SkipUntil(tok::identifier);
+        return Res;
+      }
+      // We have a valid expression.
+      KeyExprs.push_back(Res.Val);
     }
   } else if (!selIdent) {
     Diag(Tok, diag::err_expected_ident); // missing selector name.
@@ -1317,9 +1323,9 @@
   if (ReceiverName) 
     return Actions.ActOnClassMessage(CurScope,
                                      ReceiverName, Sel, LBracloc, RBracloc,
-                                     &KeyExprs[0]);
+                                     &KeyExprs[0], KeyExprs.size());
   return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracloc, RBracloc,
-                                      &KeyExprs[0]);
+                                      &KeyExprs[0], KeyExprs.size());
 }
 
 Parser::ExprResult Parser::ParseObjCStringLiteral(SourceLocation AtLoc) {

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=44172&r1=44171&r2=44172&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Thu Nov 15 07:05:42 2007
@@ -565,18 +565,20 @@
 
   // ActOnClassMessage - used for both unary and keyword messages.
   // ArgExprs is optional - if it is present, the number of expressions
-  // is obtained from Sel.getNumArgs().
+  // is obtained from NumArgs.
   virtual ExprResult ActOnClassMessage(
     Scope *S,
     IdentifierInfo *receivingClassName, Selector Sel,
-    SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
+    SourceLocation lbrac, SourceLocation rbrac, 
+    ExprTy **ArgExprs, unsigned NumArgs);
 
   // ActOnInstanceMessage - used for both unary and keyword messages.
   // ArgExprs is optional - if it is present, the number of expressions
-  // is obtained from Sel.getNumArgs().
+  // is obtained from NumArgs.
   virtual ExprResult ActOnInstanceMessage(
     ExprTy *receiver, Selector Sel,
-    SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
+    SourceLocation lbrac, SourceLocation rbrac, 
+    ExprTy **ArgExprs, unsigned NumArgs);
 private:
   // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
   // functions and arrays to their respective pointers (C99 6.3.2.1). 

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44172&r1=44171&r2=44172&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Thu Nov 15 07:05:42 2007
@@ -2124,7 +2124,7 @@
 Sema::ExprResult Sema::ActOnClassMessage(
   Scope *S,
   IdentifierInfo *receiverName, Selector Sel,
-  SourceLocation lbrac, SourceLocation rbrac, ExprTy **Args)
+  SourceLocation lbrac, SourceLocation rbrac, ExprTy **Args, unsigned NumArgs)
 {
   assert(receiverName && "missing receiver class name");
 
@@ -2142,7 +2142,7 @@
                                    SourceLocation(), ReceiverExpr.Val);
       
       return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
-                                  Args);
+                                  Args, NumArgs);
     }
     // class method
     if (ClassDecl)
@@ -2168,7 +2168,7 @@
     }
   }
   return new ObjCMessageExpr(receiverName, Sel, returnType, Method,
-                             lbrac, rbrac, ArgExprs);
+                             lbrac, rbrac, ArgExprs, NumArgs);
 }
 
 // ActOnInstanceMessage - used for both unary and keyword messages.
@@ -2176,7 +2176,7 @@
 // is obtained from Sel.getNumArgs().
 Sema::ExprResult Sema::ActOnInstanceMessage(
   ExprTy *receiver, Selector Sel,
-  SourceLocation lbrac, SourceLocation rbrac, ExprTy **Args) 
+  SourceLocation lbrac, SourceLocation rbrac, ExprTy **Args, unsigned NumArgs) 
 {
   assert(receiver && "missing receiver expression");
   
@@ -2250,5 +2250,5 @@
     }
   }
   return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
-                             ArgExprs);
+                             ArgExprs, NumArgs);
 }

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Nov 15 07:05:42 2007
@@ -1292,6 +1292,8 @@
 
   Expr **SubExprs;
   
+  unsigned NumArgs;
+  
   // A unigue name for this message.
   Selector SelName;
   
@@ -1309,12 +1311,12 @@
   ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
                   QualType retType, ObjcMethodDecl *methDecl,
                   SourceLocation LBrac, SourceLocation RBrac,
-                  Expr **ArgExprs);
+                  Expr **ArgExprs, unsigned NumArgs);
   // constructor for instance messages.
   ObjCMessageExpr(Expr *receiver, Selector selInfo,
                   QualType retType, ObjcMethodDecl *methDecl,
                   SourceLocation LBrac, SourceLocation RBrac,
-                  Expr **ArgExprs);
+                  Expr **ArgExprs, unsigned NumArgs);
   ~ObjCMessageExpr() {
     delete [] SubExprs;
   }
@@ -1332,20 +1334,20 @@
   IdentifierInfo *getClassName() { return ClassName; }
   
   /// getNumArgs - Return the number of actual arguments to this call.
-  unsigned getNumArgs() const { return SelName.getNumArgs(); }
+  unsigned getNumArgs() const { return NumArgs; }
 
 /// getArg - Return the specified argument.
   Expr *getArg(unsigned Arg) {
-    assert(Arg < SelName.getNumArgs() && "Arg access out of range!");
+    assert(Arg < NumArgs && "Arg access out of range!");
     return SubExprs[Arg+ARGS_START];
   }
   const Expr *getArg(unsigned Arg) const {
-    assert(Arg < SelName.getNumArgs() && "Arg access out of range!");
+    assert(Arg < NumArgs && "Arg access out of range!");
     return SubExprs[Arg+ARGS_START];
   }
   /// setArg - Set the specified argument.
   void setArg(unsigned Arg, Expr *ArgExpr) {
-    assert(Arg < SelName.getNumArgs() && "Arg access out of range!");
+    assert(Arg < NumArgs && "Arg access out of range!");
     SubExprs[Arg+ARGS_START] = ArgExpr;
   }
   SourceRange getSourceRange() const { return SourceRange(LBracloc, RBracloc); }

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=44172&r1=44171&r2=44172&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Nov 15 07:05:42 2007
@@ -590,22 +590,23 @@
                                      
   // ActOnClassMessage - used for both unary and keyword messages.
   // ArgExprs is optional - if it is present, the number of expressions
-  // is obtained from Sel.getNumArgs().
+  // is obtained from NumArgs.
   virtual ExprResult ActOnClassMessage(
     Scope *S,
     IdentifierInfo *receivingClassName, 
     Selector Sel,
     SourceLocation lbrac, 
     SourceLocation rbrac, 
-    ExprTy **ArgExprs) {
+    ExprTy **ArgExprs, unsigned NumArgs) {
     return 0;
   }
   // ActOnInstanceMessage - used for both unary and keyword messages.
   // ArgExprs is optional - if it is present, the number of expressions
-  // is obtained from Sel.getNumArgs().
+  // is obtained from NumArgs.
   virtual ExprResult ActOnInstanceMessage(
     ExprTy *receiver, Selector Sel,
-    SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs) {
+    SourceLocation lbrac, SourceLocation rbrac, 
+    ExprTy **ArgExprs, unsigned NumArgs) {
     return 0;
   }
   virtual DeclTy *ActOnForwardClassDeclaration(





More information about the cfe-commits mailing list