|
From: <da...@us...> - 2003-08-10 01:42:57
|
Update of /cvsroot/binaryphp/binaryphp
In directory sc8-pr-cvs1:/tmp/cvs-serv21173
Modified Files:
tokenflow.php
Log Message:
For and If support.
Index: tokenflow.php
===================================================================
RCS file: /cvsroot/binaryphp/binaryphp/tokenflow.php,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** tokenflow.php 9 Aug 2003 05:57:12 -0000 1.54
--- tokenflow.php 10 Aug 2003 01:42:54 -0000 1.55
***************
*** 78,81 ****
--- 78,93 ----
var $includes = array();
/**
+ * An array of C++ includes.
+ * @param array
+ * @access public
+ */
+ var $cppincludes = array();
+ /**
+ * An array of libraries.
+ * @param array
+ * @access public
+ */
+ var $libs = array();
+ /**
* Variable scope
* @param array
***************
*** 94,100 ****
$this->curfunction = 0;
$this->tokens = $tokenizer->tokens;
- $this->Parse_Tokenstream();
$this->functions[0] = array('main', 'int', array(array('int', 'argc'), array('char**', 'argv')));
- $this->scope[0] = array();
/*
* First element of each array in the functions array is the name of the function.
--- 106,110 ----
***************
*** 102,105 ****
--- 112,117 ----
* The third argument is an array of arguments in the form array(type, name).
*/
+ $this->scope[0] = array();
+ $this->Parse_Tokenstream();
}
/**
***************
*** 141,145 ****
case T_ECHO:
++$this->token;
! if($begin == null && $end == null)
$this->B_echo($this->Parse_Tokenstream(',', ';'), true);
else
--- 153,157 ----
case T_ECHO:
++$this->token;
! if($break == null && $end == null)
$this->B_echo($this->Parse_Tokenstream(',', ';'), true);
else
***************
*** 156,172 ****
break;
case T_VARIABLE:
! if($break == null && $end == null)
! {
! if($begin == null && $end == null)
! $this->B_variable($this->Parse_Tokenstream('=', ';'), true);
! else
! $code .= $this->B_variable($this->Parse_Tokenstream('=', ';'));
! }
! else
! {
! if($this->Define($data))
! $code .= 'php_var ';
! $code .= '_' . substr($data, 1);
! }
break;
case T_LNUMBER:
--- 168,174 ----
break;
case T_VARIABLE:
! if($this->Define($data))
! $code .= 'php_var ';
! $code .= '_' . substr($data, 1);
break;
case T_LNUMBER:
***************
*** 178,189 ****
{
++$this->token;
! if($begin == null && $end == null)
! $this->B_function($data, $this->Parse_Tokenstream(',', ')'), true);
else
! $code .= $this->B_function($data, $this->Parse_Tokenstream(',', ')'));
}
else
$code .= $data;
break;
case '-':
case '+':
--- 180,205 ----
{
++$this->token;
! if($break == null && $end == null)
! $this->B_function_call($data, $this->Parse_Tokenstream(',', ')'), true);
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_FOR:
+ ++$this->token;
+ if($break == null && $end == null)
+ $this->B_for($this->Parse_Tokenstream(';', ')'), true);
+ else
+ $code .= $this->B_for($this->Parse_Tokenstream(';', ')'));
+ break;
case '-':
case '+':
***************
*** 193,202 ****
--- 209,226 ----
case '&':
case '|':
+ case '%':
+ case '<':
+ case '=':
$code .= ' ' . $token . ' ';
break;
case T_BOOLEAN_AND:
case T_BOOLEAN_OR:
+ case T_IS_EQUAL:
$code .= ' ' . $data . ' ';
break;
+ case T_INC:
+ case T_DEC:
+ $code .= $data;
+ break;
}
}
***************
*** 248,252 ****
* Code generator for functions
*
! * @param string $function Name of the function.
* @param array $parameters Parameters to the function.
* @param bool $add Set to true to add the code to the source.
--- 272,276 ----
* 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.
***************
*** 254,263 ****
* @access private
*/
! function B_function($function, $parameters, $add = false)
{
$code = $function . '(' . implode(', ', $parameters);
if($add)
$this->AddCode($code);
! echo 'Bleh?', "\n";
return $code;
}
--- 278,335 ----
* @access private
*/
! function B_function_call($function, $parameters, $add = false)
{
+ global $funcs;
+ if(isset($funcs[$function]))
+ {
+ if(count($funcs[$function]) == 2)
+ {
+ list($inc, $cppinc) = $funcs[$function];
+ $lib = null;
+ }
+ else
+ list($inc, $cppinc, $lib) = $funcs[$function];
+ if($inc != null)
+ $this->AddInclude($inc);
+ if($cppinc != null)
+ $this->AddCPPInclude($cppinc);
+ if($lib != null)
+ $this->AddLib($lib);
+ }
$code = $function . '(' . implode(', ', $parameters);
if($add)
$this->AddCode($code);
! return $code;
! }
! /**
! * Code generator for IFs
! *
! * @param array $parameters Statement(s).
! * @param bool $add Set to true to add the code to the source.
! * @return string
! * @access private
! */
! function B_if($parameters, $add = false)
! {
! $code = 'if(' . $parameters[0];
! if($add)
! $this->AddCode($code);
! return $code;
! }
! /**
! * Code generator for FOR loops
! *
! * @param array $parameters Statement(s).
! * @param bool $add Set to true to add the code to the source.
! * @return string
! * @access private
! */
! function B_for($parameters, $add = false)
! {
! $code = 'for(' . $parameters[0] . '; ' . $parameters[1] . '; ' . $parameters[2];
! if(count($parameters) > 3)
! $code .= ')';
! if($add)
! $this->AddCode($code);
return $code;
}
***************
*** 283,288 ****
function AddInclude($inc)
{
! if(!in_array($inc, $this->includes))
! $this->includes[] = $inc;
}
/**
--- 355,406 ----
function AddInclude($inc)
{
! if(is_array($inc))
! {
! foreach($inc as $in)
! {
! if(!in_array($in, $this->includes))
! $this->includes[] = $in;
! }
! }
! elseif(!in_array($inc, $this->includes))
! $this->includes[] = $inc;
! }
! /**
! * Add a C++ include.
! *
! * @param string $inc Name of file to include.
! * @access public
! */
! function AddCPPInclude($inc)
! {
! if(is_array($inc))
! {
! foreach($inc as $in)
! {
! if(!in_array($in, $this->cppincludes))
! $this->cppincludes[] = $in;
! }
! }
! elseif(!in_array($inc, $this->cppincludes))
! $this->cppincludes[] = $inc;
! }
! /**
! * Add an include.
! *
! * @param string $inc Name of file to include.
! * @access public
! */
! function AddLib($inc)
! {
! if(is_array($inc))
! {
! foreach($inc as $in)
! {
! if(!in_array($in, $this->libs))
! $this->libs[] = $in;
! }
! }
! elseif(!in_array($inc, $this->libs))
! $this->libs[] = $inc;
}
/**
***************
*** 331,334 ****
--- 449,454 ----
$code .= 'using namespace ' . $this->namespace . ';' . "\n";
$code .= '#include "php_var.hpp"' . "\n";
+ foreach($this->cppincludes as $cpp)
+ $code .= implode(null, file('functions/' . $cpp)) . "\n\n";
foreach($this->code as $func => $arr)
{
***************
*** 344,348 ****
$code .= '}' . "\n";
}
! return array($code, (string) null);
}
}
--- 464,471 ----
$code .= '}' . "\n";
}
! $flags = (string) null;
! foreach($this->libs as $lib)
! $flags .= '-l' . $lib . ' ';
! return array($code, $flags);
}
}
|