From: <da...@us...> - 2003-08-31 01:20:21
|
Update of /cvsroot/binaryphp/binaryphp In directory sc8-pr-cvs1:/tmp/cvs-serv17255 Modified Files: testfile.php tokenflow.php Log Message: Arrays fully work. Index: testfile.php =================================================================== RCS file: /cvsroot/binaryphp/binaryphp/testfile.php,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** testfile.php 16 Aug 2003 22:58:03 -0000 1.49 --- testfile.php 31 Aug 2003 01:20:17 -0000 1.50 *************** *** 1,7 **** <?php ! function bleh($foo) ! { ! _cpp('cout << _foo << endl;'); ! } ! bleh('moo!'); ?> --- 1,4 ---- <?php ! $var = array('foo', 'bleh' => 'bar'); ! echo $var['bleh']; ?> Index: tokenflow.php =================================================================== RCS file: /cvsroot/binaryphp/binaryphp/tokenflow.php,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** tokenflow.php 22 Aug 2003 03:46:46 -0000 1.60 --- tokenflow.php 31 Aug 2003 01:20:17 -0000 1.61 *************** *** 146,151 **** if($this->token >= count($this->tokens)) return false; ! $this->buffer = (string)null; ! $code = &$this->buffer; $params = array(); for(; $this->token < count($this->tokens); ++$this->token) --- 146,150 ---- if($this->token >= count($this->tokens)) return false; ! $code = (string) null; $params = array(); for(; $this->token < count($this->tokens); ++$this->token) *************** *** 193,199 **** break; case T_VARIABLE: ! if($this->Define($data)) ! $code .= 'php_var '; ! $code .= '_' . substr($data, 1); break; case T_LNUMBER: --- 192,200 ---- break; case T_VARIABLE: ! $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: *************** *** 252,255 **** --- 253,261 ---- ++$this->token; break; + case T_ARRAY: + $data = $this->tokens[$this->token + 1][1]; + ++$this->token; + $code .= $this->B_array($this->Parse_Tokenstream(',', ')')); + break; case '-': case '+': *************** *** 264,267 **** --- 270,280 ---- $code .= ' ' . $token . ' '; break; + case T_DOUBLE_ARROW: + $code .= ' => '; + break; + case '[': + case ']': + $code .= $token; + break; case T_BOOLEAN_AND: case T_BOOLEAN_OR: *************** *** 307,310 **** --- 320,343 ---- } /** + * Code generator for variable declarations + * + * @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); + return $code; + } + /** * Code generator for echo * *************** *** 327,331 **** } if($add) ! $this->AddCode($code); return $code; } --- 360,364 ---- } if($add) ! $this->AddCode($code . ';'); return $code; } *************** *** 394,397 **** --- 427,450 ---- $this->AddCode($code . ';'); return $code; + } + /** + * Code generator for calls to the array() language construct. + * + * @param array $parameters Elements of the array. + * @return string + * @access private + */ + function B_array($parameters) + { + $this->AddCPPInclude('arrays/array.cpp'); + foreach($parameters as $key => $val) + { + $arr = explode('=>', $val); + if(count($arr) == 1) + $parameters[$key] = 'NULL, (void *)(php_var *) &(php_var(' . $val . '))'; + else + $parameters[$key] = '(void *)(php_var *) &(php_var(' . trim($arr[0]) . ')), (void *)(php_var *) &(php_var(' . trim($arr[1]) . '))'; + } + return 'array(' . count($parameters) . ', ' . implode(', ', $parameters); } /** |