Subversion Repositories fastphp

Rev

Rev 28 | Rev 32 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. // TODO: Parsing der Datei codeexplorer.php bricht einfach so ab?
  4.  
  5. define('ICON_ATTR_PUBLIC',           1);
  6. define('ICON_ATTR_PRIVATE',          2);
  7. define('ICON_ATTR_PROTECTED',        4);
  8. define('ICON_ATTR_ABSTRACT',         8);
  9. define('ICON_ATTR_STATIC',          16);
  10. define('ICON_ATTR_CONST',           32);
  11. define('ICON_ATTR_VAR',             64);
  12. define('ICON_ATTR_FUNCTION',       128);
  13. define('ICON_ATTR_CONSTRUCTOR',    256);
  14. define('ICON_ATTR_DESTRUCTOR',     512);
  15. define('ICON_ATTR_MAGICMETHOD',   1024);
  16. define('ICON_ATTR_CLASS',         2048);
  17. define('ICON_ATTR_TRAIT',         4096);
  18. define('ICON_ATTR_INTERFACE',     8192);
  19.  
  20. error_reporting(0);
  21.  
  22. while (true) {
  23.         $lines = array();
  24.         while ($f = fgets(STDIN)){
  25.                 if (trim($f) == chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8)) break;
  26.                 $lines[] = $f;
  27.         }
  28.         $code = implode("", $lines);
  29.  
  30.         echo "FAST100!\n";
  31.        
  32.         $code = str_replace(chr(0), '', $code); // TODO: attention: delphi outputs unicode here!!!! find solution.
  33.  
  34.         $x = token_get_all($code);
  35.        
  36.         // file_put_contents('debug.tmp', $code);
  37.        
  38.         if (!$x) {
  39.                 // TODO: when this happens, do not update the output in the editor...
  40.                 echo _outputLeafNode(2048, 1, 'SYNTAX ERROR');
  41.         }
  42.        
  43.         //print_r($x); // debug
  44.         $wait_function = false;
  45.         $wait_class = false;
  46.         $class = array();
  47.         $icon_add_flags = 0;
  48.         $dep = 0;
  49.  
  50.         foreach ($x as $n => $data) {
  51.                 if ($data == '{') $dep++;
  52.                 if ($data == '}') {
  53.                         $dep--;
  54.                         if ((count($class) > 0) && (array_peek($class)[1] == $dep)) {
  55.                                 array_pop($class);
  56.                                 echo _outputDecreaseLevel();
  57.                         }
  58.                 }
  59.  
  60.                 $token = (!is_array($data)) ? null : $data[0];
  61.                 $value = (!is_array($data)) ? null : $data[1];
  62.                 $line = (!is_array($data)) ? null : $data[2];
  63.  
  64.                 if ($wait_function && ($token == T_STRING)) {
  65.                         $desc = "function ";
  66.                         /*
  67.                         foreach ($class as $cdata) {
  68.                                 $desc .= $cdata[0].'->';
  69.                         }
  70.                         */
  71.                         $desc .= "$value()";
  72.                         $icon_add_flags = 0;
  73.                         $wait_function = false;
  74.  
  75.                         if ($value == '__construct') { // TODO: auch eine methode mit dem namen der klasse soll eine konstruktor sein
  76.                                 echo _outputLeafNode(ICON_ATTR_CONSTRUCTOR | $icon_add_flags, $line, $desc);
  77.                         } else if ($value == '__destruct') {
  78.                                 echo _outputLeafNode(ICON_ATTR_DESTRUCTOR  | $icon_add_flags, $line, $desc);
  79.                         } else if (substr($value, 0, 2) == '__') {
  80.                                 echo _outputLeafNode(ICON_ATTR_MAGICMETHOD | $icon_add_flags, $line, $desc);
  81.                         } else {
  82.                                 echo _outputLeafNode(ICON_ATTR_FUNCTION    | $icon_add_flags, $line, $desc);
  83.                         }
  84.                 }
  85.  
  86.                 if ($wait_class && ($token == T_STRING)) {
  87.                         $desc = "Class ";
  88.                         /*
  89.                         foreach ($class as $cdata) {
  90.                                 $desc .= $cdata[0].'->';
  91.                         }
  92.                         */
  93.                         $desc .= "$value\n";
  94.                         $class[] = array($value, $dep);
  95.                         $wait_class = false;
  96.  
  97.                         echo _outputLeafNode(ICON_ATTR_CLASS | $icon_add_flags, $line, $desc);
  98.                         echo _outputIncreaseLevel();
  99.                 }
  100.  
  101.                 if ($token == T_PUBLIC)    $icon_add_flags |= ICON_ATTR_PUBLIC;
  102.                 if ($token == T_PRIVATE)   $icon_add_flags |= ICON_ATTR_PRIVATE;
  103.                 if ($token == T_PROTECTED) $icon_add_flags |= ICON_ATTR_PROTECTED;
  104.                 if ($token == T_STATIC)    $icon_add_flags |= ICON_ATTR_STATIC;
  105.                 if (($data == ';') || ($data == '{') || ($data == '}')) $icon_add_flags = 0;
  106.  
  107.                 if ($token == T_FUNCTION) {
  108.                         $wait_function = true;
  109.                 }
  110.                 if ($token == T_CLASS) {
  111.                         $wait_class = true;
  112.                         $dep = 0;
  113.                 }
  114.  
  115.                 if ($token == T_COMMENT) {
  116.                         if (stripos($value, 'TODO') !== false) {
  117.                                 echo _outputLeafNode(0/*TODO*/, $line, $value);
  118.                         }
  119.                 }
  120.         }
  121.        
  122.         echo _outputExit();
  123.  
  124.         echo chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8);
  125.  
  126.         sleep(1);
  127. }
  128.  
  129. function _outputLeafNode($icon, $line, $description) {
  130.         return 'N'.
  131.              sprintf('%08s', $icon).
  132.              sprintf('%08s', $line).
  133.              sprintf('%04s', strlen($description)).
  134.              $description;
  135. }
  136.  
  137. function _outputIncreaseLevel() {
  138.         return 'I';
  139. }
  140.  
  141. function _outputDecreaseLevel() {
  142.         return 'D';
  143. }
  144.  
  145. function _outputExit() {
  146.         return 'X';
  147. }
  148.  
  149. function array_peek($array) {
  150.         if (!isset($array[count($array)-1])) return null;
  151.         return $array[count($array)-1];
  152. }
  153.  
  154. function strip_comment($x) {
  155.         if (substr($x, 0, 1) == '#') return trim(substr($x, 1));
  156.         if (substr($x, 0, 2) == '//') return trim(substr($x, 2));
  157.         if (substr($x, 0, 2) == '/*') return trim(substr($x, 2, strlen($x)-4));
  158. }
  159.  
  160.  
  161. // TODO: hallo
  162. # TODO: xxx
  163.