Skip to content

Commit

Permalink
Change the way we detect state variable initialization to be more gen…
Browse files Browse the repository at this point in the history
…eral. Resolves both RT#67040 and RT#67058.
  • Loading branch information
jnthn committed Jun 30, 2009
1 parent 2ae07bd commit c4e546e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
42 changes: 22 additions & 20 deletions src/parser/actions.pm
Expand Up @@ -2526,6 +2526,28 @@ method EXPR($/, $key) {
if $key eq 'end' {
make $<expr>.ast;
}
elsif +@($/) == 2 && $/[0].ast<scopedecl> eq 'state' && $<top><lvalue> {
# State variables - only want to actually do an assignment if
# there is no value.
my $lhs := $/[0].ast;
my $rhs := $/[1].ast;
make PAST::Op.new(
:pasttype('unless'),
:node($/),
PAST::Op.new(
:pasttype('call'),
:name('!state_var_inited'),
$lhs.isa(PAST::Var) ?? $lhs.name() !! $lhs[0].name()
),
PAST::Op.new(
:pasttype('call'),
:name('infix:='),
:lvalue(1),
$lhs,
$rhs
)
);
}
elsif ~$type eq 'infix:=' {
my $lhs := $/[0].ast;
my $rhs := $/[1].ast;
Expand All @@ -2543,26 +2565,6 @@ method EXPR($/, $key) {
@?BLOCK[0][0].push($past);
$past := PAST::Stmts.new();
}
elsif $lhs<scopedecl> eq 'state' {
# State variables - only want to actually do an assignment if
# there is no value.
$past := PAST::Op.new(
:pasttype('unless'),
:node($/),
PAST::Op.new(
:pasttype('call'),
:name('!state_var_inited'),
$lhs.isa(PAST::Var) ?? $lhs.name() !! $lhs[0].name()
),
PAST::Op.new(
:pasttype('call'),
:name('infix:='),
:lvalue(1),
$lhs,
$rhs
)
);
}
elsif $lhs<scopedecl> eq 'constant' {
$lhs<constant_value_slot>.push($rhs);
$past := $lhs;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/grammar-oper.pg
Expand Up @@ -143,7 +143,7 @@ proto infix:<:=> is precedence('i=') is pasttype('bind') { ... }
proto infix:<::=> is equiv(infix:<:=>) { ... }
proto infix:<.=> is equiv(infix:<:=>) { ... }
proto infix:«=>» is equiv(infix:<:=>) { ... }
proto infix:<//=> is equiv(infix:<:=>) { ... }
proto infix:<//=> is equiv(infix:<:=>) is lvalue(1) { ... }
proto infix:<&&=> is equiv(infix:<:=>) { ... }
proto infix:<||=> is equiv(infix:<:=>) { ... }

Expand Down

0 comments on commit c4e546e

Please sign in to comment.