|
From: <da...@us...> - 2003-08-14 17:11:11
|
Update of /cvsroot/binaryphp/binaryphp
In directory sc8-pr-cvs1:/tmp/cvs-serv23345
Modified Files:
php_var.cpp php_var.hpp testfile.php tokenflow.php
Log Message:
User-defined functions work.
Index: php_var.cpp
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/php_var.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** php_var.cpp 9 Aug 2003 03:58:34 -0000 1.26
--- php_var.cpp 14 Aug 2003 16:40:17 -0000 1.27
***************
*** 310,312 ****
--- 310,316 ----
return (float) *l / (float) *r;
}
+ php_var operator*(php_var l, php_var r)
+ {
+ return (php_var)((long) l - (long) r);
+ }
#define is_identical(var, varb) (((var) == (varb) && (var).type == (varb).type) ? (php_var)true : (php_var)false)
Index: php_var.hpp
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/php_var.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** php_var.hpp 14 Aug 2003 00:01:43 -0000 1.2
--- php_var.hpp 14 Aug 2003 16:40:17 -0000 1.3
***************
*** 86,89 ****
--- 86,90 ----
int type; // Contains current type.
};
+ php_var operator*(php_var l, php_var r);
#endif
Index: testfile.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/testfile.php,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** testfile.php 11 Aug 2003 11:17:21 -0000 1.47
--- testfile.php 14 Aug 2003 16:40:17 -0000 1.48
***************
*** 1,5 ****
<?php
! header('Location: http://google.com');
! header('Location: http://feetman.com');
! echo 'Test', "\n";
?>
--- 1,7 ----
<?php
! function bleh($foo)
! {
! echo 'Test?';
! }
! bleh('moo!');
?>
Index: tokenflow.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/tokenflow.php,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** tokenflow.php 11 Aug 2003 11:17:21 -0000 1.57
--- tokenflow.php 14 Aug 2003 16:40:17 -0000 1.58
***************
*** 95,98 ****
--- 95,116 ----
*/
var $scope = array();
+ /**
+ * Tab count
+ * @param int
+ * @access private
+ */
+ var $tabs;
+ /**
+ * Temporary tab count
+ * @param bool
+ * @access private
+ */
+ var $temptabs;
+ /**
+ * Array of the current hierarchy of encapsulating language constructs.
+ * @param array
+ * @access private
+ */
+ var $in = array();
/**
***************
*** 113,116 ****
--- 131,136 ----
*/
$this->scope[0] = array();
+ $this->tabs = 0;
+ $this->temptabs = 0;
$this->Parse_Tokenstream();
}
***************
*** 163,166 ****
--- 183,191 ----
case ';':
$code .= ';';
+ if($end == null && $break == null)
+ {
+ $this->AddCode($code);
+ $code = (string) null;
+ }
break;
case T_CONSTANT_ENCAPSED_STRING:
***************
*** 181,185 ****
--- 206,213 ----
++$this->token;
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(',', ')'));
***************
*** 195,198 ****
--- 223,239 ----
$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:
+ if($break == null && $end == null)
+ $this->B_else( true);
+ else
+ $code .= $this->B_else();
+ break;
case T_FOR:
++$this->token;
***************
*** 202,205 ****
--- 243,255 ----
$code .= $this->B_for($this->Parse_Tokenstream(';', ')'));
break;
+ case T_FUNCTION:
+ $data = $this->tokens[$this->token + 1][1];
+ $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;
case '-':
case '+':
***************
*** 224,229 ****
break;
case '{':
case '}':
! $this->AddCode($data);
break;
}
--- 274,302 ----
break;
case '{':
+ $this->AddCode('{');
+ ++$this->tabs;
+ break;
case '}':
! if(!isset($this->in[count($this->in) - 1]))
! {
! --$this->tabs;
! $this->AddCode('}');
! break;
! }
! switch($this->in[count($this->in) - 1])
! {
! case 'class':
! --$this->tabs;
! $this->AddCode('};');
! break;
! case 'function':
! $this->curfunction = 0;
! break;
! default:
! --$this->tabs;
! $this->AddCode('}');
! break;
! }
! unset($this->in[count($this->in) - 1]);
break;
}
***************
*** 253,257 ****
$code .= ' << ' . $param;
}
- $code .= ';';
if($add)
$this->AddCode($code);
--- 326,329 ----
***************
*** 259,280 ****
}
/**
! * Code generator for variables
*
! * @param array $parameters Things to echo.
* @param bool $add Set to true to add the code to the source.
* @return string
* @access private
*/
! function B_variable($parameters, $add = false)
{
! $code = implode(' = ', $parameters);
! if($add)
! $this->AddCode($code);
! return $code;
}
/**
! * Code generator for functions
*
! * @param string $function Name of the function calls.
* @param array $parameters Parameters to the function.
* @param bool $add Set to true to add the code to the source.
--- 331,357 ----
}
/**
! * Code generator for function definitions.
*
! * @param string $function Name of the function being defined.
! * @param array $parameters Parameters to the function.
* @param bool $add Set to true to add the code to the source.
* @return string
* @access private
*/
! function B_function($function, $params)
{
! $params[count($params) - 1] = substr($params[count($params) - 1], 0, -1);
! $this->curfunction = count($this->functions);
! $func = array($function, 'void', array());
! foreach($params as $param)
! $func[2][] = array('php_var', substr($param, 8));
! $this->functions[$this->curfunction] = $func;
! $this->scops[$this->curfunction] = array();
! $this->in[] = 'function';
}
/**
! * Code generator for function calls
*
! * @param string $function Name of the function being called.
* @param array $parameters Parameters to the function.
* @param bool $add Set to true to add the code to the source.
***************
*** 307,311 ****
$code = $function . '(' . implode(', ', $parameters);
if($add)
! $this->AddCode($code);
return $code;
}
--- 384,388 ----
$code = $function . '(' . implode(', ', $parameters);
if($add)
! $this->AddCode($code . ';');
return $code;
}
***************
*** 323,326 ****
--- 400,447 ----
if($add)
$this->AddCode($code);
+ if($this->tokens[$this->token + 1][0] != '{')
+ {
+ ++$this->tabs;
+ ++$this->temptabs;
+ }
+ return $code;
+ }
+ /**
+ * Code generator for ELSEIFs
+ *
+ * @param array $parameters Statement(s).
+ * @param bool $add Set to true to add the code to the source.
+ * @return string
+ * @access private
+ */
+ function B_elseif($parameters, $add = false)
+ {
+ $code = 'else if(' . $parameters[0];
+ if($add)
+ $this->AddCode($code);
+ if($this->tokens[$this->token + 1][0] != '{')
+ {
+ ++$this->tabs;
+ ++$this->temptabs;
+ }
+ return $code;
+ }
+ /**
+ * Code generator for ELSEs
+ *
+ * @param bool $add Set to true to add the code to the source.
+ * @return string
+ * @access private
+ */
+ function B_else($add = false)
+ {
+ $code = 'else';
+ if($add)
+ $this->AddCode($code);
+ if($this->tokens[$this->token + 1][0] != '{')
+ {
+ ++$this->tabs;
+ ++$this->temptabs;
+ }
return $code;
}
***************
*** 340,343 ****
--- 461,469 ----
if($add)
$this->AddCode($code);
+ if($this->tokens[$this->token + 1][0] != '{')
+ {
+ ++$this->tabs;
+ ++$this->temptabs;
+ }
return $code;
}
***************
*** 377,381 ****
if($function == null)
$function = $this->curfunction;
! $this->code[$function][] = $code;
}
/**
--- 503,512 ----
if($function == null)
$function = $this->curfunction;
! $this->code[$function][] = str_repeat("\t", $this->tabs + 1) . $code;
! if($this->temptabs > 0)
! {
! --$this->temptabs;
! --$this->tabs;
! }
}
/**
***************
*** 489,493 ****
$args2 = array();
foreach($args as $arg)
! $args2[] = $arg[0];
$code .= implode(', ', $args2) . ')' . "\n";
$code .= '{' . "\n";
--- 620,624 ----
$args2 = array();
foreach($args as $arg)
! $args2[] = $arg[0] . ' ' . $arg[1];
$code .= implode(', ', $args2) . ')' . "\n";
$code .= '{' . "\n";
|