Skip to content

Commit

Permalink
Implement .rw and .readonly for attribute introspection.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jul 29, 2009
1 parent c4f0a93 commit a48b31a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/classes/ClassHOW.pir
Expand Up @@ -165,7 +165,14 @@ Attribute descriptors.
$P3 = get_root_global [.RAKUDO_HLL], 'prefix:?'
$P2 = $P3($P2)

cur_attr_info = attr_proto.'new'('name' => $S0, 'type' => $P0, 'build' => $P1, 'accessor' => $P2)
# rw
$P4 = cur_attr_hash['rw']
unless null $P4 goto rw_done
$P4 = box 0
rw_done:
$P4 = $P3($P4)

cur_attr_info = attr_proto.'new'('name' => $S0, 'type' => $P0, 'build' => $P1, 'accessor' => $P2, 'rw' => $P4)
result_list.'push'(cur_attr_info)
goto attr_it_loop
attr_it_loop_end:
Expand Down
6 changes: 5 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -1701,6 +1701,7 @@ method scope_declarator($/) {

# If the var has a '.' twigil, we need to create an
# accessor method for it in the block (class/grammar/role)
my $readtype;
if $var<twigil> eq '.' {
my $method := PAST::Block.new( :blocktype('method') );
if $var<sigil> eq '&' {
Expand All @@ -1710,7 +1711,7 @@ method scope_declarator($/) {
}
my $value := PAST::Var.new( :name($var.name()) );
my $default_readtype := package_has_trait('rw') ?? 'rw' !! 'readonly';
my $readtype := trait_readtype( $var<traitlist> ) || $default_readtype;
$readtype := trait_readtype( $var<traitlist> ) || $default_readtype;
if $readtype eq 'CONFLICT' {
$<scoped>.panic(
"Can use only one of readonly, rw, and copy on "
Expand Down Expand Up @@ -1756,6 +1757,9 @@ method scope_declarator($/) {
if $var<twigil> eq '.' {
$has.push(PAST::Val.new( :value(1), :named('accessor') ));
}
if $readtype eq 'rw' {
$has.push(PAST::Val.new( :value(1), :named('rw') ));
}
if $var<traitlist> {
# If we have a handles, then we pass that specially.
my $handles := has_compiler_trait($var<traitlist>, 'trait_mod:handles');
Expand Down
2 changes: 2 additions & 0 deletions src/setting/Attribute.pm
Expand Up @@ -3,6 +3,8 @@ class Attribute {
has $.type;
has $.build;
has $.accessor;
has $.rw;
method readonly() { !$!rw }
}

# vim: ft=perl6

0 comments on commit a48b31a

Please sign in to comment.