From 63e0e787aaa3a2e7cc5ec955427c2004aa5b9810 Mon Sep 17 00:00:00 2001 From: Gnimuc Date: Wed, 14 Apr 2021 19:53:56 +0900 Subject: [PATCH] Support `function_argument_conflict_symbols` --- gen/generator.toml | 5 +++++ src/generator/codegen.jl | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/gen/generator.toml b/gen/generator.toml index 2e4205e2..5caa063c 100644 --- a/gen/generator.toml +++ b/gen/generator.toml @@ -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". @@ -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 diff --git a/src/generator/codegen.jl b/src/generator/codegen.jl index 9a0964e5..6a8cc8fd 100644 --- a/src/generator/codegen.jl +++ b/src/generator/codegen.jl @@ -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"] @@ -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