diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-04-08 00:30:06 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-04-08 00:30:06 +0000 |
commit | 4f4fd92c6c64ecbc65507f63ddd09211f732622c (patch) | |
tree | 74eba6eba552799ea70ca2fa22d8cdd822386846 /lib/Sema | |
parent | d6f1906ffaf38285328facd1b6f043eeee991247 (diff) |
Patch to implement gcc's cstyle arguments in objc
methods. wip.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100734 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/Sema.h | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 23 | ||||
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 10 |
3 files changed, 31 insertions, 4 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index a6bcc4375e..45574b9d69 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -3822,7 +3822,7 @@ public: // optional arguments. The number of types/arguments is obtained // from the Sel.getNumArgs(). ObjCArgInfo *ArgInfo, - llvm::SmallVectorImpl<Declarator> &Cdecls, + DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind, bool isVariadic = false); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 0c47e63d99..b422c83162 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1495,7 +1495,7 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( // optional arguments. The number of types/arguments is obtained // from the Sel.getNumArgs(). ObjCArgInfo *ArgInfo, - llvm::SmallVectorImpl<Declarator> &Cdecls, + DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind, bool isVariadic) { Decl *ClassDecl = classDecl.getAs<Decl>(); @@ -1568,7 +1568,26 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration( Params.push_back(Param); } - ObjCMethod->setMethodParams(Context, Params.data(), Sel.getNumArgs()); + for (unsigned i = 0, e = CNumArgs; i != e; ++i) { + ParmVarDecl *Param = CParamInfo[i].Param.getAs<ParmVarDecl>(); + QualType ArgType = Param->getType(); + if (ArgType.isNull()) + ArgType = Context.getObjCIdType(); + else + // Perform the default array/function conversions (C99 6.7.5.3p[7,8]). + ArgType = adjustParameterType(ArgType); + if (ArgType->isObjCInterfaceType()) { + Diag(Param->getLocation(), + diag::err_object_cannot_be_passed_returned_by_value) + << 1 << ArgType; + Param->setInvalidDecl(); + } + Param->setDeclContext(ObjCMethod); + IdResolver.RemoveDecl(Param); + Params.push_back(Param); + } + + ObjCMethod->setMethodParams(Context, Params.data(), Params.size()); ObjCMethod->setObjCDeclQualifier( CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier())); const ObjCMethodDecl *PrevMethod = 0; diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index d5a22ca15f..99db910a90 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -182,7 +182,15 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, ReturnType = Method->getResultType(); unsigned NumNamedArgs = Sel.getNumArgs(); - assert(NumArgs >= NumNamedArgs && "Too few arguments for selector!"); + // Method might have more arguments than selector indicates. This is due + // to addition of c-style arguments in method. + if (Method->param_size() > Sel.getNumArgs()) + NumNamedArgs = Method->param_size(); + // FIXME. This need be cleaned up. + if (NumArgs < NumNamedArgs) { + Diag(lbrac, diag::err_typecheck_call_too_few_args) << 2; + return false; + } bool IsError = false; for (unsigned i = 0; i < NumNamedArgs; i++) { |