On Oct 11, 2011, at 7:46 AM, Erik Verbruggen wrote:

> Hi,
> 
> The attached patch adds clang_getCompletionAnnotation to libclang, which can 
> be used to retrieve annotation attributes for CXCompletionString-s. To do 
> this, I extended CodeCompletionString to store the annotation strings inside 
> the object, right after the Chunks. This patch is on top of r141497.

I think it's a little strange that we're pulling data traditionally in cursors 
into completions, piece-meal, but I don't see a better way right now. A few 
comments:

--- a/include/clang/Sema/CodeCompleteConsumer.h
+++ b/include/clang/Sema/CodeCompleteConsumer.h
@@ -435,12 +435,15 @@ private:
   
   /// \brief The availability of this code-completion result.
   unsigned Availability : 2;
+
+  unsigned NumAnnotations;

Shouldn't we use less than 32 bits for the number of annotations?

+CXString clang_getCompletionAnnotation(CXCompletionString completion_string,
+                                       unsigned annotation_number) {
+  CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
+  return CCStr? createCXString(CCStr->getAnnotation(annotation_number))
+              : createCXString((const char *) 0);
+}
+

Returning an empty CXString to mean "no more annotations" makes for a very 
subtle distinction with, e.g.,

        int blah __attribute__((annotate("one"), annotate(""), 
annotate("three")));

I'd feel slightly better if there were a 
clang_getCompletionNumAnnotations(CXCompletionString) function for the client 
to use.

        - Doug

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to