Skip to content

Commit

Permalink
fix-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Aug 18, 2024
1 parent 0227723 commit 0fab870
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions deps/generate_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ resolve_headers(headers::Vector{String}, include_paths::Vector{String})::Vector{
resolve_header.(headers, Ref(include_paths))

function get_full_name(cursor, funcargs::Bool=true, buf="")
parent = Clang.getCursorLexicalParent(cursor)
parent = Clang.getCursorSemanticParent(cursor)
parent_kind = spelling(kind(parent))
cursor_name = name(cursor)
if !funcargs
Expand Down Expand Up @@ -111,6 +111,36 @@ function get_julia_name(cursor::CLCursor)
replace(vname, "::" => "")
end

nns(x::Clang.CLInvalidFile) = ""
nns(x::Clang.CLTranslationUnit) = ""
function nns(x::CLCursor)
pn = nns(Clang.getCursorSemanticParent(x))
if isempty(pn)
return spelling(x)
else
return pn * "::" * spelling(x)
end
end
get_qualified_name(x::CLCursor) = isempty(spelling(x)) ? "" : nns(x)

get_qualified_basename(x::CLCursor) = ""
function get_qualified_basename(x::CLTypeRef)
n = spelling(x)
startswith(n, "class ") && return split(n, "class ")[2]
startswith(n, "struct ") && return split(n, "struct ")[2]
startswith(n, "Union ") && return split(n, "Union ")[2]
return ""
end
get_qualified_basename(x::CLCXXBaseSpecifier) = get_qualified_basename(children(x)[1])
function get_qualified_basename(x::Union{CLClassDecl,CLStructDecl,CLUnionDecl})
bn = get_qualified_basename(children(x)[1])
if isempty(bn)
return spelling(x)
else
return bn * "::" * spelling(x)
end
end

function object_decl_handler(ctx::BindgenContext, classdecl::CLCursor)::Tuple{Union{Nothing, String}, Union{Nothing, String}}
full_name = get_full_name(classdecl)
length(children(classdecl)) == 0 && return nothing, "skip_empty_classdecl"
Expand All @@ -125,7 +155,7 @@ function object_decl_handler(ctx::BindgenContext, classdecl::CLCursor)::Tuple{Un
# handle simple inheritance
subnodes = children(classdecl)
if length(subnodes) > 1 && kind(subnodes[1]) == Clang.CXCursor_CXXBaseSpecifier
base_class = get_full_name(subnodes[1])
base_class = get_qualified_basename(subnodes[1])
if !isempty(base_class)

ctx.outputSupertypes *= "template<> struct SuperType<$full_name> { typedef $base_class type; };\n"
Expand Down

0 comments on commit 0fab870

Please sign in to comment.