Bugs filed, links for reference:<div><br></div><div><a href="http://llvm.org/bugs/show_bug.cgi?id=12970">http://llvm.org/bugs/show_bug.cgi?id=12970</a></div><div><div><a href="http://llvm.org/bugs/show_bug.cgi?id=12971">http://llvm.org/bugs/show_bug.cgi?id=12971</a></div>
<div><div><a href="http://llvm.org/bugs/show_bug.cgi?id=12972">http://llvm.org/bugs/show_bug.cgi?id=12972</a></div></div><div><div><a href="http://llvm.org/bugs/show_bug.cgi?id=12975">http://llvm.org/bugs/show_bug.cgi?id=12975</a></div>
</div><div><div><a href="http://llvm.org/bugs/show_bug.cgi?id=12976">http://llvm.org/bugs/show_bug.cgi?id=12976</a></div></div><div><div><a href="http://llvm.org/bugs/show_bug.cgi?id=12977">http://llvm.org/bugs/show_bug.cgi?id=12977</a></div>
</div><div><br></div><div>Regards</div><div>Michal Staromiejski</div><div><br></div><div class="gmail_quote">On 27 May 2012 15:15, Michał Staromiejski <span dir="ltr"><<a href="mailto:michal.staromiejski@gmail.com" target="_blank">michal.staromiejski@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thanks for your quick reply!<br><br>As for (3), I've realized that with CXTranslationUnit_DetailedPreprocessingRecord option macros are annotated as expected (this option is used by c-index-test, which explains different behavior).<br>


<br>For other things I'll file bugs as soon as possible.<div><br></div><div>Michal Staromiejski<div><div class="h5"><br><br><div class="gmail_quote">On 26 May 2012 00:37, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:kyrtzidis@apple.com" target="_blank">kyrtzidis@apple.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On May 25, 2012, at 6:03 AM, Michał Staromiejski wrote:<br>
<br>
> Hi everyone!<br>
><br>
> First of all, thank you for libclang ;)<br>
<br>
</div>You're welcome :)<br>
<div><br>
><br>
> I'm working on semantic highlight plugin for Code::Blocks IDE based on libclang.<br>
> So far, everything works quite well, but I've noticed some issues with<br>
> the functions clang_annotateTokens and (this is probably more specific) clang_getCursor.<br>
><br>
> I'm using svn version (rev. 157460) but the same is with 3.1.<br>
><br>
> From the documentation:<br>
> "clang_getCursor() maps an arbitrary source location within a translation unit down to the most specific cursor that describes the entity at that location."<br>
<br>
</div>As a sidenote, in case it isn't obvious, if the location cannot be resolved it resolves to the enclosing entity, e.g. if you point at a comment inside a namespace it will give you the namespace.<br>
<div><div><br>
><br>
> And the weird things begin. Consider the following (valid) C++ code:<br>
><br>
> ---------------------------------8<----------------------------------------<br>
> #ifdef _MY_MACRO_<br>
> #define NUM 2<br>
> #else<br>
> #define NUM 5<br>
> #endif<br>
><br>
> template <class T><br>
> class A<br>
> {<br>
> #ifdef _MY_MACRO_ // (1)<br>
>     int a; // (2)<br>
> #else<br>
>     bool a;<br>
> #endif<br>
><br>
> public:<br>
>     static bool array[NUM]; // (3)<br>
>     operator T();<br>
> };<br>
><br>
> template <class T> // (4)<br>
> bool A<T>::array[NUM]; // (5)<br>
><br>
> bool g(A<bool> a)<br>
> {<br>
>     return a; // (6)<br>
> }<br>
><br>
> template <class T> // (4)<br>
> T f(A<T> a)<br>
> {<br>
>     return a;<br>
> }<br>
> ---------------------------------8<----------------------------------------<br>
><br>
> Using clang_annotateTokens (clang_getCursor) or c-index-test -test-annotate-tokens (-cursor-at, resp.) everything but the following is OK:<br>
><br>
> (1) Inside any block (class, struct, namespace, ... declaration, function body, etc.) preprocessor directives<br>
> are not annotated as such.<br>
<br>
</div></div>Please file a bug for this.<br>
<div><br>
> (2) If the macro _MY_MACRO_ is not defined, all tokens in "int a;" are annotated in same way as the block they belong to;<br>
> shouldn't they be annotated as, for example, CXXCursor_InactiveCode (new CXCursorKind value)?<br>
<br>
</div>This is a known limitation, we don't identify inactive source due to preprocessor directives so it resolves to the enclosing scope; it'd be good to do as you said, please file a bug to track it.<br>
<div><br>
> (3) It's weird but here clang_annotateTokens behaves different from c-index-test: the former annotates the 'NUM' token<br>
> as 'VarDecl=array' (wrong) and the latter as 'macro expansion=NUM', as expected...<br>
<br>
</div>File a bug with a test case that uses clang_annotateTokens and reproduces this.<br>
<div><br>
> (4) The whole line is annotated here with CXCursor_FirstInvalid (70) and this concerns all such 'template' lines.<br>
<br>
</div>We should probably identify this as part of the 'array' declaration, and have 'T' be a TemplateTypeParameter, file a bug.<br>
<div><br>
> (5) The whole line is marked as 'VarDecl=array' (IHMO 'A' should be 'TemplateRef=A' and 'T' should be 'TypeRef=T', 'NUM' behaves similarly as in (3)).<br>
<br>
</div>I believe you are right, file bug.<br>
<div><br>
> (6) 'a' is annotated as 'CallExpr=operator _Bool', shouldn't be 'DeclRefExpr=a'? It is weird, but in the function 'f' there is no such problem.<br>
<br>
</div>You are right, and, you guessed it, please file a bug.<br>
<div><br>
><br>
> Is it a bug or do I miss something?<br>
<br>
</div>It's better that each separate issue is tracked in different bugs, the work involved varies greatly.<br>
<br>
Thanks for the feedback!<br>
<br>
><br>
> Cheers,<br>
> Michal Staromiejski<br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br>
</blockquote></div><br>
</div></div></div>
</blockquote></div><br></div>