@@ -298,25 +298,30 @@ Base.eltype(::AbstractExpressionNode{T}) where {T} = T
298298
299299has_max_degree (:: Type{<:AbstractNode} ) = false
300300has_max_degree (:: Type{<:AbstractNode{D}} ) where {D} = true
301+ has_eltype (:: Type{<:AbstractExpressionNode} ) = false
302+ has_eltype (:: Type{<:AbstractExpressionNode{T}} ) where {T} = true
301303# COV_EXCL_STOP
302304# ! format: on
303305
304- @unstable function constructorof (:: Type{N} ) where {N<: Node }
305- return Node{T, max_degree (N)} where {T}
306+ @unstable function node_wrapper (:: Type{N} ) where {N<: AbstractExpressionNode }
307+ return Base . typename (N). wrapper
306308end
307- @unstable function constructorof (:: Type{N} ) where {N<: GraphNode }
308- return GraphNode {T,max_degree (N)} where {T}
309+ @unstable function constructorof (:: Type{N} ) where {N<: AbstractExpressionNode }
310+ return node_wrapper (N) {T,max_degree (N)} where {T}
309311end
310-
311- function with_type_parameters (:: Type{N} , :: Type{T} ) where {N<: Node ,T}
312- return Node{T,max_degree (N)}
312+ function with_type_parameters (:: Type{N} , :: Type{T} ) where {N<: AbstractExpressionNode ,T}
313+ return node_wrapper (N){T,max_degree (N)}
313314end
314- function with_type_parameters (:: Type{N} , :: Type{T} ) where {N<: GraphNode ,T}
315- return GraphNode{T,max_degree (N)}
315+ @unstable function with_max_degree (:: Type{N} , :: Val{D} ) where {N<: AbstractExpressionNode ,D}
316+ if has_eltype (N)
317+ return node_wrapper (N){eltype (N),D}
318+ else
319+ return node_wrapper (N){T,D} where {T}
320+ end
321+ end
322+ @unstable function with_default_max_degree (:: Type{N} ) where {N<: AbstractNode }
323+ return with_max_degree (N, Val (max_degree (N)))
316324end
317-
318- with_max_degree (:: Type{N} , :: Val{D} ) where {T,N<: Node{T} ,D} = Node{T,D}
319- with_max_degree (:: Type{N} , :: Val{D} ) where {T,N<: GraphNode{T} ,D} = GraphNode{T,D}
320325
321326function default_allocator (:: Type{N} , :: Type{T} ) where {N<: AbstractExpressionNode ,T}
322327 return with_type_parameters (N, T)()
@@ -341,17 +346,26 @@ include("base.jl")
341346 else
342347 children
343348 end
344- validate_not_all_defaults (N, val, feature, op, _children)
349+ if all_defaults (N, val, feature, op, _children)
350+ return make_default (N, T1)
351+ end
345352 return node_factory (N, T1, val, feature, op, _children, allocator)
346353end
347- function validate_not_all_defaults (:: Type{N} , val, feature, op, children ) where {N<: AbstractExpressionNode }
348- if all (isnothing, (val, feature, op, children) )
354+ function make_default (:: Type{N} , :: Type{T1} ) where {T1, N<: AbstractExpressionNode }
355+ if has_max_degree (N )
349356 error (
350357 " Encountered the call for $N () inside the generic constructor. "
351358 * " Did you forget to define `$(Base. typename (N). wrapper) {T,D}() where {T,D} = new{T,D}()`?"
352359 )
353360 end
354- return nothing
361+ if T1 === Undefined
362+ return with_default_max_degree (N)()
363+ else
364+ return with_type_parameters (with_default_max_degree (N), T1)()
365+ end
366+ end
367+ function all_defaults (:: Type{N} , val, feature, op, children) where {N<: AbstractExpressionNode }
368+ return all (isnothing, (val, feature, op, children))
355369end
356370""" Create a constant leaf."""
357371@inline function node_factory (
0 commit comments