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