Skip to content

Commit 5cd574c

Browse files
committed
scopes: Add show methods
1 parent 43178ee commit 5cd574c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/scopes.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,47 @@ struct InvalidScope <: AbstractScope
7373
y::AbstractScope
7474
end
7575

76+
# Show methods
77+
78+
function Base.show(io::IO, scope::UnionScope)
79+
indent = io isa IOContext ? get(io, :indent, 0) : 0
80+
println(io, "UnionScope:")
81+
indent += 2
82+
inner_io = IOContext(io, :indent => indent)
83+
if length(scope.scopes) == 0
84+
print(io, " "^indent, "empty")
85+
return
86+
end
87+
for (idx, inner_scope) in enumerate(scope.scopes)
88+
print(io, " "^indent); print(inner_io, inner_scope)
89+
idx < length(scope.scopes) && println(io)
90+
end
91+
end
92+
function Base.show(io::IO, scope::TaintScope)
93+
indent = io isa IOContext ? get(io, :indent, 0) : 0
94+
println(io, "TaintScope:")
95+
indent += 2
96+
inner_io = IOContext(io, :indent => indent)
97+
print(io, " "^indent, "scope: "); println(inner_io, scope.scope)
98+
if length(scope.taints) == 0
99+
print(io, " "^indent, "no taints")
100+
return
101+
end
102+
println(io, " "^indent, "taints: ")
103+
indent += 4
104+
inner_io = IOContext(io, :indent => indent)
105+
for (idx, taint) in enumerate(scope.taints)
106+
print(io, " "^indent); print(inner_io, taint)
107+
idx < length(scope.taints) && println(io)
108+
end
109+
end
110+
Base.show(io::IO, scope::NodeScope) =
111+
print(io, "NodeScope: node == $(scope.uuid)")
112+
Base.show(io::IO, scope::ProcessScope) =
113+
print(io, "ProcessScope: worker == $(scope.wid)")
114+
Base.show(io::IO, scope::ExactScope) =
115+
print(io, "ExactScope: processor == $(scope.processor)")
116+
76117
# Comparisons and constraint checking
77118

78119
constrain(x, y) = x < y ? constrain(y, x) : throw(MethodError(constrain, x, y))

0 commit comments

Comments
 (0)