-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-deadcode.py
executable file
·49 lines (39 loc) · 1.06 KB
/
test-deadcode.py
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
#!/usr/bin/env python3
from lib.parser.parser import *
from semantic_analysis import *
def main():
from io import StringIO
testprog = StringIO('''
f(a, b) :: Int Int -> Int {
Int c = 5;
if(a > 3){
return False;
}
else {
return True;
}
a = a + 1;
}
''')
tokenstream = tokenize(testprog)
tokenlist = list(tokenstream)
parse_res = SPL.parse_strict(tokenlist, testprog)
# Build symbol table
ERROR_HANDLER.setSourceMapping(testprog, [])
symbol_table = buildSymbolTable(parse_res)
ERROR_HANDLER.checkpoint()
# Normalize table
normalizeAllTypes(symbol_table)
ERROR_HANDLER.checkpoint()
# Resolve Expr names
resolveNames(symbol_table)
ERROR_HANDLER.checkpoint()
# Parse expression
op_table = buildOperatorTable(symbol_table)
ast = fixExpression(parse_res, op_table)
ERROR_HANDLER.checkpoint()
# Test for deadcode
analyseFunc(parse_res.decls[0].val)
ERROR_HANDLER.checkpoint()
if __name__ == "__main__":
main()