Returns the first ancestor WhileContext of `ctxt`. Returns `ctxt` if `ctxt` is a WhileContext, or None if `ctxt` is not in a while loop. Args: ctxt: ControlFlowContext stop_ctxt: ControlFlowContext, optional. If provided, the search will end if it sees stop_ctxt. Returns:
(ctxt, stop_ctxt=None)
| 189 | |
| 190 | |
| 191 | def GetContainingWhileContext(ctxt, stop_ctxt=None): |
| 192 | """Returns the first ancestor WhileContext of `ctxt`. |
| 193 | |
| 194 | Returns `ctxt` if `ctxt` is a WhileContext, or None if `ctxt` is not in a |
| 195 | while loop. |
| 196 | |
| 197 | Args: |
| 198 | ctxt: ControlFlowContext |
| 199 | stop_ctxt: ControlFlowContext, optional. If provided, the search will end |
| 200 | if it sees stop_ctxt. |
| 201 | |
| 202 | Returns: |
| 203 | `ctxt` if `ctxt` is a WhileContext, the most nested WhileContext containing |
| 204 | `ctxt`, or None if `ctxt` is not in a while loop. If `stop_ctxt` is not |
| 205 | `None`, this returns `ctxt` if it matches `stop_ctxt` in its traversal. |
| 206 | """ |
| 207 | while ctxt: |
| 208 | if ctxt.IsWhileContext() or ctxt == stop_ctxt: return ctxt |
| 209 | ctxt = ctxt.outer_context |
| 210 | return None |
| 211 | |
| 212 | |
| 213 | def GetContainingXLAContext(ctxt): |
no test coverage detected