|
From: <da...@us...> - 2003-11-21 12:36:47
|
Update of /cvsroot/binaryphp/binaryphp
In directory sc8-pr-cvs1:/tmp/cvs-serv15743
Modified Files:
convert.php php_var.cpp php_var.hpp testfile.php tokenflow.php
tokenizer.php
Log Message:
Fixed massive parser bug, implimented partial OOP support.
Index: convert.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/convert.php,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** convert.php 20 Sep 2003 17:10:12 -0000 1.25
--- convert.php 21 Nov 2003 12:36:43 -0000 1.26
***************
*** 1,3 ****
! #!/usr/bin/php
<?php
--- 1,3 ----
! #!/usr/local/bin/php
<?php
Index: php_var.cpp
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/php_var.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** php_var.cpp 25 Sep 2003 22:24:34 -0000 1.35
--- php_var.cpp 21 Nov 2003 12:36:43 -0000 1.36
***************
*** 70,73 ****
--- 70,78 ----
type = PHP_BOOL;
}
+ php_var::php_var(void *bleh)
+ {
+ obj = bleh;
+ type = PHP_OBJECT;
+ }
php_var::operator const char*()
{
Index: php_var.hpp
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/php_var.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** php_var.hpp 25 Sep 2003 22:24:34 -0000 1.6
--- php_var.hpp 21 Nov 2003 12:36:43 -0000 1.7
***************
*** 17,91 ****
class php_var
{
! public:
! php_var(); // Constructor
! php_var(const char* str);
! php_var(double i);
! php_var(int i);
! php_var(unsigned int i);
! php_var(long i);
! php_var(const php_var &temp);
! php_var(char * str);
! php_var(string str);
! php_var(bool b);
!
! operator const char*();
! operator string();
! operator bool();
! operator double();
! operator float();
! operator int();
! operator unsigned int();
! operator long();
!
! php_var &operator[](int subscript);
! php_var &operator[](unsigned int subscript);
! php_var &operator[](const char* subscript);
! php_var &operator[](char* subscript);
! php_var &operator[](string subscript);
! php_var &operator[](php_var subscript);
!
! bool operator<(int i);
! bool operator>(int i);
! bool operator<(php_var i);
! bool operator>(php_var i);
! bool operator!=(const char* cmp);
! bool operator!=(int i);
! bool operator!=(php_var var);
! bool operator==(const char* cmp);
! bool operator==(int i);
! bool operator==(php_var var);
!
! int operator++(int i);
! int operator++();
! int operator--(int i);
! int operator--();
!
! php_var &operator=(const php_var &temp);
! php_var &operator=(int i);
! php_var &operator=(unsigned int i);
! php_var &operator=(long i);
! php_var &operator=(double d);
! php_var &operator=(char *str);
! php_var &operator=(string str);
! php_var &operator=(bool b);
!
! void operator+=(int inc);
! void operator+=(php_var str);
! void operator+=(string str);
! void operator+=(const char* str);
! void operator+=(char* str);
! void operator-=(int dec);
! void operator-=(php_var i);
! friend ostream &operator<<( ostream &out, const php_var &var );
! void to_array();
! string container; // Contains value.
! vector<php_var> keys;
! vector<php_var> data;
! void *res;
! void *obj_type;
! int res_type;
! php_var_type type; // Contains current type.
};
--- 17,92 ----
class php_var
{
! public:
! php_var(); // Constructor
! php_var(const char* str);
! php_var(double i);
! php_var(int i);
! php_var(unsigned int i);
! php_var(long i);
! php_var(const php_var &temp);
! php_var(char * str);
! php_var(string str);
! php_var(bool b);
! php_var(void *foo);
! operator const char*();
! operator string();
! operator bool();
! operator double();
! operator float();
! operator int();
! operator unsigned int();
! operator long();
!
! php_var &operator[](int subscript);
! php_var &operator[](unsigned int subscript);
! php_var &operator[](const char* subscript);
! php_var &operator[](char* subscript);
! php_var &operator[](string subscript);
! php_var &operator[](php_var subscript);
!
! bool operator<(int i);
! bool operator>(int i);
! bool operator<(php_var i);
! bool operator>(php_var i);
! bool operator!=(const char* cmp);
! bool operator!=(int i);
! bool operator!=(php_var var);
! bool operator==(const char* cmp);
! bool operator==(int i);
! bool operator==(php_var var);
!
! int operator++(int i);
! int operator++();
! int operator--(int i);
! int operator--();
!
! php_var &operator=(const php_var &temp);
! php_var &operator=(int i);
! php_var &operator=(unsigned int i);
! php_var &operator=(long i);
! php_var &operator=(double d);
! php_var &operator=(char *str);
! php_var &operator=(string str);
! php_var &operator=(bool b);
!
! void operator+=(int inc);
! void operator+=(php_var str);
! void operator+=(string str);
! void operator+=(const char* str);
! void operator+=(char* str);
! void operator-=(int dec);
! void operator-=(php_var i);
! friend ostream &operator<<( ostream &out, const php_var &var );
! void to_array();
!
! string container; // Contains value.
! vector<php_var> keys;
! vector<php_var> data;
! void *res;
! void *obj;
! int res_type;
! php_var_type type; // Contains current type.
};
***************
*** 96,98 ****
--- 97,100 ----
php_var operator*(php_var l, php_var r);
+ #define OBJECT(var, type) ((type) *) (var).obj
#endif
Index: testfile.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/testfile.php,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** testfile.php 31 Aug 2003 01:20:17 -0000 1.50
--- testfile.php 21 Nov 2003 12:36:43 -0000 1.51
***************
*** 1,4 ****
<?php
! $var = array('foo', 'bleh' => 'bar');
! echo $var['bleh'];
?>
--- 1,8 ----
<?php
! class foo
! {
! var $bar = 'bleh';
! }
! $moo = new foo();
! echo $moo->bar;
?>
Index: tokenflow.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/tokenflow.php,v
retrieving revision 1.61
retrieving revision 1.62
diff -C2 -d -r1.61 -r1.62
*** tokenflow.php 31 Aug 2003 01:20:17 -0000 1.61
--- tokenflow.php 21 Nov 2003 12:36:43 -0000 1.62
***************
*** 60,69 ****
var $curfunction;
/**
- * An array of each function name.
- * @param array
- * @access public
- */
- var $functions = array();
- /**
* Current namespace
* @param string
--- 60,63 ----
***************
*** 138,146 ****
* Parses the flow of tokens generated by the tokenizer.
*
! * @param mixed $end The token to stop parsing at. This can be a string literal, or an int corresponding to a token.
* @return array
* @access private
*/
! function Parse_Tokenstream($break = null, $end = null)
{
if($this->token >= count($this->tokens))
--- 132,142 ----
* Parses the flow of tokens generated by the tokenizer.
*
! * @param mixed $break What token to break parameters and move on from.
! * @param mixed $end The token to stop parsing at. This can be a string literal, or an int corresponding to a token.
! * @param bool $for If being called from a for.
* @return array
* @access private
*/
! function Parse_Tokenstream($break = null, $end = null, $for = false)
{
if($this->token >= count($this->tokens))
***************
*** 151,157 ****
{
list($token, $data) = $this->tokens[$this->token];
! if($end != null && $token == $end)
{
! if($this->token < count($this->tokens) - 2)
{
if($data == null)
--- 147,153 ----
{
list($token, $data) = $this->tokens[$this->token];
! if($end != null && ($token == $end || (is_array($end) && in_array($token, $end))))
{
! if(!$for && $this->token < count($this->tokens) - 2)
{
if($data == null)
***************
*** 160,166 ****
$code .= $data;
}
break;
}
! if($break != null && $token == $break)
{
$params[] = $code;
--- 156,164 ----
$code .= $data;
}
+ if($for)
+ --$this->token;
break;
}
! if($break != null && ($token == $break || (is_array($break) && in_array($token, $break))))
{
$params[] = $code;
***************
*** 170,179 ****
switch($token)
{
case T_ECHO:
++$this->token;
if($break == null && $end == null)
! $this->B_echo($this->Parse_Tokenstream(',', ';'), true);
else
! $code .= $this->B_echo($this->Parse_Tokenstream(',', ';'));
break;
case ',':
--- 168,183 ----
switch($token)
{
+ case T_CLASS:
+ ++$this->token;
+ $this->AddCode('class ' . $this->tokens[$this->token][1]);
+ $this->in[] = 'class';
+ break;
case T_ECHO:
++$this->token;
if($break == null && $end == null)
! $this->B_echo($this->Parse_Tokenstream(array('.', ','), ';', true), true);
else
! $code .= $this->B_echo($this->Parse_Tokenstream(array('.', ','), ';', true));
! ++$this->token;
break;
case ',':
***************
*** 194,200 ****
$this->token += 1;
if($break == null && $end == null)
! $this->B_var($data, $this->Parse_Tokenstream(null, ';'), true);
else
! $code .= $this->B_var($data, $this->Parse_Tokenstream(null, ';'));
break;
case T_LNUMBER:
--- 198,204 ----
$this->token += 1;
if($break == null && $end == null)
! $this->B_var($data, $this->Parse_Tokenstream(null, array(';', ')', ','), $for), true);
else
! $code .= $this->B_var($data, $this->Parse_Tokenstream(null, array(';', ')', ','), $for));
break;
case T_LNUMBER:
***************
*** 208,233 ****
if($break == null && $end == null)
{
! $this->B_function_call($data, $this->Parse_Tokenstream(',', ')'), true);
++$this->token;
}
else
! $code .= $this->B_function_call($data, $this->Parse_Tokenstream(',', ')'));
}
else
$code .= $data;
break;
case T_IF:
++$this->token;
if($break == null && $end == null)
! $this->B_if($this->Parse_Tokenstream(null, ')'), true);
else
! $code .= $this->B_if($this->Parse_Tokenstream(null, ')'));
break;
case T_ELSEIF:
++$this->token;
if($break == null && $end == null)
! $this->B_elseif($this->Parse_Tokenstream(null, ')'), true);
else
! $code .= $this->B_elseif($this->Parse_Tokenstream(null, ')'));
break;
case T_ELSE:
--- 212,243 ----
if($break == null && $end == null)
{
! $this->B_function_call($data, $this->Parse_Tokenstream(',', ')', $for), true);
++$this->token;
}
else
! $code .= $this->B_function_call($data, $this->Parse_Tokenstream(',', ')', $for));
}
else
$code .= $data;
break;
+ case T_NEW:
+ $code .= 'new ';
+ break;
+ case T_OBJECT_OPERATOR:
+ $code .= '->';
+ break;
case T_IF:
++$this->token;
if($break == null && $end == null)
! $this->B_if($this->Parse_Tokenstream(null, ')', $for), true);
else
! $code .= $this->B_if($this->Parse_Tokenstream(null, ')', $for));
break;
case T_ELSEIF:
++$this->token;
if($break == null && $end == null)
! $this->B_elseif($this->Parse_Tokenstream(null, ')', $for), true);
else
! $code .= $this->B_elseif($this->Parse_Tokenstream(null, ')', $for));
break;
case T_ELSE:
***************
*** 240,246 ****
++$this->token;
if($break == null && $end == null)
! $this->B_for($this->Parse_Tokenstream(';', ')'), true);
else
! $code .= $this->B_for($this->Parse_Tokenstream(';', ')'));
break;
case T_FUNCTION:
--- 250,256 ----
++$this->token;
if($break == null && $end == null)
! $this->B_for($this->Parse_Tokenstream(';', ')', true), true);
else
! $code .= $this->B_for($this->Parse_Tokenstream(';', ')', true));
break;
case T_FUNCTION:
***************
*** 248,254 ****
$this->token += 3;
if($break == null && $end == null)
! $this->B_function($data, $this->Parse_Tokenstream(',', ')'), true);
else
! $code .= $this->B_function($data, $this->Parse_Tokenstream(',', ')'));
++$this->token;
break;
--- 258,264 ----
$this->token += 3;
if($break == null && $end == null)
! $this->B_function($data, $this->Parse_Tokenstream(',', ')', $for), true);
else
! $code .= $this->B_function($data, $this->Parse_Tokenstream(',', ')', $for));
++$this->token;
break;
***************
*** 256,260 ****
$data = $this->tokens[$this->token + 1][1];
++$this->token;
! $code .= $this->B_array($this->Parse_Tokenstream(',', ')'));
break;
case '-':
--- 266,270 ----
$data = $this->tokens[$this->token + 1][1];
++$this->token;
! $code .= $this->B_array($this->Parse_Tokenstream(',', ')', $for));
break;
case '-':
***************
*** 323,338 ****
*
* @param string $var Variable name.
! * @param array $code Value of the variable.
* @param bool $add Set to true to add the code to the source.
* @return string
* @access private
*/
! function B_var($var, $code, $add = false)
{
$var = '_' . substr($var, 1);
if($this->Define($var))
! $code = 'php_var ' . $var . implode(' ', $code);
! else
! $code = $var . implode(' ', $code);
if($add)
$this->AddCode($code);
--- 333,351 ----
*
* @param string $var Variable name.
! * @param array $val Value of the variable.
* @param bool $add Set to true to add the code to the source.
* @return string
* @access private
*/
! function B_var($var, $val, $add = false)
{
$var = '_' . substr($var, 1);
if($this->Define($var))
! $code = 'php_var ';
! else
! $code = (string) null;
! if(substr($val[0], 0, 2) == '->')
! $var = 'OBJECT(' . $var . ', foo)';
! $code .= $var . implode(' ', $val);
if($add)
$this->AddCode($code);
***************
*** 355,359 ****
{
if($param == '"\n"')
! $code .= ' << endl;';
else
$code .= ' << ' . $param;
--- 368,372 ----
{
if($param == '"\n"')
! $code .= ' << endl';
else
$code .= ' << ' . $param;
***************
*** 517,526 ****
function B_for($parameters, $add = false)
{
! $code = 'for(' . $parameters[0] . '; ' . $parameters[1] . '; ' . $parameters[2];
! if(count($parameters) > 3)
! $code .= ')';
if($add)
$this->AddCode($code);
! if($this->tokens[$this->token + 1][0] != '{')
{
++$this->tabs;
--- 530,537 ----
function B_for($parameters, $add = false)
{
! $code = 'for(' . $parameters[0] . '; ' . $parameters[1] . '; ' . $parameters[2] . ')';
if($add)
$this->AddCode($code);
! if(isset($this->tokens[$this->token + 1][0]) && $this->tokens[$this->token + 1][0] != '{')
{
++$this->tabs;
***************
*** 548,554 ****
$code = 'cout << ' . substr($parameters[0], 0, -1);
if($this->current_header == $header_count)
! $code .= " << endl << endl;";
else
! $code .= " << endl;";
return $code;
}
--- 559,565 ----
$code = 'cout << ' . substr($parameters[0], 0, -1);
if($this->current_header == $header_count)
! $code .= ' << endl << endl;';
else
! $code .= ' << endl;';
return $code;
}
***************
*** 669,673 ****
$code = (string) null;
foreach($this->includes as $include)
! $code .= '#include <' . $include . '>' . "\n";
if(!empty($this->namespace))
$code .= 'using namespace ' . $this->namespace . ';' . "\n";
--- 680,689 ----
$code = (string) null;
foreach($this->includes as $include)
! {
! if(file_exists('functions/' . $include))
! $code .= '#include "functions/' . $include . '"' . "\n";
! else
! $code .= '#include <' . $include . '>' . "\n";
! }
if(!empty($this->namespace))
$code .= 'using namespace ' . $this->namespace . ';' . "\n";
Index: tokenizer.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/tokenizer.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** tokenizer.php 8 Aug 2003 05:10:53 -0000 1.2
--- tokenizer.php 21 Nov 2003 12:36:43 -0000 1.3
***************
*** 22,26 ****
function Strip()
{
! $strip = array(T_WHITESPACE, T_COMMENT, T_ML_COMMENT);
$tokens = array();
foreach($this->tokens as $token)
--- 22,26 ----
function Strip()
{
! $strip = array(T_WHITESPACE, T_COMMENT);
$tokens = array();
foreach($this->tokens as $token)
***************
*** 36,40 ****
{
if(is_array($token))
! print token_name((int) $token[0]) . ' -- \'' . $token[1] . '\'' . "\n";
}
}
--- 36,40 ----
{
if(is_array($token))
! echo token_name((int) $token[0]), ' -- \'', $token[1], '\'', "\n";
}
}
|