Author: bernhard
Date: Thu Dec 25 12:18:40 2008
New Revision: 34356
Modified:
trunk/languages/pipp/src/pct/actions.pm
trunk/languages/pipp/src/pct/grammar.pg
Log:
[Pipp] keep track of $?BLOCK and @?BLOCK for functions and methods
and class definitions
Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm (original)
+++ trunk/languages/pipp/src/pct/actions.pm Thu Dec 25 12:18:40 2008
@@ -478,22 +478,29 @@
);
}
-method function_definition($/) {
+method function_definition($/, $key) {
+ our @?BLOCK; # A stack of PAST::Block
+ our $?BLOCK; # The current block. Used for managing the symbol table.
- # PHP has two scopes: local to functions and global
- our $?PIPP_CURRENT_SCOPE := 'lexical';
+ if $key eq 'open' {
+ # note that $<param_list> creates a new PAST::Block.
+ my $?BLOCK := $( $<param_list> );
+ @?BLOCK.unshift($?BLOCK);
+ }
+ else {
+ # PHP has two scopes: local to functions and global
+ our $?PIPP_CURRENT_SCOPE := 'lexical';
- # note that $<param_list> creates a new PAST::Block.
- my $past := $( $<param_list> );
- # TODO: set $?BLOCK
+ my $past := @?BLOCK.shift();
- $past.name( ~$<FUNCTION_NAME> );
- $past.control('return_pir');
- $past.push( $( $<block> ) );
+ $past.name( ~$<FUNCTION_NAME> );
+ $past.control('return_pir');
+ $past.push( $( $<block> ) );
- $?PIPP_CURRENT_SCOPE := '';
+ $?PIPP_CURRENT_SCOPE := '';
- make $past;
+ make $past;
+ }
}
# nested functions are not supported yet
@@ -506,18 +513,25 @@
$?PIPP_CURRENT_SCOPE := 'package';
}
-method class_method_definition($/) {
+method class_method_definition($/, $key) {
+ our @?BLOCK; # A stack of PAST::Block
+ our $?BLOCK; # The current block. Used for managing the symbol table.
- # note that $<param_list> creates a new PAST::Block.
- my $past := $( $<param_list> );
- # TODO: set $?BLOCK
-
- $past.name( ~$<METHOD_NAME> );
- $past.blocktype( 'method' );
- $past.control('return_pir');
- $past.push( $( $<block> ) );
+ if $key eq 'open' {
+ # note that $<param_list> creates a new PAST::Block.
+ my $?BLOCK := $( $<param_list> );
+ @?BLOCK.unshift($?BLOCK);
+ }
+ else {
+ my $past := @?BLOCK.shift();
- make $past;
+ $past.name( ~$<METHOD_NAME> );
+ $past.blocktype( 'method' );
+ $past.control('return_pir');
+ $past.push( $( $<block> ) );
+
+ make $past;
+ }
}
method param_list($/) {
@@ -526,7 +540,6 @@
:blocktype('declaration'),
:node($/)
);
- # TODO: set $?BLOCK
my $arity := 0;
for $<VAR_NAME> {
my $param := $( $_ );
@@ -551,16 +564,14 @@
our $?BLOCK; # The current block. Used for managing the symbol table.
if $key eq 'open' {
- # TODO: set $?BLOCK
- }
- else {
- # TODO: put this into the 'if' branch
$?BLOCK := PAST::Block.new(
:node($/),
:blocktype('declaration'),
:pirflags( ':init :load' )
);
@?BLOCK.unshift($?BLOCK);
+ }
+ else {
my $past := @?BLOCK.shift();
$past.namespace( $<CLASS_NAME><ident> );
$past.push( PAST::Stmts.new(
@@ -578,7 +589,6 @@
$past.push( $($_) );
}
- # TODO: set $?BLOCK
my $methods_block := PAST::Block.new( :blocktype('immediate') );
for $<class_member_definition> {
$methods_block.symbol(
@@ -604,7 +614,6 @@
my $past;
if $key eq 'quote_regex' {
our $?NS;
- # TODO: set $?BLOCK
$past := PAST::Block.new(
$<quote_regex>,
:compiler('PGE::Perl6Regex'),
Modified: trunk/languages/pipp/src/pct/grammar.pg
==============================================================================
--- trunk/languages/pipp/src/pct/grammar.pg (original)
+++ trunk/languages/pipp/src/pct/grammar.pg Thu Dec 25 12:18:40 2008
@@ -7,10 +7,10 @@
# the starting rule
token TOP {
- {*} #= open
- <sea_or_code>*
- [ $ || <.panic: 'Syntax error'> ]
- {*} #= close
+ {*} #= open
+ <sea_or_code>*
+ [ $ || <.panic: 'Syntax error'> ]
+ {*} #= close
}
# Whitespace and comments
@@ -370,8 +370,11 @@
# declarations
rule function_definition {
- 'function' <FUNCTION_NAME> <.ENTER_FUNCTION_DEF> <param_list> <block>
<.EXIT_FUNCTION_DEF>
- {*}
+ 'function' <FUNCTION_NAME> <.ENTER_FUNCTION_DEF> <param_list>
+ {*} #= open
+ <block>
+ {*} #= close
+ <.EXIT_FUNCTION_DEF>
}
# special subrule for marking variable scope
@@ -404,8 +407,8 @@
}
rule class_definition {
- {*} #= open
'class' <CLASS_NAME> [ 'implements' <INTERFACE_NAME> ]? '{'
+ {*} #= open
<class_constant_definition>*
<class_member_definition>*
<class_method_definition>*
@@ -423,8 +426,10 @@
}
rule class_method_definition {
- 'function' <METHOD_NAME> <param_list> <block>
- {*}
+ 'function' <METHOD_NAME> <param_list>
+ {*} #= open
+ <block>
+ {*} #= close
}