From d7b64804cc290207daeaee39306940bbd21e5f91 Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:54:36 -0800 Subject: [PATCH] t2 --- .../crate/src/runtime/compilation/internal.rs | 58 ++++++++++++++++++- .../src/generated/compilation/internal.rs | 56 +++++++++++++++++- .../src/generated/compilation/internal.rs | 56 +++++++++++++++++- 3 files changed, 167 insertions(+), 3 deletions(-) diff --git a/crates/codegen/runtime/cargo/crate/src/runtime/compilation/internal.rs b/crates/codegen/runtime/cargo/crate/src/runtime/compilation/internal.rs index c690b5d347..beeac6e838 100644 --- a/crates/codegen/runtime/cargo/crate/src/runtime/compilation/internal.rs +++ b/crates/codegen/runtime/cargo/crate/src/runtime/compilation/internal.rs @@ -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, +} + +impl Compilation { + pub fn create(version: Version) -> std::result::Result { + 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 }))); + } +} diff --git a/crates/solidity/outputs/cargo/crate/src/generated/compilation/internal.rs b/crates/solidity/outputs/cargo/crate/src/generated/compilation/internal.rs index beb707bdcf..d2ff8d9b32 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/compilation/internal.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/compilation/internal.rs @@ -1,3 +1,57 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -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, +} + +impl Compilation { + pub fn create(version: Version) -> std::result::Result { + 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 }))); + } +} diff --git a/crates/testlang/outputs/cargo/crate/src/generated/compilation/internal.rs b/crates/testlang/outputs/cargo/crate/src/generated/compilation/internal.rs index beb707bdcf..d2ff8d9b32 100644 --- a/crates/testlang/outputs/cargo/crate/src/generated/compilation/internal.rs +++ b/crates/testlang/outputs/cargo/crate/src/generated/compilation/internal.rs @@ -1,3 +1,57 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -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, +} + +impl Compilation { + pub fn create(version: Version) -> std::result::Result { + 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 }))); + } +}