-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68bf29c
commit 3c4fb33
Showing
9 changed files
with
105 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::rc::Rc; | ||
|
||
use infra_utils::paths::PathExtensions; | ||
use metaslang_bindings::PathResolver; | ||
use slang_solidity::bindings::{create_with_resolver, BindingGraph}; | ||
use slang_solidity::cst::{Cursor, KindTypes}; | ||
|
||
use crate::dataset::SOLC_VERSION; | ||
use crate::tests::parser::ParsedFile; | ||
|
||
pub fn setup() -> Vec<ParsedFile> { | ||
super::parser::run(super::parser::setup()) | ||
} | ||
|
||
pub fn run(files: Vec<ParsedFile>) -> Rc<BindingGraph> { | ||
let mut bindings_graph_builder = | ||
create_with_resolver(SOLC_VERSION, Rc::new(Resolver {})).unwrap(); | ||
|
||
for file in files { | ||
bindings_graph_builder.add_user_file( | ||
file.path.unwrap_str(), | ||
file.parse_output.create_tree_cursor(), | ||
); | ||
} | ||
|
||
bindings_graph_builder.build() | ||
} | ||
|
||
struct Resolver; | ||
|
||
impl PathResolver<KindTypes> for Resolver { | ||
fn resolve_path(&self, _context_path: &str, path_to_resolve: &Cursor) -> Option<String> { | ||
let path = path_to_resolve.node().unparse(); | ||
let path = path | ||
.strip_prefix(|c| matches!(c, '"' | '\''))? | ||
.strip_suffix(|c| matches!(c, '"' | '\''))?; | ||
|
||
Some(path.to_owned()) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
crates/solidity/testing/perf/src/tests/bindings_resolve.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::rc::Rc; | ||
|
||
use slang_solidity::bindings::BindingGraph; | ||
use slang_solidity::cst::{NonterminalKind, TerminalKind}; | ||
|
||
use crate::tests::parser::ParsedFile; | ||
|
||
pub struct BuiltBindingGraph { | ||
files: Vec<ParsedFile>, | ||
binding_graph: Rc<BindingGraph>, | ||
} | ||
|
||
pub fn setup() -> BuiltBindingGraph { | ||
let files = super::bindings_build::setup(); | ||
let binding_graph = super::bindings_build::run(files.clone()); | ||
|
||
BuiltBindingGraph { | ||
files, | ||
binding_graph, | ||
} | ||
} | ||
|
||
pub fn run(dependencies: BuiltBindingGraph) { | ||
let BuiltBindingGraph { | ||
files, | ||
binding_graph, | ||
} = dependencies; | ||
|
||
for file in files { | ||
let mut cursor = file.parse_output.create_tree_cursor(); | ||
|
||
while cursor.go_to_next_terminal_with_kinds(&[ | ||
TerminalKind::Identifier, | ||
TerminalKind::YulIdentifier, | ||
]) { | ||
if matches!( | ||
cursor.ancestors().next(), | ||
Some(ancestor) if ancestor.kind == NonterminalKind::ExperimentalFeature | ||
) { | ||
// ignore identifiers in `pragma experimental` directives, as they are unbound feature names: | ||
continue; | ||
} | ||
|
||
if binding_graph.definition_at(&cursor).is_none() | ||
&& binding_graph.reference_at(&cursor).is_none() | ||
{ | ||
panic!( | ||
"Unbound identifier: '{value}' at '{range:?}'.", | ||
value = cursor.node().unparse(), | ||
range = cursor.text_range() | ||
); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
pub mod bindings_build; | ||
pub mod bindings_resolve; | ||
pub mod cursor; | ||
pub mod definitions; | ||
pub mod init_bindings; | ||
pub mod parser; | ||
pub mod query; | ||
pub mod references; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.