-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpreprocessor.php
60 lines (49 loc) · 1.45 KB
/
preprocessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter;
use PhpParser\Node;
require_once 'symbolTable.php';
class Preprocessor {
public $stmts;
public $sym_table;
public function __construct($tree) {
$this->stmts = $tree;
$this->sym_table = new SymbolTable();
}
public function renameClass() {
return $this->stmts;
}
public function do_statements() {
foreach ($this->stmts as $stmt) {
if ($stmt instanceof Node\Expr) {
$this->do_expression($stmt);
}
else {
// todo
echo "You hit an unimplemented feature!!";
exit(1);
}
}
}
public function do_expression($expr) {
if ($expr instanceof Node\Expr\Assign) {
$this->do_assignment($expr);
}
else if ($expr instanceof Node\Expr\PropertyFetch) {
$this->sym_table->registerClass($expr->var->name);
}
else if ($expr instanceof PhpParser\Node\Expr\New_) {
$this->sym_table->registerClass($expr->class->parts[0]);
}
else {
// todo
echo "You hit an unimplemented feature!!";
exit(1);
}
}
public function do_assignment($expr) {
$this->do_expression($expr->left);
$this->do_expression($expr->right);
}
}