forked from NomicFoundation/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
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
aa97cbb
commit d7b6480
Showing
3 changed files
with
167 additions
and
3 deletions.
There are no files selected for viewing
58 changes: 57 additions & 1 deletion
58
crates/codegen/runtime/cargo/crate/src/runtime/compilation/internal.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 |
---|---|---|
@@ -1 +1,57 @@ | ||
pub struct InternalCompilation {} | ||
use std::collections::BTreeMap; | ||
use std::rc::Rc; | ||
|
||
use semver::Version; | ||
|
||
use crate::parser::{ParseOutput, Parser, ParserInitializationError}; | ||
|
||
pub enum FileEntry { | ||
Resolved { | ||
id: String, | ||
|
||
parse_output: ParseOutput, | ||
}, | ||
Unresolved, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum CompilationInitializationError { | ||
#[error("Unsupported language version '{0}'.")] | ||
UnsupportedLanguageVersion(Version), | ||
} | ||
|
||
pub struct Compilation { | ||
parser: Parser, | ||
files: BTreeMap<String, FileEntry>, | ||
} | ||
|
||
impl Compilation { | ||
pub fn create(version: Version) -> std::result::Result<Self, CompilationInitializationError> { | ||
let parser = match Parser::create(version) { | ||
Ok(parser) => parser, | ||
Err(ParserInitializationError::UnsupportedLanguageVersion(version)) => { | ||
return Err(CompilationInitializationError::UnsupportedLanguageVersion( | ||
version, | ||
)); | ||
} | ||
}; | ||
|
||
Ok(Self { | ||
parser, | ||
files: BTreeMap::new(), | ||
}) | ||
} | ||
|
||
pub fn version(&self) -> &Version { | ||
&self.parser.version | ||
} | ||
|
||
pub fn add_file(&mut self, id: String, contents: &str) { | ||
|
||
|
||
let parse_output = self.parser.parse(Parser::ROOT_KIND, contents); | ||
|
||
self.files | ||
.insert(id.clone(), File(Rc::new(FileData { id, parse_output }))); | ||
} | ||
} |
56 changes: 55 additions & 1 deletion
56
crates/solidity/outputs/cargo/crate/src/generated/compilation/internal.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
56 changes: 55 additions & 1 deletion
56
crates/testlang/outputs/cargo/crate/src/generated/compilation/internal.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.