File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -610,6 +610,21 @@ getidx(md::Metadata, vn::VarName) = md.idcs[vn]
610
610
Return the index range of `vn` in the metadata of `vi`.
611
611
"""
612
612
getrange (vi:: VarInfo , vn:: VarName ) = getrange (getmetadata (vi, vn), vn)
613
+ # For `TypedVarInfo` it's more difficult since we need to keep track of the offset.
614
+ # TOOD: Should we unroll this using `@generated`?
615
+ function getrange (vi:: TypedVarInfo , vn:: VarName )
616
+ offset = 0
617
+ for md in values (vi. metadata)
618
+ # First, we need to check if `vn` is in `md`.
619
+ # In this case, we can just return the corresponding range + offset.
620
+ haskey (md, vn) && return getrange (md, vn) .+ offset
621
+ # Otherwise, we need to get the cumulative length of the ranges in `md`
622
+ # and add it to the offset.
623
+ offset += sum (length, md. ranges)
624
+ end
625
+ # If we reach this point, `vn` is not in `vi.metadata`.
626
+ throw (KeyError (vn))
627
+ end
613
628
getrange (md:: Metadata , vn:: VarName ) = md. ranges[getidx (md, vn)]
614
629
615
630
"""
You can’t perform that action at this time.
0 commit comments