With libclang, how to get cursor for declaration type of a cursor at function call?

StackOverflow https://stackoverflow.com/questions/13789814

  •  06-12-2021
  •  | 
  •  

문제

I have a cursor that's pointing to a function call for which the prototype is declared inside an included header file. I want to get the location for such declaration, but as can be seen in the gdb output bellow, after getting the type for the function call, getting the cursor for the declaration type is failing, how to get it right?

(gdb) n
66      CXType mickey_type = clang_getCursorType(mickey_cursor);
(gdb) n
67      CXCursor mickey_decl_cursor = clang_getTypeDeclaration(mickey_type);
(gdb) n
68      CXSourceLocation mickey_decl_location = clang_getCursorLocation(mickey_decl_cursor);
(gdb) p mickey_type 
$1 = {
  kind = CXType_FunctionProto, 
  data = {0x102826cb0, 0x100a03d90}
}
(gdb) print mickey_decl_cursor 
$2 = {
  kind = CXCursor_NoDeclFound, 
  xdata = 0, 
  data = {0x0, 0x0, 0x0}
}
(gdb) q

Here's all the relevant source code:

도움이 되었습니까?

해결책

bah, my bad, I should have used clang_getCursorReferenced instead... there's no location for the declaration of the function's type! I must look for the function declaration.

Fixed Code

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top