[cfe-commits] Extensions to ObjCSuperCallChecker

Jordan Rose jordan_rose at apple.com
Fri Nov 2 10:14:01 PDT 2012


I think my long-term suggestion would be to have one "initializeSelectors" method that runs in advance and fills up a map of class names -> selector sets. Then you iterate through the superclasses until you find one that's in the map, and then check the selectors as before. (If you wanted to be a little more lazy about it, you could put function pointers in the map, where each function returned the set of selectors appropriate for that class.)

As for multi-keyword selectors, what you have to do is make an array of IdentifierInfo objects appropriate for that selector. You could either do this explicitly (with an array of strings and then an array of IdentifierInfo), or cheat using variadic functions. Take a look at isMultiArgSelector in NoReturnFunctionChecker.cpp and generateSelector in RetainCountChecker.cpp to see what I mean.

For bonus points, change SelectorTable::getSelector to take an ArrayRef<IdentifierInfo *> instead of a size and pointer-to-first-element. (In a separate patch, please, since this will cause changes throughout the entire compiler! Benign changes, though.)

Would love to see more work from you to improve this checker (and others). Thanks for thinking about this.
Jordan


On Nov 2, 2012, at 5:05 , Julian Mayer <julian at corecode.at> wrote:

> On 30.10.2012, at 02:22, wrote Jordan Rose:
>> 
>> Committed, with a few slight tweaks, as r166993. Thanks!
>> 
>> http://llvm-reviews.chandlerc.com/D78
> 
> 
> 
> hi jordan,
> 
> thanks, thats great ;)
> 
> while the topic is still hot, do you have any ideas for the future of the checker?
> 
> the first things i'd like to address are :
> 1.) checking other classes like UIResponder and NSResponder. should we extend our simple C const array based approach that we are using now for the selector names to multiple classes like this?
> 
> 		
> 		const char *UIVC_SelectorNames[] = {"addChildViewController", "viewDidAppear", "viewDidDisappear"};
> 		const unsigned UIVC_SelectorArgumentCounts[] = {1, 1, 1};
> 		const size_t UIVC_SelectorCount = llvm::array_lengthof(UIVC_SelectorNames);
> 		
> 		const char *UIR_SelectorNames[] = {"resignFirstResponder"};
> 		const unsigned UIR_SelectorArgumentCounts[] = {0};
> 		const size_t UIR_SelectorCount = llvm::array_lengthof(UIR_SelectorNames);
> 		
> 		const void *Classes[] = {"UIViewController", UIVC_SelectorNames, UIVC_SelectorArgumentCounts, &UIVC_SelectorCount,
> 								 "UIResponder", UIR_SelectorNames, UIR_SelectorArgumentCounts, &UIR_SelectorCount};
> 		
> 
> 		for (int i = 0; i < llvm::array_lengthof(Classes); i += 4)
> 		{
> 			const char *className = (const char *)Classes[i+0];
> 			const char **selectorNames = (const char  **)Classes[i+1];
> 			const unsigned *selectorArgumentCounts = (const unsigned *)Classes[i+2];
> 			const size_t *selectorCount = (const size_t *)Classes[i+3];
> 
> 			for (size_t v = 0; v < *selectorCount; v++)
> 			{
> 				 /* do checks as previously */
> 				
> 			}
> 		}
> 
> 
> 2.) checking multi-argument methods. as i understand it we currently can't check selectors with more than one argument because the call to Ctx.Selectors.getSelector(ArgumentCount, &II) doesn't work in these cases. i have searched the llvm internals documentation but couldn't find a simple solution to this problem...any ideas?
> 
> bye, julian
> 
> 
> --
> A. Julian Mayer   <julian at corecode.at>
> CoreCode | Founder | Lead Developer
> http://www.corecode.at
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121102/1fbd7c55/attachment.html>


More information about the cfe-commits mailing list