Skip to content

Commit

Permalink
Use a fixed Solidity parser version to parse built-ins file
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Dec 24, 2024
1 parent 976a6c8 commit 177c7f0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::parser::ParserInitializationError;
#[allow(clippy::needless_pass_by_value)]
pub fn add_built_ins(
_binding_graph: &mut BindingGraph,
_version: Version,
_version: &Version,
) -> Result<(), ParserInitializationError> {
unreachable!("Built-ins are Solidity-specific")
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum BindingGraphInitializationError {
ParserInitialization(#[from] ParserInitializationError),
}

#[allow(clippy::needless_pass_by_value)]
pub fn create_with_resolver(
version: Version,
resolver: Rc<dyn PathResolver<KindTypes>>,
Expand All @@ -37,7 +38,7 @@ pub fn create_with_resolver(
resolver,
);

crate::extensions::bindings::add_built_ins(&mut binding_graph, version)?;
crate::extensions::bindings::add_built_ins(&mut binding_graph, &version)?;

Ok(binding_graph)
}
Expand Down
16 changes: 11 additions & 5 deletions crates/solidity/outputs/cargo/crate/src/extensions/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ use crate::bindings::BindingGraph;
use crate::cst::{Edge, Node, NonterminalNode, TerminalKind, TerminalNode};
use crate::parser::{Parser, ParserInitializationError};

static BUILT_INS_PARSER_VERSION: Version = Version::new(0, 8, 28);

pub fn add_built_ins(
binding_graph: &mut BindingGraph,
version: Version,
version: &Version,
) -> Result<(), ParserInitializationError> {
let source = get_built_ins_contents(&version);
let parser = Parser::create(version)?;
let parse_output = parser.parse(Parser::ROOT_KIND, source);
let parser = Parser::create(BUILT_INS_PARSER_VERSION.clone())?;
let built_ins_parse_output = parser.parse(Parser::ROOT_KIND, get_built_ins_contents(version));
assert!(
built_ins_parse_output.is_valid(),
"built-ins parse without errors"
);

let built_ins_cursor = transform(parse_output.tree()).cursor_with_offset(TextIndex::ZERO);
let built_ins_cursor = transform(built_ins_parse_output.tree())
.cursor_with_offset(TextIndex::ZERO);

binding_graph.add_system_file("built_ins.sol", built_ins_cursor);
Ok(())
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::parser::ParserInitializationError;
#[allow(clippy::needless_pass_by_value)]
pub fn add_built_ins(
_binding_graph: &mut BindingGraph,
_version: Version,
_version: &Version,
) -> Result<(), ParserInitializationError> {
unreachable!("Built-ins are Solidity-specific")
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 177c7f0

Please sign in to comment.