Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option for skipping static functions #456

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gen/generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ field_access_method_list = []
# prevent the generated symbols from conflicting with the symbols defined and exported in Base.
function_argument_conflict_symbols = []

# if set to true, static functions will be ignored
skip_static_functions = false

# emit constructors for all custom-layout structs like bitfield in the list,
# or set to `true` to do so for all such structs
add_record_constructors = []
Expand Down
1 change: 1 addition & 0 deletions src/generator/Generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using ..Clang:
getArgument,
getCursorType,
getCanonicalType,
getCursorLinkage,
getCursorResultType,
getElementType,
getEnumDeclIntegerType,
Expand Down
3 changes: 3 additions & 0 deletions src/generator/top_level.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function collect_top_level_nodes!(nodes::Vector{ExprNode}, cursor::CLCursor, opt
end

function collect_top_level_nodes!(nodes::Vector{ExprNode}, cursor::CLFunctionDecl, options)
skip_static_func = get(options, "skip_static_functions", false)
skip_static_func && getCursorLinkage(cursor) == CXLinkage_Internal && return nodes

func_type = getCursorType(cursor)

if kind(func_type) == CXType_FunctionNoProto
Expand Down
6 changes: 6 additions & 0 deletions test/generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,9 @@ end
ctx = create_context([joinpath(@__DIR__, "include/struct-mutual-ref.h")], get_default_args())
@test_logs (:info, "Done!") match_mode = :any build!(ctx)
end

@testset "Issue 455 - skip static functions" begin
options = Dict("general" => Dict{String,Any}("skip_static_functions" => true))
ctx = create_context([joinpath(@__DIR__, "include/static.h")], get_default_args(), options)
@test_logs (:info, "Done!") match_mode = :any build!(ctx)
end
9 changes: 9 additions & 0 deletions test/include/static.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef STATIC_H
#define STATIC_H

static inline int skip_static(void)
{
return 0;
}

#endif
Loading