summaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorVolker Weißmann <volker.weissmann@gmx.de>2025-03-16 23:01:03 +0100
committerDylan Baker <dylan@pnwbakers.com>2025-05-29 09:20:27 -0700
commit9c5c9745d02e2931e83e01ee6d055ccda6cfe14a (patch)
tree8f4f6a959c5194ecd1b89c482316195288504098 /unittests
parentad10057deb4705a937bf8ae1801ce3632fa49ff8 (diff)
downloadmeson-9c5c9745d02e2931e83e01ee6d055ccda6cfe14a.tar.gz
Add AstInterpreter.dataflow_dag
Make the AstInterpreter create a directed acyclic graph (called `dataflow_dag`) that stores the how the data flowes from one node in the AST to another. Add `AstInterpreter.node_to_runtime_value` which uses `dataflow_dag` to find what value a variable at runtime will have. We don't use dataflow_dag or node_to_runtime_value anywhere yet, but it will prove useful in future commits.
Diffstat (limited to 'unittests')
-rw-r--r--unittests/rewritetests.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/unittests/rewritetests.py b/unittests/rewritetests.py
index 0bd21c74f..70a80347e 100644
--- a/unittests/rewritetests.py
+++ b/unittests/rewritetests.py
@@ -433,3 +433,24 @@ class RewriterTests(BasePlatformTests):
}
}
self.assertDictEqual(out, expected)
+
+ # Asserts that AstInterpreter.dataflow_dag is what it should be
+ def test_dataflow_dag(self):
+ test_path = Path(self.rewrite_test_dir, '1 basic')
+ interpreter = IntrospectionInterpreter(test_path, '', 'ninja', visitors = [AstIDGenerator()])
+ interpreter.analyze()
+
+ def sortkey(node):
+ return (node.lineno, node.colno, node.end_lineno, node.end_colno)
+
+ def node_to_str(node):
+ return f"{node.__class__.__name__}({node.lineno}:{node.colno})"
+
+ dag_as_str = ""
+ for target in sorted(interpreter.dataflow_dag.tgt_to_srcs.keys(), key=sortkey):
+ dag_as_str += f"Data flowing to {node_to_str(target)}:\n"
+ for source in sorted(interpreter.dataflow_dag.tgt_to_srcs[target], key=sortkey):
+ dag_as_str += f" {node_to_str(source)}\n"
+
+ expected = Path(test_path / "expected_dag.txt").read_text().strip()
+ self.assertEqual(dag_as_str.strip(), expected)