4,48 → 4,81 |
|
error_reporting(0); |
|
define('ICON_TYPE_FUNCTION', 'FUN'); |
define('ICON_TYPE_CONSTRUCTOR', 'CST'); |
define('ICON_TYPE_DESTRUCTOR', 'DST'); |
define('ICON_TYPE_MAGICMETHOD', 'MAG'); |
define('ICON_TYPE_CLASS', 'CLS'); |
define('ICON_TYPE_TRAIT', 'TRA'); |
define('ICON_TYPE_INTERFACE', 'INT'); |
define('ICON_TYPE_VAR', 'VAR'); |
define('ICON_TYPE_CONST', 'CON'); |
define('ICON_TYPE_TODO', 'TDO'); |
define('ICON_TYPE_ERROR', 'ERR'); |
require_once __DIR__ . '/codeexplorer_api.inc.php'; |
|
while (true) { |
$code = FastNodeReader::readCodeFromEditor(); |
define('ICON_TYPE_FUNCTION', 1); |
define('ICON_TYPE_CONSTRUCTOR', 2); |
define('ICON_TYPE_DESTRUCTOR', 3); |
define('ICON_TYPE_MAGICMETHOD', 4); |
define('ICON_TYPE_CLASS', 5); |
define('ICON_TYPE_TRAIT', 6); |
define('ICON_TYPE_INTERFACE', 7); |
define('ICON_TYPE_VAR', 8); |
define('ICON_TYPE_CONST', 9); |
define('ICON_TYPE_TODO', 10); |
define('ICON_TYPE_ERROR', 11); |
|
$x = token_get_all($code); |
class MyFastPHPIcon extends FastPHPIcon { |
|
public function imageIndex() { |
if (($this->getType() == ICON_TYPE_CLASS) && (!$this->isAbstract())) return 0; // class |
else if (($this->getType() == ICON_TYPE_CLASS) && ( $this->isAbstract())) return 1; // abstract class |
else if (($this->getType() == ICON_TYPE_INTERFACE) ) return 2; // interface |
else if (($this->getType() == ICON_TYPE_TRAIT) ) return 3; // trait |
else if (($this->getType() == ICON_TYPE_CONST) && ($this->isPrivate()) ) return 4; // private const |
else if (($this->getType() == ICON_TYPE_VAR) && ($this->isPrivate()) ) return 5; // private var |
else if (($this->isMethod()) && ($this->isPrivate()) && (!$this->isAbstract())) return 6; // private function |
else if (($this->isMethod()) && ($this->isPrivate()) && ( $this->isAbstract())) return 7; // private abstract function |
else if (($this->getType() == ICON_TYPE_CONST) && ($this->isProtected()) ) return 8; // protected const |
else if (($this->getType() == ICON_TYPE_VAR) && ($this->isProtected()) ) return 9; // protected var |
else if (($this->isMethod()) && ($this->isProtected()) && (!$this->isAbstract())) return 10; // protected function |
else if (($this->isMethod()) && ($this->isProtected()) && ( $this->isAbstract())) return 11; // protected abstract function |
else if (($this->getType() == ICON_TYPE_CONST) && ($this->isPublic()) ) return 12; // public const |
else if (($this->getType() == ICON_TYPE_VAR) && ($this->isPublic()) ) return 13; // public var |
else if (($this->isMethod()) && ($this->isPublic()) && (!$this->isAbstract())) return 14; // public function |
else if (($this->isMethod()) && ($this->isPublic()) && ( $this->isAbstract())) return 15; // public abstract function |
else if (($this->getType() == ICON_TYPE_TODO) ) return 16; // ToDo comment |
else return -1; |
} |
|
public function isMethod() { |
return (($this->getType() == ICON_TYPE_FUNCTION) || |
($this->getType() == ICON_TYPE_CONSTRUCTOR) || |
($this->getType() == ICON_TYPE_DESTRUCTOR) || |
($this->getType() == ICON_TYPE_MAGICMETHOD)); |
} |
|
} |
|
class MyFastPHPCodeExplorer { |
|
public function handle($code) { |
$token = token_get_all($code); |
$wait_function = false; |
$wait_const = false; |
$wait_class = false; |
$wait_trait = false; |
$icon = new MyFastPHPIcon(); |
$wait_interface = false; |
$wait_abstract_func_list_end = false; |
$levelAry = array(); |
$icon = new FastPHPIcon(); |
$dep = 0; |
$insideFuncAry = array(); |
|
echo FastNodeWriter::outputHeader(); |
|
if (!$x) { |
if (!$token) { |
$icon->setType(ICON_TYPE_ERROR); |
echo FastNodeWriter::outputLeafNode($icon, 1, 'SYNTAX ERROR'); |
FastPHPWriter::outputLeafNode($icon, 0, 'SYNTAX ERROR'); |
} |
|
foreach ($x as $n => $data) { |
foreach ($token as $data) { |
if ($data == '{') $dep++; |
if ($data == '}') { |
$dep--; |
if ((count($levelAry) > 0) && (array_peek($levelAry) == $dep)) { |
if ((count($levelAry) > 0) && (self::array_peek($levelAry) == $dep)) { |
array_pop($levelAry); |
echo FastNodeWriter::outputDecreaseLevel(); |
FastPHPWriter::outputDecreaseLevel(); |
} |
if ((count($insideFuncAry) > 0) && (array_peek($insideFuncAry) == $dep)) { |
if ((count($insideFuncAry) > 0) && (self::array_peek($insideFuncAry) == $dep)) { |
array_pop($insideFuncAry); |
} |
} |
73,7 → 106,7 |
} else { |
$icon->setType(ICON_TYPE_FUNCTION); |
} |
echo FastNodeWriter::outputLeafNode($icon, $line, $desc); |
FastPHPWriter::outputLeafNode($icon, $line, $desc); |
$icon->reset(); |
} |
|
87,10 → 120,10 |
$levelAry[] = $dep; |
|
$icon->setType(ICON_TYPE_CLASS); |
echo FastNodeWriter::outputLeafNode($icon, $line, $desc); |
FastPHPWriter::outputLeafNode($icon, $line, $desc); |
$icon->reset(); |
|
echo FastNodeWriter::outputIncreaseLevel(); |
FastPHPWriter::outputIncreaseLevel(); |
} |
|
if ($wait_trait && ($token == T_STRING)) { |
99,10 → 132,10 |
$levelAry[] = $dep; |
|
$icon->setType(ICON_TYPE_TRAIT); |
echo FastNodeWriter::outputLeafNode($icon, $line, $desc); |
FastPHPWriter::outputLeafNode($icon, $line, $desc); |
$icon->reset(); |
|
echo FastNodeWriter::outputIncreaseLevel(); |
FastPHPWriter::outputIncreaseLevel(); |
} |
|
if ($wait_interface && ($token == T_STRING)) { |
111,10 → 144,10 |
$levelAry[] = $dep; |
|
$icon->setType(ICON_TYPE_INTERFACE); |
echo FastNodeWriter::outputLeafNode($icon, $line, $desc); |
FastPHPWriter::outputLeafNode($icon, $line, $desc); |
$icon->reset(); |
|
echo FastNodeWriter::outputIncreaseLevel(); |
FastPHPWriter::outputIncreaseLevel(); |
} |
|
if ($wait_const && ($token == T_STRING)) { |
122,7 → 155,7 |
$wait_const = false; |
|
$icon->setType(ICON_TYPE_CONST); |
echo FastNodeWriter::outputLeafNode($icon, $line, $desc); |
FastPHPWriter::outputLeafNode($icon, $line, $desc); |
$icon->reset(); |
} |
|
130,7 → 163,7 |
$desc = "$value\n"; |
|
$icon->setType(ICON_TYPE_VAR); |
echo FastNodeWriter::outputLeafNode($icon, $line, $desc); |
FastPHPWriter::outputLeafNode($icon, $line, $desc); |
$icon->reset(); |
} |
|
166,23 → 199,18 |
$wait_const = true; |
} |
|
if (($token == T_COMMENT) && _isToDoDescription($value)) { |
if (($token == T_COMMENT) && self::isToDoDescription($value)) { |
// Because a TO-DO-entry can stand everywhere (e.g. between a "private" and a "function") |
// we shall not alter the $icon instance |
$todoIcon = clone $icon; |
$todoIcon->setType(ICON_TYPE_TODO); |
echo FastNodeWriter::outputLeafNode($todoIcon, $line, strip_comment($value)); |
unset($todoIcon); |
FastPHPWriter::outputLeafNode($todoIcon, $line, self::stripComment($value)); |
} |
} |
|
echo FastNodeWriter::outputExit(); |
|
echo FastNodeWriter::signalOutputEnd(); |
|
sleep(1); |
} |
|
function _isToDoDescription($comment) { |
private static function isToDoDescription($comment) { |
return ((stripos($value, 'TODO') !== false) || |
(stripos($value, 'BUGBUG') !== false) || |
(stripos($value, 'FIXME') !== false) || |
189,159 → 217,29 |
(stripos($value, 'XXX') !== false)); |
} |
|
function _iconCodeToIndex(/* FastPHPIcon */ $icon) { |
if (($icon->getType() == ICON_TYPE_CLASS) && (!$icon->isAbstract())) return 0; // class |
else if (($icon->getType() == ICON_TYPE_CLASS) && ( $icon->isAbstract())) return 1; // abstract class |
else if (($icon->getType() == ICON_TYPE_INTERFACE) ) return 2; // interface |
else if (($icon->getType() == ICON_TYPE_TRAIT) ) return 3; // trait |
else if (($icon->getType() == ICON_TYPE_CONST) && ($icon->isPrivate()) ) return 4; // private const |
else if (($icon->getType() == ICON_TYPE_VAR) && ($icon->isPrivate()) ) return 5; // private var |
else if (($icon->isMethod()) && ($icon->isPrivate()) && (!$icon->isAbstract())) return 6; // private function |
else if (($icon->isMethod()) && ($icon->isPrivate()) && ( $icon->isAbstract())) return 7; // private abstract function |
else if (($icon->getType() == ICON_TYPE_CONST) && ($icon->isProtected()) ) return 8; // protected const |
else if (($icon->getType() == ICON_TYPE_VAR) && ($icon->isProtected()) ) return 9; // protected var |
else if (($icon->isMethod()) && ($icon->isProtected()) && (!$icon->isAbstract())) return 10; // protected function |
else if (($icon->isMethod()) && ($icon->isProtected()) && ( $icon->isAbstract())) return 11; // protected abstract function |
else if (($icon->getType() == ICON_TYPE_CONST) && ($icon->isPublic()) ) return 12; // public const |
else if (($icon->getType() == ICON_TYPE_VAR) && ($icon->isPublic()) ) return 13; // public var |
else if (($icon->isMethod()) && ($icon->isPublic()) && (!$icon->isAbstract())) return 14; // public function |
else if (($icon->isMethod()) && ($icon->isPublic()) && ( $icon->isAbstract())) return 15; // public abstract function |
else if (($icon->getType() == ICON_TYPE_TODO) ) return 16; // ToDo comment |
else return -1; |
private static function stripComment($x) { |
if (substr($x, 0, 1) == '#') return trim(substr($x, 1)); |
if (substr($x, 0, 2) == '//') return trim(substr($x, 2)); |
if (substr($x, 0, 2) == '/*') return trim(substr($x, 2, strlen($x)-4)); |
} |
|
class FastPHPIcon { |
private $type; // ICON_TYPE_* |
private $visibility; // 1=private, 2=protected, 3=public(default) |
private $abstractFinal; // 'A', 'F', ''(default) |
private $static; // true, false(default) |
|
public function setType($type) { |
$this->type = $type; |
private static final function array_peek($array) { |
if (!isset($array[count($array)-1])) return null; |
return $array[count($array)-1]; |
} |
public function getType() { |
return $this->type; |
} |
|
public function setAbstract() { |
$this->abstractFinal = 'A'; |
$parser = new MyFastPHPCodeExplorer($icon); |
while (true) { |
try { |
$code = FastPHPReader::readCodeFromEditor(); |
} catch (FastPHPExitSignalReceivedException $e) { |
die(); |
} |
public function isAbstract() { |
return $this->abstractFinal == 'A'; |
FastPHPWriter::outputHeader(); |
$parser->handle($code); |
FastPHPWriter::outputExit(); |
FastPHPWriter::signalOutputEnd(); |
sleep(1); |
} |
|
public function setFinal() { |
$this->abstractFinal = 'F'; |
} |
public function isFinal() { |
return $this->abstractFinal == 'F'; |
} |
|
public function setStatic() { |
$this->static = true; |
} |
public function isStatic() { |
return $this->static; |
} |
|
public function setPrivate() { |
$this->visibility = 1; |
} |
public function isPrivate() { |
return $this->visibility == 1; |
} |
|
public function setProtected() { |
$this->visibility = 2; |
} |
public function isProtected() { |
return $this->visibility == 2; |
} |
|
public function setPublic() { |
$this->visibility = 3; |
} |
public function isPublic() { |
return $this->visibility == 3; |
} |
|
public function isMethod() { |
return (($this->type == ICON_TYPE_FUNCTION) || |
($this->type == ICON_TYPE_CONSTRUCTOR) || |
($this->type == ICON_TYPE_DESTRUCTOR) || |
($this->type == ICON_TYPE_MAGICMETHOD)); |
} |
|
public function reset() { |
$this->type = null; |
$this->visibility = 3; |
$this->abstractFinal = ''; |
$this->static = false; |
} |
|
public function __construct() { |
$this->reset(); |
} |
} |
|
class FastNodeReader { |
public static function readCodeFromEditor() { |
$lines = array(); |
while ($f = fgets(STDIN)){ |
if (trim($f) == chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8)) break; |
|
// Signal to terminate the code explorer |
if (trim($f) == chr(8).chr(7).chr(6).chr(5).chr(4).chr(3).chr(2).chr(1)) { |
die("\n".chr(8).chr(7).chr(6).chr(5).chr(4).chr(3).chr(2).chr(1)."\n"); |
} |
|
$lines[] = $f; |
} |
return implode("", $lines); |
} |
} |
|
class FastNodeWriter { |
|
public static function outputLeafNode(/* FastPHPIcon */ $icon, $lineNo, $description) { |
$imageindex = _iconCodeToIndex($icon); |
return 'N'.($imageindex == -1 ? '____' : sprintf('%04s', $imageindex)). |
sprintf('%08s', $lineNo). |
sprintf('%04s', strlen(trim($description))). |
trim($description). |
"\n"; |
} |
|
public static function outputIncreaseLevel() { |
return "I\n"; |
} |
|
public static function outputDecreaseLevel() { |
return "D\n"; |
} |
|
public static function outputExit() { |
return "X\n"; |
} |
|
public static function signalOutputEnd() { |
return "\n".chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8)."\n"; |
} |
|
public static function outputHeader() { |
return "FAST100!"; |
} |
|
} |
|
function array_peek($array) { |
if (!isset($array[count($array)-1])) return null; |
return $array[count($array)-1]; |
} |
|
function strip_comment($x) { |
if (substr($x, 0, 1) == '#') return trim(substr($x, 1)); |
if (substr($x, 0, 2) == '//') return trim(substr($x, 2)); |
if (substr($x, 0, 2) == '/*') return trim(substr($x, 2, strlen($x)-4)); |
} |
|