Lines Matching refs:self
27 def __init__(self, statement, line_no, variables): argument
28 self.statement = statement
29 self.line_no = line_no
30 self.variables = variables
34 def __init__(self, msg, line_no): argument
35 self.msg = msg
36 self.line_no = line_no
69 def __init__(self): argument
70 self.stack = []
72 def can_execute(self): argument
77 if self._is_empty():
79 return abs(self._peek()) == IfStack.BRANCH_TAKEN
81 def handle(self, statement, variables): argument
88 self._if(statement, variables)
90 self._elif(statement, variables)
92 self._else(statement)
95 self._fi(statement)
97 def eof(self): argument
101 if not self._is_empty():
104 def _is_empty(self): argument
105 return not self.stack
107 def _if(self, statement, variables): argument
108 if not self._is_empty() and abs(self._peek()) in [IfStack.BRANCH_NOT_TAKEN,
110 self._push(IfStack.BRANCH_NOT_TAKEN)
112 self._push(IfStack.BRANCH_TAKEN)
114 self._push(IfStack.BRANCH_NOT_TAKEN_YET)
116 def _elif(self, statement, variables): argument
117 if self._is_empty():
120 if self._peek() < 0:
122 if self._peek() == IfStack.BRANCH_TAKEN:
123 self._set_last(IfStack.BRANCH_NOT_TAKEN)
124 elif self._peek() == IfStack.BRANCH_NOT_TAKEN_YET:
126 self._set_last(IfStack.BRANCH_TAKEN)
130 assert self._peek() == IfStack.BRANCH_NOT_TAKEN
132 def _else(self, statement): argument
133 if self._is_empty():
136 if self._peek() < 0:
138 if self._peek() in [IfStack.BRANCH_TAKEN, IfStack.BRANCH_NOT_TAKEN]:
141 self._set_last(-IfStack.BRANCH_NOT_TAKEN)
143 assert self._peek() == IfStack.BRANCH_NOT_TAKEN_YET
145 self._set_last(-IfStack.BRANCH_TAKEN)
147 def _fi(self, statement): argument
148 if self._is_empty():
150 self.stack.pop()
152 def _peek(self): argument
153 assert not self._is_empty()
154 return self.stack[-1]
156 def _push(self, element): argument
157 self.stack.append(element)
159 def _set_last(self, element): argument
160 self.stack[-1] = element
184 def __init__(self, c1_pass, variables={}): argument
185 self.cursor = 0
186 self.c1_pass = c1_pass
187 self.c1_length = len(c1_pass.body)
188 self.variables = ImmutableDict(variables)
189 self.dag_queue = []
190 self.not_queue = []
191 self.if_stack = IfStack()
192 self.last_variant = None
194 def move_cursor(self, match): argument
195 assert self.cursor <= match.scope.end
198 self.handle_not_queue(MatchScope(self.cursor, match.scope.start))
200 self.cursor = match.scope.end + 1
201 self.variables = match.variables
203 def handle_dag_queue(self, scope): argument
214 if not self.dag_queue:
218 variables = self.variables
220 for statement in self.dag_queue:
222 match = find_matching_line(statement, self.c1_pass, scope, variables, matched_lines)
229 self.dag_queue = []
230 self.move_cursor(match)
232 def handle_not_queue(self, scope): argument
238 for statement in self.not_queue:
241 if match_lines(statement, self.c1_pass.body[i], self.variables) is not None:
242 raise MatchFailedException(statement, i, self.variables)
243 self.not_queue = []
245 def handle_eof(self): argument
247 match = MatchInfo(MatchScope(self.c1_length, self.c1_length), None)
248 self.move_cursor(match)
250 def handle_in_order(self, statement): argument
256 scope = MatchScope(self.cursor, self.c1_length)
257 match = find_matching_line(statement, self.c1_pass, scope, self.variables)
258 self.move_cursor(match)
260 def handle_next_line(self, statement): argument
266 if self.last_variant not in [TestStatement.Variant.IN_ORDER, TestStatement.Variant.NEXT_LINE]:
271 scope = MatchScope(self.cursor, self.cursor + 1)
272 match = find_matching_line(statement, self.c1_pass, scope, self.variables)
273 self.move_cursor(match)
275 def handle_eval(self, statement): argument
280 if not evaluate_line(statement, self.variables):
281 raise MatchFailedException(statement, self.cursor, self.variables)
283 def handle(self, statement): argument
290 self.if_stack.handle(statement, self.variables)
294 self.if_stack.eof()
296 if not self.if_stack.can_execute():
302 self.handle_dag_queue(MatchScope(self.cursor, self.c1_length))
305 self.handle_eof()
307 self.handle_in_order(statement)
309 self.handle_next_line(statement)
311 self.dag_queue.append(statement)
313 self.not_queue.append(statement)
316 self.handle_eval(statement)
318 self.last_variant = variant