Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[t/spec] Support :tree option for .^roles.
  • Loading branch information
jnthn committed Jul 29, 2009
1 parent b6f792c commit c4f0a93
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/classes/ClassHOW.pir
Expand Up @@ -330,6 +330,17 @@ Gets a list of roles done by the class of this object.
.sub 'roles' :method
.param pmc obj
.param pmc local :named('local') :optional
.param pmc tree :named('tree') :optional

# Transform false values to nulls.
if null local goto local_setup
if local goto local_setup
local = null
local_setup:
if null tree goto tree_setup
if tree goto tree_setup
tree = null
tree_setup:

# Create result list.
.local pmc result_list
Expand All @@ -338,22 +349,35 @@ Gets a list of roles done by the class of this object.

# Get list of parents whose roles we are interested in, and put
# us on the start. With the local flag, that's just us.
.local pmc parents, parents_it, cur_class
.local pmc parents, parents_it, cur_class, us
unless null tree goto do_tree
if null local goto all_parents
unless local goto all_parents
parents = get_root_global [.RAKUDO_HLL], 'Array'
parents = parents.'new'()
goto parents_list_made
all_parents:
parents = self.'parents'(obj)
goto parents_list_made
do_tree:
parents = self.'parents'(obj, 'local'=>1)
parents_list_made:
$P0 = obj.'WHAT'()
parents.'unshift'($P0)
us = obj.'WHAT'()
parents.'unshift'(us)
parents_it = iter parents
parents_it_loop:
unless parents_it goto done
cur_class = shift parents_it

# If it's us, disregard :tree. Otherwise, if we have :tree, now we call
# ourself recursively and push an array onto the result.
if null tree goto tree_handled
eq_addr cur_class, us, tree_handled
$P0 = self.'roles'(cur_class, 'tree'=>tree)
$P0 = new 'Perl6Scalar', $P0
result_list.'push'($P0)
goto parents_it_loop
tree_handled:

# Get Parrot-level class.
.local pmc parrot_class, roles, role_it, cur_role
parrot_class = self.'get_parrotclass'(cur_class)
Expand Down

0 comments on commit c4f0a93

Please sign in to comment.