Skip to content

Commit

Permalink
Support function_argument_conflict_symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnimuc committed Apr 14, 2021
1 parent f476f99 commit 63e0e78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gen/generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ opaque_as_mutable_struct = true
# generate getproperty/setproperty! methods for the types in the following list
field_access_method_list = []

# the generator will prefix the function argument names in the following list with a "_" to
# prevent the generated symbols from conflicting with the symbols defined and exported in Base.
function_argument_conflict_symbols = ["Ptr"]

[codegen.macro]
# it‘s highly recommended to set this entry to "basic".
# if you'd like to skip all of the macros, please set this entry to "disable".
Expand All @@ -145,6 +149,7 @@ add_comment_for_skipped_macro = true
ignore_header_guards = true
ignore_header_guards_with_suffixes = []


[general.log]
# CollectTopLevelNode_log = false
# LinkTypedefToAnonymousTagType_log = false
Expand Down
4 changes: 4 additions & 0 deletions src/generator/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ emit!(dag::ExprDAG, node::ExprNode, options::Dict; args...) = dag
############################### Function ###############################

function emit!(dag::ExprDAG, node::ExprNode{FunctionProto}, options::Dict; args...)
conflict_syms = get(options, "function_argument_conflict_symbols", [])

cursor = node.cursor

library_name = options["library_name"]
Expand Down Expand Up @@ -37,6 +39,8 @@ function emit!(dag::ExprDAG, node::ExprNode{FunctionProto}, options::Dict; args.
# handle name collisions
if haskey(dag.tags, ns) || haskey(dag.ids, ns) || haskey(dag.ids_extra, ns)
safe_name *= "_"
elseif safe_name conflict_syms
safe_name = "_" * safe_name
end
arg_names[i] = Symbol(safe_name)
end
Expand Down

0 comments on commit 63e0e78

Please sign in to comment.