diff --git a/bin/systemlib.php b/bin/systemlib.php index 350e8a5a0..54adf539a 100644 --- a/bin/systemlib.php +++ b/bin/systemlib.php @@ -1,4 +1,4 @@ -path = $path; + $this->handle = opendir($path); } - public function map($callback) { - return new MappedIterable($this, $callback); - } - public function filter($callback) { - return new FilteredIterable($this, $callback); - } - public function zip($iterable) { - return new ZippedIterable($this, $iterable); - } -} -trait KeyedIterableTrait { - public function view() { - return $this; + public function read() { + return readdir($this->handle); } - public function map($callback) { - return new MappedKeyedIterable($this, $callback); - } - public function filter($callback) { - return new FilteredKeyedIterable($this, $callback); - } - public function zip($iterable) { - return new ZippedKeyedIterable($this, $iterable); - } - public function keys() { - return new KeysIterable($this); - } - public function kvzip() { - return new KVZippedIterable($this); - } -} -class MappedIterator implements Iterator { - private $it; - private $fn; - - public function __construct($it, $fn) { - $this->it = $it; - $this->fn = $fn; - } - public function __clone() { - $this->it = clone $this->it; - } public function rewind() { - $this->it->rewind(); + rewinddir($this->handle); } - public function valid() { - return $this->it->valid(); - } - public function next() { - $this->it->next(); - } - public function key() { - return null; - } - public function current() { - return ($this->fn)($this->it->current()); + + public function close() { + closedir($this->handle); } } -class MappedIterable implements Iterable { - use IterableTrait; +class SoapFault extends Exception { + public $faultcode; + public $faultcodens; + public $faultstring; + public $faultactor; + public $detail; + public $_name; + public $headerfault; - private $iterable; - private $fn; + public function __construct($code, $message, $actor = null, $detail = null, + $name = null, $header = null) { + $fault_ns = null; + $fault_code = null; + if (is_string($code)) { + $fault_code = $code; + } else if (is_array($code) && count($code) == 2) { + $code = array_values($code); + $fault_ns = $code[0]; + $fault_code = $code[1]; + if (!is_string($fault_ns) || !is_string($fault_code)) { + hphp_throw_fatal_error("Invalid fault code"); + return; + } + } else { + hphp_throw_fatal_error("Invalid fault code"); + return; + } + $this->faultcodens = $fault_ns; + $this->faultcode = $fault_code; + if (empty($this->faultcode)) { + hphp_throw_fatal_error("Invalid fault code"); + return; + } - public function __construct($iterable, $fn) { - $this->iterable = $iterable; - $this->fn = $fn; - } - public function getIterator() { - return new MappedIterator($this->iterable->getIterator(), $this->fn); - } -} + $this->faultstring = $this->message = $message; + $this->faultactor = $actor; + $this->detail = $detail; + $this->_name = $name; + $this->headerfault = $header; -class MappedKeyedIterator implements KeyedIterator { - private $it; - private $fn; + $SOAP_1_1 = 1; + $SOAP_1_2 = 2; + $SOAP_1_1_ENV_NAMESPACE = 'http://schemas.xmlsoap.org/soap/envelope/'; + $SOAP_1_2_ENV_NAMESPACE = 'http://www.w3.org/2003/05/soap-envelope'; - public function __construct($it, $fn) { - $this->it = $it; - $this->fn = $fn; - } - public function __clone() { - $this->it = clone $this->it; - } - public function rewind() { - $this->it->rewind(); - } - public function valid() { - return $this->it->valid(); - } - public function next() { - $this->it->next(); - } - public function key() { - return $this->it->key(); - } - public function current() { - return ($this->fn)($this->it->current()); - } -} - -class MappedKeyedIterable implements KeyedIterable { - use KeyedIterableTrait; - - private $iterable; - private $fn; - - public function __construct($iterable, $fn) { - $this->iterable = $iterable; - $this->fn = $fn; - } - public function getIterator() { - return new MappedKeyedIterator($this->iterable->getIterator(), $this->fn); - } -} - -class FilteredIterator implements Iterator { - private $it; - private $fn; - - public function __construct($it, $fn) { - $this->it = $it; - $this->fn = $fn; - } - public function __clone() { - $this->it = clone $this->it; - } - public function rewind() { - $it = $this->it; - $fn = $this->fn; - $it->rewind(); - while ($it->valid() && !$fn($it->current())) { - $it->next(); + $soap_version = _soap_active_version(); + if (empty($this->faultcodens)) { + if ($soap_version == $SOAP_1_1) { + if ($this->faultcode == "Client" || + $this->faultcode == "Server" || + $this->faultcode == "VersionMismatch" || + $this->faultcode == "MustUnderstand") { + $this->faultcodens = $SOAP_1_1_ENV_NAMESPACE; + } + } else if ($soap_version == $SOAP_1_2) { + if ($this->faultcode == "Client") { + $this->faultcode = "Sender"; + $this->faultcodens = $SOAP_1_2_ENV_NAMESPACE; + } else if ($this->faultcode == "Server") { + $this->faultcode = "Receiver"; + $this->faultcodens = $SOAP_1_2_ENV_NAMESPACE; + } else if ($this->faultcode == "VersionMismatch" || + $this->faultcode == "MustUnderstand" || + $this->faultcode == "DataEncodingUnknown") { + $this->faultcodens = $SOAP_1_2_ENV_NAMESPACE; + } + } } } - public function valid() { - return $this->it->valid(); + + public function __toString() { + return "SoapFault exception: [" . $this->faultcode . "] " . + $this->faultstring; } - public function next() { - $it = $this->it; - $fn = $this->fn; - $it->next(); - while ($it->valid() && !$fn($it->current())) { - $it->next(); +} + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/class.splobjectstorage.php ) + * + * The SplObjectStorage class provides a map from objects to data or, by + * ignoring data, an object set. This dual purpose can be useful in many + * cases involving the need to uniquely identify objects. + * + */ +class SplObjectStorage implements Iterator, Countable { + private $storage = array(); + private $index = 0; + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.rewind.php ) + * + * Rewind the iterator to the first storage element. + * + * @return mixed No value is returned. + */ + function rewind() { + rewind($this->storage); + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.valid.php ) + * + * Returns if the current iterator entry is valid. + * + * @return mixed Returns TRUE if the iterator entry is valid, FALSE + * otherwise. + */ + function valid() { + return key($this->storage) !== false; + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.key.php ) + * + * Returns the index at which the iterator currently is. + * + * @return mixed The index corresponding to the position of the + * iterator. + */ + function key() { + return $this->index; + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.current.php ) + * + * Returns the current storage entry. + * + * @return mixed The object at the current iterator position. + */ + function current() { + return current($this->storage); + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.next.php ) + * + * Moves the iterator to the next object in the storage. + * + * @return mixed No value is returned. + */ + function next() { + next($this->storage); + $this->index++; + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.count.php ) + * + * Counts the number of objects in the storage. + * + * @return mixed The number of objects in the storage. + */ + function count() { + return count($this->storage); + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.contains.php ) + * + * Checks if the storage contains the object provided. + * + * @obj mixed The object to look for. + * + * @return mixed Returns TRUE if the object is in the storage, FALSE + * otherwise. + */ + function contains($obj) { + if (is_object($obj)) { + foreach($this->storage as $object) { + if ($object === $obj) { + return true; + } + } + } + return false; + } + +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.attach.php ) + * + * Adds an object inside the storage, and optionaly associate it to some + * data. + * + * @obj mixed The object to add. + * + * @return mixed No value is returned. + */ + function attach($obj) { + if (is_object($obj) && !$this->contains($obj)) { + $this->storage[] = $obj; } } - public function key() { - return null; - } - public function current() { - return $this->it->current(); - } -} -class FilteredIterable implements Iterable { - use IterableTrait; - - private $iterable; - private $fn; - - public function __construct($iterable, $fn) { - $this->iterable = $iterable; - $this->fn = $fn; - } - public function getIterator() { - return new FilteredIterator($this->iterable->getIterator(), $this->fn); - } -} - -class FilteredKeyedIterator implements KeyedIterator { - private $it; - private $fn; - - public function __construct($it, $fn) { - $this->it = $it; - $this->fn = $fn; - } - public function __clone() { - $this->it = clone $this->it; - } - public function rewind() { - $it = $this->it; - $fn = $this->fn; - $it->rewind(); - while ($it->valid() && !$fn($it->current())) { - $it->next(); +// Do NOT modifiy this doc comment block generated by idl/sysdoc.php +/** + * ( excerpt from http://php.net/manual/en/splobjectstorage.detach.php ) + * + * Removes the object from the storage. + * + * @obj mixed The object to remove. + * + * @return mixed No value is returned. + */ + function detach($obj) { + if (is_object($obj)) { + foreach($this->storage as $idx => $object) { + if ($object === $obj) { + unset($this->storage[$idx]); + $this->rewind(); + return; + } + } } } - public function valid() { - return $this->it->valid(); - } - public function next() { - $it = $this->it; - $fn = $this->fn; - $it->next(); - while ($it->valid() && !$fn($it->current())) { - $it->next(); - } - } - public function key() { - return $this->it->key(); - } - public function current() { - return $this->it->current(); - } } -class FilteredKeyedIterable implements KeyedIterable { - use KeyedIterableTrait; - - private $iterable; - private $fn; - - public function __construct($iterable, $fn) { - $this->iterable = $iterable; - $this->fn = $fn; +/** + * Helps application inserting an artificial frame in xhprof's reporting. + */ +class XhprofFrame { + public function __construct($name) { + xhprof_frame_begin($name); } - public function getIterator() { - return new FilteredKeyedIterator($this->iterable->getIterator(), $this->fn); + public function __destruct() { + xhprof_frame_end(); } } -class ZippedIterator implements Iterator { - private $it1; - private $it2; - - public function __construct($it1, $it2) { - $this->it1 = $it1; - $this->it2 = $it2; - } - public function __clone() { - $this->it1 = clone $this->it1; - $this->it2 = clone $this->it2; - } - public function rewind() { - $this->it1->rewind(); - $this->it2->rewind(); - } - public function valid() { - return ($this->it1->valid() && $this->it2->valid()); - } - public function next() { - $this->it1->next(); - $this->it2->next(); - } - public function key() { - return null; - } - public function current() { - return Pair {$this->it1->current(), $this->it2->current()}; - } -} - -class ZippedIterable implements Iterable { - use IterableTrait; - - private $iterable1; - private $iterable2; - - public function __construct($iterable1, $iterable2) { - $this->iterable1 = $iterable1; - $this->iterable2 = $iterable2; - } - public function getIterator() { - return new ZippedIterator($this->iterable1->getIterator(), - $this->iterable2->getIterator()); - } -} - -class ZippedKeyedIterator implements KeyedIterator { - private $it1; - private $it2; - - public function __construct($it1, $it2) { - $this->it1 = $it1; - $this->it2 = $it2; - } - public function __clone() { - $this->it1 = clone $this->it1; - $this->it2 = clone $this->it2; - } - public function rewind() { - $this->it1->rewind(); - $this->it2->rewind(); - } - public function valid() { - return ($this->it1->valid() && $this->it2->valid()); - } - public function next() { - $this->it1->next(); - $this->it2->next(); - } - public function key() { - return $this->it1->key(); - } - public function current() { - return Pair {$this->it1->current(), $this->it2->current()}; - } -} - -class ZippedKeyedIterable implements KeyedIterable { - use KeyedIterableTrait; - - private $iterable1; - private $iterable2; - - public function __construct($iterable1, $iterable2) { - $this->iterable1 = $iterable1; - $this->iterable2 = $iterable2; - } - public function getIterator() { - return new ZippedKeyedIterator($this->iterable1->getIterator(), - $this->iterable2->getIterator()); - } -} - -class KeysIterator implements Iterator { - private $it; - - public function __construct($it) { - $this->it = $it; - } - public function __clone() { - $this->it = clone $this->it; - } - public function rewind() { - $this->it->rewind(); - } - public function valid() { - return $this->it->valid(); - } - public function next() { - $this->it->next(); - } - public function key() { - return null; - } - public function current() { - return $this->it->key(); - } -} - -class KeysIterable implements Iterable { - use IterableTrait; - - private $iterable; - - public function __construct($iterable) { - $this->iterable = $iterable; - } - public function getIterator() { - return new KeysIterator($this->iterable->getIterator()); - } -} - -class KVZippedIterator implements Iterator { - private $it; - - public function __construct($it) { - $this->it = $it; - } - public function __clone() { - $this->it = clone $this->it; - } - public function rewind() { - $this->it->rewind(); - } - public function valid() { - return $this->it->valid(); - } - public function next() { - $this->it->next(); - } - public function key() { - return null; - } - public function current() { - return Pair {$this->it->key(), $this->it->current()}; - } -} - -class KVZippedIterable implements Iterable { - use IterableTrait; - - private $iterable; - - public function __construct($iterable) { - $this->iterable = $iterable; - } - public function getIterator() { - return new KVZippedIterator($this->iterable->getIterator()); - } -} - -interface ConstCollection extends Countable { - public function isEmpty(); - public function count(); - public function items(); -} - -interface OutputCollection { - public function add($e); - public function addAll($iterable); -} - -interface Collection extends ConstCollection, - OutputCollection { - public function clear(); -} - -interface ConstSetAccess { - public function contains($m); -} - -interface SetAccess extends ConstSetAccess { - public function remove($m); -} - -interface ConstIndexAccess { - public function at($k); - public function get($k); - public function containsKey($k); -} - -interface IndexAccess extends ConstIndexAccess { - public function set($k,$v); - public function setAll($iterable); - public function removeKey($k); -} - -interface ConstMapAccess extends ConstSetAccess, - ConstIndexAccess { -} - -interface MapAccess extends ConstMapAccess, - SetAccess, - IndexAccess { -} - -interface Indexish extends KeyedTraversable { -} - -interface ConstVector extends ConstCollection, - ConstIndexAccess, - KeyedIterable { -} - -interface MutableVector extends ConstVector, - Collection, - IndexAccess { -} - -interface ConstMap extends ConstCollection, - ConstMapAccess, - KeyedIterable { -} - -interface MutableMap extends ConstMap, - Collection, - MapAccess { -} - -interface ConstSet extends ConstCollection, - ConstSetAccess, - Iterable { -} - -interface MutableSet extends ConstSet, - Collection, - SetAccess { -} - -class IterableView implements Iterable { - public $iterable; - - public function __construct($iterable) { $this->iterable = $iterable; } - public function getIterator() { return $this->iterable->getIterator(); } - public function view() { - return $this; - } - public function map($callback) { - return new MappedIterable($this->iterable, $callback); - } - public function filter($callback) { - return new FilteredIterable($this->iterable, $callback); - } - public function zip($iterable) { - return new ZippedIterable($this->iterable, $iterable); - } -} - -class KeyedIterableView implements KeyedIterable { - public $iterable; - - public function __construct($iterable) { $this->iterable = $iterable; } - public function getIterator() { return $this->iterable->getIterator(); } - public function view() { - return $this; - } - public function map($callback) { - return new MappedKeyedIterable($this->iterable, $callback); - } - public function filter($callback) { - return new FilteredKeyedIterable($this->iterable, $callback); - } - public function zip($iterable) { - return new ZippedKeyedIterable($this->iterable, $iterable); - } - public function keys() { - return new KeysIterable($this->iterable); - } - public function kvzip() { - return new KVZippedIterable($this->iterable); - } -} - - interface DebuggerCommand { /** * Called when DebuggerClient needs to auto-complete. Inside this function, @@ -2777,28 +2510,6 @@ interface DebuggerCommand { public function onServer($proxy); } -class Directory { - public $path; - public $handle; - - public function __construct($path) { - $this->path = $path; - $this->handle = opendir($path); - } - - public function read() { - return readdir($this->handle); - } - - public function rewind() { - rewinddir($this->handle); - } - - public function close() { - closedir($this->handle); - } -} - // Do NOT modifiy this doc comment block generated by idl/sysdoc.php /** * ( excerpt from http://php.net/manual/en/class.directoryiterator.php ) @@ -3043,608 +2754,6 @@ class RecursiveDirectoryIterator extends DirectoryIterator } } -/* vim: set expandtab tabstop=4 shiftwidth=4: */ -// +----------------------------------------------------------------------+ -// | Copyright (c) 2002-2004 Brent Cook | -// +----------------------------------------------------------------------+ -// | This library is free software; you can redistribute it and/or | -// | modify it under the terms of the GNU Lesser General Public | -// | License as published by the Free Software Foundation; either | -// | version 2.1 of the License, or (at your option) any later version. | -// | | -// | This library is distributed in the hope that it will be useful, | -// | but WITHOUT ANY WARRANTY; without even the implied warranty of | -// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | -// | Lesser General Public License for more details. | -// | | -// | You should have received a copy of the GNU Lesser General Public | -// | License along with this library; if not, write to the Free Software | -// | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| -// +----------------------------------------------------------------------+ -// | Authors: Brent Cook | -// | Jason Pell | -// +----------------------------------------------------------------------+ -// -// $Id: Lexer.php,v 1.20 2004/05/07 12:33:35 busterb Exp $ -// - -// {{{ token definitions -// variables: 'ident', 'sys_var' -// values: 'real_val', 'text_val', 'int_val', null -// }}} - -/** - * A lexigraphical analyser inspired by the msql lexer - * - * @author Brent Cook - * @version 0.5 - * @access public - * @package SQL_Parser - */ -class FB_MySQLLexer -{ - // array of valid tokens for the lexer to recognize - // format is 'token literal'=>TOKEN_VALUE - var $symbols = array(); - -// {{{ instance variables - var $tokPtr = 0; - var $tokStart = 0; - var $tokLen = 0; - var $tokText = ''; - var $lineNo = 0; - var $lineBegin = 0; - var $string = ''; - var $stringLen = 0; - - // Will not be altered by skip() - var $tokAbsStart = 0; - var $skipText = ''; - - // Provide lookahead capability. - var $lookahead = 0; - // Specify how many tokens to save in tokenStack, so the - // token stream can be pushed back. - var $tokenStack = array(); - var $stackPtr = 0; -// }}} - -// {{{ incidental functions - function __construct($string = '', $lookahead=0) - { - $this->string = $string; - $this->stringLen = strlen($string); - $this->lookahead = $lookahead; - } - - function get() { - ++$this->tokPtr; - ++$this->tokLen; - return ($this->tokPtr <= $this->stringLen) ? $this->string{$this->tokPtr - 1} : null; - } - - function unget() { - --$this->tokPtr; - --$this->tokLen; - } - - function skip() { - ++$this->tokStart; - return ($this->tokPtr != $this->stringLen) ? $this->string{$this->tokPtr++} : ''; - } - - function revert() { - $this->tokPtr = $this->tokStart; - $this->tokLen = 0; - } - - function isCompop($c) { - return (($c == '<') || ($c == '>') || ($c == '=') || ($c == '!')); - } -// }}} - -// {{{ pushBack() -/* - * Push back a token, so the very next call to lex() will return that token. - * Calls to this function will be ignored if there is no lookahead specified - * to the constructor, or the pushBack() function has already been called the - * maximum number of token's that can be looked ahead. - */ -function pushBack() -{ - if($this->lookahead>0 && count($this->tokenStack)>0 && $this->stackPtr>0) { - $this->stackPtr--; - } -} -// }}} - -// {{{ lex() -function lex() -{ - if($this->lookahead>0) { - // The stackPtr, should always be the same as the count of - // elements in the tokenStack. The stackPtr, can be thought - // of as pointing to the next token to be added. If however - // a pushBack() call is made, the stackPtr, will be less than the - // count, to indicate that we should take that token from the - // stack, instead of calling nextToken for a new token. - - if ($this->stackPtrtokenStack)) { - - $this->tokText = $this->tokenStack[$this->stackPtr]['tokText']; - $this->skipText = $this->tokenStack[$this->stackPtr]['skipText']; - $token = $this->tokenStack[$this->stackPtr]['token']; - - // We have read the token, so now iterate again. - $this->stackPtr++; - return $token; - - } else { - - // If $tokenStack is full (equal to lookahead), pop the oldest - // element off, to make room for the new one. - - if ($this->stackPtr == $this->lookahead) { - // For some reason array_shift and - // array_pop screw up the indexing, so we do it manually. - for($i=0; $i<(count($this->tokenStack)-1); $i++) { - $this->tokenStack[$i] = $this->tokenStack[$i+1]; - } - - // Indicate that we should put the element in - // at the stackPtr position. - $this->stackPtr--; - } - - $token = $this->nextToken(); - $this->tokenStack[$this->stackPtr] = - array('token'=>$token, - 'tokText'=>$this->tokText, - 'skipText'=>$this->skipText); - $this->stackPtr++; - return $token; - } - } - else - { - return $this->nextToken(); - } -} -// }}} - -// {{{ nextToken() -function nextToken() -{ - if ($this->string == '') return; - $state = 0; - $this->tokAbsStart = $this->tokStart; - - while (true){ - //echo "State: $state, Char: $c\n"; - switch($state) { - // {{{ State 0 : Start of token - case 0: - $this->tokPtr = $this->tokStart; - $this->tokText = ''; - $this->tokLen = 0; - $c = $this->get(); - - if (is_null($c)) { // End Of Input - $state = 1000; - break; - } - - while (($c == ' ') || ($c == "\t") - || ($c == "\n") || ($c == "\r")) { - if ($c == "\n" || $c == "\r") { - // Handle MAC/Unix/Windows line endings. - if($c == "\r") { - $c = $this->skip(); - - // If not DOS newline - if($c != "\n") - $this->unget(); - } - ++$this->lineNo; - $this->lineBegin = $this->tokPtr; - } - - $c = $this->skip(); - $this->tokLen = 1; - } - - // Escape quotes and backslashes - if ($c == '\\') { - $t = $this->get(); - if ($t == '\'' || $t == '\\' || $t == '"') { - $this->tokText = $t; - $this->tokStart = $this->tokPtr; - return $this->tokText; - } else { - $this->unget(); - - // Unknown token. Revert to single char - $state = 999; - break; - } - } - - if (($c == '\'') || ($c == '"')) { // text string - $quote = $c; - $state = 12; - break; - } - - if ($c == '_') { // system variable - $state = 18; - break; - } - - if ($c == '`') { // escaped ident - $state = 20; - break; - } - - if (ctype_alpha($c)) { // keyword or ident - $state = 1; - break; - } - - if (ctype_digit($c)) { // real or int number - $state = 5; - break; - } - - if ($c == '.') { - $t = $this->get(); - if ($t == '.') { // ellipsis - if ($this->get() == '.') { - $this->tokText = '...'; - $this->tokStart = $this->tokPtr; - return $this->tokText; - } else { - $state = 999; - break; - } - } else if (ctype_digit($t)) { // real number - $this->unget(); - $state = 7; - break; - } else { // period - $this->unget(); - } - } - - if ($c == '#') { // Comments - $state = 14; - break; - } - if ($c == '-') { - $t = $this->get(); - if ($t == '-') { - $state = 14; - break; - } else { - // negative number ... or - used as an operator - $state = 999; - break; - } - } - - if ($this->isCompop($c)) { // comparison operator - $state = 10; - break; - } - // Unknown token. Revert to single char - $state = 999; - break; - // }}} - - // {{{ State 1 : Incomplete keyword or ident - case 1: - $c = $this->get(); - if (ctype_alnum($c) || ($c == '_')) { - $state = 1; - break; - } - $state = 2; - break; - // }}} - - // {{{ State 20 : Incomplete keyword or ident - case 20: - do { - $c = $this->get(); - } while ('`' != $c); - - $c = $this->get(); - $state = 2; - break; - // }}} - - /* {{{ State 2 : Complete keyword or ident */ - case 2: - $this->unget(); - $this->tokText = substr($this->string, $this->tokStart, - $this->tokLen); - - $testToken = strtolower($this->tokText); - if (isset($this->symbols[$testToken])) { - - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - return $testToken; - } else { - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - $this->tokText = trim($this->tokText, '`'); - return 'ident'; - } - break; - // }}} - - // {{{ State 5: Incomplete real or int number - case 5: - $c = $this->get(); - if (ctype_digit($c)) { - $state = 5; - break; - } else if ($c == '.') { - $t = $this->get(); - if ($t == '.') { // ellipsis - $this->unget(); - } else { // real number - $state = 7; - break; - } - } else if(ctype_alpha($c)) { // number must end with non-alpha character - $state = 999; - break; - } else { - // complete number - $state = 6; - break; - } - // }}} - - // {{{ State 6: Complete integer number - case 6: - $this->unget(); - $this->tokText = intval(substr($this->string, $this->tokStart, - $this->tokLen)); - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - return 'int_val'; - break; - // }}} - - // {{{ State 7: Incomplete real number - case 7: - $c = $this->get(); - - /* Analogy Start */ - if ($c == 'e' || $c == 'E') { - $state = 15; - break; - } - /* Analogy End */ - - if (ctype_digit($c)) { - $state = 7; - break; - } - $state = 8; - break; - // }}} - - // {{{ State 8: Complete real number */ - case 8: - $this->unget(); - $this->tokText = floatval(substr($this->string, $this->tokStart, - $this->tokLen)); - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - return 'real_val'; - // }}} - - // {{{ State 10: Incomplete comparison operator - case 10: - $c = $this->get(); - if ($this->isCompop($c)) - { - $state = 10; - break; - } - $state = 11; - break; - // }}} - - // {{{ State 11: Complete comparison operator - case 11: - $this->unget(); - $this->tokText = substr($this->string, $this->tokStart, - $this->tokLen); - if($this->tokText) { - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - return $this->tokText; - } - $state = 999; - break; - // }}} - - // {{{ State 12: Incomplete text string - case 12: - $bail = false; - $text = ''; - while (!$bail) { - $c = $this->get(); - switch ($c) { - case '': - $this->tokText = null; - $bail = true; - break; - case "\\": - $c = $this->get(); - switch ($c) { - // undo mysql_escape_string - case '0': - $text .= "\0"; - break; - case 'r': - $text .= "\r"; - break; - case 'n': - $text .= "\n"; - break; - case 'Z': - $text .= "\x1a"; - break; - default: - if (!$c) { - $this->tokText = null; - $bail = true; - } else { - $text .= $c; - } - } - break; - case $quote: - $this->tokText = $text; - $bail = true; - break; - default: - $text .= $c; - break; - } - } - if (!is_null($this->tokText)) { - $state = 13; - break; - } - $state = 999; - break; - // }}} - - // {{{ State 13: Complete text string - case 13: - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - return 'text_val'; - break; - // }}} - - // {{{ State 14: Comment - case 14: - $c = $this->skip(); - if ($c == "\n" || $c == "\r" || $c == "") { - // Handle MAC/Unix/Windows line endings. - if ($c == "\r") { - $c = $this->skip(); - // If not DOS newline - if ($c != "\n") { - $this->unget(); - } - } - - if ($c != "") { - ++$this->lineNo; - $this->lineBegin = $this->tokPtr; - } - - // We need to skip all the text. - $this->tokStart = $this->tokPtr; - $state = 0; - } else { - $state = 14; - } - break; - // }}} - - // {{{ State 15: Exponent Sign in Scientific Notation - case 15: - $c = $this->get(); - if($c == '-' || $c == '+') { - $state = 16; - break; - } - $state = 999; - break; - // }}} - - // {{{ state 16: Exponent Value-first digit in Scientific Notation - case 16: - $c = $this->get(); - if (ctype_digit($c)) { - $state = 17; - break; - } - $state = 999; // if no digit, then token is unknown - break; - // }}} - - // {{{ State 17: Exponent Value in Scientific Notation - case 17: - $c = $this->get(); - if (ctype_digit($c)) { - $state = 17; - break; - } - $state = 8; // At least 1 exponent digit was required - break; - // }}} - - // {{{ State 18 : Incomplete System Variable - case 18: - $c = $this->get(); - if (ctype_alnum($c) || $c == '_') { - $state = 18; - break; - } - $state = 19; - break; - // }}} - - // {{{ State 19: Complete Sys Var - case 19: - $this->unget(); - $this->tokText = substr($this->string, $this->tokStart, - $this->tokLen); - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - return 'sys_var'; - // }}} - - // {{{ State 999 : Unknown token. Revert to single char - case 999: - $this->revert(); - $this->tokText = $this->get(); - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - return $this->tokText; - // }}} - - // {{{ State 1000 : End Of Input - case 1000: - $this->tokText = '*end of input*'; - $this->skipText = substr($this->string, $this->tokAbsStart, - $this->tokStart-$this->tokAbsStart); - $this->tokStart = $this->tokPtr; - return null; - // }}} - } - } -} -// }}} -} /////////////////////////////////////////////////////////////////////////////// // helpers @@ -5943,246 +5052,1133 @@ class ReflectionExtension implements Reflector { } } -class SoapFault extends Exception { - public $faultcode; - public $faultcodens; - public $faultstring; - public $faultactor; - public $detail; - public $_name; - public $headerfault; - - public function __construct($code, $message, $actor = null, $detail = null, - $name = null, $header = null) { - $fault_ns = null; - $fault_code = null; - if (is_string($code)) { - $fault_code = $code; - } else if (is_array($code) && count($code) == 2) { - $code = array_values($code); - $fault_ns = $code[0]; - $fault_code = $code[1]; - if (!is_string($fault_ns) || !is_string($fault_code)) { - hphp_throw_fatal_error("Invalid fault code"); - return; - } - } else { - hphp_throw_fatal_error("Invalid fault code"); - return; - } - $this->faultcodens = $fault_ns; - $this->faultcode = $fault_code; - if (empty($this->faultcode)) { - hphp_throw_fatal_error("Invalid fault code"); - return; - } - - $this->faultstring = $this->message = $message; - $this->faultactor = $actor; - $this->detail = $detail; - $this->_name = $name; - $this->headerfault = $header; - - $SOAP_1_1 = 1; - $SOAP_1_2 = 2; - $SOAP_1_1_ENV_NAMESPACE = 'http://schemas.xmlsoap.org/soap/envelope/'; - $SOAP_1_2_ENV_NAMESPACE = 'http://www.w3.org/2003/05/soap-envelope'; - - $soap_version = _soap_active_version(); - if (empty($this->faultcodens)) { - if ($soap_version == $SOAP_1_1) { - if ($this->faultcode == "Client" || - $this->faultcode == "Server" || - $this->faultcode == "VersionMismatch" || - $this->faultcode == "MustUnderstand") { - $this->faultcodens = $SOAP_1_1_ENV_NAMESPACE; - } - } else if ($soap_version == $SOAP_1_2) { - if ($this->faultcode == "Client") { - $this->faultcode = "Sender"; - $this->faultcodens = $SOAP_1_2_ENV_NAMESPACE; - } else if ($this->faultcode == "Server") { - $this->faultcode = "Receiver"; - $this->faultcodens = $SOAP_1_2_ENV_NAMESPACE; - } else if ($this->faultcode == "VersionMismatch" || - $this->faultcode == "MustUnderstand" || - $this->faultcode == "DataEncodingUnknown") { - $this->faultcodens = $SOAP_1_2_ENV_NAMESPACE; - } - } - } +trait IterableTrait { + public function view() { + return $this; } - - public function __toString() { - return "SoapFault exception: [" . $this->faultcode . "] " . - $this->faultstring; + public function map($callback) { + return new MappedIterable($this, $callback); + } + public function filter($callback) { + return new FilteredIterable($this, $callback); + } + public function zip($iterable) { + return new ZippedIterable($this, $iterable); } } -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/class.splobjectstorage.php ) - * - * The SplObjectStorage class provides a map from objects to data or, by - * ignoring data, an object set. This dual purpose can be useful in many - * cases involving the need to uniquely identify objects. - * - */ -class SplObjectStorage implements Iterator, Countable { - private $storage = array(); - private $index = 0; - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.rewind.php ) - * - * Rewind the iterator to the first storage element. - * - * @return mixed No value is returned. - */ - function rewind() { - rewind($this->storage); +trait KeyedIterableTrait { + public function view() { + return $this; } - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.valid.php ) - * - * Returns if the current iterator entry is valid. - * - * @return mixed Returns TRUE if the iterator entry is valid, FALSE - * otherwise. - */ - function valid() { - return key($this->storage) !== false; + public function map($callback) { + return new MappedKeyedIterable($this, $callback); } - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.key.php ) - * - * Returns the index at which the iterator currently is. - * - * @return mixed The index corresponding to the position of the - * iterator. - */ - function key() { - return $this->index; + public function filter($callback) { + return new FilteredKeyedIterable($this, $callback); } - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.current.php ) - * - * Returns the current storage entry. - * - * @return mixed The object at the current iterator position. - */ - function current() { - return current($this->storage); + public function zip($iterable) { + return new ZippedKeyedIterable($this, $iterable); } - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.next.php ) - * - * Moves the iterator to the next object in the storage. - * - * @return mixed No value is returned. - */ - function next() { - next($this->storage); - $this->index++; + public function keys() { + return new KeysIterable($this); } - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.count.php ) - * - * Counts the number of objects in the storage. - * - * @return mixed The number of objects in the storage. - */ - function count() { - return count($this->storage); - } - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.contains.php ) - * - * Checks if the storage contains the object provided. - * - * @obj mixed The object to look for. - * - * @return mixed Returns TRUE if the object is in the storage, FALSE - * otherwise. - */ - function contains($obj) { - if (is_object($obj)) { - foreach($this->storage as $object) { - if ($object === $obj) { - return true; - } - } - } - return false; - } - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.attach.php ) - * - * Adds an object inside the storage, and optionaly associate it to some - * data. - * - * @obj mixed The object to add. - * - * @return mixed No value is returned. - */ - function attach($obj) { - if (is_object($obj) && !$this->contains($obj)) { - $this->storage[] = $obj; - } - } - -// Do NOT modifiy this doc comment block generated by idl/sysdoc.php -/** - * ( excerpt from http://php.net/manual/en/splobjectstorage.detach.php ) - * - * Removes the object from the storage. - * - * @obj mixed The object to remove. - * - * @return mixed No value is returned. - */ - function detach($obj) { - if (is_object($obj)) { - foreach($this->storage as $idx => $object) { - if ($object === $obj) { - unset($this->storage[$idx]); - $this->rewind(); - return; - } - } - } + public function kvzip() { + return new KVZippedIterable($this); } } -/** - * Helps application inserting an artificial frame in xhprof's reporting. - */ -class XhprofFrame { - public function __construct($name) { - xhprof_frame_begin($name); +class MappedIterator implements Iterator { + private $it; + private $fn; + + public function __construct($it, $fn) { + $this->it = $it; + $this->fn = $fn; } - public function __destruct() { - xhprof_frame_end(); + public function __clone() { + $this->it = clone $this->it; + } + public function rewind() { + $this->it->rewind(); + } + public function valid() { + return $this->it->valid(); + } + public function next() { + $this->it->next(); + } + public function key() { + return null; + } + public function current() { + return ($this->fn)($this->it->current()); } } -// Used as a sentinel type in 86pinit(). -class __pinitSentinel { +class MappedIterable implements Iterable { + use IterableTrait; + + private $iterable; + private $fn; + + public function __construct($iterable, $fn) { + $this->iterable = $iterable; + $this->fn = $fn; + } + public function getIterator() { + return new MappedIterator($this->iterable->getIterator(), $this->fn); + } +} + +class MappedKeyedIterator implements KeyedIterator { + private $it; + private $fn; + + public function __construct($it, $fn) { + $this->it = $it; + $this->fn = $fn; + } + public function __clone() { + $this->it = clone $this->it; + } + public function rewind() { + $this->it->rewind(); + } + public function valid() { + return $this->it->valid(); + } + public function next() { + $this->it->next(); + } + public function key() { + return $this->it->key(); + } + public function current() { + return ($this->fn)($this->it->current()); + } +} + +class MappedKeyedIterable implements KeyedIterable { + use KeyedIterableTrait; + + private $iterable; + private $fn; + + public function __construct($iterable, $fn) { + $this->iterable = $iterable; + $this->fn = $fn; + } + public function getIterator() { + return new MappedKeyedIterator($this->iterable->getIterator(), $this->fn); + } +} + +class FilteredIterator implements Iterator { + private $it; + private $fn; + + public function __construct($it, $fn) { + $this->it = $it; + $this->fn = $fn; + } + public function __clone() { + $this->it = clone $this->it; + } + public function rewind() { + $it = $this->it; + $fn = $this->fn; + $it->rewind(); + while ($it->valid() && !$fn($it->current())) { + $it->next(); + } + } + public function valid() { + return $this->it->valid(); + } + public function next() { + $it = $this->it; + $fn = $this->fn; + $it->next(); + while ($it->valid() && !$fn($it->current())) { + $it->next(); + } + } + public function key() { + return null; + } + public function current() { + return $this->it->current(); + } +} + +class FilteredIterable implements Iterable { + use IterableTrait; + + private $iterable; + private $fn; + + public function __construct($iterable, $fn) { + $this->iterable = $iterable; + $this->fn = $fn; + } + public function getIterator() { + return new FilteredIterator($this->iterable->getIterator(), $this->fn); + } +} + +class FilteredKeyedIterator implements KeyedIterator { + private $it; + private $fn; + + public function __construct($it, $fn) { + $this->it = $it; + $this->fn = $fn; + } + public function __clone() { + $this->it = clone $this->it; + } + public function rewind() { + $it = $this->it; + $fn = $this->fn; + $it->rewind(); + while ($it->valid() && !$fn($it->current())) { + $it->next(); + } + } + public function valid() { + return $this->it->valid(); + } + public function next() { + $it = $this->it; + $fn = $this->fn; + $it->next(); + while ($it->valid() && !$fn($it->current())) { + $it->next(); + } + } + public function key() { + return $this->it->key(); + } + public function current() { + return $this->it->current(); + } +} + +class FilteredKeyedIterable implements KeyedIterable { + use KeyedIterableTrait; + + private $iterable; + private $fn; + + public function __construct($iterable, $fn) { + $this->iterable = $iterable; + $this->fn = $fn; + } + public function getIterator() { + return new FilteredKeyedIterator($this->iterable->getIterator(), $this->fn); + } +} + +class ZippedIterator implements Iterator { + private $it1; + private $it2; + + public function __construct($it1, $it2) { + $this->it1 = $it1; + $this->it2 = $it2; + } + public function __clone() { + $this->it1 = clone $this->it1; + $this->it2 = clone $this->it2; + } + public function rewind() { + $this->it1->rewind(); + $this->it2->rewind(); + } + public function valid() { + return ($this->it1->valid() && $this->it2->valid()); + } + public function next() { + $this->it1->next(); + $this->it2->next(); + } + public function key() { + return null; + } + public function current() { + return Pair {$this->it1->current(), $this->it2->current()}; + } +} + +class ZippedIterable implements Iterable { + use IterableTrait; + + private $iterable1; + private $iterable2; + + public function __construct($iterable1, $iterable2) { + $this->iterable1 = $iterable1; + $this->iterable2 = $iterable2; + } + public function getIterator() { + return new ZippedIterator($this->iterable1->getIterator(), + $this->iterable2->getIterator()); + } +} + +class ZippedKeyedIterator implements KeyedIterator { + private $it1; + private $it2; + + public function __construct($it1, $it2) { + $this->it1 = $it1; + $this->it2 = $it2; + } + public function __clone() { + $this->it1 = clone $this->it1; + $this->it2 = clone $this->it2; + } + public function rewind() { + $this->it1->rewind(); + $this->it2->rewind(); + } + public function valid() { + return ($this->it1->valid() && $this->it2->valid()); + } + public function next() { + $this->it1->next(); + $this->it2->next(); + } + public function key() { + return $this->it1->key(); + } + public function current() { + return Pair {$this->it1->current(), $this->it2->current()}; + } +} + +class ZippedKeyedIterable implements KeyedIterable { + use KeyedIterableTrait; + + private $iterable1; + private $iterable2; + + public function __construct($iterable1, $iterable2) { + $this->iterable1 = $iterable1; + $this->iterable2 = $iterable2; + } + public function getIterator() { + return new ZippedKeyedIterator($this->iterable1->getIterator(), + $this->iterable2->getIterator()); + } +} + +class KeysIterator implements Iterator { + private $it; + + public function __construct($it) { + $this->it = $it; + } + public function __clone() { + $this->it = clone $this->it; + } + public function rewind() { + $this->it->rewind(); + } + public function valid() { + return $this->it->valid(); + } + public function next() { + $this->it->next(); + } + public function key() { + return null; + } + public function current() { + return $this->it->key(); + } +} + +class KeysIterable implements Iterable { + use IterableTrait; + + private $iterable; + + public function __construct($iterable) { + $this->iterable = $iterable; + } + public function getIterator() { + return new KeysIterator($this->iterable->getIterator()); + } +} + +class KVZippedIterator implements Iterator { + private $it; + + public function __construct($it) { + $this->it = $it; + } + public function __clone() { + $this->it = clone $this->it; + } + public function rewind() { + $this->it->rewind(); + } + public function valid() { + return $this->it->valid(); + } + public function next() { + $this->it->next(); + } + public function key() { + return null; + } + public function current() { + return Pair {$this->it->key(), $this->it->current()}; + } +} + +class KVZippedIterable implements Iterable { + use IterableTrait; + + private $iterable; + + public function __construct($iterable) { + $this->iterable = $iterable; + } + public function getIterator() { + return new KVZippedIterator($this->iterable->getIterator()); + } +} + +interface ConstCollection extends Countable { + public function isEmpty(); + public function count(); + public function items(); +} + +interface OutputCollection { + public function add($e); + public function addAll($iterable); +} + +interface Collection extends ConstCollection, + OutputCollection { + public function clear(); +} + +interface ConstSetAccess { + public function contains($m); +} + +interface SetAccess extends ConstSetAccess { + public function remove($m); +} + +interface ConstIndexAccess { + public function at($k); + public function get($k); + public function containsKey($k); +} + +interface IndexAccess extends ConstIndexAccess { + public function set($k,$v); + public function setAll($iterable); + public function removeKey($k); +} + +interface ConstMapAccess extends ConstSetAccess, + ConstIndexAccess { +} + +interface MapAccess extends ConstMapAccess, + SetAccess, + IndexAccess { +} + +interface Indexish extends KeyedTraversable { +} + +interface ConstVector extends ConstCollection, + ConstIndexAccess, + KeyedIterable { +} + +interface MutableVector extends ConstVector, + Collection, + IndexAccess { +} + +interface ConstMap extends ConstCollection, + ConstMapAccess, + KeyedIterable { +} + +interface MutableMap extends ConstMap, + Collection, + MapAccess { +} + +interface ConstSet extends ConstCollection, + ConstSetAccess, + Iterable { +} + +interface MutableSet extends ConstSet, + Collection, + SetAccess { +} + +class IterableView implements Iterable { + public $iterable; + + public function __construct($iterable) { $this->iterable = $iterable; } + public function getIterator() { return $this->iterable->getIterator(); } + public function view() { + return $this; + } + public function map($callback) { + return new MappedIterable($this->iterable, $callback); + } + public function filter($callback) { + return new FilteredIterable($this->iterable, $callback); + } + public function zip($iterable) { + return new ZippedIterable($this->iterable, $iterable); + } +} + +class KeyedIterableView implements KeyedIterable { + public $iterable; + + public function __construct($iterable) { $this->iterable = $iterable; } + public function getIterator() { return $this->iterable->getIterator(); } + public function view() { + return $this; + } + public function map($callback) { + return new MappedKeyedIterable($this->iterable, $callback); + } + public function filter($callback) { + return new FilteredKeyedIterable($this->iterable, $callback); + } + public function zip($iterable) { + return new ZippedKeyedIterable($this->iterable, $iterable); + } + public function keys() { + return new KeysIterable($this->iterable); + } + public function kvzip() { + return new KVZippedIterable($this->iterable); + } +} + +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | Copyright (c) 2002-2004 Brent Cook | +// +----------------------------------------------------------------------+ +// | This library is free software; you can redistribute it and/or | +// | modify it under the terms of the GNU Lesser General Public | +// | License as published by the Free Software Foundation; either | +// | version 2.1 of the License, or (at your option) any later version. | +// | | +// | This library is distributed in the hope that it will be useful, | +// | but WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | Lesser General Public License for more details. | +// | | +// | You should have received a copy of the GNU Lesser General Public | +// | License along with this library; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA| +// +----------------------------------------------------------------------+ +// | Authors: Brent Cook | +// | Jason Pell | +// +----------------------------------------------------------------------+ +// +// $Id: Lexer.php,v 1.20 2004/05/07 12:33:35 busterb Exp $ +// + +// {{{ token definitions +// variables: 'ident', 'sys_var' +// values: 'real_val', 'text_val', 'int_val', null +// }}} + +/** + * A lexigraphical analyser inspired by the msql lexer + * + * @author Brent Cook + * @version 0.5 + * @access public + * @package SQL_Parser + */ +class FB_MySQLLexer +{ + // array of valid tokens for the lexer to recognize + // format is 'token literal'=>TOKEN_VALUE + var $symbols = array(); + +// {{{ instance variables + var $tokPtr = 0; + var $tokStart = 0; + var $tokLen = 0; + var $tokText = ''; + var $lineNo = 0; + var $lineBegin = 0; + var $string = ''; + var $stringLen = 0; + + // Will not be altered by skip() + var $tokAbsStart = 0; + var $skipText = ''; + + // Provide lookahead capability. + var $lookahead = 0; + // Specify how many tokens to save in tokenStack, so the + // token stream can be pushed back. + var $tokenStack = array(); + var $stackPtr = 0; +// }}} + +// {{{ incidental functions + function __construct($string = '', $lookahead=0) + { + $this->string = $string; + $this->stringLen = strlen($string); + $this->lookahead = $lookahead; + } + + function get() { + ++$this->tokPtr; + ++$this->tokLen; + return ($this->tokPtr <= $this->stringLen) ? $this->string{$this->tokPtr - 1} : null; + } + + function unget() { + --$this->tokPtr; + --$this->tokLen; + } + + function skip() { + ++$this->tokStart; + return ($this->tokPtr != $this->stringLen) ? $this->string{$this->tokPtr++} : ''; + } + + function revert() { + $this->tokPtr = $this->tokStart; + $this->tokLen = 0; + } + + function isCompop($c) { + return (($c == '<') || ($c == '>') || ($c == '=') || ($c == '!')); + } +// }}} + +// {{{ pushBack() +/* + * Push back a token, so the very next call to lex() will return that token. + * Calls to this function will be ignored if there is no lookahead specified + * to the constructor, or the pushBack() function has already been called the + * maximum number of token's that can be looked ahead. + */ +function pushBack() +{ + if($this->lookahead>0 && count($this->tokenStack)>0 && $this->stackPtr>0) { + $this->stackPtr--; + } +} +// }}} + +// {{{ lex() +function lex() +{ + if($this->lookahead>0) { + // The stackPtr, should always be the same as the count of + // elements in the tokenStack. The stackPtr, can be thought + // of as pointing to the next token to be added. If however + // a pushBack() call is made, the stackPtr, will be less than the + // count, to indicate that we should take that token from the + // stack, instead of calling nextToken for a new token. + + if ($this->stackPtrtokenStack)) { + + $this->tokText = $this->tokenStack[$this->stackPtr]['tokText']; + $this->skipText = $this->tokenStack[$this->stackPtr]['skipText']; + $token = $this->tokenStack[$this->stackPtr]['token']; + + // We have read the token, so now iterate again. + $this->stackPtr++; + return $token; + + } else { + + // If $tokenStack is full (equal to lookahead), pop the oldest + // element off, to make room for the new one. + + if ($this->stackPtr == $this->lookahead) { + // For some reason array_shift and + // array_pop screw up the indexing, so we do it manually. + for($i=0; $i<(count($this->tokenStack)-1); $i++) { + $this->tokenStack[$i] = $this->tokenStack[$i+1]; + } + + // Indicate that we should put the element in + // at the stackPtr position. + $this->stackPtr--; + } + + $token = $this->nextToken(); + $this->tokenStack[$this->stackPtr] = + array('token'=>$token, + 'tokText'=>$this->tokText, + 'skipText'=>$this->skipText); + $this->stackPtr++; + return $token; + } + } + else + { + return $this->nextToken(); + } +} +// }}} + +// {{{ nextToken() +function nextToken() +{ + if ($this->string == '') return; + $state = 0; + $this->tokAbsStart = $this->tokStart; + + while (true){ + //echo "State: $state, Char: $c\n"; + switch($state) { + // {{{ State 0 : Start of token + case 0: + $this->tokPtr = $this->tokStart; + $this->tokText = ''; + $this->tokLen = 0; + $c = $this->get(); + + if (is_null($c)) { // End Of Input + $state = 1000; + break; + } + + while (($c == ' ') || ($c == "\t") + || ($c == "\n") || ($c == "\r")) { + if ($c == "\n" || $c == "\r") { + // Handle MAC/Unix/Windows line endings. + if($c == "\r") { + $c = $this->skip(); + + // If not DOS newline + if($c != "\n") + $this->unget(); + } + ++$this->lineNo; + $this->lineBegin = $this->tokPtr; + } + + $c = $this->skip(); + $this->tokLen = 1; + } + + // Escape quotes and backslashes + if ($c == '\\') { + $t = $this->get(); + if ($t == '\'' || $t == '\\' || $t == '"') { + $this->tokText = $t; + $this->tokStart = $this->tokPtr; + return $this->tokText; + } else { + $this->unget(); + + // Unknown token. Revert to single char + $state = 999; + break; + } + } + + if (($c == '\'') || ($c == '"')) { // text string + $quote = $c; + $state = 12; + break; + } + + if ($c == '_') { // system variable + $state = 18; + break; + } + + if ($c == '`') { // escaped ident + $state = 20; + break; + } + + if (ctype_alpha($c)) { // keyword or ident + $state = 1; + break; + } + + if (ctype_digit($c)) { // real or int number + $state = 5; + break; + } + + if ($c == '.') { + $t = $this->get(); + if ($t == '.') { // ellipsis + if ($this->get() == '.') { + $this->tokText = '...'; + $this->tokStart = $this->tokPtr; + return $this->tokText; + } else { + $state = 999; + break; + } + } else if (ctype_digit($t)) { // real number + $this->unget(); + $state = 7; + break; + } else { // period + $this->unget(); + } + } + + if ($c == '#') { // Comments + $state = 14; + break; + } + if ($c == '-') { + $t = $this->get(); + if ($t == '-') { + $state = 14; + break; + } else { + // negative number ... or - used as an operator + $state = 999; + break; + } + } + + if ($this->isCompop($c)) { // comparison operator + $state = 10; + break; + } + // Unknown token. Revert to single char + $state = 999; + break; + // }}} + + // {{{ State 1 : Incomplete keyword or ident + case 1: + $c = $this->get(); + if (ctype_alnum($c) || ($c == '_')) { + $state = 1; + break; + } + $state = 2; + break; + // }}} + + // {{{ State 20 : Incomplete keyword or ident + case 20: + do { + $c = $this->get(); + } while ('`' != $c); + + $c = $this->get(); + $state = 2; + break; + // }}} + + /* {{{ State 2 : Complete keyword or ident */ + case 2: + $this->unget(); + $this->tokText = substr($this->string, $this->tokStart, + $this->tokLen); + + $testToken = strtolower($this->tokText); + if (isset($this->symbols[$testToken])) { + + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + return $testToken; + } else { + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + $this->tokText = trim($this->tokText, '`'); + return 'ident'; + } + break; + // }}} + + // {{{ State 5: Incomplete real or int number + case 5: + $c = $this->get(); + if (ctype_digit($c)) { + $state = 5; + break; + } else if ($c == '.') { + $t = $this->get(); + if ($t == '.') { // ellipsis + $this->unget(); + } else { // real number + $state = 7; + break; + } + } else if(ctype_alpha($c)) { // number must end with non-alpha character + $state = 999; + break; + } else { + // complete number + $state = 6; + break; + } + // }}} + + // {{{ State 6: Complete integer number + case 6: + $this->unget(); + $this->tokText = intval(substr($this->string, $this->tokStart, + $this->tokLen)); + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + return 'int_val'; + break; + // }}} + + // {{{ State 7: Incomplete real number + case 7: + $c = $this->get(); + + /* Analogy Start */ + if ($c == 'e' || $c == 'E') { + $state = 15; + break; + } + /* Analogy End */ + + if (ctype_digit($c)) { + $state = 7; + break; + } + $state = 8; + break; + // }}} + + // {{{ State 8: Complete real number */ + case 8: + $this->unget(); + $this->tokText = floatval(substr($this->string, $this->tokStart, + $this->tokLen)); + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + return 'real_val'; + // }}} + + // {{{ State 10: Incomplete comparison operator + case 10: + $c = $this->get(); + if ($this->isCompop($c)) + { + $state = 10; + break; + } + $state = 11; + break; + // }}} + + // {{{ State 11: Complete comparison operator + case 11: + $this->unget(); + $this->tokText = substr($this->string, $this->tokStart, + $this->tokLen); + if($this->tokText) { + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + return $this->tokText; + } + $state = 999; + break; + // }}} + + // {{{ State 12: Incomplete text string + case 12: + $bail = false; + $text = ''; + while (!$bail) { + $c = $this->get(); + switch ($c) { + case '': + $this->tokText = null; + $bail = true; + break; + case "\\": + $c = $this->get(); + switch ($c) { + // undo mysql_escape_string + case '0': + $text .= "\0"; + break; + case 'r': + $text .= "\r"; + break; + case 'n': + $text .= "\n"; + break; + case 'Z': + $text .= "\x1a"; + break; + default: + if (!$c) { + $this->tokText = null; + $bail = true; + } else { + $text .= $c; + } + } + break; + case $quote: + $this->tokText = $text; + $bail = true; + break; + default: + $text .= $c; + break; + } + } + if (!is_null($this->tokText)) { + $state = 13; + break; + } + $state = 999; + break; + // }}} + + // {{{ State 13: Complete text string + case 13: + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + return 'text_val'; + break; + // }}} + + // {{{ State 14: Comment + case 14: + $c = $this->skip(); + if ($c == "\n" || $c == "\r" || $c == "") { + // Handle MAC/Unix/Windows line endings. + if ($c == "\r") { + $c = $this->skip(); + // If not DOS newline + if ($c != "\n") { + $this->unget(); + } + } + + if ($c != "") { + ++$this->lineNo; + $this->lineBegin = $this->tokPtr; + } + + // We need to skip all the text. + $this->tokStart = $this->tokPtr; + $state = 0; + } else { + $state = 14; + } + break; + // }}} + + // {{{ State 15: Exponent Sign in Scientific Notation + case 15: + $c = $this->get(); + if($c == '-' || $c == '+') { + $state = 16; + break; + } + $state = 999; + break; + // }}} + + // {{{ state 16: Exponent Value-first digit in Scientific Notation + case 16: + $c = $this->get(); + if (ctype_digit($c)) { + $state = 17; + break; + } + $state = 999; // if no digit, then token is unknown + break; + // }}} + + // {{{ State 17: Exponent Value in Scientific Notation + case 17: + $c = $this->get(); + if (ctype_digit($c)) { + $state = 17; + break; + } + $state = 8; // At least 1 exponent digit was required + break; + // }}} + + // {{{ State 18 : Incomplete System Variable + case 18: + $c = $this->get(); + if (ctype_alnum($c) || $c == '_') { + $state = 18; + break; + } + $state = 19; + break; + // }}} + + // {{{ State 19: Complete Sys Var + case 19: + $this->unget(); + $this->tokText = substr($this->string, $this->tokStart, + $this->tokLen); + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + return 'sys_var'; + // }}} + + // {{{ State 999 : Unknown token. Revert to single char + case 999: + $this->revert(); + $this->tokText = $this->get(); + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + return $this->tokText; + // }}} + + // {{{ State 1000 : End Of Input + case 1000: + $this->tokText = '*end of input*'; + $this->skipText = substr($this->string, $this->tokAbsStart, + $this->tokStart-$this->tokAbsStart); + $this->tokStart = $this->tokPtr; + return null; + // }}} + } + } +} +// }}} +} + +interface Awaitable { + public function getWaitHandle(); } // Used to represent resources @@ -6192,3 +6188,7 @@ class __resource { } } +// Used as a sentinel type in 86pinit(). +class __pinitSentinel { +} + diff --git a/hphp/system/lib/gen_systemlib.php b/hphp/system/lib/gen_systemlib.php index c4d3d4ead..fb5f2195c 100644 --- a/hphp/system/lib/gen_systemlib.php +++ b/hphp/system/lib/gen_systemlib.php @@ -3,7 +3,7 @@ global $scriptPath, $outputPath; $scriptPath = dirname(__FILE__); if (!isset($argv[1])) { - throw new Exception("Usage: gen_systemlib.php "); + throw new Exception("Usage: gen_systemlib.php [input files]"); } $outputPath = $argv[1]; @@ -20,36 +20,28 @@ function processPhpFile($phpfile, $systemlib_php) { fwrite($systemlib_php, substr($contents, $k)); } -function searchDirForPhpFiles($searchPath, &$phpfiles) { - $list = scandir($searchPath); - $files = array(); - foreach ($list as $name) { - if ($name === '.' || $name === '..') continue; - $files[] = $searchPath . '/' . $name; - } - for ($i = 0; $i < count($files); ++$i) { - $file = $files[$i]; - if (is_dir($file)) { - $list = scandir($file); - foreach ($list as $name) { - if ($name === '.' || $name === '..') continue; - $files[] = $file . '/' . $name; - } - continue; - } - if (!preg_match('/\.php$/', $file)) continue; +function populatePhpFiles($input_files) { + $php_files = array(); + foreach ($input_files as $file) { $key = strtolower(basename($file)); - if (isset($phpfiles[$key])) { - $errMsg = "ERROR: Encountered multiple php files with the same name (" . - $file . " vs " . $phpfiles[$key] . ")"; + if (!preg_match('/\.php$/', $file)) { + $errMsg = "ERROR: Encountered non-php file ($file)"; echo $errMsg . "\n"; throw new Exception($errMsg); } - $phpfiles[$key] = $file; + if (isset($php_files[$key])) { + $errMsg = "ERROR: Encountered multiple php files with the same name (" . + $file . " vs " . $php_files[$key] . ")"; + echo $errMsg . "\n"; + throw new Exception($errMsg); + } + // calling Makefile machinery will use the truncated path, full is expected + $php_files[$key] = $_ENV['FBCODE_DIR'].'/'.$file; } + return $php_files; } -function genSystemlib() { +function genSystemlib($input_files) { global $scriptPath; global $outputPath; @@ -59,14 +51,7 @@ function genSystemlib() { try { $systemlib_php_tempnam = tempnam('/tmp', 'systemlib.php.tmp'); $systemlib_php = fopen($systemlib_php_tempnam, 'w'); - // Build up a list of all the .php files in hphp/system/classes - $phpfiles = array(); - $searchPath = realpath($scriptPath . '/../../system/classes'); - searchDirForPhpFiles($searchPath, $phpfiles); - $searchPath = realpath($scriptPath . '/../../system/classes_hhvm'); - searchDirForPhpFiles($searchPath, $phpfiles); - $searchPath = realpath($scriptPath . '/../../facebook/system/classes'); - searchDirForPhpFiles($searchPath, $phpfiles); + $phpfiles = populatePhpFiles($input_files); fwrite($systemlib_php, "