]> granicus.if.org Git - clang/commitdiff
Implement support for variadic methods (work in progress).
authorSteve Naroff <snaroff@apple.com>
Thu, 15 Nov 2007 12:35:21 +0000 (12:35 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 15 Nov 2007 12:35:21 +0000 (12:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44171 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp
Parse/ParseObjc.cpp
Sema/Sema.h
Sema/SemaDecl.cpp
include/clang/AST/DeclObjC.h
include/clang/Parse/Action.h

index a768d17b3a582842953cbd2a450fb56068143ef1..b5dcdfc802ec20bb07b463cd823011b13980218d 100644 (file)
@@ -1274,11 +1274,11 @@ Stmt *RewriteTest::RewriteMessageExpr(ObjCMessageExpr *Exp) {
   // xx.m:13: note: if this code is reached, the program will abort
   cast = new CastExpr(Context->getPointerType(Context->VoidTy), DRE, 
                       SourceLocation());
-                                                   
+    
   // Now do the "normal" pointer to function cast.
   QualType castType = Context->getFunctionType(returnType, 
                                                &ArgTypes[0], ArgTypes.size(),
-                                               false/*FIXME:variadic*/);
+                                               Exp->getMethodDecl()->isVariadic());
   castType = Context->getPointerType(castType);
   cast = new CastExpr(castType, cast, SourceLocation());
 
index 345906e70f1a0df32d35bbb455839e6d44033af7..be33f86f0ccff4dac34b4e161f36ba6ae51b3955 100644 (file)
@@ -619,13 +619,17 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
     // We have a selector or a colon, continue parsing.
   }
   
+  bool isVariadic = false;
+  
   // Parse the (optional) parameter list.
   while (Tok.is(tok::comma)) {
     ConsumeToken();
     if (Tok.is(tok::ellipsis)) {
+      isVariadic = true;
       ConsumeToken();
       break;
     }
+    // FIXME: implement this...
     // Parse the c-style argument declaration-specifier.
     DeclSpec DS;
     ParseDeclarationSpecifiers(DS);
@@ -645,8 +649,8 @@ Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
   return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
                                         mType, IDecl, DSRet, ReturnType, Sel, 
                                         &ArgTypeQuals[0], &KeyTypes[0], 
-                                        &ArgNames[0],
-                                        MethodAttrs, MethodImplKind);
+                                        &ArgNames[0], MethodAttrs, 
+                                        MethodImplKind, isVariadic);
 }
 
 /// CmpProtocolVals - Comparison predicate for sorting protocols.
index 8b470fe5c6c78d7cbe7e3cde7d93127526d90a8e..a1026448867a99f723c5f58f9a5a86d738a3c1b3 100644 (file)
@@ -560,7 +560,8 @@ public:
     // optional arguments. The number of types/arguments is obtained
     // from the Sel.getNumArgs().
     ObjcDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
-    AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind);
+    AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
+    bool isVariadic = false);
 
   // ActOnClassMessage - used for both unary and keyword messages.
   // ArgExprs is optional - if it is present, the number of expressions
index dc1a9935191aed96883a9f79ade3cec9cff65827..2c016df78129f2fae2fc4a5f1f24a0ff5ba57932 100644 (file)
@@ -2119,7 +2119,8 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration(
     // optional arguments. The number of types/arguments is obtained
     // from the Sel.getNumArgs().
     ObjcDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
-    AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind) {
+    AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind,
+    bool isVariadic) {
   llvm::SmallVector<ParmVarDecl*, 16> Params;
   
   for (unsigned i = 0; i < Sel.getNumArgs(); i++) {
@@ -2148,7 +2149,7 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration(
                                       resultDeclType,
                                       CDecl,
                                       0, -1, AttrList, 
-                                      MethodType == tok::minus,
+                                      MethodType == tok::minus, isVariadic,
                                       MethodDeclKind == tok::objc_optional ? 
                                       ObjcMethodDecl::Optional : 
                                       ObjcMethodDecl::Required);
index a475984b12bac2715c4ad34048a4e3ea62692fee..fb0a8b4a36ae1524734ba8d0387217b26f7aa915 100644 (file)
@@ -626,6 +626,8 @@ private:
   /// declared in class Decl.
   /// instance (true) or class (false) method.
   bool IsInstance : 1;
+  bool IsVariadic : 1;
+  
   /// @required/@optional
   ImplementationControl DeclImplementation : 2;
   
@@ -657,11 +659,12 @@ public:
                  Decl *contextDecl,
                  ParmVarDecl **paramInfo = 0, int numParams=-1,
                  AttributeList *M = 0, bool isInstance = true,
+                 bool isVariadic = false,
                  ImplementationControl impControl = None,
                  Decl *PrevDecl = 0)
   : Decl(ObjcMethod, beginLoc),
-    IsInstance(isInstance), DeclImplementation(impControl),
-    objcDeclQualifier(OBJC_TQ_None),
+    IsInstance(isInstance), IsVariadic(isVariadic),
+    DeclImplementation(impControl), objcDeclQualifier(OBJC_TQ_None),
     MethodContext(static_cast<NamedDecl*>(contextDecl)),
     SelName(SelInfo), MethodDeclType(T), 
     ParamInfo(paramInfo), NumMethodParams(numParams),
@@ -704,6 +707,8 @@ public:
   
   AttributeList *getMethodAttrs() const {return MethodAttrs;}
   bool isInstance() const { return IsInstance; }
+  bool isVariadic() const { return IsVariadic; }
+  
   // Related to protocols declared in  @protocol
   void setDeclImplementation(ImplementationControl ic) { 
     DeclImplementation = ic; 
index bfbcfb93dc3f18fc1ad0359e54790feddbd1c005..e2aa1bad402c4bf74b2fd399472f7f07873a2c52 100644 (file)
@@ -565,7 +565,8 @@ public:
     IdentifierInfo **ArgNames, // non-zero when Sel.getNumArgs() > 0
     AttributeList *AttrList,   // optional
     // tok::objc_not_keyword, tok::objc_optional, tok::objc_required    
-    tok::ObjCKeywordKind impKind) {
+    tok::ObjCKeywordKind impKind,
+    bool isVariadic = false) {
     return 0;
   }
   // ActOnAtEnd - called to mark the @end. For declarations (interfaces,