From 80418cced14f2346df2955380387118b83a03bbf Mon Sep 17 00:00:00 2001 From: Owen Lynch Date: Wed, 10 Jan 2024 14:16:31 -0800 Subject: [PATCH 1/2] export the generic acset name from the generated intertype module --- src/intertypes/InterTypes.jl | 19 +++++++++++++++++++ src/intertypes/julia.jl | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/intertypes/InterTypes.jl b/src/intertypes/InterTypes.jl index d728817..a8fa84d 100644 --- a/src/intertypes/InterTypes.jl +++ b/src/intertypes/InterTypes.jl @@ -82,6 +82,16 @@ end NamedACSetType(typespec::ACSetTypeSpec) end +exports(::InterTypeDecl) = Symbol[] + +function exports(acset_type::NamedACSetType) + if !isnothing(acset_type.typespec.genericname) + [acset_type.typespec.genericname] + else + [] + end +end + function hashdecls end struct InterTypeModule @@ -98,6 +108,15 @@ struct InterTypeModule end end +function exports(mod::InterTypeModule) + export_list = Symbol[] + for (name, decl) in pairs(mod.declarations) + push!(export_list, name) + append!(export_list, exports(decl)) + end + export_list +end + function intertype end abstract type ExportTarget end diff --git a/src/intertypes/julia.jl b/src/intertypes/julia.jl index fcd0402..dec9556 100644 --- a/src/intertypes/julia.jl +++ b/src/intertypes/julia.jl @@ -313,7 +313,7 @@ function include_intertypes(into::Module, file::String, imports::AbstractVector) into.include(as_intertypes(mod), file) # recompute the hash mod = InterTypeModule(name, mod.imports, mod.declarations) - into.eval(Expr(:export, keys(mod.declarations)...)) + into.eval(Expr(:export, exports(mod)...)) mod end From da324ba6807ed1d185e07521be4e51c496fd2fa8 Mon Sep 17 00:00:00 2001 From: Owen Lynch Date: Wed, 10 Jan 2024 14:20:13 -0800 Subject: [PATCH 2/2] add test for exported generic name --- test/intertypes/InterTypes.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/intertypes/InterTypes.jl b/test/intertypes/InterTypes.jl index bcf13e3..4003599 100644 --- a/test/intertypes/InterTypes.jl +++ b/test/intertypes/InterTypes.jl @@ -69,7 +69,14 @@ g = EDWeightedGraph() add_parts!(g, :V, 2) add_part!(g, :E, src=1, tgt=2, weight=EdgeData(:mass_ave, 42)) -@test testjson(m) +@test testjson(g) + +sg = WeightedGraph{Symbol}() + +add_parts!(sg, :V, 2) +add_part!(sg, :E, src=1, tgt=2, weight=:mass_ave) + +@test testjson(sg) generate_module(wgraph, JSONTarget)