google / tangent

Source-to-Source Debuggable Derivatives in Pure Python
Apache License 2.0
2.32k stars 434 forks source link

How are CFG.visit_Break and CFG.visit_Continue get called? #78

Closed wangkuiyi closed 6 years ago

wangkuiyi commented 6 years ago

Hello Tangent Authors,

I got a question as the title of this issue.

I see that class CFG is a subclass of gast.NodeVisitor and it has some visit methods. The only place I noticed that would get these visit methods called is in the CFG.visit_statements method:

https://github.com/google/tangent/blob/3318ecab3eec71ef97702df66a59d1a2197c8de3/tangent/cfg.py#L112-L113

where gast.NodeVisitor.visit is called only if the current statement under interest is a control-flow, which includes the following kinds of statements:

https://github.com/google/tangent/blob/3318ecab3eec71ef97702df66a59d1a2197c8de3/tangent/grammar.py#L20

My question is that the above tuple doesn't include Break or Continue, whereas the class CFG has visit_Break and visit_Continue:

https://github.com/google/tangent/blob/3318ecab3eec71ef97702df66a59d1a2197c8de3/tangent/cfg.py#L159

https://github.com/google/tangent/blob/3318ecab3eec71ef97702df66a59d1a2197c8de3/tangent/cfg.py#L162

Are these two visit methods get called from somewhere else I didn't notice?

Thank you!

wangkuiyi commented 6 years ago

Sorry for bothering. I just realized that the invocation to visit inside visit_statements would check inside the loop and conditional structures.