Add getCursorNumArguments, getCursorArgument, getCursorResultTypeSpelling

Provide dedicated APIs for inspecting function arguments and return types.
These are more reliable than getChildren + type string splitting for headers
that use macro-based calling conventions (e.g. SDL_DECLSPEC/SDLCALL), where
parameter cursors may not appear as AST children in the expected way.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Greg ShuflinandClaude Sonnet 4.6 committed 2026-05-15 04:24:00 -07:00
1 parent 650b667a79
commit 5bfd26b703
2 files changed
+46

No files matched your search

+13
View File
@@ -96,6 +96,19 @@ opaque getChildren (cursor : @& Cursor) : IO (Array Cursor)
@[extern "lean_clang_cursorIsNull"]
opaque cursorIsNull (cursor : @& Cursor) : IO Bool
/-- Get the number of arguments of a function/method cursor (-1 if not applicable). -/
@[extern "lean_clang_getCursorNumArguments"]
opaque getCursorNumArguments (cursor : @& Cursor) : IO UInt32
/-- Get the Nth argument cursor of a function/method cursor. -/
@[extern "lean_clang_getCursorArgument"]
opaque getCursorArgument (cursor : @& Cursor) (i : UInt32) : IO Cursor
/-- Get the return type spelling of a function cursor (more reliable than
splitting the full function type string). -/
@[extern "lean_clang_getCursorResultTypeSpelling"]
opaque getCursorResultTypeSpelling (cursor : @& Cursor) : IO String
/-- Get the signed integer value of an `enumConstantDecl` cursor. -/
@[extern "lean_clang_getCursorEnumConstantValue"]
opaque getCursorEnumConstantValue (cursor : @& Cursor) : IO Int64
+33
View File
@@ -299,6 +299,39 @@ lean_obj_res lean_clang_cursorIsNull(lean_obj_arg cursor, lean_obj_arg world) {
return lean_io_result_mk_ok(lean_box(clang_Cursor_isNull(c) != 0));
}
/*
Function argument access (more reliable than getChildren for macro-heavy SDL-style headers)
*/
lean_obj_res lean_clang_getCursorNumArguments(lean_obj_arg cursor,
lean_obj_arg world) {
CXCursor c = lean_to_cursor(cursor);
int n = clang_Cursor_getNumArguments(c);
return lean_io_result_mk_ok(lean_box((unsigned)(n < 0 ? 0 : n)));
}
lean_obj_res lean_clang_getCursorArgument(lean_obj_arg cursor,
uint32_t i,
lean_obj_arg world) {
CXCursor c = lean_to_cursor(cursor);
lean_object *tu_ref = lean_cursor_tu_ref(cursor);
CXCursor arg = clang_Cursor_getArgument(c, (unsigned)i);
return lean_io_result_mk_ok(cursor_to_lean(arg, tu_ref));
}
/*
Return type of a function cursor
*/
lean_obj_res lean_clang_getCursorResultTypeSpelling(lean_obj_arg cursor,
lean_obj_arg world) {
CXCursor c = lean_to_cursor(cursor);
CXType funcType = clang_getCursorType(c);
CXType resultType = clang_getResultType(funcType);
CXString spelling = clang_getTypeSpelling(resultType);
return lean_io_result_mk_ok(cxstring_to_lean(spelling));
}
/*
Enum constant value
*/