-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutputs.py
122 lines (85 loc) · 3.15 KB
/
outputs.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
class Output(object):
def __init__(self, indent=0):
super().__init__()
self.indent = indent
def write(self, text):
print(text)
class PipeOutput(Output):
def __init__(self, output, indent=0):
super().__init__(indent=indent)
self.output = output
def write(self, text):
self.output.write(text)
class FileOutput(Output):
def __init__(self, file, indent=0):
super().__init__(indent=indent)
self.file = file
def write(self, text):
self.file.write(text)
class VariablesOutput(Output):
def __init__(self, variables, indent=0, var_type=False):
super().__init__(indent=indent)
self.variables = variables
self.var_type = var_type
def write(self, text):
if not self.var_type:
if text == "\n":
self.variables.variables[-1].append("")
else:
self.variables.variables[-1][-1] += text
else:
self.variables.var_types[-1] += text
class FunctionParametersOutput(Output):
def __init__(self, function, indent=0, var_type=False):
super().__init__(indent=indent)
self.function = function
self.var_type = var_type
def write(self, text):
if self.function.local_variables is not None:
if not self.var_type:
if text == "\n":
self.function.local_variables[-1].append("")
else:
self.function.local_variables[-1][-1] += text
else:
self.function.local_types[-1] += text
elif self.function.variables is not None:
if not self.var_type:
if text == "\n":
self.function.variables[-1].append("")
else:
self.function.variables[-1][-1] += text
else:
self.function.var_types[-1] += text
class FunctionArgumentOutput(Output):
def __init__(self, function_call, indent=0):
super().__init__(indent=indent)
self.function_call = function_call
def write(self, text):
self.function_call.arguments[-1] += text
class AssignmentOutput(Output):
def __init__(self, assignment, indent=0):
super().__init__(indent=indent)
self.assignment = assignment
def write(self, text):
self.assignment.rhs += text
class ConditionalOutput(Output):
def __init__(self, condition, indent=0):
super().__init__(indent=indent)
self.condition = condition
def write(self, text):
self.condition.condition += text
class ForLoopOutput(Output):
def __init__(self, for_loop, indent=0):
super().__init__(indent=indent)
self.for_loop = for_loop
def write(self, text):
if self.for_loop.increment is not None:
self.for_loop.increment += text
elif self.for_loop.end_value is not None:
self.for_loop.end_value += text
elif self.for_loop.start_value is not None:
self.for_loop.start_value += text
elif self.for_loop.variable is not None:
self.for_loop.variable += text