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

Douglas Gregor dgregor at apple.com
Tue Jul 26 08:25:11 PDT 2011


On Jul 25, 2011, at 5:21 PM, Connor Wakamo wrote:

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

Just one minor issue I corrected…

+            StringRef selectorString = Context.getSelIdents()[i]->getName();
+            AllocatedResults.Selector += selectorString.data();

data() here returns a pointer to character data that may not be NULL terminated. I've changed it to use str().

Committed as r136084 with the above fix. Thanks!

	- Doug

> Thanks,
> Connor Wakamo
> cwakamo at apple.com
> 
> <clang_codeCompleteGetObjCSelector_v2.patch>
> 
> 
> 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/20110726/f6270ec6/attachment.html>


More information about the cfe-commits mailing list