Libclang receives member announcement

class aclass{
public:
    int num;
};

int main()
{
    aclass *ok;
    ok->num = 4;
    return 0;
}

      

now when i do clang_getCursorDefinition (cur_cursor); to the cursor to the right at the beginning of o in ok-> num = 4; it gives a cursor for int num; inside aclass. I want it to give me a cursor for aclass * ok; declaration inside main. The clang_getCursorSemanticParent (cur_cursor) call seems to be wrong, as if I were putting the declaration inside or outside the main () function, it still returns main () as the semantic parent.

Is there a way to efficiently do this without iterating over every possible cursor?

EDIT: Clang counts tabs as 1 character, which is correct. The editor I tested with automatically counted tabs of size 4, so what was expected in column 2 my editor was sending as column 5. Now getCursorDefinition works as expected and leads me to define the scope.

+3


source to share


1 answer


when i do clang_getCursorDefinition (cur_cursor); on the course at the beginning o

onok->num = 4;

You might be surprised at the behavior of your code due to the (common) misconception that there is only one cursor at each source location.



There are actually many cursors at this position, one pointing to the entire expression, another pointing to a member reference ok->num

, and also pointing to a pointer ok

. (see, for example, this question for more detailed explanations about this: C ++ libclang: retrieving cursor from CXSourceLocation returning invalid pointer? )

You should probably try to find the correct cursor among all in the same place. The way to do this depends on how you originally got your cursor.

+2


source







All Articles