@@ -8,14 +8,7 @@ import ..NodeModule: default_allocator, with_type_parameters, constructorof, get
8
8
abstract type AbstractReadOnlyNode{T,D,N<: AbstractExpressionNode{T,D} } < :
9
9
AbstractExpressionNode{T,D} end
10
10
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
17
11
@inline inner (n:: AbstractReadOnlyNode ) = getfield (n, :_inner )
18
- @unstable constructorof (:: Type{<:ReadOnlyNode} ) = ReadOnlyNode
19
12
@inline function Base. getproperty (n:: AbstractReadOnlyNode , s:: Symbol )
20
13
out = getproperty (inner (n), s)
21
14
if out isa AbstractExpressionNode
25
18
end
26
19
end
27
20
@inline function get_children (node:: AbstractReadOnlyNode )
28
- return map (ReadOnlyNode , get_children (inner (node)))
21
+ return map (constructorof ( typeof (node)) , get_children (inner (node)))
29
22
end
30
23
function Base. setproperty! (:: AbstractReadOnlyNode , :: Symbol , v)
31
24
return error (" Cannot set properties on a ReadOnlyNode" )
32
25
end
33
26
Base. 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
35
36
36
37
end
0 commit comments