Skip to content

Commit

Permalink
Add flag to control outputting of system code (#485)
Browse files Browse the repository at this point in the history
Add a flag to control the outputting of symbols in `-isystem` headers

---------

Co-authored-by: Gnimuc <qiyupei@gmail.com>
  • Loading branch information
Octogonapus and Gnimuc authored Apr 18, 2024
1 parent 586f3df commit 64f640b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Clang"
uuid = "40e3b903-d033-50b4-a0cc-940c62c95e31"
version = "0.18.1"
version = "0.18.2"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
30 changes: 22 additions & 8 deletions src/generator/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,10 @@ function (x::Audit)(dag::ExprDAG, options::Dict)
return dag
end

function should_exclude_node(node, ignorelist, exclusivelist)
function should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist=[])
str_node = string(node.id)
str_node isystem_ignorelist && return true

for item ignorelist
the_match = match(Regex(item), str_node)
if the_match !== nothing && the_match.match == str_node
Expand Down Expand Up @@ -944,10 +946,13 @@ function (x::FunctionPrinter)(dag::ExprDAG, options::Dict)
ignorelist = get(general_options, "output_ignorelist", get(general_options, "printer_blacklist", []))
exclusivelist = get(general_options, "output_exclusivelist", nothing)

isystem_ignorelist = []
!get(general_options, "generate_isystem_symbols", true) && append!(isystem_ignorelist, string(x.id) for x in dag.sys)

show_info && @info "[FunctionPrinter]: print to $(x.file)"
open(x.file, "w") do io
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractFunctionNodeType || continue
pretty_print(io, node, general_options)
end
Expand All @@ -972,16 +977,19 @@ function (x::CommonPrinter)(dag::ExprDAG, options::Dict)
ignorelist = get(general_options, "output_ignorelist", get(general_options, "printer_blacklist", []))
exclusivelist = get(general_options, "output_exclusivelist", nothing)

isystem_ignorelist = []
!get(general_options, "generate_isystem_symbols", true) && append!(isystem_ignorelist, string(x.id) for x in dag.sys)

show_info && @info "[CommonPrinter]: print to $(x.file)"
open(x.file, "w") do io
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
(node.type isa AbstractMacroNodeType || node.type isa AbstractFunctionNodeType) && continue
pretty_print(io, node, general_options)
end
# print macros in the bottom of the file
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType || continue
pretty_print(io, node, options)
end
Expand All @@ -1007,16 +1015,19 @@ function (x::GeneralPrinter)(dag::ExprDAG, options::Dict)
general_options["DAG_ids"] = merge(dag.ids, dag.tags)
exclusivelist = get(general_options, "output_exclusivelist", nothing)

isystem_ignorelist = []
!get(general_options, "generate_isystem_symbols", true) && append!(isystem_ignorelist, string(x.id) for x in dag.sys)

show_info && @info "[GeneralPrinter]: print to $(x.file)"
open(x.file, "a") do io
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && 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
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType || continue
isempty(node.exprs)
pretty_print(io, node, options)
Expand All @@ -1043,14 +1054,17 @@ function (x::StdPrinter)(dag::ExprDAG, options::Dict)
ignorelist = get(general_options, "output_ignorelist", get(general_options, "printer_blacklist", []))
exclusivelist = get(general_options, "output_exclusivelist", nothing)

isystem_ignorelist = []
!get(general_options, "generate_isystem_symbols", true) && append!(isystem_ignorelist, string(x.id) for x in dag.sys)

for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType && continue
pretty_print(stdout, node, general_options)
end
# print macros
for node in dag.nodes
should_exclude_node(node, ignorelist, exclusivelist) && continue
should_exclude_node(node, ignorelist, exclusivelist, isystem_ignorelist) && continue
node.type isa AbstractMacroNodeType || continue
pretty_print(stdout, node, options)
end
Expand Down

1 comment on commit 64f640b

@Octogonapus
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gnimuc could you please register this version?

Please sign in to comment.