-
Notifications
You must be signed in to change notification settings - Fork 0
/
dumper.py
76 lines (62 loc) · 2.93 KB
/
dumper.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from assertions import assertType
from supertypes import SourceDumper
from source import SubroutineFullName
from printout import printInline, printLine
class SourceLineDumper(SourceDumper):
def dumpSubroutine(self, subroutineName):
assertType(subroutineName, 'subroutineName', SubroutineFullName)
subroutine = self._findSubroutine(subroutineName);
if subroutine is not None:
numberLength = len(str(subroutine.getLastLineNumber()));
for i, line in subroutine.getLines():
if (self._printLineNumbers):
printInline(str(i).zfill(numberLength) + ' ')
printInline(line)
def dumpModule(self, moduleName):
assertType(moduleName, 'moduleName', str)
module = self._findModule(moduleName);
if module is not None:
numberLength = len(str(module.getLastLineNumber()));
for i, line in module.getLines():
if (self._printLineNumbers):
printInline(str(i).zfill(numberLength) + ' ')
printInline(line)
def dumpSourceFile(self, fileName):
assertType(fileName, 'fileName', str)
sourceFile = self._findSourceFile(fileName);
if sourceFile is not None:
lines = sourceFile.getLines();
numberLength = len(str(len(lines)));
for i, line in lines:
if (self._printLineNumbers):
printInline(str(i).zfill(numberLength) + ' ')
printInline(line)
class SourceStatementDumper(SourceDumper):
def dumpSubroutine(self, subroutineName):
assertType(subroutineName, 'subroutineName', SubroutineFullName)
subroutine = self._findSubroutine(subroutineName);
if subroutine is not None:
numberLength = len(str(subroutine.getLastLineNumber()));
for i, statement, _ in subroutine.getStatements():
if (self._printLineNumbers):
printInline(str(i).zfill(numberLength) + ' ')
printLine(statement)
def dumpModule(self, moduleName):
assertType(moduleName, 'moduleName', str)
module = self._findModule(moduleName);
if module is not None:
numberLength = len(str(module.getLastLineNumber()));
for i, statement, _ in module.getStatements():
if (self._printLineNumbers):
printInline(str(i).zfill(numberLength) + ' ')
printLine(statement)
def dumpSourceFile(self, fileName):
assertType(fileName, 'fileName', str)
sourceFile = self._findSourceFile(fileName);
if sourceFile is not None:
statements = sourceFile.getStatements();
numberLength = len(str(len(statements)));
for i, statement, _ in statements:
if (self._printLineNumbers):
printInline(str(i).zfill(numberLength) + ' ')
printLine(statement)