Author: bernhard
Date: Fri Dec 26 11:29:12 2008
New Revision: 34397
Modified:
trunk/languages/pipp/src/pct/actions.pm
trunk/languages/pipp/src/pct/grammar.pg
trunk/languages/pipp/t/php/oo.t
Log:
[Pipp] scalars and arrays are now always 'lexical'.
TODO some OO tests, as some lexicals end up in the wrong block.
Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm (original)
+++ trunk/languages/pipp/src/pct/actions.pm Fri Dec 26 11:29:12 2008
@@ -372,23 +372,19 @@
method array_elem($/) {
our $?BLOCK;
-
- my $isdecl;
- if $?BLOCK.symbol( ~$/ ) {
- # symbol is already present
- $isdecl := 0;
- }
- else {
- $isdecl := 1;
- $?BLOCK.symbol(
- ~$/,
- :scope('package')
+ unless $?BLOCK.symbol( ~$<VAR_NAME> ) {
+ $?BLOCK.symbol( ~$<VAR_NAME>, :scope('lexical') );
+ $?BLOCK.push(
+ PAST::Var.new(
+ :name(~$<VAR_NAME>),
+ :viviself('PhpArray'),
+ :isdecl(1)
+ )
);
}
my $past_var_name :=
PAST::Var.new(
- :scope('package'),
:name(~$<VAR_NAME>),
:viviself('PhpArray'),
:lvalue(1),
@@ -404,24 +400,19 @@
}
method simple_var($/) {
- our $?PIPP_CURRENT_SCOPE;
our $?BLOCK;
-
- my $isdecl;
- if $?BLOCK.symbol( ~$/ ) {
- # symbol is already present
- $isdecl := 0;
- }
- else {
- $isdecl := 1;
- $?BLOCK.symbol(
- ~$<VAR_NAME>,
- :scope( $?PIPP_CURRENT_SCOPE ?? $?PIPP_CURRENT_SCOPE !! 'package' )
+ unless $?BLOCK.symbol( ~$<VAR_NAME> ) {
+ $?BLOCK.symbol( ~$<VAR_NAME>, :scope('lexical') );
+ $?BLOCK.push(
+ PAST::Var.new(
+ :name(~$<VAR_NAME>),
+ :viviself('PhpNull'),
+ :isdecl(1)
+ )
);
}
make PAST::Var.new(
- :scope( $?PIPP_CURRENT_SCOPE ?? $?PIPP_CURRENT_SCOPE !! 'package'
),
:name(~$<VAR_NAME>),
:viviself('PhpNull'),
:lvalue(1),
@@ -544,31 +535,16 @@
@?BLOCK.unshift($?BLOCK);
}
else {
- # PHP has two scopes: local to functions and global
- our $?PIPP_CURRENT_SCOPE := 'lexical';
-
my $past := @?BLOCK.shift();
$past.name( ~$<FUNCTION_NAME> );
$past.control('return_pir');
$past.push( $( $<block> ) );
- $?PIPP_CURRENT_SCOPE := '';
-
make $past;
}
}
-# nested functions are not supported yet
-method ENTER_FUNCTION_DEF($/) {
- our $?PIPP_CURRENT_SCOPE;
- $?PIPP_CURRENT_SCOPE := 'lexical';
-}
-method EXIT_FUNCTION_DEF($/) {
- our $?PIPP_CURRENT_SCOPE;
- $?PIPP_CURRENT_SCOPE := 'package';
-}
-
method class_method_definition($/, $key) {
our @?BLOCK; # A stack of PAST::Block
our $?BLOCK; # The current block. Used for managing the symbol table.
@@ -598,21 +574,6 @@
);
my $arity := 0;
for $<VAR_NAME> {
- our $?BLOCK;
-
- my $isdecl;
- if $?BLOCK.symbol( ~$_ ) {
- # symbol is already present
- $isdecl := 0;
- }
- else {
- $isdecl := 1;
- $?BLOCK.symbol(
- ~$_,
- :scope('parameter')
- );
- }
-
my $param :=
PAST::Var.new(
:scope('parameter'),
@@ -621,13 +582,6 @@
:lvalue(1),
);
$past.push($param);
-
- # enter the parameter as a lexical into the block's symbol table
- # TODO: lexical by default
- $past.symbol(
- :scope('lexical'),
- $param.name()
- );
$arity++;
}
$past.arity( $arity );
Modified: trunk/languages/pipp/src/pct/grammar.pg
==============================================================================
--- trunk/languages/pipp/src/pct/grammar.pg (original)
+++ trunk/languages/pipp/src/pct/grammar.pg Fri Dec 26 11:29:12 2008
@@ -388,21 +388,10 @@
# declarations
rule function_definition {
- 'function' <FUNCTION_NAME> <.ENTER_FUNCTION_DEF> <param_list>
+ 'function' <FUNCTION_NAME> <param_list>
{*} #= open
<block>
{*} #= close
- <.EXIT_FUNCTION_DEF>
-}
-
-# special subrule for marking variable scope
-token ENTER_FUNCTION_DEF {
- {*}
-}
-
-# ditto
-token EXIT_FUNCTION_DEF {
- {*}
}
rule param_list {
Modified: trunk/languages/pipp/t/php/oo.t
==============================================================================
--- trunk/languages/pipp/t/php/oo.t (original)
+++ trunk/languages/pipp/t/php/oo.t Fri Dec 26 11:29:12 2008
@@ -54,7 +54,7 @@
constant bar in class Foo
OUT
-language_output_is( 'Pipp', <<'CODE', <<'OUT', 'calling an instance method' );
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'calling an instance method',
todo => '$dings declared in wrong block' );
<?php
class Dings {
@@ -72,7 +72,7 @@
The function bums() in class Dings has been called.
OUT
-language_output_is( 'Pipp', <<'CODE', <<'OUT', 'class with a public member' );
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'class with a public member',
todo => '$dings declared in wrong block' );
<?php
class Dings {
@@ -92,7 +92,7 @@
OUT
-language_output_is( 'Pipp', <<'CODE', <<'OUT', 'calling a method within a
method' );
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'calling a method within a
method', todo => '$dings declared in wrong block' );
<?php
class Foo {