|
From: <da...@us...> - 2003-08-03 06:29:14
|
Update of /cvsroot/binaryphp/binaryphp
In directory sc8-pr-cvs1:/tmp/cvs-serv22129
Modified Files:
convert.php functions.php php_var.cpp tokenflow.php
Log Message:
Fixed numerous bugs in tokenflow.php. Implimented globals. Split some functions into subdirectories.
Index: convert.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/convert.php,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** convert.php 2 Aug 2003 04:05:53 -0000 1.14
--- convert.php 3 Aug 2003 06:29:12 -0000 1.15
***************
*** 8,12 ****
require_once 'functions.php';
$tokenizer = new Tokenizer();
! $tokenizer->Parse('testfile.php');
$tokenizer->Strip();
$gen = new Generator($tokenizer);
--- 8,12 ----
require_once 'functions.php';
$tokenizer = new Tokenizer();
! $tokenizer->Parse('testfile2.php');
$tokenizer->Strip();
$gen = new Generator($tokenizer);
Index: functions.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/functions.php,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** functions.php 2 Aug 2003 04:23:48 -0000 1.32
--- functions.php 3 Aug 2003 06:29:12 -0000 1.33
***************
*** 1,5 ****
<?php
! $funcs = array('strlen' => array(null, 'strlen.cpp'),
! 'array' => array(null, 'array.cpp'),
'is_null' => array(null, 'is_null.cpp'),
'is_string' => array(null, 'is_string.cpp'),
--- 1,5 ----
<?php
! $funcs = array('strlen' => array(null, 'string/strlen.cpp'),
! 'array' => array(null, 'arrays/array.cpp'),
'is_null' => array(null, 'is_null.cpp'),
'is_string' => array(null, 'is_string.cpp'),
***************
*** 9,28 ****
'count' => array(null, 'count.cpp'),
'error_reporting' => array(null, 'error_reporting.cpp'),
! 'substr' => array(null, 'substr.cpp'),
! 'unlink' => array('stdio.h', 'unlink.cpp'),
! 'strtolower' => array('stdio.h', 'strtolower.cpp'),
'explode' => array(null, array('array.cpp', 'explode.cpp')),
'implode' => array(null, 'implode.cpp'),
! 'fopen' => array('cstdio', 'fopen.cpp'),
! 'fread' => array('cstdio', 'fread.cpp'),
'is_resource' => array(null, 'is_resource.cpp'),
! 'file_get_contents' => array('stdio.h', 'file_get_contents.cpp'),
'file' => array('stdio.h', array('array.cpp', 'explode.cpp', 'count.cpp', 'file.cpp')),
! 'strstr' => array(null, 'strstr.cpp'),
! 'strpos' => array(null, 'strpos.cpp'),
! 'str_replace' => array(null, 'str_replace.cpp'),
! 'str_repeat' => array(null, 'str_repeat.cpp'),
! 'fclose' => array('cstdio', 'fclose.cpp'),
! 'fwrite' => array('cstdio', 'fwrite.cpp'),
'array_reverse' => array(null, 'array_reverse'),
'in_array' => array(null, 'in_array.cpp'),
--- 9,28 ----
'count' => array(null, 'count.cpp'),
'error_reporting' => array(null, 'error_reporting.cpp'),
! 'substr' => array(null, 'string/substr.cpp'),
! 'unlink' => array('stdio.h', 'io/unlink.cpp'),
! 'strtolower' => array('stdio.h', 'string/strtolower.cpp'),
'explode' => array(null, array('array.cpp', 'explode.cpp')),
'implode' => array(null, 'implode.cpp'),
! 'fopen' => array('cstdio', 'io/fopen.cpp'),
! 'fread' => array('cstdio', 'io/fread.cpp'),
'is_resource' => array(null, 'is_resource.cpp'),
! 'file_get_contents' => array('stdio.h', 'io/file_get_contents.cpp'),
'file' => array('stdio.h', array('array.cpp', 'explode.cpp', 'count.cpp', 'file.cpp')),
! 'strstr' => array(null, 'string/strstr.cpp'),
! 'strpos' => array(null, 'string/strpos.cpp'),
! 'str_replace' => array(null, 'string/str_replace.cpp'),
! 'str_repeat' => array(null, 'string/str_repeat.cpp'),
! 'fclose' => array('cstdio', 'io/fclose.cpp'),
! 'fwrite' => array('cstdio', 'io/fwrite.cpp'),
'array_reverse' => array(null, 'array_reverse'),
'in_array' => array(null, 'in_array.cpp'),
***************
*** 33,39 ****
'token_name' => array(null, 'token_name.cpp'),
'token_get_all' => array(null, 'token_get_all.cpp'),
! 'touch' => array(null, 'touch.cpp'),
'ksort' => array(null, 'ksort.cpp'),
! 'stristr' => array('stdio.h', array('strtolower.cpp', 'stristr.cpp')),
'ucwords' => array('stdio.h', array('array.cpp', 'explode.cpp', 'implode.cpp', 'ucwords.cpp')),
'ucfirst' => array('cstdio', 'ucfirst.cpp'),
--- 33,39 ----
'token_name' => array(null, 'token_name.cpp'),
'token_get_all' => array(null, 'token_get_all.cpp'),
! 'touch' => array(null, 'io/touch.cpp'),
'ksort' => array(null, 'ksort.cpp'),
! 'stristr' => array('stdio.h', array('string/strtolower.cpp', 'string/stristr.cpp')),
'ucwords' => array('stdio.h', array('array.cpp', 'explode.cpp', 'implode.cpp', 'ucwords.cpp')),
'ucfirst' => array('cstdio', 'ucfirst.cpp'),
Index: php_var.cpp
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/php_var.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** php_var.cpp 2 Aug 2003 04:23:48 -0000 1.18
--- php_var.cpp 3 Aug 2003 06:29:12 -0000 1.19
***************
*** 14,21 ****
char* intstring(long i)
{
! char *buf = new char[5];
sprintf(buf, "%i", i);
return buf;
}
class php_var
--- 14,27 ----
char* intstring(long i)
{
! char *buf = new char[11];
sprintf(buf, "%i", i);
return buf;
}
+ char* doublestring(double i)
+ {
+ char *buf = new char[16];
+ sprintf(buf, "%d", i);
+ return buf;
+ }
class php_var
***************
*** 27,36 ****
container = "";
}
- /* php_var(void *ptr)
- {
- res = ptr;
- type = PHP_OBJECT;
- obj_type = &test;
- } */
php_var(const char* str)
{
--- 33,36 ----
***************
*** 38,41 ****
--- 38,46 ----
type = PHP_STRING;
}
+ php_var(double i)
+ {
+ type = PHP_INT;
+ container = doublestring(i);
+ }
php_var(int i)
{
***************
*** 99,102 ****
--- 104,111 ----
return false;
}
+ operator double()
+ {
+ return atof(container.c_str());
+ }
operator int()
{
***************
*** 383,390 ****
}
}
! // test* operator->()
! // {
! // return (test *) res;
! // }
friend ostream &operator<<( ostream &out, const php_var &var );
void to_array()
--- 392,405 ----
}
}
! void operator/(php_var i)
! {
! if(type == PHP_INT)
! container = doublestring(atof(container.c_str()) / atof(i.container.c_str()));
! }
! void operator-(php_var i)
! {
! if(type == PHP_INT)
! container = doublestring(atof(container.c_str()) - atof(i.container.c_str()));
! }
friend ostream &operator<<( ostream &out, const php_var &var );
void to_array()
Index: tokenflow.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/tokenflow.php,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** tokenflow.php 2 Aug 2003 04:05:53 -0000 1.44
--- tokenflow.php 3 Aug 2003 06:29:12 -0000 1.45
***************
*** 11,15 ****
var $namespace;
var $tabs = 0;
! var $scope = array(array());
var $funccount = 1;
var $inclass = false;
--- 11,15 ----
var $namespace;
var $tabs = 0;
! var $scope = array();
var $funccount = 1;
var $inclass = false;
***************
*** 23,26 ****
--- 23,27 ----
var $switched = array();
var $libs = array();
+ var $globals = array();
function Generator($tokenizer)
{
***************
*** 36,39 ****
--- 37,46 ----
for($a = 0; $a < count($tokenizer->tokens); ++$a)
{
+ if(is_array($tokenizer->tokens[$a]) && $tokenizer->tokens[$a][0] == T_GLOBAL && !in_array('_' . substr($tokenizer->tokens[$a + 1][1], 1), $this->globals))
+ $this->globals[] = '_' . substr($tokenizer->tokens[$a + 1][1], 1);
+ }
+ $this->scope[] = $this->globals;
+ for($a = 0; $a < count($tokenizer->tokens); ++$a)
+ {
if(is_array($tokenizer->tokens[$a]))
list($token, $data) = $tokenizer->tokens[$a];
***************
*** 82,91 ****
{
--$this->tabs;
- // if($temptabs == 2)
- // $this->AddCode('}');
$temptabs = false;
}
$a = $z - 1;
break;
case T_FUNCTION:
break;
--- 89,100 ----
{
--$this->tabs;
$temptabs = false;
}
$a = $z - 1;
break;
+ case T_GLOBAL:
+ $this->scope[$this->curfunction][] = substr($tokenizer->tokens[$a + 1][1], 1);
+ $a += 3;
+ break;
case T_FUNCTION:
break;
***************
*** 104,108 ****
$this->prototypes[$data] = array('void', $params);
$this->code[$data] = array();
! $a = $z;
}
elseif(is_array($tokenizer->tokens[$a - 1]) && $tokenizer->tokens[$a - 1][0] == T_CLASS)
--- 113,118 ----
$this->prototypes[$data] = array('void', $params);
$this->code[$data] = array();
! $a = $z + 1;
! // ++$this->tabs;
}
elseif(is_array($tokenizer->tokens[$a - 1]) && $tokenizer->tokens[$a - 1][0] == T_CLASS)
***************
*** 116,121 ****
{
list($statement, $z) = $this->parse_function($tokenizer, $a);
! $this->AddCode($statement . ';');
$a = $z;
}
break;
--- 126,139 ----
{
list($statement, $z) = $this->parse_function($tokenizer, $a);
! if($statement != NULL)
! $this->AddCode($statement . ';');
$a = $z;
+ if($temptabs != false)
+ {
+ --$this->tabs;
+ // if($temptabs == 2)
+ // $this->AddCode('}');
+ $temptabs = false;
+ }
}
break;
***************
*** 309,312 ****
--- 327,331 ----
break;
case '}':
+ echo $this->functions[$this->curfunction], ' - ', $this->tabs, "\n";
if($this->tabs == 0)
{
***************
*** 316,321 ****
$this->curfunction = 0;
}
! elseif($this->tabs == 1 && $this->inclass)
$this->curfunction = 0;
else
{
--- 335,343 ----
$this->curfunction = 0;
}
! elseif(($this->tabs == 1 && $this->inclass) || ($this->tabs < 0 && $this->curfunction > 0))
! {
$this->curfunction = 0;
+ $this->tabs = 0;
+ }
else
{
***************
*** 329,332 ****
--- 351,356 ----
else
$this->AddCode('}');
+ if($this->tabs == 0 && $this->curfunction > 0)
+ $this->curfunction = 0;
}
break;
***************
*** 393,396 ****
--- 417,421 ----
$parameters[count($parameters) - 1] = $parameters[count($parameters) - 1];
break;
+ case T_DNUMBER:
case T_LNUMBER:
if($tokenizer->tokens[$token_][0] == T_ARRAY && count($parameters) % 2 == 0 && (is_array($tokenizer->tokens[$i + 1]) && $tokenizer->tokens[$i + 1][1] != '=>'))
***************
*** 414,418 ****
}
}
! if($tokenizer->tokens[$i] == ';')
--$i;
if($tokenizer->tokens[$token_][0] == T_ARRAY)
--- 439,445 ----
}
}
! if(strtolower($funcname) == 'define')
! ++$i;
! elseif($tokenizer->tokens[$i] == ';')
--$i;
if($tokenizer->tokens[$token_][0] == T_ARRAY)
***************
*** 544,547 ****
--- 571,575 ----
$code .= '"' . str_replace('"', '\\"', substr($data_, 1, -1) ). '"';
break;
+ case T_DNUMBER:
case T_LNUMBER:
$code .= $data_;
***************
*** 603,606 ****
--- 631,642 ----
$code .= ' + ';
break;
+ case '%':
+ $code .= ' % ';
+ break;
+ case '/':
+ $code .= ' / ';
+ break;
+ default:
+ break;
}
}
***************
*** 623,627 ****
if($function === null)
$function = $this->curfunction;
! $this->code[$this->functions[$function]][] = str_repeat("\t", $this->tabs) . $line;
}
function Convert()
--- 659,666 ----
if($function === null)
$function = $this->curfunction;
! if($this->tabs > 0)
! $this->code[$this->functions[$function]][] = str_repeat("\t", $this->tabs) . $line;
! else
! $this->code[$this->functions[$function]][] = $line;
}
function Convert()
***************
*** 659,662 ****
--- 698,703 ----
}
}
+ foreach($this->globals as $glob)
+ $code .= 'php_var ' . $glob . ';' . "\n";
foreach($this->defines as $def => $val)
$code .= '#define ' . $def . ' ' . $val . "\n";
|