Hi everyone!<div><br></div><div>First of all, thank you for libclang ;)</div><div><br></div><div>I'm working on semantic highlight plugin for Code::Blocks IDE based on libclang.</div><div>So far, everything works quite well, but I've noticed some issues with</div>
<div>the functions clang_annotateTokens and (this is probably more specific) clang_getCursor.</div><div><br></div><div>I'm using svn version (rev. 157460) but the same is with 3.1.</div><div><br></div><div>From the documentation:</div>
"clang_getCursor() maps an arbitrary source location within a translation unit down to the most specific cursor that describes the entity at that location."<div><br></div><div>And the weird things begin. Consider the following (valid) C++ code:</div>
<div><br></div><div>---------------------------------8<----------------------------------------</div><div><div>#ifdef _MY_MACRO_</div><div>#define NUM 2</div><div>#else</div><div>#define NUM 5</div><div>#endif</div><div>
<br></div><div>template <class T></div><div>class A</div><div>{</div><div>#ifdef _MY_MACRO_ // (1)</div><div>    int a; // (2)</div><div>#else</div><div>    bool a;</div><div>#endif</div><div><br></div><div>public:</div>
<div>    static bool array[NUM]; // (3)</div><div>    operator T();</div><div>};</div><div><br></div><div>template <class T> // (4)</div><div>bool A<T>::array[NUM]; // (5)</div><div><br></div><div>bool g(A<bool> a)</div>
<div>{</div><div>    return a; // (6)</div><div>}</div><div><br></div><div>template <class T> // (4)</div><div>T f(A<T> a)</div><div>{</div><div>    return a;</div><div>}</div></div><div>---------------------------------8<----------------------------------------</div>
<div><br></div><div>Using clang_annotateTokens (clang_getCursor) or c-index-test -test-annotate-tokens (-cursor-at, resp.) everything but the following is OK:</div><div><br></div><div>(1) Inside any block (class, struct, namespace, ... declaration, function body, etc.) preprocessor directives</div>
<div>are not annotated as such.</div><div>(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;</div><div>shouldn't they be annotated as, for example, CXXCursor_InactiveCode (new CXCursorKind value)?</div>
<div>(3) It's weird but here clang_annotateTokens behaves different from c-index-test: the former annotates the 'NUM' token</div><div>as 'VarDecl=array' (wrong) and the latter as 'macro expansion=NUM', as expected...</div>
<div>(4) The whole line is annotated here with CXCursor_FirstInvalid (70) and this concerns all such 'template' lines.</div><div>(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)).</div>
<div>(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.</div><div><br></div><div>Is it a bug or do I miss something?</div>
<div><br></div><div>Cheers,</div><div>Michal Staromiejski</div>