What is the best way to capture usage of another function within another function? #109
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Good questions! The premise of how stack graphs work is that we process of name resolution, i.e. linking references to definitions, is essentially split up in two parts. The first part constructs a stack graph that should result in references being able to reach definitions. They do not necessarily have to be connected to them in a single step. This first part is what we use TSG for. The rules convert the program into a graph, but do this using fairly local information. We may create edges between the nodes of parents and children in the syntax tree, but usually not further than that. The second part does a search in the graph to find the definitions that match references. This part traverses the edges, and can possible find reachable definitions that originated in parts of the program far from where the references is located. This is the non-local part. However, you don't have to program this directly, you rely on the path finding algorithm of the stack graph, and the structure of the constructed graph. Given these two things, let's consider your example. (I'll just consider a single file here.) The The diagram would look something like this now: flowchart LR
file_node(FILE_NODE)
bar_def[bar]
barbar_def[barbar]
foo_def[foo]
foo_scope(foo.scope)
bar_ref[bar]
barbar_ref[barbar]
file_node --> bar_def
file_node --> barbar_def
file_node --> foo_def
foo_scope --> file_node
bar_ref --> foo_scope
barbar_ref --> foo_scope
Finally, to debug the TSG rules you're writing, it is helpful to write tests. See this example. The comments say how you expect the reference to resolve (to which line). Run the test with |
Beta Was this translation helpful? Give feedback.
Good questions! The premise of how stack graphs work is that we process of name resolution, i.e. linking references to definitions, is essentially split up in two parts.
The first part constructs a stack graph that should result in references being able to reach definitions. They do not necessarily have to be connected to them in a single step. This first part is what we use TSG for. The rules convert the program into a graph, but do this using fairly local information. We may create edges between the nodes of parents and children in the syntax tree, but usually not further than that.
The second part does a search in the graph to find the definitions that match references. This part trave…