Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain the expression when FLAG_EXPLAIN_EXPRESSION[]=true #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import StaticArraysCore
document[:Base] = Symbol[]

const FLAG_EXPLAIN_EXPRESSION = Ref(false)

#= ============================ =#
# IDS and IDSvector structures #
#= ============================ =#
Expand Down Expand Up @@ -398,10 +400,27 @@

elseif !isfrozen(ids)
# expressions
if FLAG_EXPLAIN_EXPRESSION[]
expr_info_dict = get_expr_info_dict(Val{:onetime_and_dynamic})

Check warning on line 404 in src/data.jl

View check run for this annotation

Codecov / codecov/patch

src/data.jl#L404

Added line #L404 was not covered by tests
end
uloc = ulocation(ids, field)
for (onetime, expressions) in zip((true, false), (get_expressions(Val{:onetime}), get_expressions(Val{:dynamic})))
if uloc ∈ keys(expressions)
func = expressions[uloc]

if FLAG_EXPLAIN_EXPRESSION[]
show(stdout, "text/plain", expr_info_dict[uloc])

Check warning on line 412 in src/data.jl

View check run for this annotation

Codecov / codecov/patch

src/data.jl#L412

Added line #L412 was not covered by tests

# To get the result of this expression, turning off the FLAG temporarily
FLAG_EXPLAIN_EXPRESSION[] = false
value = exec_expression_with_ancestor_args(ids, field, func)
FLAG_EXPLAIN_EXPRESSION[] = true

Check warning on line 417 in src/data.jl

View check run for this annotation

Codecov / codecov/patch

src/data.jl#L415-L417

Added lines #L415 - L417 were not covered by tests

# Display the result
printstyled("[Result]\n"; color=:blue)
display(value)
print("\n")

Check warning on line 422 in src/data.jl

View check run for this annotation

Codecov / codecov/patch

src/data.jl#L420-L422

Added lines #L420 - L422 were not covered by tests
end
value = exec_expression_with_ancestor_args(ids, field, func)
if typeof(value) <: Exception
# check in the reference
Expand Down
5 changes: 5 additions & 0 deletions src/expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
return Dict{String,Function}()
end

function get_expr_info_dict(::Type{Val{T}}) where {T}

Check warning on line 21 in src/expressions.jl

View check run for this annotation

Codecov / codecov/patch

src/expressions.jl#L21

Added line #L21 was not covered by tests
# This is just a place holder, the actual second argument will be "ExprInfo" struct defined in IMAS
return Dict{String,Any}()

Check warning on line 23 in src/expressions.jl

View check run for this annotation

Codecov / codecov/patch

src/expressions.jl#L23

Added line #L23 was not covered by tests
end

const expression_onetime_weakref = Dict{UInt64,WeakRef}()

"""
Expand Down
Loading