r189514 - For methods where clang automatically infers instancetype from the selector
jahanian
fjahanian at apple.com
Wed Aug 28 14:28:15 PDT 2013
On Aug 28, 2013, at 2:09 PM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Aug 28, 2013, at 1:49 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>
>> Author: fjahanian
>> Date: Wed Aug 28 15:49:58 2013
>> New Revision: 189514
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=189514&view=rev
>> Log:
>> For methods where clang automatically infers instancetype from the selector
>> (e.g., all -init* methods), no need to suggest "instancetype" because it
>> is redundant.
>>
>> Modified:
>> cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
>> cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result
>> cfe/trunk/test/ARCMT/objcmt-instancetype-2.m.result
>> cfe/trunk/test/ARCMT/objcmt-instancetype.m.result
>>
>> Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=189514&r1=189513&r2=189514&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
>> +++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Wed Aug 28 15:49:58 2013
>> @@ -668,15 +668,13 @@ void ObjCMigrateASTConsumer::migrateMeth
>> case OIT_None:
>> migrateFactoryMethod(Ctx, CDecl, OM);
>> return;
>> + // For methods where Clang automatically infers instancetype from the selector
>> + // (e.g., all -init* methods), we should not suggest "instancetype" because it
>> + // is redundant,
>> case OIT_Array:
>> - ClassName = "NSArray";
>> - break;
>> case OIT_Dictionary:
>> - ClassName = "NSDictionary";
>> - break;
>> case OIT_MemManage:
>> - ClassName = "NSObject";
>> - break;
>> + return;
>> case OIT_Singleton:
>> migrateFactoryMethod(Ctx, CDecl, OM, OIT_Singleton);
>> return;
>
> This is just checking a few special cases. What we want is to avoid adding ‘instancetype’ when the method already has a related result type, which you can check directly with ObjCMethodDecl::hasRelatedResultType().
>
> For example, migrateFactoryMethod() should replace the “== Ctx.getObjCInstanceType()” check with a call to hasRelatedResultType().
>
> if (OM->isInstanceMethod() ||
> OM->getResultType() == Ctx.getObjCInstanceType() ||
> !OM->getResultType()->isObjCIdType())
> return;
>
> And migrateMethodInstanceType() should bail out early if it sees that the method already has a related result type.
>
Early bail out is good. Thanks for pointing me to this API. In r189520.
- Fariborz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130828/e6c54189/attachment.html>
More information about the cfe-commits
mailing list