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

Remove "blacklist" and "whitelist" in favor of neutral terms #302

Merged
merged 1 commit into from
Oct 13, 2021
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
14 changes: 7 additions & 7 deletions gen/generator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ prologue_file_path = "./prologue.jl"
# this is often used for applying custom patches.
epilogue_file_path = ""

# node with an id in the `printer_blacklist` will be ignored in the printing passes.
# node with an id in the `printer_denylist` will be ignored in the printing passes.
# this is very useful for custom editing.
printer_blacklist = [
printer_denylist = [
"CINDEX_EXPORTS",
"CINDEX_VERSION",
"CINDEX_VERSION_STRING",
Expand Down Expand Up @@ -115,11 +115,11 @@ auto_mutability_with_new = true
# when calling this function via `ccall`, passing a `Vector{mutable_type}(undef, n)` to the first
# argument will trigger a crash, the reason is mutable structs are not stored inline within a `Vector`,
# one should use `Ref{NTuple{n,mutable_type}}()` instead.
# this is not convenient and that's where the `auto_mutability_blacklist` comes in.
auto_mutability_blacklist = []
# this is not convenient and that's where the `auto_mutability_denylist` comes in.
auto_mutability_denylist = []

# opposite to `auto_mutability_blacklist` and has a higher priority
auto_mutability_whitelist = []
# opposite to `auto_mutability_denylist` and has a higher priority
auto_mutability_allowlist = []

# if set to "raw", extract and dump raw c comment;
# if set to "doxygen", parse and format doxygen comment.
Expand Down Expand Up @@ -176,7 +176,7 @@ function_argument_conflict_symbols = []
macro_mode = "basic"

# function-like macros in the following list will always be translated.
functionlike_macro_whitelist = [
functionlike_macro_allowlist = [
"CINDEX_VERSION_ENCODE",
]

Expand Down
14 changes: 7 additions & 7 deletions src/generator/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ is_macro_definition_only(toks::Vector) = length(toks) == 1 && is_identifier(toks
is_macro_definition_only(toks::TokenList) = toks.size == 1 && is_identifier(toks[1])
is_macro_definition_only(cursor::CLCursor) = is_macro_definition_only(tokenize(cursor))

# identifier and keyword blacklist
const MACRO_IDK_BLACKLIST = [
# identifier and keyword denylist
const MACRO_IDK_DENYLIST = [
C_KEYWORDS_UNSUPPORTED...,
"_Pragma",
"__attribute__",
Expand All @@ -214,9 +214,9 @@ Return true if the macro should be ignored.
"""
function is_macro_unsupported(cursor::CLCursor)
for tok in tokenize(cursor)
is_identifier(tok) && tok.text ∈ MACRO_IDK_BLACKLIST && return true
is_keyword(tok) && tok.text ∈ MACRO_IDK_BLACKLIST && return true
is_punctuation(tok) && tok.text ∈ MACRO_IDK_BLACKLIST && return true
is_identifier(tok) && tok.text ∈ MACRO_IDK_DENYLIST && return true
is_keyword(tok) && tok.text ∈ MACRO_IDK_DENYLIST && return true
is_punctuation(tok) && tok.text ∈ MACRO_IDK_DENYLIST && return true
end
return false
end
Expand Down Expand Up @@ -335,13 +335,13 @@ end
function macro_emit!(dag::ExprDAG, node::ExprNode{MacroFunctionLike}, options::Dict)
print_comment = get(options, "add_comment_for_skipped_macro", true)
mode = get(options, "macro_mode", "basic")
whitelist = get(options, "functionlike_macro_whitelist", String[])
allowlist = get(options, "functionlike_macro_allowlist", String[])

cursor = node.cursor
toks = collect(tokenize(cursor))
tokens = tweak_exprs(dag, toks)
id = tokens[1].text
mode != "aggressive" && id ∉ whitelist && return dag
mode != "aggressive" && id ∉ allowlist && return dag

lhs_sym = make_symbol_safe(id)

Expand Down
38 changes: 19 additions & 19 deletions src/generator/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,10 @@ In this pass, the mutability of those structs which are not necessary to be immu
will be reset to `true` according to the following rules:

if this type is not used as a field type in any other types
if this type is in the whitelist
if this type is in the allowlist
then reset

if this type is in the blacklist
if this type is in the denylist
then skip

if this type is used as the argument type in some function protos
Expand All @@ -704,8 +704,8 @@ function (x::TweakMutability)(dag::ExprDAG, options::Dict)
general_options = get(options, "general", Dict())
log_options = get(general_options, "log", Dict())
show_info = get(log_options, "TweakMutability_log", x.show_info)
blacklist = get(general_options, "auto_mutability_blacklist", [])
whitelist = get(general_options, "auto_mutability_whitelist", [])
denylist = get(general_options, "auto_mutability_denylist", get(general_options, "auto_mutability_blacklist", []))
allowlist = get(general_options, "auto_mutability_allowlist", get(general_options, "auto_mutability_whitelist", []))
add_new = get(general_options, "auto_mutability_with_new", true)

# collect referenced node ids
Expand All @@ -731,9 +731,9 @@ function (x::TweakMutability)(dag::ExprDAG, options::Dict)
type_name = string(expr.args[2])

apply_reset = false
if type_name ∈ whitelist
if type_name ∈ allowlist
apply_reset = true
elseif type_name ∈ blacklist
elseif type_name ∈ denylist
apply_reset = false
else
apply_reset = should_tweak(dag.nodes, i)
Expand Down Expand Up @@ -832,12 +832,12 @@ function (x::FunctionPrinter)(dag::ExprDAG, options::Dict)
general_options = get(options, "general", Dict())
log_options = get(general_options, "log", Dict())
show_info = get(log_options, "FunctionPrinter_log", x.show_info)
blacklist = get(general_options, "printer_blacklist", [])
denylist = get(general_options, "printer_denylist", get(general_options, "printer_blacklist", []))

show_info && @info "[FunctionPrinter]: print to $(x.file)"
open(x.file, "w") do io
for node in dag.nodes
string(node.id) ∈ blacklist && continue
string(node.id) ∈ denylist && continue
node.type isa AbstractFunctionNodeType || continue
pretty_print(io, node, general_options)
end
Expand All @@ -859,18 +859,18 @@ function (x::CommonPrinter)(dag::ExprDAG, options::Dict)
general_options = get(options, "general", Dict())
log_options = get(general_options, "log", Dict())
show_info = get(log_options, "CommonPrinter_log", x.show_info)
blacklist = get(general_options, "printer_blacklist", [])
denylist = get(general_options, "printer_denylist", get(general_options, "printer_blacklist", []))

show_info && @info "[CommonPrinter]: print to $(x.file)"
open(x.file, "w") do io
for node in dag.nodes
string(node.id) ∈ blacklist && continue
(node.type isa AbstractMacroNodeType || node.type isa AbstractFunctionNodeType) && continue
string(node.id) ∈ denylist && continue
node.type isa AbstractMacroNodeType && continue
pretty_print(io, node, general_options)
end
# print macros in the bottom of the file
for node in dag.nodes
string(node.id) ∈ blacklist && continue
string(node.id) ∈ denylist && continue
node.type isa AbstractMacroNodeType || continue
pretty_print(io, node, options)
end
Expand All @@ -892,19 +892,19 @@ function (x::GeneralPrinter)(dag::ExprDAG, options::Dict)
general_options = get(options, "general", Dict())
log_options = get(general_options, "log", Dict())
show_info = get(log_options, "GeneralPrinter_log", x.show_info)
blacklist = get(general_options, "printer_blacklist", [])
denylist = get(general_options, "printer_denylist", get(general_options, "printer_blacklist", []))
general_options["DAG_ids"] = merge(dag.ids, dag.tags)

show_info && @info "[GeneralPrinter]: print to $(x.file)"
open(x.file, "a") do io
for node in dag.nodes
string(node.id) ∈ blacklist && continue
string(node.id) ∈ denylist && continue
node.type isa AbstractMacroNodeType && continue
pretty_print(io, node, general_options)
end
# print macros in the bottom of the file
for node in dag.nodes
string(node.id) ∈ blacklist && continue
string(node.id) ∈ denylist && continue
node.type isa AbstractMacroNodeType || continue
isempty(node.exprs)
pretty_print(io, node, options)
Expand All @@ -928,16 +928,16 @@ function (x::StdPrinter)(dag::ExprDAG, options::Dict)
general_options = get(options, "general", Dict())
log_options = get(general_options, "log", Dict())
show_info = get(log_options, "StdPrinter_log", x.show_info)
blacklist = get(general_options, "printer_blacklist", [])
denylist = get(general_options, "printer_denylist", get(general_options, "auto_mutability_blacklist", []))

for node in dag.nodes
string(node.id) ∈ blacklist && continue
string(node.id) ∈ denylist && continue
node.type isa AbstractMacroNodeType && continue
pretty_print(stdout, node, general_options)
end
# print macros
for node in dag.nodes
string(node.id) ∈ blacklist && continue
string(node.id) ∈ denylist && continue
node.type isa AbstractMacroNodeType || continue
pretty_print(stdout, node, options)
end
Expand Down Expand Up @@ -1101,4 +1101,4 @@ function collect_nested_tags(dag::ExprDAG)
end
end
nested_tags
end
end