Subversion Repositories fastphp

Rev

Rev 28 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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