@@ -8,14 +8,7 @@ import ..NodeModule: default_allocator, with_type_parameters, constructorof, get
88abstract type AbstractReadOnlyNode{T,D,N<: AbstractExpressionNode{T,D} } < :
99 AbstractExpressionNode{T,D} end
1010
11- """ A type of expression node that prevents writing to the inner node"""
12- struct ReadOnlyNode{T,D,N} <: AbstractReadOnlyNode{T,D,N}
13- _inner:: N
14-
15- ReadOnlyNode (n:: N ) where {T,N<: AbstractExpressionNode{T} } = new {T,max_degree(N),N} (n)
16- end
1711@inline inner (n:: AbstractReadOnlyNode ) = getfield (n, :_inner )
18- @unstable constructorof (:: Type{<:ReadOnlyNode} ) = ReadOnlyNode
1912@inline function Base. getproperty (n:: AbstractReadOnlyNode , s:: Symbol )
2013 out = getproperty (inner (n), s)
2114 if out isa AbstractExpressionNode
2518 end
2619end
2720@inline function get_children (node:: AbstractReadOnlyNode )
28- return map (ReadOnlyNode , get_children (inner (node)))
21+ return map (constructorof ( typeof (node)) , get_children (inner (node)))
2922end
3023function Base. setproperty! (:: AbstractReadOnlyNode , :: Symbol , v)
3124 return error (" Cannot set properties on a ReadOnlyNode" )
3225end
3326Base. propertynames (n:: AbstractReadOnlyNode ) = propertynames (inner (n))
34- Base. copy (n:: AbstractReadOnlyNode ) = ReadOnlyNode (copy (inner (n)))
27+ Base. copy (n:: AbstractReadOnlyNode ) = constructorof (typeof (n))(copy (inner (n)))
28+
29+ """ A type of expression node that prevents writing to the inner node"""
30+ struct ReadOnlyNode{T,D,N} <: AbstractReadOnlyNode{T,D,N}
31+ _inner:: N
32+
33+ ReadOnlyNode (n:: N ) where {T,N<: AbstractExpressionNode{T} } = new {T,max_degree(N),N} (n)
34+ end
35+ @unstable constructorof (:: Type{<:ReadOnlyNode} ) = ReadOnlyNode
3536
3637end
0 commit comments