[cfe-commits] [PATCH] New libclang API function, clang_codeCompleteGetObjCSelector

Connor Wakamo cwakamo at apple.com
Mon Jul 25 17:21:20 PDT 2011


Let me try this again… I've now attached the updated version of the patch with the changes you suggested incorporated.

Thanks,
Connor Wakamo
cwakamo at apple.com



On Jul 25, 2011, at 4:13 PM, Connor Wakamo wrote:

> I've incorporated the changes that you suggested.  Please let me know if there is anything else I need to change.
> 
> Thanks,
> Connor Wakamo
> cwakamo at apple.com
> 
> <clang_codeCompleteGetObjCSelector.patch>
> 
> 
> On Jul 25, 2011, at 11:10 AM, Douglas Gregor wrote:
> 
>> 
>> On Jul 22, 2011, at 5:30 PM, Connor Wakamo wrote:
>> 
>>> I am submitting for review a patch with a new API function for libclang:
>>> 
>>> CXString clang_codeCompleteGetObjCSelector(CXCodeCompleteResults *)
>>> 
>>> This function returns a string containing the selector parts that have been typed thus far when code completion is requested for an Objective-C message.  For instance, if you're asking for completions after "[Foo initWithBar:bar object:obj", it'll return "initWithBar:object:".
>>> 
>>> I've also added some additional output to c-index-test and added a couple of checks in test/Index/complete-objc-message.m for both class and instance messages.
>>> 
>>> Please let me know what else I need to do with this patch.
>> 
>> Cool. A couple comments:
>> 
>> Index: tools/libclang/CIndexCodeCompletion.cpp
>> ===================================================================
>> --- tools/libclang/CIndexCodeCompletion.cpp	(revision 135677)
>> +++ tools/libclang/CIndexCodeCompletion.cpp	(working copy)
>> @@ -247,10 +247,17 @@
>>   /// current context.
>>   unsigned long long Contexts;
>> 
>> +  /// \brief The kind of the container for the current context for completions.
>>   enum CXCursorKind ContainerKind;
>> +  /// \brief The USR of the container for the current context for completions.
>>   CXString ContainerUSR;
>> +  /// \brief a boolean value indicating whether there is complete information
>> +  /// about the container
>> +  unsigned ContainerIsIncomplete;
>> 
>> -  unsigned ContainerIsIncomplete;
>> +  /// \brief A string containing the Objective-C selector entered thus far for a
>> +  /// message send.
>> +  char *Selector;
>> };
>> 
>> Please use a std::string for Selector, so we don't have to manually manage the memory.
>> 
>> +      if (Context.getNumSelIdents() > 0) {
>> +        printf("We have selector parts to save!\n");
>> 
>> Please drop the printf.
>> 
>> +        size_t selectorLength = 0;
>> +        for (unsigned i = 0; i < Context.getNumSelIdents(); i++) {
>> +          StringRef selectorString = Context.getSelIdents()[i]->getName();
>> +          selectorLength += selectorString.size();
>> +        }
>> 
>> the IdentifierInfo* within a selector can actually be NULL, so make sure you check for it first. That's how we represent such ill-advised selectors as
>> 
>> 	foo::bar:
>> 
>> +        char *selectorString = (char *)malloc(selectorLength +
>> +                                              Context.getNumSelIdents() + 1);
>> +        if (selectorString) {
>> +          for (unsigned i = 0; i < Context.getNumSelIdents(); i++) {
>> +            strcat(selectorString, Context.getSelIdents()[i]->getName().data());
>> +            strcat(selectorString, ":");
>> +          }
>> +        }
>> +        AllocatedResults.Selector = selectorString;
>> 
>> This will be way easier with std::string :)
>> 
>> Index: tools/libclang/libclang.darwin.exports
>> ===================================================================
>> --- tools/libclang/libclang.darwin.exports	(revision 135677)
>> +++ tools/libclang/libclang.darwin.exports	(working copy)
>> @@ -9,6 +9,9 @@
>> _clang_codeCompleteGetContainerKind
>> _clang_codeCompleteGetContainerUSR
>> _clang_codeCompleteGetContexts
>> +_clang_codeCompleteGetContainerKind
>> +_clang_codeCompleteGetContainerUSR
>> +_clang_codeCompleteGetObjCSelector
>> _clang_constructUSR_ObjCCategory
>> _clang_constructUSR_ObjCClass
>> _clang_constructUSR_ObjCIvar
>> Index: tools/libclang/libclang.exports
>> ===================================================================
>> --- tools/libclang/libclang.exports	(revision 135677)
>> +++ tools/libclang/libclang.exports	(working copy)
>> @@ -9,6 +9,9 @@
>> clang_codeCompleteGetContainerKind
>> clang_codeCompleteGetContainerUSR
>> clang_codeCompleteGetContexts
>> +clang_codeCompleteGetContainerKind
>> +clang_codeCompleteGetContainerUSR
>> +clang_codeCompleteGetObjCSelector
>> clang_constructUSR_ObjCCategory
>> clang_constructUSR_ObjCClass
>> clang_constructUSR_ObjCIvar
>> 
>> Some extraneous exports here from a prior patch.
>> 
>> 	- Doug
>> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110725/d21e16fd/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang_codeCompleteGetObjCSelector_v2.patch
Type: application/octet-stream
Size: 10230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110725/d21e16fd/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110725/d21e16fd/attachment-0001.html>


More information about the cfe-commits mailing list