-
Notifications
You must be signed in to change notification settings - Fork 22
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
Showing
410 changed files
with
13,168 additions
and
2,315 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@nomicfoundation/slang": minor | ||
--- | ||
|
||
rename `parser/Parser.supportedVersions()` API to `utils/LanguageFacts.supportedVersions()`. |
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,5 @@ | ||
--- | ||
"@nomicfoundation/slang": minor | ||
--- | ||
|
||
expose the `BingingGraph` API to allow querying definitions/references between source files. |
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,5 @@ | ||
--- | ||
"@nomicfoundation/slang": minor | ||
--- | ||
|
||
add a `CompilationBuilder` API to incrementally load and resolve source files and their imports. |
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
12 changes: 12 additions & 0 deletions
12
crates/codegen/runtime/cargo/crate/src/extensions/bindings/mod.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,12 @@ | ||
use semver::Version; | ||
|
||
use crate::bindings::BindingGraph; | ||
use crate::parser::ParserInitializationError; | ||
|
||
#[allow(clippy::needless_pass_by_value)] | ||
pub fn add_built_ins( | ||
_binding_graph: &mut BindingGraph, | ||
_version: Version, | ||
) -> Result<(), ParserInitializationError> { | ||
unreachable!("Built-ins are Solidity-specific") | ||
} |
15 changes: 15 additions & 0 deletions
15
crates/codegen/runtime/cargo/crate/src/extensions/compilation/mod.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,15 @@ | ||
use crate::cst::Cursor; | ||
|
||
pub struct ImportPathsExtractor; | ||
|
||
impl ImportPathsExtractor { | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
|
||
#[allow(clippy::unused_self)] | ||
#[allow(clippy::needless_pass_by_value)] | ||
pub fn extract(&self, _: Cursor) -> Vec<Cursor> { | ||
unreachable!("Import paths are Solidity-specific") | ||
} | ||
} |
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,8 @@ | ||
#[cfg(all( | ||
feature = "__experimental_bindings_api", | ||
feature = "__private_compilation_api" | ||
))] | ||
pub mod compilation; | ||
|
||
#[cfg(feature = "__experimental_bindings_api")] | ||
pub mod bindings; |
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
3 changes: 2 additions & 1 deletion
3
crates/codegen/runtime/cargo/crate/src/runtime/bindings/built_ins.rs.jinja2
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
3 changes: 2 additions & 1 deletion
3
crates/codegen/runtime/cargo/crate/src/runtime/bindings/generated/built_ins.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
45 changes: 45 additions & 0 deletions
45
crates/codegen/runtime/cargo/crate/src/runtime/compilation/file.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,45 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use metaslang_cst::text_index::TextIndex; | ||
|
||
use crate::cst::{Cursor, Node}; | ||
|
||
#[derive(Clone)] | ||
pub struct File { | ||
id: String, | ||
tree: Node, | ||
|
||
resolved_imports: BTreeMap<usize, String>, | ||
} | ||
|
||
impl File { | ||
pub(super) fn new(id: String, tree: Node) -> Self { | ||
Self { | ||
id, | ||
tree, | ||
|
||
resolved_imports: BTreeMap::new(), | ||
} | ||
} | ||
|
||
pub fn id(&self) -> &str { | ||
&self.id | ||
} | ||
|
||
pub fn tree(&self) -> &Node { | ||
&self.tree | ||
} | ||
|
||
pub fn create_tree_cursor(&self) -> Cursor { | ||
self.tree.clone().cursor_with_offset(TextIndex::ZERO) | ||
} | ||
|
||
pub(super) fn resolve_import(&mut self, import_path: &Cursor, destination_file_id: String) { | ||
self.resolved_imports | ||
.insert(import_path.node().id(), destination_file_id); | ||
} | ||
|
||
pub(super) fn resolved_import(&self, import_path: &Cursor) -> Option<&String> { | ||
self.resolved_imports.get(&import_path.node().id()) | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
crates/codegen/runtime/cargo/crate/src/runtime/compilation/internal_builder.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,93 @@ | ||
use std::collections::BTreeMap; | ||
use std::rc::Rc; | ||
|
||
use metaslang_cst::nodes::Node; | ||
use semver::Version; | ||
|
||
use crate::compilation::{CompilationUnit, File}; | ||
use crate::cst::Cursor; | ||
use crate::extensions::compilation::ImportPathsExtractor; | ||
use crate::parser::{Parser, ParserInitializationError}; | ||
|
||
pub struct InternalCompilationBuilder { | ||
parser: Parser, | ||
imports: ImportPathsExtractor, | ||
files: BTreeMap<String, File>, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum CompilationInitializationError { | ||
#[error(transparent)] | ||
ParserInitialization(#[from] ParserInitializationError), | ||
} | ||
|
||
impl InternalCompilationBuilder { | ||
pub fn create(language_version: Version) -> Result<Self, CompilationInitializationError> { | ||
let parser = Parser::create(language_version)?; | ||
|
||
Ok(Self { | ||
parser, | ||
imports: ImportPathsExtractor::new(), | ||
files: BTreeMap::new(), | ||
}) | ||
} | ||
|
||
pub fn add_file(&mut self, id: String, contents: &str) -> AddFileResponse { | ||
if self.files.contains_key(&id) { | ||
// Already added. No need to process it again: | ||
return AddFileResponse { | ||
import_paths: vec![], | ||
}; | ||
} | ||
|
||
let parse_output = self.parser.parse(Parser::ROOT_KIND, contents); | ||
|
||
let import_paths = self.imports.extract(parse_output.create_tree_cursor()); | ||
|
||
let file = File::new( | ||
id.clone(), | ||
Node::Nonterminal(Rc::clone(parse_output.tree())), | ||
); | ||
self.files.insert(id, file); | ||
|
||
AddFileResponse { import_paths } | ||
} | ||
|
||
pub fn resolve_import( | ||
&mut self, | ||
source_file_id: &str, | ||
import_path: &Cursor, | ||
destination_file_id: String, | ||
) -> Result<(), ResolveImportError> { | ||
self.files | ||
.get_mut(source_file_id) | ||
.ok_or_else(|| ResolveImportError::SourceFileNotFound(source_file_id.to_owned()))? | ||
.resolve_import(import_path, destination_file_id); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn build(&self) -> CompilationUnit { | ||
let language_version = self.parser.language_version().to_owned(); | ||
|
||
let files = self | ||
.files | ||
.iter() | ||
.map(|(id, file)| (id.to_owned(), Rc::new(file.to_owned()))) | ||
.collect(); | ||
|
||
CompilationUnit::new(language_version, files) | ||
} | ||
} | ||
|
||
pub struct AddFileResponse { | ||
pub import_paths: Vec<Cursor>, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum ResolveImportError { | ||
#[error( | ||
"Source file not found: '{0}'. Make sure to add it first, before resolving its imports." | ||
)] | ||
SourceFileNotFound(String), | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/codegen/runtime/cargo/crate/src/runtime/compilation/mod.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,7 @@ | ||
mod file; | ||
mod internal_builder; | ||
mod unit; | ||
|
||
pub use file::File; | ||
pub use internal_builder::{AddFileResponse, InternalCompilationBuilder}; | ||
pub use unit::CompilationUnit; |
Oops, something went wrong.