Skip to content

Commit

Permalink
Adapt to Clang's ElaboratedType sugaring changes
Browse files Browse the repository at this point in the history
ref: https://reviews.llvm.org/D112374
Co-Authored-By: James Wrigley <JamesWrigley@users.noreply.github.com>
  • Loading branch information
Gnimuc and JamesWrigley committed Mar 6, 2024
1 parent 839d108 commit ba7d48d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Clang.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export is_typedef_anon, is_forward_declaration, is_inclusion_directive
export search, children

include("type.jl")
export has_elaborated_reference, get_elaborated_cursor
export has_elaborated_reference, has_elaborated_tag_reference, get_elaborated_cursor
export has_function_reference
export fields

Expand Down
6 changes: 1 addition & 5 deletions src/generator/jltypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ tojulia(x::CLFloat16) = JuliaCfloat16() # Float16
tojulia(x::CLNullPtr) = JuliaUnknown(x) # C++11 nullptr
tojulia(x::CLPointer) = JuliaCpointer(x)
tojulia(x::CLBlockPointer) = JuliaUnknown(x) # ObjectveC's block pointer
function tojulia(x::CLElaborated)
jlty = tojulia(getNamedType(x))
@assert jlty isa JuliaCenum || jlty isa JuliaCrecord
return jlty
end
tojulia(x::CLElaborated) = tojulia(getNamedType(x))
tojulia(x::CLInvalid) = JuliaUnknown(x)
tojulia(x::CLFunctionProto) = JuliaCfunction(spelling(getTypeDeclaration(x)))
tojulia(x::CLFunctionNoProto) = JuliaCfunction(spelling(getTypeDeclaration(x)))
Expand Down
2 changes: 1 addition & 1 deletion src/generator/nested.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function collect_nested_record!(dag::ExprDAG, node::ExprNode, new_tags, isdeterm
field_cursors = isempty(field_cursors) ? children(node.cursor) : field_cursors
for field_cursor in field_cursors
field_ty = getCursorType(field_cursor)
has_elaborated_reference(field_ty) || continue
has_elaborated_tag_reference(field_ty) || continue
field_jlty = tojulia(field_ty)
leaf_jlty = get_jl_leaf_type(field_jlty)
leaf_jlty isa JuliaCrecord || continue # nested enums are not legal in C
Expand Down
6 changes: 3 additions & 3 deletions src/generator/resolve_deps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function resolve_dependency!(dag::ExprDAG, node::ExprNode{FunctionProto}, option
# do nothing for unknowns since we just skip them in the downstream passes
is_jl_unknown(leaf_ty) && return dag

hasref = has_elaborated_reference(ty)
hasref = has_elaborated_tag_reference(ty)
if hasref && haskey(dag.tags, leaf_ty.sym)
push!(node.adj, dag.tags[leaf_ty.sym])
elseif !hasref && haskey(dag.ids, leaf_ty.sym)
Expand Down Expand Up @@ -59,7 +59,7 @@ function resolve_dependency!(dag::ExprDAG, node::ExprNode{FunctionNoProto}, opti

is_jl_basic(leaf_ty) && return dag

hasref = has_elaborated_reference(ty)
hasref = has_elaborated_tag_reference(ty)
if hasref && haskey(dag.tags, leaf_ty.sym)
push!(node.adj, dag.tags[leaf_ty.sym])
elseif !hasref && haskey(dag.ids, leaf_ty.sym)
Expand Down Expand Up @@ -145,7 +145,7 @@ function resolve_dependency!(dag::ExprDAG, node::ExprNode{<:AbstractStructNodeTy

is_jl_basic(leaf_ty) && continue

hasref = has_elaborated_reference(ty)
hasref = has_elaborated_tag_reference(ty)
if hasref && haskey(dag.tags, leaf_ty.sym)
push!(node.adj, dag.tags[leaf_ty.sym])
elseif !hasref && haskey(dag.ids, leaf_ty.sym)
Expand Down
6 changes: 3 additions & 3 deletions src/generator/system_deps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function collect_dependent_system_nodes!(dag::ExprDAG, node::ExprNode{FunctionPr

# FIXME: typedef func proto

hasref = has_elaborated_reference(ty)
hasref = has_elaborated_tag_reference(ty)
if (hasref && haskey(dag.tags, leaf_ty.sym)) ||
(!hasref && haskey(dag.ids, leaf_ty.sym)) ||
haskey(dag.ids_extra, leaf_ty.sym) ||
Expand All @@ -50,7 +50,7 @@ function collect_dependent_system_nodes!(dag::ExprDAG, node::ExprNode{FunctionNo

is_jl_basic(leaf_ty) && return system_nodes

hasref = has_elaborated_reference(ty)
hasref = has_elaborated_tag_reference(ty)
if (hasref && haskey(dag.tags, leaf_ty.sym)) ||
(!hasref && haskey(dag.ids, leaf_ty.sym)) ||
haskey(dag.ids_extra, leaf_ty.sym)
Expand Down Expand Up @@ -134,7 +134,7 @@ function collect_dependent_system_nodes!(dag::ExprDAG, type::CLType, system_node

# FIXME: typedef func proto

hasref = has_elaborated_reference(ty)
hasref = has_elaborated_tag_reference(ty)
if (hasref && haskey(dag.tags, leaf_ty.sym)) ||
(!hasref && haskey(dag.ids, leaf_ty.sym)) ||
haskey(dag.ids_extra, leaf_ty.sym) ||
Expand Down
2 changes: 1 addition & 1 deletion src/generator/top_level.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end
function collect_top_level_nodes!(nodes::Vector{ExprNode}, cursor::CLTypedefDecl, options)
lhs_type = getTypedefDeclUnderlyingType(cursor)

if has_elaborated_reference(lhs_type)
if has_elaborated_tag_reference(lhs_type)
ty = TypedefElaborated()
elseif has_function_reference(lhs_type)
ty = TypedefFunction()
Expand Down
29 changes: 29 additions & 0 deletions src/type.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,35 @@ function has_elaborated_reference(ty::CXType)
end
has_elaborated_reference(ty::CLType) = has_elaborated_reference(ty.type)


"""
has_elaborated_tag_reference(ty::CLType) -> Bool
has_elaborated_tag_reference(ty::CXType) -> Bool
Return true if the type is an elaborated tag type or the type indirectly refers to an
elaborated tag type.
"""
function has_elaborated_tag_reference(ty::CXType)
if kind(ty) == CXType_Pointer
ptreety = getPointeeType(ty)
return has_elaborated_tag_reference(ptreety)
elseif kind(ty) == CXType_ConstantArray || kind(ty) == CXType_IncompleteArray
elty = getElementType(ty)
return has_elaborated_tag_reference(elty)
elseif is_elaborated(ty)
nty = getNamedType(ty)
if kind(nty) == CXType_Enum || kind(nty) == CXType_Record
return true
else
return has_elaborated_tag_reference(nty)
end
else
return false
end
end
has_elaborated_tag_reference(ty::CLType) = has_elaborated_tag_reference(ty.type)



"""
get_elaborated_cursor(ty::CLType) -> CLCursor
get_elaborated_cursor(ty::CXType) -> CXCursor
Expand Down

0 comments on commit ba7d48d

Please sign in to comment.