Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
feat(solc): add source map parser (#658)
Browse files Browse the repository at this point in the history
* feat(solc): add source map parser

* merge branch master

* make some types private

* chore: make id an option

* fix: support negative field values

* check parsed element
  • Loading branch information
mattsse authored Jan 6, 2022
1 parent 10f014b commit 88b3422
Show file tree
Hide file tree
Showing 5 changed files with 569 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ethers-solc/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ use std::{
str::FromStr,
};

use crate::{compile::*, error::SolcIoError, remappings::Remapping, utils};
use crate::{
compile::*,
error::SolcIoError,
remappings::Remapping,
sourcemap::{self, SourceMap, SyntaxError},
utils,
};
use ethers_core::abi::Address;
use serde::{de::Visitor, Deserialize, Deserializer, Serialize, Serializer};

Expand Down Expand Up @@ -813,6 +819,13 @@ pub struct Bytecode {
}

impl Bytecode {
/// Returns the parsed source map
///
/// See also https://docs.soliditylang.org/en/v0.8.10/internals/source_mappings.html
pub fn source_map(&self) -> Option<Result<SourceMap, SyntaxError>> {
self.source_map.as_ref().map(|map| sourcemap::parse(map))
}

/// Same as `Bytecode::link` but with fully qualified name (`file.sol:Math`)
pub fn link_fully_qualified(&mut self, name: impl AsRef<str>, addr: Address) -> bool {
if let Some((file, lib)) = name.as_ref().split_once(':') {
Expand Down
1 change: 1 addition & 0 deletions ethers-solc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![doc = include_str ! ("../README.md")]

pub mod artifacts;
pub mod sourcemap;

pub use artifacts::{CompilerInput, CompilerOutput, EvmVersion};
use std::collections::btree_map::Entry;
Expand Down
Loading

0 comments on commit 88b3422

Please sign in to comment.