[cfe-commits] r100734 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExprObjC.cpp test/SemaObjC/objc-cstyle-args-in-methods.m
Fariborz Jahanian
fjahanian at apple.com
Wed Apr 7 17:30:06 PDT 2010
Author: fjahanian
Date: Wed Apr 7 19:30:06 2010
New Revision: 100734
URL: http://llvm.org/viewvc/llvm-project?rev=100734&view=rev
Log:
Patch to implement gcc's cstyle arguments in objc
methods. wip.
Added:
cfe/trunk/test/SemaObjC/objc-cstyle-args-in-methods.m
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=100734&r1=100733&r2=100734&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Apr 7 19:30:06 2010
@@ -2306,7 +2306,7 @@
TypeTy *ReturnType, // the method return type.
Selector Sel, // a unique name for the method.
ObjCArgInfo *ArgInfo, // ArgInfo: Has 'Sel.getNumArgs()' entries.
- llvm::SmallVectorImpl<Declarator> &Cdecls, // c-style args
+ DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
AttributeList *MethodAttrList, // optional
// tok::objc_not_keyword, tok::objc_optional, tok::objc_required
tok::ObjCKeywordKind impKind,
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=100734&r1=100733&r2=100734&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Apr 7 19:30:06 2010
@@ -823,7 +823,7 @@
return DeclPtrTy();
}
- llvm::SmallVector<Declarator, 8> CargNames;
+ llvm::SmallVector<DeclaratorChunk::ParamInfo, 8> CParamInfo;
if (Tok.isNot(tok::colon)) {
// If attributes exist after the method, parse them.
if (getLang().ObjC2 && Tok.is(tok::kw___attribute))
@@ -834,7 +834,9 @@
DeclPtrTy Result
= Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
- 0, CargNames, MethodAttrs.get(),
+ 0,
+ CParamInfo.data(), CParamInfo.size(),
+ MethodAttrs.get(),
MethodImplKind);
PD.complete(Result);
return Result;
@@ -897,7 +899,13 @@
// Parse the declarator.
Declarator ParmDecl(DS, Declarator::PrototypeContext);
ParseDeclarator(ParmDecl);
- CargNames.push_back(ParmDecl);
+ IdentifierInfo *ParmII = ParmDecl.getIdentifier();
+ DeclPtrTy Param = Actions.ActOnParamDeclarator(CurScope, ParmDecl);
+ CParamInfo.push_back(DeclaratorChunk::ParamInfo(ParmII,
+ ParmDecl.getIdentifierLoc(),
+ Param,
+ 0));
+
}
// FIXME: Add support for optional parmameter list...
@@ -913,7 +921,8 @@
DeclPtrTy Result
= Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
- &ArgInfos[0], CargNames,
+ &ArgInfos[0],
+ CParamInfo.data(), CParamInfo.size(),
MethodAttrs.get(),
MethodImplKind, isVariadic);
PD.complete(Result);
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=100734&r1=100733&r2=100734&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Apr 7 19:30:06 2010
@@ -3822,7 +3822,7 @@
// 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);
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=100734&r1=100733&r2=100734&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Apr 7 19:30:06 2010
@@ -1495,7 +1495,7 @@
// 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 @@
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;
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=100734&r1=100733&r2=100734&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Apr 7 19:30:06 2010
@@ -182,7 +182,15 @@
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++) {
Added: cfe/trunk/test/SemaObjC/objc-cstyle-args-in-methods.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-cstyle-args-in-methods.m?rev=100734&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-cstyle-args-in-methods.m (added)
+++ cfe/trunk/test/SemaObjC/objc-cstyle-args-in-methods.m Wed Apr 7 19:30:06 2010
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+ at interface Foo
+- (id)test:(id)one, id two;
+- (id)bad:(id)one, id two, double three;
+ at end
+
+ at implementation Foo
+- (id)test:(id )one, id two {return two; }
+- (id)bad:(id)one, id two, double three { return two; }
+ at end
+
+
+int main() {
+ Foo *foo;
+ [foo test:@"One", @"Two"];
+ [foo bad:@"One", @"Two"]; // expected-error {{too few arguments to method call}}
+ [foo bad:@"One", @"Two", 3.14];
+ [foo bad:@"One", @"Two", 3.14, @"Two"]; // expected-error {{too many arguments to method call}}
+}
More information about the cfe-commits
mailing list