diff --git a/crates/codegen/testing/src/bindings.rs b/crates/codegen/testing/src/bindings.rs new file mode 100644 index 000000000..04cb78831 --- /dev/null +++ b/crates/codegen/testing/src/bindings.rs @@ -0,0 +1,116 @@ +use std::collections::{BTreeMap, BTreeSet}; +use std::fmt::Write; +use std::path::Path; + +use anyhow::{bail, Result}; +use codegen_language_definition::model::Language; +use inflector::Inflector; +use infra_utils::codegen::CodegenFileSystem; +use infra_utils::paths::FileWalker; + +pub fn generate_bindings_tests( + _language: &Language, + data_dir: &Path, + output_dir: &Path, +) -> Result<()> { + let bindings_tests = collect_bindings_tests(data_dir)?; + + let mut fs = CodegenFileSystem::new(data_dir)?; + + generate_mod_file(&mut fs, &output_dir.join("mod.rs"), &bindings_tests)?; + + for (group_name, test_files) in &bindings_tests { + generate_unit_test_file( + &mut fs, + group_name, + test_files, + &output_dir.join(format!("{0}.rs", group_name.to_snake_case())), + )?; + } + + Ok(()) +} + +fn collect_bindings_tests(data_dir: &Path) -> Result>> { + let mut bindings_tests = BTreeMap::>::new(); + + for file in FileWalker::from_directory(data_dir).find(["**/*.sol"])? { + let parts: Vec<_> = file + .strip_prefix(data_dir)? + .iter() + .map(|p| p.to_str().unwrap()) + .collect(); + + match parts[..] { + [group_name, test_file] => { + bindings_tests + .entry(group_name.to_owned()) + .or_default() + .insert(test_file.to_owned()); + } + _ => { + bail!("Invalid test input. Should be in the form of '/GROUP_NAME/TEST_FILE.sol', but found: {file:?}"); + } + }; + } + + Ok(bindings_tests) +} + +fn generate_mod_file( + fs: &mut CodegenFileSystem, + mod_file_path: &Path, + bindings_tests: &BTreeMap>, +) -> Result<()> { + let module_declarations_str = + bindings_tests + .keys() + .fold(String::new(), |mut buffer, group_name| { + writeln!(buffer, "mod {0};", group_name.to_snake_case()).unwrap(); + buffer + }); + + let contents = format!( + " + {module_declarations_str} + ", + ); + + fs.write_file(mod_file_path, contents) +} + +fn generate_unit_test_file( + fs: &mut CodegenFileSystem, + group_name: &str, + test_files: &BTreeSet, + unit_test_file_path: &Path, +) -> Result<()> { + let unit_tests_str = test_files + .iter() + .fold(String::new(), |mut buffer, test_file| { + let test_name = test_file.strip_suffix(".sol").unwrap(); + writeln!( + buffer, + r#" + #[test] + fn {test_name}() -> Result<()> {{ + run("{group_name}", "{test_file}") + }} + "# + ) + .unwrap(); + buffer + }); + + let contents = format!( + " + use anyhow::Result; + + use crate::bindings::runner::run; + + {unit_tests_str} + " + ); + + fs.write_file(unit_test_file_path, contents) +} diff --git a/crates/codegen/testing/src/lib.rs b/crates/codegen/testing/src/lib.rs index 1ac29db58..fc4057a23 100644 --- a/crates/codegen/testing/src/lib.rs +++ b/crates/codegen/testing/src/lib.rs @@ -1,3 +1,4 @@ +mod bindings; mod cst_output; use std::path::Path; @@ -5,14 +6,19 @@ use std::path::Path; use anyhow::Result; use codegen_language_definition::model::Language; +use crate::bindings::generate_bindings_tests; use crate::cst_output::generate_cst_output_tests; pub trait TestingGeneratorExtensions { fn generate_cst_output_tests(&self, snapshots_dir: &Path, output_dir: &Path) -> Result<()>; + fn generate_bindings_tests(&self, snapshots_dir: &Path, output_dir: &Path) -> Result<()>; } impl TestingGeneratorExtensions for Language { fn generate_cst_output_tests(&self, data_dir: &Path, output_dir: &Path) -> Result<()> { generate_cst_output_tests(self, data_dir, output_dir) } + fn generate_bindings_tests(&self, data_dir: &Path, output_dir: &Path) -> Result<()> { + generate_bindings_tests(self, data_dir, output_dir) + } } diff --git a/crates/solidity/outputs/cargo/tests/build.rs b/crates/solidity/outputs/cargo/tests/build.rs index 6b8b50426..de03e537a 100644 --- a/crates/solidity/outputs/cargo/tests/build.rs +++ b/crates/solidity/outputs/cargo/tests/build.rs @@ -10,5 +10,11 @@ fn main() -> Result<()> { &CargoWorkspace::locate_source_crate("solidity_testing_snapshots")?.join("cst_output"), &CargoWorkspace::locate_source_crate("solidity_cargo_tests")? .join("src/cst_output/generated"), + )?; + + lang_def.generate_bindings_tests( + &CargoWorkspace::locate_source_crate("solidity_testing_snapshots")?.join("bindings"), + &CargoWorkspace::locate_source_crate("solidity_cargo_tests")? + .join("src/bindings/generated"), ) } diff --git a/crates/solidity/outputs/cargo/tests/src/bindings/generated/lexical.rs b/crates/solidity/outputs/cargo/tests/src/bindings/generated/lexical.rs new file mode 100644 index 000000000..c491b70b1 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/bindings/generated/lexical.rs @@ -0,0 +1,20 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +use anyhow::Result; + +use crate::bindings::runner::run; + +#[test] +fn local_vars() -> Result<()> { + run("lexical", "local_vars.sol") +} + +#[test] +fn params() -> Result<()> { + run("lexical", "params.sol") +} + +#[test] +fn state_vars() -> Result<()> { + run("lexical", "state_vars.sol") +} diff --git a/crates/solidity/outputs/cargo/tests/src/bindings/generated/mod.rs b/crates/solidity/outputs/cargo/tests/src/bindings/generated/mod.rs new file mode 100644 index 000000000..6c44b6f97 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/bindings/generated/mod.rs @@ -0,0 +1,3 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +mod lexical; diff --git a/crates/solidity/outputs/cargo/tests/src/bindings/mod.rs b/crates/solidity/outputs/cargo/tests/src/bindings/mod.rs index 1335899b1..6007e75fb 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings/mod.rs @@ -1 +1,3 @@ +mod generated; +mod rules; mod runner; diff --git a/crates/solidity/outputs/cargo/tests/src/bindings/rules.rs b/crates/solidity/outputs/cargo/tests/src/bindings/rules.rs new file mode 100644 index 000000000..f5b513a53 --- /dev/null +++ b/crates/solidity/outputs/cargo/tests/src/bindings/rules.rs @@ -0,0 +1,7 @@ +use slang_solidity::bindings::Bindings; + +#[test] +fn test_bindings_rules_parsing() { + let result = Bindings::get_graph_builder(); + assert!(result.is_ok()); +} diff --git a/crates/solidity/outputs/cargo/tests/src/bindings/runner.rs b/crates/solidity/outputs/cargo/tests/src/bindings/runner.rs index 5d4d6deb6..85fb43554 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings/runner.rs @@ -4,7 +4,6 @@ use std::path::PathBuf; use anyhow::Result; use infra_utils::cargo::CargoWorkspace; -use infra_utils::paths::FileWalker; use slang_solidity::assertions::{check_assertions, collect_assertions}; use slang_solidity::bindings::graph_builder::{ ExecutionConfig, Functions, Graph, NoCancellation, Variables, @@ -13,21 +12,10 @@ use slang_solidity::bindings::Bindings; use slang_solidity::language::Language; use slang_solidity::parse_output::ParseOutput; -#[test] -pub fn run_all() -> Result<()> { - let data_dir = - CargoWorkspace::locate_source_crate("solidity_testing_snapshots")?.join("bindings"); - - for file in FileWalker::from_directory(data_dir).find(["*.sol"])? { - run(file.file_name().unwrap().to_str().unwrap())?; - } - - Ok(()) -} - -fn run(file_name: &str) -> Result<()> { - let data_dir = - CargoWorkspace::locate_source_crate("solidity_testing_snapshots")?.join("bindings"); +pub fn run(group_name: &str, file_name: &str) -> Result<()> { + let data_dir = CargoWorkspace::locate_source_crate("solidity_testing_snapshots")? + .join("bindings") + .join(group_name); let input_path = data_dir.join(file_name); let input = fs::read_to_string(&input_path)?; diff --git a/crates/solidity/testing/snapshots/bindings/generated/lexical.sol.mmd b/crates/solidity/testing/snapshots/bindings/generated/lexical.sol.mmd deleted file mode 100644 index 28e66b3ee..000000000 --- a/crates/solidity/testing/snapshots/bindings/generated/lexical.sol.mmd +++ /dev/null @@ -1,210 +0,0 @@ -graph TD - N0["`**0** @(1, 1) -@source_unit.lexical_scope -line 25 column 21`"] - N1["`**1** @(1, 1) -@source_unit.defs -line 26 column 21`"] - N1 --> N3 - N2["`**2** @(1, 1) -@contract.lexical_scope -line 35 column 18`"] - N2 --> N0 - N2 --> N4 - N2 --> N6 - N2 --> N8 - N2 --> N34 - N3["`**3** @(1, 1) -@contract.defs -line 36 column 18`"] - N3 --> N4 - N3 --> N34 - N4[\"`**Foo** @(1, 1) -def -line 40 column 8`"/] - N5["`**5** @(3, 1) -@function.lexical_scope -line 119 column 18`"] - N5 --> N2 - N5 --> N9 - N5 --> N12 - N6["`**6** @(3, 1) -@function.defs -line 120 column 18`"] - N6 --> N9 - N7["`**7** @(15, 1) -@function.lexical_scope -line 119 column 18`"] - N7 --> N2 - N7 --> N10 - N8["`**8** @(15, 1) -@function.defs -line 120 column 18`"] - N8 --> N10 - N9[\"`**bar** @(3, 1) -def -line 124 column 8`"/] - N10[\"`**baz** @(15, 1) -def -line 124 column 8`"/] - N11["`**11** @(5, 18) -@param.lexical_scope -line 132 column 15`"] - N11 --> N17 - N12["`**12** @(5, 18) -@param.defs -line 133 column 15`"] - N12 --> N17 - N13["`**13** @(5, 35) -@param.lexical_scope -line 132 column 15`"] - N14["`**14** @(5, 35) -@param.defs -line 133 column 15`"] - N15["`**15** @(16, 29) -@param.lexical_scope -line 132 column 15`"] - N16["`**16** @(16, 29) -@param.defs -line 133 column 15`"] - N17[\"`**z** @(5, 18) -def -line 137 column 8`"/] - N18["`**18** @(5, 40) -@body.lexical_scope -line 169 column 14`"] - N18 --> N5 - N19["`**19** @(5, 40) -@body.defs -line 170 column 14`"] - N20["`**20** @(16, 33) -@body.lexical_scope -line 169 column 14`"] - N20 --> N7 - N21["`**21** @(16, 33) -@body.defs -line 170 column 14`"] - N22["`**22** @(5, 40) -@block.lexical_scope -line 184 column 15`"] - N22 --> N18 - N22 --> N23 - N23["`**23** @(5, 40) -@block.defs -line 185 column 15`"] - N23 --> N27 - N23 --> N29 - N24["`**24** @(16, 33) -@block.lexical_scope -line 184 column 15`"] - N24 --> N20 - N24 --> N25 - N25["`**25** @(16, 33) -@block.defs -line 185 column 15`"] - N25 --> N31 - N26["`**26** @(6, 1) -@stmt.lexical_scope -line 190 column 14`"] - N26 --> N22 - N26 --> N32 - N27["`**27** @(6, 1) -@stmt.defs -line 191 column 14`"] - N27 --> N32 - N28["`**28** @(8, 1) -@stmt.lexical_scope -line 190 column 14`"] - N28 --> N22 - N29["`**29** @(8, 1) -@stmt.defs -line 191 column 14`"] - N30["`**30** @(17, 1) -@stmt.lexical_scope -line 190 column 14`"] - N30 --> N24 - N31["`**31** @(17, 1) -@stmt.defs -line 191 column 14`"] - N32[\"`**x** @(6, 1) -def -line 209 column 8`"/] - N33["`**33** @(2, 1) -@state_var.lexical_scope -line 238 column 19`"] - N33 --> N2 - N33 --> N35 - N34["`**34** @(2, 1) -@state_var.defs -line 239 column 19`"] - N34 --> N35 - N35[\"`**y** @(2, 1) -def -line 243 column 8`"/] - N36["`**36** @(7, 17) -@expr.lexical_scope -line 320 column 14`"] - N37["`**37** @(10, 15) -@expr.lexical_scope -line 320 column 14`"] - N37 --> N28 - N38["`**38** @(10, 15) -@expr.lexical_scope -line 320 column 14`"] - N38 --> N37 - N39["`**39** @(10, 15) -@expr.lexical_scope -line 320 column 14`"] - N39 --> N38 - N40["`**40** @(10, 19) -@expr.lexical_scope -line 320 column 14`"] - N40 --> N38 - N41["`**41** @(10, 23) -@expr.lexical_scope -line 320 column 14`"] - N41 --> N37 - N42["`**42** @(17, 15) -@expr.lexical_scope -line 320 column 14`"] - N42 --> N30 - N43["`**43** @(17, 15) -@expr.lexical_scope -line 320 column 14`"] - N43 --> N42 - N44["`**44** @(17, 15) -@expr.lexical_scope -line 320 column 14`"] - N44 --> N43 - N45["`**45** @(17, 19) -@expr.lexical_scope -line 320 column 14`"] - N45 --> N43 - N46["`**46** @(17, 23) -@expr.lexical_scope -line 320 column 14`"] - N46 --> N42 - N47[/"`**x** @(10, 15) -ref -line 324 column 8`"\] - N47 --> N39 - N48[/"`**y** @(10, 19) -ref -line 324 column 8`"\] - N48 --> N40 - N49[/"`**z** @(10, 23) -ref -line 324 column 8`"\] - N49 --> N41 - N50[/"`**w** @(17, 15) -ref -line 324 column 8`"\] - N50 --> N44 - N51[/"`**z** @(17, 19) -ref -line 324 column 8`"\] - N51 --> N45 - N52[/"`**x** @(17, 23) -ref -line 324 column 8`"\] - N52 --> N46 diff --git a/crates/solidity/testing/snapshots/bindings/lexical.sol b/crates/solidity/testing/snapshots/bindings/lexical.sol deleted file mode 100644 index a2b24e4c1..000000000 --- a/crates/solidity/testing/snapshots/bindings/lexical.sol +++ /dev/null @@ -1,22 +0,0 @@ -contract Foo { - uint y; - // ^def:1 - - function bar(uint z) returns (uint) { - // ^def:2 - uint x = 10; - // ^def:3 - - return x + y + z; - // ^ref:2 - // ^ref:1 - // ^ref:3 - } - - function baz() returns (int) { - return w + z + x; - // ^ref:! - // ^ref:! - // ^ref:! - } -} diff --git a/crates/solidity/testing/snapshots/bindings/lexical/generated/local_vars.sol.mmd b/crates/solidity/testing/snapshots/bindings/lexical/generated/local_vars.sol.mmd new file mode 100644 index 000000000..743d834e8 --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings/lexical/generated/local_vars.sol.mmd @@ -0,0 +1,156 @@ +graph TD + N0["`**0** @(1, 1) +@source_unit.lexical_scope +line 25 column 21`"] + N1["`**1** @(1, 1) +@source_unit.defs +line 26 column 21`"] + N1 --> N3 + N2["`**2** @(1, 1) +@contract.lexical_scope +line 35 column 18`"] + N2 --> N0 + N2 --> N4 + N2 --> N6 + N2 --> N8 + N3["`**3** @(1, 1) +@contract.defs +line 36 column 18`"] + N3 --> N4 + N4[\"`**Foo** @(1, 1) +def +line 40 column 8`"/] + N5["`**5** @(2, 1) +@function.lexical_scope +line 119 column 18`"] + N5 --> N2 + N5 --> N9 + N6["`**6** @(2, 1) +@function.defs +line 120 column 18`"] + N6 --> N9 + N7["`**7** @(9, 1) +@function.lexical_scope +line 119 column 18`"] + N7 --> N2 + N7 --> N10 + N8["`**8** @(9, 1) +@function.defs +line 120 column 18`"] + N8 --> N10 + N9[\"`**bar** @(2, 1) +def +line 124 column 8`"/] + N10[\"`**baz** @(9, 1) +def +line 124 column 8`"/] + N11["`**11** @(2, 29) +@param.lexical_scope +line 132 column 15`"] + N12["`**12** @(2, 29) +@param.defs +line 133 column 15`"] + N13["`**13** @(10, 29) +@param.lexical_scope +line 132 column 15`"] + N14["`**14** @(10, 29) +@param.defs +line 133 column 15`"] + N15["`**15** @(2, 34) +@body.lexical_scope +line 169 column 14`"] + N15 --> N5 + N16["`**16** @(2, 34) +@body.defs +line 170 column 14`"] + N17["`**17** @(10, 33) +@body.lexical_scope +line 169 column 14`"] + N17 --> N7 + N18["`**18** @(10, 33) +@body.defs +line 170 column 14`"] + N19["`**19** @(2, 34) +@block.lexical_scope +line 184 column 15`"] + N19 --> N15 + N19 --> N20 + N20["`**20** @(2, 34) +@block.defs +line 185 column 15`"] + N20 --> N24 + N20 --> N26 + N21["`**21** @(10, 33) +@block.lexical_scope +line 184 column 15`"] + N21 --> N17 + N21 --> N22 + N22["`**22** @(10, 33) +@block.defs +line 185 column 15`"] + N22 --> N28 + N23["`**23** @(3, 1) +@stmt.lexical_scope +line 190 column 14`"] + N23 --> N19 + N23 --> N29 + N24["`**24** @(3, 1) +@stmt.defs +line 191 column 14`"] + N24 --> N29 + N25["`**25** @(4, 1) +@stmt.lexical_scope +line 190 column 14`"] + N25 --> N19 + N26["`**26** @(4, 1) +@stmt.defs +line 191 column 14`"] + N27["`**27** @(11, 1) +@stmt.lexical_scope +line 190 column 14`"] + N27 --> N21 + N28["`**28** @(11, 1) +@stmt.defs +line 191 column 14`"] + N29[\"`**x** @(3, 1) +def +line 209 column 8`"/] + N30["`**30** @(3, 17) +@expr.lexical_scope +line 320 column 14`"] + N31["`**31** @(6, 15) +@expr.lexical_scope +line 320 column 14`"] + N31 --> N25 + N32["`**32** @(6, 15) +@expr.lexical_scope +line 320 column 14`"] + N32 --> N31 + N33["`**33** @(6, 19) +@expr.lexical_scope +line 320 column 14`"] + N33 --> N31 + N34["`**34** @(11, 15) +@expr.lexical_scope +line 320 column 14`"] + N34 --> N27 + N35["`**35** @(11, 15) +@expr.lexical_scope +line 320 column 14`"] + N35 --> N34 + N36["`**36** @(11, 19) +@expr.lexical_scope +line 320 column 14`"] + N36 --> N34 + N37[/"`**x** @(6, 15) +ref +line 324 column 8`"\] + N37 --> N32 + N38[/"`**w** @(11, 15) +ref +line 324 column 8`"\] + N38 --> N35 + N39[/"`**x** @(11, 19) +ref +line 324 column 8`"\] + N39 --> N36 diff --git a/crates/solidity/testing/snapshots/bindings/lexical/generated/params.sol.mmd b/crates/solidity/testing/snapshots/bindings/lexical/generated/params.sol.mmd new file mode 100644 index 000000000..18eafe536 --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings/lexical/generated/params.sol.mmd @@ -0,0 +1,148 @@ +graph TD + N0["`**0** @(1, 1) +@source_unit.lexical_scope +line 25 column 21`"] + N1["`**1** @(1, 1) +@source_unit.defs +line 26 column 21`"] + N1 --> N3 + N2["`**2** @(1, 1) +@contract.lexical_scope +line 35 column 18`"] + N2 --> N0 + N2 --> N4 + N2 --> N6 + N2 --> N8 + N3["`**3** @(1, 1) +@contract.defs +line 36 column 18`"] + N3 --> N4 + N4[\"`**Foo** @(1, 1) +def +line 40 column 8`"/] + N5["`**5** @(2, 1) +@function.lexical_scope +line 119 column 18`"] + N5 --> N2 + N5 --> N9 + N5 --> N12 + N6["`**6** @(2, 1) +@function.defs +line 120 column 18`"] + N6 --> N9 + N7["`**7** @(8, 1) +@function.lexical_scope +line 119 column 18`"] + N7 --> N2 + N7 --> N10 + N8["`**8** @(8, 1) +@function.defs +line 120 column 18`"] + N8 --> N10 + N9[\"`**bar** @(2, 1) +def +line 124 column 8`"/] + N10[\"`**baz** @(8, 1) +def +line 124 column 8`"/] + N11["`**11** @(2, 18) +@param.lexical_scope +line 132 column 15`"] + N11 --> N17 + N12["`**12** @(2, 18) +@param.defs +line 133 column 15`"] + N12 --> N17 + N13["`**13** @(2, 35) +@param.lexical_scope +line 132 column 15`"] + N14["`**14** @(2, 35) +@param.defs +line 133 column 15`"] + N15["`**15** @(9, 29) +@param.lexical_scope +line 132 column 15`"] + N16["`**16** @(9, 29) +@param.defs +line 133 column 15`"] + N17[\"`**z** @(2, 18) +def +line 137 column 8`"/] + N18["`**18** @(2, 40) +@body.lexical_scope +line 169 column 14`"] + N18 --> N5 + N19["`**19** @(2, 40) +@body.defs +line 170 column 14`"] + N20["`**20** @(9, 33) +@body.lexical_scope +line 169 column 14`"] + N20 --> N7 + N21["`**21** @(9, 33) +@body.defs +line 170 column 14`"] + N22["`**22** @(2, 40) +@block.lexical_scope +line 184 column 15`"] + N22 --> N18 + N22 --> N23 + N23["`**23** @(2, 40) +@block.defs +line 185 column 15`"] + N23 --> N27 + N24["`**24** @(9, 33) +@block.lexical_scope +line 184 column 15`"] + N24 --> N20 + N24 --> N25 + N25["`**25** @(9, 33) +@block.defs +line 185 column 15`"] + N25 --> N29 + N26["`**26** @(3, 1) +@stmt.lexical_scope +line 190 column 14`"] + N26 --> N22 + N27["`**27** @(3, 1) +@stmt.defs +line 191 column 14`"] + N28["`**28** @(10, 1) +@stmt.lexical_scope +line 190 column 14`"] + N28 --> N24 + N29["`**29** @(10, 1) +@stmt.defs +line 191 column 14`"] + N30["`**30** @(5, 15) +@expr.lexical_scope +line 320 column 14`"] + N30 --> N26 + N31["`**31** @(5, 15) +@expr.lexical_scope +line 320 column 14`"] + N31 --> N30 + N32["`**32** @(5, 19) +@expr.lexical_scope +line 320 column 14`"] + N32 --> N30 + N33["`**33** @(10, 15) +@expr.lexical_scope +line 320 column 14`"] + N33 --> N28 + N34["`**34** @(10, 15) +@expr.lexical_scope +line 320 column 14`"] + N34 --> N33 + N35["`**35** @(10, 19) +@expr.lexical_scope +line 320 column 14`"] + N35 --> N33 + N36[/"`**z** @(5, 15) +ref +line 324 column 8`"\] + N36 --> N31 + N37[/"`**z** @(10, 15) +ref +line 324 column 8`"\] + N37 --> N34 diff --git a/crates/solidity/testing/snapshots/bindings/lexical/generated/state_vars.sol.mmd b/crates/solidity/testing/snapshots/bindings/lexical/generated/state_vars.sol.mmd new file mode 100644 index 000000000..97788998d --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings/lexical/generated/state_vars.sol.mmd @@ -0,0 +1,197 @@ +graph TD + N0["`**0** @(1, 1) +@source_unit.lexical_scope +line 25 column 21`"] + N1["`**1** @(1, 1) +@source_unit.defs +line 26 column 21`"] + N1 --> N3 + N1 --> N5 + N2["`**2** @(1, 1) +@contract.lexical_scope +line 35 column 18`"] + N2 --> N0 + N2 --> N6 + N2 --> N9 + N2 --> N11 + N2 --> N42 + N3["`**3** @(1, 1) +@contract.defs +line 36 column 18`"] + N3 --> N6 + N3 --> N42 + N4["`**4** @(15, 1) +@contract.lexical_scope +line 35 column 18`"] + N4 --> N0 + N4 --> N7 + N4 --> N13 + N5["`**5** @(15, 1) +@contract.defs +line 36 column 18`"] + N5 --> N7 + N6[\"`**Foo** @(1, 1) +def +line 40 column 8`"/] + N7[\"`**Bar** @(15, 1) +def +line 40 column 8`"/] + N8["`**8** @(3, 1) +@function.lexical_scope +line 119 column 18`"] + N8 --> N2 + N8 --> N14 + N9["`**9** @(3, 1) +@function.defs +line 120 column 18`"] + N9 --> N14 + N10["`**10** @(9, 1) +@function.lexical_scope +line 119 column 18`"] + N10 --> N2 + N10 --> N15 + N11["`**11** @(9, 1) +@function.defs +line 120 column 18`"] + N11 --> N15 + N12["`**12** @(17, 1) +@function.lexical_scope +line 119 column 18`"] + N12 --> N4 + N12 --> N16 + N13["`**13** @(17, 1) +@function.defs +line 120 column 18`"] + N13 --> N16 + N14[\"`**bar** @(3, 1) +def +line 124 column 8`"/] + N15[\"`**baz** @(9, 1) +def +line 124 column 8`"/] + N16[\"`**quux** @(17, 1) +def +line 124 column 8`"/] + N17["`**17** @(5, 29) +@param.lexical_scope +line 132 column 15`"] + N18["`**18** @(5, 29) +@param.defs +line 133 column 15`"] + N19["`**19** @(10, 29) +@param.lexical_scope +line 132 column 15`"] + N20["`**20** @(10, 29) +@param.defs +line 133 column 15`"] + N21["`**21** @(17, 30) +@param.lexical_scope +line 132 column 15`"] + N22["`**22** @(17, 30) +@param.defs +line 133 column 15`"] + N23["`**23** @(5, 34) +@body.lexical_scope +line 169 column 14`"] + N23 --> N8 + N24["`**24** @(5, 34) +@body.defs +line 170 column 14`"] + N25["`**25** @(10, 33) +@body.lexical_scope +line 169 column 14`"] + N25 --> N10 + N26["`**26** @(10, 33) +@body.defs +line 170 column 14`"] + N27["`**27** @(17, 35) +@body.lexical_scope +line 169 column 14`"] + N27 --> N12 + N28["`**28** @(17, 35) +@body.defs +line 170 column 14`"] + N29["`**29** @(5, 34) +@block.lexical_scope +line 184 column 15`"] + N29 --> N23 + N29 --> N30 + N30["`**30** @(5, 34) +@block.defs +line 185 column 15`"] + N30 --> N36 + N31["`**31** @(10, 33) +@block.lexical_scope +line 184 column 15`"] + N31 --> N25 + N31 --> N32 + N32["`**32** @(10, 33) +@block.defs +line 185 column 15`"] + N32 --> N38 + N33["`**33** @(17, 35) +@block.lexical_scope +line 184 column 15`"] + N33 --> N27 + N33 --> N34 + N34["`**34** @(17, 35) +@block.defs +line 185 column 15`"] + N34 --> N40 + N35["`**35** @(6, 1) +@stmt.lexical_scope +line 190 column 14`"] + N35 --> N29 + N36["`**36** @(6, 1) +@stmt.defs +line 191 column 14`"] + N37["`**37** @(11, 1) +@stmt.lexical_scope +line 190 column 14`"] + N37 --> N31 + N38["`**38** @(11, 1) +@stmt.defs +line 191 column 14`"] + N39["`**39** @(18, 1) +@stmt.lexical_scope +line 190 column 14`"] + N39 --> N33 + N40["`**40** @(18, 1) +@stmt.defs +line 191 column 14`"] + N41["`**41** @(2, 1) +@state_var.lexical_scope +line 238 column 19`"] + N41 --> N2 + N41 --> N43 + N42["`**42** @(2, 1) +@state_var.defs +line 239 column 19`"] + N42 --> N43 + N43[\"`**x** @(2, 1) +def +line 243 column 8`"/] + N44["`**44** @(6, 15) +@expr.lexical_scope +line 320 column 14`"] + N44 --> N35 + N45["`**45** @(11, 15) +@expr.lexical_scope +line 320 column 14`"] + N45 --> N37 + N46["`**46** @(18, 15) +@expr.lexical_scope +line 320 column 14`"] + N46 --> N39 + N47[/"`**x** @(6, 15) +ref +line 324 column 8`"\] + N47 --> N44 + N48[/"`**y** @(11, 15) +ref +line 324 column 8`"\] + N48 --> N45 + N49[/"`**x** @(18, 15) +ref +line 324 column 8`"\] + N49 --> N46 diff --git a/crates/solidity/testing/snapshots/bindings/lexical/local_vars.sol b/crates/solidity/testing/snapshots/bindings/lexical/local_vars.sol new file mode 100644 index 000000000..f4c3a060c --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings/lexical/local_vars.sol @@ -0,0 +1,15 @@ +contract Foo { + function bar() returns (uint) { + uint x = 10; + // ^def:1 + + return x + 2; + // ^ref:1 + } + + function baz() returns (int) { + return w + x; + // ^ref:! + // ^ref:! + } +} diff --git a/crates/solidity/testing/snapshots/bindings/lexical/params.sol b/crates/solidity/testing/snapshots/bindings/lexical/params.sol new file mode 100644 index 000000000..730a1187f --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings/lexical/params.sol @@ -0,0 +1,13 @@ +contract Foo { + function bar(uint z) returns (uint) { + // ^def:1 + + return z + 1; + // ^ref:1 + } + + function baz() returns (int) { + return z + 2; + // ^ref:! + } +} diff --git a/crates/solidity/testing/snapshots/bindings/lexical/state_vars.sol b/crates/solidity/testing/snapshots/bindings/lexical/state_vars.sol new file mode 100644 index 000000000..d90352548 --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings/lexical/state_vars.sol @@ -0,0 +1,21 @@ +contract Foo { + uint x; + // ^def:1 + + function bar() returns (uint) { + return x; + // ^ref:1 + } + + function baz() returns (int) { + return y; + // ^ref:! + } +} + +contract Bar { + function quux() returns (uint) { + return x; + // ^ref:! + } +}